Device.java
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package com.adroplat.fist_switch.jni;
import com.adroplat.fist_switch.config.GlobalVar;
import com.adroplat.fist_switch.utils.ByteUtils;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
/**
* Created by WLJ on 16-3-8.
*/
public class Device implements Serializable, Cloneable {
private static final long serialVersionUID = -1055014034866886590L;
private static Device instance;
private Device() {
}
public static Device getInstance() {
if (null == instance) {
instance = new Device();
}
Device hub;
try {
hub = (Device) instance.clone();
} catch (CloneNotSupportedException e) {
hub = new Device();
}
return hub;
}
/**
* 控制ID
*/
private long ControllerId;
/**
* 命令类型
*/
private int CmdType;
/**
* 错误码
*/
private byte ErrorCode;
/**
* 设备IP
*/
private byte[] DeviceIp;
/**
* 设备端口
*/
private int DevicePort;
/**
* 设备公网IP
*/
private byte[] MappedIp;
/**
* 设备公网端口
*/
private int MappedPort;
/**
* 设备号
*/
private byte[] DeviceNum;
/**
* 设备口令
*/
private byte[] DeviceKey;
/**
* 是否是广域网控制
*/
private boolean IsWan;
/**
* 子设备
*/
private ArrayList<SubDevice> SubDevices;
public long getControllerId() {
return ControllerId;
}
public void setControllerId(long controllerId) {
ControllerId = controllerId;
}
public int getCmdType() {
return CmdType;
}
public void setCmdType(int cmdType) {
CmdType = cmdType;
}
public byte getErrorCode() {
return ErrorCode;
}
public void setErrorCode(byte errorCode) {
ErrorCode = errorCode;
}
public byte[] getDeviceIp() {
return DeviceIp;
}
public String getStringDeviceIp() {
String strIp = "null";
if (null != DeviceIp) {
char point = '.';
StringBuilder builder = new StringBuilder();
for (byte b : DeviceIp) {
builder.append(b & GlobalVar.MAX_BYTE).append(point);
}
builder.deleteCharAt(builder.length() - 1);
strIp = builder.toString();
}
return strIp;
}
public void setDeviceIp(byte[] deviceIp) {
DeviceIp = deviceIp;
}
public int getDevicePort() {
return DevicePort;
}
public void setDevicePort(int devicePort) {
DevicePort = devicePort;
}
public byte[] getMappedIp() {
return MappedIp;
}
public void setMappedIp(byte[] mappedIp) {
MappedIp = mappedIp;
}
public int getMappedPort() {
return MappedPort;
}
public void setMappedPort(int mappedPort) {
MappedPort = mappedPort;
}
public byte[] getDeviceNum() {
return DeviceNum;
}
public void setDeviceNum(byte[] deviceNum) {
DeviceNum = deviceNum;
}
public byte[] getDeviceKey() {
return DeviceKey;
}
public String getDeviceStrKey() {
String strKey = "";
try {
strKey = new String(DeviceKey, GlobalVar.CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return strKey;
}
public void setDeviceKey(byte[] deviceKey) {
DeviceKey = deviceKey;
}
public boolean isWan() {
return IsWan;
}
public void setWan(boolean wan) {
IsWan = wan;
}
public ArrayList<SubDevice> getSubDevices() {
return SubDevices;
}
public void setSubDevices(ArrayList<SubDevice> subDevices) {
this.SubDevices = subDevices;
}
/**
* DeviceNum转换成long
*
* @return
*/
public long getLongDeviceNum() {
return ByteUtils.macArrayToLong(DeviceNum);
}
/**
* DeviceKey转换成long
*
* @return
*/
public long getLongDeviceKey() {
return ByteUtils.macArrayToLong(DeviceKey);
}
/**
* MappedIp转换成int
*
* @return
*/
public int getIntMappedIp() {
return ByteUtils.byteArrayToInt(MappedIp);
}
/**
* DeviceIp转换成int
*
* @return
*/
public int getIntDeviceIp() {
return ByteUtils.byteArrayToInt(DeviceIp);
}
}