|
1
|
package com.adroplat.fist_switch.jni;
|
1
|
package com.adroplat.fist_switch.jni;
|
|
2
|
|
2
|
|
|
3
|
-import android.content.Context;
|
|
|
|
4
|
import android.content.Intent;
|
3
|
import android.content.Intent;
|
|
5
|
import android.os.AsyncTask;
|
4
|
import android.os.AsyncTask;
|
|
6
|
-import android.support.v4.content.LocalBroadcastManager;
|
|
|
|
7
|
import android.text.TextUtils;
|
5
|
import android.text.TextUtils;
|
|
8
|
import android.util.Log;
|
6
|
import android.util.Log;
|
|
9
|
-import com.adroplat.fist_switch.SwitchApplication;
|
|
|
|
10
|
import com.adroplat.fist_switch.config.GlobalVar;
|
7
|
import com.adroplat.fist_switch.config.GlobalVar;
|
|
11
|
import com.adroplat.fist_switch.utils.ToastUtils;
|
8
|
import com.adroplat.fist_switch.utils.ToastUtils;
|
|
12
|
import com.adroplat.fist_switch.utils.WifiUtils;
|
9
|
import com.adroplat.fist_switch.utils.WifiUtils;
|
|
13
|
import com.adroplat.fist_switch.utils.protocol.one.FistProtocol;
|
10
|
import com.adroplat.fist_switch.utils.protocol.one.FistProtocol;
|
|
14
|
import com.google.gson.Gson;
|
11
|
import com.google.gson.Gson;
|
|
15
|
-import com.qnbar.switchcontrol.model.MessageEvent;
|
12
|
+import com.qnbar.switchcontrol.model.SwitchMessageEvent;
|
|
16
|
import io.realm.Realm;
|
13
|
import io.realm.Realm;
|
|
17
|
import org.greenrobot.eventbus.EventBus;
|
14
|
import org.greenrobot.eventbus.EventBus;
|
|
18
|
|
15
|
|
|
@@ -30,6 +27,9 @@ public class FistJni { |
|
@@ -30,6 +27,9 @@ public class FistJni { |
|
30
|
public static final int DEVICE_SWITCH_ONLINE_NOTIFY = 0x7102;
|
27
|
public static final int DEVICE_SWITCH_ONLINE_NOTIFY = 0x7102;
|
|
31
|
private static final String DEVICE_SWITCH_ONLINE_NOTIFY_STR = "DEVICE_SWITCH_ONLINE_NOTIFY_STR";
|
28
|
private static final String DEVICE_SWITCH_ONLINE_NOTIFY_STR = "DEVICE_SWITCH_ONLINE_NOTIFY_STR";
|
|
32
|
|
29
|
|
|
|
|
30
|
+ public static final int DEVICE_SWITCH_ADD_OVER = 0x7103;
|
|
|
|
31
|
+ private static final String DEVICE_SWITCH_ADD_OVER_STR = "DEVICE_SWITCH_ADD_OVER_STR";
|
|
|
|
32
|
+
|
|
33
|
static {
|
33
|
static {
|
|
34
|
System.loadLibrary("fist_ndk");
|
34
|
System.loadLibrary("fist_ndk");
|
|
35
|
}
|
35
|
}
|
|
@@ -69,7 +69,7 @@ public class FistJni { |
|
@@ -69,7 +69,7 @@ public class FistJni { |
|
69
|
public static final String JSON_DEVICE = "JSON_DEVICE";
|
69
|
public static final String JSON_DEVICE = "JSON_DEVICE";
|
|
70
|
|
70
|
|
|
71
|
private static void configDone(Device device) {
|
71
|
private static void configDone(Device device) {
|
|
72
|
- sendJsonDevice(CONFIG_DONE, device);
|
72
|
+// sendJsonDevice(CONFIG_DONE, device);
|
|
73
|
}
|
73
|
}
|
|
74
|
|
74
|
|
|
75
|
private static ArrayList<Device> hubs;
|
75
|
private static ArrayList<Device> hubs;
|
|
@@ -102,14 +102,14 @@ public class FistJni { |
|
@@ -102,14 +102,14 @@ public class FistJni { |
|
102
|
// if (!hasAdded) {
|
102
|
// if (!hasAdded) {
|
|
103
|
getHubs().add(device);
|
103
|
getHubs().add(device);
|
|
104
|
// }
|
104
|
// }
|
|
105
|
- sendMessage(DEVICE_HUBS_ONLINE_NOTIFY, DEVICE_HUBS_ONLINE_NOTIFY_STR);
|
105
|
+// sendMessage(DEVICE_HUBS_ONLINE_NOTIFY, DEVICE_HUBS_ONLINE_NOTIFY_STR);
|
|
106
|
}
|
106
|
}
|
|
107
|
|
107
|
|
|
108
|
private static void sendMessage(int type, String typeStr) {
|
108
|
private static void sendMessage(int type, String typeStr) {
|
|
109
|
- MessageEvent messageEvent = new MessageEvent();
|
|
|
|
110
|
- messageEvent.setEventId(type);
|
|
|
|
111
|
- messageEvent.setMessage(typeStr);
|
|
|
|
112
|
- EventBus.getDefault().post(messageEvent);
|
109
|
+ SwitchMessageEvent switchMessageEvent = new SwitchMessageEvent();
|
|
|
|
110
|
+ switchMessageEvent.setEventId(type);
|
|
|
|
111
|
+ switchMessageEvent.setMessage(typeStr);
|
|
|
|
112
|
+ EventBus.getDefault().post(switchMessageEvent);
|
|
113
|
}
|
113
|
}
|
|
114
|
|
114
|
|
|
115
|
private static void saveRemote(Device device) {
|
115
|
private static void saveRemote(Device device) {
|
|
@@ -139,49 +139,59 @@ public class FistJni { |
|
@@ -139,49 +139,59 @@ public class FistJni { |
|
139
|
return gson;
|
139
|
return gson;
|
|
140
|
}
|
140
|
}
|
|
141
|
|
141
|
|
|
|
|
142
|
+// /**
|
|
|
|
143
|
+// * 发送广播
|
|
|
|
144
|
+// *
|
|
|
|
145
|
+// * @param action
|
|
|
|
146
|
+// * @param device
|
|
|
|
147
|
+// */
|
|
|
|
148
|
+// private static void sendJsonDevice(String action, Device device) {
|
|
|
|
149
|
+// if (null == action || action.isEmpty() || null == device) return;
|
|
|
|
150
|
+// Context context = SwitchApplication.getAppContext();
|
|
|
|
151
|
+// if (null == context) return;
|
|
|
|
152
|
+// Intent intent = getIntent();
|
|
|
|
153
|
+// intent.setAction(action);
|
|
|
|
154
|
+// intent.putExtra(JSON_DEVICE, device);
|
|
|
|
155
|
+// LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
|
|
|
156
|
+// }
|
|
|
|
157
|
+
|
|
142
|
/**
|
158
|
/**
|
|
143
|
- * 发送广播
|
159
|
+ * 发送消息
|
|
144
|
*
|
160
|
*
|
|
145
|
- * @param action
|
|
|
|
146
|
- * @param device
|
161
|
+ * @param type
|
|
|
|
162
|
+ * @param msg
|
|
147
|
*/
|
163
|
*/
|
|
148
|
- private static void sendJsonDevice(String action, Device device) {
|
|
|
|
149
|
- if (null == action || action.isEmpty() || null == device) return;
|
|
|
|
150
|
- Context context = SwitchApplication.getAppContext();
|
|
|
|
151
|
- if (null == context) return;
|
|
|
|
152
|
- Intent intent = getIntent();
|
|
|
|
153
|
- intent.setAction(action);
|
|
|
|
154
|
- intent.putExtra(JSON_DEVICE, device);
|
|
|
|
155
|
- LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
164
|
+ private static void sendJsonDevice(int type, String msg) {
|
|
|
|
165
|
+ if (TextUtils.isEmpty(msg)) {
|
|
|
|
166
|
+ return;
|
|
|
|
167
|
+ }
|
|
|
|
168
|
+ sendMessage(type, msg);
|
|
156
|
}
|
169
|
}
|
|
157
|
|
170
|
|
|
158
|
- static String deviceJsonAA;
|
|
|
|
159
|
-
|
|
|
|
160
|
public static void fistListener(String jsonDevice) {
|
171
|
public static void fistListener(String jsonDevice) {
|
|
161
|
if (null == jsonDevice || jsonDevice.isEmpty()) return;
|
172
|
if (null == jsonDevice || jsonDevice.isEmpty()) return;
|
|
162
|
-// GlobalVar.getLogUtils().i("fistListener jsonDevice =" + jsonDevice);
|
|
|
|
163
|
Log.d(TAG, jsonDevice);
|
173
|
Log.d(TAG, jsonDevice);
|
|
164
|
Gson gson = getGson();
|
174
|
Gson gson = getGson();
|
|
165
|
Device device = gson.fromJson(jsonDevice, Device.class);
|
175
|
Device device = gson.fromJson(jsonDevice, Device.class);
|
|
166
|
char cmdTpye = (char) device.getCmdType();
|
176
|
char cmdTpye = (char) device.getCmdType();
|
|
167
|
- if (TextUtils.isEmpty(deviceJsonAA)) {
|
|
|
|
168
|
- deviceJsonAA = jsonDevice;
|
|
|
|
169
|
- }
|
177
|
+// qnbar_switch
|
|
|
|
178
|
+ Log.d("qnbar_switch", "cmdType:" + device.getCmdType() + "");
|
|
170
|
if (FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE == cmdTpye) {//查询响应
|
179
|
if (FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE == cmdTpye) {//查询响应
|
|
171
|
removeId(device);
|
180
|
removeId(device);
|
|
172
|
online(device, jsonDevice);
|
181
|
online(device, jsonDevice);
|
|
173
|
- sendJsonDevice(SEARCH_RESPONSE, device);
|
|
|
|
174
|
-
|
182
|
+// sendJsonDevice(SEARCH_RESPONSE, device);
|
|
|
|
183
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE, SEARCH_RESPONSE);
|
|
175
|
} else if (FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE == cmdTpye) {//配置完成处理
|
184
|
} else if (FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE == cmdTpye) {//配置完成处理
|
|
176
|
- configDone(device);
|
185
|
+// configDone(device);
|
|
|
|
186
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE, CONFIG_DONE);
|
|
177
|
|
187
|
|
|
178
|
} else if (FistProtocol.CommondType.CMD_TYPE_ONLINE == cmdTpye) {//上线通知
|
188
|
} else if (FistProtocol.CommondType.CMD_TYPE_ONLINE == cmdTpye) {//上线通知
|
|
179
|
removeId(device);
|
189
|
removeId(device);
|
|
180
|
online(device, jsonDevice);
|
190
|
online(device, jsonDevice);
|
|
181
|
- configDone(device);
|
|
|
|
182
|
-
|
191
|
+// configDone(device);
|
|
|
|
192
|
+ sendMessage(FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE, CONFIG_DONE);
|
|
183
|
} else if (FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE == cmdTpye) {
|
193
|
} else if (FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE == cmdTpye) {
|
|
184
|
- sendJsonDevice(ADD_DONE, device);
|
194
|
+// sendJsonDevice(ADD_DONE, device);
|
|
185
|
ArrayList<SubDevice> subDevices = device.getSubDevices();
|
195
|
ArrayList<SubDevice> subDevices = device.getSubDevices();
|
|
186
|
if (!subDevices.isEmpty()) {//查询结果不为空
|
196
|
if (!subDevices.isEmpty()) {//查询结果不为空
|
|
187
|
subDeviceOnline(subDevices);
|
197
|
subDeviceOnline(subDevices);
|
|
@@ -189,30 +199,44 @@ public class FistJni { |
|
@@ -189,30 +199,44 @@ public class FistJni { |
|
189
|
// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
|
199
|
// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
|
|
190
|
}
|
200
|
}
|
|
191
|
// sendJsonDevice(LightingGroupAdapter.REFRESH, device);
|
201
|
// sendJsonDevice(LightingGroupAdapter.REFRESH, device);
|
|
|
|
202
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
|
|
192
|
|
203
|
|
|
193
|
} else if (FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE == cmdTpye) {
|
204
|
} else if (FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE == cmdTpye) {
|
|
194
|
- sendJsonDevice(START_ADD, device);
|
205
|
+// sendJsonDevice(START_ADD, device);
|
|
195
|
// FistJni.stopAddSubDevice(jsonDevice);
|
206
|
// FistJni.stopAddSubDevice(jsonDevice);
|
|
196
|
device.setCmdType(49);
|
207
|
device.setCmdType(49);
|
|
197
|
getInstance().query(gson.toJson(device));
|
208
|
getInstance().query(gson.toJson(device));
|
|
198
|
// getInstance().query(gson.toJson(device));
|
209
|
// getInstance().query(gson.toJson(device));
|
|
|
|
210
|
+
|
|
199
|
FistJni.stopAddSubDevice(jsonDevice);
|
211
|
FistJni.stopAddSubDevice(jsonDevice);
|
|
|
|
212
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE, START_ADD);
|
|
|
|
213
|
+
|
|
200
|
} else if (FistProtocol.CommondType.CMD_TYPE_ADD_OVER == cmdTpye) {//子设备结束入网
|
214
|
} else if (FistProtocol.CommondType.CMD_TYPE_ADD_OVER == cmdTpye) {//子设备结束入网
|
|
201
|
if (0 == device.getIntDeviceIp()) return;
|
215
|
if (0 == device.getIntDeviceIp()) return;
|
|
202
|
device.setCmdType(49);
|
216
|
device.setCmdType(49);
|
|
203
|
// getInstance().query(gson.toJson(device));
|
217
|
// getInstance().query(gson.toJson(device));
|
|
204
|
getInstance().query(gson.toJson(device));
|
218
|
getInstance().query(gson.toJson(device));
|
|
205
|
FistJni.stopAddSubDevice(jsonDevice);
|
219
|
FistJni.stopAddSubDevice(jsonDevice);
|
|
|
|
220
|
+// sendMessage(DEVICE_SWITCH_ADD_OVER, DEVICE_SWITCH_ADD_OVER_STR);
|
|
|
|
221
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_ADD_OVER, ADD_DONE);
|
|
|
|
222
|
+
|
|
206
|
// getInstance().query(jsonDevice);
|
223
|
// getInstance().query(jsonDevice);
|
|
207
|
- } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL == cmdTpye) {//控制超时
|
|
|
|
208
|
- sendJsonDevice(CONTROL_REQUEST_TIMEOUT, device);
|
224
|
+ } else if (FistProtocol.CommondType.CMD_TYPE_ADD_OVER_RESPONSE == cmdTpye) {
|
|
|
|
225
|
+// sendJsonDevice(CONTROL_REQUEST_TIMEOUT, device);
|
|
|
|
226
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_ADD_OVER_RESPONSE, "CMD_TYPE_ADD_OVER_RESPONSE");
|
|
|
|
227
|
+
|
|
|
|
228
|
+ }else if (FistProtocol.CommondType.CMD_TYPE_CONTROL == cmdTpye) {//控制超时
|
|
|
|
229
|
+// sendJsonDevice(CONTROL_REQUEST_TIMEOUT, device);
|
|
|
|
230
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONTROL, CONTROL_REQUEST_TIMEOUT);
|
|
209
|
|
231
|
|
|
210
|
} else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_RESPONSE == cmdTpye) {//控制应答
|
232
|
} else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_RESPONSE == cmdTpye) {//控制应答
|
|
211
|
- sendJsonDevice(CONTROL_RESPONSE, device);
|
233
|
+// sendJsonDevice(CONTROL_RESPONSE, device);
|
|
|
|
234
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONTROL_RESPONSE, CONTROL_RESPONSE);
|
|
212
|
|
235
|
|
|
213
|
} else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_DONE_RESPONSE == cmdTpye) {//单个控制结果
|
236
|
} else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_DONE_RESPONSE == cmdTpye) {//单个控制结果
|
|
214
|
- sendJsonDevice(CONTROL_DONE, device);
|
237
|
+// sendJsonDevice(CONTROL_DONE, device);
|
|
215
|
getInstance().query(getGson().toJson(getHubs().get(0)));
|
238
|
getInstance().query(getGson().toJson(getHubs().get(0)));
|
|
|
|
239
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONTROL_RESPONSE, CONFIG_DONE);
|
|
216
|
// ArrayList<SubDevice> subDevices = device.getSubDevices();
|
240
|
// ArrayList<SubDevice> subDevices = device.getSubDevices();
|
|
217
|
// if (!subDevices.isEmpty()) {//查询结果不为空
|
241
|
// if (!subDevices.isEmpty()) {//查询结果不为空
|
|
218
|
// subDeviceOnline(subDevices);
|
242
|
// subDeviceOnline(subDevices);
|
|
@@ -220,17 +244,21 @@ public class FistJni { |
|
@@ -220,17 +244,21 @@ public class FistJni { |
|
220
|
//// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
|
244
|
//// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
|
|
221
|
// }
|
245
|
// }
|
|
222
|
} else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_OVER == cmdTpye) {
|
246
|
} else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_OVER == cmdTpye) {
|
|
223
|
- sendJsonDevice(CONTROL_OVER, device);
|
|
|
|
224
|
- GlobalVar.getLogUtils().i("CONTROL_OVER");
|
247
|
+// sendJsonDevice(CONTROL_OVER, device);
|
|
|
|
248
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONTROL_OVER, CONTROL_OVER);
|
|
|
|
249
|
+// GlobalVar.getLogUtils().i("CONTROL_OVER");
|
|
225
|
} else if (FistProtocol.CommondType.CMD_NET_LINK_STATUS_RESPONSE == cmdTpye) {
|
250
|
} else if (FistProtocol.CommondType.CMD_NET_LINK_STATUS_RESPONSE == cmdTpye) {
|
|
226
|
- sendJsonDevice(LINK_STATUS_RESPONSE, device);
|
251
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_NET_LINK_STATUS_RESPONSE, LINK_STATUS_RESPONSE);
|
|
|
|
252
|
+// sendJsonDevice(LINK_STATUS_RESPONSE, device);
|
|
227
|
|
253
|
|
|
228
|
} else if (FistProtocol.CommondType.CMD_LINK_RESPONSE == cmdTpye) {
|
254
|
} else if (FistProtocol.CommondType.CMD_LINK_RESPONSE == cmdTpye) {
|
|
229
|
- sendJsonDevice(LINK_RESPONSE, device);
|
255
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_LINK_RESPONSE, LINK_RESPONSE);
|
|
|
|
256
|
+// sendJsonDevice(LINK_RESPONSE, device);
|
|
230
|
|
257
|
|
|
231
|
} else if (FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE == cmdTpye) {
|
258
|
} else if (FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE == cmdTpye) {
|
|
232
|
- GlobalVar.getLogUtils().i("FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE");
|
|
|
|
233
|
- sendJsonDevice(CTRL_PWD_RESPONSE, device);
|
259
|
+// GlobalVar.getLogUtils().i("FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE");
|
|
|
|
260
|
+ sendJsonDevice(FistProtocol.CommondType.CMD_MODIFY_CTRL_PWD_RESPONSE, CTRL_PWD_RESPONSE);
|
|
|
|
261
|
+// sendJsonDevice(CTRL_PWD_RESPONSE, device);
|
|
234
|
|
262
|
|
|
235
|
} /*else if (RemoteProtocol.MsgType.SET_SUCCESS == cmdTpye) {//密码设置成功
|
263
|
} /*else if (RemoteProtocol.MsgType.SET_SUCCESS == cmdTpye) {//密码设置成功
|
|
236
|
GlobalVar.getLogUtils().i("SET_SUCCESS jsonDevice =" + jsonDevice);
|
264
|
GlobalVar.getLogUtils().i("SET_SUCCESS jsonDevice =" + jsonDevice);
|
|
@@ -277,7 +305,7 @@ public class FistJni { |
|
@@ -277,7 +305,7 @@ public class FistJni { |
|
277
|
}
|
305
|
}
|
|
278
|
// if (!hasAdd) {
|
306
|
// if (!hasAdd) {
|
|
279
|
getSubDevices().add(subDevice);
|
307
|
getSubDevices().add(subDevice);
|
|
280
|
- sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
|
308
|
+// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR);
|
|
281
|
// }
|
309
|
// }
|
|
282
|
}
|
310
|
}
|
|
283
|
}
|
311
|
}
|
|
@@ -340,19 +368,6 @@ public class FistJni { |
|
@@ -340,19 +368,6 @@ public class FistJni { |
|
340
|
}.execute();
|
368
|
}.execute();
|
|
341
|
}
|
369
|
}
|
|
342
|
|
370
|
|
|
343
|
- public void query() {
|
|
|
|
344
|
-// if (!HeService.isConn()) {
|
|
|
|
345
|
-// return;
|
|
|
|
346
|
-// }
|
|
|
|
347
|
- new AsyncTask<Void, Void, Void>() {
|
|
|
|
348
|
- @Override
|
|
|
|
349
|
- protected Void doInBackground(Void... params) {
|
|
|
|
350
|
- querySubDevice(deviceJsonAA);
|
|
|
|
351
|
- return null;
|
|
|
|
352
|
- }
|
|
|
|
353
|
- }.execute();
|
|
|
|
354
|
- }
|
|
|
|
355
|
-
|
|
|
|
356
|
/**
|
371
|
/**
|
|
357
|
* 开始添加子设备
|
372
|
* 开始添加子设备
|
|
358
|
*/
|
373
|
*/
|