mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-08 12:00:11 +08:00
Merge branch 'dev' of http://192.168.2.46:8099/jsowell/jsowell-charger-web into dev
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package com.jsowell.netty.decoder;
|
package com.jsowell.netty.decoder;
|
||||||
|
|
||||||
import com.jsowell.netty.domain.ChargingPileMessage;
|
import com.jsowell.netty.domain.EBikeMessage;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||||
@@ -22,7 +22,7 @@ public class MessageDecode extends ByteToMessageDecoder {
|
|||||||
in.readBytes(bytes);
|
in.readBytes(bytes);
|
||||||
|
|
||||||
// 解析字节数组
|
// 解析字节数组
|
||||||
ChargingPileMessage message = ChargingPileMessage.parseMessage(bytes);
|
EBikeMessage message = EBikeMessage.parseMessage(bytes);
|
||||||
out.add(message);
|
out.add(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,7 @@ import java.util.Arrays;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Builder
|
@Builder
|
||||||
public class ChargingPileMessage {
|
public class EBikeMessage {
|
||||||
private String header; // 包头 (3字节)
|
private String header; // 包头 (3字节)
|
||||||
private int length; // 长度 (2字节)
|
private int length; // 长度 (2字节)
|
||||||
private int physicalId; // 物理ID (4字节)
|
private int physicalId; // 物理ID (4字节)
|
||||||
@@ -40,12 +40,12 @@ public class ChargingPileMessage {
|
|||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChargingPileMessage parseMessage(byte[] messageBytes) {
|
public static EBikeMessage parseMessage(byte[] messageBytes) {
|
||||||
if (messageBytes == null || messageBytes.length < 14 || messageBytes.length > 256) {
|
if (messageBytes == null || messageBytes.length < 14 || messageBytes.length > 256) {
|
||||||
throw new IllegalArgumentException("Invalid message bytes");
|
throw new IllegalArgumentException("Invalid message bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
ChargingPileMessage message = new ChargingPileMessage();
|
EBikeMessage message = new EBikeMessage();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 读取包头
|
// 读取包头
|
||||||
@@ -1,27 +1,18 @@
|
|||||||
package com.jsowell.netty.server.electricbicycles;
|
package com.jsowell.netty.server.electricbicycles;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.jsowell.common.util.BytesUtil;
|
import com.jsowell.netty.domain.EBikeMessage;
|
||||||
import com.jsowell.netty.domain.ChargingPileMessage;
|
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class ChargingPileHandler extends SimpleChannelInboundHandler<ChargingPileMessage> {
|
public class ChargingPileHandler extends SimpleChannelInboundHandler<EBikeMessage> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, ChargingPileMessage msg) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, EBikeMessage msg) throws Exception {
|
||||||
log.info("收到消息, channelId:{}, msg:{}", ctx.channel().id().toString(), JSON.toJSONString(msg));
|
log.info("收到消息, channelId:{}, msg:{}", ctx.channel().id().toString(), JSON.toJSONString(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user