|
@@ -29,12 +29,14 @@ import com.hboxs.serialport.util.HexUtils;
|
|
|
import com.orhanobut.hawk.Hawk;
|
|
|
import com.sunzee.R;
|
|
|
import com.sunzee.base.BaseApplication;
|
|
|
+import com.sunzee.db.CleaningBeanDao;
|
|
|
import com.sunzee.db.WarringBeanDao;
|
|
|
import com.sunzee.model.Global;
|
|
|
import com.sunzee.model.Heartbeat;
|
|
|
import com.sunzee.model.HoleInformation;
|
|
|
import com.sunzee.model.HttpResult;
|
|
|
import com.sunzee.model.domain.AddAlarmRecordBean;
|
|
|
+import com.sunzee.model.domain.CleaningBean;
|
|
|
import com.sunzee.model.domain.ErrorBean;
|
|
|
import com.sunzee.model.domain.GetAdBean;
|
|
|
import com.sunzee.model.domain.HeartbeatBean;
|
|
@@ -50,6 +52,7 @@ import com.sunzee.retrofit.ApiClient;
|
|
|
import com.sunzee.retrofit.ApiStores;
|
|
|
import com.sunzee.thread.advanceparameter.ThreadPoolAdvanceParameter;
|
|
|
import com.sunzee.thread.myservice.ThreadPoolMyservice;
|
|
|
+import com.sunzee.ui.activity.HomeActivity;
|
|
|
import com.sunzee.ui.dialog.WarringDialog;
|
|
|
import com.sunzee.utils.FileUtil;
|
|
|
import com.sunzee.utils.HexadecimalUtil;
|
|
@@ -64,8 +67,11 @@ import com.wuxiaolong.androidutils.library.LogUtil;
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
+import org.greenrobot.greendao.query.QueryBuilder;
|
|
|
+import org.greenrobot.greendao.query.WhereCondition;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
@@ -91,7 +97,7 @@ public class MyService extends Service {
|
|
|
private boolean isRead = true;
|
|
|
private boolean isRegularCleaning = false;
|
|
|
private ThreadPoolAdvanceParameter mPoolAdvanceParameter = new ThreadPoolAdvanceParameter();
|
|
|
- public final static int TOTAL_SUM = 14;
|
|
|
+ public final static int TOTAL_SUM = 6;
|
|
|
|
|
|
//存储两个数据:是否上过厕所,一开始上厕所的时间是什么时候
|
|
|
//CopyOnWriteArrayList并不是完全意义上的线程安全,如果涉及到remove操作,一定要谨慎处理。
|
|
@@ -115,7 +121,7 @@ public class MyService extends Service {
|
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
|
Log.d(TAG, "MyServiceonCreate: ");
|
|
|
- synchronized (sCleaningLocationList){
|
|
|
+ synchronized (sCleaningLocationList) {
|
|
|
sHoleInformationList.clear();
|
|
|
for (int i = 0; i < TOTAL_SUM; i++) {
|
|
|
sHoleInformationList.add(new HoleInformation(2, 0));//初始化
|
|
@@ -186,6 +192,30 @@ public class MyService extends Service {
|
|
|
if (warringDialog == null) {
|
|
|
warringBeanDao = BaseApplication.getInstances().getDaoSession().getWarringBeanDao();
|
|
|
}
|
|
|
+ if (cleaningBeanDao == null) {
|
|
|
+ cleaningBeanDao = BaseApplication.getInstances().getDaoSession().getCleaningBeanDao();
|
|
|
+ }
|
|
|
+ /* if (cleaningBeanDao==null) {
|
|
|
+ cleaningBeanDao = BaseApplication.getInstances().getDaoSession().getCleaningBeanDao();
|
|
|
+
|
|
|
+ //初始化数据
|
|
|
+ //取出数据
|
|
|
+ QueryBuilder<CleaningBean> qb = cleaningBeanDao.queryBuilder();
|
|
|
+ List<CleaningBean> list = qb.where(new WhereCondition.StringCondition("TIME >= ? and TIME <= ?",
|
|
|
+ tomorrowDateStr(0), tomorrowDateStr(1))).build().list();
|
|
|
+ Log.d(TAG, "tomorrowDateStronStartCommand: "+list.size());
|
|
|
+ if (list.size()<=0) {
|
|
|
+ //添加今天的数据,如果一直不关机呢?那么我们就需要当前时间如何重新插入数据。
|
|
|
+ CleaningBean cleaningBean = new CleaningBean();
|
|
|
+ cleaningBean.setOutCount("0");
|
|
|
+ cleaningBean.setInCount("0");
|
|
|
+ cleaningBean.setCleanCount("0");
|
|
|
+ cleaningBean.setTime(System.currentTimeMillis());
|
|
|
+ long insert = cleaningBeanDao.insert(cleaningBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ }*/
|
|
|
+
|
|
|
if (isRead) {
|
|
|
isRead = !isRead;
|
|
|
mThreadPoolMyservice.stopReadM600();
|
|
@@ -198,6 +228,50 @@ public class MyService extends Service {
|
|
|
//return START_STICKY ;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增加清洗次数
|
|
|
+ */
|
|
|
+ public void addTodayCleanCount(int cleanCount, int inCount, int outCount) {
|
|
|
+ QueryBuilder<CleaningBean> qb = cleaningBeanDao.queryBuilder();
|
|
|
+ List<CleaningBean> list = qb.where(new WhereCondition.StringCondition("TIME >= ? and TIME <= ?",
|
|
|
+ tomorrowDateStr(0), tomorrowDateStr(1))).build().list();
|
|
|
+ if (list.size() > 0) {
|
|
|
+ CleaningBean cleaningBean = list.get(0);
|
|
|
+ cleaningBean.setCleanCount((Integer.valueOf(cleaningBean.getCleanCount()) + cleanCount) + "");
|
|
|
+
|
|
|
+ cleaningBean.setInCount(Integer.valueOf(cleaningBean.getInCount()) + inCount + "");
|
|
|
+ cleaningBean.setOutCount(Integer.valueOf(cleaningBean.getOutCount()) + outCount + "");
|
|
|
+
|
|
|
+ cleaningBeanDao.update(cleaningBean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取明天的日期字符串
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static long tomorrowDateStr(int number) {
|
|
|
+ Date date = new Date();//取时间
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date);
|
|
|
+ //把日期往后增加一天.整数往后推,负数往前移动
|
|
|
+ calendar.add(calendar.DATE, number);
|
|
|
+ //这个时间就是日期往后推一天的结果
|
|
|
+ date = calendar.getTime();
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String tomorrowStr = formatter.format(date);
|
|
|
+ Date parse = null;
|
|
|
+ try {
|
|
|
+ parse = formatter.parse(tomorrowStr);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return parse.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onDestroy() {
|
|
|
super.onDestroy();
|
|
@@ -361,6 +435,14 @@ public class MyService extends Service {
|
|
|
//开始清洗 随机清洗,会给要清洗的蹲位是
|
|
|
cleanPositionNum(messageEvent.getData());
|
|
|
break;
|
|
|
+ case "allcleaning":
|
|
|
+ if (!PreventSpeedClickUtil.isFastClick()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //监听开机按钮的全蹲位清洗
|
|
|
+ cleanPositionNumX20((Integer)messageEvent.getData(),0);
|
|
|
+ cleanPositionNum(messageEvent.getData());
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
|
|
@@ -919,7 +1001,7 @@ public class MyService extends Service {
|
|
|
}
|
|
|
|
|
|
//------------------------------------------------------------------------广告 end---------------------------------
|
|
|
- private boolean isAwait = true;
|
|
|
+ private boolean isAwait = false;
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
public void event(Message messageEvent) {
|
|
@@ -1021,30 +1103,7 @@ public class MyService extends Service {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- }/* else if (name.equals("X12")) {
|
|
|
- String results = HexadecimalUtil.hexStringToByte(AsciiUtils.asciiByteArray2HexStr(responseFrame.getData()));
|
|
|
- String s1 = HexadecimalUtil.flipString(results, 6).substring(0, TOTAL_SUM);//6个厕所蹲位
|
|
|
- List<String> lis = Arrays.asList(s1.split(""));//第0位会是空字符串
|
|
|
- ArrayList<String> result = new ArrayList(lis);//
|
|
|
- result.remove(0);
|
|
|
- String s = Arrays.toString(result.toArray());
|
|
|
- Log.d(TAG, "X12event: "+result.size()+";s:"+s);
|
|
|
- // Log.d(TAG, "result event: " + result.get(0) + result.get(1));
|
|
|
-
|
|
|
- //todo 是否监听
|
|
|
- //监控1号厕所
|
|
|
- monitoring(result.get(0), 1);
|
|
|
- //监控2号厕所
|
|
|
- monitoring(result.get(1), 2);
|
|
|
- //监控3号厕所
|
|
|
- monitoring(result.get(2), 3);
|
|
|
- //监控4号厕所
|
|
|
- monitoring(result.get(3), 4);
|
|
|
- //监控5号厕所
|
|
|
- monitoring(result.get(4), 5);
|
|
|
- //监控6号厕所
|
|
|
- monitoring(result.get(5), 6);
|
|
|
- }*/else if(name.equals("X12")){
|
|
|
+ } else if (name.equals("X12")) {
|
|
|
String result = AsciiUtils.asciiByteArray2HexStr(responseFrame.getData());
|
|
|
List<String> strList = HexadecimalUtil.getStrList(result, 4);
|
|
|
StringBuilder sb = new StringBuilder();
|
|
@@ -1061,21 +1120,48 @@ public class MyService extends Service {
|
|
|
list2.remove(0);
|
|
|
|
|
|
String s = Arrays.toString(list2.toArray());
|
|
|
- Log.d(TAG, "X12event1: "+s);
|
|
|
+ Log.d(TAG, "X12event1: " + s);
|
|
|
+ //如果没有开机,那么这里面的代码不会执行。
|
|
|
+ if (!HomeActivity.isStartingUp) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //监控1号厕所:门锁,以及人体传感器。根据厕所的个数来决定要监听的厕所的个数
|
|
|
+ for (int i = 1; i<=TOTAL_SUM;i++){
|
|
|
+ if (i==5 |i==6) {
|
|
|
+ monitoring(list2.get(i+1), i, "0");
|
|
|
+ bodySensor(i, list2.get(i+7));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ monitoring(list2.get(i+1), i, list2.get(i+7));
|
|
|
+ bodySensor(i, list2.get(i+7));
|
|
|
+ }
|
|
|
+
|
|
|
+ //监控1号厕所:门锁,以及人体传感器。
|
|
|
+ /* monitoring(list2.get(2), 1, list2.get(8));
|
|
|
+ //监控2号厕所
|
|
|
+ monitoring(list2.get(3), 2, list2.get(9));
|
|
|
+ //监控3号厕所
|
|
|
+ monitoring(list2.get(4), 3, list2.get(10));
|
|
|
+ //监控4号厕所
|
|
|
+ monitoring(list2.get(5), 4, list2.get(11));
|
|
|
+ //监控5号厕所
|
|
|
+ monitoring(list2.get(6), 5, "0");
|
|
|
+ //监控6号厕所
|
|
|
+ monitoring(list2.get(7), 6, "0" );*/
|
|
|
|
|
|
|
|
|
//监控1号厕所
|
|
|
- monitoring(list2.get(2), 1,list2.get(8));
|
|
|
+ /* bodySensor(1, list2.get(8));
|
|
|
//监控2号厕所
|
|
|
- monitoring(list2.get(3), 2,list2.get(9));
|
|
|
+ bodySensor(2, list2.get(9));
|
|
|
//监控3号厕所
|
|
|
- monitoring(list2.get(4), 3,list2.get(10));
|
|
|
+ bodySensor(3, list2.get(10));
|
|
|
//监控4号厕所
|
|
|
- monitoring(list2.get(5), 4,"0"/*list2.get(11)*/);
|
|
|
+ bodySensor(4, list2.get(11));
|
|
|
//监控5号厕所
|
|
|
- monitoring(list2.get(6), 5,"0"/*list2.get(12)*/);
|
|
|
+ bodySensor(5, list2.get(12));
|
|
|
//监控6号厕所
|
|
|
- monitoring(list2.get(7), 6,"0"/*list2.get(13)*/);
|
|
|
+ bodySensor(6, list2.get(13));*/
|
|
|
|
|
|
} else if (name.equals("D2")) {
|
|
|
String data = String.valueOf(HexadecimalUtil.hex2dec(HexadecimalUtil.flipString(AsciiUtils.asciiByteArray2HexStr(responseFrame.getData())).get(0)));
|
|
@@ -1089,6 +1175,9 @@ public class MyService extends Service {
|
|
|
if (!isToiletClean) {
|
|
|
isToiletClean = true;
|
|
|
}
|
|
|
+ if (isCleanOK) {
|
|
|
+ isCleanOK = false;
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case "1": //第一次待机中,开机完毕
|
|
@@ -1097,6 +1186,7 @@ public class MyService extends Service {
|
|
|
synchronized (sCleaningLocationList) {//多线程操作需要加上同步锁
|
|
|
if (isAwait) {
|
|
|
isAwait = false;
|
|
|
+ isCleanOK = false;
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
@@ -1104,15 +1194,19 @@ public class MyService extends Service {
|
|
|
while (sCleaningLocationList.size() > 0) {
|
|
|
Integer first = sCleaningLocationList.getFirst();
|
|
|
HoleInformation holeInformation = sHoleInformationList.get(first - 1);
|
|
|
- if (holeInformation.getState() != 0 && holeInformation.getState() != 2 && "1".equals(holeInformation.getBodySensor())) {
|
|
|
- //被移除了
|
|
|
- Log.d(TAG, "被移除了1: " + first);
|
|
|
- sCleaningLocationList.removeFirst();
|
|
|
- } else if (holeInformation.getState() != 0 && holeInformation.getState() != 2) {
|
|
|
+ if (holeInformation.getState() != 0 && holeInformation.getState() != 2) {
|
|
|
Log.d(TAG, "被移除了3: " + first);
|
|
|
sCleaningLocationList.removeFirst();
|
|
|
- }else {
|
|
|
- cleanPositionNumX20(first);
|
|
|
+ } else {
|
|
|
+ if ("1".equals(holeInformation.getBodySensor())) {// 1表示有人,有人我们就移出他
|
|
|
+ Log.d(TAG, "run: 人体传感器检测到还有人,那么单纯靠人体传感器来执行。");
|
|
|
+ //这里需要判断门是否关着,如果光着,我们没有必要使用人体传感器,如果门关着,都不会添加到这里面
|
|
|
+ holeInformation.setInBodySensor(true);//可以开始判断了。
|
|
|
+ sCleaningLocationList.removeFirst();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ addTodayCleanCount(1, 0, 0);
|
|
|
+ cleanPositionNumX20(first, 1);
|
|
|
Log.d(TAG, "isClean開始清洗add: " + first);
|
|
|
cleanCount++;
|
|
|
return;
|
|
@@ -1120,7 +1214,7 @@ public class MyService extends Service {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- },6000);
|
|
|
+ }, 6000);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -1128,24 +1222,24 @@ public class MyService extends Service {
|
|
|
//todo 清洗中,需要各个10秒再开始
|
|
|
synchronized (sCleaningLocationList) {
|
|
|
//todo 必须sCleaningLocationList和sHoleInformationList不为空。才能执行里面的代码。
|
|
|
- if (sCleaningLocationList.size()>0 &&sHoleInformationList.size()>0) {
|
|
|
+ if (sCleaningLocationList.size() > 0 && sHoleInformationList.size() > 0) {
|
|
|
if (isToiletClean) {
|
|
|
isCleanOK = true;
|
|
|
//多线程,我们需要控制只执行一次?
|
|
|
Integer first = sCleaningLocationList.getFirst();//sCleaningLocationList取出来的数据从1开始。
|
|
|
HoleInformation holeInformation = sHoleInformationList.get(first - 1);
|
|
|
+ holeInformation.setUserStates("2");
|
|
|
Log.d(TAG, "isClean開始清洗add急停: " + holeInformation.getState());
|
|
|
if (holeInformation.getState() != 2) {
|
|
|
//如果在清洗中,那么就急停
|
|
|
isToiletClean = false;
|
|
|
+ sCleaningLocationList.removeFirst();//检测到厕所里面有人,那么我就移出她。但是移出,会不会影响其他的呢?
|
|
|
mThreadPoolMyservice.stopSetMM10();
|
|
|
mThreadPoolMyservice.startSetMM10("M10");
|
|
|
Log.d(TAG, "sCleaningLocationList: 紧急停止");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
break;
|
|
|
case "7"://清洗完毕----清洗過程中還是清洗完畢
|
|
@@ -1153,58 +1247,60 @@ public class MyService extends Service {
|
|
|
if (isCleanOK) {
|
|
|
isCleanOK = false;
|
|
|
|
|
|
- //准备清洗下一个厕所,如果为10次,那么就需要复位。
|
|
|
- if (cleanCount >= 10) {
|
|
|
- cleanCount = 0;
|
|
|
- mThreadPoolMyservice.stopWriteMM3();
|
|
|
- mThreadPoolMyservice.startWriteMM3("M3");
|
|
|
- return;
|
|
|
- }
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
synchronized (sCleaningLocationList) {//移除这里出现了问题。
|
|
|
- if (sCleaningLocationList.size() != 0) {
|
|
|
- Integer first = null;
|
|
|
- //上一个清洗的厕所123
|
|
|
- Log.d(TAG, "被移除了2: " + first);
|
|
|
- last = sCleaningLocationList.removeFirst();
|
|
|
- //如果集合大于0,那么我就取出第一个位置,进行判断是否正在上厕所,如果是,那么就需要移除,继续下一个,
|
|
|
- while (sCleaningLocationList.size() > 0) {
|
|
|
- first = sCleaningLocationList.getFirst();//现在要清洗的厕所。456
|
|
|
-// if (sHoleInformationList.get(first-1).getState()==3) {
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- for (Integer integer1 : sCleaningLocationList) {
|
|
|
- sb.append(integer1);
|
|
|
- }
|
|
|
+ if (sCleaningLocationList.size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer first = null;
|
|
|
+ //上一个清洗的厕所123
|
|
|
+ Log.d(TAG, "被移除了2: " + first);
|
|
|
+ last = sCleaningLocationList.removeFirst();
|
|
|
+ //准备清洗下一个厕所,如果为10次,那么就需要复位。移除之后再复位。
|
|
|
+ if (cleanCount >= 10) {
|
|
|
+ cleanCount = 0;
|
|
|
+ mThreadPoolMyservice.stopWriteMM3();
|
|
|
+ mThreadPoolMyservice.startWriteMM3("M3");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //如果集合大于0,那么我就取出第一个位置,进行判断是否正在上厕所,如果是,那么就需要移除,继续下一个,
|
|
|
+ while (sCleaningLocationList.size() > 0) {
|
|
|
|
|
|
- HoleInformation holeInformation = sHoleInformationList.get(first - 1);
|
|
|
- if (holeInformation.getState() != 0 && holeInformation.getState() != 2 && "1".equals(holeInformation.getBodySensor())) {
|
|
|
- Log.d(TAG, "被移除了3: " + first);
|
|
|
- sCleaningLocationList.removeFirst();
|
|
|
- //如果没有人在里面,但是人体传感器检测到有人,那么移除
|
|
|
- //如果有人在里面,即使人体创奇检测到有人或者没人,都移除。
|
|
|
- } else if (holeInformation.getState() != 0 && holeInformation.getState() != 2) {
|
|
|
- Log.d(TAG, "被移除了3: " + first);
|
|
|
- sCleaningLocationList.removeFirst();
|
|
|
- } else {
|
|
|
- if ((last == 1 || last == 2 || last == 3) && (first == 4 || first == 5 || first == 6)) {
|
|
|
- mThreadPoolMyservice.stopWriteMM3();
|
|
|
- mThreadPoolMyservice.startWriteMM3("M3");
|
|
|
- Log.d(TAG, "isClean: 开始复位4");
|
|
|
- return;
|
|
|
- }
|
|
|
- cleanPositionNumX20(first);
|
|
|
- Log.d(TAG, "isClean開始清洗add: " + first);
|
|
|
- cleanCount++;
|
|
|
+ first = sCleaningLocationList.getFirst();//现在要清洗的厕所。456
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (Integer integer1 : sCleaningLocationList) {
|
|
|
+ sb.append(integer1);
|
|
|
+ }
|
|
|
+ HoleInformation holeInformation = sHoleInformationList.get(first - 1);
|
|
|
+ if (holeInformation.getState() != 0 && holeInformation.getState() != 2) {
|
|
|
+ Log.d(TAG, "被移除了3: " + first);
|
|
|
+ sCleaningLocationList.removeFirst();
|
|
|
+ } else {
|
|
|
+ if ((last == 1 || last == 2 || last == 3) && (first == 4 || first == 5 || first == 6)) {
|
|
|
+ mThreadPoolMyservice.stopWriteMM3();
|
|
|
+ mThreadPoolMyservice.startWriteMM3("M3");
|
|
|
+ Log.d(TAG, "isClean: 开始复位4");
|
|
|
return;
|
|
|
}
|
|
|
+ //判断是否有人,是否可以清洗,如果可以,那么继续走下去,如果不可以,直接移除
|
|
|
+ if ("1".equals(holeInformation.getBodySensor())) {//这里使用的判断不对,因为一开始就是false
|
|
|
+ Log.d(TAG, "run: 人体传感器检测到还有人,那么单纯靠人体传感器来执行。");
|
|
|
+ holeInformation.setInBodySensor(true);//可以开始判断了。
|
|
|
+ sCleaningLocationList.removeFirst();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ addTodayCleanCount(1, 0, 0);
|
|
|
+ cleanPositionNumX20(first, 2);
|
|
|
+ Log.d(TAG, "isClean開始清洗add: " + first);
|
|
|
+ cleanCount++;
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- },6000);
|
|
|
+ }, 6000);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -1217,27 +1313,66 @@ public class MyService extends Service {
|
|
|
ArrayList<String> results = HexadecimalUtil.flipString(result);
|
|
|
setAdvanced(name, results, mPoolAdvanceParameter);
|
|
|
}
|
|
|
-
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void bodySensor(int position, String isSomeone1) {
|
|
|
+ synchronized (sCleaningLocationList) {
|
|
|
+ HoleInformation holeInformation = sHoleInformationList.get(position - 1);
|
|
|
+ //表示这个厕所可以单纯靠人体传感器来判断是否需要开始清洗了。
|
|
|
+ if (!(holeInformation.isInBodySensor() && "0".equals(isSomeone1))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //如果靠人体传感器来,那么我们需要附加一个条件就是人体传感器必须灭了才行
|
|
|
+ holeInformation.setInBodySensor(false);
|
|
|
+ Log.d(TAG, "bodySensor 人体传感器开始执行了。" + position + isSomeone1);
|
|
|
+ if (sCleaningLocationList.size() == 0) {
|
|
|
+ //添加进来,并且开始清洗。
|
|
|
+ Log.d(TAG, "addLastbodySensor: 1");
|
|
|
+ if (isAwait) {//为true,表示复位中
|
|
|
+ //只是添加进来
|
|
|
+ Log.d(TAG, "addLastbodySensor: 2");
|
|
|
+ addTodayCleanCount(0, 0, 1);
|
|
|
+ sCleaningLocationList.addLast(position);
|
|
|
+ } else {//表示没有复位中。那么就可以直接清洗
|
|
|
+ sCleaningLocationList.addLast(position);
|
|
|
+ if (last == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ((last == 1 || last == 2 || last == 3) && (position == 4 || position == 5 || position == 6)) {
|
|
|
+ Log.d(TAG, "isClean: 開始复位1");
|
|
|
+ mThreadPoolMyservice.stopWriteMM3();
|
|
|
+ mThreadPoolMyservice.startWriteMM3("M3");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cleanCount++;
|
|
|
+ addTodayCleanCount(1, 0, 1);
|
|
|
+ cleanPositionNumX20(position, 3);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //只是添加进来
|
|
|
+ Log.d(TAG, "addLastbodySensor: 2");
|
|
|
+ addTodayCleanCount(0, 0, 1);
|
|
|
+ sCleaningLocationList.addLast(position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void monitoring(String number, int position, String isSomeone1) {
|
|
|
- // Log.d(TAG, "monitoring: " + number + position);
|
|
|
synchronized (sCleaningLocationList) {//多线程操作需要加上同步锁
|
|
|
- if ("0".equals(number)) {//
|
|
|
+ if ("0".equals(number)) {//没人
|
|
|
//是否加入清洗
|
|
|
- isClean(position,isSomeone1);
|
|
|
- } else if ("1".equals(number)) {
|
|
|
+ isClean(position, isSomeone1);
|
|
|
+ } else if ("1".equals(number)) {//有人
|
|
|
//记录
|
|
|
- addCleanTime(position,isSomeone1);
|
|
|
+ addCleanTime(position, isSomeone1);
|
|
|
}
|
|
|
- Log.d(TAG, "isClean開始清洗add信号: 厕所"+position+",信号为:" + number);
|
|
|
-
|
|
|
+ Log.d(TAG, "isClean開始清洗add信号: 厕所" + position + ",信号为:" + number);
|
|
|
}
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
private void addCleanTime(int number, String isSomeone) {
|
|
@@ -1246,21 +1381,22 @@ public class MyService extends Service {
|
|
|
* 将标志位变为0.,如果我为0 就不执行了。避免时间一直更新。
|
|
|
* 存储当前的时间,到指定的集合中【标志位,0time】
|
|
|
*/
|
|
|
-// Log.d(TAG, "addCleanTime: 为零isCleanaddCleanTime1");
|
|
|
HoleInformation holeInformation = sHoleInformationList.get(number - 1);
|
|
|
holeInformation.setBodySensor(isSomeone);
|
|
|
-// Log.d(TAG, "为零isCleanaddCleanTime11: " + sHoleInformationList.size() + holeInformation.getState());
|
|
|
-// Log.d(TAG, "为零isCleanaddCleanTime12: " + (number - 1));
|
|
|
+ holeInformation.setUserAndEmpty(true);
|
|
|
+ if (!isCleanOK) holeInformation.setUserStates("0");
|
|
|
if (holeInformation.getState() != 1 && holeInformation.getState() != 3) {
|
|
|
holeInformation.setState(1);//上厕所
|
|
|
holeInformation.setTimeDuration(System.currentTimeMillis());//存储他上厕所的时间
|
|
|
+ holeInformation.setInBodySensor(false);//进厕所了,表示不靠人体传感器来清洗。
|
|
|
+ Log.d(TAG, "run: 重新上厕所了,那么我们就需要取消单纯靠人体传感器来执行了。");
|
|
|
} else if (holeInformation.getState() == 1) {
|
|
|
if (System.currentTimeMillis() - holeInformation.getTimeDuration() > 10000) {
|
|
|
+ holeInformation.setInBodySensor(false);//进厕所了,表示不靠人体传感器来清洗。
|
|
|
//將其標誌位上過廁所。
|
|
|
+ addTodayCleanCount(0, 1, 0);
|
|
|
holeInformation.setState(3);
|
|
|
- // Log.d(TAG, "addCleanTime: 上厕所超过20秒");
|
|
|
- } else {
|
|
|
- // Log.d(TAG, "addCleanTime: 上厕所没超过20秒");
|
|
|
+ //进入厕所了,那么我们需要统计。
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1285,38 +1421,53 @@ public class MyService extends Service {
|
|
|
*/
|
|
|
HoleInformation holeInformation = sHoleInformationList.get(number - 1);
|
|
|
holeInformation.setBodySensor(isSomeone);
|
|
|
+ holeInformation.setUserAndEmpty(false);
|
|
|
+ if (!isCleanOK) holeInformation.setUserStates("1");
|
|
|
+
|
|
|
int state = holeInformation.getState();
|
|
|
if (state == 3) {
|
|
|
+
|
|
|
holeInformation.setState(4);
|
|
|
holeInformation.setOutTimeDuration(System.currentTimeMillis());//存储他上厕所的时间
|
|
|
} else if (holeInformation.getState() == 4) {
|
|
|
- if (System.currentTimeMillis() - holeInformation.getOutTimeDuration() > 10000) {
|
|
|
+ if (System.currentTimeMillis() - holeInformation.getOutTimeDuration() > 5000) {
|
|
|
//上廁所超過20秒,那麼將狀態改為上廁所狀態。
|
|
|
- Log.d(TAG, "为零isClean: " + sCleaningLocationList.size());
|
|
|
+ Log.d(TAG, "人体传感器为零isClean: " + sCleaningLocationList.size());
|
|
|
if (sCleaningLocationList.size() == 0) {
|
|
|
- //如果不包含,那么就走这里
|
|
|
- sCleaningLocationList.addLast(number);
|
|
|
- Log.d(TAG, "为零isCleannumber4: " + number);
|
|
|
- if (last != null) {
|
|
|
- if ((last == 1 || last == 2 || last == 3) && (number == 4 || number == 5 || number == 6)) {
|
|
|
- Log.d(TAG, "isClean: 開始复位1");
|
|
|
- mThreadPoolMyservice.stopWriteMM3();
|
|
|
- mThreadPoolMyservice.startWriteMM3("M3");
|
|
|
- return;
|
|
|
- }
|
|
|
+ //如果人体传感器检测没人,那么就走如下的逻辑,如果有人,那么这里跳过。
|
|
|
+ Log.d(TAG, number + "号厕所cleanPositionNumX20人体传感器isClean: " + holeInformation.getBodySensor());
|
|
|
+ if (!"0".equals(holeInformation.getBodySensor())) {
|
|
|
+ return;
|
|
|
}
|
|
|
- cleanCount++;//
|
|
|
- if ("1".equals(holeInformation.getBodySensor())) {
|
|
|
- sCleaningLocationList.removeFirst();
|
|
|
- Log.d(TAG, "holeInformation被移除了。: ");
|
|
|
- }else{
|
|
|
- cleanPositionNumX20(number);
|
|
|
+ if (isAwait) {//为true,表示复位中
|
|
|
+ addTodayCleanCount(0, 0, 1);
|
|
|
+ sCleaningLocationList.addLast(number);
|
|
|
+ } else {
|
|
|
+ Log.d(TAG, "人体传感器不亮了" + holeInformation.getBodySensor());
|
|
|
+ //如果不包含,那么就走这里
|
|
|
+ Log.d(TAG, "addLastbodySensor: 3");
|
|
|
+ sCleaningLocationList.addLast(number);
|
|
|
+ Log.d(TAG, "为零isCleannumber4: " + number);
|
|
|
+ if (last != null) {
|
|
|
+ if ((last == 1 || last == 2 || last == 3) && (number == 4 || number == 5 || number == 6)) {
|
|
|
+ Log.d(TAG, "isClean: 開始复位1");
|
|
|
+ mThreadPoolMyservice.stopWriteMM3();
|
|
|
+ mThreadPoolMyservice.startWriteMM3("M3");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cleanCount++;
|
|
|
+ //清洗次数增加
|
|
|
+ addTodayCleanCount(1, 0, 1);
|
|
|
+ cleanPositionNumX20(number, 4);
|
|
|
+ Log.d(TAG, "isClean開始清洗add: " + number);
|
|
|
+ Log.d(TAG, "addCleanTimeisClean: " + "開始清洗");
|
|
|
}
|
|
|
- Log.d(TAG, "isClean開始清洗add: " + number);
|
|
|
- Log.d(TAG, "addCleanTimeisClean: " + "開始清洗");
|
|
|
+ holeInformation.setState(2);//改为2或者0都可以。
|
|
|
+
|
|
|
} else {
|
|
|
//那么我们就需要判断是否在清洗,通过一个标志位。清洗中,清洗完毕
|
|
|
- int index = 100;
|
|
|
+ int index = 100;//如果已经存在,那么就移除后假如
|
|
|
for (int i = 0; i < sCleaningLocationList.size(); i++) {
|
|
|
Log.d(TAG, "isClean111: " + (sCleaningLocationList.get(i) == (number)) + "" + sCleaningLocationList.get(i) + (number));
|
|
|
if (sCleaningLocationList.get(i) == (number)) {
|
|
@@ -1327,16 +1478,19 @@ public class MyService extends Service {
|
|
|
}
|
|
|
if (index != 100) {
|
|
|
Log.d(TAG, "被移除了4: " + index);
|
|
|
+ addTodayCleanCount(0, 0, 1);
|
|
|
sCleaningLocationList.remove(index);//如果移除后等于0,集合大小等于0,那么开始清洗。
|
|
|
+ Log.d(TAG, "addLastbodySensor: 4");
|
|
|
sCleaningLocationList.addLast(number);
|
|
|
} else {
|
|
|
+ addTodayCleanCount(0, 0, 1);
|
|
|
+ Log.d(TAG, "addLastbodySensor: 5");
|
|
|
sCleaningLocationList.addLast(number);
|
|
|
}
|
|
|
Log.d(TAG, "addCleanTime: 清洗集合個數大於0:");
|
|
|
+ holeInformation.setState(2);//改为2或者0都可以。
|
|
|
}
|
|
|
- holeInformation.setState(2);//改为2或者0都可以。
|
|
|
- } else {
|
|
|
- Log.d(TAG, "addCleanTime进厕所没超过20秒 ");
|
|
|
+
|
|
|
}
|
|
|
} else if (holeInformation.getState() == 1) {
|
|
|
if (holeInformation.getState() != 2) {
|
|
@@ -1346,7 +1500,8 @@ public class MyService extends Service {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void cleanPositionNumX20(int data) {
|
|
|
+ private void cleanPositionNumX20(int data, int number) {
|
|
|
+ Log.d(TAG, "cleanPositionNumX20厕所: " + number);
|
|
|
mThreadPoolMyservice.stopWriteDD120();
|
|
|
mThreadPoolMyservice.startWriteDD120("D120", "000" + data);
|
|
|
}
|
|
@@ -1455,6 +1610,7 @@ public class MyService extends Service {
|
|
|
}
|
|
|
|
|
|
private WarringBeanDao warringBeanDao;
|
|
|
+ private CleaningBeanDao cleaningBeanDao;
|
|
|
|
|
|
/**
|
|
|
* @param key
|
|
@@ -1654,9 +1810,3 @@ public class MyService extends Service {
|
|
|
TimerUtil.stopTimerAndTimerTask(timerGetTime, timerTaskGetTime);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-//todo 重启触摸屏后回出现问题:有的已经在清洗了,但是安卓屏幕不认。所以就会开始清洗。
|
|
|
-/**
|
|
|
- * 如何优化呢?
|
|
|
- * 1.就需要
|
|
|
- */
|