Przeglądaj źródła

云快充拆包

liuf 2 miesięcy temu
rodzic
commit
3647a14b93

+ 47 - 2
src/main/java/com/tmzn/devicelinkykc/controller/TestController.java

@@ -17,6 +17,7 @@ import com.tmzn.devicelinkykc.frameMsg.frameType.RealTimeStatusPushFrame;
 import com.tmzn.devicelinkykc.frameMsg.frameType.TransactionFlowPushFrame;
 import com.tmzn.devicelinkykc.mapstruct.BillingModelMapping;
 import com.tmzn.devicelinkykc.message.DeviceMsgHandle;
+import com.tmzn.devicelinkykc.message.YkcMsgHandle;
 import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
 import com.tmzn.devicelinkykc.redis.RedisCache;
 import com.tmzn.devicelinkykc.service.*;
@@ -38,6 +39,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -75,6 +77,9 @@ public class TestController {
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    private YkcMsgHandle ykcMsgHandle;
+
     @Autowired
     private MessageParseMgr messageParseMgr;
 
@@ -90,15 +95,55 @@ public class TestController {
     @Autowired
     private SocketHandle socketHandle;
 
+    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+
+    @RequestMapping("/pkg")
+    public String testPkg(@RequestParam("hex")String  hex) {
+        byte[] data = DataConversion.hexStringToBytes(hex);
+
+
+        buffer.write(data,0,data.length);
+        List<byte[]> packages =  ykcMsgHandle.tryParsePackages(buffer);
+        Socket socket = new Socket();
+        DeviceConnectionMsg deviceConnectionMsg = new DeviceConnectionMsg(socket,"333","444","333","1.6",1);
+
+        if(packages.isEmpty()){
+            //如果没有拆出包 就处理默认
+            System.out.println("未解析出包");
+            if(buffer.size()>300){
+                buffer.reset();
+            }
+
+            System.out.println(DataConversion.bytesToHexString(data));
+        }else{
+            // 循环处理每个包
+            for (byte[] pkg : packages) {
+                System.out.println("解析出包");
+                System.out.println(DataConversion.bytesToHexString(pkg));
+                try{
+                    ykcMsgHandle.handlePackage(deviceConnectionMsg,pkg.length,pkg);
+                }catch (Exception e){
+
+                }
+            }
+        }
+
+        System.out.println("buffer");
+        System.out.println(DataConversion.bytesToHexString(buffer.toByteArray()));
+
+        return "";
+    }
+
     @Autowired
     private TransMoney transMoney;
     @PostMapping("/msg")
-    public String testMsg() {
+    public String testMsg(@RequestParam("hex")String  hex) {
         try {
+
+
             boolean temp = false;
             int result = 0x00;    //失败
             int reason = 0x00;   //无
-
             //检查流量费是否过期
             QueryWrapper<ShoppingGoods> goodsQueryWrapper = new QueryWrapper<>();
 

+ 12 - 0
src/main/java/com/tmzn/devicelinkykc/frameMsg/DataConversion.java

@@ -129,6 +129,18 @@ public class DataConversion {
         }
         return sb.toString();
     }
+
+    // 将16进制字符串转换为字节数组
+    public static byte[] hexStringToBytes(String hex) {
+        int len = hex.length();
+        byte[] result = new byte[len / 2];
+        for (int i = 0; i < len; i += 2) {
+            result[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
+                    + Character.digit(hex.charAt(i + 1), 16));
+        }
+        return result;
+    }
+
     public static byte[] temp(byte[] b){
         for (int i = 0; i < b.length; i++) {
             b[i]=0x00;

+ 1 - 1
src/main/java/com/tmzn/devicelinkykc/message/DeviceMsgHandle.java

@@ -787,7 +787,7 @@ public class DeviceMsgHandle {
 
         if (portStatus.equals(PortStatusConstant.CHARGING_END)) {
             //7状态的时候 充满停止以后 认为未插枪 不允许充电 因为启动不了,必须要重新拔枪
-            deviceOnline(portStatus, imei, port, (byte) StatusConstant.FREE, StatusConstant.INSERT_GUNS_NO);
+            deviceOnline(portStatus, imei, port, (byte) StatusConstant.FREE, StatusConstant.INSERT_GUNS_YES);
             return;
         }
 

+ 225 - 132
src/main/java/com/tmzn/devicelinkykc/message/YkcMsgHandle.java

@@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.time.Instant;
@@ -97,10 +98,14 @@ public class YkcMsgHandle {
     @Autowired
     private DeviceService deviceService;
 
+    private static final byte FRAME_START = 0x68;
+
     public void startListening(DeviceConnectionMsg deviceConnectionMsg) {
 
         Runnable listener = () -> {
             boolean temp = true;
+            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+
             while (temp) {
                 // 接收数据帧
                 byte[] receiveData = new byte[1024];
@@ -117,7 +122,7 @@ public class YkcMsgHandle {
                 } catch (IOException e) {
                     //e.printStackTrace();
                     String message = e.getMessage();
-                    logger.info(deviceConnectionMsg.getDeviceId() + ":Receive YKC dataMsg IOException !!!!!!!:" + message + "!!!!!!!!" + message + "!!!!!!!!" + message + "!!!!!!!!" + message + "!!!!!!!!");
+                    logger.info(deviceConnectionMsg.getDeviceId() + ":Receive YKC dataMsg IOException !!!!!!!:" + message + "!!!!!!!!");
                     //异常后操作删除所有的缓存,重新获取
                     DataParam dataParam = new DataParam();
                     dataParam.setDeviceId(deviceConnectionMsg.getImei());
@@ -129,161 +134,249 @@ public class YkcMsgHandle {
                     temp = false;
                     continue;
                 }
-                byte[] response = new byte[length];
-                //将接收到的消息类型拿到进行判断
-                System.arraycopy(receiveData, 0, response, 0, response.length);
-                //String s = Integer.toHexString(response[5] & 0xFF);
-                byte[] fromMsgSeq = {response[2],response[3]};
-                int framType = response[5] & 0xFF;//Integer.parseInt(s);
-                int encry = response[4] & 0xFF;
-
-                //消息体
-                byte[] respone_msg = Arrays.copyOfRange(response, 6, response.length - 2);
-                if (encry == 0) {
-                    if(framType!=4){
-                        logger.info("{},un_encry_msg,frame:{},data:{}",deviceConnectionMsg.getDeviceId(),framType, DataConversion.bytesToHexString(response));
+                buffer.write(receiveData, 0, length);
+                // 进行拆包处理
+                List<byte[]> packages = tryParsePackages(buffer);
+
+                if(packages.isEmpty()){
+                    //如果没有拆出包 就处理默认
+                    handlePackage(deviceConnectionMsg,receiveData.length, receiveData);
+                    logger.info("{},package_error,data:{}",deviceConnectionMsg.getDeviceId(), DataConversion.bytesToHexString(receiveData));
+                    if(buffer.size()>1024){
+                        buffer.reset();
                     }
-                } else {
-                    try {
-                        String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
-//                        String key = redisCache.getCacheObject(RedisConstant.KEYS + deviceConnectionMsg.getDeviceId());
-                        respone_msg = Encrytion.decrypt(respone_msg, key.getBytes());
-
-                        logger.info("{},encry_msg,frame:{},data:{}",deviceConnectionMsg.getDeviceId(),framType, DataConversion.bytesToHexString(respone_msg));
-                    } catch (Exception e) {
-                        logger.info("{},ykc->msg decrypt Exception",deviceConnectionMsg.getDeviceId());
-                        e.printStackTrace();
+                }else{
+                    // 循环处理每个包
+                    for (byte[] pkg : packages) {
+                        handlePackage(deviceConnectionMsg,pkg.length, pkg);
                     }
                 }
-                if (framType == YkcSendDevice.LOGIN_RESPONSE.getFrameType()) {
-                    logger.info("↓↓↓↓↓"+deviceConnectionMsg.getDeviceId()+"登录认证应答"+framType);
-                    //处理登录成功与否
-                    boolean res = loginResponse(deviceConnectionMsg, respone_msg);
-                    //计费模型请求
-                    if(res){
-                        logger.info("↓↓↓↓↓"+deviceConnectionMsg.getDeviceId()+"请求计费模型");
-                        billingModelFrame.checkBillingModel(deviceConnectionMsg);
-                    }
 
-                } else if (framType == YkcSendDevice.HEART_RESPONSE.getFrameType()) {
-                    //TODO:个人理解,枪不管故障还是正常都会有心跳,心跳应答正常说明设备是正常的状态,所以这里不管是同一设备的几号枪心跳都缓存下来心跳应答时间
-                    //  logger.info("ykc->dev"+deviceConnectionMsg.getDeviceId()+"↓↓↓↓↓↓↓↓↓↓↓↓↓心跳包应答消息↓↓↓↓↓↓↓↓↓↓↓↓↓"+framType);
-                    deviceConnectionMsg.setHeartTime(System.currentTimeMillis());
-//                    logger.info("===========心跳包应答============over");
+            }
+        };
+        Thread thread = new Thread(listener);
+        thread.start();
+    }
 
-                } else if (framType == YkcSendDevice.BILLING_MODEL_VALIDATE_RESPONSE.getFrameType()) {
-                    billingModelHandle(deviceConnectionMsg, respone_msg);
 
-                } else if (framType == YkcSendDevice.BILLING_MODEL_RESPONSE.getFrameType()) {
-                    logger.info("↓↓↓↓↓" + deviceConnectionMsg.getDeviceId() + "计费模型请求应答" + framType);
-                    try {
-                        billingModelFrame.setBillingModel(deviceConnectionMsg, respone_msg);
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
+    /**
+     * 尝试从缓冲区中解析出完整的包
+     * @param buffer 数据缓冲区
+     * @return 完整的包列表
+     */
+    public List<byte[]> tryParsePackages(ByteArrayOutputStream buffer) {
+        List<byte[]> packages = new ArrayList<>();
+        byte[] data = buffer.toByteArray();
+        int currentIndex = 0;
+        final int MAX_FRAME_LENGTH = 1024; // 添加最大帧长保护
+
+        while (currentIndex < data.length) {
+            // 查找帧起始符 0x68
+            int frameStart = -1;
+            for (int i = currentIndex; i < data.length; i++) {
+                if (data[i] == FRAME_START) {
+                    frameStart = i;
+                    break;
+                }
+            }
 
-                } else if (framType == YkcSendDevice.BILLING_MODEL_VALIDATE_RESPONSE_SG.getFrameType()) {
-                    logger.info("↓↓↓↓↓" + deviceConnectionMsg.getDeviceId() + "深谷计费模型请求应答" + framType);
-                    try {
-                        billingModelFrame.setSgBillingModel(deviceConnectionMsg, respone_msg);
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                } else if (framType == YkcSendDevice.TRANSACTION_RECORDS_RESPONSE.getFrameType()) {
-                    logger.info("↓↓↓↓↓" + deviceConnectionMsg.getDeviceId() + "交易记录确认");
-                    byte[] trans = Arrays.copyOfRange(respone_msg, 0, 16);
-                    byte[] reason = Arrays.copyOfRange(respone_msg, 16, 17);
-                    QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
-                    orderStatusQueryWrapper.eq("trans_order", trans).eq("pile_code",deviceConnectionMsg.getDeviceId());
-                    OrderStatus one = orderStatusService.getOne(orderStatusQueryWrapper);
-                    if(one!=null){
-                        QueryWrapper<TransOrder> transOrderQueryWrapper = new QueryWrapper<>();
-                        transOrderQueryWrapper.eq("trans_order", trans).eq("pile_code",deviceConnectionMsg.getDeviceId());
-
-                        TransOrder transOrderServiceOne = transOrderService.getOne(transOrderQueryWrapper);
-                        if (reason[0] == 0x00) {
-                            one.setTransactionOrderReplyStatus(StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_SUCC);
-
-                            transOrderServiceOne.setFlage(StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_SUCC);
-                        } else if (reason[0] == 0x01) {
-                            one.setTransactionOrderReplyStatus(StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_FAIL);
-                        } else if (reason[0] == 0x02) {
-                            one.setTransactionOrderReplyStatus(StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_ILLEGAL);
-                        }
-                        //接收到后将订单校验从redis剔除
-                        orderStatusService.updateById(one);
-                        transOrderService.updateById(transOrderServiceOne);
-                    }
+            if (frameStart == -1) {
+                // 没有找到帧头,清空缓冲区
+                buffer.reset();
+                break;
+            }
 
+            // 检查是否有足够的数据读取数据域长度
+            if (frameStart + 1 >= data.length) {
+                // 保留从帧头开始的数据
+                byte[] remaining = Arrays.copyOfRange(data, frameStart, data.length);
+                buffer.reset();
+                buffer.write(remaining, 0, remaining.length);
+                break;
+            }
 
-                } else if (framType == YkcSendDevice.DEVICE_STATUS_REQUEST.getFrameType()) {
-                    logger.info("↓↓↓↓↓{}读取实时监测数据",deviceConnectionMsg.getDeviceId());
-                    handleRealTimeReport(deviceConnectionMsg,respone_msg,fromMsgSeq);
+            // 读取数据域长度(第2字节)
+            int dataFieldLength = data[frameStart + 1] & 0xFF;
 
+            // 计算完整帧长度 = 8字节固定头尾 + 数据域长度
+            int totalFrameLength = 4 + dataFieldLength;
 
+            // 检查是否收到完整帧
+            if ((frameStart + totalFrameLength) > data.length) {
+                // 数据不够完整帧,保留剩余数据
+                byte[] remaining = Arrays.copyOfRange(data, frameStart, data.length);
+                buffer.reset();
+                buffer.write(remaining, 0, remaining.length);
+                break;
+            }
 
-                } else if (framType == YkcSendDevice.START_CHARNGING_REQUEST.getFrameType() || framType == YkcSendDevice.START_CHARNGING_REQUEST_16.getFrameType()) {
-                    logger.info("↓↓↓↓↓{}运营平台远程控制启机" + framType,deviceConnectionMsg.getDeviceId());
-                    startChargingRequest(deviceConnectionMsg, respone_msg,fromMsgSeq);
+            // 提取完整帧
+            byte[] completeFrame = Arrays.copyOfRange(data, frameStart, frameStart + totalFrameLength);
 
-                } else if (framType == YkcSendDevice.STOP_CHARNGING_REQUEST.getFrameType()) {
-                    logger.info("↓↓↓↓↓{}运营平台远程停机",deviceConnectionMsg.getDeviceId());
-                    stopChargingRequest(deviceConnectionMsg, respone_msg,fromMsgSeq);
+            packages.add(completeFrame);
+            currentIndex = frameStart + totalFrameLength;
+        }
 
-                } else if (framType == YkcSendDevice.UPDATE_BALANCE.getFrameType()) {
-                    logger.info("↓↓↓↓↓{}远程更新余额",deviceConnectionMsg.getDeviceId());
-                    try {
-                        remoteBalanceUpdate(deviceConnectionMsg, respone_msg,fromMsgSeq);
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
+        // 如果所有数据都处理完了,清空缓冲区
+        if (currentIndex >= data.length) {
+            buffer.reset();
+        }
 
-                } else if (framType == YkcSendDevice.CHECKTIME.getFrameType()) {
-                    logger.info("↓↓↓↓↓{}对时设置" + framType,deviceConnectionMsg.getDeviceId());
-                    checkTime.checkTimeSend(deviceConnectionMsg,fromMsgSeq);
-
-                } else if (framType == YkcSendDevice.BILLING_MODEL_SETTING_SG.getFrameType()) {
-                    logger.info("↓↓↓↓↓{}深谷计费模型设置",deviceConnectionMsg.getDeviceId());
-                    try {
-                        //有异常就是失败
-                        billingModelFrame.setSgBillingModel(deviceConnectionMsg, respone_msg);
-                        billingModelFrame.resp(deviceConnectionMsg, (byte) 1,fromMsgSeq);
-                    } catch (Exception e) {
-                        billingModelFrame.resp(deviceConnectionMsg, (byte) 0,fromMsgSeq);
-                        e.printStackTrace();
-                    }
+        return packages;
+    }
 
-                } else if(framType == YkcSendDevice.CONFIG_SETTING.getFrameType()){
-                    logger.info("↓↓↓↓↓{}工作参数设置",deviceConnectionMsg.getDeviceId());
-                    otherFrame.configSettingSend(deviceConnectionMsg,respone_msg,fromMsgSeq);
+    public void handlePackage(DeviceConnectionMsg deviceConnectionMsg,int length,byte[] receiveData){
+        byte[] response = new byte[length];
+        //将接收到的消息类型拿到进行判断
+        System.arraycopy(receiveData, 0, response, 0, response.length);
+        //String s = Integer.toHexString(response[5] & 0xFF);
+        byte[] fromMsgSeq = {response[2],response[3]};
+        int framType = response[5] & 0xFF;//Integer.parseInt(s);
+        int encry = response[4] & 0xFF;
+
+        //消息体
+        byte[] respone_msg = Arrays.copyOfRange(response, 6, response.length - 2);
+        if (encry == 0) {
+            if(framType!=4){
+                logger.info("{},un_encry_msg,frame:{},data:{}",deviceConnectionMsg.getDeviceId(),framType, DataConversion.bytesToHexString(response));
+            }
+        } else {
+            try {
+                String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
+//                        String key = redisCache.getCacheObject(RedisConstant.KEYS + deviceConnectionMsg.getDeviceId());
+                respone_msg = Encrytion.decrypt(respone_msg, key.getBytes());
 
+                logger.info("{},encry_msg,frame:{},data:{}",deviceConnectionMsg.getDeviceId(),framType, DataConversion.bytesToHexString(respone_msg));
+            } catch (Exception e) {
+                logger.info("{},ykc->msg decrypt Exception",deviceConnectionMsg.getDeviceId());
+                e.printStackTrace();
+            }
+        }
+        if (framType == YkcSendDevice.LOGIN_RESPONSE.getFrameType()) {
+            logger.info("↓↓↓↓↓"+deviceConnectionMsg.getDeviceId()+"登录认证应答"+framType);
+            //处理登录成功与否
+            boolean res = loginResponse(deviceConnectionMsg, respone_msg);
+            //计费模型请求
+            if(res){
+                logger.info("↓↓↓↓↓"+deviceConnectionMsg.getDeviceId()+"请求计费模型");
+                billingModelFrame.checkBillingModel(deviceConnectionMsg);
+            }
 
+        } else if (framType == YkcSendDevice.HEART_RESPONSE.getFrameType()) {
+            //TODO:个人理解,枪不管故障还是正常都会有心跳,心跳应答正常说明设备是正常的状态,所以这里不管是同一设备的几号枪心跳都缓存下来心跳应答时间
+            //  logger.info("ykc->dev"+deviceConnectionMsg.getDeviceId()+"↓↓↓↓↓↓↓↓↓↓↓↓↓心跳包应答消息↓↓↓↓↓↓↓↓↓↓↓↓↓"+framType);
+            deviceConnectionMsg.setHeartTime(System.currentTimeMillis());
+//                    logger.info("===========心跳包应答============over");
 
-                } else if (framType == YkcSendDevice.BILLING_MODEL_SETTING.getFrameType()) {
-                    logger.info("↓↓↓↓↓{}计费模型设置",deviceConnectionMsg.getDeviceId());
-                    try {
-                        //有异常就是失败
-                        billingModelFrame.setBillingModel(deviceConnectionMsg, respone_msg);
-                        billingModelFrame.resp(deviceConnectionMsg, (byte) 1,fromMsgSeq);
-                    } catch (Exception e) {
-                        billingModelFrame.resp(deviceConnectionMsg, (byte) 0,fromMsgSeq);
-                        e.printStackTrace();
-                    }
+        } else if (framType == YkcSendDevice.BILLING_MODEL_VALIDATE_RESPONSE.getFrameType()) {
+            billingModelHandle(deviceConnectionMsg, respone_msg);
 
-                } else if (framType == YkcSendDevice.REMOTE_REBOOT.getFrameType()) {
-                    logger.info("↓↓↓↓↓{}远程重启",deviceConnectionMsg.getDeviceId());
-                    otherFrame.remoteRebootSend(deviceConnectionMsg,fromMsgSeq);
+        } else if (framType == YkcSendDevice.BILLING_MODEL_RESPONSE.getFrameType()) {
+            logger.info("↓↓↓↓↓" + deviceConnectionMsg.getDeviceId() + "计费模型请求应答" + framType);
+            try {
+                billingModelFrame.setBillingModel(deviceConnectionMsg, respone_msg);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
 
+        } else if (framType == YkcSendDevice.BILLING_MODEL_VALIDATE_RESPONSE_SG.getFrameType()) {
+            logger.info("↓↓↓↓↓" + deviceConnectionMsg.getDeviceId() + "深谷计费模型请求应答" + framType);
+            try {
+                billingModelFrame.setSgBillingModel(deviceConnectionMsg, respone_msg);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        } else if (framType == YkcSendDevice.TRANSACTION_RECORDS_RESPONSE.getFrameType()) {
+            logger.info("↓↓↓↓↓" + deviceConnectionMsg.getDeviceId() + "交易记录确认");
+            byte[] trans = Arrays.copyOfRange(respone_msg, 0, 16);
+            byte[] reason = Arrays.copyOfRange(respone_msg, 16, 17);
+            QueryWrapper<OrderStatus> orderStatusQueryWrapper = new QueryWrapper<>();
+            orderStatusQueryWrapper.eq("trans_order", trans).eq("pile_code",deviceConnectionMsg.getDeviceId());
+            OrderStatus one = orderStatusService.getOne(orderStatusQueryWrapper);
+            if(one!=null){
+                QueryWrapper<TransOrder> transOrderQueryWrapper = new QueryWrapper<>();
+                transOrderQueryWrapper.eq("trans_order", trans).eq("pile_code",deviceConnectionMsg.getDeviceId());
+
+                TransOrder transOrderServiceOne = transOrderService.getOne(transOrderQueryWrapper);
+                if (reason[0] == 0x00) {
+                    one.setTransactionOrderReplyStatus(StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_SUCC);
+
+                    transOrderServiceOne.setFlage(StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_SUCC);
+                } else if (reason[0] == 0x01) {
+                    one.setTransactionOrderReplyStatus(StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_FAIL);
+                } else if (reason[0] == 0x02) {
+                    one.setTransactionOrderReplyStatus(StatusConstant.TRANSACTION_ORDER_REPLY_STATUS_ILLEGAL);
+                }
+                //接收到后将订单校验从redis剔除
+                orderStatusService.updateById(one);
+                transOrderService.updateById(transOrderServiceOne);
+            }
 
-                } else if (framType == YkcSendDevice.UPLOAD_FILE_UPDATE.getFrameType()) {
-                    logger.info("↓↓↓↓↓{}远程更新",deviceConnectionMsg.getDeviceId());
-                    otherFrame.remoteUpdateSend(deviceConnectionMsg,fromMsgSeq);
 
-                }
+        } else if (framType == YkcSendDevice.DEVICE_STATUS_REQUEST.getFrameType()) {
+            logger.info("↓↓↓↓↓{}读取实时监测数据",deviceConnectionMsg.getDeviceId());
+            handleRealTimeReport(deviceConnectionMsg,respone_msg,fromMsgSeq);
+
+
+
+        } else if (framType == YkcSendDevice.START_CHARNGING_REQUEST.getFrameType() || framType == YkcSendDevice.START_CHARNGING_REQUEST_16.getFrameType()) {
+            logger.info("↓↓↓↓↓{}运营平台远程控制启机" + framType,deviceConnectionMsg.getDeviceId());
+            startChargingRequest(deviceConnectionMsg, respone_msg,fromMsgSeq);
+
+        } else if (framType == YkcSendDevice.STOP_CHARNGING_REQUEST.getFrameType()) {
+            logger.info("↓↓↓↓↓{}运营平台远程停机",deviceConnectionMsg.getDeviceId());
+            stopChargingRequest(deviceConnectionMsg, respone_msg,fromMsgSeq);
+
+        } else if (framType == YkcSendDevice.UPDATE_BALANCE.getFrameType()) {
+            logger.info("↓↓↓↓↓{}远程更新余额",deviceConnectionMsg.getDeviceId());
+            try {
+                remoteBalanceUpdate(deviceConnectionMsg, respone_msg,fromMsgSeq);
+            } catch (Exception e) {
+                e.printStackTrace();
             }
-        };
-        Thread thread = new Thread(listener);
-        thread.start();
+
+        } else if (framType == YkcSendDevice.CHECKTIME.getFrameType()) {
+            logger.info("↓↓↓↓↓{}对时设置" + framType,deviceConnectionMsg.getDeviceId());
+            checkTime.checkTimeSend(deviceConnectionMsg,fromMsgSeq);
+
+        } else if (framType == YkcSendDevice.BILLING_MODEL_SETTING_SG.getFrameType()) {
+            logger.info("↓↓↓↓↓{}深谷计费模型设置",deviceConnectionMsg.getDeviceId());
+            try {
+                //有异常就是失败
+                billingModelFrame.setSgBillingModel(deviceConnectionMsg, respone_msg);
+                billingModelFrame.resp(deviceConnectionMsg, (byte) 1,fromMsgSeq);
+            } catch (Exception e) {
+                billingModelFrame.resp(deviceConnectionMsg, (byte) 0,fromMsgSeq);
+                e.printStackTrace();
+            }
+
+        } else if(framType == YkcSendDevice.CONFIG_SETTING.getFrameType()){
+            logger.info("↓↓↓↓↓{}工作参数设置",deviceConnectionMsg.getDeviceId());
+            otherFrame.configSettingSend(deviceConnectionMsg,respone_msg,fromMsgSeq);
+
+
+
+        } else if (framType == YkcSendDevice.BILLING_MODEL_SETTING.getFrameType()) {
+            logger.info("↓↓↓↓↓{}计费模型设置",deviceConnectionMsg.getDeviceId());
+            try {
+                //有异常就是失败
+                billingModelFrame.setBillingModel(deviceConnectionMsg, respone_msg);
+                billingModelFrame.resp(deviceConnectionMsg, (byte) 1,fromMsgSeq);
+            } catch (Exception e) {
+                billingModelFrame.resp(deviceConnectionMsg, (byte) 0,fromMsgSeq);
+                e.printStackTrace();
+            }
+
+        } else if (framType == YkcSendDevice.REMOTE_REBOOT.getFrameType()) {
+            logger.info("↓↓↓↓↓{}远程重启",deviceConnectionMsg.getDeviceId());
+            otherFrame.remoteRebootSend(deviceConnectionMsg,fromMsgSeq);
+
+
+        } else if (framType == YkcSendDevice.UPLOAD_FILE_UPDATE.getFrameType()) {
+            logger.info("↓↓↓↓↓{}远程更新",deviceConnectionMsg.getDeviceId());
+            otherFrame.remoteUpdateSend(deviceConnectionMsg,fromMsgSeq);
+
+        }
     }
 
     /**