mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 电单车协议
This commit is contained in:
@@ -36,23 +36,29 @@ public class ChargingPileDecoder extends ByteToMessageDecoder {
|
||||
|
||||
// 读取物理ID
|
||||
int physicalId = in.readInt();
|
||||
log.info("physicalId:{}", physicalId);
|
||||
|
||||
// 读取消息ID
|
||||
short messageId = in.readShort();
|
||||
log.info("messageId:{}", messageId);
|
||||
|
||||
// 读取命令
|
||||
byte command = in.readByte();
|
||||
log.info("command:{}", command);
|
||||
|
||||
// 读取数据
|
||||
int dataLength = length - 13; // 13 = 包头(3) + 长度(2) + 物理ID(4) + 消息ID(2) + 命令(1) + 校验(2)
|
||||
byte[] data = new byte[dataLength];
|
||||
in.readBytes(data);
|
||||
log.info("data:{}", data);
|
||||
|
||||
// 读取校验和
|
||||
short checksum = in.readShort();
|
||||
log.info("checksum:{}", checksum);
|
||||
|
||||
// 验证校验和
|
||||
short calculatedChecksum = calculateChecksum(in, length);
|
||||
log.info("calculatedChecksum:{}", calculatedChecksum);
|
||||
if (checksum != calculatedChecksum) {
|
||||
log.info("校验和错误,丢弃此帧");
|
||||
continue;
|
||||
@@ -60,11 +66,12 @@ public class ChargingPileDecoder extends ByteToMessageDecoder {
|
||||
|
||||
// 创建消息对象并添加到输出列表
|
||||
ChargingPileMessage message = new ChargingPileMessage(physicalId, messageId, command, data);
|
||||
log.info("ChargingPileMessage:{}", message.toString());
|
||||
out.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidHeader(byte[] header) {
|
||||
private boolean isValidHeader(byte[] header) {
|
||||
log.info("isValidHeader header:{}", header);
|
||||
return header[0] == FRAME_HEADER[0] && header[1] == FRAME_HEADER[1] && header[2] == FRAME_HEADER[2];
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ public class ElectricBicyclesServerChannelInitializer extends ChannelInitializer
|
||||
@Override
|
||||
protected void initChannel(SocketChannel channel) throws Exception {
|
||||
ChannelPipeline pipeline = channel.pipeline();
|
||||
// pipeline.addLast("frameDecoder",new CustomDecoder());
|
||||
pipeline.addLast("frameDecoder", new StartAndLengthFieldFrameDecoder());
|
||||
pipeline.addLast("frameDecoder", new ChargingPileDecoder());
|
||||
pipeline.addLast("decoder", new ByteArrayDecoder());
|
||||
pipeline.addLast("encoder", new ByteArrayDecoder());
|
||||
//读超时时间设置为10s,0表示不监控
|
||||
|
||||
Reference in New Issue
Block a user