优化代码

This commit is contained in:
weitang 2025-04-27 14:19:54 +08:00
parent 7597ddfe2e
commit 2d4a76f9ce
2 changed files with 44 additions and 31 deletions

View File

@ -64,26 +64,30 @@ public class IIEC104Service {
queryWrapper.eq(GatewayDevice::getIpAddr, meterDevice.getNetdeviceIp()); queryWrapper.eq(GatewayDevice::getIpAddr, meterDevice.getNetdeviceIp());
//查找网关机 //查找网关机
GatewayDevice gatewayDevice = gatewayDeviceService.getOne(queryWrapper); GatewayDevice gatewayDevice = gatewayDeviceService.getOne(queryWrapper);
if (ObjUtil.isNotEmpty(gatewayDevice)) { if (ObjUtil.isEmpty(gatewayDevice)) {
int iecaddr = gatewayDevice.getIecAddr(); return false;
String address = ""; }
if ("yk".equals(type)) { int iecaddr = gatewayDevice.getIecAddr();
address = deviceSignal.getYkAddr(); String address = "";
} else if ("yt".equals(type)) { if ("yk".equals(type)) {
address = deviceSignal.getYtAddr(); 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<String, BootNettyClientChannel> 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 (bootNettyChannel.getCode().equals(meterDevice.getNetdeviceIp())) {
//以上都是自加的 bootNettyChannel.getChannel().writeAndFlush(comand);
if (BootNettyClientChannelCache.channelMapCache.size() > 0) {
for (Map.Entry<String, BootNettyClientChannel> entry :
BootNettyClientChannelCache.channelMapCache.entrySet()) {
BootNettyClientChannel bootNettyChannel = entry.getValue();
if (bootNettyChannel != null && bootNettyChannel.getChannel().isOpen()) {
if (bootNettyChannel.getCode().equals(meterDevice.getNetdeviceIp())) {//对应的终端
bootNettyChannel.getChannel().writeAndFlush(comand);
}
}
}
} }
} }
} }
@ -128,16 +132,20 @@ public class IIEC104Service {
typeIdentifierEnum = TypeIdentifierEnum.normalizedTeleadjustment; typeIdentifierEnum = TypeIdentifierEnum.normalizedTeleadjustment;
short value1 = Short.parseShort(value); short value1 = Short.parseShort(value);
byte[] byteArray = new byte[2]; 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); message.setMessageInfos(byteArray);
} else if ("04".equals(type)) { } else if ("04".equals(type)) {
//遥调 -标度化值 //遥调 -标度化值
typeIdentifierEnum = TypeIdentifierEnum.scaledTeleadjustment; typeIdentifierEnum = TypeIdentifierEnum.scaledTeleadjustment;
short value1 = Short.parseShort(value); short value1 = Short.parseShort(value);
byte[] byteArray = new byte[2]; 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); message.setMessageInfos(byteArray);
} else if ("05".equals(type)) { } else if ("05".equals(type)) {
//遥调 -浮点数值 //遥调 -浮点数值
@ -145,19 +153,24 @@ public class IIEC104Service {
byte[] byteArray = new byte[4]; byte[] byteArray = new byte[4];
float value1 = Float.parseFloat(value); float value1 = Float.parseFloat(value);
int intBits = Float.floatToIntBits(value1); int intBits = Float.floatToIntBits(value1);
byteArray[0] = (byte) (intBits & 0xFF); // 第一个字节最低位 // 第一个字节最低位
byteArray[1] = (byte) ((intBits >> 8) & 0xFF); // 第二个字节 byteArray[0] = (byte) (intBits & 0xFF);
byteArray[2] = (byte) ((intBits >> 16) & 0xFF);// 第三个字节 // 第二个字节
byteArray[3] = (byte) ((intBits >> 24) & 0xFF);// 第四个字节最高位 byteArray[1] = (byte) ((intBits >> 8) & 0xFF);
// 第三个字节
byteArray[2] = (byte) ((intBits >> 16) & 0xFF);
// 第四个字节最高位
byteArray[3] = (byte) ((intBits >> 24) & 0xFF);
message.setMessageInfos(byteArray); message.setMessageInfos(byteArray);
} }
message.setMessageAddress(messageAddress); message.setMessageAddress(messageAddress);
messages.add(message); messages.add(message);
short terminalAddress1 = (short) terminalAddress; short terminalAddress1 = (short) terminalAddress;
//SQ=0 length =1 //SQ=0 length =1
int sq = 0; // int sq = 0;
//可变结构限定词 01 //可变结构限定词 01
boolean isContinuous = sq == 0 ? false : true; // boolean isContinuous = sq == 0 ? false : true;
boolean isContinuous = false;
// 传输原因 // 传输原因
short transferReason = 6; short transferReason = 6;
//公共地址 //公共地址
@ -168,7 +181,7 @@ public class IIEC104Service {
MessageDetail ruleDetail104 = new MessageDetail(control, typeIdentifierEnum, isContinuous, isTest, isPN, MessageDetail ruleDetail104 = new MessageDetail(control, typeIdentifierEnum, isContinuous, isTest, isPN,
transferReason, transferReason,
terminalAddress1, messageAddress, messages, null, null); 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; QualifiersEnum qualifiers = QualifiersEnum.qualityQualifiers;
ruleDetail104 = new MessageDetail(control, typeIdentifierEnum, isContinuous, isTest, isPN, transferReason, ruleDetail104 = new MessageDetail(control, typeIdentifierEnum, isContinuous, isTest, isPN, transferReason,
terminalAddress1, messageAddress, messages, null, qualifiers); terminalAddress1, messageAddress, messages, null, qualifiers);

View File

@ -44,7 +44,7 @@ public class IECController {
@Resource @Resource
private IDeviceSignalService deviceSignalService; private IDeviceSignalService deviceSignalService;
//变电站辅控设备 服务类 //变电站辅控设备 服务类
@Resource @Resource
private IGatewayDeviceService gatewayDeviceService; private IGatewayDeviceService gatewayDeviceService;