这是上一篇博客指令格式代码
boolean tag = device.getIsOpen1();
// 远程控制
if (Content.isyauncheng == true) {
String str = "";
if (tag == false) {// 表明灯是关的、需要发开的指令
// FA07+蓝牙地址+(01-09)序号+开关指令71、72、74(开)
// 61、62、64(关) click_num(如果连续按了两次,指令才处理,方便区分究竟是处理了那次指令) 指令的定义跟公司有关。
// device.getMdeviceAddress():远程控制器的MAC地址
str = "FA07"
+ device.getMdeviceAddress().replace(":", "")
+ "0" + click_num + 71;
} else if (tag == true) {// 表明灯是开的
str = "FA07"
+ device.getMdeviceAddress().replace(":", "")
+ "0" + click_num + 61;
}
1.首先说明一下,boolean tag = device.getIsOpen1();
- tag 是判断发送打开开关指令(str = “FA07”+ device.getMdeviceAddress().replace(“:”, “”) + “0” + click_num + 71;)还是关闭开关指令(str = “FA07”+ device.getMdeviceAddress().replace(“:”, “”) + “0” + click_num + 61;)。
2.那么IsOpen1()值是哪里设置的呢?
- 备注:具体代码看上一篇博客
// 首先,获取返回服务器返回的状态值
clickString = str;
...
// 然后,获取clickString的14位到16位作为判断状态的值
result = clickString.substring(14, 16).trim();
...
// 然后,给具体各路开关设置状态值
switch (result) {
// TODO: 00代表几路开关都是关的
case "00"://三路开关都是显示关的状态
mLeDeviceListAdapter_cxj.getDevice(clickPosition).setIsOpen1(false);
mLeDeviceListAdapter_cxj.getDevice(clickPosition).setOpen2(false);
mLeDeviceListAdapter_cxj.getDevice(clickPosition).setOpen3(false);
break;
case "01"://一路开关开,其他两路关
mLeDeviceListAdapter_cxj.getDevice(clickPosition).setIsOpen1(true);
mLeDeviceListAdapter_cxj.getDevice(clickPosition).setOpen2(false);
mLeDeviceListAdapter_cxj.getDevice(clickPosition).setOpen3(false);
break;
case "02"://二路开,其他两路关
mLeDeviceListAdapter_cxj.getDevice(clickPosition).setIsOpen1(false);
mLeDeviceListAdapter_cxj.getDevice(clickPosition).setOpen2(true);
mLeDeviceListAdapter_cxj.getDevice(clickPosition).setOpen3(false);
break;
...
3.其实这样依赖服务反馈回来的状态值设置开关的现在所处的状态,然后依赖现在开关的所处的状态去发送开指令或者关指令,会引发连续发送开指令或者连续发送关指令的问题(客户端发送指令–服务器–远程控制器–开关,这个过程是耗时操作,现在的硬件的水平以及WiFi稳定性,成功率一般在90%左右,只要反馈的状态值还没有来的急刷新该路开关的UI状态值,然后第二次指令又再次发送很可能会发动两次开的指令,甚至更多)。
4.对于上面这个问题,个人已经想出处理问题的办法,那就是不管开关是开或者是关,都发送同一个指令(前提发送同一个指令过去的时候,硬件能实现取反功能)
if (Content.isyauncheng == true) {
String str = "";
// if (tag == false) {// 表明灯是关的、需要发开的指令
// FA07+蓝牙地址+(01-09)序号+开关指令71、72、74(开)
// 61、62、64(关)
str = "FA07"
+ device.getMdeviceAddress().replace(":", "")
+ "0" + click_num + 01;
System.out.println("发送开的指令:" + str);
// }
// else if (tag == true) {// 表明灯是开的
// str = "FA07"
// + device.getMdeviceAddress().replace(":", "")
// + "0" + click_num + 61;
// System.out.println("发送关的指令:" + str);
// }
备注: 不明白的地方可以留言。