Browse Source

经纬手表测试 开关增加模式是否切换成功判断

jianghouwei 6 years ago
parent
commit
5252e07655

+ 30 - 6
src/main/java/com/tidecloud/dataacceptance/service/impl/WatchJWServerHandler.java

@@ -71,9 +71,9 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
 					break;
 				case "AP01": // 位置信息
 					String gpsState = msg.substring(12, 13);
+					setSwitchMap(deviceId, gpsState);// 采集数据
 					sendMsg2Kafka((msg + deviceId).getBytes(), deviceId, channel);
 					normalReply(factory, channel, "BP01");
-					setSwitchMap(deviceId, gpsState);// 采集数据
 					break;
 				default: // 其他
 					logger.info("client send data without handle type ...");
@@ -85,7 +85,12 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
 	}
 
 
-	// 心跳包check map 数据
+	/**
+	 *  模式设置
+	 * @param factory
+	 * @param deviceId
+	 * @param channel
+	 */
 	protected void checkSwitchMap(String factory, String deviceId, Channel channel) {
 		Long nowTime = System.currentTimeMillis();// 当前时间戳
 		if (deviceId == null || !switchMap.containsKey(deviceId)) {
@@ -95,8 +100,11 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
 		logger.warn("心跳检测是否更改终端模式:" + (nowTime - swm.getActiveTime() + ";" + (nowTime - swm.getSwitchTime())));
 		if (nowTime - swm.getActiveTime() > INTERVAL_TIME
 				&& nowTime - swm.getSwitchTime() > INTERVAL_TIME) {
-			// 如果当前状态为A 紧急模式
 			Integer workType = (3 == swm.getWorkType()) ? 2 : 3;
+			if(nowTime - swm.getGpsUpTime() > INTERVAL_TIME){
+				workType =3; // APO1上传间隔大于5分种再次设置为紧急模式
+			}
+			// 如果当前状态为A 紧急模式
 			swm.setSwitchTime(nowTime);
 			swm.setWorkType(workType);
 			switchMap.put(deviceId, swm);
@@ -120,6 +128,7 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
 		swm.setActiveTime(time);
 		swm.setSwitchTime(time);
 		swm.setWorkType(3);//1:正常模式,2:省电模式,3:紧急模式
+		swm.setGpsUpTime(0L);// GPS 上报时间接口
 		switchMap.put(deviceId, swm);
 		logger.warn("初始化数据》》》》》》》》》》" + JSON.toJSONString(swm));
 	}
@@ -133,15 +142,17 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
 		if (deviceId == null) {
 			return;
 		}
+		Long time = System.currentTimeMillis();
+		SwitchWorkModel swm = switchMap.get(deviceId);
+		swm.setGpsUpTime(time);
 		if ("A".equals(gpsState)) {
-			SwitchWorkModel swm = switchMap.get(deviceId);
-			Long time = System.currentTimeMillis();
 			swm.setActiveTime(time);
-			switchMap.put(deviceId, swm);
 			logger.warn("更新A 活跃时间》》》》》》》》》》" + JSON.toJSONString(swm));
 		} else {
 			logger.warn("当前上报数据为V 时间不更新!!>>>>>>>>>>>>>>>");
 		}
+		switchMap.put(deviceId, swm);
+		logger.warn("更新A 活跃时间》》》》》》》》》》" + JSON.toJSONString(swm));
 	}
 
 	protected void printAcceptanceData(ByteBuf dataByteBuf, ChannelHandlerContext ctx) {
@@ -295,6 +306,11 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
 		 */
 		private Long switchTime;
 
+		/**
+		 *  GPS APO1 上傳时间
+		 */
+		private Long gpsUpTime;
+
 		public Long getActiveTime() {
 			return activeTime;
 		}
@@ -318,6 +334,14 @@ public class WatchJWServerHandler extends HexBinaryAcceptanceHandlerAdapter {
 		public void setSwitchTime(Long switchTime) {
 			this.switchTime = switchTime;
 		}
+
+		public Long getGpsUpTime() {
+			return gpsUpTime;
+		}
+
+		public void setGpsUpTime(Long gpsUpTime) {
+			this.gpsUpTime = gpsUpTime;
+		}
 	}
 
 }

+ 1 - 6
src/main/resources/prod/application.yml

@@ -122,7 +122,7 @@ acceptance:
     enable: true
    -
     name: jingwei_watch
-    topic: device-jingwei-watch
+    topic: device-jingwei-1-watch
     ip: 10.25.19.87
     port: 6000
     dataFileDir: /home/service/collector_7518/rawdata/
@@ -139,8 +139,3 @@ acceptance:
 logging:
   config:
     classpath: logback.xml
-
-
-
-
-