优化代码
This commit is contained in:
parent
7597ddfe2e
commit
2d4a76f9ce
@ -64,7 +64,9 @@ public class IIEC104Service {
|
||||
queryWrapper.eq(GatewayDevice::getIpAddr, meterDevice.getNetdeviceIp());
|
||||
//查找网关机
|
||||
GatewayDevice gatewayDevice = gatewayDeviceService.getOne(queryWrapper);
|
||||
if (ObjUtil.isNotEmpty(gatewayDevice)) {
|
||||
if (ObjUtil.isEmpty(gatewayDevice)) {
|
||||
return false;
|
||||
}
|
||||
int iecaddr = gatewayDevice.getIecAddr();
|
||||
String address = "";
|
||||
if ("yk".equals(type)) {
|
||||
@ -74,20 +76,22 @@ public class IIEC104Service {
|
||||
}
|
||||
MessageDetail comand = getYk_YtCommand(iecaddr, deviceSignal.getYkytType(), address, value);
|
||||
//以上都是自加的
|
||||
if (BootNettyClientChannelCache.channelMapCache.size() > 0) {
|
||||
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()) {
|
||||
if (bootNettyChannel.getCode().equals(meterDevice.getNetdeviceIp())) {//对应的终端
|
||||
if (bootNettyChannel == null || !bootNettyChannel.getChannel().isOpen()) {
|
||||
//对应的终端
|
||||
continue;
|
||||
}
|
||||
if (bootNettyChannel.getCode().equals(meterDevice.getNetdeviceIp())) {
|
||||
bootNettyChannel.getChannel().writeAndFlush(comand);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user