update 电单车协议

This commit is contained in:
Guoqs
2024-09-03 16:24:03 +08:00
parent e5100ef65f
commit a6f1b48cd1
3 changed files with 37 additions and 15 deletions

View File

@@ -7,6 +7,9 @@ import com.jsowell.common.util.id.IdUtils;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.serversend.EBikeMessageCmd82;
import com.jsowell.pile.service.EBikeSendCommandService;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -27,13 +30,13 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
EBikeMessageCmd82.SpecificData data = new EBikeMessageCmd82.SpecificData();
// 充电模式
data.setRateMode("3");
data.setRateMode("0");
// 余额或有效期
data.setBalanceOrValidity("0");
data.setBalanceOrValidity("356");
// 端口号
data.setPortNumber("1");
// 充电命令
data.setChargeCommand("1");
data.setChargeCommand("01");
// 充电时长/功率
data.setChargeDurationOrPower("0");
@@ -41,8 +44,10 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
String orderNumber = IdUtils.generateTransactionCode(pileSn, connectorCode);
data.setOrderNumber(orderNumber);
data.setMaxChargeDuration("0");
data.setOverloadPower("0");
// 最大充电时长
data.setMaxChargeDuration("28800");
// 过载功率
data.setOverloadPower("5000");
data.setQrCodeLight("0");
data.setLongChargeMode("0");
data.setExtraFloatChargeTime("0");
@@ -62,15 +67,29 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
private void send(AbsEBikeMessage msg) {
String pileSn = msg.getPhysicalId() + "";
byte[] messageBytes = msg.getMessageBytes();
PileChannelEntity.output();
log.info("发送电单车命令, pileSn:{}, messageBytes:{}", pileSn, BytesUtil.binary(messageBytes, 16));
// PileChannelEntity.output();
log.info("发送电单车send命令, pileSn:{}, messageBytes:{}", pileSn, BytesUtil.binary(messageBytes, 16));
// 获取桩的channel
ChannelHandlerContext ctx = PileChannelEntity.getChannelByPileSn(pileSn);
if (Objects.isNull(ctx)) {
log.error("电单车send命令失败, 桩号:{}无法获取到长连接, 请检查充电桩连接状态!", pileSn);
throw new NullPointerException("channel");
}
// ctx.writeAndFlush(messageBytes);
ByteBuf byteBuf = ctx.channel().alloc().buffer().writeBytes(messageBytes);
ChannelFuture channelFuture = ctx.channel().writeAndFlush(byteBuf);
channelFuture.addListener((ChannelFutureListener) channelFutureListener -> {
// 检查操作的状态
if (channelFutureListener.isSuccess()) {
log.info("【电单车send结果===>成功】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), msg.getCommand(), BytesUtil.binary(messageBytes, 16));
} else {
// 如果发生错误则访问描述原因的Throwable
Throwable cause = channelFutureListener.cause();
log.info("【电单车send结果===>失败】, pileSn:{}, remoteAddress:{}, channelId:{}, 帧类型:{}, 报文:{}",
pileSn, ctx.channel().remoteAddress(), ctx.channel().id(), msg.getCommand(), BytesUtil.binary(messageBytes, 16));
log.error("电单车send发送命令失败, pileSn:{}", pileSn, cause);
}
});
}
}