Browse Source

慷慨斯GK309下班打卡回复错误bug

vinson 5 years ago
parent
commit
3145153c4e

+ 41 - 5
src/main/java/com/tidecloud/dataacceptance/service/impl/GK309GpsServerHandler.java

@@ -1,6 +1,8 @@
 package com.tidecloud.dataacceptance.service.impl;
 
 import com.accept.client.DeviceMsgClient;
+import com.accept.model.DeviceMsgDto;
+import com.smartsanitation.common.util.StringUtil;
 import com.tidecloud.dataacceptance.codec.HeaderTailDelimiterFrameDecoder;
 import com.tidecloud.dataacceptance.common.*;
 import com.tidecloud.dataacceptance.entity.YiTongGPSDevice;
@@ -60,8 +62,25 @@ public class GK309GpsServerHandler extends HexBinaryAcceptanceHandlerAdapter {
 
     private static final Integer DATA_SIZE = 6;
 
-    @Autowired
-    private DeviceMsgClient deviceMsgClient;
+    private static final byte MARK = 0B00111100;
+
+    private static final byte SIGN_IN = 0B00000100; //上班打卡
+    private static final byte SIGN_OUT = 0B00001000; // 下班打卡
+
+//    @Autowired
+    private DeviceMsgClient deviceMsgClient = new DeviceMsgClient() {
+    @Override
+    public void acceptDeviceMsg(DeviceMsgDto deviceMsgDto) {
+        logger.info(StringUtil.convert2String(deviceMsgDto));
+
+    }
+
+    @Override
+    public void acceptDeviceMsgParam(String s, String s1, Integer integer, String s2, Long aLong) {
+        logger.info("111");
+
+    }
+};
 
     @Override
     protected void handle(ByteBuf in, Channel channel) throws Exception {
@@ -135,13 +154,30 @@ public class GK309GpsServerHandler extends HexBinaryAcceptanceHandlerAdapter {
                 short terminalReservedWord = in.readShort();
                 byte[] reservedWorkBytes = short2Bytes(terminalReservedWord);
 
+
+                // 根据文档查看上下班标示
+                ByteBuf byteBuf = in.readBytes(13);
+                byteBuf.skipBytes(12);
+                byte b = byteBuf.readByte();
+                // 2-5位代表是上班还是下班
+                byte i = (byte) (b & MARK);
+
+//                类型: 1(上班), 2(下班)
+                Byte signResponse = null;
+                if (i == SIGN_IN) {
+                    signResponse = 0X01;
+                } else {
+                    signResponse = 0x02;
+                }
+
+
                 // 减去前面跳过的第一位和前面跳过的7位,再减去最后的四位(序列号本身的2位+校验位2位)
-                in.skipBytes(length - 8 - 2 - 2);
+                in.skipBytes(length - 8 - 2 - 2 - 15);
                 short serNum = in.readShort();
                 byte[] serNumBytes = short2Bytes(serNum);
 
-                // 状态: 0(失败), 1(成功) 类型: 1(上班), 2(下班)
-                byte[] signResult = new byte[]{0x01, 0x01};
+                // 状态: 0(失败), 1(成功)
+                byte[] signResult = new byte[]{0x01, signResponse};
                 // 0X0F是长度,固定长度
                 byte[] contentsOfPackage = mergeByteArray(new byte[]{0X0F, SIGN_IN_MSG},
                         dataBytes, signResult, reservedWorkBytes, serNumBytes);