Showing
6 changed files
with
127 additions
and
178 deletions
| 1 | -package com.adroplat.fist_switch; | |
| 2 | - | |
| 3 | -import android.app.Application; | |
| 4 | -import android.content.Context; | |
| 5 | - | |
| 6 | -/** | |
| 7 | - * Created by wugian on 2017/3/8. | |
| 8 | - */ | |
| 9 | - | |
| 10 | -public class SwitchApplication extends Application { | |
| 11 | - private static Context context; | |
| 12 | - | |
| 13 | - public static Context getAppContext() { | |
| 14 | - return context; | |
| 15 | - } | |
| 16 | - | |
| 17 | - @Override | |
| 18 | - public void onCreate() { | |
| 19 | - super.onCreate(); | |
| 20 | - context = this.getApplicationContext(); | |
| 21 | - } | |
| 22 | -} |
| 1 | 1 | package com.adroplat.fist_switch.jni; |
| 2 | 2 | |
| 3 | -import android.content.Context; | |
| 4 | 3 | import android.content.Intent; |
| 5 | 4 | import android.os.AsyncTask; |
| 6 | -import android.support.v4.content.LocalBroadcastManager; | |
| 7 | 5 | import android.text.TextUtils; |
| 8 | 6 | import android.util.Log; |
| 9 | -import com.adroplat.fist_switch.SwitchApplication; | |
| 10 | 7 | import com.adroplat.fist_switch.config.GlobalVar; |
| 11 | 8 | import com.adroplat.fist_switch.utils.ToastUtils; |
| 12 | 9 | import com.adroplat.fist_switch.utils.WifiUtils; |
| 13 | 10 | import com.adroplat.fist_switch.utils.protocol.one.FistProtocol; |
| 14 | 11 | import com.google.gson.Gson; |
| 15 | -import com.qnbar.switchcontrol.model.MessageEvent; | |
| 12 | +import com.qnbar.switchcontrol.model.SwitchMessageEvent; | |
| 16 | 13 | import io.realm.Realm; |
| 17 | 14 | import org.greenrobot.eventbus.EventBus; |
| 18 | 15 | |
| ... | ... | @@ -30,6 +27,9 @@ public class FistJni { |
| 30 | 27 | public static final int DEVICE_SWITCH_ONLINE_NOTIFY = 0x7102; |
| 31 | 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 | 33 | static { |
| 34 | 34 | System.loadLibrary("fist_ndk"); |
| 35 | 35 | } |
| ... | ... | @@ -69,7 +69,7 @@ public class FistJni { |
| 69 | 69 | public static final String JSON_DEVICE = "JSON_DEVICE"; |
| 70 | 70 | |
| 71 | 71 | private static void configDone(Device device) { |
| 72 | - sendJsonDevice(CONFIG_DONE, device); | |
| 72 | +// sendJsonDevice(CONFIG_DONE, device); | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | private static ArrayList<Device> hubs; |
| ... | ... | @@ -102,14 +102,14 @@ public class FistJni { |
| 102 | 102 | // if (!hasAdded) { |
| 103 | 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 | 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 | 115 | private static void saveRemote(Device device) { |
| ... | ... | @@ -139,49 +139,59 @@ public class FistJni { |
| 139 | 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 | 171 | public static void fistListener(String jsonDevice) { |
| 161 | 172 | if (null == jsonDevice || jsonDevice.isEmpty()) return; |
| 162 | -// GlobalVar.getLogUtils().i("fistListener jsonDevice =" + jsonDevice); | |
| 163 | 173 | Log.d(TAG, jsonDevice); |
| 164 | 174 | Gson gson = getGson(); |
| 165 | 175 | Device device = gson.fromJson(jsonDevice, Device.class); |
| 166 | 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 | 179 | if (FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE == cmdTpye) {//查询响应 |
| 171 | 180 | removeId(device); |
| 172 | 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 | 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 | 188 | } else if (FistProtocol.CommondType.CMD_TYPE_ONLINE == cmdTpye) {//上线通知 |
| 179 | 189 | removeId(device); |
| 180 | 190 | online(device, jsonDevice); |
| 181 | - configDone(device); | |
| 182 | - | |
| 191 | +// configDone(device); | |
| 192 | + sendMessage(FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE, CONFIG_DONE); | |
| 183 | 193 | } else if (FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE == cmdTpye) { |
| 184 | - sendJsonDevice(ADD_DONE, device); | |
| 194 | +// sendJsonDevice(ADD_DONE, device); | |
| 185 | 195 | ArrayList<SubDevice> subDevices = device.getSubDevices(); |
| 186 | 196 | if (!subDevices.isEmpty()) {//查询结果不为空 |
| 187 | 197 | subDeviceOnline(subDevices); |
| ... | ... | @@ -189,30 +199,44 @@ public class FistJni { |
| 189 | 199 | // sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR); |
| 190 | 200 | } |
| 191 | 201 | // sendJsonDevice(LightingGroupAdapter.REFRESH, device); |
| 202 | + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE, DEVICE_SWITCH_ONLINE_NOTIFY_STR); | |
| 192 | 203 | |
| 193 | 204 | } else if (FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE == cmdTpye) { |
| 194 | - sendJsonDevice(START_ADD, device); | |
| 205 | +// sendJsonDevice(START_ADD, device); | |
| 195 | 206 | // FistJni.stopAddSubDevice(jsonDevice); |
| 196 | 207 | device.setCmdType(49); |
| 197 | 208 | getInstance().query(gson.toJson(device)); |
| 198 | 209 | // getInstance().query(gson.toJson(device)); |
| 210 | + | |
| 199 | 211 | FistJni.stopAddSubDevice(jsonDevice); |
| 212 | + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_ADD_RESPONSE, START_ADD); | |
| 213 | + | |
| 200 | 214 | } else if (FistProtocol.CommondType.CMD_TYPE_ADD_OVER == cmdTpye) {//子设备结束入网 |
| 201 | 215 | if (0 == device.getIntDeviceIp()) return; |
| 202 | 216 | device.setCmdType(49); |
| 203 | 217 | // getInstance().query(gson.toJson(device)); |
| 204 | 218 | getInstance().query(gson.toJson(device)); |
| 205 | 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 | 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 | 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 | 236 | } else if (FistProtocol.CommondType.CMD_TYPE_CONTROL_DONE_RESPONSE == cmdTpye) {//单个控制结果 |
| 214 | - sendJsonDevice(CONTROL_DONE, device); | |
| 237 | +// sendJsonDevice(CONTROL_DONE, device); | |
| 215 | 238 | getInstance().query(getGson().toJson(getHubs().get(0))); |
| 239 | + sendJsonDevice(FistProtocol.CommondType.CMD_TYPE_CONTROL_RESPONSE, CONFIG_DONE); | |
| 216 | 240 | // ArrayList<SubDevice> subDevices = device.getSubDevices(); |
| 217 | 241 | // if (!subDevices.isEmpty()) {//查询结果不为空 |
| 218 | 242 | // subDeviceOnline(subDevices); |
| ... | ... | @@ -220,17 +244,21 @@ public class FistJni { |
| 220 | 244 | //// sendMessage(DEVICE_SWITCH_ONLINE_NOTIFY, DEVICE_SWITCH_ONLINE_NOTIFY_STR); |
| 221 | 245 | // } |
| 222 | 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 | 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 | 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 | 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 | 263 | } /*else if (RemoteProtocol.MsgType.SET_SUCCESS == cmdTpye) {//密码设置成功 |
| 236 | 264 | GlobalVar.getLogUtils().i("SET_SUCCESS jsonDevice =" + jsonDevice); |
| ... | ... | @@ -277,7 +305,7 @@ public class FistJni { |
| 277 | 305 | } |
| 278 | 306 | // if (!hasAdd) { |
| 279 | 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 | 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 | */ | ... | ... |
| 1 | -package com.qnbar.switchcontrol; | |
| 2 | - | |
| 3 | -import android.os.Bundle; | |
| 4 | -import android.support.v7.app.AppCompatActivity; | |
| 5 | -import android.view.View; | |
| 6 | -import com.adroplat.fist_switch.jni.FistJni; | |
| 7 | - | |
| 8 | -public class MainActivity extends AppCompatActivity { | |
| 9 | - @Override | |
| 10 | - protected void onCreate(Bundle savedInstanceState) { | |
| 11 | - super.onCreate(savedInstanceState); | |
| 12 | - setContentView(R.layout.activity_main); | |
| 13 | - | |
| 14 | -// Handler handler = new Handler() { | |
| 15 | -// @Override | |
| 16 | -// public void dispatchMessage(Message msg) { | |
| 17 | -// super.dispatchMessage(msg); | |
| 18 | -// switch (msg.what) { | |
| 19 | -// case UdpPostSender.MSG_What: | |
| 20 | -// Log.d("lovely_switch", "msg what:" + msg.toString()); | |
| 21 | -// break; | |
| 22 | -// default: | |
| 23 | -// Log.d("lovely_switch", msg.toString()); | |
| 24 | -// } | |
| 25 | -// } | |
| 26 | -// }; | |
| 27 | -// new UdpPostSender("", 9000, 9000, handler).start(); | |
| 28 | -// new Thread(){ | |
| 29 | -// @Override | |
| 30 | -// public void run() { | |
| 31 | -// super.run(); | |
| 32 | -// new UdpHelper().StartListen(); | |
| 33 | -// } | |
| 34 | -// }.start(); | |
| 35 | -// new UdpHelper().run(); | |
| 36 | -// new UdpHelper().run(); | |
| 37 | - | |
| 38 | - } | |
| 39 | - | |
| 40 | - public void startSdk(View view) { | |
| 41 | - FistJni fistJni = FistJni.getInstance(); | |
| 42 | - fistJni.startSdk(); | |
| 43 | - } | |
| 44 | - | |
| 45 | - public void searchLocalDevice(View view) { | |
| 46 | - FistJni fistJni = FistJni.getInstance(); | |
| 47 | - fistJni.searchLocalDevice(); | |
| 48 | - } | |
| 49 | - | |
| 50 | - public void startFist(View view) { | |
| 51 | - | |
| 52 | - FistJni fistJni = FistJni.getInstance(); | |
| 53 | - fistJni.query(); | |
| 54 | - } | |
| 55 | - | |
| 56 | - | |
| 57 | - public void normalC1(View view) { | |
| 58 | - FistJni fistJni = FistJni.getInstance(); | |
| 59 | - fistJni.normalC("{\"CmdType\":32,\"ErrorCode\":0,\"DeviceIp\":[192,168,31,163],\"DeviceNum\":[255,255,255,255,0,255],\"DeviceKey\":[120,56,53,98,97,117],\"DevicePort\":9000,\"MappedIp\":[0,0,0,0],\"MappedPort\":0,\"SubDevices\":[{\"SubDeviceNum\":4294967151,\"SubDeviceType\":33,\"SubDeviceStatus\":1,\"SubDeviceOnlineStatus\":0,\"SubDeviceBit\":0}]}"); | |
| 60 | - } | |
| 61 | - | |
| 62 | - public void normalC(View view) { | |
| 63 | - FistJni fistJni = FistJni.getInstance(); | |
| 64 | - fistJni.normalC("{\"CmdType\":32,\"ErrorCode\":0,\"DeviceIp\":[192,168,31,163],\"DeviceNum\":[255,255,255,255,0,255],\"DeviceKey\":[120,56,53,98,97,117],\"DevicePort\":9000,\"MappedIp\":[0,0,0,0],\"MappedPort\":0,\"SubDevices\":[{\"SubDeviceNum\":4294967151,\"SubDeviceType\":33,\"SubDeviceStatus\":0,\"SubDeviceOnlineStatus\":0,\"SubDeviceBit\":0}]}"); | |
| 65 | - } | |
| 66 | - | |
| 67 | -} |
| ... | ... | @@ -11,10 +11,11 @@ import android.widget.Toast; |
| 11 | 11 | import com.adroplat.fist_switch.jni.Device; |
| 12 | 12 | import com.adroplat.fist_switch.jni.FistJni; |
| 13 | 13 | import com.adroplat.fist_switch.jni.SubDevice; |
| 14 | +import com.adroplat.fist_switch.utils.protocol.one.FistProtocol; | |
| 14 | 15 | import com.google.gson.Gson; |
| 15 | 16 | import com.qnbar.switchcontrol.adapter.DeviceListAdapter; |
| 16 | 17 | import com.qnbar.switchcontrol.adapter.SwitchListAdapter; |
| 17 | -import com.qnbar.switchcontrol.model.MessageEvent; | |
| 18 | +import com.qnbar.switchcontrol.model.SwitchMessageEvent; | |
| 18 | 19 | import org.greenrobot.eventbus.EventBus; |
| 19 | 20 | import org.greenrobot.eventbus.Subscribe; |
| 20 | 21 | import org.greenrobot.eventbus.ThreadMode; |
| ... | ... | @@ -22,14 +23,15 @@ import org.greenrobot.eventbus.ThreadMode; |
| 22 | 23 | import java.util.ArrayList; |
| 23 | 24 | |
| 24 | 25 | public class SwitchControlActivity extends AppCompatActivity { |
| 25 | - private String deviceStrKey = "MtfuJL"; | |
| 26 | + private String deviceStrKey = "gRdrgR"; | |
| 26 | 27 | |
| 27 | 28 | @Override |
| 28 | 29 | protected void onCreate(Bundle savedInstanceState) { |
| 29 | 30 | super.onCreate(savedInstanceState); |
| 30 | 31 | setContentView(R.layout.activity_switch_control); |
| 31 | 32 | EventBus.getDefault().register(this); |
| 32 | - //TODO EventBus,List of Hub,List of Lights | |
| 33 | + //EventBus,List of Hub,List of Lights | |
| 34 | + //TODO save DeviceNum,SubDeviceNum | |
| 33 | 35 | initList(); |
| 34 | 36 | FistJni fistJni = FistJni.getInstance(); |
| 35 | 37 | fistJni.startSdk(); |
| ... | ... | @@ -44,21 +46,6 @@ public class SwitchControlActivity extends AppCompatActivity { |
| 44 | 46 | fistJni.searchLocalDevice(); |
| 45 | 47 | } |
| 46 | 48 | |
| 47 | - public void startFist() { | |
| 48 | - FistJni fistJni = FistJni.getInstance(); | |
| 49 | - fistJni.query(); | |
| 50 | - } | |
| 51 | - | |
| 52 | - public void normalC1() { | |
| 53 | - FistJni fistJni = FistJni.getInstance(); | |
| 54 | - fistJni.normalC("{\"CmdType\":32,\"ErrorCode\":0,\"DeviceIp\":[192,168,31,163],\"DeviceNum\":[255,255,255,255,0,255],\"DeviceKey\":[120,56,53,98,97,117],\"DevicePort\":9000,\"MappedIp\":[0,0,0,0],\"MappedPort\":0,\"SubDevices\":[{\"SubDeviceNum\":4294967151,\"SubDeviceType\":33,\"SubDeviceStatus\":1,\"SubDeviceOnlineStatus\":0,\"SubDeviceBit\":0}]}"); | |
| 55 | - } | |
| 56 | - | |
| 57 | - public void normalC() { | |
| 58 | - FistJni fistJni = FistJni.getInstance(); | |
| 59 | - fistJni.normalC("{\"CmdType\":32,\"ErrorCode\":0,\"DeviceIp\":[192,168,31,163],\"DeviceNum\":[255,255,255,255,0,255],\"DeviceKey\":[120,56,53,98,97,117],\"DevicePort\":9000,\"MappedIp\":[0,0,0,0],\"MappedPort\":0,\"SubDevices\":[{\"SubDeviceNum\":4294967151,\"SubDeviceType\":33,\"SubDeviceStatus\":0,\"SubDeviceOnlineStatus\":0,\"SubDeviceBit\":0}]}"); | |
| 60 | - } | |
| 61 | - | |
| 62 | 49 | DeviceListAdapter hubAdapter; |
| 63 | 50 | SwitchListAdapter switchAdapter; |
| 64 | 51 | RecyclerView hubRv; |
| ... | ... | @@ -75,8 +62,17 @@ public class SwitchControlActivity extends AppCompatActivity { |
| 75 | 62 | hubAdapter.setListener(new DeviceListAdapter.OnRecyclerViewItemClickListener() { |
| 76 | 63 | @Override |
| 77 | 64 | public void onItemClick(Device light, int position) { |
| 78 | - FistJni fistJni = FistJni.getInstance(); | |
| 79 | - fistJni.query(new Gson().toJson(light)); | |
| 65 | + Device device = null; | |
| 66 | + for (Device deviceCur : FistJni.getHubs()) { | |
| 67 | + if (deviceCur.getDeviceStrKey().equals(deviceStrKey)) { | |
| 68 | + device = deviceCur; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + if (device == null) { | |
| 72 | + toast("没有发现当前配置主机"); | |
| 73 | + return; | |
| 74 | + } | |
| 75 | + FistJni.getInstance().query(new Gson().toJson(light)); | |
| 80 | 76 | } |
| 81 | 77 | |
| 82 | 78 | @Override |
| ... | ... | @@ -87,7 +83,7 @@ public class SwitchControlActivity extends AppCompatActivity { |
| 87 | 83 | @Override |
| 88 | 84 | public void onMenuClick(View v, int position) { |
| 89 | 85 | deviceStrKey = FistJni.getHubs().get(position).getDeviceStrKey(); |
| 90 | - Toast.makeText(SwitchControlActivity.this, "重设控制口令", Toast.LENGTH_SHORT).show(); | |
| 86 | + toast("重设控制口令"); | |
| 91 | 87 | Log.d("menu", "reset control hub:" + deviceStrKey); |
| 92 | 88 | } |
| 93 | 89 | }); |
| ... | ... | @@ -110,7 +106,7 @@ public class SwitchControlActivity extends AppCompatActivity { |
| 110 | 106 | } |
| 111 | 107 | } |
| 112 | 108 | if (device == null) { |
| 113 | - Toast.makeText(SwitchControlActivity.this, "当前控制口令出错,请重新选择控制主机按menu设置", Toast.LENGTH_SHORT).show(); | |
| 109 | + toast("当前控制口令出错,请重新选择控制主机按menu设置"); | |
| 114 | 110 | return; |
| 115 | 111 | } |
| 116 | 112 | if (light.getSubDeviceStatus() == 0) { |
| ... | ... | @@ -118,7 +114,7 @@ public class SwitchControlActivity extends AppCompatActivity { |
| 118 | 114 | } else { |
| 119 | 115 | light.setSubDeviceStatus(0); |
| 120 | 116 | } |
| 121 | - final ArrayList<SubDevice> subDevices = new ArrayList<>(); | |
| 117 | + ArrayList<SubDevice> subDevices = new ArrayList<>(); | |
| 122 | 118 | subDevices.add(light); |
| 123 | 119 | device.setSubDevices(subDevices); |
| 124 | 120 | FistJni.getInstance().normalC(new Gson().toJson(device)); |
| ... | ... | @@ -139,7 +135,7 @@ public class SwitchControlActivity extends AppCompatActivity { |
| 139 | 135 | } |
| 140 | 136 | } |
| 141 | 137 | if (device == null) { |
| 142 | - Toast.makeText(SwitchControlActivity.this, "当前控制口令出错,请重新选择控制主机按menu设置", Toast.LENGTH_SHORT).show(); | |
| 138 | + toast("当前控制口令出错,请重新选择控制主机按menu设置"); | |
| 143 | 139 | return; |
| 144 | 140 | } |
| 145 | 141 | |
| ... | ... | @@ -147,6 +143,8 @@ public class SwitchControlActivity extends AppCompatActivity { |
| 147 | 143 | subDevices.add(FistJni.getSubDevices().get(position)); |
| 148 | 144 | device.setSubDevices(subDevices); |
| 149 | 145 | FistJni.getInstance().delSub(new Gson().toJson(device)); |
| 146 | + FistJni.getSubDevices().clear(); | |
| 147 | + switchAdapter.notifyDataSetChanged(); | |
| 150 | 148 | } |
| 151 | 149 | }); |
| 152 | 150 | switchRv.setAdapter(switchAdapter); |
| ... | ... | @@ -181,7 +179,12 @@ public class SwitchControlActivity extends AppCompatActivity { |
| 181 | 179 | public void setLinkMsg(View view) { |
| 182 | 180 | FistJni fistJni = FistJni.getInstance(); |
| 183 | 181 | Device device = FistJni.getHubs().get(0); |
| 184 | - fistJni.getlinkRouter(new Gson().toJson(device),"Xiaomi123","88888888"); | |
| 182 | +// fistJni.getlinkRouter(new Gson().toJson(device),"Xiaomi123","88888888"); | |
| 183 | + fistJni.getlinkRouter(new Gson().toJson(device), "LEMOMOFFICE2.4G", "88888888"); | |
| 184 | + } | |
| 185 | + | |
| 186 | + public void scanHubs(View view) { | |
| 187 | + searchLocalDevice(); | |
| 185 | 188 | } |
| 186 | 189 | |
| 187 | 190 | public class MovieItemDecoration extends RecyclerView.ItemDecoration { |
| ... | ... | @@ -196,20 +199,37 @@ public class SwitchControlActivity extends AppCompatActivity { |
| 196 | 199 | } |
| 197 | 200 | |
| 198 | 201 | @Subscribe(threadMode = ThreadMode.MAIN) |
| 199 | - public void onMoonEvent(MessageEvent messageEvent) { | |
| 200 | - switch (messageEvent.getEventId()) { | |
| 202 | + public void onMoonEvent(SwitchMessageEvent switchMessageEvent) { | |
| 203 | + switch (switchMessageEvent.getEventId()) { | |
| 201 | 204 | case FistJni.DEVICE_HUBS_ONLINE_NOTIFY: |
| 202 | - Log.d("switch", messageEvent.getMessage()); | |
| 205 | + case FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE: | |
| 206 | + Log.d("qnbar_switch", switchMessageEvent.getMessage()); | |
| 203 | 207 | hubAdapter.notifyDataSetChanged(); |
| 204 | 208 | break; |
| 205 | - | |
| 206 | 209 | case FistJni.DEVICE_SWITCH_ONLINE_NOTIFY: |
| 207 | - Log.d("switch", messageEvent.getMessage()); | |
| 210 | + case FistProtocol.CommondType.CMD_TYPE_QUERY_RESPONSE: | |
| 211 | + Log.d("qnbar_switch", switchMessageEvent.getMessage()); | |
| 208 | 212 | switchAdapter.notifyDataSetChanged(); |
| 209 | 213 | break; |
| 214 | + case FistJni.DEVICE_SWITCH_ADD_OVER: | |
| 215 | + case FistProtocol.CommondType.CMD_TYPE_ADD_OVER: | |
| 216 | + Log.d("qnbar_switch", switchMessageEvent.getMessage()); | |
| 217 | + toast("设备添加完成"); | |
| 218 | + break; | |
| 219 | + case FistProtocol.CommondType.CMD_TYPE_ADD_OVER_RESPONSE: | |
| 220 | + Log.d("qnbar_switch", switchMessageEvent.getMessage()); | |
| 221 | + toast("子设备有变动"); | |
| 222 | + break; | |
| 223 | + default: | |
| 224 | + Log.d("qnbar_switch", "default:" + switchMessageEvent.getMessage() + "," + switchMessageEvent.getEventId()); | |
| 225 | + break; | |
| 210 | 226 | } |
| 211 | 227 | } |
| 212 | 228 | |
| 229 | + private void toast(String msg) { | |
| 230 | + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); | |
| 231 | + } | |
| 232 | + | |
| 213 | 233 | @Override |
| 214 | 234 | protected void onDestroy() { |
| 215 | 235 | super.onDestroy(); | ... | ... |
| ... | ... | @@ -15,6 +15,9 @@ |
| 15 | 15 | |
| 16 | 16 | <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> |
| 17 | 17 | |
| 18 | + <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="扫描主机" | |
| 19 | + android:onClick="scanHubs"/> | |
| 20 | + | |
| 18 | 21 | <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始添加" |
| 19 | 22 | android:onClick="startAdd"/> |
| 20 | 23 | ... | ... |
Please
register
or
login
to post a comment