| xqd
@@ -209,6 +209,14 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
SerialPortUtil.getInstance().getOtherDevice().clearCurrent();
|
|
|
}
|
|
|
};
|
|
|
+ public View.OnClickListener btnClickSelectPower = new View.OnClickListener() {
|
|
|
+ //清除电流过大查询值
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ System.out.println("read response");
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().selectPower();
|
|
|
+ }
|
|
|
+ };
|
|
|
public View.OnClickListener btnClickSpeech=new View.OnClickListener() {
|
|
|
//播放音频
|
|
|
@Override
|
| xqd
@@ -313,6 +321,14 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
a++;
|
|
|
}
|
|
|
};
|
|
|
+ public View.OnClickListener btnClickSetPowerBigger = new View.OnClickListener() {
|
|
|
+ //设置更大的电流值
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ SerialPortUtil.getInstance().getOtherDevice().setPowerBigger();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
public View.OnClickListener btnClickSendMsg = new View.OnClickListener() {
|
|
|
//发送短信 事件测试
|
|
|
@Override
|
| xqd
@@ -605,38 +621,46 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
};
|
|
|
private void pullRodMethod(){
|
|
|
SerialPortUtil.getInstance().getOtherDevice().pullRod();
|
|
|
- try {
|
|
|
- AssetFileDescriptor fd = getApplication().getAssets().openFd("nonetPullRod.mp3");
|
|
|
- mMediaPlay =new MediaPlayer();
|
|
|
- mMediaPlay.reset();
|
|
|
- mMediaPlay.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
|
|
|
- mMediaPlay.prepare();
|
|
|
- Log.i(TAG,"播放音频");
|
|
|
- mMediaPlay.start();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ AssetFileDescriptor fd = getApplication().getAssets().openFd("nonetPullRod.mp3");
|
|
|
+ mMediaPlay = new MediaPlayer();
|
|
|
+ mMediaPlay.reset();
|
|
|
+ mMediaPlay.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
|
|
|
+ mMediaPlay.prepare();
|
|
|
+ Log.i(TAG, "播放音频");
|
|
|
+ mMediaPlay.start();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }},100);
|
|
|
}
|
|
|
private void pullonNetRodMethod(){
|
|
|
//有网开门
|
|
|
SerialPortUtil.getInstance().getOtherDevice().pullRod();
|
|
|
- try {
|
|
|
- AssetFileDescriptor fd = getApplication().getAssets().openFd("netPullRod.mp3");
|
|
|
- mMediaPlay =new MediaPlayer();
|
|
|
- mMediaPlay.reset();
|
|
|
- mMediaPlay.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
|
|
|
- mMediaPlay.prepare();
|
|
|
- Log.i(TAG,"播放音频");
|
|
|
- mMediaPlay.start();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ mHandler.postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ AssetFileDescriptor fd = getApplication().getAssets().openFd("netPullRod.mp3");
|
|
|
+ mMediaPlay = new MediaPlayer();
|
|
|
+ mMediaPlay.reset();
|
|
|
+ mMediaPlay.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
|
|
|
+ mMediaPlay.prepare();
|
|
|
+ Log.i(TAG, "播放音频");
|
|
|
+ mMediaPlay.start();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }},100);
|
|
|
}
|
|
|
private void pushRodMethod(){
|
|
|
//有网下关门
|
|
|
SerialPortUtil.getInstance().getOtherDevice().pushRod();//关门
|
|
|
reportProperty();
|
|
|
-
|
|
|
+ reportDeviceEvent("commoneEvent","close",3);
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
| xqd
@@ -692,7 +716,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
@Override
|
|
|
public void run() {
|
|
|
reportProperty();
|
|
|
- reportDeviceEvent("commoneEvent","close",3);
|
|
|
+// reportDeviceEvent("commoneEvent","close",3);
|
|
|
}
|
|
|
},4000);
|
|
|
}
|
| xqd
@@ -816,7 +840,6 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
|
|
|
System.out.println("收到云端下行的数据:connectId:"+connectId+" topic :"+topic+" aMessage data:"+ aMessage.getData().getClass().getSimpleName());
|
|
|
byte[] dataBytes = (byte[])aMessage.getData();
|
|
|
-
|
|
|
System.out.println(new String(dataBytes));
|
|
|
// if (topic.endsWith("thing/event/property/post_reply")){ //推送设备属性的回包。
|
|
|
// }
|
| xqd
@@ -835,15 +858,14 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
// SerialPortUtil.getInstance().getOtherDevice().clearWeight();//去皮清零
|
|
|
SPUtils.getInstance().put("clearWight",2);
|
|
|
}
|
|
|
+ pullonNetRodMethod();//开门
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- reportProperty();
|
|
|
- pullonNetRodMethod();
|
|
|
+ reportProperty();//上报数据
|
|
|
reportDeviceEvent("commoneEvent","open",3);
|
|
|
}
|
|
|
},500);
|
|
|
-
|
|
|
Log.i(TAG,"欢迎使用智能回收箱");
|
|
|
Log.i(TAG,"收到开门=============");
|
|
|
Thread thread=new Thread(new Runnable() {
|
| xqd
@@ -855,12 +877,15 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
try {
|
|
|
sleep(1000);
|
|
|
numInt++;
|
|
|
+ Log.i("开门","开门"+numInt);
|
|
|
if(SPUtils.getInstance().getString("RodSwitch").equals("0")){
|
|
|
- break;
|
|
|
+ break;//关门了就退出
|
|
|
+ }
|
|
|
+ if(numInt==41){
|
|
|
+ reportProperty();
|
|
|
}
|
|
|
if(numInt==82){
|
|
|
- pushRodMethod();
|
|
|
- reportDeviceEvent("commoneEvent","close",3);
|
|
|
+ pushRodMethod();//82秒后关门
|
|
|
break;
|
|
|
}
|
|
|
} catch (InterruptedException e) {
|
| xqd
@@ -871,14 +896,6 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
});
|
|
|
thread.start();
|
|
|
-// mHandler.postDelayed(new Runnable() {
|
|
|
-// @Override
|
|
|
-// public void run() {
|
|
|
-// if(SPUtils.getInstance().getString("RodSwitch").equals("1")) {
|
|
|
-// pushRodMethod();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// },82000);//82s没关门就自动关门
|
|
|
}
|
|
|
if(topic.endsWith("thing/service/RemoteClose")){
|
|
|
Log.i(TAG,"收到关门========================");
|
| xqd
@@ -1090,6 +1107,8 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
if(topic.endsWith("thing/service/currentWeight")){
|
|
|
Log.d(TAG , "读取当前读数");
|
|
|
+ reportProperty();
|
|
|
+ //以下没啥用
|
|
|
int weight = SerialPortUtil.getInstance().getWeightDevice().readWeight();
|
|
|
// int weight = SerialPortUtil.getInstance().getOtherDevice().readWeight();
|
|
|
String pushDSata = weight+"";
|
| xqd
@@ -1130,6 +1149,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
@Override
|
|
|
public void onConnectStateChange(String connectId, ConnectState connectState) {
|
|
|
+
|
|
|
System.out.println("onConnectStateChange connectId:"+connectId+" connectState:"+connectState);
|
|
|
if(connectState == ConnectState.CONNECTED){
|
|
|
// reportProperty(1);
|
| xqd
@@ -1138,6 +1158,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
//未授权写权限。
|
|
|
requestFilePermissions.call();
|
|
|
}
|
|
|
+ reportProperty();//重新连接后上报数据
|
|
|
reportVersion();
|
|
|
otaListener();
|
|
|
}
|
| xqd
@@ -1482,26 +1503,27 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
// 注册下行监听,包括长连接的状态和云端下行的数据
|
|
|
LinkKit.getInstance().registerOnPushListener(notifyListener);
|
|
|
// MqttRrpcRegisterRequest rrpcRegisterRequest = new MqttRrpcRegisterRequest();
|
|
|
-//// rrpcRegisterRequest.topic = "/a1EtqHmfpNk/9pD3trz6OaDV8GF7yRsb/thing/service/currentWeight";
|
|
|
-//// rrpcRegisterRequest.topic = "/a13H8L6bDyf/9pD3trz6OaDV8GF7yRsb/thing/service/currentWeight";
|
|
|
-//
|
|
|
-// MqttSubscribeRequest subscribeRequest = new MqttSubscribeRequest();
|
|
|
-//// subscribeRequest.topic = "/a1EtqHmfpNk/9pD3trz6OaDV8GF7yRsb/user/checkOnlineStatus";
|
|
|
-// subscribeRequest.topic = "/a13H8L6bDyf/"+IMEI+"/user/checkOnlineStatus";
|
|
|
-//
|
|
|
-// subscribeRequest.isSubscribe = true;
|
|
|
-// subscribeRequest.qos = 0;
|
|
|
-// LinkKit.getInstance().subscribe(subscribeRequest, new IConnectSubscribeListener() {
|
|
|
-// @Override
|
|
|
-// public void onSuccess() {
|
|
|
-// System.out.println("checkOnlineStatus subscribe success");
|
|
|
-// }
|
|
|
-// @Override
|
|
|
-// public void onFailure(AError aError) {
|
|
|
-// System.out.println("checkOnlineStatus subscribe Fail");
|
|
|
-// }
|
|
|
-// });
|
|
|
-// publish();
|
|
|
+//// rrpcRegisterRequest.topic = "/a1EtqHmfpNk/"+IMEI+"/thing/service/currentWeight";//正式服
|
|
|
+// rrpcRegisterRequest.topic = "/a13H8L6bDyf/"+IMEI+"/thing/service/currentWeight";//测试服
|
|
|
+
|
|
|
+ MqttSubscribeRequest subscribeRequest = new MqttSubscribeRequest();
|
|
|
+// subscribeRequest.topic = "/a1EtqHmfpNk/"+IMEI+"/user/checkOnlineStatus";//正式服
|
|
|
+ subscribeRequest.topic = "/a13H8L6bDyf/"+IMEI+"/user/checkOnlineStatus";//测试服
|
|
|
+
|
|
|
+ subscribeRequest.isSubscribe = true;
|
|
|
+ subscribeRequest.qos = 0;
|
|
|
+ LinkKit.getInstance().subscribe(subscribeRequest, new IConnectSubscribeListener() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess() {
|
|
|
+ System.out.println("checkOnlineStatus subscribe success");
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onFailure(AError aError) {
|
|
|
+ System.out.println("checkOnlineStatus subscribe Fail");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ publish();
|
|
|
}
|
|
|
private void reportVersion(){
|
|
|
//上报版本
|
| xqd
@@ -1582,52 +1604,42 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
}
|
|
|
private int disconnectTimes = 0;
|
|
|
|
|
|
-// private void publish(){
|
|
|
-// //一个循环方法,用来更新数据
|
|
|
-// System.out.println("checkOnlineStatus");
|
|
|
-// MqttPublishRequest publishRequest = new MqttPublishRequest();
|
|
|
-// publishRequest.qos = 0;
|
|
|
-//// publishRequest.topic = "/a1EtqHmfpNk/"+IMEI+"/user/checkOnlineStatus";//a1EtqHmfpNk
|
|
|
-// publishRequest.topic = "/a13H8L6bDyf/"+IMEI+"/user/checkOnlineStatus";//a1EtqHmfpNk
|
|
|
-//
|
|
|
-// publishRequest.payloadObj = "{\"id\":"+ publishRequest.msgId+", \"version\":\"1.0\",\"time\":" + System.currentTimeMillis() + "}";
|
|
|
-//// 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) {
|
|
|
-// disconnectTimes = 0;
|
|
|
-// mHandler.postDelayed(new Runnable() {
|
|
|
-// @Override
|
|
|
-// public void run() {
|
|
|
-// reportProperty();
|
|
|
-// }
|
|
|
-// },5000);
|
|
|
-//
|
|
|
-// System.out.println("publish on Response :" + aResponse.getData());
|
|
|
-// }
|
|
|
-// @Override
|
|
|
-// public void onFailure(ARequest aRequest, AError aError) {
|
|
|
-// System.out.println("publish onFailure error:" + aError.getMsg());
|
|
|
-// disconnectTimes++;
|
|
|
-// if (disconnectTimes > 5) {
|
|
|
-// registerAliIoTListener(); //重新连接。
|
|
|
-// disconnectTimes = 0;
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// mHandler.postDelayed(new Runnable() {
|
|
|
-// @Override
|
|
|
-// public void run() {
|
|
|
-// publish();
|
|
|
-// }
|
|
|
-// },1000000);
|
|
|
-//
|
|
|
-// }
|
|
|
-// });
|
|
|
-//// }
|
|
|
-//
|
|
|
-// }
|
|
|
+ private void publish(){
|
|
|
+ //一个循环方法,用来更新数据
|
|
|
+ System.out.println("checkOnlineStatus");
|
|
|
+ MqttPublishRequest publishRequest = new MqttPublishRequest();
|
|
|
+ publishRequest.isRPC = false;
|
|
|
+
|
|
|
+// publishRequest.topic = "/a1EtqHmfpNk/"+IMEI+"/user/checkOnlineStatus";//正式服
|
|
|
+ publishRequest.topic = "/a13H8L6bDyf/"+IMEI+"/user/checkOnlineStatus";//测试服
|
|
|
+ publishRequest.qos = 0;
|
|
|
+ publishRequest.payloadObj = "{\"id\":"+ publishRequest.msgId+", \"version\":\"8.0\",\"time\":" + System.currentTimeMillis() + "}";
|
|
|
+ publishRequest.payloadObj = "{\"id\":\"1}";
|
|
|
+
|
|
|
+ int networkNum=SPUtils.getInstance().getInt("netWork",1);
|
|
|
+ if(networkNum!=0){
|
|
|
+ LinkKit.getInstance().publish(publishRequest, new IConnectSendListener() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(ARequest aRequest, AResponse aResponse) {
|
|
|
+ Log.i(TAG,"发布成功");
|
|
|
+ disconnectTimes = 0;
|
|
|
+ System.out.println("publish on Response :" + aResponse.getData());
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onFailure(ARequest aRequest, AError aError) {
|
|
|
+ Log.i(TAG,"发布失败");
|
|
|
+ System.out.println("publish onFailure error:" + aError.getMsg());
|
|
|
+ disconnectTimes++;
|
|
|
+ if (disconnectTimes > 5) {
|
|
|
+ registerAliIoTListener(); //重新连接。
|
|
|
+ disconnectTimes = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public void unRegisterIoTListener(){
|
| xqd
@@ -1709,6 +1721,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
Log.i(TAG,"offset="+offset);
|
|
|
if(SPUtils.getInstance().getInt("phoneType")==2){
|
|
|
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS,responseBytes.length,responseBytes );// 响应客户端
|
|
|
+ Log.d(TAG,"客户端读取Characteristic[" + characteristic.getUuid() + "]:\n" + response);
|
|
|
}else {
|
|
|
if(responseBytes.length>offset){
|
|
|
int restLen = responseBytes.length-offset;
|
| xqd
@@ -1771,16 +1784,15 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
public void run() {
|
|
|
int numInt=0;
|
|
|
long curr=System.currentTimeMillis();
|
|
|
- while(System.currentTimeMillis()-curr<finalTimeInt){
|
|
|
+ while(System.currentTimeMillis()-curr<finalTimeInt+5000){
|
|
|
try {
|
|
|
sleep(1000);
|
|
|
numInt++;
|
|
|
-
|
|
|
- Log.i("倒计时时间",numInt+"---"+SPUtils.getInstance().getString("RodSwitch"));
|
|
|
+ Log.i("倒计时时间",numInt+"---"+SPUtils.getInstance().getString("RodSwitch")+"---"+finalTimeInt);
|
|
|
if(SPUtils.getInstance().getString("RodSwitch").equals("0")){
|
|
|
break;
|
|
|
}
|
|
|
- if(numInt== finalTimeInt){
|
|
|
+ if(numInt*1000== finalTimeInt){
|
|
|
pushRodMethodNonet();
|
|
|
SPUtils.getInstance().put("type","close");
|
|
|
String response=reportDataMethodEncrypt();
|
| xqd
@@ -2161,10 +2173,12 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
task3 =new TimerTask(){
|
|
|
public void run(){
|
|
|
publishRepeat();
|
|
|
+ reportProperty();
|
|
|
+
|
|
|
Log.i("Task","300秒循环");
|
|
|
}
|
|
|
};
|
|
|
- timer.schedule(task3,60000,600000);
|
|
|
+ timer.schedule(task3,10000,600000);
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 11);
|
| xqd
@@ -2172,8 +2186,9 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
task2=new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
+ openLight();
|
|
|
if(readTime()==3){
|
|
|
- restartApp();
|
|
|
+// restartApp();
|
|
|
restartAndroid();
|
|
|
}
|
|
|
Integer networkInt=netWorkInfo();
|
| xqd
@@ -2189,12 +2204,10 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
task1=new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
-// publish();
|
|
|
- openLight();
|
|
|
- reportProperty();
|
|
|
+ publish();
|
|
|
}
|
|
|
};
|
|
|
- timer.schedule(task1,10000,3600000);
|
|
|
+ timer.schedule(task1,1000,60000);
|
|
|
|
|
|
}
|
|
|
private void publishRepeat(){
|
| xqd
@@ -2206,7 +2219,7 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
SPUtils.getInstance().put("ClampHandNum",num+1);//记录被夹次数
|
|
|
SerialPortUtil.getInstance().getOtherDevice().clearCurrent();
|
|
|
}
|
|
|
- if(currentTemperature>60){
|
|
|
+ if(currentTemperature>70){
|
|
|
SPUtils.getInstance().put("RunningState",2);//温度过高
|
|
|
Log.i(TAG,"温度过高");
|
|
|
// Integer networkInt=netWorkInfo();
|
| xqd
@@ -2252,10 +2265,6 @@ public class MainViewModel extends BaseViewModel implements SerialPortHelper.OnS
|
|
|
SerialPortUtil.getInstance().getOtherDevice().closeLight2();
|
|
|
SerialPortUtil.getInstance().getOtherDevice().closeLight3();
|
|
|
SerialPortUtil.getInstance().getOtherDevice().closeLight4();
|
|
|
- if(readTime()==3){
|
|
|
- restartApp();
|
|
|
-// restartAndroid();
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|