|
@@ -111,7 +111,9 @@ public class MyService extends Service {
|
|
|
private String[] lastTimeSplit;
|
|
|
private String[] nextTimeSplit;
|
|
|
public static boolean isLate = true;//记录从后台查询是否过期的情况。一开始为false,先让他不检测,得知结果后再执行,否则就会出现假象。
|
|
|
+ public static Integer late = 0;
|
|
|
private String sD2Data = "";
|
|
|
+ private Integer queriesFailedNumber = 0;
|
|
|
|
|
|
@Nullable
|
|
|
@Override
|
|
@@ -132,7 +134,7 @@ public class MyService extends Service {
|
|
|
for (int i = 0; i < TOTAL_SUM; i++) {
|
|
|
sHomePageLocationList.add("0");//初始化
|
|
|
}
|
|
|
- Log.d(TAG, "onCreate: "+sHomePageLocationList.size());
|
|
|
+ Log.d(TAG, "onCreate: " + sHomePageLocationList.size());
|
|
|
}
|
|
|
|
|
|
if (!EventBus.getDefault().isRegistered(this))
|
|
@@ -196,6 +198,7 @@ public class MyService extends Service {
|
|
|
if (isRead) {
|
|
|
isRead = !isRead;
|
|
|
mThreadPoolMyservice.stopReadM600();
|
|
|
+ mThreadPoolMyservice.stopReadM71();
|
|
|
mThreadPoolMyservice.stopReadD2();
|
|
|
mThreadPoolMyservice.startALLRead();
|
|
|
}
|
|
@@ -378,30 +381,47 @@ public class MyService extends Service {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timedata));
|
|
|
//第一次就会出现报错。
|
|
|
- Long overdueDate =Hawk.get(Name.OVERDUE_DATE,0L);//购买的到期的时间
|
|
|
+ Long overdueDate = Hawk.get(Name.OVERDUE_DATE, 0L);//购买的到期的时间
|
|
|
Long timeInMillis = calendar.getTimeInMillis();//当前时间
|
|
|
- String data = Hawk.get(Name.REMAINING,"0");
|
|
|
+ String data = Hawk.get(Name.REMAINING, "0");
|
|
|
long remaining = Long.valueOf(data);
|
|
|
Log.d(TAG, "onSuccess: 时间过期remaining" + remaining);
|
|
|
//如果时间没过期,那么可以继续制作
|
|
|
if (overdueDate > timeInMillis) {
|
|
|
Log.d(TAG, "onSuccess: 没有过期");
|
|
|
isLate = true;
|
|
|
+ last = 0;
|
|
|
} else if (remaining > 0) {
|
|
|
Log.d(TAG, "onSuccess: 时间过期,按次数计算");
|
|
|
isLate = true;
|
|
|
+ last = 0;
|
|
|
} else {
|
|
|
Log.d(TAG, "onSuccess: 全部过期,全部不能清洗");
|
|
|
+ LogUtils.logWrite("myservice1支付查询失败");
|
|
|
isLate = false;
|
|
|
+ last = 1;
|
|
|
+ }
|
|
|
+ if (queriesFailedNumber != 0) {
|
|
|
+ queriesFailedNumber = 0;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- Log.d(TAG, "onSuccess: "+e);
|
|
|
+ Log.d(TAG, "onSuccess: " + e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onFailure(String msg) {
|
|
|
- isLate = false;
|
|
|
+ if (queriesFailedNumber >= 3) {//说明失败了三次。
|
|
|
+ if (isLate != false) {
|
|
|
+ isLate = false;
|
|
|
+ }
|
|
|
+ if (last != 2) {
|
|
|
+ last = 2;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ queriesFailedNumber++;
|
|
|
+ LogUtils.logWrite("myservice2支付查询失败");
|
|
|
Log.d(TAG, "onSuccess onFailure: ");
|
|
|
}
|
|
|
|
|
@@ -524,9 +544,9 @@ public class MyService extends Service {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timedata));
|
|
|
//第一次就会出现报错。
|
|
|
- Long overdueDate = (Long) Hawk.get(Name.OVERDUE_DATE,0L);//购买的到期的时间
|
|
|
+ Long overdueDate = (Long) Hawk.get(Name.OVERDUE_DATE, 0L);//购买的到期的时间
|
|
|
Long timeInMillis = calendar.getTimeInMillis();//当前时间
|
|
|
- String data = (String) Hawk.get(Name.REMAINING);
|
|
|
+ String data = (String) Hawk.get(Name.REMAINING, "0");
|
|
|
long remaining = Long.valueOf(data);
|
|
|
Log.d(TAG, "onSuccess: 时间过期remaining" + remaining);
|
|
|
//如果时间没过期,那么可以继续制作
|
|
@@ -661,6 +681,7 @@ public class MyService extends Service {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
private CompositeDisposable mDisposables;
|
|
|
protected ApiStores apiStores = ApiClient.retrofit().create(ApiStores.class);
|
|
|
|
|
@@ -729,9 +750,10 @@ public class MyService extends Service {
|
|
|
mThreadPoolMyservice.stopSetMMM3();
|
|
|
mThreadPoolMyservice.startSetMMM3("M3");
|
|
|
Log.d(TAG, "isClean: 開始清洗3");
|
|
|
+ LogUtils.logWrite("急停复位");
|
|
|
}
|
|
|
}
|
|
|
- }, 2000);
|
|
|
+ }, 4000);
|
|
|
} else if (messageEvent.getName().equals("MMM3")) {
|
|
|
Log.d(TAG, "stopSetMMM3runevent: ");
|
|
|
mThreadPoolMyservice.stopSetMMM3();
|
|
@@ -777,8 +799,32 @@ public class MyService extends Service {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ } else if (name.equals("M71")) {
|
|
|
+ try {
|
|
|
+ String result = AsciiUtils.asciiByteArray2HexStr(responseFrame.getData());
|
|
|
+ List<String> strList = HexadecimalUtil.getStrList(result, 4);
|
|
|
+ if (result.length() != 16) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0, len = strList.size(); i < len; i++) {
|
|
|
+ String list = strList.get(i);
|
|
|
+ String s1 = HexadecimalUtil.hexStringToByte(list);
|
|
|
+ String s2 = HexadecimalUtil.flipString(s1, 8);
|
|
|
+ sb.append(s2);
|
|
|
+ }
|
|
|
+ String s1 = sb.toString();
|
|
|
+ List<String> lis = Arrays.asList(s1.split(""));
|
|
|
+ ArrayList<String> list = new ArrayList(lis);
|
|
|
+ list.remove(0);
|
|
|
+ LogUtil.d("" + list.get(0) + list.get(1));
|
|
|
+// showErrorDialog(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
} else if (name.equals("X12")) {
|
|
|
- if (isLate) {
|
|
|
+ if (late == 0) {
|
|
|
+// if (isLate) {
|
|
|
String result = AsciiUtils.asciiByteArray2HexStr(responseFrame.getData());
|
|
|
List<String> strList = HexadecimalUtil.getStrList(result, 4);
|
|
|
StringBuilder sb = new StringBuilder();
|
|
@@ -804,9 +850,9 @@ public class MyService extends Service {
|
|
|
boolean[] isSelectCheckBox = Hawk.get(Name.ISSELECTCHECKBOX, null);
|
|
|
boolean[] isSelectPeopleCheckbox = Hawk.get(Name.ISSELECTPEOPLECHECKBOX, null);
|
|
|
for (int i = 0; i < TOTAL_SUM; i++) {
|
|
|
- sHomePageLocationList.set(i,list2.get(i + 2));
|
|
|
+ sHomePageLocationList.set(i, list2.get(i + 2));
|
|
|
}
|
|
|
- Log.d(TAG, "even1t: "+sHomePageLocationList.size());
|
|
|
+ Log.d(TAG, "even1t: " + sHomePageLocationList.size());
|
|
|
if (isSelectCheckBox == null) {//厕所状态为空,说明还没设置,也就是全部都监听
|
|
|
for (int i = 1; i <= TOTAL_SUM; i++) {//什么都监听
|
|
|
monitoring(list2.get(i + 1), i, list2.get(i + 7));
|
|
@@ -828,25 +874,29 @@ public class MyService extends Service {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- }else{
|
|
|
+ } else if (late == 1) {
|
|
|
ToastUtil.showToast("设备已过期,请充值后使用");
|
|
|
+ } else if (late == 2) {
|
|
|
+ ToastUtil.showToast("没有网络无法监听蹲位。");
|
|
|
}
|
|
|
} else if (name.equals("D2")) {
|
|
|
String data = String.valueOf(HexadecimalUtil.hex2dec(HexadecimalUtil.flipString(AsciiUtils.asciiByteArray2HexStr(responseFrame.getData())).get(0)));
|
|
|
// Log.d(TAG, "addCleanTimeD2event: " + data);
|
|
|
if (!sD2Data.equals(data)) {//如果相等,说明已经写入过了,我们需要先别写入
|
|
|
- switch (data){
|
|
|
- case "1":
|
|
|
- LogUtils.logWrite("设备开机完毕");
|
|
|
- break;
|
|
|
- case "5":
|
|
|
- LogUtils.logWrite("设备清洗中");
|
|
|
- break;
|
|
|
- case "7":
|
|
|
- LogUtils.logWrite("设备清洗完毕");
|
|
|
- break;
|
|
|
- }
|
|
|
+ switch (data) {
|
|
|
+ case "1":
|
|
|
+ LogUtils.logWrite("设备开机完毕");
|
|
|
+ break;
|
|
|
+ case "5":
|
|
|
+ LogUtils.logWrite("设备清洗中");
|
|
|
+ break;
|
|
|
+ case "7":
|
|
|
+ LogUtils.logWrite("设备清洗完毕");
|
|
|
+ break;
|
|
|
+ case "0":
|
|
|
+ LogUtils.logWrite("设备复位中");
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
this.sD2Data = data;//记录上次的data值
|
|
@@ -877,11 +927,23 @@ public class MyService extends Service {
|
|
|
public void run() {
|
|
|
synchronized (sCleaningLocationList) {
|
|
|
while (sCleaningLocationList.size() > 0) {
|
|
|
+ LogUtils.logWrite("开机完毕开始检查:" + sCleaningLocationList.size());
|
|
|
Integer first = sCleaningLocationList.getFirst();
|
|
|
HoleInformation holeInformation = sHoleInformationList.get(first - 1);
|
|
|
+ Log.d(TAG, "run: " + holeInformation.getState());
|
|
|
if (holeInformation.getState() != 0 && holeInformation.getState() != 2) {
|
|
|
Log.d(TAG, "被移除了3: " + first);
|
|
|
- sCleaningLocationList.removeFirst();
|
|
|
+ if (holeInformation.isUserAndEmpty()) {
|
|
|
+ sCleaningLocationList.removeFirst();
|
|
|
+ } else {
|
|
|
+ if (!isCleanOK) {//不再清洗的时候才去清洗。
|
|
|
+ //清洗次数增加
|
|
|
+ addTodayCleanCount(1, 0, 1);
|
|
|
+ cleanPositionNumX20(first, 4);
|
|
|
+ cleanCount++;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
if ("1".equals(holeInformation.getBodySensor())) {// 1表示有人,有人我们就移出他
|
|
|
Log.d(TAG, "run: 人体传感器检测到还有人,那么单纯靠人体传感器来执行。");
|
|
@@ -915,13 +977,15 @@ public class MyService extends Service {
|
|
|
//多线程,我们需要控制只执行一次?
|
|
|
Integer first = sCleaningLocationList.getFirst();//sCleaningLocationList取出来的数据从1开始。
|
|
|
HoleInformation holeInformation = sHoleInformationList.get(first - 1);
|
|
|
- holeInformation.setUserStates("2");
|
|
|
+ if (!"2".equals(holeInformation.getUserStates())) {
|
|
|
+ holeInformation.setUserStates("2");
|
|
|
+ }
|
|
|
Log.d(TAG, "isClean開始清洗add急停: " + holeInformation.getState());
|
|
|
if (holeInformation.getState() != 2) {
|
|
|
//如果在清洗中,那么就急停
|
|
|
isToiletClean = false;
|
|
|
sCleaningLocationList.removeFirst();//检测到厕所里面有人,那么我就移出她。但是移出,会不会影响其他的呢?
|
|
|
- mThreadPoolMyservice.stopSetMM10();
|
|
|
+ mThreadPoolMyservice.stopSetMM10();//去掉急停,就直接去掉,然后也去掉这个要清洗的厕所,因为肯定有人进去了。并且锁门了。
|
|
|
mThreadPoolMyservice.startSetMM10("M10");
|
|
|
Log.d(TAG, "sCleaningLocationList: 紧急停止");
|
|
|
}
|
|
@@ -1099,7 +1163,22 @@ public class MyService extends Service {
|
|
|
HoleInformation holeInformation = sHoleInformationList.get(number - 1);
|
|
|
holeInformation.setBodySensor(isSomeone);
|
|
|
holeInformation.setUserAndEmpty(true);
|
|
|
- if (!isCleanOK) holeInformation.setUserStates("1");
|
|
|
+ //0,也不等于1,也不等于2, 所以会改变。
|
|
|
+ if (sCleaningLocationList.size() > 0) {
|
|
|
+ LogUtil.d("addCleanTime first:" + sCleaningLocationList.getFirst() + ";number:" + number);
|
|
|
+ if (sCleaningLocationList.getFirst() != number) {
|
|
|
+ if (!("1".equals(holeInformation.getUserStates()))) {
|
|
|
+ //如果为0 ,或者为2,那么我们返回。因为要么清洗中,或者本来就是0.
|
|
|
+ holeInformation.setUserStates("1");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ holeInformation.setUserStates("1");
|
|
|
+ }
|
|
|
+// if (!"1".equals(holeInformation.getUserStates())) {
|
|
|
+// holeInformation.setUserStates("1");
|
|
|
+// }
|
|
|
+ Log.d(TAG, "addCleanTime1212: " + holeInformation.getState());
|
|
|
if (holeInformation.getState() != 1 && holeInformation.getState() != 3) {
|
|
|
holeInformation.setState(1);//上厕所
|
|
|
holeInformation.setTimeDuration(System.currentTimeMillis());//存储他上厕所的时间
|
|
@@ -1137,8 +1216,20 @@ public class MyService extends Service {
|
|
|
HoleInformation holeInformation = sHoleInformationList.get(number - 1);
|
|
|
holeInformation.setBodySensor(isSomeone);
|
|
|
holeInformation.setUserAndEmpty(false);
|
|
|
- if (!isCleanOK) holeInformation.setUserStates("0");
|
|
|
-
|
|
|
+ if (sCleaningLocationList.size() > 0) {
|
|
|
+ LogUtil.d("isClean first:" + sCleaningLocationList.getFirst() + ";number:" + number);
|
|
|
+ if (sCleaningLocationList.getFirst() != number) {
|
|
|
+ if (!("0".equals(holeInformation.getUserStates()))) {
|
|
|
+ //如果为0 ,或者为2,那么我们返回。因为要么清洗中,或者本来就是0.
|
|
|
+ holeInformation.setUserStates("0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ holeInformation.setUserStates("0");
|
|
|
+ }
|
|
|
+// if (!"0".equals(holeInformation.getUserStates())) {
|
|
|
+// holeInformation.setUserStates("0");
|
|
|
+// }
|
|
|
int state = holeInformation.getState();
|
|
|
if (state == 3) {
|
|
|
holeInformation.setState(4);
|
|
@@ -1216,7 +1307,7 @@ public class MyService extends Service {
|
|
|
Log.d(TAG, "cleanPositionNumX20厕所: " + number);
|
|
|
mThreadPoolMyservice.stopWriteDD120();
|
|
|
mThreadPoolMyservice.startWriteDD120("D120", "000" + data);
|
|
|
- LogUtils.logWrite("开始清洗"+data+"号厕所");//日志记录
|
|
|
+ LogUtils.logWrite("开始清洗" + data + "号厕所"+number);//日志记录
|
|
|
}
|
|
|
|
|
|
private boolean isOpenReadWarring = true;
|
|
@@ -1528,9 +1619,10 @@ public class MyService extends Service {
|
|
|
|
|
|
private Timer procedureISRunTimer;
|
|
|
private TimerTask procedureISRunTimerTask;
|
|
|
+
|
|
|
//判断程序是否在运行
|
|
|
private void procedureISRun() {
|
|
|
- stopTimerAndTimerTask(procedureISRunTimer,procedureISRunTimerTask);
|
|
|
+ stopTimerAndTimerTask(procedureISRunTimer, procedureISRunTimerTask);
|
|
|
procedureISRunTimer = new Timer();
|
|
|
procedureISRunTimerTask = new TimerTask() {
|
|
|
@Override
|