mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
解码器拆分
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.jsowell.netty.server.electricbicycles;
|
||||
|
||||
import com.jsowell.netty.decoder.YouDianDecoder;
|
||||
import com.jsowell.netty.decoder.YouDianProtocolDecoder;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
@@ -20,7 +20,7 @@ public class ElectricBicyclesServerChannelInitializer extends ChannelInitializer
|
||||
@Override
|
||||
protected void initChannel(SocketChannel channel) throws Exception {
|
||||
ChannelPipeline pipeline = channel.pipeline();
|
||||
pipeline.addLast("frameDecoder", new YouDianDecoder());
|
||||
pipeline.addLast("frameDecoder", new YouDianProtocolDecoder());
|
||||
// pipeline.addLast("decoder", new MessageDecode());
|
||||
// pipeline.addLast("encoder", new MessageEncode());
|
||||
pipeline.addLast("decoder", new ByteArrayDecoder());
|
||||
|
||||
@@ -20,8 +20,8 @@ public class NettyServerChannelInitializer extends ChannelInitializer<SocketChan
|
||||
@Override
|
||||
protected void initChannel(SocketChannel channel) throws Exception {
|
||||
ChannelPipeline pipeline = channel.pipeline();
|
||||
// pipeline.addLast("frameDecoder",new CustomDecoder());
|
||||
pipeline.addLast("frameDecoder", new YunKuaiChongDecoder());
|
||||
pipeline.addLast("frameDecoder",new YunKuaiChongDecoder());
|
||||
// pipeline.addLast("frameDecoder", new YkcProtocolDecoder());
|
||||
pipeline.addLast("decoder", new ByteArrayDecoder());
|
||||
pipeline.addLast("encoder", new ByteArrayDecoder());
|
||||
//读超时时间设置为10s,0表示不监控
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jsowell.netty.server.yunkuaichong;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
|
||||
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
|
||||
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
@@ -68,9 +69,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
||||
*/
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object message) throws Exception {
|
||||
// log.info("channelRead-aClass:{}", message.getClass());
|
||||
// log.info("加载客户端报文channelRead=== channelId:" + ctx.channel().id() + ", msg:" + message);
|
||||
// 下面可以解析数据,保存数据,生成返回报文,将需要返回报文写入write函数
|
||||
byte[] msg = (byte[]) message;
|
||||
YKCDataProtocol ykcDataProtocol = (YKCDataProtocol) message;
|
||||
byte[] msg = ykcDataProtocol.getBytes();
|
||||
|
||||
// 获取帧类型
|
||||
byte[] frameTypeBytes = BytesUtil.copyBytes(msg, 5, 1);
|
||||
|
||||
Reference in New Issue
Block a user