| xqd
@@ -1,10 +1,14 @@
|
|
|
package com.siwei.recyclebox.ui.main;
|
|
|
|
|
|
import android.Manifest;
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.annotation.TargetApi;
|
|
|
import android.app.ActivityManager;
|
|
|
import android.app.AlarmManager;
|
|
|
import android.app.Application;
|
|
|
import android.app.PendingIntent;
|
|
|
+import android.app.job.JobInfo;
|
|
|
+import android.app.job.JobScheduler;
|
|
|
import android.bluetooth.BluetoothAdapter;
|
|
|
import android.bluetooth.BluetoothDevice;
|
|
|
import android.bluetooth.BluetoothGatt;
|
| xqd
@@ -19,6 +23,7 @@ import android.bluetooth.le.AdvertiseData;
|
|
|
import android.bluetooth.le.AdvertiseSettings;
|
|
|
import android.bluetooth.le.BluetoothLeAdvertiser;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
+import android.content.ComponentName;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.PackageManager;
|
| xqd
@@ -125,35 +130,37 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
public void onCreate(){
|
|
|
super.onCreate();
|
|
|
- Intent service = new Intent(getApplication(), MyService.class);
|
|
|
- getApplication().startService(service);//打开服务,把程序写在服务里不容易被系统kill
|
|
|
- mLocationUtils = LocationUtils.getInstance();
|
|
|
- Log.i(TAG,"定位--------------------");
|
|
|
- mLocationUtils.startLocationInfo();
|
|
|
- mLocationUtils.onCreate(new LocationUtils.LocationListener() {
|
|
|
- @Override
|
|
|
- public void locationSuccess(MapLocationInfo mapLocationInfo, String message) {
|
|
|
- mMapLocationInfo = mapLocationInfo;
|
|
|
- Log.i("定位: ","" + message);
|
|
|
- Log.i(TAG,"定位ok");
|
|
|
- Log.i(TAG,mMapLocationInfo.toString());
|
|
|
- Log.i(TAG,"纬度"+mMapLocationInfo.getLatitude()+"经度"+mMapLocationInfo.getLongitude());
|
|
|
- }
|
|
|
- @Override
|
|
|
- public void locationFail(String message) {
|
|
|
- Log.i("定位: ","" + message);
|
|
|
- }
|
|
|
- });
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- mLocationUtils.stopLocationClient();
|
|
|
- }
|
|
|
- },5000);
|
|
|
+
|
|
|
+// Intent service = new Intent(getApplication(), MyService.class);
|
|
|
+// getApplication().startService(service);//打开服务,把程序写在服务里不容易被系统kill
|
|
|
+
|
|
|
+// mLocationUtils = LocationUtils.getInstance();
|
|
|
+// Log.i(TAG,"定位--------------------");
|
|
|
+// mLocationUtils.startLocationInfo();
|
|
|
+// mLocationUtils.onCreate(new LocationUtils.LocationListener() {
|
|
|
+// @Override
|
|
|
+// public void locationSuccess(MapLocationInfo mapLocationInfo, String message) {
|
|
|
+// mMapLocationInfo = mapLocationInfo;
|
|
|
+// Log.i("定位: ","" + message);
|
|
|
+// Log.i(TAG,"定位ok");
|
|
|
+// Log.i(TAG,mMapLocationInfo.toString());
|
|
|
+// Log.i(TAG,"纬度"+mMapLocationInfo.getLatitude()+"经度"+mMapLocationInfo.getLongitude());
|
|
|
+// }
|
|
|
+// @Override
|
|
|
+// public void locationFail(String message) {
|
|
|
+// Log.i("定位: ","" + message);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// mHandler.postDelayed(new Runnable() {
|
|
|
+// @Override
|
|
|
+// public void run() {
|
|
|
+// mLocationUtils.stopLocationClient();
|
|
|
+// }
|
|
|
+// },5000);
|
|
|
|
|
|
MainViewModel.context = getApplication();
|
|
|
SPUtils.getInstance().put("RunningState",0);//设备运行状态
|
|
|
- SPUtils.getInstance().put("magDoorSwitch","0");//门磁状态
|
|
|
+ SPUtils.getInstance().put("magDoorSwitch",0);//门磁状态
|
|
|
|
|
|
BatteryManager batteryManager = (BatteryManager)getSystemService(BATTERY_SERVICE);//电量管理
|
|
|
int battery = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);//查询电量值
|
| xqd
@@ -172,9 +179,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public ObservableField<String> textIMEI = new ObservableField<>();//imei显示
|
|
|
public ObservableField<String> textqueryCurrentData = new ObservableField<>();//电流过大查询显示
|
|
|
|
|
|
-// public void startLocation(){
|
|
|
-// mLocationUtils.startLocationInfo();
|
|
|
-// }
|
|
|
+
|
|
|
/*
|
|
|
* 按钮模拟指令
|
|
|
* */
|
| xqd
@@ -224,7 +229,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- int a=1;
|
|
|
+ int a=2;
|
|
|
public View.OnClickListener btnClickOpenLight1234 = new View.OnClickListener() {
|
|
|
//打开关闭灯4按钮 开灯1
|
|
|
@Override
|
| xqd
@@ -433,6 +438,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
try {
|
|
|
sleep(1000);
|
|
|
numInt++;
|
|
|
+ Log.i(TAG,numInt+"秒");
|
|
|
if(SPUtils.getInstance().getString("RodSwitch").equals("0")){//判断是否已经关门
|
|
|
break;
|
|
|
}
|
| xqd
@@ -461,40 +467,53 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
|
|
|
int stopValue=0;
|
|
|
public void repeatRod(){
|
|
|
- //循环开门推拉杆
|
|
|
- stopValue=1;
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().pullRod();
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().pushRod();
|
|
|
- }
|
|
|
- },60000);
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
+ Thread thread=new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- repeatRod();
|
|
|
+ //循环开门推拉杆
|
|
|
+ stopValue=1;
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().pullRod();
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().pushRod();
|
|
|
+ }
|
|
|
+ },60000);
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ repeatRod();
|
|
|
+ }
|
|
|
+ },120000);
|
|
|
}
|
|
|
- },120000);
|
|
|
+ });
|
|
|
+ thread.start();
|
|
|
+
|
|
|
};
|
|
|
int stopValue2=0;
|
|
|
public void repeatLock(){
|
|
|
- //循环开关锁
|
|
|
- stopValue2=1;
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().openLock();
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
+ Thread thread=new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().closeLock();
|
|
|
- }
|
|
|
- },7000);
|
|
|
+ //循环开关锁
|
|
|
+ stopValue2 = 1;
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().openLock();
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().closeLock();
|
|
|
+ }
|
|
|
+ }, 7000);
|
|
|
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- repeatLock();
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ repeatLock();
|
|
|
+ }
|
|
|
+ }, 40000);
|
|
|
}
|
|
|
- },40000);
|
|
|
+ });
|
|
|
+ thread.start();
|
|
|
};
|
|
|
public View.OnClickListener btnClickRodRepeat = new View.OnClickListener() {
|
|
|
//循环开门按钮
|
| xqd
@@ -502,6 +521,13 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void onClick(View view) {
|
|
|
System.out.println("btnClickRodRepeat");
|
|
|
if(stopValue==0){
|
|
|
+// Thread thread=new Thread(new Runnable() {
|
|
|
+// @Override
|
|
|
+// public void run() {
|
|
|
+// repeatRod();
|
|
|
+// }
|
|
|
+// });
|
|
|
+// thread.start();
|
|
|
repeatRod();
|
|
|
}
|
|
|
|
| xqd
@@ -513,6 +539,13 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void onClick(View view) {
|
|
|
System.out.println("btnClickRodRepeat");
|
|
|
if(stopValue2==0){
|
|
|
+// Thread thread=new Thread(new Runnable() {
|
|
|
+// @Override
|
|
|
+// public void run() {
|
|
|
+// repeatLock();
|
|
|
+// }
|
|
|
+// });
|
|
|
+// thread.start();
|
|
|
repeatLock();
|
|
|
}
|
|
|
}
|
| xqd
@@ -770,8 +803,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
byte[] dataBytes = (byte[])aMessage.getData();
|
|
|
|
|
|
System.out.println(new String(dataBytes));
|
|
|
- if (topic.endsWith("thing/event/property/post_reply")){ //推送设备属性的回包。
|
|
|
- }
|
|
|
+// if (topic.endsWith("thing/event/property/post_reply")){ //推送设备属性的回包。
|
|
|
+// }
|
|
|
if(topic.endsWith("thing/service/restartApp")){
|
|
|
restartApp();//重启app
|
|
|
}
|
| xqd
@@ -828,7 +861,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
if(topic.endsWith("thing/service/RemoteAgentOpen")){//开收运门
|
|
|
Log.i(TAG,"开运收门");
|
|
|
- SPUtils.getInstance().put("magDoorSwitch","1");
|
|
|
+ SPUtils.getInstance().put("magDoorSwitch",1);
|
|
|
short i = 1;
|
|
|
try {
|
|
|
SerialPortUtil.getInstance().getOtherDevice().openLock();
|
| xqd
@@ -860,7 +893,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
try{
|
|
|
long curr=System.currentTimeMillis();
|
|
|
while(System.currentTimeMillis()-curr<300000) {
|
|
|
- Thread.sleep(2000);
|
|
|
+ Thread.sleep(10000);
|
|
|
Integer magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//通过门磁感应判断收运门是否关闭
|
|
|
if(magDoorSwitch==0){
|
|
|
SerialPortUtil.getInstance().getWeightDevice().weightClear();//若关闭,称重清零
|
| xqd
@@ -871,7 +904,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
reportProperty();
|
|
|
}
|
|
|
},3000);
|
|
|
- SPUtils.getInstance().put("magDoorSwitch","0");
|
|
|
+ SPUtils.getInstance().put("magDoorSwitch",0);
|
|
|
break;
|
|
|
}
|
|
|
}
|
| xqd
@@ -891,7 +924,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
if(topic.endsWith("thing/service/RemoteAgentClose")) {//关收运门
|
|
|
Log.i(TAG, "关运收门");
|
|
|
- SPUtils.getInstance().put("magDoorSwitch", "0");
|
|
|
+ SPUtils.getInstance().put("magDoorSwitch", 0);
|
|
|
SerialPortUtil.getInstance().getWeightDevice().weightClear();
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().clearWeight();
|
|
|
mHandler.postDelayed(new Runnable() {
|
| xqd
@@ -1005,14 +1038,14 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- if(topic.endsWith("thing/service/RepeatRod")){//开灯
|
|
|
+ if(topic.endsWith("thing/service/RepeatRod")){//循环推杆
|
|
|
try {
|
|
|
repeatRod();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- if(topic.endsWith("thing/service/RepeatLock")){//关灯
|
|
|
+ if(topic.endsWith("thing/service/RepeatLock")){//循环开锁
|
|
|
try {
|
|
|
repeatLock();
|
|
|
} catch (Exception e) {
|
| xqd
@@ -1094,112 +1127,117 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
// publishRepeat();
|
|
|
Log.i(TAG,"上报数据");
|
|
|
- try{
|
|
|
- double longitude=107.31;
|
|
|
- double latitude=23.16;
|
|
|
- if(mMapLocationInfo!=null){
|
|
|
- longitude=mMapLocationInfo.getLongitude();
|
|
|
- latitude=mMapLocationInfo.getLatitude();
|
|
|
- Log.i(TAG,mMapLocationInfo.toString()+"--地址:"+mMapLocationInfo.getAddress());
|
|
|
+ Integer networkNum=netWorkInfo();
|
|
|
+ if(networkNum!=0) {
|
|
|
+ try {
|
|
|
+ double longitude = 107.31;
|
|
|
+ double latitude = 23.16;
|
|
|
+ if (mMapLocationInfo != null) {
|
|
|
+ longitude = mMapLocationInfo.getLongitude();
|
|
|
+ latitude = mMapLocationInfo.getLatitude();
|
|
|
+ Log.i(TAG, mMapLocationInfo.toString() + "--地址:" + mMapLocationInfo.getAddress());
|
|
|
|
|
|
- }
|
|
|
- Integer weight = 0;
|
|
|
- Log.i("num=1","读一次称重");
|
|
|
- weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();//读称重
|
|
|
- if(weight==1){
|
|
|
+ }
|
|
|
+ Integer weight = 0;
|
|
|
+ Log.i("num=1", "读一次称重");
|
|
|
weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();//读称重
|
|
|
- }
|
|
|
+ if (weight == 1) {
|
|
|
+ weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();//读称重
|
|
|
+ }
|
|
|
// weight=SerialPortUtil.getInstance().getOtherDevice().readWeight();//称重
|
|
|
- Integer capacity=0;
|
|
|
- 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();//温度
|
|
|
- }
|
|
|
- Log.i(TAG,"----------------------------------------");
|
|
|
+ Integer capacity = 0;
|
|
|
+ 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();//温度
|
|
|
+ }
|
|
|
+ Log.i(TAG, "----------------------------------------");
|
|
|
|
|
|
- Map<String, ValueWrapper> locationMap = new HashMap<>();
|
|
|
- Map<String, ValueWrapper> reportData = new HashMap<>();
|
|
|
+ Map<String, ValueWrapper> locationMap = new HashMap<>();
|
|
|
+ Map<String, ValueWrapper> reportData = new HashMap<>();
|
|
|
// SPUtils.getInstance().put("RodNumber","4721");
|
|
|
- String rodNumberStr= SPUtils.getInstance().getString("RodNumber");
|
|
|
- if(rodNumberStr.equals("")){
|
|
|
- rodNumberStr="0";
|
|
|
- }
|
|
|
- int rodNumberInt=Integer.parseInt(rodNumberStr);
|
|
|
- String rodSwitchStr=SPUtils.getInstance().getString("RodSwitch");
|
|
|
- if(rodSwitchStr.equals("")){
|
|
|
- rodSwitchStr="0";
|
|
|
- }
|
|
|
- int rodSwitchInt=Integer.parseInt(rodSwitchStr);
|
|
|
+ String rodNumberStr = SPUtils.getInstance().getString("RodNumber");
|
|
|
+ if (rodNumberStr.equals("")) {
|
|
|
+ rodNumberStr = "0";
|
|
|
+ }
|
|
|
+ int rodNumberInt = Integer.parseInt(rodNumberStr);
|
|
|
+ String rodSwitchStr = SPUtils.getInstance().getString("RodSwitch");
|
|
|
+ if (rodSwitchStr.equals("")) {
|
|
|
+ rodSwitchStr = "0";
|
|
|
+ }
|
|
|
+ int rodSwitchInt = Integer.parseInt(rodSwitchStr);
|
|
|
// SPUtils.getInstance().put("LockNumber","7562");
|
|
|
- String lockNumberStr=SPUtils.getInstance().getString("LockNumber");
|
|
|
- if(lockNumberStr.equals("")){
|
|
|
- lockNumberStr="0";
|
|
|
- }
|
|
|
- int lockNumberInt=Integer.parseInt(lockNumberStr);
|
|
|
+ String lockNumberStr = SPUtils.getInstance().getString("LockNumber");
|
|
|
+ if (lockNumberStr.equals("")) {
|
|
|
+ lockNumberStr = "0";
|
|
|
+ }
|
|
|
+ int lockNumberInt = Integer.parseInt(lockNumberStr);
|
|
|
+ int clampHandNum = SPUtils.getInstance().getInt("ClampHandNum", 0);
|
|
|
+ int runningStateInt = SPUtils.getInstance().getInt("RunningState");
|
|
|
+ reportData.put("RodOpenNum", new ValueWrapper.IntValueWrapper(rodNumberInt));
|
|
|
+ reportData.put("LockOpenNum", new ValueWrapper.IntValueWrapper(lockNumberInt));
|
|
|
+
|
|
|
+ reportData.put("ClampHandNum", new ValueWrapper.IntValueWrapper(clampHandNum));
|
|
|
|
|
|
- int runningStateInt=SPUtils.getInstance().getInt("RunningState");
|
|
|
- reportData.put("RodOpenNum",new ValueWrapper.IntValueWrapper(rodNumberInt));
|
|
|
- reportData.put("LockOpenNum",new ValueWrapper.IntValueWrapper(lockNumberInt));
|
|
|
+ reportData.put("Weight", new ValueWrapper.IntValueWrapper(weight)); //重量 单位 --- 克
|
|
|
+ reportData.put("CurrentTemperature", new ValueWrapper.IntValueWrapper(currentTemperature));//温度,范围正负 ,精确到小数点后2位
|
|
|
+ reportData.put("RestCapacity", new ValueWrapper.IntValueWrapper(capacity)); //距离值,单位mm
|
|
|
+ reportData.put("MagDoorSwitch", new ValueWrapper.BooleanValueWrapper(magDoorSwitch));//门磁 0-关闭状态 1-开门状态
|
|
|
|
|
|
- reportData.put("Weight", new ValueWrapper.IntValueWrapper(weight)); //重量 单位 --- 克
|
|
|
- reportData.put("CurrentTemperature", new ValueWrapper.IntValueWrapper(currentTemperature));//温度,范围正负 ,精确到小数点后2位
|
|
|
- reportData.put("RestCapacity", new ValueWrapper.IntValueWrapper(capacity)); //距离值,单位mm
|
|
|
- reportData.put("MagDoorSwitch", new ValueWrapper.BooleanValueWrapper(magDoorSwitch));//门磁 0-关闭状态 1-开门状态
|
|
|
+ reportData.put("LockSwitch", new ValueWrapper.BooleanValueWrapper(lockSwitch)); //锁开关状态:0-关锁 1-解锁 解锁后3s就关锁
|
|
|
+ reportData.put("RodSwitch", new ValueWrapper.BooleanValueWrapper(rodSwitchInt)); //推杆状态:0-关闭状态 1-打开 开门
|
|
|
|
|
|
- reportData.put("LockSwitch", new ValueWrapper.BooleanValueWrapper(lockSwitch)); //锁开关状态:0-关锁 1-解锁 解锁后3s就关锁
|
|
|
- reportData.put("RodSwitch", new ValueWrapper.BooleanValueWrapper(rodSwitchInt)); //推杆状态:0-关闭状态 1-打开 开门
|
|
|
|
|
|
- reportData.put("RunningState", new ValueWrapper.BooleanValueWrapper(runningStateInt)); // 0正常
|
|
|
+ reportData.put("RunningState", new ValueWrapper.BooleanValueWrapper(runningStateInt)); // 0正常
|
|
|
// 1设备故障 未识别到称重设备 报警 未识别到杆、门磁、锁、温度、红外、超声波设备 报警
|
|
|
// 2温度过高 报警
|
|
|
// 3收运门意外打开报警
|
|
|
// 4称重失灵报警 错误一次就再读一次 超过两次读取错误就报警
|
|
|
// 5温度和超声波失灵警告 失灵显示的000000000
|
|
|
|
|
|
- System.out.println(IMEI+"DeviceId");
|
|
|
- reportData.put("IMEI", new ValueWrapper.StringValueWrapper(IMEI));
|
|
|
- locationMap.put("longitude", new ValueWrapper.DoubleValueWrapper(longitude));
|
|
|
- locationMap.put("latitude", new ValueWrapper.DoubleValueWrapper(latitude));
|
|
|
- locationMap.put("altitude", new ValueWrapper.DoubleValueWrapper(523.1));
|
|
|
- reportData.put("GeoLocation", new ValueWrapper.StructValueWrapper(locationMap)); //
|
|
|
-
|
|
|
- int queryCurrent=SPUtils.getInstance().getInt("queryCurrent");
|
|
|
- Log.i(TAG, "称重" + weight.toString() + "距离" + capacity.toString() + "温度" + currentTemperature);
|
|
|
- textReportData.set("称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " +
|
|
|
- currentTemperature+"度;门磁 "+magDoorSwitch+";杆状态 "+rodSwitchInt+";锁状态 "+lockSwitch+";杆开门次数 "+rodNumberInt+";开锁次数 "+lockNumberInt+";被夹次数"+queryCurrent+";运行状态"+runningStateInt
|
|
|
- );
|
|
|
-
|
|
|
- String text = "称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " + currentTemperature+"度;门磁 "+magDoorSwitch+";杆状态 "+
|
|
|
- rodSwitchInt+";锁状态 "+lockSwitch+";杆开门次数 "+rodNumberInt+";开锁次数 "+lockNumberInt+";被夹次数"+queryCurrent+"------------------------------";
|
|
|
- Log.i(TAG, text + "=textReportData---------------------");
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- LinkKit.getInstance().getDeviceThing().thingPropertyPost(reportData, new IPublishResourceListener() {
|
|
|
- @Override
|
|
|
- public void onSuccess(String s, Object o) {
|
|
|
- Log.d("", "onSuccess() called with: s = [" + s + "], o = [" + o + "]");
|
|
|
- SPUtils.getInstance().put("RunningState",0);
|
|
|
- }
|
|
|
- @Override
|
|
|
- public void onError(String s, AError aError) {
|
|
|
- Log.e("Main", s);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- },200);
|
|
|
+ System.out.println(IMEI + "DeviceId");
|
|
|
+ reportData.put("IMEI", new ValueWrapper.StringValueWrapper(IMEI));
|
|
|
+ locationMap.put("longitude", new ValueWrapper.DoubleValueWrapper(longitude));
|
|
|
+ locationMap.put("latitude", new ValueWrapper.DoubleValueWrapper(latitude));
|
|
|
+ locationMap.put("altitude", new ValueWrapper.DoubleValueWrapper(523.1));
|
|
|
+ reportData.put("GeoLocation", new ValueWrapper.StructValueWrapper(locationMap)); //
|
|
|
+
|
|
|
+ Log.i(TAG, "称重" + weight.toString() + "距离" + capacity.toString() + "温度" + currentTemperature);
|
|
|
+ textReportData.set("称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " +
|
|
|
+ currentTemperature + "度;门磁 " + magDoorSwitch + ";杆状态 " + rodSwitchInt + ";锁状态 " + lockSwitch + ";杆开门次数 " + rodNumberInt + ";开锁次数 " + lockNumberInt + ";被夹次数" + clampHandNum + ";运行状态" + runningStateInt
|
|
|
+ );
|
|
|
+
|
|
|
+ String text = "称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " + currentTemperature + "度;门磁 " + magDoorSwitch + ";杆状态 " +
|
|
|
+ rodSwitchInt + ";锁状态 " + lockSwitch + ";杆开门次数 " + rodNumberInt + ";开锁次数 " + lockNumberInt + ";被夹次数" + clampHandNum + "------------------------------";
|
|
|
+ Log.i(TAG, text + "=textReportData---------------------");
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ LinkKit.getInstance().getDeviceThing().thingPropertyPost(reportData, new IPublishResourceListener() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String s, Object o) {
|
|
|
+ Log.d("", "onSuccess() called with: s = [" + s + "], o = [" + o + "]");
|
|
|
+ SPUtils.getInstance().put("RunningState", 0);
|
|
|
+ }
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void onError(String s, AError aError) {
|
|
|
+ Log.e("Main", s);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, 200);
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
thread.start();
|
| xqd
@@ -1337,7 +1375,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
//设备事件上报
|
|
|
public static void reportDeviceEvent(String identifier, String event, int num){
|
|
|
- /* HashMap<String, ValueWrapper> hashMap = new HashMap<>();
|
|
|
+ HashMap<String, ValueWrapper> hashMap = new HashMap<>();
|
|
|
// TODO 用户根据实际情况设置
|
|
|
// hashMap.put("ErrorCode", new ValueWrapper.IntValueWrapper(0));
|
|
|
if(num==1){
|
| xqd
@@ -1347,17 +1385,22 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
OutputParams params = new OutputParams(hashMap);
|
|
|
Log.i("设备故障",identifier+"====="+params);
|
|
|
+ Integer networkNum=netWorkInfoStatic();
|
|
|
+ if(networkNum!=0){
|
|
|
+ LinkKit.getInstance().getDeviceThing().thingEventPost(identifier, params, new IPublishResourceListener() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String resId, Object o) { // 事件上报成功
|
|
|
+ Log.i("事件上报","上报成功");
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onError(String resId, AError aError) { // 事件上报失败
|
|
|
+ Log.i("事件上报","上报失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ Log.i("上报","失败,没有网络");
|
|
|
+ }
|
|
|
|
|
|
- LinkKit.getInstance().getDeviceThing().thingEventPost(identifier, params, new IPublishResourceListener() {
|
|
|
- @Override
|
|
|
- public void onSuccess(String resId, Object o) { // 事件上报成功
|
|
|
- Log.i("事件上报","上报成功");
|
|
|
- }
|
|
|
- @Override
|
|
|
- public void onError(String resId, AError aError) { // 事件上报失败
|
|
|
- Log.i("事件上报","上报失败");
|
|
|
- }
|
|
|
- });*/
|
|
|
}
|
|
|
private void getDeviceProperty(String identifier){
|
|
|
// 根据 identifier 获取当前物模型中该属性的值
|
| xqd
@@ -1491,6 +1534,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
publishRequest.payloadObj = "{\"id\":"+ publishRequest.msgId+", \"version\":\"1.0\",\"time\":" + System.currentTimeMillis() + "}";
|
|
|
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
@@ -1498,9 +1542,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- if(networkInt!=0){
|
|
|
- reportProperty();
|
|
|
- }
|
|
|
+ reportProperty();
|
|
|
}
|
|
|
},5000);
|
|
|
|
| xqd
@@ -1524,6 +1566,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
|
|
|
}
|
|
|
});
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
| xqd
@@ -1656,18 +1700,19 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
if(timeInt==0){
|
|
|
timeInt=82;
|
|
|
}
|
|
|
- int finalTimeInt = timeInt;
|
|
|
+ int finalTimeInt = timeInt*1000+5000;
|
|
|
Log.i("计时",""+finalTimeInt);
|
|
|
Thread thread=new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
int numInt=0;
|
|
|
long curr=System.currentTimeMillis();
|
|
|
- while(System.currentTimeMillis()-curr<finalTimeInt+5){
|
|
|
+ while(System.currentTimeMillis()-curr<finalTimeInt){
|
|
|
try {
|
|
|
sleep(1000);
|
|
|
numInt++;
|
|
|
- Log.i("倒计时时间",numInt+"");
|
|
|
+
|
|
|
+ Log.i("倒计时时间",numInt+"---"+SPUtils.getInstance().getString("RodSwitch"));
|
|
|
if(SPUtils.getInstance().getString("RodSwitch").equals("0")){
|
|
|
break;
|
|
|
}
|
| xqd
@@ -1683,7 +1728,6 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
});
|
|
|
thread.start();
|
| xqd
@@ -1691,7 +1735,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
if(data[1].equals("22")){
|
|
|
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, requestBytes);// 响应客户端
|
|
|
try {
|
|
|
- SPUtils.getInstance().put("magDoorSwitch","1");
|
|
|
+ SPUtils.getInstance().put("magDoorSwitch",1);
|
|
|
SerialPortUtil.getInstance().getOtherDevice().openLock();
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
| xqd
@@ -1720,12 +1764,12 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
try{
|
|
|
long curr=System.currentTimeMillis();
|
|
|
- while(System.currentTimeMillis()-curr<3000000) {
|
|
|
- Thread.sleep(1000);
|
|
|
+ while(System.currentTimeMillis()-curr<600000) {
|
|
|
+ Thread.sleep(10000);
|
|
|
Integer magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//通过门磁感应判断收运门是否关闭
|
|
|
if(magDoorSwitch==0){
|
|
|
SerialPortUtil.getInstance().getWeightDevice().weightClear();//若关闭,称重清零
|
|
|
- SPUtils.getInstance().put("magDoorSwitch","0");
|
|
|
+ SPUtils.getInstance().put("magDoorSwitch",0);
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().clearWeight();
|
|
|
String response=reportDataMethodEncrypt();
|
|
|
SPUtils.getInstance().put("response",response);
|
| xqd
@@ -1758,7 +1802,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
if(requestStr.equals("close2")){
|
|
|
Log.i(TAG,"+++++收运门关");
|
|
|
SerialPortUtil.getInstance().getWeightDevice().weightClear();//若关闭,称重清零
|
|
|
- SPUtils.getInstance().put("magDoorSwitch","0");
|
|
|
+ SPUtils.getInstance().put("magDoorSwitch",0);
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().clearWeight();
|
|
|
SPUtils.getInstance().put("type","close");
|
|
|
String response=reportDataMethodEncrypt();
|
| xqd
@@ -1877,15 +1921,15 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
private List<UsbSerialPort> mEntries = new ArrayList<UsbSerialPort>();
|
|
|
private BroadcastReceiver mUsbReceiver;
|
|
|
private UsbManager mUsbManager;
|
|
|
- UsbSerialPort port = null;
|
|
|
-
|
|
|
- public void closePort(){
|
|
|
- try {
|
|
|
- port.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
+// UsbSerialPort port = null;
|
|
|
+//
|
|
|
+// public void closePort(){
|
|
|
+// try {
|
|
|
+// port.close();
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
public static String getDeviceId(Context context) {
|
|
|
StringBuilder deviceId = new StringBuilder();
|
| xqd
@@ -1995,6 +2039,28 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 判断是否有网
|
|
|
+ * */
|
|
|
+ public static Integer netWorkInfoStatic(){
|
|
|
+ ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
+ NetworkInfo info = connectivity.getActiveNetworkInfo();
|
|
|
+ if(info != null && info.isAvailable()){
|
|
|
+ if (info.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
|
+ return 2;
|
|
|
+ } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
|
|
|
+//移动网络
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+//网络错误
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+//网络错误
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
/*
|
|
|
* 重启app方法
|
|
|
* */
|
| xqd
@@ -2022,73 +2088,70 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
|
|
|
public void repeatTask() {
|
|
|
Log.i("----------------------","ok");
|
|
|
-// task3 =new TimerTask(){
|
|
|
-// public void run(){
|
|
|
-// publishRepeat();
|
|
|
-// Log.i("Task","300秒循环");
|
|
|
-// }
|
|
|
-// };
|
|
|
-// timer.schedule(task3,60000,600000);
|
|
|
-// Calendar calendar = Calendar.getInstance();
|
|
|
-// calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
-// calendar.set(Calendar.HOUR_OF_DAY, 11);
|
|
|
-// calendar.set(Calendar.MINUTE, 26);
|
|
|
-// task2=new TimerTask() {
|
|
|
-// @Override
|
|
|
-// public void run() {
|
|
|
-// openLight();
|
|
|
-// }
|
|
|
-// };
|
|
|
-// timer.schedule(task2,0,1800000);
|
|
|
+ task3 =new TimerTask(){
|
|
|
+ public void run(){
|
|
|
+ publishRepeat();
|
|
|
+ Log.i("Task","300秒循环");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timer.schedule(task3,60000,600000);
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 11);
|
|
|
+ calendar.set(Calendar.MINUTE, 26);
|
|
|
+ task2=new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if(readTime()==3){
|
|
|
+ restartApp();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timer.schedule(task2,3300000,3300000);
|
|
|
|
|
|
task1=new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
publish();
|
|
|
+ openLight();
|
|
|
}
|
|
|
};
|
|
|
timer.schedule(task1,600000,1800000);
|
|
|
+
|
|
|
}
|
|
|
private void publishRepeat(){
|
|
|
Integer currentTemperature= SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
Integer magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();
|
|
|
Integer queryCurrent=SerialPortUtil.getInstance().getOtherDevice().queryCurrent();
|
|
|
if(queryCurrent==1){
|
|
|
- int num=SPUtils.getInstance().getInt("queryCurrent");
|
|
|
- SPUtils.getInstance().put("queryCurrent",num+1);//记录被夹次数
|
|
|
+ int num=SPUtils.getInstance().getInt("ClampHandNum",0);
|
|
|
+ SPUtils.getInstance().put("ClampHandNum",num+1);//记录被夹次数
|
|
|
SerialPortUtil.getInstance().getOtherDevice().clearCurrent();
|
|
|
}
|
|
|
if(currentTemperature>60){
|
|
|
SPUtils.getInstance().put("RunningState",2);//温度过高
|
|
|
Log.i(TAG,"温度过高");
|
|
|
Integer networkInt=netWorkInfo();
|
|
|
- if(networkInt!=0){
|
|
|
+// if(networkInt!=0){
|
|
|
// reportProperty();
|
|
|
//短信通知
|
|
|
SendSmsResponse("温度过高");
|
|
|
-
|
|
|
- }
|
|
|
+// }
|
|
|
}
|
|
|
if(currentTemperature>25){
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().openuFan();//打开风扇
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().openLight4();
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().openLight1();
|
|
|
}else{
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().closeFan();//打开风扇
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().closeLight4();
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
|
}
|
|
|
-
|
|
|
if(magDoorSwitch==1){
|
|
|
- if(SPUtils.getInstance().getString("magDoorSwitch").equals("0")){
|
|
|
+ if(SPUtils.getInstance().getInt("magDoorSwitch")==0){
|
|
|
SPUtils.getInstance().put("RunningState",3);
|
|
|
Log.i(TAG,"收运门意外打开");
|
|
|
SendSmsResponse("收运门意外打开");
|
|
|
}
|
|
|
}
|
|
|
-// if(currentTemperature<100&magDoorSwitch==0) {
|
|
|
-// SPUtils.getInstance().put("RunningState","0");
|
|
|
-// }
|
|
|
-// }
|
|
|
-// });
|
|
|
|
|
|
}
|
|
|
public int readTime(){
|
| xqd
@@ -2100,12 +2163,16 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
|
|
|
public void openLight(){
|
|
|
Log.i("d定时","ok");
|
|
|
- if(readTime()>18||readTime()<1){
|
|
|
+ if(readTime()>18||readTime()<2){
|
|
|
Log.i("night","开灯");
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().openLight4();
|
|
|
- }else {
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().openLight1();
|
|
|
+ } else {
|
|
|
+
|
|
|
Log.i("day","关灯");
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().closeLight4();
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
|
+ if(readTime()==3){
|
|
|
+ restartAndroid();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
| xqd
@@ -2119,43 +2186,15 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
Log.i("报警","发送"+event);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /*DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4FcFSGUX9ngzehwMMU6M", "SxG0xU9U7bqpCDoK0nMGo4pSXAdNHc");
|
|
|
- IAcsClient client = new DefaultAcsClient(profile);
|
|
|
- CommonRequest request = new CommonRequest();
|
|
|
- request.setMethod(MethodType.POST);
|
|
|
- request.setDomain("dysmsapi.aliyuncs.com");
|
|
|
- request.setVersion("2017-05-25");
|
|
|
- request.setAction("SendSms");
|
|
|
- request.putQueryParameter("RegionId", "cn-hangzhou");
|
|
|
- request.putQueryParameter("PhoneNumbers", "18116680579");
|
|
|
- request.putQueryParameter("SignName", "思维定制");
|
|
|
- request.putQueryParameter("TemplateCode", "SMS_185242509");
|
|
|
- JSONObject jsono=new JSONObject();
|
|
|
-// jsono.put("DeviceId", SPUtils.getInstance().getString("IMEI"));
|
|
|
- jsono.put("DeviceName", event);
|
|
|
-
|
|
|
- request.putQueryParameter("TemplateParam", jsono.toJSONString());
|
|
|
- try {
|
|
|
- CommonResponse response = client.getCommonResponse(request);
|
|
|
- System.out.println(response.getData());
|
|
|
- } catch (ClientException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }*/
|
|
|
- /* try {
|
|
|
- Response response = OkHttpUtils.post()
|
|
|
- .url("/api/v1/sendMessage/send")
|
|
|
- .addParams("code", event)
|
|
|
- .build().execute();
|
|
|
- if (response.isSuccessful()) {
|
|
|
- String jsonStr = response.body().string();
|
|
|
- Log.i("RESPONSE==", "JSONstr=" + jsonStr);
|
|
|
- } else {
|
|
|
- throw new IOException(response.message());
|
|
|
- }
|
|
|
- }catch (IOException e){
|
|
|
- e.printStackTrace();
|
|
|
- }*/
|
|
|
+ }
|
|
|
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
+ public void startJobScheduler() {
|
|
|
+ int jobId = 1;
|
|
|
+ @SuppressLint("JobSchedulerService") JobInfo.Builder jobInfo = new JobInfo.Builder(jobId, new ComponentName(getApplication(), MyService.class));
|
|
|
+ jobInfo.setPeriodic(10000);
|
|
|
+ jobInfo.setPersisted(true);
|
|
|
+ JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
|
|
|
+ jobScheduler.schedule(jobInfo.build());
|
|
|
}
|
|
|
|
|
|
}
|