Преглед изворни кода

[功能修复]添加直流soc上报

liuf пре 10 месеци
родитељ
комит
863a969e03

+ 85 - 0
src/main/java/com/tmzn/devicelinkykc/controller/TestController.java

@@ -5,9 +5,11 @@ 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.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;
@@ -16,6 +18,7 @@ import com.tmzn.devicelinkykc.service.DeviceControlerService;
 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;
@@ -28,6 +31,7 @@ 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;
@@ -39,6 +43,7 @@ import java.util.stream.Collectors;
  * @explain "  "
  */
 @Controller
+@Slf4j(topic = "RealTimeStatusPushFrame")
 @RequestMapping
 public class TestController {
     @Autowired
@@ -85,6 +90,86 @@ public class TestController {
         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 ) {
 

+ 51 - 9
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/RealTimeStatusPushFrame.java

@@ -2,7 +2,9 @@ package com.tmzn.devicelinkykc.frameMsg.frameType;
 
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
+import com.alibaba.fastjson2.JSONArray;
 import com.tmzn.devicelinkykc.constant.RedisConstant;
+import com.tmzn.devicelinkykc.constant.ykc.StatusConstant;
 import com.tmzn.devicelinkykc.frameMsg.DataConversion;
 import com.tmzn.devicelinkykc.frameMsg.FrameDataSplicing;
 import com.tmzn.devicelinkykc.msgEnum.DeviceSendYkc;
@@ -32,10 +34,11 @@ public class RealTimeStatusPushFrame {
     public void deviceStatusPush(DeviceConnectionMsg deviceConnectionMsg, byte[] trans, String pileCode, byte guns, byte gunsStatus, byte gunsInsert, double voltage, double power, BigDecimal elec, BigDecimal money, int time) {
         byte[] encrypt = new byte[0];
 
+
         int encFlag = DeviceSendYkc.UPLOAD_DEVICE_STATUS_RESPONSE.getEncryptFlag();
         if(deviceConnectionMsg.getIs18()){
             try {
-                byte[] send = upStatusDevice(trans, pileCode, guns, gunsStatus, gunsInsert, voltage, power, elec, money, time);
+                byte[] send = upStatusDevice(deviceConnectionMsg,trans, pileCode, guns, gunsStatus, gunsInsert, voltage, power, elec, money, time);
                 log.info("deviceStatusPush>{}reporting>>>"+DataConversion.bytesToHexString(send),pileCode);
 //                String key = redisCache.getCacheObject(RedisConstant.KEYS+deviceConnectionMsg.getDeviceId());
                 String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
@@ -48,7 +51,7 @@ public class RealTimeStatusPushFrame {
             }
         }else{
             try {
-                byte[] send = upStatusDevice(trans, pileCode, guns, gunsStatus, gunsInsert, voltage, power, elec, money, time);
+                byte[] send = upStatusDevice(deviceConnectionMsg,trans, pileCode, guns, gunsStatus, gunsInsert, voltage, power, elec, money, time);
                 log.info("deviceStatusPush>reporting-save>>>"+DataConversion.bytesToHexString(send));
                 // log.info("deviceStatusPush>设备实时状态key>>>"+key);
                 encrypt = send;
@@ -88,7 +91,39 @@ public class RealTimeStatusPushFrame {
 
     }
 
-    private byte[] upStatusDevice(byte[] trans, String pileCode, byte guns, byte gunsStatus, byte gunsInsert, double voltage, double power, BigDecimal elec, BigDecimal money, int time) throws Exception {
+    private byte[] upStatusDevice(DeviceConnectionMsg deviceConnectionMsg,byte[] trans, String pileCode, byte guns, byte gunsStatus, byte gunsInsert, double voltage, double power, BigDecimal elec, BigDecimal money, int time) throws Exception {
+
+        //剩余
+        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;
+
+        if(deviceConnectionMsg.getIsDc()){
+            try{
+                //重置电压 直流电压放大10倍
+                voltage = voltage/10;
+                if(gunsStatus== StatusConstant.CHARGING){
+                    JSONArray dataArray = redisCache.getCacheMapValue("device_last_163",deviceConnectionMsg.getImei()+"_"+guns);
+                    if(dataArray != null){
+                        //获取soc和剩余时间
+                        //重置soc
+                        soc[0] = dataArray.getByte(21+3);
+                        remain_time[0] = dataArray.getByte(22+3);
+                        remain_time[1] = dataArray.getByte(23+3);
+                        log.info("充电中-soc:{},remain:{}",soc,remain_time);
+                    }
+                }
+
+            }catch (Exception e){
+
+            }
+        }
 
         byte[] msg = new byte[60];
 //1.交易流水号,,空闲自己生成上报状态,充电拿到交易流水
@@ -138,11 +173,11 @@ public class RealTimeStatusPushFrame {
         System.arraycopy(out_A, 0, msg, index, out_A.length);
         index += out_A.length;
 
-        byte[] guns_line_temp = new byte[1];
-        //9.枪线温度
-        guns_line_temp[0] = 0x32;
+
         System.arraycopy(guns_line_temp, 0, msg, index, guns_line_temp.length);
         index += guns_line_temp.length;
+
+
 //10.枪线编码
         byte[] guns_line_num = new byte[8];
         guns_line_num[0] = 0x00;
@@ -155,22 +190,29 @@ public class RealTimeStatusPushFrame {
         guns_line_num[7] = 0x00;
         System.arraycopy(guns_line_num, 0, msg, index, guns_line_num.length);
         index += guns_line_num.length;
+
+
+
+
         //11.SOC
-        byte[] soc = new byte[]{0x00};
+
         System.arraycopy(soc, 0, msg, index, soc.length);
         index += soc.length;
 //12.电池组最高温度
-        byte[] battery_temp = {0x32};
+
         System.arraycopy(battery_temp, 0, msg, index, battery_temp.length);
         index += battery_temp.length;
+
 //13. 累计充电时间 BIN 码 2 单位:min;待机置零
         byte[] charnging_Time = new byte[2];
         charnging_Time[1] = (byte) ((time >> 8) & 0xFF);
         charnging_Time[0] = (byte) (time & 0xFF);
         System.arraycopy(charnging_Time, 0, msg, index, charnging_Time.length);
         index += charnging_Time.length;
+
+
         //14. 剩余时间 BIN 码 2 单位:min;待机置零、交流桩置零
-        byte[] remain_time = {0x00, 0x00};
+
         System.arraycopy(remain_time, 0, msg, index, remain_time.length);
         index += remain_time.length;
 

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

@@ -317,7 +317,7 @@ public class DeviceMsgHandle {
             logger.info("{}已禁用{}", imei, pileCode);
             return false;
         }
-        boolean res = socketHandle.addDeviceConnection(device.getIp(), device.getPort(), device.getPileCode(), device.getDeviceImei(), device.getDeviceSn(), device.getCommProtocolVer());
+        boolean res = socketHandle.addDeviceConnection(device.getIp(), device.getPort(), device.getPileCode(), device.getDeviceImei(), device.getDeviceSn(), device.getCommProtocolVer(),device.getPileType());
 
         try{
             Thread.sleep(500);
@@ -360,6 +360,12 @@ public class DeviceMsgHandle {
             return;
         }
 
+        if (!NormalChargeConstant.KEY_PORT_DETAIL_EXTEND.equals(cmd)) {
+            //163 解析
+            handle163(jsonObject,imei,pileCode);
+            return;
+        }
+
         //端口状态
         if (NormalChargeConstant.KEY_PORT_DETAIL.equals(type)) {
             handle103(jsonObject, imei, type);
@@ -548,6 +554,22 @@ public class DeviceMsgHandle {
 
     }
 
+    //单个端口状态
+    private void handle163(JSONObject jsonObject, String imei, String pileCode) {
+        try {
+            //状态查询101
+            JSONArray dataArray = jsonObject.getJSONArray("data");
+            //设置订单已停止充电和结束时间
+            Integer port = (Integer) dataArray.get(3);
+            redisCache.setCacheMapValue("device_last_163",imei+"_"+port,dataArray);
+
+
+        } catch (Exception e) {
+            logger.info("处理163失败{}", imei);
+        }
+
+    }
+
     private void handle103(JSONObject jsonObject, String imei, int type) throws Exception {
         //103状态是带电压功率等信息的,所以需要对该信息进行处理操作
         JSONObject data = jsonObject.getJSONObject("real_data");

+ 6 - 1
src/main/java/com/tmzn/devicelinkykc/socket/DeviceConnectionMsg.java

@@ -22,11 +22,12 @@ public class DeviceConnectionMsg {
     private BufferedInputStream inputStream;
     private Integer loginStatus;
     private boolean is18;
+    private boolean isDc;
     private String ver;
     private long loginTime;
     private boolean loginMsgSend;
 
-    public DeviceConnectionMsg(Socket socket, String deviceId,String imei,String deviceSn,String ver) {
+    public DeviceConnectionMsg(Socket socket, String deviceId,String imei,String deviceSn,String ver,int isDc) {
         this.heartTime= 0L;
         this.deviceId = deviceId;
         this.socket = socket;
@@ -36,6 +37,7 @@ public class DeviceConnectionMsg {
         this.deviceSn=deviceSn;
         this.ver = ver;
         this.is18 = true;
+        this.isDc = isDc == 1;
         if(!ver.startsWith("1.8")){
             this.is18=false;
         }
@@ -98,6 +100,9 @@ public class DeviceConnectionMsg {
     public boolean getIs18() {
         return is18;
     }
+    public boolean getIsDc() {
+        return isDc;
+    }
 
     public Long getHeartTime() {
         return heartTime;

+ 2 - 2
src/main/java/com/tmzn/devicelinkykc/socket/SocketHandle.java

@@ -32,7 +32,7 @@ public class SocketHandle {
     @Autowired
     private YkcMsgHandle ykcMsgHandle;
 
-    public synchronized boolean addDeviceConnection(String ip, int port, String deviceId, String imei, String deviceSn, String ver) throws IOException {
+    public synchronized boolean addDeviceConnection(String ip, int port, String deviceId, String imei, String deviceSn, String ver,int isDc) throws IOException {
         if (deviceConnectionMsgMap.containsKey(deviceId)) {
             log.info("已存在登录{}",imei);
             return  true;
@@ -46,7 +46,7 @@ public class SocketHandle {
             Socket socket = new Socket();
             socket.connect(new InetSocketAddress(ip, port), 5000);
             socket.setKeepAlive(true);
-            DeviceConnectionMsg deviceConnectionMsg = new DeviceConnectionMsg(socket, deviceId,imei,deviceSn,ver);
+            DeviceConnectionMsg deviceConnectionMsg = new DeviceConnectionMsg(socket, deviceId,imei,deviceSn,ver,isDc);
             //每个设备连接后开启监听接收消息
             ykcMsgHandle.startListening(deviceConnectionMsg);
             //并将连接信息等保存再Map中

+ 1 - 1
src/main/java/com/tmzn/devicelinkykc/taskQueue/runner/DeviceOnlineRunner.java

@@ -131,7 +131,7 @@ public class DeviceOnlineRunner {
                         return ;
                     }
                     logger.info("桩检测需要自动上线{}",device.getPileCode());
-                    socketHandle.addDeviceConnection(device.getIp(),device.getPort(),device.getPileCode(), device.getDeviceImei(), device.getDeviceSn(),device.getCommProtocolVer());
+                    socketHandle.addDeviceConnection(device.getIp(),device.getPort(),device.getPileCode(), device.getDeviceImei(), device.getDeviceSn(),device.getCommProtocolVer(),device.getPileType());
                     try{
                         Thread.sleep(300);
                         loginFrame.loginMsgSend(socketHandle.getDeviceConnection(device.getPileCode()), device);

+ 3 - 0
src/main/java/com/tmzn/devicelinkykc/transdata/constant/NormalChargeConstant.java

@@ -100,6 +100,9 @@ public class NormalChargeConstant{
     //端口详情
     public static final Integer KEY_PORT_DETAIL = 103;
 
+    //端口详情
+    public static final Integer KEY_PORT_DETAIL_EXTEND = 163;
+
     //主动上报详情
     public static final Integer KEY_PORT_REPORT = 115;