|
@@ -1,9 +1,20 @@
|
|
|
package com.sunzee.service;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.Log;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
+import com.hboxs.serialport.SerialPortDevice;
|
|
|
+import com.hboxs.serialport.SerialPortManager;
|
|
|
+import com.hboxs.serialport.SerialPortSendQueue;
|
|
|
+import com.hboxs.serialport.frame.RstCommandFrame;
|
|
|
+import com.hboxs.serialport.frame.SetCommandFrame;
|
|
|
+import com.hboxs.serialport.frame.WriteCommandFrame;
|
|
|
+import com.hboxs.serialport.message.Message;
|
|
|
+import com.hboxs.serialport.util.ByteUtils;
|
|
|
+import com.hboxs.serialport.util.HexUtils;
|
|
|
import com.igexin.sdk.GTIntentService;
|
|
|
import com.igexin.sdk.message.GTCmdMessage;
|
|
|
import com.igexin.sdk.message.GTNotificationMessage;
|
|
@@ -30,6 +41,8 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Timer;
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
import io.reactivex.Observable;
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
@@ -96,7 +109,7 @@ public class MyIntentService extends GTIntentService {
|
|
|
String kind = geTuiBean.getKind();
|
|
|
switch (kind) {
|
|
|
case "clean":
|
|
|
- //开始清洗
|
|
|
+ //一间清洗
|
|
|
startClean(gson, geTuiBean, kind);
|
|
|
break;
|
|
|
case "statusType":
|
|
@@ -104,10 +117,14 @@ public class MyIntentService extends GTIntentService {
|
|
|
statusType(gson, geTuiBean, kind);
|
|
|
break;
|
|
|
case "pushTimeRule":
|
|
|
- LogUtil.d(TAG, "pushTimeRule: ");
|
|
|
+ LogUtil.d(TAG, "MyIntentServicepushTimeRule: ");
|
|
|
//广告规则
|
|
|
changeAdRules(geTuiBean);
|
|
|
break;
|
|
|
+ case "Param":
|
|
|
+ //更新参数。
|
|
|
+ updataParam(gson, geTuiBean, kind);
|
|
|
+ break;
|
|
|
//不需要更新广告了,而是更具规则来下载广告。
|
|
|
// case "push":
|
|
|
// LogUtil.d(TAG, "push: ");
|
|
@@ -122,6 +139,115 @@ public class MyIntentService extends GTIntentService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void updataParam(Gson gson, GeTuiBean geTuiBean, String kind) {
|
|
|
+ String[] split = geTuiBean.getKind_data().split(":");
|
|
|
+ String address = split[0];
|
|
|
+ String data = split[1];
|
|
|
+ if (!TextUtils.isEmpty(address) || !TextUtils.isEmpty(data)) {
|
|
|
+ switch (address) {
|
|
|
+ //复位和置位 0为启动,1为关闭。
|
|
|
+ case "M311":
|
|
|
+ case "M312":
|
|
|
+ case "M313":
|
|
|
+ case "M315":
|
|
|
+ case "M316":
|
|
|
+ case "M317":
|
|
|
+ case "M318":
|
|
|
+ case "M17":
|
|
|
+ if ("0".equals(data)) {
|
|
|
+ startSet(address);
|
|
|
+ } else {
|
|
|
+ startRst(address);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ //写入,写入后需要上传。
|
|
|
+ case "D426":
|
|
|
+ case "D427":
|
|
|
+ case "D428":
|
|
|
+ case "D429":
|
|
|
+ case "D430":
|
|
|
+ case "D431":
|
|
|
+ startWrite(address, data.trim());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Timer timerWrite;
|
|
|
+ private TimerTask timerTaskWrite;
|
|
|
+
|
|
|
+ private void startWrite(final String address, final String data) {
|
|
|
+ timerWrite = new Timer();
|
|
|
+ timerTaskWrite = new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ Log.d(TAG, "run: ");
|
|
|
+ String text = ByteUtils.decimal2fitHex(Integer.valueOf(data));
|
|
|
+ SerialPortManager.getInstance().sendCommandFrame(new WriteCommandFrame(address, HexUtils.hexStr2BinStr(text)), address);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timerWrite.schedule(timerTaskWrite, 0, 1000);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private Timer timerSet;
|
|
|
+ private TimerTask timerTaskSet;
|
|
|
+
|
|
|
+ private void startSet(final String address) {
|
|
|
+ timerSet = new Timer();
|
|
|
+ timerTaskSet = new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ SerialPortSendQueue.sendCommand(new SetCommandFrame(address), 18, address);
|
|
|
+ Log.d(TAG, "run: ");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timerSet.schedule(timerTaskSet, 0, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Timer timerRst;
|
|
|
+ private TimerTask timerTaskRst;
|
|
|
+
|
|
|
+ private void startRst(final String address) {
|
|
|
+ timerRst = new Timer();
|
|
|
+ timerTaskRst = new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ SerialPortSendQueue.sendCommand(new RstCommandFrame(address), 18, address);
|
|
|
+ Log.d(TAG, "run: ");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timerRst.schedule(timerTaskRst, 0, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stopSet(Timer timer, TimerTask timerTask) {
|
|
|
+ Log.d(TAG, "stopSet: ");
|
|
|
+ if (timer != null) {
|
|
|
+ timerTask.cancel();
|
|
|
+ timer.cancel();
|
|
|
+ timer = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stopWrite(Timer timer, TimerTask timerTask) {
|
|
|
+ Log.d(TAG, "stopWrite: ");
|
|
|
+ if (timer != null) {
|
|
|
+ timerTask.cancel();
|
|
|
+ timer.cancel();
|
|
|
+ timer = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stopRst(Timer timer, TimerTask timerTask) {
|
|
|
+ if (timer != null) {
|
|
|
+ timerTask.cancel();
|
|
|
+ timer.cancel();
|
|
|
+ timer = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private CompositeDisposable mDisposables;
|
|
|
protected ApiStores apiStores = ApiClient.retrofit().create(ApiStores.class);
|
|
|
|
|
@@ -159,13 +285,15 @@ public class MyIntentService extends GTIntentService {
|
|
|
|
|
|
@Override
|
|
|
public void onSuccess(HttpResult<String> rule) {
|
|
|
+ Log.d(TAG, "onSuccess: ");
|
|
|
String data = rule.getData();
|
|
|
//广告数据
|
|
|
ArrayList<GetAdBean> adBeans = Hawk.get("showAd", new ArrayList<GetAdBean>());
|
|
|
-
|
|
|
Gson gson = new Gson();
|
|
|
+ Log.d(TAG, "onSuccess: 1" + adBeans);
|
|
|
List<TimeRuleBean> list = gson.fromJson(data, new TypeToken<List<TimeRuleBean>>() {
|
|
|
}.getType());
|
|
|
+ Log.d(TAG, "onSuccess: 2");
|
|
|
//每个id对应的时间数
|
|
|
Map<String, String> adRulesMap = new HashMap<>();
|
|
|
for (int i = 0; i < adBeans.size(); i++) {
|
|
@@ -177,7 +305,6 @@ public class MyIntentService extends GTIntentService {
|
|
|
for (int k = 0; k < ad.size(); k++) {
|
|
|
if (ad.get(k).equals(getAdBean.getId())) {
|
|
|
sb.append(list.get(j).getTime() + "、");
|
|
|
- LogUtil.d(TAG, "list get get" + list.get(j).getName());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -187,17 +314,17 @@ public class MyIntentService extends GTIntentService {
|
|
|
LogUtil.e(TAG, "onNext: " + "ad_id=" + getAdBean.getId() + " rules=" + sb.toString());
|
|
|
adRulesMap.put(getAdBean.getId(), sb.toString());
|
|
|
}
|
|
|
+ Log.d(TAG, "onSuccess: 3" + adRulesMap);
|
|
|
//保存对应的id对应的广告规则
|
|
|
Hawk.put("ad_rules_map", adRulesMap);
|
|
|
EventBus.getDefault().post(new ApiMessageEvent("pushTimeRule", null));
|
|
|
-
|
|
|
//发送设备id
|
|
|
deviceIdPostApi();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onFailure(String msg) {
|
|
|
-
|
|
|
+ Log.d(TAG, "onFailure: ");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -222,7 +349,6 @@ public class MyIntentService extends GTIntentService {
|
|
|
|
|
|
@Override
|
|
|
public void onFailure(String msg) {
|
|
|
- LogUtil.e(TAG, msg);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -277,11 +403,40 @@ public class MyIntentService extends GTIntentService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+// @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
+// public void event(ApiMessageEvent messageEvent) {
|
|
|
+// }
|
|
|
+
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
- public void event(ApiMessageEvent messageEvent) {
|
|
|
+ public void event(Message messageEvent) {
|
|
|
+ switch (messageEvent.getType()) {
|
|
|
+ case connected:
|
|
|
+ Log.d(TAG, "event: connected");
|
|
|
+ break;
|
|
|
+ case sendError:
|
|
|
+ Log.d(TAG, "event: sendError");
|
|
|
+ break;
|
|
|
+ case ack:
|
|
|
+ Log.d(TAG, "event: 写入成功");
|
|
|
+ stopRst(timerRst, timerTaskRst);
|
|
|
+ stopSet(timerSet, timerTaskSet);
|
|
|
+ stopWrite(timerWrite,timerTaskWrite);
|
|
|
+ Log.d(TAG, "event: ack");
|
|
|
+ break;
|
|
|
+ case nak:
|
|
|
+ Log.d(TAG, "event: nak");
|
|
|
+ break;
|
|
|
+ case disconnected:
|
|
|
+ SerialPortDevice device = new SerialPortDevice("/dev/ttyS2", "9600");
|
|
|
+ SerialPortManager.getInstance().open(device);
|
|
|
+ Log.d(TAG, "event: disconnected");
|
|
|
+ break;
|
|
|
+ case response:
|
|
|
+ Log.d(TAG, "event: response");
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* cid 离线上线通知
|
|
|
*/
|