aaaaa
This commit is contained in:
parent
2f7ba359e4
commit
8b0b219fbb
6
pom.xml
6
pom.xml
|
@ -82,7 +82,11 @@
|
||||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- tools -->
|
<!-- tools -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
|
<version>1.60</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.iot.modbus_rtcp.netty;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import com.iot.modbus_rtcp.config.EquipmentIPProperties;
|
import com.iot.modbus_rtcp.config.EquipmentIPProperties;
|
||||||
import com.iot.modbus_rtcp.dto.ModbusCommandDto;
|
import com.iot.modbus_rtcp.dto.ModbusCommandDto;
|
||||||
|
import com.iot.modbus_rtcp.utils.CRCUtil;
|
||||||
import com.iot.modbus_rtcp.utils.HexUtil;
|
import com.iot.modbus_rtcp.utils.HexUtil;
|
||||||
import com.iot.modbus_rtcp.utils.SpringUtil;
|
import com.iot.modbus_rtcp.utils.SpringUtil;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
@ -10,6 +11,7 @@ import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||||
import org.springframework.amqp.core.QueueBuilder;
|
import org.springframework.amqp.core.QueueBuilder;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||||
|
|
||||||
|
@ -88,8 +90,21 @@ public class ModbusDecoder extends ByteToMessageDecoder {
|
||||||
if (bytesCache.length < (message.getLength() / 2)) {
|
if (bytesCache.length < (message.getLength() / 2)) {
|
||||||
DataCache.put(identity, bytesCache);
|
DataCache.put(identity, bytesCache);
|
||||||
} else if (bytesCache.length == (message.getLength() / 2)) {
|
} else if (bytesCache.length == (message.getLength() / 2)) {
|
||||||
|
// if (!verifyCRC(bytesCache)) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
out.add(HexUtil.bytesToHexString(bytesCache));
|
out.add(HexUtil.bytesToHexString(bytesCache));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean verifyCRC(byte[] bytes) {
|
||||||
|
byte[] crc = ByteUtils.subArray(bytes, bytes.length - 2, bytes.length);
|
||||||
|
byte[] data = ByteUtils.subArray(bytes, 0, bytes.length - 2);
|
||||||
|
|
||||||
|
String generate = CRCUtil.getCRC(data);
|
||||||
|
String original = HexUtil.bytesToHexString(crc);
|
||||||
|
|
||||||
|
return original.equalsIgnoreCase(generate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue