|
@@ -184,12 +184,15 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
* 按钮模拟指令
|
|
* 按钮模拟指令
|
|
* */
|
|
* */
|
|
public View.OnClickListener btnClickqueryCurrent = new View.OnClickListener() {
|
|
public View.OnClickListener btnClickqueryCurrent = new View.OnClickListener() {
|
|
- //电流过大查询值
|
|
|
|
|
|
+ //查询电流过大值
|
|
@Override
|
|
@Override
|
|
public void onClick(View view) {
|
|
public void onClick(View view) {
|
|
- System.out.println("btnClickqueryCurrent");
|
|
|
|
- Integer queryCurrentData=SerialPortUtil.getInstance().getOtherDevice().queryCurrent();
|
|
|
|
- textqueryCurrentData.set(String.valueOf(queryCurrentData));
|
|
|
|
|
|
+// System.out.println("btnClickqueryCurrent");
|
|
|
|
+// Integer queryCurrentData=SerialPortUtil.getInstance().getOtherDevice().queryCurrent();
|
|
|
|
+// textqueryCurrentData.set(String.valueOf(queryCurrentData));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
};
|
|
};
|
|
public void onSerialPortDataReceived(ComPortData comPortData) {
|
|
public void onSerialPortDataReceived(ComPortData comPortData) {
|
|
@@ -316,6 +319,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
public void onClick(View view) {
|
|
public void onClick(View view) {
|
|
// SendSmsResponse("(测试12355656)");
|
|
// SendSmsResponse("(测试12355656)");
|
|
SendSmsResponse("温度超声波失灵");
|
|
SendSmsResponse("温度超声波失灵");
|
|
|
|
+ SendSmsResponse("温度超声波失灵");
|
|
|
|
+ reportDeviceEvent("commoneEvent","open",3);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
public View.OnClickListener btnClickGetDeviceValue = new View.OnClickListener() {
|
|
public View.OnClickListener btnClickGetDeviceValue = new View.OnClickListener() {
|
|
@@ -343,10 +348,17 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
@Override
|
|
@Override
|
|
public void onClick(View view) {
|
|
public void onClick(View view) {
|
|
System.out.println("btnClicksetScale");
|
|
System.out.println("btnClicksetScale");
|
|
-// SerialPortUtil.getInstance().getOtherDevice().setScale();
|
|
|
|
- SerialPortUtil.getInstance().getWeightDevice().setScale();
|
|
|
|
-// SerialPortUtil.getInstance().getOtherDevice().weightSet();
|
|
|
|
|
|
+ // SerialPortUtil.getInstance().getOtherDevice().weightSet();
|
|
SerialPortUtil.getInstance().getWeightDevice().weightSet();
|
|
SerialPortUtil.getInstance().getWeightDevice().weightSet();
|
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().setScale();
|
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ SerialPortUtil.getInstance().getWeightDevice().setScale();
|
|
|
|
+ }
|
|
|
|
+ },1000);
|
|
|
|
+// SerialPortUtil.getInstance().getWeightDevice().setScale();
|
|
|
|
+
|
|
}
|
|
}
|
|
};
|
|
};
|
|
public View.OnClickListener btnClickclearWeight = new View.OnClickListener() {
|
|
public View.OnClickListener btnClickclearWeight = new View.OnClickListener() {
|
|
@@ -676,10 +688,11 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
}
|
|
}
|
|
},13000);
|
|
},13000);
|
|
|
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
|
|
|
+ mHandler.postDelayed(new Runnable() {//关门过程中称重会有波动,暂时不上报
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
reportProperty();
|
|
reportProperty();
|
|
|
|
+ reportDeviceEvent("commoneEvent","close",3);
|
|
}
|
|
}
|
|
},4000);
|
|
},4000);
|
|
}
|
|
}
|
|
@@ -822,8 +835,15 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
// SerialPortUtil.getInstance().getOtherDevice().clearWeight();//去皮清零
|
|
// SerialPortUtil.getInstance().getOtherDevice().clearWeight();//去皮清零
|
|
SPUtils.getInstance().put("clearWight",2);
|
|
SPUtils.getInstance().put("clearWight",2);
|
|
}
|
|
}
|
|
- pullonNetRodMethod();
|
|
|
|
- reportProperty();
|
|
|
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ reportProperty();
|
|
|
|
+ pullonNetRodMethod();
|
|
|
|
+ reportDeviceEvent("commoneEvent","open",3);
|
|
|
|
+ }
|
|
|
|
+ },500);
|
|
|
|
+
|
|
Log.i(TAG,"欢迎使用智能回收箱");
|
|
Log.i(TAG,"欢迎使用智能回收箱");
|
|
Log.i(TAG,"收到开门=============");
|
|
Log.i(TAG,"收到开门=============");
|
|
Thread thread=new Thread(new Runnable() {
|
|
Thread thread=new Thread(new Runnable() {
|
|
@@ -840,6 +860,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
}
|
|
}
|
|
if(numInt==82){
|
|
if(numInt==82){
|
|
pushRodMethod();
|
|
pushRodMethod();
|
|
|
|
+ reportDeviceEvent("commoneEvent","close",3);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
@@ -1162,16 +1183,16 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
// weight=SerialPortUtil.getInstance().getOtherDevice().readWeight();//称重
|
|
// weight=SerialPortUtil.getInstance().getOtherDevice().readWeight();//称重
|
|
Integer capacity = 0;
|
|
Integer capacity = 0;
|
|
capacity = SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离
|
|
capacity = SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离
|
|
- if (capacity == 0) {
|
|
|
|
- capacity = SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离
|
|
|
|
- }
|
|
|
|
|
|
+// if (capacity == 0) {//不准就再读一次
|
|
|
|
+// capacity = SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离
|
|
|
|
+// }
|
|
Integer magDoorSwitch = 0;
|
|
Integer magDoorSwitch = 0;
|
|
// magDoorSwitch = SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//门磁 //因为门磁安装问题,不需要去判断是否开关门了
|
|
// magDoorSwitch = SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//门磁 //因为门磁安装问题,不需要去判断是否开关门了
|
|
Integer currentTemperature = 0;
|
|
Integer currentTemperature = 0;
|
|
currentTemperature = SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
currentTemperature = SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
- if (currentTemperature == 0) {
|
|
|
|
- currentTemperature = SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
|
- }
|
|
|
|
|
|
+// if (currentTemperature == 0) {
|
|
|
|
+// currentTemperature = SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
|
+// }
|
|
Log.i(TAG, "----------------------------------------");
|
|
Log.i(TAG, "----------------------------------------");
|
|
|
|
|
|
Map<String, ValueWrapper> locationMap = new HashMap<>();
|
|
Map<String, ValueWrapper> locationMap = new HashMap<>();
|
|
@@ -1394,15 +1415,25 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
//设备事件上报
|
|
//设备事件上报
|
|
public static void reportDeviceEvent(String identifier, String event, int num){
|
|
public static void reportDeviceEvent(String identifier, String event, int num){
|
|
HashMap<String, ValueWrapper> hashMap = new HashMap<>();
|
|
HashMap<String, ValueWrapper> hashMap = new HashMap<>();
|
|
|
|
+ HashMap<String, ValueWrapper> hashMapWeight = new HashMap<>();
|
|
// TODO 用户根据实际情况设置
|
|
// TODO 用户根据实际情况设置
|
|
// hashMap.put("ErrorCode", new ValueWrapper.IntValueWrapper(0));
|
|
// hashMap.put("ErrorCode", new ValueWrapper.IntValueWrapper(0));
|
|
if(num==1){
|
|
if(num==1){
|
|
hashMap.put("warnEvent",new ValueWrapper.StringValueWrapper(event));
|
|
hashMap.put("warnEvent",new ValueWrapper.StringValueWrapper(event));
|
|
}else if(num==2){
|
|
}else if(num==2){
|
|
hashMap.put("errorEvent",new ValueWrapper.StringValueWrapper(event));
|
|
hashMap.put("errorEvent",new ValueWrapper.StringValueWrapper(event));
|
|
|
|
+ }else if(num==3){
|
|
|
|
+ int weight =SerialPortUtil.getInstance().getWeightDevice().readWeight();
|
|
|
|
+ String weightS=weight+"";
|
|
|
|
+ hashMap.put("action",new ValueWrapper.StringValueWrapper(event));
|
|
|
|
+ hashMap.put("weight",new ValueWrapper.StringValueWrapper(weightS));
|
|
|
|
+// hashMapWeight.put("weight",new ValueWrapper.IntValueWrapper(weight));
|
|
|
|
+// hashMapWeight.put("action",new ValueWrapper.StringValueWrapper(event));
|
|
|
|
+// hashMapWeight.put("weight",new ValueWrapper.IntValueWrapper(weight));
|
|
|
|
+// hashMap.put("commoneEvent", new ValueWrapper.StructValueWrapper(hashMapWeight));
|
|
}
|
|
}
|
|
OutputParams params = new OutputParams(hashMap);
|
|
OutputParams params = new OutputParams(hashMap);
|
|
- Log.i("设备故障",identifier+"====="+params);
|
|
|
|
|
|
+ Log.i("事件上报",identifier+"====="+event);
|
|
int networkNum=SPUtils.getInstance().getInt("netWork",1);
|
|
int networkNum=SPUtils.getInstance().getInt("netWork",1);
|
|
if(networkNum!=0){
|
|
if(networkNum!=0){
|
|
LinkKit.getInstance().getDeviceThing().thingEventPost(identifier, params, new IPublishResourceListener() {
|
|
LinkKit.getInstance().getDeviceThing().thingEventPost(identifier, params, new IPublishResourceListener() {
|
|
@@ -1447,9 +1478,13 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
// 注册下行监听,包括长连接的状态和云端下行的数据
|
|
// 注册下行监听,包括长连接的状态和云端下行的数据
|
|
LinkKit.getInstance().registerOnPushListener(notifyListener);
|
|
LinkKit.getInstance().registerOnPushListener(notifyListener);
|
|
MqttRrpcRegisterRequest rrpcRegisterRequest = new MqttRrpcRegisterRequest();
|
|
MqttRrpcRegisterRequest rrpcRegisterRequest = new MqttRrpcRegisterRequest();
|
|
|
|
+// rrpcRegisterRequest.topic = "/a1EtqHmfpNk/9pD3trz6OaDV8GF7yRsb/thing/service/currentWeight";
|
|
rrpcRegisterRequest.topic = "/a13H8L6bDyf/9pD3trz6OaDV8GF7yRsb/thing/service/currentWeight";
|
|
rrpcRegisterRequest.topic = "/a13H8L6bDyf/9pD3trz6OaDV8GF7yRsb/thing/service/currentWeight";
|
|
|
|
+
|
|
MqttSubscribeRequest subscribeRequest = new MqttSubscribeRequest();
|
|
MqttSubscribeRequest subscribeRequest = new MqttSubscribeRequest();
|
|
|
|
+// subscribeRequest.topic = "/a1EtqHmfpNk/9pD3trz6OaDV8GF7yRsb/user/checkOnlineStatus";
|
|
subscribeRequest.topic = "/a13H8L6bDyf/9pD3trz6OaDV8GF7yRsb/user/checkOnlineStatus";
|
|
subscribeRequest.topic = "/a13H8L6bDyf/9pD3trz6OaDV8GF7yRsb/user/checkOnlineStatus";
|
|
|
|
+
|
|
subscribeRequest.isSubscribe = true;
|
|
subscribeRequest.isSubscribe = true;
|
|
subscribeRequest.qos = 0;
|
|
subscribeRequest.qos = 0;
|
|
LinkKit.getInstance().subscribe(subscribeRequest, new IConnectSubscribeListener() {
|
|
LinkKit.getInstance().subscribe(subscribeRequest, new IConnectSubscribeListener() {
|
|
@@ -1548,7 +1583,9 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
System.out.println("checkOnlineStatus");
|
|
System.out.println("checkOnlineStatus");
|
|
MqttPublishRequest publishRequest = new MqttPublishRequest();
|
|
MqttPublishRequest publishRequest = new MqttPublishRequest();
|
|
publishRequest.qos = 0;
|
|
publishRequest.qos = 0;
|
|
- publishRequest.topic = "/a13H8L6bDyf/device2/user/checkOnlineStatus";
|
|
|
|
|
|
+// publishRequest.topic = "/a1EtqHmfpNk/"+IMEI+"/user/checkOnlineStatus";//a1EtqHmfpNk
|
|
|
|
+ publishRequest.topic = "/a13H8L6bDyf/"+IMEI+"/user/checkOnlineStatus";//a1EtqHmfpNk
|
|
|
|
+
|
|
publishRequest.payloadObj = "{\"id\":"+ publishRequest.msgId+", \"version\":\"1.0\",\"time\":" + System.currentTimeMillis() + "}";
|
|
publishRequest.payloadObj = "{\"id\":"+ publishRequest.msgId+", \"version\":\"1.0\",\"time\":" + System.currentTimeMillis() + "}";
|
|
// Integer networkInt=netWorkInfo();
|
|
// Integer networkInt=netWorkInfo();
|
|
// Log.i(TAG,"network网络"+networkInt);
|
|
// Log.i(TAG,"network网络"+networkInt);
|
|
@@ -2170,8 +2207,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
if(currentTemperature>25){
|
|
if(currentTemperature>25){
|
|
-// SerialPortUtil.getInstance().getOtherDevice().openuFan();//打开风扇
|
|
|
|
-// SerialPortUtil.getInstance().getOtherDevice().openLight1();
|
|
|
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().openLight1();/打开风扇
|
|
}else{
|
|
}else{
|
|
// SerialPortUtil.getInstance().getOtherDevice().closeFan();//打开风扇
|
|
// SerialPortUtil.getInstance().getOtherDevice().closeFan();//打开风扇
|
|
// SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
// SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
@@ -2216,11 +2252,25 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
|
|
|
public static void SendSmsResponse(String event){//
|
|
public static void SendSmsResponse(String event){//
|
|
if(event.equals("温度超声波失灵")){
|
|
if(event.equals("温度超声波失灵")){
|
|
- reportDeviceEvent("errorEvent","温度超声波失灵",2);
|
|
|
|
- Log.i("警告","发送"+event);
|
|
|
|
|
|
+ int errorNum=SPUtils.getInstance().getInt("errorEvent",1)+1;
|
|
|
|
+ SPUtils.getInstance().put("errorEvent",errorNum);
|
|
|
|
+ if(errorNum==20){//过滤,每20次再上报一次,因为超声和温度是同一个设备,读取了2次,实际上是10次上报一次
|
|
|
|
+ reportDeviceEvent("errorEvent","温度超声波失灵",2);
|
|
|
|
+ Log.i("警告","发送"+event);
|
|
|
|
+ SPUtils.getInstance().put("errorEvent",0);
|
|
|
|
+ }
|
|
|
|
+ Log.i("警告","次数"+errorNum);
|
|
|
|
+// reportDeviceEvent("errorEvent","温度超声波失灵",2);
|
|
|
|
+// Log.i("警告","发送"+event);
|
|
}else {
|
|
}else {
|
|
- reportDeviceEvent("warnEvent",event,1);
|
|
|
|
- Log.i("报警","发送"+event);
|
|
|
|
|
|
+ int warnEvent=SPUtils.getInstance().getInt("warnEvent",1)+1;
|
|
|
|
+ SPUtils.getInstance().put("errorEvent",warnEvent);
|
|
|
|
+ if(warnEvent==3){//过滤
|
|
|
|
+ reportDeviceEvent("warnEvent",event,1);
|
|
|
|
+ Log.i("报警","发送"+event);
|
|
|
|
+ SPUtils.getInstance().put("errorEvent",0);
|
|
|
|
+ }
|
|
|
|
+ Log.i("报警","次数"+warnEvent);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|