From a6f1b48cd1e292a88e06cdf39aced4137fe9c57b Mon Sep 17 00:00:00 2001 From: Guoqs <123@jsowell.com> Date: Tue, 3 Sep 2024 16:24:03 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E7=94=B5=E5=8D=95=E8=BD=A6=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/uniapp/customer/TempController.java | 1 + .../ebike/serversend/EBikeMessageCmd82.java | 16 +++++---- .../impl/EBikeSendCommandServiceImpl.java | 35 ++++++++++++++----- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/TempController.java b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/TempController.java index ad4a0574f..fd6337427 100644 --- a/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/TempController.java +++ b/jsowell-admin/src/main/java/com/jsowell/api/uniapp/customer/TempController.java @@ -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); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/serversend/EBikeMessageCmd82.java b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/serversend/EBikeMessageCmd82.java index 3482c5fec..aab97106e 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/serversend/EBikeMessageCmd82.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/domain/ebike/serversend/EBikeMessageCmd82.java @@ -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); // 额外浮充时间 diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/EBikeSendCommandServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/EBikeSendCommandServiceImpl.java index 529ad6598..87a125a5c 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/EBikeSendCommandServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/EBikeSendCommandServiceImpl.java @@ -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); + } + }); } }