浏览代码

急停上报故障

liuf 8 月之前
父节点
当前提交
1356216ec2

+ 306 - 300
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/RealTimeStatusPushFrame.java

@@ -1,301 +1,307 @@
-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;
-import com.tmzn.devicelinkykc.redis.RedisCache;
-import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
-import com.tmzn.devicelinkykc.util.Encrytion;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * @author xp
- * @date 2024/3/16
- * @explain " 加密 "
- */
-@Component
-@Slf4j(topic = "RealTimeStatusPushFrame")
-public class RealTimeStatusPushFrame {
-    @Autowired
-    private RedisCache redisCache;
-
-
-    public void deviceStatusPush(byte[] responeMsg,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(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());
-                // log.info("deviceStatusPush>设备实时状态key>>>"+key);
-                encrypt = Encrytion.aesEncrypt(send, key.getBytes());
-//                log.info("deviceStatusPush>设备实时状态encrypt msg::>>>"+DataConversion.bytesToHexString(encrypt));
-            } catch (Exception e) {
-                log.info("pileCode:" + pileCode + " deviceStatusPush params Exception");
-                e.printStackTrace();
-            }
-        }else{
-            try {
-                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;
-                encFlag = 0;
-            } catch (Exception e) {
-                log.info("pileCode:" + pileCode + " deviceStatusPush params Exception");
-                e.printStackTrace();
-            }
-        }
-
-        if (encrypt.length > 0) {
-            byte[] bytes = FrameDataSplicing.spliceing(responeMsg, DeviceSendYkc.UPLOAD_DEVICE_STATUS_RESPONSE.getFrameType() ,encFlag, encrypt, encrypt.length, deviceConnectionMsg.getIs18());
-            try {
-                deviceConnectionMsg.getOutputStream().write(bytes,0,bytes.length);
-                deviceConnectionMsg.getOutputStream().flush();
-            } catch (IOException e) {
-                log.info("pileCode:" + pileCode + " ,realTimeStatus push frame Exception");
-
-                //调用重启
-                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());
-                }
-
-                e.printStackTrace();
-            }
-            deviceConnectionMsg.incrementMessageCount();
-        } else {
-            log.info("pileCode:" + pileCode + " deviceStatusPush params null");
-        }
-
-    }
-
-    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(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());
-                // log.info("deviceStatusPush>设备实时状态key>>>"+key);
-                encrypt = Encrytion.aesEncrypt(send, key.getBytes());
-//                log.info("deviceStatusPush>设备实时状态encrypt msg::>>>"+DataConversion.bytesToHexString(encrypt));
-            } catch (Exception e) {
-                log.info("pileCode:" + pileCode + " deviceStatusPush params Exception");
-                e.printStackTrace();
-            }
-        }else{
-            try {
-                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;
-                encFlag = 0;
-            } catch (Exception e) {
-                log.info("pileCode:" + pileCode + " deviceStatusPush params Exception");
-                e.printStackTrace();
-            }
-        }
-
-        if (encrypt.length > 0) {
-            byte[] bytes = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.UPLOAD_DEVICE_STATUS_RESPONSE.getFrameType() ,encFlag, encrypt, encrypt.length, deviceConnectionMsg.getIs18());
-            try {
-                deviceConnectionMsg.getOutputStream().write(bytes,0,bytes.length);
-                deviceConnectionMsg.getOutputStream().flush();
-            } catch (IOException e) {
-                log.info("pileCode:" + pileCode + " ,realTimeStatus push frame Exception");
-
-                //调用重启
-                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());
-                }
-
-                e.printStackTrace();
-            }
-            deviceConnectionMsg.incrementMessageCount();
-        } else {
-            log.info("pileCode:" + pileCode + " deviceStatusPush params null");
-        }
-
-    }
-
-    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.交易流水号,,空闲自己生成上报状态,充电拿到交易流水
-        int index = 0;
-        byte[] transaction = new byte[16];
-        System.arraycopy(trans, 0, msg, index, transaction.length);
-        index += transaction.length;
-        //2.桩编码
-        byte[] pileCodebytes = new byte[7];
-        pileCodebytes = DataConversion.bcdToBytes(pileCode, pileCodebytes.length);
-        System.arraycopy(pileCodebytes, 0, msg, index, pileCodebytes.length);
-        index += pileCodebytes.length;
-//3.枪号
-        byte[] gunsBytes = new byte[1];
-        gunsBytes = new byte[]{guns};
-
-        System.arraycopy(gunsBytes, 0, msg, index, gunsBytes.length);
-        index += gunsBytes.length;
-//4.状态
-        byte[] guns_status = {gunsStatus};
-        System.arraycopy(guns_status, 0, msg, index, guns_status.length);
-        index += guns_status.length;
-//5.枪是否归位,默认归位
-        byte[] guns_return = {0x01};
-        System.arraycopy(guns_return, 0, msg, index, guns_return.length);
-        index += guns_return.length;
-//6.是否插枪
-        byte[] guns_insert = {gunsInsert};
-        System.arraycopy(guns_insert, 0, msg, index, guns_insert.length);
-        index += guns_insert.length;
-//7.输出电压
-        byte[] out_V = new byte[2];
-
-        out_V = DataConversion.bin2ToOne(new BigDecimal(voltage));
-        System.arraycopy(out_V, 0, msg, index, out_V.length);
-        index += out_V.length;
-
-        if (guns == 10) {
-            power = 9000;
-        }
-        byte[] out_A = new byte[2];           //8.输出电流
-        if (voltage == 0) {
-            out_A = new byte[]{0x00, 0x00};
-        } else {
-            out_A = DataConversion.bin2ToOne(new BigDecimal(power).divide(new BigDecimal(voltage),1,BigDecimal.ROUND_DOWN));
-        }
-        System.arraycopy(out_A, 0, msg, index, out_A.length);
-        index += out_A.length;
-
-
-        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;
-        guns_line_num[1] = 0x00;
-        guns_line_num[2] = 0x00;
-        guns_line_num[3] = 0x00;
-        guns_line_num[4] = 0x00;
-        guns_line_num[5] = 0x00;
-        guns_line_num[6] = 0x00;
-        guns_line_num[7] = 0x00;
-        System.arraycopy(guns_line_num, 0, msg, index, guns_line_num.length);
-        index += guns_line_num.length;
-
-
-
-
-        //11.SOC
-
-        System.arraycopy(soc, 0, msg, index, soc.length);
-        index += soc.length;
-//12.电池组最高温度
-
-        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;待机置零、交流桩置零
-
-        System.arraycopy(remain_time, 0, msg, index, remain_time.length);
-        index += remain_time.length;
-
-        //15 充电度数
-        byte[] charnging_kwh = new byte[4];
-        charnging_kwh = DataConversion.bin4Tofour(elec);
-        System.arraycopy(charnging_kwh, 0, msg, index, charnging_kwh.length);
-        index += charnging_kwh.length;
-        //16. 计损充电度数 BIN 码 4 精确到小数点后四位;待机置零未设置计损比例时等于充电度数
-        byte[] charnging_loss_kwh = new byte[4];
-        charnging_loss_kwh = DataConversion.bin4Tofour(new BigDecimal("0"));
-        System.arraycopy(charnging_loss_kwh, 0, msg, index, charnging_loss_kwh.length);
-        index += charnging_loss_kwh.length;
-//17. 已充金额 BIN 码 4 精确到小数点后四位;待机置零(电费+服务费)*计损充电度数
-        byte[] charnging_rmb = new byte[4];
-        charnging_rmb = DataConversion.bin4Tofour(money);
-        System.arraycopy(charnging_rmb, 0, msg, index, charnging_rmb.length);
-        index += charnging_rmb.length;
-
-        byte[] charnging_damage = {0x00, 0x00};//18. 硬件故障
-        System.arraycopy(charnging_damage, 0, msg, index, charnging_damage.length);
-        index += charnging_damage.length;
-        return msg;
-    }
+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;
+import com.tmzn.devicelinkykc.redis.RedisCache;
+import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
+import com.tmzn.devicelinkykc.util.Encrytion;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @author xp
+ * @date 2024/3/16
+ * @explain " 加密 "
+ */
+@Component
+@Slf4j(topic = "RealTimeStatusPushFrame")
+public class RealTimeStatusPushFrame {
+    @Autowired
+    private RedisCache redisCache;
+
+
+    public void deviceStatusPush(byte[] responeMsg,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(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());
+                // log.info("deviceStatusPush>设备实时状态key>>>"+key);
+                encrypt = Encrytion.aesEncrypt(send, key.getBytes());
+//                log.info("deviceStatusPush>设备实时状态encrypt msg::>>>"+DataConversion.bytesToHexString(encrypt));
+            } catch (Exception e) {
+                log.info("pileCode:" + pileCode + " deviceStatusPush params Exception");
+                e.printStackTrace();
+            }
+        }else{
+            try {
+                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;
+                encFlag = 0;
+            } catch (Exception e) {
+                log.info("pileCode:" + pileCode + " deviceStatusPush params Exception");
+                e.printStackTrace();
+            }
+        }
+
+        if (encrypt.length > 0) {
+            byte[] bytes = FrameDataSplicing.spliceing(responeMsg, DeviceSendYkc.UPLOAD_DEVICE_STATUS_RESPONSE.getFrameType() ,encFlag, encrypt, encrypt.length, deviceConnectionMsg.getIs18());
+            try {
+                deviceConnectionMsg.getOutputStream().write(bytes,0,bytes.length);
+                deviceConnectionMsg.getOutputStream().flush();
+            } catch (IOException e) {
+                log.info("pileCode:" + pileCode + " ,realTimeStatus push frame Exception");
+
+                //调用重启
+                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());
+                }
+
+                e.printStackTrace();
+            }
+            deviceConnectionMsg.incrementMessageCount();
+        } else {
+            log.info("pileCode:" + pileCode + " deviceStatusPush params null");
+        }
+
+    }
+
+    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(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());
+                // log.info("deviceStatusPush>设备实时状态key>>>"+key);
+                encrypt = Encrytion.aesEncrypt(send, key.getBytes());
+//                log.info("deviceStatusPush>设备实时状态encrypt msg::>>>"+DataConversion.bytesToHexString(encrypt));
+            } catch (Exception e) {
+                log.info("pileCode:" + pileCode + " deviceStatusPush params Exception");
+                e.printStackTrace();
+            }
+        }else{
+            try {
+                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;
+                encFlag = 0;
+            } catch (Exception e) {
+                log.info("pileCode:" + pileCode + " deviceStatusPush params Exception");
+                e.printStackTrace();
+            }
+        }
+
+        if (encrypt.length > 0) {
+            byte[] bytes = FrameDataSplicing.spliceing(deviceConnectionMsg.getMessageCount(), DeviceSendYkc.UPLOAD_DEVICE_STATUS_RESPONSE.getFrameType() ,encFlag, encrypt, encrypt.length, deviceConnectionMsg.getIs18());
+            try {
+                deviceConnectionMsg.getOutputStream().write(bytes,0,bytes.length);
+                deviceConnectionMsg.getOutputStream().flush();
+            } catch (IOException e) {
+                log.info("pileCode:" + pileCode + " ,realTimeStatus push frame Exception");
+
+                //调用重启
+                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());
+                }
+
+                e.printStackTrace();
+            }
+            deviceConnectionMsg.incrementMessageCount();
+        } else {
+            log.info("pileCode:" + pileCode + " deviceStatusPush params null");
+        }
+
+    }
+
+    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.交易流水号,,空闲自己生成上报状态,充电拿到交易流水
+        int index = 0;
+        byte[] transaction = new byte[16];
+        System.arraycopy(trans, 0, msg, index, transaction.length);
+        index += transaction.length;
+        //2.桩编码
+        byte[] pileCodebytes = new byte[7];
+        pileCodebytes = DataConversion.bcdToBytes(pileCode, pileCodebytes.length);
+        System.arraycopy(pileCodebytes, 0, msg, index, pileCodebytes.length);
+        index += pileCodebytes.length;
+//3.枪号
+        byte[] gunsBytes = new byte[1];
+        gunsBytes = new byte[]{guns};
+
+        System.arraycopy(gunsBytes, 0, msg, index, gunsBytes.length);
+        index += gunsBytes.length;
+//4.状态
+        byte[] guns_status = {gunsStatus};
+        System.arraycopy(guns_status, 0, msg, index, guns_status.length);
+        index += guns_status.length;
+//5.枪是否归位,默认归位
+        byte[] guns_return = {0x01};
+        System.arraycopy(guns_return, 0, msg, index, guns_return.length);
+        index += guns_return.length;
+//6.是否插枪
+        byte[] guns_insert = {gunsInsert};
+        System.arraycopy(guns_insert, 0, msg, index, guns_insert.length);
+        index += guns_insert.length;
+//7.输出电压
+        byte[] out_V = new byte[2];
+
+        out_V = DataConversion.bin2ToOne(new BigDecimal(voltage));
+        System.arraycopy(out_V, 0, msg, index, out_V.length);
+        index += out_V.length;
+
+        if (guns == 10) {
+            power = 9000;
+        }
+        byte[] out_A = new byte[2];           //8.输出电流
+        if (voltage == 0) {
+            out_A = new byte[]{0x00, 0x00};
+        } else {
+            out_A = DataConversion.bin2ToOne(new BigDecimal(power).divide(new BigDecimal(voltage),1,BigDecimal.ROUND_DOWN));
+        }
+        System.arraycopy(out_A, 0, msg, index, out_A.length);
+        index += out_A.length;
+
+
+        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;
+        guns_line_num[1] = 0x00;
+        guns_line_num[2] = 0x00;
+        guns_line_num[3] = 0x00;
+        guns_line_num[4] = 0x00;
+        guns_line_num[5] = 0x00;
+        guns_line_num[6] = 0x00;
+        guns_line_num[7] = 0x00;
+        System.arraycopy(guns_line_num, 0, msg, index, guns_line_num.length);
+        index += guns_line_num.length;
+
+
+
+
+        //11.SOC
+
+        System.arraycopy(soc, 0, msg, index, soc.length);
+        index += soc.length;
+//12.电池组最高温度
+
+        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;待机置零、交流桩置零
+
+        System.arraycopy(remain_time, 0, msg, index, remain_time.length);
+        index += remain_time.length;
+
+        //15 充电度数
+        byte[] charnging_kwh = new byte[4];
+        charnging_kwh = DataConversion.bin4Tofour(elec);
+        System.arraycopy(charnging_kwh, 0, msg, index, charnging_kwh.length);
+        index += charnging_kwh.length;
+        //16. 计损充电度数 BIN 码 4 精确到小数点后四位;待机置零未设置计损比例时等于充电度数
+        byte[] charnging_loss_kwh = new byte[4];
+        charnging_loss_kwh = DataConversion.bin4Tofour(new BigDecimal("0"));
+        System.arraycopy(charnging_loss_kwh, 0, msg, index, charnging_loss_kwh.length);
+        index += charnging_loss_kwh.length;
+//17. 已充金额 BIN 码 4 精确到小数点后四位;待机置零(电费+服务费)*计损充电度数
+        byte[] charnging_rmb = new byte[4];
+        charnging_rmb = DataConversion.bin4Tofour(money);
+        System.arraycopy(charnging_rmb, 0, msg, index, charnging_rmb.length);
+        index += charnging_rmb.length;
+
+        byte[] charnging_damage = {0x00, 0x00};//18. 硬件故障
+
+        //如果是急停
+        if(gunsStatus==StatusConstant.FAULT){
+            charnging_damage = new byte[]{0x01, 0x00};
+        }
+
+        System.arraycopy(charnging_damage, 0, msg, index, charnging_damage.length);
+        index += charnging_damage.length;
+        return msg;
+    }
 }

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

@@ -787,7 +787,7 @@ public class DeviceMsgHandle {
 
         if (portStatus.equals(PortStatusConstant.EMERGENCY_STOP)) {
             //急停中按要求需要上报空闲状态;急停保存原始状态
-            deviceOnline(portStatus, imei, port, (byte) PortStatusConstant.EMERGENCY_STOP, StatusConstant.INSERT_GUNS_NO);
+            deviceOnline(portStatus, imei, port, (byte) StatusConstant.FAULT, StatusConstant.INSERT_GUNS_NO);
         }
     }