| xqd
@@ -9,7 +9,6 @@ import android.app.PendingIntent;
|
|
|
import android.bluetooth.BluetoothAdapter;
|
|
|
import android.bluetooth.BluetoothDevice;
|
|
|
import android.bluetooth.BluetoothGatt;
|
|
|
-import android.bluetooth.BluetoothGattCallback;
|
|
|
import android.bluetooth.BluetoothGattCharacteristic;
|
|
|
import android.bluetooth.BluetoothGattDescriptor;
|
|
|
import android.bluetooth.BluetoothGattServer;
|
| xqd
@@ -23,43 +22,29 @@ import android.bluetooth.le.BluetoothLeAdvertiser;
|
|
|
import android.content.BroadcastReceiver;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
-import android.content.IntentFilter;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.content.res.AssetFileDescriptor;
|
|
|
import android.databinding.ObservableField;
|
|
|
-import android.hardware.usb.UsbDevice;
|
|
|
-import android.hardware.usb.UsbDeviceConnection;
|
|
|
import android.hardware.usb.UsbManager;
|
|
|
import android.media.MediaPlayer;
|
|
|
import android.net.ConnectivityManager;
|
|
|
import android.net.NetworkInfo;
|
|
|
-import android.net.Uri;
|
|
|
import android.net.wifi.WifiInfo;
|
|
|
import android.net.wifi.WifiManager;
|
|
|
import android.os.BatteryManager;
|
|
|
import android.os.Build;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.os.Environment;
|
|
|
import android.os.Handler;
|
|
|
-import android.os.Message;
|
|
|
import android.os.ParcelUuid;
|
|
|
-import android.os.SystemClock;
|
|
|
-import android.speech.tts.TextToSpeech;
|
|
|
-import android.speech.tts.TextToSpeechService;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.RequiresApi;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
-import android.support.v4.content.FileProvider;
|
|
|
-import android.support.v7.app.AppCompatActivity;
|
|
|
import android.telephony.TelephonyManager;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
-import android.widget.Toast;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.alink.dm.api.IOta;
|
|
|
-import com.aliyun.alink.dm.api.ResultCallback;
|
|
|
import com.aliyun.alink.linkkit.api.LinkKit;
|
|
|
import com.aliyun.alink.linksdk.cmp.connect.channel.MqttPublishRequest;
|
|
|
import com.aliyun.alink.linksdk.cmp.connect.channel.MqttRrpcRegisterRequest;
|
| xqd
@@ -69,35 +54,28 @@ import com.aliyun.alink.linksdk.cmp.core.base.ARequest;
|
|
|
import com.aliyun.alink.linksdk.cmp.core.base.AResponse;
|
|
|
import com.aliyun.alink.linksdk.cmp.core.base.ConnectState;
|
|
|
import com.aliyun.alink.linksdk.cmp.core.listener.IConnectNotifyListener;
|
|
|
-import com.aliyun.alink.linksdk.cmp.core.listener.IConnectRrpcHandle;
|
|
|
-import com.aliyun.alink.linksdk.cmp.core.listener.IConnectRrpcListener;
|
|
|
import com.aliyun.alink.linksdk.cmp.core.listener.IConnectSendListener;
|
|
|
import com.aliyun.alink.linksdk.cmp.core.listener.IConnectSubscribeListener;
|
|
|
import com.aliyun.alink.linksdk.tmp.api.OutputParams;
|
|
|
import com.aliyun.alink.linksdk.tmp.device.payload.ValueWrapper;
|
|
|
import com.aliyun.alink.linksdk.tmp.listener.IPublishResourceListener;
|
|
|
-import com.aliyun.alink.linksdk.tmp.listener.ITResRequestHandler;
|
|
|
-import com.aliyun.alink.linksdk.tmp.listener.ITResResponseCallback;
|
|
|
-import com.aliyun.alink.linksdk.tmp.utils.ErrorInfo;
|
|
|
import com.aliyun.alink.linksdk.tools.AError;
|
|
|
-import com.hoho.android.usbserial.driver.Ch34xSerialDriver;
|
|
|
-import com.hoho.android.usbserial.driver.ProlificSerialDriver;
|
|
|
-import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
|
|
+import com.aliyuncs.CommonRequest;
|
|
|
+import com.aliyuncs.CommonResponse;
|
|
|
+import com.aliyuncs.DefaultAcsClient;
|
|
|
+import com.aliyuncs.IAcsClient;
|
|
|
+import com.aliyuncs.exceptions.ClientException;
|
|
|
+import com.aliyuncs.http.MethodType;
|
|
|
+import com.aliyuncs.profile.DefaultProfile;
|
|
|
import com.hoho.android.usbserial.driver.UsbSerialPort;
|
|
|
-import com.hoho.android.usbserial.driver.UsbSerialProber;
|
|
|
-import com.hoho.android.usbserial.util.SerialInputOutputManager;
|
|
|
import com.siwei.recyclebox.BuildConfig;
|
|
|
import com.siwei.recyclebox.deviceUtils.SerialPortUtil;
|
|
|
-import com.siwei.recyclebox.deviceUtils.WeightDevice;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.DataOutputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.InputStreamReader;
|
|
|
-import java.nio.charset.Charset;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.Calendar;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Locale;
|
| xqd
@@ -106,54 +84,58 @@ import java.util.Spliterator;
|
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
|
import java.util.UUID;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
import me.goldze.mvvmhabit.base.BaseModel;
|
|
|
import me.goldze.mvvmhabit.base.BaseViewModel;
|
|
|
-import me.goldze.mvvmhabit.binding.command.BindingAction;
|
|
|
-import me.goldze.mvvmhabit.binding.command.BindingCommand;
|
|
|
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
|
|
|
-import me.goldze.mvvmhabit.http.ApiDisposableObserver;
|
|
|
+import me.goldze.mvvmhabit.crash.CaocConfig;
|
|
|
+import me.goldze.mvvmhabit.crash.CustomActivityOnCrash;
|
|
|
+import me.goldze.mvvmhabit.crash.DefaultErrorActivity;
|
|
|
import me.goldze.mvvmhabit.utils.SPUtils;
|
|
|
import me.goldze.mvvmhabit.utils.StringUtils;
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
+import okhttp3.Response;
|
|
|
import okio.ByteString;
|
|
|
import top.maybesix.xhlibrary.serialport.ComPortData;
|
|
|
import top.maybesix.xhlibrary.serialport.SerialPortHelper;
|
|
|
import top.maybesix.xhlibrary.util.HexStringUtils;
|
|
|
|
|
|
-import com.siwei.recyclebox.entity.DataEntity;
|
|
|
-import com.siwei.recyclebox.service.MyService;
|
|
|
import com.siwei.recyclebox.utils.DemoOne;
|
|
|
import com.siwei.recyclebox.utils.SilentInstall;
|
|
|
import com.siwei.recyclebox.utils.unZipFileDemo;
|
|
|
-import com.tencent.bugly.crashreport.CrashReport;
|
|
|
+import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
|
|
|
import static android.content.Context.BATTERY_SERVICE;
|
|
|
-import static android.content.Context.EUICC_SERVICE;
|
|
|
import static java.lang.Thread.sleep;
|
|
|
|
|
|
public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnSerialPortReceivedListener{
|
|
|
|
|
|
Integer lockSwitch=0;//锁的状态
|
|
|
private static Context context;//上下文
|
|
|
+ private final Timer timer=new Timer();
|
|
|
+ private TimerTask task1;
|
|
|
+ private TimerTask task2;
|
|
|
+ private TimerTask task3;
|
|
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
|
public void onCreate(){
|
|
|
super.onCreate();
|
|
|
- Intent service = new Intent(getApplication(), MyService.class);
|
|
|
- getApplication().startService(service);//打开服务,把程序写在服务里不容易被系统kill
|
|
|
+// Intent service = new Intent(getApplication(), MyService.class);
|
|
|
+// getApplication().startService(service);//打开服务,把程序写在服务里不容易被系统kill
|
|
|
|
|
|
MainViewModel.context = getApplication();
|
|
|
- SPUtils.getInstance().put("RunningState","0");//设备运行状态
|
|
|
+ SPUtils.getInstance().put("RunningState",0);//设备运行状态
|
|
|
SPUtils.getInstance().put("magDoorSwitch","0");//门磁状态
|
|
|
- SPUtils.getInstance().put("type","0");//小程序传送数据类型
|
|
|
|
|
|
BatteryManager batteryManager = (BatteryManager)getSystemService(BATTERY_SERVICE);//电量管理
|
|
|
int battery = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);//查询电量值
|
|
|
Log.i(TAG,"电量值="+battery);
|
|
|
|
|
|
+
|
|
|
+ if(SPUtils.getInstance().getInt("TaskSwitch")==1){
|
|
|
+ repeatTask();
|
|
|
+ }
|
|
|
+ SPUtils.getInstance().put("TaskSwitch",0);
|
|
|
+
|
|
|
}
|
|
|
private MediaPlayer mMediaPlay=null;
|
|
|
public ObservableField<String> textReadWeightData = new ObservableField<>();//称重数据显示
|
| xqd
@@ -212,7 +194,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
|
|
|
int a=1;
|
|
|
public View.OnClickListener btnClickOpenLight1234 = new View.OnClickListener() {
|
|
|
- //打开关闭灯4按钮
|
|
|
+ //打开关闭灯4按钮 开灯1
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
if(a%2==0){
|
| xqd
@@ -268,13 +250,15 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
//打开关闭灯2按钮
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
- if(a%2==0){
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().openLight2();
|
|
|
- }
|
|
|
- else {
|
|
|
- SerialPortUtil.getInstance().getOtherDevice().closeLight2();
|
|
|
- }
|
|
|
- a++;
|
|
|
+// if(a%2==0){
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().openLight2();
|
|
|
+// }
|
|
|
+// else {
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().closeLight2();
|
|
|
+// }
|
|
|
+// a++;
|
|
|
+ int hour=readTime();
|
|
|
+ Log.i("当前时间hour是:",hour+"dian");
|
|
|
}
|
|
|
};
|
|
|
public View.OnClickListener btnClickOpenLight1 = new View.OnClickListener() {
|
| xqd
@@ -288,7 +272,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
|
}
|
|
|
a++;*/
|
|
|
- reportDeviceEvent("haoge");
|
|
|
+// reportDeviceEvent("haoge");
|
|
|
+ SendSmsResponse("(测试123)");
|
|
|
}
|
|
|
};
|
|
|
public View.OnClickListener btnClickreadWeight = new View.OnClickListener() {
|
| xqd
@@ -354,7 +339,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
System.out.println("btnClickReport");
|
|
|
- reportProperty(1);
|
|
|
+ reportProperty();
|
|
|
}
|
|
|
};
|
|
|
public View.OnClickListener btnQeryIMEI = new View.OnClickListener() {
|
| xqd
@@ -424,7 +409,6 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- SPUtils.getInstance().put("infraredNum1",0);
|
|
|
SerialPortUtil.getInstance().getOtherDevice().pushRod();
|
|
|
}
|
|
|
},60000);
|
| xqd
@@ -545,15 +529,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
private void pushRodMethod(){
|
|
|
//有网下关门
|
|
|
- SPUtils.getInstance().put("infraredNum1",0);
|
|
|
SerialPortUtil.getInstance().getOtherDevice().pushRod();//关门
|
|
|
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- avgWeight();
|
|
|
- }
|
|
|
- },500);
|
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
| xqd
@@ -609,12 +586,12 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- reportProperty(2);
|
|
|
+ reportProperty();
|
|
|
}
|
|
|
},4000);
|
|
|
}
|
|
|
|
|
|
- private void avgWeight(){
|
|
|
+ /* private void avgWeight(){
|
|
|
Thread thread=new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
| xqd
@@ -630,9 +607,9 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
// e.printStackTrace();
|
|
|
// }
|
|
|
// arr[n]=n;
|
|
|
- Log.i("n=", String.valueOf(n));
|
|
|
+// Log.i("n=", String.valueOf(n));
|
|
|
// arr[n]=SerialPortUtil.getInstance().getOtherDevice().readWeight();
|
|
|
- Log.i("weight=", String.valueOf(arr[n]));
|
|
|
+// Log.i("weight=", String.valueOf(arr[n]));
|
|
|
weight=arr[n]+weight;
|
|
|
if(n==3){
|
|
|
Log.i("weight=", Arrays.toString(arr));
|
| xqd
@@ -652,12 +629,11 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
});
|
|
|
thread.start();
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
private void pushRodMethodNonet(){
|
|
|
//无网下关门
|
|
|
- SPUtils.getInstance().put("infraredNum1",0);
|
|
|
SerialPortUtil.getInstance().getOtherDevice().pushRod();//关门
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
| xqd
@@ -746,7 +722,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
// SerialPortUtil.getInstance().getWeightDevice().weightClear();//去皮清零
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().clearWeight();//去皮清零
|
|
|
pullonNetRodMethod();
|
|
|
- reportProperty(1);
|
|
|
+ reportProperty();
|
|
|
Log.i(TAG,"欢迎使用智能回收箱");
|
|
|
Log.i(TAG,"收到开门=============");
|
|
|
Thread thread=new Thread(new Runnable() {
|
| xqd
@@ -819,8 +795,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
try{
|
|
|
long curr=System.currentTimeMillis();
|
|
|
- while(System.currentTimeMillis()-curr<1800000) {
|
|
|
- Thread.sleep(1000);
|
|
|
+ while(System.currentTimeMillis()-curr<300000) {
|
|
|
+ Thread.sleep(2000);
|
|
|
Integer magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//通过门磁感应判断收运门是否关闭
|
|
|
if(magDoorSwitch==0){
|
|
|
SerialPortUtil.getInstance().getWeightDevice().weightClear();//若关闭,称重清零
|
| xqd
@@ -828,9 +804,9 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- reportProperty(1);
|
|
|
+ reportProperty();
|
|
|
}
|
|
|
- },1000);
|
|
|
+ },3000);
|
|
|
SPUtils.getInstance().put("magDoorSwitch","0");
|
|
|
break;
|
|
|
}
|
| xqd
@@ -849,6 +825,18 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+ if(topic.endsWith("thing/service/RemoteAgentClose")) {//关收运门
|
|
|
+ Log.i(TAG, "关运收门");
|
|
|
+ SPUtils.getInstance().put("magDoorSwitch", "0");
|
|
|
+ SerialPortUtil.getInstance().getWeightDevice().weightClear();
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().clearWeight();
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ reportProperty();
|
|
|
+ }
|
|
|
+ },3000);
|
|
|
+ }
|
|
|
if(topic.endsWith("thing/service/RemoteOpenPort2")){//开继电器2号端口
|
|
|
short i = 2;
|
|
|
try {
|
| xqd
@@ -1036,36 +1024,30 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
* 数据上行
|
|
|
* 上报状态
|
|
|
*/
|
|
|
- public void reportProperty(int num) {
|
|
|
+ public void reportProperty() {
|
|
|
Log.i(TAG,"上报数据");
|
|
|
try{
|
|
|
-// SerialPortUtil.getInstance().getWeightDevice().weightClear();//去皮清零
|
|
|
- // SerialPortUtil.getInstance().getOtherDevice().clearWeight();//去皮清零
|
|
|
Integer weight = 0;
|
|
|
- if(num==1){
|
|
|
- Log.i("num=1","读一次称重");
|
|
|
+ Log.i("num=1","读一次称重");
|
|
|
+ weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();//读称重
|
|
|
+ if(weight==1){
|
|
|
weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();//读称重
|
|
|
- }else if(num==2){
|
|
|
- Log.i("num=2","读平均称重或最后");
|
|
|
- weight=SPUtils.getInstance().getInt("avgWeight");
|
|
|
}
|
|
|
-
|
|
|
// 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;
|
|
|
- // Integer magDoorSwitch=0;
|
|
|
- // Integer currentTemperature=0;
|
|
|
-
|
|
|
-
|
|
|
Map<String, ValueWrapper> locationMap = new HashMap<>();
|
|
|
Map<String, ValueWrapper> reportData = new HashMap<>();
|
|
|
// SPUtils.getInstance().put("RodNumber","4721");
|
| xqd
@@ -1086,11 +1068,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
int lockNumberInt=Integer.parseInt(lockNumberStr);
|
|
|
|
|
|
- String runningStateStr=SPUtils.getInstance().getString("RunningState");
|
|
|
- if(runningStateStr.equals("")){
|
|
|
- runningStateStr="0";
|
|
|
- }
|
|
|
- int runningStateInt=Integer.parseInt(runningStateStr);
|
|
|
+ int runningStateInt=SPUtils.getInstance().getInt("RunningState");
|
|
|
reportData.put("RodOpenNum",new ValueWrapper.IntValueWrapper(rodNumberInt));
|
|
|
reportData.put("LockOpenNum",new ValueWrapper.IntValueWrapper(lockNumberInt));
|
|
|
|
| xqd
@@ -1102,7 +1080,12 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
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 正常 1 故障
|
|
|
+ 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));
|
| xqd
@@ -1111,13 +1094,14 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
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
|
|
|
+ currentTemperature+"度;门磁 "+magDoorSwitch+";杆状态 "+rodSwitchInt+";锁状态 "+lockSwitch+";杆开门次数 "+rodNumberInt+";开锁次数 "+lockNumberInt+";被夹次数"+queryCurrent
|
|
|
);
|
|
|
|
|
|
String text = "称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " + currentTemperature+"度;门磁 "+magDoorSwitch+";杆状态 "+
|
|
|
- rodSwitchInt+";锁状态 "+lockSwitch+";杆开门次数 "+rodNumberInt+";开锁次数 "+lockNumberInt+"------------------------------";
|
|
|
+ rodSwitchInt+";锁状态 "+lockSwitch+";杆开门次数 "+rodNumberInt+";开锁次数 "+lockNumberInt+";被夹次数"+queryCurrent+"------------------------------";
|
|
|
Log.i(TAG, text + "=textReportData---------------------");
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
| xqd
@@ -1126,6 +1110,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
@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) {
|
| xqd
@@ -1139,37 +1124,33 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- /* public View.OnClickListener btnClickclearCurrent = new View.OnClickListener() {//清除
|
|
|
- @Override
|
|
|
- public void onClick(View view) {
|
|
|
- System.out.println("btnClickclearCurrent");
|
|
|
- String reportDataToString=reportDataMethod();
|
|
|
- try {
|
|
|
- String base64Str = DemoOne.java_openssl_encrypt("SSSS", "96e79218965eb72c92a549dd", "1234567891234567");//加密
|
|
|
- Log.i(TAG,base64Str+"+++++base64Str");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- };*/
|
|
|
/*
|
|
|
* 上报给蓝牙的数据格式
|
|
|
* */
|
|
|
public JSONObject reportDataMethod(){
|
|
|
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();//温度
|
|
|
+ }
|
|
|
Integer weight = 0;
|
|
|
weight=SerialPortUtil.getInstance().getWeightDevice().readWeight();
|
|
|
+ if(weight==1){
|
|
|
+ weight=SerialPortUtil.getInstance().getWeightDevice().readWeight();
|
|
|
+ }
|
|
|
// weight=SerialPortUtil.getInstance().getOtherDevice().readWeight();//称重
|
|
|
|
|
|
String text = "称重 " + weight.toString() + ";距离 " + capacity.toString() + "mm;温度 " + currentTemperature+"度;门磁 "+magDoorSwitch+";杆状态 "+";锁状态 "+lockSwitch;
|
|
|
Log.i(TAG, text + "=textReportData---------------------");
|
|
|
|
|
|
- JSONObject locationMap =new JSONObject();
|
|
|
+// JSONObject locationMap =new JSONObject();
|
|
|
String rodNumberStr= SPUtils.getInstance().getString("RodNumber");
|
|
|
if(rodNumberStr.equals("")){
|
|
|
rodNumberStr="0";
|
| xqd
@@ -1187,11 +1168,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
int lockNumberInt=Integer.parseInt(lockNumberStr);
|
|
|
|
|
|
- String runningStateStr=SPUtils.getInstance().getString("RunningState");
|
|
|
- if(runningStateStr.equals("")){
|
|
|
- runningStateStr="0";
|
|
|
- }
|
|
|
- int runningStateInt=Integer.parseInt(runningStateStr);
|
|
|
+
|
|
|
+ int runningStateInt=SPUtils.getInstance().getInt("RunningState");
|
|
|
// JSONObject tem1 =new JSONObject();
|
|
|
// tem1.put("V",IMEI);
|
|
|
// tem1.put("I","IMEI");
|
| xqd
@@ -1251,12 +1229,10 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
array.add(tem9);
|
|
|
array.add(tem10);
|
|
|
// array.add(tem11);
|
|
|
-
|
|
|
JSONObject reportData =new JSONObject();
|
|
|
reportData.put("P",array);
|
|
|
-
|
|
|
-
|
|
|
Log.i(TAG,"reportData=+++++"+reportData.toString());
|
|
|
+ SPUtils.getInstance().put("RunningState",0);
|
|
|
return reportData;
|
|
|
// return (String) reportData;
|
|
|
}
|
| xqd
@@ -1280,7 +1256,6 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
//设备事件上报
|
|
|
public static void reportDeviceEvent(String identifier){
|
|
|
- SPUtils.getInstance().put("RunningState","1");
|
|
|
HashMap<String, ValueWrapper> hashMap = new HashMap<>();
|
|
|
// TODO 用户根据实际情况设置
|
|
|
// hashMap.put("ErrorCode", new ValueWrapper.IntValueWrapper(0));
|
| xqd
@@ -1304,7 +1279,6 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
// }
|
|
|
// });
|
|
|
}
|
|
|
-
|
|
|
private void getDeviceProperty(String identifier){
|
|
|
// 根据 identifier 获取当前物模型中该属性的值
|
|
|
LinkKit.getInstance().getDeviceThing().getPropertyValue(identifier);
|
| xqd
@@ -1331,14 +1305,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
System.out.println("checkOnlineStatus subscribe Fail");
|
|
|
}
|
|
|
});
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- publish();
|
|
|
- publishRepeat();
|
|
|
-
|
|
|
- }
|
|
|
- },600000);
|
|
|
+ publish();
|
|
|
}
|
|
|
private void reportVersion(){
|
|
|
//上报版本
|
| xqd
@@ -1366,21 +1333,6 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}else{
|
|
|
Log.i("安装","no");
|
|
|
}
|
|
|
-
|
|
|
-// Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
-//// 安装完成后,启动app
|
|
|
-// Log.i(TAG,"安装");
|
|
|
-// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
-//// Uri uri = Uri.parse("file://" + apkFile.toString());
|
|
|
-// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
-// intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
-// Uri uri = FileProvider.getUriForFile(getApplication(), getApplication().getPackageName() + ".fileprovider", apkFile3);
|
|
|
-// intent.setDataAndType(uri, "application/vnd.android.package-archive");
|
|
|
-// } else {
|
|
|
-// intent.setDataAndType(Uri.fromFile(apkFile3), "application/vnd.android.package-archive");
|
|
|
-// }
|
|
|
-//// intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
|
|
|
-// getApplication().startActivity(intent);
|
|
|
}
|
|
|
},1000);
|
|
|
}
|
| xqd
@@ -1434,7 +1386,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
private int disconnectTimes = 0;
|
|
|
|
|
|
- private void publish (){
|
|
|
+ private void publish(){
|
|
|
//一个循环方法,用来更新数据
|
|
|
System.out.println("checkOnlineStatus");
|
|
|
MqttPublishRequest publishRequest = new MqttPublishRequest();
|
| xqd
@@ -1442,22 +1394,23 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
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);
|
|
|
+
|
|
|
LinkKit.getInstance().publish(publishRequest, new IConnectSendListener() {
|
|
|
@Override
|
|
|
public void onResponse(ARequest aRequest, AResponse aResponse) {
|
|
|
disconnectTimes = 0;
|
|
|
- System.out.println("publish on Response :" + aResponse.getData());
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- publish();
|
|
|
if(networkInt!=0){
|
|
|
- reportProperty(1);
|
|
|
- Log.i(TAG,"循环上报数据");
|
|
|
+ reportProperty();
|
|
|
}
|
|
|
}
|
|
|
- }, 1800000);
|
|
|
+ },5000);
|
|
|
+
|
|
|
+ System.out.println("publish on Response :" + aResponse.getData());
|
|
|
}
|
|
|
@Override
|
|
|
public void onFailure(ARequest aRequest, AError aError) {
|
| xqd
@@ -1473,49 +1426,13 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
publish();
|
|
|
}
|
|
|
- }, 1800000);
|
|
|
+ },100000);
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void publishRepeat(){
|
|
|
- //每隔一段时间检测磁控和温度 如果异常就上报(前提是有网条件下)
|
|
|
- Thread thread=new Thread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- Integer currentTemperature=SerialPortUtil.getInstance().getOtherDevice().geTemperature();//温度
|
|
|
- Integer magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();
|
|
|
- if(currentTemperature>100){
|
|
|
- SPUtils.getInstance().put("RunningState","2");//温度过高
|
|
|
- Log.i(TAG,"温度过高");
|
|
|
- Integer networkInt=netWorkInfo();
|
|
|
- if(networkInt!=0){
|
|
|
- reportProperty(1);
|
|
|
- }
|
|
|
- }
|
|
|
- if(magDoorSwitch==1){
|
|
|
- if(SPUtils.getInstance().getString("magDoorSwitch").equals("0")){
|
|
|
- SPUtils.getInstance().put("RunningState","3");
|
|
|
- Log.i(TAG,"收运门意外打开");
|
|
|
- Integer networkInt=netWorkInfo();
|
|
|
- if(networkInt!=0){
|
|
|
- reportProperty(1);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(currentTemperature<100&magDoorSwitch==0) {
|
|
|
- SPUtils.getInstance().put("RunningState","0");
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- thread.start();
|
|
|
- mHandler.postDelayed(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- publishRepeat();
|
|
|
- }
|
|
|
- }, 420000);
|
|
|
- }
|
|
|
+
|
|
|
public void unRegisterIoTListener(){
|
|
|
// 取消注册 notifyListener,notifyListener对象需和注册的时候是同一个对象
|
|
|
LinkKit.getInstance().unRegisterOnPushListener(notifyListener);
|
| xqd
@@ -1646,6 +1563,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
timeInt=82;
|
|
|
}
|
|
|
int finalTimeInt = timeInt;
|
|
|
+ Log.i("计时",""+finalTimeInt);
|
|
|
Thread thread=new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
| xqd
@@ -1655,6 +1573,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
try {
|
|
|
sleep(1000);
|
|
|
numInt++;
|
|
|
+ Log.i("倒计时时间",numInt+"");
|
|
|
if(SPUtils.getInstance().getString("RodSwitch").equals("0")){
|
|
|
break;
|
|
|
}
|
| xqd
@@ -1707,7 +1626,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
try{
|
|
|
long curr=System.currentTimeMillis();
|
|
|
- while(System.currentTimeMillis()-curr<1800000) {
|
|
|
+ while(System.currentTimeMillis()-curr<3000000) {
|
|
|
Thread.sleep(1000);
|
|
|
Integer magDoorSwitch=SerialPortUtil.getInstance().getOtherDevice().queryMagDoor();//通过门磁感应判断收运门是否关闭
|
|
|
if(magDoorSwitch==0){
|
| xqd
@@ -1744,6 +1663,9 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
if(requestStr.equals("close2")){
|
|
|
Log.i(TAG,"+++++收运门关");
|
|
|
+ SerialPortUtil.getInstance().getWeightDevice().weightClear();//若关闭,称重清零
|
|
|
+ SPUtils.getInstance().put("magDoorSwitch","0");
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().clearWeight();
|
|
|
SPUtils.getInstance().put("type","close");
|
|
|
String response=reportDataMethodEncrypt();
|
|
|
SPUtils.getInstance().put("response",response);
|
| xqd
@@ -1995,6 +1917,141 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
return getApplication().getSystemService(name);
|
|
|
}
|
|
|
|
|
|
+ public void repeatTask() {
|
|
|
+ Log.i("----------------------","ok");
|
|
|
+ task3 =new TimerTask(){
|
|
|
+ public void run(){
|
|
|
+ publishRepeat();
|
|
|
+ Log.i("Task","300秒循环");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timer.schedule(task3,60000,300000);
|
|
|
+ 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);
|
|
|
+
|
|
|
+ task1=new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ publish();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timer.schedule(task1,600000,600000);
|
|
|
+ }
|
|
|
+ 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);//记录被夹次数
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().clearCurrent();
|
|
|
+ }
|
|
|
+ if(currentTemperature>90){
|
|
|
+ SPUtils.getInstance().put("RunningState",2);//温度过高
|
|
|
+ Log.i(TAG,"温度过高");
|
|
|
+ Integer networkInt=netWorkInfo();
|
|
|
+ if(networkInt!=0){
|
|
|
+ reportProperty();
|
|
|
+ //短信通知
|
|
|
+ SendSmsResponse("温度过高");
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(currentTemperature>40){
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().openuFan();//打开分钟
|
|
|
+ }else{
|
|
|
+ // SerialPortUtil.getInstance().getOtherDevice().closeFan();//打开分钟
|
|
|
+ }
|
|
|
|
|
|
+ if(magDoorSwitch==1){
|
|
|
+ if(SPUtils.getInstance().getString("magDoorSwitch").equals("0")){
|
|
|
+ SPUtils.getInstance().put("RunningState",3);
|
|
|
+ Log.i(TAG,"收运门意外打开");
|
|
|
+ Integer networkInt=netWorkInfo();
|
|
|
+ /* if(networkInt!=0){
|
|
|
+ reportProperty();
|
|
|
+ //短信通知
|
|
|
+ try {
|
|
|
+ SendSmsResponse("收运门意外打开");
|
|
|
+ } catch (ClientException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ }
|
|
|
+// if(currentTemperature<100&magDoorSwitch==0) {
|
|
|
+// SPUtils.getInstance().put("RunningState","0");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+
|
|
|
+ }
|
|
|
+ public int readTime(){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
|
|
+ Log.i("Time hour=","现在是"+hour+"点");
|
|
|
+ return hour;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void openLight(){
|
|
|
+ Log.i("d定时","ok");
|
|
|
+ if(readTime()>19||readTime()<1){
|
|
|
+ Log.i("night","开灯");
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().openLight1();
|
|
|
+ }else {
|
|
|
+ Log.i("day","关灯");
|
|
|
+// SerialPortUtil.getInstance().getOtherDevice().closeLight1();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void SendSmsResponse(String event){
|
|
|
+ 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("")
|
|
|
+ .addParams("event", 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();
|
|
|
+ }*/
|
|
|
+ }
|
|
|
|
|
|
}
|