liuf 8 месяцев назад
Родитель
Сommit
da0e27b244

+ 371 - 348
src/main/java/com/tmzn/devicelinkykc/controller/TestController.java

@@ -1,348 +1,371 @@
-package com.tmzn.devicelinkykc.controller;
-
-import cn.hutool.http.HttpRequest;
-import cn.hutool.http.HttpResponse;
-import com.alibaba.fastjson2.JSONArray;
-import com.alibaba.fastjson2.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.tmzn.devicelinkykc.constant.ykc.StatusConstant;
-import com.tmzn.devicelinkykc.entity.BillingModel;
-import com.tmzn.devicelinkykc.entity.DeviceStatus;
-import com.tmzn.devicelinkykc.entity.param.AjaxResult;
-import com.tmzn.devicelinkykc.entity.param.dto.BillingModelDTO;
-import com.tmzn.devicelinkykc.frameMsg.DataConversion;
-import com.tmzn.devicelinkykc.mapstruct.BillingModelMapping;
-import com.tmzn.devicelinkykc.message.DeviceMsgHandle;
-import com.tmzn.devicelinkykc.redis.RedisCache;
-import com.tmzn.devicelinkykc.service.BillingModelService;
-import com.tmzn.devicelinkykc.service.DeviceControlerService;
-import com.tmzn.devicelinkykc.service.DeviceStatusService;
-import com.tmzn.devicelinkykc.transdata.entity.DeviceParam;
-import com.tmzn.devicelinkykc.msgparser.MessageParseMgr;
-import com.tmzn.devicelinkykc.util.Encrytion;
-import lombok.extern.slf4j.Slf4j;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.*;
-
-import javax.servlet.http.HttpServletRequest;
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * @author xp
- * @date 2024/4/13
- * @explain "  "
- */
-@Controller
-@Slf4j(topic = "RealTimeStatusPushFrame")
-@RequestMapping
-public class TestController {
-    @Autowired
-    private DeviceControlerService deviceControlerService;
-    @Autowired
-    private BillingModelService billingModelService;
-    @Autowired
-    private BillingModelMapping billingModelMapping;
-    @Value("${billingInterface}")
-    private String url;
-
-    @Autowired
-    private RedisCache redisCache;
-
-    @Autowired
-    private MessageParseMgr messageParseMgr;
-
-    @Autowired
-    private DeviceMsgHandle deviceMsgHandle;
-
-    @PostMapping("/msg")
-    public String testMsg(@RequestBody String message) {
-        try {
-            deviceMsgHandle.testMsg(message);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return "ok";
-    }
-
-    @Autowired
-    DeviceStatusService deviceStatusService;
-
-    @PostMapping("/parser1")
-    public String parser1(@RequestBody String message ) {
-
-        try{
-
-
-            QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
-            billWapper.eq("pile_code", "32010600530570");
-            billWapper.eq("device_imei", "863218078065418");
-            BillingModel b = billingModelService.getOne(billWapper);
-            if (b == null) {
-                log.info("{}上报充电中未匹配计费模型", "32010600530570");
-            }
-
-
-
-            QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
-            deviceStatusQueryWrapper.eq("device_imei", "863343064704539");
-            deviceStatusQueryWrapper.last("limit 1");
-            DeviceStatus statusServiceOne = deviceStatusService.getOne(deviceStatusQueryWrapper);
-            System.out.println(statusServiceOne);
-
-//            deviceMsgHandle.deviceMsg(message);
-        }catch (Exception e){
-            e.printStackTrace();
-            System.out.println(e.getMessage());
-        }
-
-        System.out.println(111);
-
-
-        return "ok";
-    }
-
-    @PostMapping("/parser2")
-    public String parser2(@RequestBody String message ) {
-
-        //剩余
-        byte[] soc = new byte[]{0x00};
-        //电池组最高温度
-        byte[] battery_temp = {0x32};
-        //剩余时间
-        byte[] remain_time = {0x00, 0x00};
-        //枪线温度
-        byte[] guns_line_temp = new byte[1];
-        //9.枪线温度
-        guns_line_temp[0] = 0x32;
-
-        byte gunsStatus = 3;
-        String imei = "868371073352243";
-        byte guns = 1;
-        double voltage = 136;
-
-        try{
-            //重置电压 直流电压放大10倍
-            if(gunsStatus== StatusConstant.CHARGING){
-                JSONArray dataArray = redisCache.getCacheMapValue("device_last_163",imei+"_"+guns);
-                if(dataArray != null){
-                    //获取soc和剩余时间
-                    //重置soc
-                    soc[0] = (byte) (dataArray.getInteger(21+3) & 0xff);
-
-                    remain_time[0] = dataArray.getByte(22+3);
-                    remain_time[1] = dataArray.getByte(23+3);
-//                    int remainTIme = (dataArray.getInteger(22+3)) | (dataArray.getInteger(23+3)<<8);
-//                    remain_time[1] = (byte) ((remainTIme >> 8) & 0xFF);
-//                    remain_time[0] = (byte) (remainTIme & 0xFF);
-//
-//                    System.out.println(remainTIme);
-//                    System.out.println(remain_time);
-
-
-                    log.info("充电中-soc:{},remain:{}",soc,remain_time);
-                }
-            }
-
-            int time = 136;
-            byte[] charnging_Time = new byte[2];
-            charnging_Time[1] = (byte) ((time >> 8) & 0xFF);
-            charnging_Time[0] = (byte) (time & 0xFF);
-            System.out.println(charnging_Time);
-
-        }catch (Exception e){
-
-        }
-
-        System.out.println(111);
-
-
-        return "ok";
-    }
-
-    @GetMapping("/test163")
-    public AjaxResult test163(HttpServletRequest request ) {
-        String data = request.getParameter("data");
-        List<Integer> split = Arrays.stream(data.split(","))
-                .map(Integer::parseInt)  // 将 String 转换为 Integer
-                .collect(Collectors.toList());  // 收集结果到 List 中
-        List<List<Integer>> packages = Encrytion.parseMorePackage(split);
-
-
-        System.out.println(111);
-
-//        JSONArray objects = new JSONArray(split);
-//        JSONObject obj = new JSONObject();
-//        obj.put("data",objects);
-        // JSONObject object = messageParseMgr.parseMessage("75960_103", obj);
-
-        //  System.out.println(object);
-
-        return null;
-    }
-
-
-    @GetMapping("/parser")
-    public AjaxResult parser(HttpServletRequest request ) {
-
-
-        String data = request.getParameter("data");
-
-        List<Integer> split = Arrays.stream(data.split(","))
-                .map(Integer::parseInt)  // 将 String 转换为 Integer
-                .collect(Collectors.toList());  // 收集结果到 List 中
-
-        List<List<Integer>> packages = Encrytion.parseMorePackage(split);
-
-        System.out.println(packages);
-
-        for(int i=0;i<packages.size();i++){
-            JSONObject obj = new JSONObject();
-            obj.put("data",packages.get(i));
-
-            System.out.println("parser:"+"75960_"+packages.get(i).get(1));
-            JSONObject object = messageParseMgr.parseMessage("75960_"+packages.get(i).get(1),obj);
-            System.out.println(object);
-
-            if(object!=null){
-                String m = object.toString();
-                System.out.println(m);
-            }
-
-
-
-        }
-
-        System.out.println(111);
-
-//        JSONArray objects = new JSONArray(split);
-//        JSONObject obj = new JSONObject();
-//        obj.put("data",objects);
-       // JSONObject object = messageParseMgr.parseMessage("75960_103", obj);
-
-      //  System.out.println(object);
-
-        return null;
-    }
-
-
-    @GetMapping("/test")
-    public String test(@RequestParam("method") String method, @RequestParam("imei") String imei) {
-
-        String deviceId = imei;
-        String ccid = imei;
-        if ("start".equals(method)) {
-            deviceControlerService.startCharge(imei, imei, 1,50000);
-        } else if ("stop".equals(method)) {
-            deviceControlerService.stopCharge(imei, imei, 1);
-        } else if ("port".equals(method)) {
-
-            DeviceParam deviceParam = new DeviceParam();
-            deviceParam.setDeviceId(imei);
-            deviceParam.setCcid(imei);
-            deviceControlerService.sendPortDetailCmd(deviceParam);
-        } else if ("restartDevice".equals(method)) {
-
-            deviceControlerService.restart(imei, imei);
-        } else if ("rest".equals(method)) {
-            deviceControlerService.reset(imei, imei);
-        }
-        return "ok";
-    }
-    private static final Logger logger = LoggerFactory.getLogger(DeviceMsgHandle.class);
-
-    @GetMapping("/test2")
-    public String test2(@RequestParam("pileCode") String pileCode) {
-        //调用重启
-
-      //  redisCache.setCacheMapValue(RedisConstant.PILE_GUN_PAY_TIME, pileCode+"_"+1,System.currentTimeMillis());
-
-//        return "ok";
-//        //标记最后订单时间 5分钟内不上报空闲状态 避免刚下单状态还没更新就被freeTask任务给顶掉了
-
-
-        new Thread(() -> {
-            try {
-                Thread.sleep(5000); // 延迟 5 秒
-                DeviceParam dataParam = new DeviceParam();
-                dataParam.setDeviceId("123456");
-                dataParam.setCcid("123456");
-//                deviceControlerService.sendPortDetailCmd(dataParam);
-                logger.info(":主动下发103消息");
-            } catch (Exception e) {
-                logger.info(":主动下发103消息异常" + e.getMessage());
-            }
-        }).start();
-
-
-
-
-//        try{
-//            long ts = redisCache.getCacheMapValue(RedisConstant.PILE_GUN_PAY_TIME, pileCode+"_1");
-//            if(ts!=0){
-//                long ts1 = System.currentTimeMillis();
-//                if((ts1-ts)<300*1000){
-//                    return "ok";
-//                }
-//            }
-//        }catch (Exception e){
-//            return "error";
-//        }
-
-        return "ok";
-    }
-
-
-
-
-
-    @GetMapping("/test1")
-    public String test1(@RequestParam("pileCode") String pileCode) {
-        //调用重启
-        try{
-            String url = "http://127.0.0.1:8063/api/device/restLogin/"+pileCode;
-            HttpResponse execute = HttpRequest.post(url)
-                    .timeout(3000)
-                    .execute();
-            String body = execute.body();
-            System.out.println("reset login body:>>>"+body);
-        } catch (Exception ex) {
-            System.out.println("reset error :>>>"+ex.toString());
-        }
-        return "ok";
-    }
-
-    @RequestMapping("/testElec")
-    public JSONObject testCompute(@RequestParam("end")Long end,@RequestParam("start")Long star,@RequestParam("imei")String imei,@RequestParam("port")int port) {
-        QueryWrapper<BillingModel> billingModelQueryWrapper = new QueryWrapper<>();
-        BillingModel one = billingModelService.getOne(billingModelQueryWrapper);
-        BillingModelDTO billingModelDTO = billingModelMapping.billingModelToBillingModelDto(one);
-        HashMap<String, Object> map = new HashMap<>();
-        map.put("port",port);
-        map.put("billingModel",billingModelDTO);
-        map.put("startTime",star/1000);
-        map.put("endTime",end/1000);
-        JSONObject jsonObject = new JSONObject(map);
-        String s = jsonObject.toString();
-        HttpResponse execute = HttpRequest.post(url)
-                .form("data",s)
-                .timeout(3000)
-                .execute();
-        int status = execute.getStatus();
-        String body = execute.body();
-        System.out.println("body:>>>"+body);
-        return null;
-
-    }
-}
+package com.tmzn.devicelinkykc.controller;
+
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.tmzn.devicelinkykc.constant.ykc.StatusConstant;
+import com.tmzn.devicelinkykc.entity.BillingModel;
+import com.tmzn.devicelinkykc.entity.Device;
+import com.tmzn.devicelinkykc.entity.DeviceStatus;
+import com.tmzn.devicelinkykc.entity.param.AjaxResult;
+import com.tmzn.devicelinkykc.entity.param.dto.BillingModelDTO;
+import com.tmzn.devicelinkykc.frameMsg.DataConversion;
+import com.tmzn.devicelinkykc.frameMsg.FrameDataSplicing;
+import com.tmzn.devicelinkykc.frameMsg.frameType.LoginFrame;
+import com.tmzn.devicelinkykc.mapstruct.BillingModelMapping;
+import com.tmzn.devicelinkykc.message.DeviceMsgHandle;
+import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
+import com.tmzn.devicelinkykc.redis.RedisCache;
+import com.tmzn.devicelinkykc.service.BillingModelService;
+import com.tmzn.devicelinkykc.service.DeviceControlerService;
+import com.tmzn.devicelinkykc.service.DeviceStatusService;
+import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
+import com.tmzn.devicelinkykc.transdata.entity.DeviceParam;
+import com.tmzn.devicelinkykc.msgparser.MessageParseMgr;
+import com.tmzn.devicelinkykc.util.Encrytion;
+import lombok.extern.slf4j.Slf4j;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author xp
+ * @date 2024/4/13
+ * @explain "  "
+ */
+@Controller
+@Slf4j(topic = "RealTimeStatusPushFrame")
+@RequestMapping
+public class TestController {
+    @Autowired
+    private DeviceControlerService deviceControlerService;
+    @Autowired
+    private BillingModelService billingModelService;
+    @Autowired
+    private BillingModelMapping billingModelMapping;
+    @Value("${billingInterface}")
+    private String url;
+
+    @Autowired
+    private RedisCache redisCache;
+
+    @Autowired
+    private MessageParseMgr messageParseMgr;
+
+    @Autowired
+    private DeviceMsgHandle deviceMsgHandle;
+
+    @PostMapping("/msg")
+    public String testMsg(@RequestBody String message) {
+        try {
+            deviceMsgHandle.testMsg(message);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "ok";
+    }
+
+    @Autowired
+    DeviceStatusService deviceStatusService;
+
+    @PostMapping("/parser1")
+    public String parser1(@RequestBody String message ) {
+
+        try{
+
+            String str_key = "6492806831843423";
+            String code = "";
+            byte[] res = Encrytion.rsaEncrypt(str_key.getBytes(),"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKbtY6sYSeN1uv4pafiaTPMHySxmIosW1Jia1mOcaMmWUQrN57uieY++1wkW3LVg4KY7CG/eeQXAwqbbvoax7yMCAwEAAQ==");
+            System.out.println(res);
+
+            byte[] res1 = Encrytion.rsaEncrypt(str_key.getBytes(),"MFwwDQYJKoZIhycNAQEBBQADSWAWSAJBAKbtY6sYSeN1uv4pafiaTPMHySxmlosW1Jia1mOcaMmWUQrN57uieY++1wkW3LVg4KY7CG/eeQxAwabbvoax7yMCAWEAAQ==");
+            System.out.println(res1);
+
+
+            QueryWrapper<BillingModel> billWapper = new QueryWrapper<>();
+            billWapper.eq("pile_code", "32010600530570");
+            billWapper.eq("device_imei", "863218078065418");
+            BillingModel b = billingModelService.getOne(billWapper);
+            if (b == null) {
+                log.info("{}上报充电中未匹配计费模型", "32010600530570");
+            }
+
+
+
+            QueryWrapper<DeviceStatus> deviceStatusQueryWrapper = new QueryWrapper<>();
+            deviceStatusQueryWrapper.eq("device_imei", "863343064704539");
+            deviceStatusQueryWrapper.last("limit 1");
+            DeviceStatus statusServiceOne = deviceStatusService.getOne(deviceStatusQueryWrapper);
+            System.out.println(statusServiceOne);
+
+//            deviceMsgHandle.deviceMsg(message);
+        }catch (Exception e){
+            e.printStackTrace();
+            System.out.println(e.getMessage());
+        }
+
+        System.out.println(111);
+
+
+        return "ok";
+    }
+
+    @PostMapping("/parser2")
+    public String parser2(@RequestBody String message ) {
+
+        //剩余
+        byte[] soc = new byte[]{0x00};
+        //电池组最高温度
+        byte[] battery_temp = {0x32};
+        //剩余时间
+        byte[] remain_time = {0x00, 0x00};
+        //枪线温度
+        byte[] guns_line_temp = new byte[1];
+        //9.枪线温度
+        guns_line_temp[0] = 0x32;
+
+        byte gunsStatus = 3;
+        String imei = "868371073352243";
+        byte guns = 1;
+        double voltage = 136;
+
+        try{
+            //重置电压 直流电压放大10倍
+            if(gunsStatus== StatusConstant.CHARGING){
+                JSONArray dataArray = redisCache.getCacheMapValue("device_last_163",imei+"_"+guns);
+                if(dataArray != null){
+                    //获取soc和剩余时间
+                    //重置soc
+                    soc[0] = (byte) (dataArray.getInteger(21+3) & 0xff);
+
+                    remain_time[0] = dataArray.getByte(22+3);
+                    remain_time[1] = dataArray.getByte(23+3);
+//                    int remainTIme = (dataArray.getInteger(22+3)) | (dataArray.getInteger(23+3)<<8);
+//                    remain_time[1] = (byte) ((remainTIme >> 8) & 0xFF);
+//                    remain_time[0] = (byte) (remainTIme & 0xFF);
+//
+//                    System.out.println(remainTIme);
+//                    System.out.println(remain_time);
+
+
+                    log.info("充电中-soc:{},remain:{}",soc,remain_time);
+                }
+            }
+
+            int time = 136;
+            byte[] charnging_Time = new byte[2];
+            charnging_Time[1] = (byte) ((time >> 8) & 0xFF);
+            charnging_Time[0] = (byte) (time & 0xFF);
+            System.out.println(charnging_Time);
+
+        }catch (Exception e){
+
+        }
+
+        System.out.println(111);
+
+
+        return "ok";
+    }
+
+    @GetMapping("/test163")
+    public AjaxResult test163(HttpServletRequest request ) {
+        String data = request.getParameter("data");
+        List<Integer> split = Arrays.stream(data.split(","))
+                .map(Integer::parseInt)  // 将 String 转换为 Integer
+                .collect(Collectors.toList());  // 收集结果到 List 中
+        List<List<Integer>> packages = Encrytion.parseMorePackage(split);
+
+
+        System.out.println(111);
+
+//        JSONArray objects = new JSONArray(split);
+//        JSONObject obj = new JSONObject();
+//        obj.put("data",objects);
+        // JSONObject object = messageParseMgr.parseMessage("75960_103", obj);
+
+        //  System.out.println(object);
+
+        return null;
+    }
+
+
+    @GetMapping("/parser")
+    public AjaxResult parser(HttpServletRequest request ) {
+
+
+        String data = request.getParameter("data");
+
+        List<Integer> split = Arrays.stream(data.split(","))
+                .map(Integer::parseInt)  // 将 String 转换为 Integer
+                .collect(Collectors.toList());  // 收集结果到 List 中
+
+        List<List<Integer>> packages = Encrytion.parseMorePackage(split);
+
+        System.out.println(packages);
+
+        for(int i=0;i<packages.size();i++){
+            JSONObject obj = new JSONObject();
+            obj.put("data",packages.get(i));
+
+            System.out.println("parser:"+"75960_"+packages.get(i).get(1));
+            JSONObject object = messageParseMgr.parseMessage("75960_"+packages.get(i).get(1),obj);
+            System.out.println(object);
+
+            if(object!=null){
+                String m = object.toString();
+                System.out.println(m);
+            }
+
+
+
+        }
+
+        System.out.println(111);
+
+//        JSONArray objects = new JSONArray(split);
+//        JSONObject obj = new JSONObject();
+//        obj.put("data",objects);
+       // JSONObject object = messageParseMgr.parseMessage("75960_103", obj);
+
+      //  System.out.println(object);
+
+        return null;
+    }
+
+
+    @GetMapping("/test")
+    public String test(@RequestParam("method") String method, @RequestParam("imei") String imei) {
+
+        String deviceId = imei;
+        String ccid = imei;
+        if ("start".equals(method)) {
+            deviceControlerService.startCharge(imei, imei, 1,50000);
+        } else if ("stop".equals(method)) {
+            deviceControlerService.stopCharge(imei, imei, 1);
+        } else if ("port".equals(method)) {
+
+            DeviceParam deviceParam = new DeviceParam();
+            deviceParam.setDeviceId(imei);
+            deviceParam.setCcid(imei);
+            deviceControlerService.sendPortDetailCmd(deviceParam);
+        } else if ("restartDevice".equals(method)) {
+
+            deviceControlerService.restart(imei, imei);
+        } else if ("rest".equals(method)) {
+            deviceControlerService.reset(imei, imei);
+        }
+        return "ok";
+    }
+    private static final Logger logger = LoggerFactory.getLogger(DeviceMsgHandle.class);
+
+    @GetMapping("/test2")
+    public String test2(@RequestParam("pileCode") String pileCode) {
+        //调用重启
+
+      //  redisCache.setCacheMapValue(RedisConstant.PILE_GUN_PAY_TIME, pileCode+"_"+1,System.currentTimeMillis());
+
+//        return "ok";
+//        //标记最后订单时间 5分钟内不上报空闲状态 避免刚下单状态还没更新就被freeTask任务给顶掉了
+
+
+        new Thread(() -> {
+            try {
+                Thread.sleep(5000); // 延迟 5 秒
+                DeviceParam dataParam = new DeviceParam();
+                dataParam.setDeviceId("123456");
+                dataParam.setCcid("123456");
+//                deviceControlerService.sendPortDetailCmd(dataParam);
+                logger.info(":主动下发103消息");
+            } catch (Exception e) {
+                logger.info(":主动下发103消息异常" + e.getMessage());
+            }
+        }).start();
+
+
+
+
+//        try{
+//            long ts = redisCache.getCacheMapValue(RedisConstant.PILE_GUN_PAY_TIME, pileCode+"_1");
+//            if(ts!=0){
+//                long ts1 = System.currentTimeMillis();
+//                if((ts1-ts)<300*1000){
+//                    return "ok";
+//                }
+//            }
+//        }catch (Exception e){
+//            return "error";
+//        }
+
+        return "ok";
+    }
+
+    @Autowired LoginFrame loginFrame;
+
+    @GetMapping("/test3")
+    public String test3() throws Exception {
+        //调用重启
+
+
+
+        loginFrame.test();
+        return "ok";
+    }
+
+
+
+    @GetMapping("/test1")
+    public String test1(@RequestParam("pileCode") String pileCode) {
+        //调用重启
+        try{
+            String url = "http://127.0.0.1:8063/api/device/restLogin/"+pileCode;
+            HttpResponse execute = HttpRequest.post(url)
+                    .timeout(3000)
+                    .execute();
+            String body = execute.body();
+            System.out.println("reset login body:>>>"+body);
+        } catch (Exception ex) {
+            System.out.println("reset error :>>>"+ex.toString());
+        }
+        return "ok";
+    }
+
+    @RequestMapping("/testElec")
+    public JSONObject testCompute(@RequestParam("end")Long end,@RequestParam("start")Long star,@RequestParam("imei")String imei,@RequestParam("port")int port) {
+        QueryWrapper<BillingModel> billingModelQueryWrapper = new QueryWrapper<>();
+        BillingModel one = billingModelService.getOne(billingModelQueryWrapper);
+        BillingModelDTO billingModelDTO = billingModelMapping.billingModelToBillingModelDto(one);
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("port",port);
+        map.put("billingModel",billingModelDTO);
+        map.put("startTime",star/1000);
+        map.put("endTime",end/1000);
+        JSONObject jsonObject = new JSONObject(map);
+        String s = jsonObject.toString();
+        HttpResponse execute = HttpRequest.post(url)
+                .form("data",s)
+                .timeout(3000)
+                .execute();
+        int status = execute.getStatus();
+        String body = execute.body();
+        System.out.println("body:>>>"+body);
+        return null;
+
+    }
+}

+ 141 - 134
src/main/java/com/tmzn/devicelinkykc/frameMsg/FrameDataSplicing.java

@@ -1,134 +1,141 @@
-package com.tmzn.devicelinkykc.frameMsg;
-
-import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
-
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-
-/**
- * @author xp
- * @date 2024/3/13
- * @explain " 帧数据拼接 "
- */
-public class FrameDataSplicing {
-
-
-
-    public static byte[] spliceing(byte[] seq, int frameType, int encryptFlag, byte[] data, int length,boolean is18) {
-        byte[] outBuf = new byte[8 + data.length];
-        int index = 0;
-        outBuf[index++] = (byte) 0x68; //其实字节
-        outBuf[index++] = (byte) (length + 4); //字节长度
-        outBuf[index++] = (byte) seq[0];
-        outBuf[index++] = (byte) seq[1];
-        outBuf[index++] = (byte) encryptFlag;
-        outBuf[index++] = (byte) frameType;
-        System.arraycopy(data, 0, outBuf, index, length);
-        index += length;
-        int crc;
-        if(is18){
-            crc = modbusCRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
-        }else{
-            crc = modbus16CRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
-        }
-        outBuf[index++] = (byte) (crc & 0x00FF);
-        outBuf[index++] = (byte) ((crc >> 8) & 0x00FF);
-        System.out.println("发送消息>>>"+ DeviceSendYkc.getNameByframeType(frameType)+">>>>>>>>>>"+DataConversion.bytesToHexString(outBuf));
-        return outBuf;
-    }
-
-    /**
-     *
-     * @param seq  序列号
-     * @param frameType     帧类型
-     * @param encryptFlag   加密标志
-     * @param data          消息体
-     * @param length           长度
-     * @return
-     */
-    public static byte[] spliceing(int seq, int frameType, int encryptFlag, byte[] data, int length,boolean is18) {
-        byte[] outBuf = new byte[8 + data.length];
-        int index = 0;
-        outBuf[index++] = (byte) 0x68; //其实字节
-        outBuf[index++] = (byte) (length + 4); //字节长度
-        int seqTemp = seq;
-        outBuf[index++] = (byte) ((seqTemp >> 8) & 0x00FF);
-        outBuf[index++] = (byte) (seqTemp & 0x00FF);
-        outBuf[index++] = (byte) encryptFlag;
-        outBuf[index++] = (byte) frameType;
-        System.arraycopy(data, 0, outBuf, index, length);
-        index += length;
-        int crc;
-        if(is18){
-             crc = modbusCRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
-        }else{
-             crc = modbus16CRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
-        }
-        outBuf[index++] = (byte) (crc & 0x00FF);
-        outBuf[index++] = (byte) ((crc >> 8) & 0x00FF);
-        System.out.println("发送消息>>>"+ DeviceSendYkc.getNameByframeType(frameType)+">>>>>>>>>>"+DataConversion.bytesToHexString(outBuf));
-        return outBuf;
-    }
-
-    /**
-     * CRC 计算函数
-     */
-    private static int modbusCRC(byte[] pData, int len) {
-        int crc = 0xFFFF;
-        for (int i = 0; i < len; i++) {
-            crc = (crc ^ pData[i]) & 0xFF;
-            for (int j = 0; j < 8; j++) {
-                if ((crc & 0x0001) != 0) {
-                    crc = ((crc >> 1) ^ 0xA001) & 0xFFFF;
-                } else {
-                    crc >>= 1;
-                }
-            }
-        }
-        return crc;
-    }
-
-    /**
-     * CRC 计算函数
-     */
-    private static int modbus16CRC(byte[] pData, int len) {
-        int crc = 0xFFFF;
-        for (int i = 0; i < len; i++) {
-            crc ^= pData[i] & 0xFF;
-            for (int j = 0; j < 8; j++) {
-                if ((crc & 0x0001) != 0) {
-                    crc >>= 1;
-                    crc ^= 0xA001;
-                } else {
-                    crc >>= 1;
-                }
-            }
-        }
-        return crc;
-    }
-    /**
-     * 流水号生成
-     */
-    public static byte[] transactionNum(String pilecode,int msgCount){
-        int index = 0;
-        byte[] transaction = new byte[16];  //1.交易流水,自己生成上报状态
-//        byte[] pileCodebytes = DataConversion.bcdToBytes(pilecode, 7);
-//        Date date = new Date();
-//        SimpleDateFormat yy = new SimpleDateFormat("yy-MM-dd-HH-mm-ss");
-//        String format = yy.format(date);
-//        System.out.println(format);
-//        String[] split = format.split("-");
-//        byte[] time1 = new byte[6];
-//        time1[0] = 20;
-//        for (int i = 1; i < split.length; i++) {
-//            time1[i] = Byte.parseByte(split[i - 1]);
-//        }
-//
-//        System.arraycopy(pileCodebytes, 0, transaction, 0, pileCodebytes.length);
-//        System.arraycopy(time1, 0, transaction, 7, time1.length);
-//        transaction[14] = (byte) ((msgCount >> 8) & 0xFF);//自增
-//        transaction[15] = (byte) (msgCount & 0xFF);
-        return transaction;
-    }
-}
+package com.tmzn.devicelinkykc.frameMsg;
+
+import com.tmzn.devicelinkykc.frameMsg.frameType.YunCrcUtil;
+import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
+
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+
+/**
+ * @author xp
+ * @date 2024/3/13
+ * @explain " 帧数据拼接 "
+ */
+public class FrameDataSplicing {
+
+
+
+    public static byte[] spliceing(byte[] seq, int frameType, int encryptFlag, byte[] data, int length,boolean is18) {
+        byte[] outBuf = new byte[8 + data.length];
+        int index = 0;
+        outBuf[index++] = (byte) 0x68; //其实字节
+        outBuf[index++] = (byte) (length + 4); //字节长度
+        outBuf[index++] = (byte) seq[0];
+        outBuf[index++] = (byte) seq[1];
+        outBuf[index++] = (byte) encryptFlag;
+        outBuf[index++] = (byte) frameType;
+        System.arraycopy(data, 0, outBuf, index, length);
+        index += length;
+        int crc;
+        if(is18){
+            crc = modbusCRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
+        }else{
+            crc = modbus16CRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
+        }
+        outBuf[index++] = (byte) (crc & 0x00FF);
+        outBuf[index++] = (byte) ((crc >> 8) & 0x00FF);
+        System.out.println("发送消息>>>"+ DeviceSendYkc.getNameByframeType(frameType)+">>>>>>>>>>"+DataConversion.bytesToHexString(outBuf));
+        return outBuf;
+    }
+
+    /**
+     *
+     * @param seq  序列号
+     * @param frameType     帧类型
+     * @param encryptFlag   加密标志
+     * @param data          消息体
+     * @param length           长度
+     * @return
+     */
+    public static byte[] spliceing(int seq, int frameType, int encryptFlag, byte[] data, int length,boolean is18) {
+        byte[] outBuf = new byte[8 + data.length];
+        int index = 0;
+        outBuf[index++] = (byte) 0x68; //其实字节
+        outBuf[index++] = (byte) (length + 4); //字节长度
+        int seqTemp = seq;
+        outBuf[index++] = (byte) ((seqTemp >> 8) & 0x00FF);
+        outBuf[index++] = (byte) (seqTemp & 0x00FF);
+        outBuf[index++] = (byte) encryptFlag;
+        outBuf[index++] = (byte) frameType;
+        System.arraycopy(data, 0, outBuf, index, length);
+        index += length;
+        int crc;
+        if(is18){
+             crc = modbusCRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
+        }else{
+            crc = YunCrcUtil.calculateCrc( Arrays.copyOfRange(outBuf, 2, index));
+             //crc = modbus16CRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
+//            int c1  = modbus16CRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
+//
+//            int c2 = modbusCRC(Arrays.copyOfRange(outBuf, 2, index), index - 2);
+//            System.out.println(c1);
+//            System.out.println(c2);
+        }
+        outBuf[index++] = (byte) (crc & 0x00FF);
+        outBuf[index++] = (byte) ((crc >> 8) & 0x00FF);
+        System.out.println("发送消息>>>"+ DeviceSendYkc.getNameByframeType(frameType)+">>>>>>>>>>"+DataConversion.bytesToHexString(outBuf));
+        return outBuf;
+    }
+
+    /**
+     * CRC 计算函数
+     */
+    private static int modbusCRC(byte[] pData, int len) {
+        int crc = 0xFFFF;
+        for (int i = 0; i < len; i++) {
+            crc = (crc ^ pData[i]) & 0xFF;
+            for (int j = 0; j < 8; j++) {
+                if ((crc & 0x0001) != 0) {
+                    crc = ((crc >> 1) ^ 0xA001) & 0xFFFF;
+                } else {
+                    crc >>= 1;
+                }
+            }
+        }
+        return crc;
+    }
+
+    /**
+     * CRC 计算函数
+     */
+    private static int modbus16CRC(byte[] pData, int len) {
+        int crc = 0xFFFF;
+        for (int i = 0; i < len; i++) {
+            crc ^= pData[i] & 0xFF;
+            for (int j = 0; j < 8; j++) {
+                if ((crc & 0x0001) != 0) {
+                    crc >>= 1;
+                    crc ^= 0xA001;
+                } else {
+                    crc >>= 1;
+                }
+            }
+        }
+        return crc;
+    }
+    /**
+     * 流水号生成
+     */
+    public static byte[] transactionNum(String pilecode,int msgCount){
+        int index = 0;
+        byte[] transaction = new byte[16];  //1.交易流水,自己生成上报状态
+//        byte[] pileCodebytes = DataConversion.bcdToBytes(pilecode, 7);
+//        Date date = new Date();
+//        SimpleDateFormat yy = new SimpleDateFormat("yy-MM-dd-HH-mm-ss");
+//        String format = yy.format(date);
+//        System.out.println(format);
+//        String[] split = format.split("-");
+//        byte[] time1 = new byte[6];
+//        time1[0] = 20;
+//        for (int i = 1; i < split.length; i++) {
+//            time1[i] = Byte.parseByte(split[i - 1]);
+//        }
+//
+//        System.arraycopy(pileCodebytes, 0, transaction, 0, pileCodebytes.length);
+//        System.arraycopy(time1, 0, transaction, 7, time1.length);
+//        transaction[14] = (byte) ((msgCount >> 8) & 0xFF);//自增
+//        transaction[15] = (byte) (msgCount & 0xFF);
+        return transaction;
+    }
+}

+ 237 - 217
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/LoginFrame.java

@@ -1,217 +1,237 @@
-package com.tmzn.devicelinkykc.frameMsg.frameType;
-
-import com.tmzn.devicelinkykc.constant.RedisConstant;
-import com.tmzn.devicelinkykc.entity.Device;
-import com.tmzn.devicelinkykc.entity.GdDispostion;
-import com.tmzn.devicelinkykc.frameMsg.DataConversion;
-import com.tmzn.devicelinkykc.frameMsg.FrameDataSplicing;
-import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
-import com.tmzn.devicelinkykc.redis.RedisCache;
-import com.tmzn.devicelinkykc.service.GdDispostionService;
-import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
-import com.tmzn.devicelinkykc.socket.SocketHandle;
-import com.tmzn.devicelinkykc.util.Encrytion;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.io.IOException;
-import java.util.Base64;
-import java.util.Random;
-
-/**
- * @author xp
- * @date 2024/3/14
- * @explain " 登录认证 不加密"
- */
-@Component
-public class LoginFrame {
-
-    @Autowired
-    private SocketHandle socketHandle;
-
-    private static final Logger log = LoggerFactory.getLogger(LoginFrame.class);
-    @Autowired
-    private RedisCache redisCache;
-
-    @Autowired
-    private BillingModelFrame billingModelFrame;
-
-
-    @Autowired
-    private GdDispostionService gdDispostionService;
-
-    public void loginMsgSend(DeviceConnectionMsg deviceConnectionMsg,Device device){
-        if(deviceConnectionMsg.getLoginMsgSend()) {
-            log.info("has send login msg {}", device.getPileCode());
-            return;
-        }
-
-        byte[] send = new byte[0];
-        try {
-            if(deviceConnectionMsg.getIs18()){
-                send = loginMsg18(device);
-            }else{
-                send = loginMsgNot18(device);
-            }
-        } catch (Exception e) {
-            log.info("pileCode:"+device.getPileCode()+" login params Exception:");
-            e.printStackTrace();
-        }
-        if (send.length>0) {
-            log.info("{}>设备登录消息上送>>>"+DataConversion.bytesToHexString(send),device.getPileCode());
-            byte[] bytes = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.LOGIN.getFrameType(), DeviceSendYkc.LOGIN.getEncryptFlag(), send, send.length, deviceConnectionMsg.getIs18());
-            try {
-                deviceConnectionMsg.getOutputStream().write(bytes);
-                deviceConnectionMsg.getOutputStream().flush();
-                deviceConnectionMsg.incrementMessageCount();
-                deviceConnectionMsg.setLoginMsgSend();
-            } catch (IOException e) {
-                log.info("pileCode:" + device.getPileCode() + " ,login push frame Exception");
-                e.printStackTrace();
-                //发送异常直接停止
-                socketHandle.removeDeviceConnection(device.getPileCode());
-            }
-        }else {
-            log.info("pileCode:"+device.getPileCode()+" login params null");
-        }
-        log.info("pileCode:"+device.getPileCode()+" login over");
-    }
-
-    private byte[] loginMsgNot18( Device device) throws Exception {
-
-        byte[] msg = new byte[30];//消息体
-
-        int index = 0;
-        //1.桩编码
-        byte[] pile_code = new byte[7];
-        byte[] bcd = DataConversion.bcdToBytes(device.getPileCode(), pile_code.length);
-        System.arraycopy(bcd, 0, pile_code, 0, bcd.length);
-        System.arraycopy(pile_code, 0, msg, index, pile_code.length);
-        index += pile_code.length;
-        //3. 充电桩类型,0:直流,1:交流
-        byte[] pile_type = new byte[]{device.getPileType()};
-        System.arraycopy(pile_type, 0, msg, index, pile_type.length);
-        index += pile_type.length;
-        // 4.充电枪连接数
-        byte[] charger_gun_num = new byte[]{device.getChargerGunNum()};
-        System.arraycopy(charger_gun_num, 0, msg, index, charger_gun_num.length);
-        index += charger_gun_num.length;
-        // 5.通讯协议版本
-        byte[] comm_protocol_ver = new byte[1]; // 通讯协议版本
-
-        // 提取前两位
-        String[] parts = device.getCommProtocolVer().split("\\.");
-        String firstTwoParts = parts[0] + "." + parts[1];
-        // 转换为数字并乘以 10
-        double number = Double.parseDouble(firstTwoParts);
-        double result = number * 10;
-        byte byteValue = (byte) result;
-        comm_protocol_ver[0] = byteValue;
-
-        System.arraycopy(comm_protocol_ver, 0, msg, index, comm_protocol_ver.length);
-        index += comm_protocol_ver.length;
-
-        //6.程序版本
-        byte[] program_version = new byte[8];
-        byte[] program_versions = device.getProgramVersion().getBytes();
-        System.arraycopy(program_versions, 0, program_version, 0, program_versions.length);
-
-        System.arraycopy(program_version, 0, msg, index, program_version.length);
-        index += program_version.length;
-        // 7.网络链接类型,0:sim 卡
-        byte[] net_link_type = new byte[]{device.getNetLinkType()};
-        System.arraycopy(net_link_type, 0, msg, index, net_link_type.length);
-        index += net_link_type.length;
-        //8.SIM卡
-        byte[] sim_card = new byte[10];
-        sim_card = DataConversion.bcdToBytes(device.getSimCard(), sim_card.length);
-        System.arraycopy(sim_card, 0, msg, index, sim_card.length);
-        index += sim_card.length;
-        // 9.运营商,0:移动
-        byte[] operators = new byte[]{device.getOperators()};
-        System.arraycopy(operators, 0, msg, index, operators.length);
-        index += operators.length;
-
-        return msg;
-
-    }
-
-    private byte[] loginMsg18( Device device) throws Exception {
-//        Random random = new Random();
-//        StringBuilder sb = new StringBuilder();
-//        for (int i = 0; i < 16; i++) {
-//            sb.append(random.nextInt(10));
-//        }
-        byte[] msg = new byte[127];//消息体
-        // 密钥
-//        String str_key = sb.toString();
-
-        String str_key = "6492806831843423";
-
-        //当前通讯的密钥缓存到redis
-        //20240627:要求对接其他按云快充对接的
-        GdDispostion dispostionServiceById = gdDispostionService.getById(device.getOperatorsId());
-//        redisCache.setCacheObject(RedisConstant.KEYS +device.getPileCode(), str_key);
-        redisCache.setCacheMapValue(RedisConstant.YKC_KEY_MAP,device.getPileCode(),str_key);
-
-        log.info("LOGIN>>>>16weikey>>>>>>>"+str_key);
-        byte[] bytes = Encrytion.rsaEncrypt(str_key.getBytes(),dispostionServiceById.getCode());
-        byte[] base_encode = Base64.getEncoder().encode(bytes);
-        //1.随机密钥
-        byte[] random_key = new byte[88];
-        System.arraycopy(base_encode, 0, random_key, 0, base_encode.length);
-        int index = 0;
-        System.arraycopy(random_key, 0, msg, index, random_key.length);
-        index += random_key.length;
-        //2.桩编码
-        byte[] pile_code = new byte[7];
-        byte[] bcd = DataConversion.bcdToBytes(device.getPileCode(), pile_code.length);
-        System.arraycopy(bcd, 0, pile_code, 0, bcd.length);
-        System.arraycopy(pile_code, 0, msg, index, pile_code.length);
-        index += pile_code.length;
-        //3. 充电桩类型,0:直流,1:交流
-        byte[] pile_type = new byte[]{device.getPileType()};
-        System.arraycopy(pile_type, 0, msg, index, pile_type.length);
-        index += pile_type.length;
-        // 4.充电枪连接数
-        byte[] charger_gun_num = new byte[]{device.getChargerGunNum()};
-        System.arraycopy(charger_gun_num, 0, msg, index, charger_gun_num.length);
-        index += charger_gun_num.length;
-        // 5.通讯协议版本
-        byte[] comm_protocol_ver = new byte[3]; // 通讯协议版本
-        String[] split = device.getCommProtocolVer().split("\\.");
-        for (int i = 0; i < split.length; i++) {
-            comm_protocol_ver[i] = Byte.parseByte(split[i]);
-        }
-        System.arraycopy(comm_protocol_ver, 0, msg, index, comm_protocol_ver.length);
-        index += comm_protocol_ver.length;
-
-        //6.程序版本
-        byte[] program_version = new byte[8];
-        byte[] program_versions = device.getProgramVersion().getBytes();
-        System.arraycopy(program_versions, 0, program_version, 0, program_versions.length);
-        System.arraycopy(program_version, 0, msg, index, program_version.length);
-        index += program_version.length;
-        // 7.网络链接类型,0:sim 卡
-        byte[] net_link_type = new byte[]{device.getNetLinkType()};
-        System.arraycopy(net_link_type, 0, msg, index, net_link_type.length);
-        index += net_link_type.length;
-        //8.SIM卡
-        byte[] sim_card = new byte[10];
-        sim_card = DataConversion.bcdToBytes(device.getSimCard(), sim_card.length);
-        System.arraycopy(sim_card, 0, msg, index, sim_card.length);
-        index += sim_card.length;
-        // 9.运营商,0:移动
-        byte[] operators = new byte[]{device.getOperators()};
-        System.arraycopy(operators, 0, msg, index, operators.length);
-        index += operators.length;
-        //10 token
-        byte[] token = new byte[7];
-        token = DataConversion.bcdToBytes(device.getToken(), token.length);
-        System.arraycopy(token, 0, msg, index, token.length);
-        index += token.length;
-        return msg;
-    }
-}
+package com.tmzn.devicelinkykc.frameMsg.frameType;
+
+import com.tmzn.devicelinkykc.constant.RedisConstant;
+import com.tmzn.devicelinkykc.entity.Device;
+import com.tmzn.devicelinkykc.entity.GdDispostion;
+import com.tmzn.devicelinkykc.frameMsg.DataConversion;
+import com.tmzn.devicelinkykc.frameMsg.FrameDataSplicing;
+import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
+import com.tmzn.devicelinkykc.redis.RedisCache;
+import com.tmzn.devicelinkykc.service.GdDispostionService;
+import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
+import com.tmzn.devicelinkykc.socket.SocketHandle;
+import com.tmzn.devicelinkykc.util.Encrytion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.Base64;
+import java.util.Random;
+
+/**
+ * @author xp
+ * @date 2024/3/14
+ * @explain " 登录认证 不加密"
+ */
+@Component
+public class LoginFrame {
+
+    @Autowired
+    private SocketHandle socketHandle;
+
+    private static final Logger log = LoggerFactory.getLogger(LoginFrame.class);
+    @Autowired
+    private RedisCache redisCache;
+
+    @Autowired
+    private BillingModelFrame billingModelFrame;
+
+
+    @Autowired
+    private GdDispostionService gdDispostionService;
+
+    public void loginMsgSend(DeviceConnectionMsg deviceConnectionMsg,Device device){
+        if(deviceConnectionMsg.getLoginMsgSend()) {
+            log.info("has send login msg {}", device.getPileCode());
+            return;
+        }
+
+        byte[] send = new byte[0];
+        try {
+            if(deviceConnectionMsg.getIs18()){
+                send = loginMsg18(device);
+            }else{
+                send = loginMsgNot18(device);
+            }
+        } catch (Exception e) {
+            log.info("pileCode:"+device.getPileCode()+" login params Exception:");
+            e.printStackTrace();
+        }
+        if (send.length>0) {
+            log.info("{}>设备登录消息上送>>>"+DataConversion.bytesToHexString(send),device.getPileCode());
+            byte[] bytes = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.LOGIN.getFrameType(), DeviceSendYkc.LOGIN.getEncryptFlag(), send, send.length, deviceConnectionMsg.getIs18());
+            try {
+                deviceConnectionMsg.getOutputStream().write(bytes);
+                deviceConnectionMsg.getOutputStream().flush();
+                deviceConnectionMsg.incrementMessageCount();
+                deviceConnectionMsg.setLoginMsgSend();
+            } catch (IOException e) {
+                log.info("pileCode:" + device.getPileCode() + " ,login push frame Exception");
+                e.printStackTrace();
+                //发送异常直接停止
+                socketHandle.removeDeviceConnection(device.getPileCode());
+            }
+        }else {
+            log.info("pileCode:"+device.getPileCode()+" login params null");
+        }
+        log.info("pileCode:"+device.getPileCode()+" login over");
+    }
+
+    public void test() throws Exception {
+        Device device = new Device();
+        device.setPileCode("21010525042910");
+        device.setCommProtocolVer("1.5");
+        device.setProgramVersion("1.0");
+        device.setSimCard("0");
+        device.setChargerGunNum((byte) 1);
+        device.setPileType((byte) 0);
+        device.setNetLinkType((byte) 3);
+        device.setOperators((byte) 4);
+
+
+        byte[]   send = loginMsgNot18(device);
+        log.info("{}>设备登录消息上送>>>"+DataConversion.bytesToHexString(send),device.getPileCode());
+        byte[] bytes = FrameDataSplicing.spliceing(1, DeviceSendYkc.LOGIN.getFrameType(), DeviceSendYkc.LOGIN.getEncryptFlag(), send, send.length, false);
+
+        System.out.println(bytes);
+
+    }
+
+    private byte[] loginMsgNot18( Device device) throws Exception {
+
+        byte[] msg = new byte[30];//消息体
+
+        int index = 0;
+        //1.桩编码
+        byte[] pile_code = new byte[7];
+        byte[] bcd = DataConversion.bcdToBytes(device.getPileCode(), pile_code.length);
+        System.arraycopy(bcd, 0, pile_code, 0, bcd.length);
+        System.arraycopy(pile_code, 0, msg, index, pile_code.length);
+        index += pile_code.length;
+        //3. 充电桩类型,0:直流,1:交流
+        byte[] pile_type = new byte[]{device.getPileType()};
+        System.arraycopy(pile_type, 0, msg, index, pile_type.length);
+        index += pile_type.length;
+        // 4.充电枪连接数
+        byte[] charger_gun_num = new byte[]{device.getChargerGunNum()};
+        System.arraycopy(charger_gun_num, 0, msg, index, charger_gun_num.length);
+        index += charger_gun_num.length;
+        // 5.通讯协议版本
+        byte[] comm_protocol_ver = new byte[1]; // 通讯协议版本
+
+        // 提取前两位
+        String[] parts = device.getCommProtocolVer().split("\\.");
+        String firstTwoParts = parts[0] + "." + parts[1];
+        // 转换为数字并乘以 10
+        double number = Double.parseDouble(firstTwoParts);
+        double result = number * 10;
+        byte byteValue = (byte) result;
+        comm_protocol_ver[0] = byteValue;
+
+        System.arraycopy(comm_protocol_ver, 0, msg, index, comm_protocol_ver.length);
+        index += comm_protocol_ver.length;
+
+        //6.程序版本
+        byte[] program_version = new byte[8];
+        byte[] program_versions = device.getProgramVersion().getBytes();
+        System.arraycopy(program_versions, 0, program_version, 0, program_versions.length);
+
+        System.arraycopy(program_version, 0, msg, index, program_version.length);
+        index += program_version.length;
+        // 7.网络链接类型,0:sim 卡
+        byte[] net_link_type = new byte[]{device.getNetLinkType()};
+        System.arraycopy(net_link_type, 0, msg, index, net_link_type.length);
+        index += net_link_type.length;
+        //8.SIM卡
+        byte[] sim_card = new byte[10];
+        sim_card = DataConversion.bcdToBytes(device.getSimCard(), sim_card.length);
+        System.arraycopy(sim_card, 0, msg, index, sim_card.length);
+        index += sim_card.length;
+        // 9.运营商,0:移动
+        byte[] operators = new byte[]{device.getOperators()};
+        System.arraycopy(operators, 0, msg, index, operators.length);
+        index += operators.length;
+
+        return msg;
+
+    }
+
+    private byte[] loginMsg18( Device device) throws Exception {
+//        Random random = new Random();
+//        StringBuilder sb = new StringBuilder();
+//        for (int i = 0; i < 16; i++) {
+//            sb.append(random.nextInt(10));
+//        }
+        byte[] msg = new byte[127];//消息体
+        // 密钥
+//        String str_key = sb.toString();
+
+        String str_key = "6492806831843423";
+
+        //当前通讯的密钥缓存到redis
+        //20240627:要求对接其他按云快充对接的
+        GdDispostion dispostionServiceById = gdDispostionService.getById(device.getOperatorsId());
+//        redisCache.setCacheObject(RedisConstant.KEYS +device.getPileCode(), str_key);
+        redisCache.setCacheMapValue(RedisConstant.YKC_KEY_MAP,device.getPileCode(),str_key);
+
+        log.info("LOGIN>>>>16weikey>>>>>>>"+str_key);
+        byte[] bytes = Encrytion.rsaEncrypt(str_key.getBytes(),dispostionServiceById.getCode());
+        byte[] base_encode = Base64.getEncoder().encode(bytes);
+        //1.随机密钥
+        byte[] random_key = new byte[88];
+        System.arraycopy(base_encode, 0, random_key, 0, base_encode.length);
+        int index = 0;
+        System.arraycopy(random_key, 0, msg, index, random_key.length);
+        index += random_key.length;
+        //2.桩编码
+        byte[] pile_code = new byte[7];
+        byte[] bcd = DataConversion.bcdToBytes(device.getPileCode(), pile_code.length);
+        System.arraycopy(bcd, 0, pile_code, 0, bcd.length);
+        System.arraycopy(pile_code, 0, msg, index, pile_code.length);
+        index += pile_code.length;
+        //3. 充电桩类型,0:直流,1:交流
+        byte[] pile_type = new byte[]{device.getPileType()};
+        System.arraycopy(pile_type, 0, msg, index, pile_type.length);
+        index += pile_type.length;
+        // 4.充电枪连接数
+        byte[] charger_gun_num = new byte[]{device.getChargerGunNum()};
+        System.arraycopy(charger_gun_num, 0, msg, index, charger_gun_num.length);
+        index += charger_gun_num.length;
+        // 5.通讯协议版本
+        byte[] comm_protocol_ver = new byte[3]; // 通讯协议版本
+        String[] split = device.getCommProtocolVer().split("\\.");
+        for (int i = 0; i < split.length; i++) {
+            comm_protocol_ver[i] = Byte.parseByte(split[i]);
+        }
+        System.arraycopy(comm_protocol_ver, 0, msg, index, comm_protocol_ver.length);
+        index += comm_protocol_ver.length;
+
+        //6.程序版本
+        byte[] program_version = new byte[8];
+        byte[] program_versions = device.getProgramVersion().getBytes();
+        System.arraycopy(program_versions, 0, program_version, 0, program_versions.length);
+        System.arraycopy(program_version, 0, msg, index, program_version.length);
+        index += program_version.length;
+        // 7.网络链接类型,0:sim 卡
+        byte[] net_link_type = new byte[]{device.getNetLinkType()};
+        System.arraycopy(net_link_type, 0, msg, index, net_link_type.length);
+        index += net_link_type.length;
+        //8.SIM卡
+        byte[] sim_card = new byte[10];
+        sim_card = DataConversion.bcdToBytes(device.getSimCard(), sim_card.length);
+        System.arraycopy(sim_card, 0, msg, index, sim_card.length);
+        index += sim_card.length;
+        // 9.运营商,0:移动
+        byte[] operators = new byte[]{device.getOperators()};
+        System.arraycopy(operators, 0, msg, index, operators.length);
+        index += operators.length;
+        //10 token
+        byte[] token = new byte[7];
+        token = DataConversion.bcdToBytes(device.getToken(), token.length);
+        System.arraycopy(token, 0, msg, index, token.length);
+        index += token.length;
+        return msg;
+    }
+}

