update 电单车协议

This commit is contained in:
Guoqs
2024-08-03 16:59:31 +08:00
parent 01770b2123
commit 6345314725
6 changed files with 117 additions and 170 deletions

View File

@@ -102,17 +102,17 @@ public class ChargingPileHandler extends ChannelInboundHandlerAdapter {
private void handleTimeRequest(ChannelHandlerContext ctx, ChargingPileMessage message) {
// 处理时间请求
long currentTime = Instant.now().getEpochSecond();
byte[] timeBytes = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt((int)currentTime).array();
ChargingPileMessage response = new ChargingPileMessage(
message.getPhysicalId(),
message.getMessageId(),
(byte) 0x12,
timeBytes
);
ctx.writeAndFlush(response);
// long currentTime = Instant.now().getEpochSecond();
// byte[] timeBytes = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt((int)currentTime).array();
//
// ChargingPileMessage response = new ChargingPileMessage(
// message.getPhysicalId(),
// message.getMessageId(),
// (byte) 0x12,
// timeBytes
// );
//
// ctx.writeAndFlush(response);
}
private void handleFirmwareUpgradeRequest(ChannelHandlerContext ctx, ChargingPileMessage message) {
@@ -171,13 +171,13 @@ public class ChargingPileHandler extends ChannelInboundHandlerAdapter {
}
private void sendSimpleResponse(ChannelHandlerContext ctx, ChargingPileMessage originalMessage, byte command, byte result) {
ChargingPileMessage response = new ChargingPileMessage(
originalMessage.getPhysicalId(),
originalMessage.getMessageId(),
command,
new byte[]{result}
);
ctx.writeAndFlush(response);
// ChargingPileMessage response = new ChargingPileMessage(
// originalMessage.getPhysicalId(),
// originalMessage.getMessageId(),
// command,
// new byte[]{result}
// );
// ctx.writeAndFlush(response);
}
@Override

View File

@@ -1,12 +1,11 @@
package com.jsowell.netty.server.electricbicycles;
import com.jsowell.netty.decoder.ChargingPileDecoder;
import com.jsowell.netty.decoder.MessageDecode;
import com.jsowell.netty.decoder.MessageEncode;
import com.jsowell.netty.decoder.StartAndLengthFieldFrameDecoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.timeout.IdleStateHandler;
import org.springframework.stereotype.Component;
@@ -27,7 +26,7 @@ public class ElectricBicyclesServerChannelInitializer extends ChannelInitializer
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast("frameDecoder", new StartAndLengthFieldFrameDecoder());
pipeline.addLast("decoder", new MessageDecode());
pipeline.addLast("encoder", new MessageDecode());
pipeline.addLast("encoder", new MessageEncode());
//读超时时间设置为10s0表示不监控
pipeline.addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS));
pipeline.addLast("handler", chargingPileHandler);