mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
update 电单车协议
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
//读超时时间设置为10s,0表示不监控
|
||||
pipeline.addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS));
|
||||
pipeline.addLast("handler", chargingPileHandler);
|
||||
|
||||
Reference in New Issue
Block a user