+ 79 - 0
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/YunCrcUtil.java

@@ -0,0 +1,79 @@
+package com.tmzn.devicelinkykc.frameMsg.frameType;
+
+
+import java.util.Arrays;
+
+/**
+ * @author hua
+ * @date 2023-08-22
+ */
+public class YunCrcUtil {
+    private YunCrcUtil() {
+
+    }
+
+    public static final byte[] gabyCRCHi = {
+            (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+            (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+            (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+            (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+            (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+            (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+            (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+            (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+            (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+            (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+            (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+            (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+            (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+            (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+            (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+            (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40
+    };
+
+    public static final byte[] gabyCRCLo = {
+            (byte) 0x00, (byte) 0xC0, (byte) 0xC1, (byte) 0x01, (byte) 0xC3, (byte) 0x03, (byte) 0x02, (byte) 0xC2, (byte) 0xC6, (byte) 0x06, (byte) 0x07, (byte) 0xC7, (byte) 0x05, (byte) 0xC5, (byte) 0xC4, (byte) 0x04,
+            (byte) 0xCC, (byte) 0x0C, (byte) 0x0D, (byte) 0xCD, (byte) 0x0F, (byte) 0xCF, (byte) 0xCE, (byte) 0x0E, (byte) 0x0A, (byte) 0xCA, (byte) 0xCB, (byte) 0x0B, (byte) 0xC9, (byte) 0x09, (byte) 0x08, (byte) 0xC8,
+            (byte) 0xD8, (byte) 0x18, (byte) 0x19, (byte) 0xD9, (byte) 0x1B, (byte) 0xDB, (byte) 0xDA, (byte) 0x1A, (byte) 0x1E, (byte) 0xDE, (byte) 0xDF, (byte) 0x1F, (byte) 0xDD, (byte) 0x1D, (byte) 0x1C, (byte) 0xDC,
+            (byte) 0x14, (byte) 0xD4, (byte) 0xD5, (byte) 0x15, (byte) 0xD7, (byte) 0x17, (byte) 0x16, (byte) 0xD6, (byte) 0xD2, (byte) 0x12, (byte) 0x13, (byte) 0xD3, (byte) 0x11, (byte) 0xD1, (byte) 0xD0, (byte) 0x10,
+            (byte) 0xF0, (byte) 0x30, (byte) 0x31, (byte) 0xF1, (byte) 0x33, (byte) 0xF3, (byte) 0xF2, (byte) 0x32, (byte) 0x36, (byte) 0xF6, (byte) 0xF7, (byte) 0x37, (byte) 0xF5, (byte) 0x35, (byte) 0x34, (byte) 0xF4,
+            (byte) 0x3C, (byte) 0xFC, (byte) 0xFD, (byte) 0x3D, (byte) 0xFF, (byte) 0x3F, (byte) 0x3E, (byte) 0xFE, (byte) 0xFA, (byte) 0x3A, (byte) 0x3B, (byte) 0xFB, (byte) 0x39, (byte) 0xF9, (byte) 0xF8, (byte) 0x38,
+            (byte) 0x28, (byte) 0xE8, (byte) 0xE9, (byte) 0x29, (byte) 0xEB, (byte) 0x2B, (byte) 0x2A, (byte) 0xEA, (byte) 0xEE, (byte) 0x2E, (byte) 0x2F, (byte) 0xEF, (byte) 0x2D, (byte) 0xED, (byte) 0xEC, (byte) 0x2C,
+            (byte) 0xE4, (byte) 0x24, (byte) 0x25, (byte) 0xE5, (byte) 0x27, (byte) 0xE7, (byte) 0xE6, (byte) 0x26, (byte) 0x22, (byte) 0xE2, (byte) 0xE3, (byte) 0x23, (byte) 0xE1, (byte) 0x21, (byte) 0x20, (byte) 0xE0,
+            (byte) 0xA0, (byte) 0x60, (byte) 0x61, (byte) 0xA1, (byte) 0x63, (byte) 0xA3, (byte) 0xA2, (byte) 0x62, (byte) 0x66, (byte) 0xA6, (byte) 0xA7, (byte) 0x67, (byte) 0xA5, (byte) 0x65, (byte) 0x64, (byte) 0xA4,
+            (byte) 0x6C, (byte) 0xAC, (byte) 0xAD, (byte) 0x6D, (byte) 0xAF, (byte) 0x6F, (byte) 0x6E, (byte) 0xAE, (byte) 0xAA, (byte) 0x6A, (byte) 0x6B, (byte) 0xAB, (byte) 0x69, (byte) 0xA9, (byte) 0xA8, (byte) 0x68,
+            (byte) 0x78, (byte) 0xB8, (byte) 0xB9, (byte) 0x79, (byte) 0xBB, (byte) 0x7B, (byte) 0x7A, (byte) 0xBA, (byte) 0xBE, (byte) 0x7E, (byte) 0x7F, (byte) 0xBF, (byte) 0x7D, (byte) 0xBD, (byte) 0xBC, (byte) 0x7C,
+            (byte) 0xB4, (byte) 0x74, (byte) 0x75, (byte) 0xB5, (byte) 0x77, (byte) 0xB7, (byte) 0xB6, (byte) 0x76, (byte) 0x72, (byte) 0xB2, (byte) 0xB3, (byte) 0x73, (byte) 0xB1, (byte) 0x71, (byte) 0x70, (byte) 0xB0,
+            (byte) 0x50, (byte) 0x90, (byte) 0x91, (byte) 0x51, (byte) 0x93, (byte) 0x53, (byte) 0x52, (byte) 0x92, (byte) 0x96, (byte) 0x56, (byte) 0x57, (byte) 0x97, (byte) 0x55, (byte) 0x95, (byte) 0x94, (byte) 0x54,
+            (byte) 0x9C, (byte) 0x5C, (byte) 0x5D, (byte) 0x9D, (byte) 0x5F, (byte) 0x9F, (byte) 0x9E, (byte) 0x5E, (byte) 0x5A, (byte) 0x9A, (byte) 0x9B, (byte) 0x5B, (byte) 0x99, (byte) 0x59, (byte) 0x58, (byte) 0x98,
+            (byte) 0x88, (byte) 0x48, (byte) 0x49, (byte) 0x89, (byte) 0x4B, (byte) 0x8B, (byte) 0x8A, (byte) 0x4A, (byte) 0x4E, (byte) 0x8E, (byte) 0x8F, (byte) 0x4F, (byte) 0x8D, (byte) 0x4D, (byte) 0x4C, (byte) 0x8C,
+            (byte) 0x44, (byte) 0x84, (byte) 0x85, (byte) 0x45, (byte) 0x87, (byte) 0x47, (byte) 0x46, (byte) 0x86, (byte) 0x82, (byte) 0x42, (byte) 0x43, (byte) 0x83, (byte) 0x41, (byte) 0x81, (byte) 0x80, (byte) 0x40
+    };
+
+    public static int calculateCrc(byte[] data) {
+        int crc;
+        int ucCRCHi = 0x00ff;
+        int ucCRCLo = 0x00ff;
+        int iIndex;
+        for (int i = 0; i < data.length; ++i) {
+            iIndex = (ucCRCLo ^ data[i]) & 0x00ff;
+            ucCRCLo = ucCRCHi ^ gabyCRCHi[iIndex];
+            ucCRCHi = gabyCRCLo[iIndex];
+        }
+
+        crc = ((ucCRCHi & 0x00ff) << 8) | (ucCRCLo & 0x00ff) & 0xffff;
+        crc = ( (crc & 0xFF00) >> 8) | ( (crc & 0x00FF ) << 8);
+
+        return crc;
+        //byte[] bytes = toBytes(crc);
+
+      //  return Arrays.copyOfRange(bytes, 2, 4);
+    }
+
+
+    public static byte[] toBytes(int value) {
+        byte[] result = new byte[]{(byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)value};
+        return result;
+    }
+
+}