diff --git a/riis-system/src/main/java/com/yfd/platform/component/iec104/client/IIEC104Service.java b/riis-system/src/main/java/com/yfd/platform/component/iec104/client/IIEC104Service.java index 3581172..b94ad21 100644 --- a/riis-system/src/main/java/com/yfd/platform/component/iec104/client/IIEC104Service.java +++ b/riis-system/src/main/java/com/yfd/platform/component/iec104/client/IIEC104Service.java @@ -64,26 +64,30 @@ public class IIEC104Service { queryWrapper.eq(GatewayDevice::getIpAddr, meterDevice.getNetdeviceIp()); //查找网关机 GatewayDevice gatewayDevice = gatewayDeviceService.getOne(queryWrapper); - if (ObjUtil.isNotEmpty(gatewayDevice)) { - int iecaddr = gatewayDevice.getIecAddr(); - String address = ""; - if ("yk".equals(type)) { - address = deviceSignal.getYkAddr(); - } else if ("yt".equals(type)) { - address = deviceSignal.getYtAddr(); + if (ObjUtil.isEmpty(gatewayDevice)) { + return false; + } + int iecaddr = gatewayDevice.getIecAddr(); + String address = ""; + if ("yk".equals(type)) { + address = deviceSignal.getYkAddr(); + } else if ("yt".equals(type)) { + address = deviceSignal.getYtAddr(); + } + MessageDetail comand = getYk_YtCommand(iecaddr, deviceSignal.getYkytType(), address, value); + //以上都是自加的 + if (BootNettyClientChannelCache.channelMapCache.size() <= 0) { + return false; + } + for (Map.Entry entry : + BootNettyClientChannelCache.channelMapCache.entrySet()) { + BootNettyClientChannel bootNettyChannel = entry.getValue(); + if (bootNettyChannel == null || !bootNettyChannel.getChannel().isOpen()) { + //对应的终端 + continue; } - MessageDetail comand = getYk_YtCommand(iecaddr, deviceSignal.getYkytType(), address, value); - //以上都是自加的 - if (BootNettyClientChannelCache.channelMapCache.size() > 0) { - for (Map.Entry entry : - BootNettyClientChannelCache.channelMapCache.entrySet()) { - BootNettyClientChannel bootNettyChannel = entry.getValue(); - if (bootNettyChannel != null && bootNettyChannel.getChannel().isOpen()) { - if (bootNettyChannel.getCode().equals(meterDevice.getNetdeviceIp())) {//对应的终端 - bootNettyChannel.getChannel().writeAndFlush(comand); - } - } - } + if (bootNettyChannel.getCode().equals(meterDevice.getNetdeviceIp())) { + bootNettyChannel.getChannel().writeAndFlush(comand); } } } @@ -128,16 +132,20 @@ public class IIEC104Service { typeIdentifierEnum = TypeIdentifierEnum.normalizedTeleadjustment; short value1 = Short.parseShort(value); byte[] byteArray = new byte[2]; - byteArray[0] = (byte) (value1 & 0xFF); // 低位字节 - byteArray[1] = (byte) ((value1 >> 8) & 0xFF); // 高位字节 + // 低位字节 + byteArray[0] = (byte) (value1 & 0xFF); + // 高位字节 + byteArray[1] = (byte) ((value1 >> 8) & 0xFF); message.setMessageInfos(byteArray); } else if ("04".equals(type)) { //遥调 -标度化值 typeIdentifierEnum = TypeIdentifierEnum.scaledTeleadjustment; short value1 = Short.parseShort(value); byte[] byteArray = new byte[2]; - byteArray[0] = (byte) (value1 & 0xFF); // 低位字节 - byteArray[1] = (byte) ((value1 >> 8) & 0xFF); // 高位字节 + // 低位字节 + byteArray[0] = (byte) (value1 & 0xFF); + // 高位字节 + byteArray[1] = (byte) ((value1 >> 8) & 0xFF); message.setMessageInfos(byteArray); } else if ("05".equals(type)) { //遥调 -浮点数值 @@ -145,19 +153,24 @@ public class IIEC104Service { byte[] byteArray = new byte[4]; float value1 = Float.parseFloat(value); int intBits = Float.floatToIntBits(value1); - byteArray[0] = (byte) (intBits & 0xFF); // 第一个字节(最低位) - byteArray[1] = (byte) ((intBits >> 8) & 0xFF); // 第二个字节 - byteArray[2] = (byte) ((intBits >> 16) & 0xFF);// 第三个字节 - byteArray[3] = (byte) ((intBits >> 24) & 0xFF);// 第四个字节(最高位) + // 第一个字节(最低位) + byteArray[0] = (byte) (intBits & 0xFF); + // 第二个字节 + byteArray[1] = (byte) ((intBits >> 8) & 0xFF); + // 第三个字节 + byteArray[2] = (byte) ((intBits >> 16) & 0xFF); + // 第四个字节(最高位) + byteArray[3] = (byte) ((intBits >> 24) & 0xFF); message.setMessageInfos(byteArray); } message.setMessageAddress(messageAddress); messages.add(message); short terminalAddress1 = (short) terminalAddress; //SQ=0 length =1 - int sq = 0; + // int sq = 0; //可变结构限定词 01 - boolean isContinuous = sq == 0 ? false : true; + // boolean isContinuous = sq == 0 ? false : true; + boolean isContinuous = false; // 传输原因 short transferReason = 6; //公共地址 @@ -168,7 +181,7 @@ public class IIEC104Service { MessageDetail ruleDetail104 = new MessageDetail(control, typeIdentifierEnum, isContinuous, isTest, isPN, transferReason, terminalAddress1, messageAddress, messages, null, null); - if (type.equals("03") || type.equals("04") || type.equals("05")) { + if ("03".equals(type) || "04".equals(type) || "05".equals(type)) { QualifiersEnum qualifiers = QualifiersEnum.qualityQualifiers; ruleDetail104 = new MessageDetail(control, typeIdentifierEnum, isContinuous, isTest, isPN, transferReason, terminalAddress1, messageAddress, messages, null, qualifiers); diff --git a/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/controller/IECController.java b/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/controller/IECController.java index 13582bd..1686466 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/controller/IECController.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/auxcontrol/controller/IECController.java @@ -44,7 +44,7 @@ public class IECController { @Resource private IDeviceSignalService deviceSignalService; //变电站辅控设备 服务类 - + @Resource private IGatewayDeviceService gatewayDeviceService;