| xqd
@@ -157,11 +157,11 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
// mLocationUtils.stopLocationClient();
|
|
|
// }
|
|
|
// },5000);
|
|
|
-
|
|
|
MainViewModel.context = getApplication();
|
|
|
SPUtils.getInstance().put("RunningState",0);//设备运行状态
|
|
|
SPUtils.getInstance().put("magDoorSwitch",0);//门磁状态
|
|
|
-
|
|
|
+ Integer networkNum=netWorkInfoStatic();
|
|
|
+ SPUtils.getInstance().put("netWork",networkNum);
|
|
|
BatteryManager batteryManager = (BatteryManager)getSystemService(BATTERY_SERVICE);//电量管理
|
|
|
int battery = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);//查询电量值
|
|
|
Log.i(TAG,"电量值="+battery);
|
| xqd
@@ -314,7 +314,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
//发送短信 事件测试
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
- SendSmsResponse("(测试12355656)");
|
|
|
+// SendSmsResponse("(测试12355656)");
|
|
|
+ SendSmsResponse("温度超声波失灵");
|
|
|
}
|
|
|
};
|
|
|
public View.OnClickListener btnClickGetDeviceValue = new View.OnClickListener() {
|
| xqd
@@ -622,7 +623,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
private void pushRodMethod(){
|
|
|
//有网下关门
|
|
|
SerialPortUtil.getInstance().getOtherDevice().pushRod();//关门
|
|
|
-
|
|
|
+ reportProperty();
|
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
| xqd
@@ -816,9 +817,11 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
restartAndroid();//重启系统
|
|
|
}
|
|
|
if(topic.endsWith("thing/service/RemoteOpen")){// 云端开门的请求。
|
|
|
-// SerialPortUtil.getInstance().getPushRodDevice().pushRod();
|
|
|
-// SerialPortUtil.getInstance().getWeightDevice().weightClear();//去皮清零
|
|
|
+ if( SPUtils.getInstance().getInt("clearWight", 2)==1){
|
|
|
+ SerialPortUtil.getInstance().getWeightDevice().weightClear();//去皮清零
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().clearWeight();//去皮清零
|
|
|
+ SPUtils.getInstance().put("clearWight",2);
|
|
|
+ }
|
|
|
pullonNetRodMethod();
|
|
|
reportProperty();
|
|
|
Log.i(TAG,"欢迎使用智能回收箱");
|
| xqd
@@ -859,10 +862,19 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
if(topic.endsWith("thing/service/RemoteClose")){
|
|
|
Log.i(TAG,"收到关门========================");
|
|
|
pushRodMethod();
|
|
|
+ //测试 每次关门后清零
|
|
|
+// mHandler.postDelayed(new Runnable() {
|
|
|
+// @Override
|
|
|
+// public void run() {
|
|
|
+// SerialPortUtil.getInstance().getWeightDevice().weightClear();
|
|
|
+// reportProperty();
|
|
|
+// }
|
|
|
+// },10000);
|
|
|
}
|
|
|
if(topic.endsWith("thing/service/RemoteAgentOpen")){//开收运门
|
|
|
Log.i(TAG,"开运收门");
|
|
|
SPUtils.getInstance().put("magDoorSwitch",1);
|
|
|
+ SPUtils.getInstance().put("clearWight",1);
|
|
|
short i = 1;
|
|
|
try {
|
|
|
SerialPortUtil.getInstance().getOtherDevice().openLock();
|
| xqd
@@ -887,6 +899,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
@Override
|
|
|
public void run() {
|
|
|
SerialPortUtil.getInstance().getOtherDevice().closeLock();
|
|
|
+ SerialPortUtil.getInstance().getWeightDevice().weightClear();//若关闭,称重清零
|
|
|
lockSwitch=0;//关锁
|
|
|
Thread thread=new Thread(new Runnable() {
|
|
|
@Override
|
| xqd
@@ -928,6 +941,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
SPUtils.getInstance().put("magDoorSwitch", 0);
|
|
|
SerialPortUtil.getInstance().getWeightDevice().weightClear();
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().clearWeight();
|
|
|
+ reportProperty();
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
| xqd
@@ -1128,8 +1142,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
// publishRepeat();
|
|
|
Log.i(TAG,"上报数据");
|
|
|
- Integer networkNum=netWorkInfo();
|
|
|
- if(networkNum!=0) {
|
|
|
+// Integer networkNum=netWorkInfo();
|
|
|
+// if(networkNum!=0) {
|
|
|
try {
|
|
|
double longitude = 104.05;
|
|
|
double latitude = 30.69;
|
| xqd
@@ -1152,7 +1166,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
capacity = SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离
|
|
|
}
|
|
|
Integer magDoorSwitch = 0;
|
|
|
- magDoorSwitch = SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//门磁
|
|
|
+// magDoorSwitch = SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//门磁 //因为门磁安装问题,不需要去判断是否开关门了
|
|
|
Integer currentTemperature = 0;
|
|
|
currentTemperature = SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
if (currentTemperature == 0) {
|
| xqd
@@ -1238,7 +1252,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- }
|
|
|
+// }
|
|
|
}
|
|
|
});
|
|
|
thread.start();
|
| xqd
@@ -1248,18 +1262,21 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
* 上报给蓝牙的数据格式
|
|
|
* */
|
|
|
public JSONObject reportDataMethod(){
|
|
|
- Integer capacity=0;
|
|
|
- capacity=SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离/
|
|
|
- if(capacity==0){
|
|
|
- capacity=SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离/
|
|
|
- }
|
|
|
+ //称重必须要传,其他的可以删掉,不过要和后台协商,统一数据格式
|
|
|
+
|
|
|
+
|
|
|
+ Integer capacity=1000;
|
|
|
+// capacity=SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离/
|
|
|
+// if(capacity==0){
|
|
|
+// capacity=SerialPortUtil.getInstance().getOtherDevice().getDistance();//超声波距离/
|
|
|
+// }
|
|
|
Integer magDoorSwitch=0;
|
|
|
- magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//门磁
|
|
|
- Integer currentTemperature=0;
|
|
|
- currentTemperature=SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
- if(currentTemperature==0){
|
|
|
- currentTemperature=SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
- }
|
|
|
+// magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//门磁
|
|
|
+ Integer currentTemperature=25;
|
|
|
+// currentTemperature=SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
+// if(currentTemperature==0){
|
|
|
+// currentTemperature=SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
+// }
|
|
|
Integer weight = 0;
|
|
|
weight=SerialPortUtil.getInstance().getWeightDevice().readWeight();
|
|
|
if(weight==1){
|
| xqd
@@ -1290,9 +1307,9 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
|
|
|
|
|
|
int runningStateInt=SPUtils.getInstance().getInt("RunningState");
|
|
|
-// JSONObject tem1 =new JSONObject();
|
|
|
-// tem1.put("V",IMEI);
|
|
|
-// tem1.put("I","IMEI");
|
|
|
+ JSONObject tem1 =new JSONObject();
|
|
|
+ tem1.put("V",IMEI);
|
|
|
+ tem1.put("I","IMEI");
|
|
|
|
|
|
JSONObject tem2 =new JSONObject();
|
|
|
tem2.put("V",rodNumberInt);
|
| xqd
@@ -1338,7 +1355,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
// tem11.put("I","GeoLocation");
|
|
|
|
|
|
JSONArray array =new JSONArray();
|
|
|
-// array.add(tem1);
|
|
|
+ array.add(tem1);
|
|
|
array.add(tem2);
|
|
|
array.add(tem3);
|
|
|
array.add(tem4);
|
| xqd
@@ -1386,7 +1403,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
OutputParams params = new OutputParams(hashMap);
|
|
|
Log.i("设备故障",identifier+"====="+params);
|
|
|
- Integer networkNum=netWorkInfoStatic();
|
|
|
+ int networkNum=SPUtils.getInstance().getInt("netWork",1);
|
|
|
if(networkNum!=0){
|
|
|
LinkKit.getInstance().getDeviceThing().thingEventPost(identifier, params, new IPublishResourceListener() {
|
|
|
@Override
|
| xqd
@@ -1533,9 +1550,9 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
publishRequest.qos = 0;
|
|
|
publishRequest.topic = "/a13H8L6bDyf/device2/user/checkOnlineStatus";
|
|
|
publishRequest.payloadObj = "{\"id\":"+ publishRequest.msgId+", \"version\":\"1.0\",\"time\":" + System.currentTimeMillis() + "}";
|
|
|
- Integer networkInt=netWorkInfo();
|
|
|
- Log.i(TAG,"network网络"+networkInt);
|
|
|
- if(networkInt!=0){
|
|
|
+// Integer networkInt=netWorkInfo();
|
|
|
+// Log.i(TAG,"network网络"+networkInt);
|
|
|
+// if(networkInt!=0){
|
|
|
LinkKit.getInstance().publish(publishRequest, new IConnectSendListener() {
|
|
|
@Override
|
|
|
public void onResponse(ARequest aRequest, AResponse aResponse) {
|
| xqd
@@ -1563,11 +1580,11 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
publish();
|
|
|
}
|
|
|
- },100000);
|
|
|
+ },1000000);
|
|
|
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
+// }
|
|
|
|
|
|
}
|
|
|
|
| xqd
@@ -1693,6 +1710,11 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
if(data[0].endsWith("fir3")) {
|
|
|
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, requestBytes);// 响应客户端
|
|
|
if (data[1].equals("11")) {
|
|
|
+ if( SPUtils.getInstance().getInt("clearWight", 2)==1){
|
|
|
+ SerialPortUtil.getInstance().getWeightDevice().weightClear();//去皮清零
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().clearWeight();//去皮清零
|
|
|
+ SPUtils.getInstance().put("clearWight",2);
|
|
|
+ }
|
|
|
pullRodMethod();
|
|
|
Log.i(TAG, "----------------------*************--"+data[1]+"+++"+data[2]);
|
|
|
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, requestBytes);// 响应客户端
|
| xqd
@@ -1737,6 +1759,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, requestBytes);// 响应客户端
|
|
|
try {
|
|
|
SPUtils.getInstance().put("magDoorSwitch",1);
|
|
|
+ SPUtils.getInstance().put("clearWight",1);
|
|
|
+ SerialPortUtil.getInstance().getWeightDevice().weightClear();//若关闭,称重清零
|
|
|
SerialPortUtil.getInstance().getOtherDevice().openLock();
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
| xqd
@@ -2105,6 +2129,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
if(readTime()==3){
|
|
|
restartApp();
|
|
|
+ restartAndroid();
|
|
|
}
|
|
|
}
|
|
|
};
|
| xqd
@@ -2115,18 +2140,19 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
publish();
|
|
|
openLight();
|
|
|
-// Integer networkInt=netWorkInfo();
|
|
|
-// if(networkInt==0) {
|
|
|
+ Integer networkInt=netWorkInfo();
|
|
|
+ if(networkInt==0) {
|
|
|
// restartApp();
|
|
|
-// }
|
|
|
+ restartAndroid();
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
- timer.schedule(task1,600000,1800000);
|
|
|
+ timer.schedule(task1,1800000,3600000);
|
|
|
|
|
|
}
|
|
|
private void publishRepeat(){
|
|
|
Integer currentTemperature= SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
- Integer magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();
|
|
|
+// Integer magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//门磁安装问题,不需要判断意外开门了
|
|
|
Integer queryCurrent=SerialPortUtil.getInstance().getOtherDevice().queryCurrent();
|
|
|
if(queryCurrent==1){
|
|
|
int num=SPUtils.getInstance().getInt("ClampHandNum",0);
|
| xqd
@@ -2136,7 +2162,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
if(currentTemperature>60){
|
|
|
SPUtils.getInstance().put("RunningState",2);//温度过高
|
|
|
Log.i(TAG,"温度过高");
|
|
|
- Integer networkInt=netWorkInfo();
|
|
|
+// Integer networkInt=netWorkInfo();
|
|
|
// if(networkInt!=0){
|
|
|
// reportProperty();
|
|
|
//短信通知
|
| xqd
@@ -2150,13 +2176,13 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().closeFan();//打开风扇
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
|
}
|
|
|
- if(magDoorSwitch==1){
|
|
|
+ /*if(magDoorSwitch==1){
|
|
|
if(SPUtils.getInstance().getInt("magDoorSwitch")==0){
|
|
|
SPUtils.getInstance().put("RunningState",3);
|
|
|
Log.i(TAG,"收运门意外打开");
|
|
|
SendSmsResponse("收运门意外打开");
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
}
|
|
|
public int readTime(){
|
| xqd
@@ -2171,10 +2197,15 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
if(readTime()>18||readTime()<2){
|
|
|
Log.i("night","开灯");
|
|
|
SerialPortUtil.getInstance().getOtherDevice().openLight1();
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().openLight2();
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().openLight3();
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().openLight4();
|
|
|
} else {
|
|
|
-
|
|
|
Log.i("day","关灯");
|
|
|
SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().closeLight2();
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().closeLight3();
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().closeLight4();
|
|
|
if(readTime()==3){
|
|
|
restartApp();
|
|
|
// restartAndroid();
|
| xqd
@@ -2183,7 +2214,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void SendSmsResponse(String event){
|
|
|
+ public static void SendSmsResponse(String event){//
|
|
|
if(event.equals("温度超声波失灵")){
|
|
|
reportDeviceEvent("errorEvent","温度超声波失灵",2);
|
|
|
Log.i("警告","发送"+event);
|