Bläddra i källkod

[功能修复]远程重启和参数设置

liuf 9 månader sedan
förälder
incheckning
63ab14247f

+ 1 - 0
src/main/java/com/tmzn/devicelinkykc/entity/Device.java

@@ -55,6 +55,7 @@ public class Device implements Serializable {
     private byte disabled;
     private long createTime;
     private long updateTime;
+    private Integer pileStatus;
     public void setCreateTime(long createTime) {
         this.createTime = createTime;
     }

+ 91 - 1
src/main/java/com/tmzn/devicelinkykc/frameMsg/frameType/OtherFrame.java

@@ -1,10 +1,15 @@
 package com.tmzn.devicelinkykc.frameMsg.frameType;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.tmzn.devicelinkykc.constant.DeviceOnlineStatus;
 import com.tmzn.devicelinkykc.constant.RedisConstant;
+import com.tmzn.devicelinkykc.entity.Device;
 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.DeviceControlerService;
+import com.tmzn.devicelinkykc.service.DeviceService;
 import com.tmzn.devicelinkykc.socket.DeviceConnectionMsg;
 import com.tmzn.devicelinkykc.util.CP56Time2a;
 import com.tmzn.devicelinkykc.util.Encrytion;
@@ -14,6 +19,7 @@ import org.springframework.stereotype.Component;
 
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.Date;
 
 /**
@@ -28,9 +34,31 @@ public class OtherFrame {
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    DeviceControlerService deviceControlerService;
+
+    @Autowired
+    DeviceService deviceService;
+
+
     //工作参数设置
-    public void configSettingSend(DeviceConnectionMsg deviceConnectionMsg,byte[] fromMsgSeq) {
+    public void configSettingSend(DeviceConnectionMsg deviceConnectionMsg, byte[] responeMsg, byte[] fromMsgSeq) {
         log.info("{}工作参数应答",deviceConnectionMsg.getDeviceId());
+
+
+        int pileStatus = responeMsg[7] & 0xFF; //0正常 1禁用
+        int socPercent = responeMsg[8] & 0xff; //桩输出功率百分比 1-100% 最小30% 暂时不设置
+
+        QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
+        deviceQueryWrapper.eq("pile_code", deviceConnectionMsg.getDeviceId());
+        Device device = deviceService.getOne(deviceQueryWrapper);
+
+        if(device!=null && device.getPileStatus()!=pileStatus){
+            device.setPileStatus(pileStatus);
+            deviceService.updateById(device);
+            log.info("设置桩工作状态禁用");
+        }
+
         byte[] params = confirmParams(deviceConnectionMsg.getDeviceId(),1);
         if(deviceConnectionMsg.getIs18()){
             String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
@@ -56,6 +84,68 @@ public class OtherFrame {
         deviceConnectionMsg.incrementMessageCount();
     }
 
+
+
+
+    //远程重启
+    public void remoteRebootSend(DeviceConnectionMsg deviceConnectionMsg,byte[] fromMsgSeq) {
+        log.info("{}远程重启应答",deviceConnectionMsg.getDeviceId());
+
+        deviceControlerService.restart(deviceConnectionMsg.getImei(),deviceConnectionMsg.getImei());
+
+        byte[] params = confirmParams(deviceConnectionMsg.getDeviceId(),1);
+        if(deviceConnectionMsg.getIs18()){
+            String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
+            try {
+                byte[] encrypt = Encrytion.aesEncrypt(params, key.getBytes());
+                byte[] spliceing = FrameDataSplicing.spliceing(fromMsgSeq, DeviceSendYkc.REMOTE_REBOOT_RESPONSE.getFrameType(), DeviceSendYkc.REMOTE_REBOOT_RESPONSE.getEncryptFlag(), encrypt, encrypt.length, deviceConnectionMsg.getIs18());
+                deviceConnectionMsg.getOutputStream().write(spliceing);
+                deviceConnectionMsg.getOutputStream().flush();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            deviceConnectionMsg.incrementMessageCount();
+            return;
+        }
+
+        try {
+            byte[] spliceing = FrameDataSplicing.spliceing(fromMsgSeq, DeviceSendYkc.REMOTE_REBOOT_RESPONSE.getFrameType(), 0, params, params.length, deviceConnectionMsg.getIs18());
+            deviceConnectionMsg.getOutputStream().write(spliceing);
+            deviceConnectionMsg.getOutputStream().flush();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        deviceConnectionMsg.incrementMessageCount();
+    }
+
+    //远程更新
+    public void remoteUpdateSend(DeviceConnectionMsg deviceConnectionMsg,byte[] fromMsgSeq) {
+        log.info("{}远程更数应答",deviceConnectionMsg.getDeviceId());
+        byte[] params = confirmParams(deviceConnectionMsg.getDeviceId(),1);
+        if(deviceConnectionMsg.getIs18()){
+            String key = redisCache.getCacheMapValue(RedisConstant.YKC_KEY_MAP,deviceConnectionMsg.getDeviceId());
+            try {
+                byte[] encrypt = Encrytion.aesEncrypt(params, key.getBytes());
+                byte[] spliceing = FrameDataSplicing.spliceing(fromMsgSeq, DeviceSendYkc.REMOVE_UPDATE_RESPONSE.getFrameType(), DeviceSendYkc.REMOVE_UPDATE_RESPONSE.getEncryptFlag(), encrypt, encrypt.length, deviceConnectionMsg.getIs18());
+                deviceConnectionMsg.getOutputStream().write(spliceing);
+                deviceConnectionMsg.getOutputStream().flush();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            deviceConnectionMsg.incrementMessageCount();
+            return;
+        }
+
+        try {
+            byte[] spliceing = FrameDataSplicing.spliceing(fromMsgSeq, DeviceSendYkc.REMOVE_UPDATE_RESPONSE.getFrameType(), 0, params, params.length, deviceConnectionMsg.getIs18());
+            deviceConnectionMsg.getOutputStream().write(spliceing);
+            deviceConnectionMsg.getOutputStream().flush();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        deviceConnectionMsg.incrementMessageCount();
+    }
+
     private byte[] confirmParams(String pileCode,int result){
 
         byte[] msg = new byte[10];

+ 20 - 5
src/main/java/com/tmzn/devicelinkykc/message/YkcMsgHandle.java

@@ -10,10 +10,7 @@ import com.tmzn.devicelinkykc.constant.RedisConstant;
 import com.tmzn.devicelinkykc.constant.ykc.BillingModelConst;
 import com.tmzn.devicelinkykc.constant.ykc.StatusConstant;
 import com.tmzn.devicelinkykc.constant.ykc.TransConstant;
-import com.tmzn.devicelinkykc.entity.BillingModel;
-import com.tmzn.devicelinkykc.entity.DeviceStatus;
-import com.tmzn.devicelinkykc.entity.OrderStatus;
-import com.tmzn.devicelinkykc.entity.TransOrder;
+import com.tmzn.devicelinkykc.entity.*;
 import com.tmzn.devicelinkykc.frameMsg.DataConversion;
 import com.tmzn.devicelinkykc.frameMsg.TransMoney;
 import com.tmzn.devicelinkykc.frameMsg.frameType.*;
@@ -89,6 +86,9 @@ public class YkcMsgHandle {
     @Autowired
     private TransMapping transMapping;
 
+    @Autowired
+    private DeviceService deviceService;
+
     public void startListening(DeviceConnectionMsg deviceConnectionMsg) {
 
         Runnable listener = () -> {
@@ -241,7 +241,7 @@ public class YkcMsgHandle {
 
                 } else if(framType == YkcSendDevice.CONFIG_SETTING.getFrameType()){
                     logger.info("↓↓↓↓↓{}工作参数设置",deviceConnectionMsg.getDeviceId());
-                    otherFrame.configSettingSend(deviceConnectionMsg,fromMsgSeq);
+                    otherFrame.configSettingSend(deviceConnectionMsg,respone_msg,fromMsgSeq);
 
 
 
@@ -258,9 +258,12 @@ public class YkcMsgHandle {
 
                 } else if (framType == YkcSendDevice.REMOTE_REBOOT.getFrameType()) {
                     logger.info("↓↓↓↓↓{}远程重启",deviceConnectionMsg.getDeviceId());
+                    otherFrame.remoteRebootSend(deviceConnectionMsg,fromMsgSeq);
+
 
                 } else if (framType == YkcSendDevice.UPLOAD_FILE_UPDATE.getFrameType()) {
                     logger.info("↓↓↓↓↓{}远程更新",deviceConnectionMsg.getDeviceId());
+                    otherFrame.remoteUpdateSend(deviceConnectionMsg,fromMsgSeq);
 
                 }
             }
@@ -357,6 +360,18 @@ public class YkcMsgHandle {
                 }
             }
 
+            //检查桩是否禁用
+            if(!temp){
+                QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>();
+                deviceQueryWrapper.eq("pile_code", deviceConnectionMsg.getDeviceId());
+                Device device = deviceService.getOne(deviceQueryWrapper);
+                if(device!=null && device.getPileStatus()==1){
+                    temp = true;
+                    reason=0x03;
+                    logger.info("枪禁用{}",device.getPileCode());
+                }
+            }
+
             if (temp) {
                 logger.info("启动失败{}:reason:{}" ,deviceConnectionMsg.getDeviceId(), reason);
                 charngingPushFrame.startStatus(deviceConnectionMsg, transOrder, guns[0], result, reason);

+ 3 - 2
src/main/java/com/tmzn/devicelinkykc/msgEnum/DeviceSendYkc.java

@@ -21,12 +21,13 @@ public enum DeviceSendYkc {
     UPDATE_BALANCE_RESPONSE(0x41,0x01,"远程更新余额应答"),
     CHECKTIME_RESPONSE(0x55,0x00,"对时应答"),
     BILLING_MODEL_SETTING_RESPONSE(0x57,0x01," 计费模型设置应答"),
-    REMOTE_REBOOT_RESPONSE(0x93,0x01,"远程重启应答"),
-    UPLOAD_FILE_UPDATE_RESPONSE(0x93,0x01,"远程更新应答"),
+    REMOTE_REBOOT_RESPONSE(0x91,0x01,"远程重启应答"),
 
 
     CONFIG_SETTING_RESPONSE(0x51,0x01,"工作参数设置应答"),
 
+    REMOVE_UPDATE_RESPONSE(0x93,0x01,"工作参数设置应答"),
+
 
     START_CHARNGING_RESPONSE_16(0x33,0x00,"运营平台远程控制启机回复"),