Bladeren bron

清零问题解决

DESKTOP-SADJPBG\47462 5 jaren geleden
bovenliggende
commit
0d8a3af337

+ 9 - 3
app/src/main/java/com/siwei/recyclebox/application/AppApplication.java

xqd
@@ -171,15 +171,21 @@ public class AppApplication extends BaseApplication implements CustomActivityOnC
          *   调用动态注册接口去获取deviceSecret
          */
         DeviceInfo myDeviceInfo = new DeviceInfo();
-        myDeviceInfo.productKey = "a1EtqHmfpNk";
-        myDeviceInfo.productSecret = "x6wHbrbXUMFYtvLl";
+        myDeviceInfo.productKey = "a1EtqHmfpNk";//正式服
+//        myDeviceInfo.productKey = "a13H8L6bDyf";//测试服
+//
+        myDeviceInfo.productSecret = "x6wHbrbXUMFYtvLl";//正式服
+//        myDeviceInfo.productSecret = "Nc4Y4KsjofejCy27";//测试服
+
         System.out.println(MainViewModel.getDeviceId(this)+"----------------------------+");
         myDeviceInfo.deviceName = MainViewModel.getDeviceId(this);
         Log.i("IMEI=",MainViewModel.getDeviceId(this));
         SPUtils.getInstance().put("IMEI",MainViewModel.getDeviceId(this));
 //        myDeviceInfo.deviceName="123456";
+
+//        String secret = SPUtils.getInstance().getString("deviceSecret3");//读
         String secret = SPUtils.getInstance().getString("deviceSecret2");//读
-//        String secret ="";
+//        String secret ="WMClVkIJipSunIY4fOSd2Be3xo42TfVs";
         Log.i(TAG,"secret=="+secret);
 
         if(secret != null &&  !secret.equals("")){

+ 2 - 1
app/src/main/java/com/siwei/recyclebox/deviceUtils/OtherDevice.java

xqd xqd
@@ -208,7 +208,7 @@ public class OtherDevice extends BaseDeviceEntity {
 
     public void setPower(){
         try {
-            byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x02, 0x25, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
+            byte[] setPower = new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0A, 0x01, 0x66, 0x0A, 0x03, 0x60, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
             port.write(setPower, 500);
             byte[] response = new byte[12];
             port.read(response,500);
@@ -453,6 +453,7 @@ public class OtherDevice extends BaseDeviceEntity {
      * */
     public void openLight1(){
         try{
+            //AA BB 0D 01 66 01 01 FF FF FF CC DD
             byte[] bytes=new byte[]{(byte) 0xAA, (byte) 0xBB, 0x0D, 0x01, 0x66, 0x01, 0x01, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xCC, (byte) 0xDD};
             port.write(bytes,200);
             byte[] response=new byte[12];

+ 72 - 41
app/src/main/java/com/siwei/recyclebox/ui/main/MainViewModel.java

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd 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);
@@ -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() {
@@ -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
@@ -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,"欢迎使用智能回收箱");
@@ -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();
@@ -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
@@ -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() {
@@ -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;
@@ -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) {
@@ -1238,7 +1252,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
-                }
+//                }
             }
         });
            thread.start();
@@ -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){
@@ -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);
@@ -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);
@@ -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
@@ -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) {
@@ -1563,11 +1580,11 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
                         public void run() {
                             publish();
                         }
-                    },100000);
+                    },1000000);
 
                 }
             });
-        }
+//        }
 
     }
 
@@ -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);// 响应客户端
@@ -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
@@ -2105,6 +2129,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
             public void run() {
                 if(readTime()==3){
                     restartApp();
+                    restartAndroid();
                 }
             }
         };
@@ -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);
@@ -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();
                 //短信通知
@@ -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(){
@@ -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();
@@ -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);

+ 2 - 2
config.gradle

xqd
@@ -7,8 +7,8 @@ ext {
             minSdkVersion    : 21,
             targetSdkVersion : 25,
 
-            versionCode      : 1,
-            versionName      : "1.0",
+            versionCode      : 5,
+            versionName      : "1.5",
     ]
     //version配置
     versions = [