mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
update 电单车协议
This commit is contained in:
@@ -84,6 +84,7 @@ public class TempController extends BaseController {
|
||||
RestApiResponse<?> response = null;
|
||||
try {
|
||||
eBikeSendCommandService.startCharging(dto.getPileSn(), dto.getConnectorCode());
|
||||
response = new RestApiResponse<>();
|
||||
} catch (Exception e) {
|
||||
logger.error("电单车开始充电 error", e);
|
||||
response = new RestApiResponse<>(ReturnCodeEnum.CODE_FAILED);
|
||||
|
||||
@@ -142,24 +142,26 @@ public class EBikeMessageCmd82 extends AbsEBikeMessage {
|
||||
// 获取字节数组
|
||||
public byte[] getBytes() {
|
||||
// 费率模式
|
||||
byte[] rateModeBytes = BytesUtil.stringToHexBytes(rateMode, 1);
|
||||
byte[] rateModeBytes = BytesUtil.intToBytesLittle(Integer.parseInt(rateMode), 1);
|
||||
// 余额/有效期
|
||||
byte[] balanceOrValidityBytes = BytesUtil.stringToHexBytes(balanceOrValidity, 4);
|
||||
byte[] balanceOrValidityBytes = BytesUtil.intToBytesLittle(Integer.parseInt(balanceOrValidity), 4);
|
||||
// 端口号
|
||||
byte[] portNumberBytes = YouDianUtils.convertPortNumberToBytes(portNumber);
|
||||
// 充电命令
|
||||
byte[] chargeCommandBytes = BytesUtil.stringToHexBytes(chargeCommand, 1);
|
||||
byte[] chargeCommandBytes = BytesUtil.intToBytesLittle(Integer.parseInt(chargeCommand), 1);
|
||||
// 充电时长/电量
|
||||
byte[] chargeDurationOrPowerBytes = BytesUtil.stringToHexBytes(chargeDurationOrPower, 2);
|
||||
// 订单编号
|
||||
// byte[] orderNumberBytes = BytesUtil.stringToHexBytes(orderNumber, 16);
|
||||
byte[] orderNumberBytes = BytesUtil.str2Bcd(orderNumber);
|
||||
byte[] orderNumberBytes = BytesUtil.ensureLength(BytesUtil.str2Bcd(orderNumber), 16);
|
||||
// 最大充电时长
|
||||
byte[] maxChargeDurationBytes = BytesUtil.stringToHexBytes(maxChargeDuration, 2);
|
||||
// byte[] maxChargeDurationBytes = BytesUtil.stringToHexBytes(maxChargeDuration, 2);
|
||||
byte[] maxChargeDurationBytes = BytesUtil.intToBytesLittle(Integer.parseInt(maxChargeDuration), 2);
|
||||
// 过载功率
|
||||
byte[] overloadPowerBytes = BytesUtil.stringToHexBytes(overloadPower, 2);
|
||||
// byte[] overloadPowerBytes = BytesUtil.stringToHexBytes(overloadPower, 2);
|
||||
byte[] overloadPowerBytes = BytesUtil.intToBytesLittle(Integer.parseInt(overloadPower), 2);
|
||||
// 二维码灯
|
||||
// byte[] qrCodeLightBytes = BytesUtil.stringToHexBytes(qrCodeLight, 1);
|
||||
byte[] qrCodeLightBytes = BytesUtil.intToBytesLittle(Integer.parseInt(qrCodeLight), 1);
|
||||
// 长充模式
|
||||
// byte[] longChargeModeBytes = BytesUtil.stringToHexBytes(longChargeMode, 1);
|
||||
// 额外浮充时间
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user