mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-08-10 00:03:44 +08:00
远程启动充电指令增加同步等待充电桩应答并打印结果
pushStartChargingCommand 发送 0x34 启机指令后,通过 SyncPromise 同步等待 0x33 应答(最多3秒),在同一线程打印启动结果。效果:成功打印成功,失败打印失败(原因),超时打印超时提示。
This commit is contained in:
@@ -406,14 +406,40 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService {
|
||||
byte[] accountBalanceByteArr = YKCUtils.getPriceByte(chargeAmount.toString(), 2);
|
||||
|
||||
byte[] msgBody = Bytes.concat(orderIdByteArr, pileSnByteArr, connectorCodeByteArr, logicCardNumByteArr, physicsCardNumByteArr, accountBalanceByteArr);
|
||||
|
||||
// 注册同步等待容器,用于接收充电桩 0x33 应答并打印启动结果
|
||||
SyncPromise syncPromise = new SyncPromise();
|
||||
String responseKey = transactionCode + "_0x33";
|
||||
RpcUtil.getSyncPromiseMap().put(responseKey, syncPromise);
|
||||
|
||||
try {
|
||||
this.runSend(msgBody, pileSn, YKCFrameTypeCode.REMOTE_CONTROL_START_CHARGING_CODE);
|
||||
} catch (Exception e) {
|
||||
RpcUtil.getSyncPromiseMap().remove(responseKey);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
log.info("【=====平台下发充电指令=====】:订单id:{}, 桩号:{}, 枪口号:{}, 逻辑卡号:{}, 物理卡号:{}, 账户余额:{}",
|
||||
transactionCode, pileSn, BytesUtil.bcd2Str(connectorCodeByteArr), logicCardNum, physicsCardNum, chargeAmount);
|
||||
|
||||
// 等待充电桩应答(最多 3 秒)
|
||||
byte[] response;
|
||||
try {
|
||||
response = syncPromise.get(3, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
response = null;
|
||||
} finally {
|
||||
RpcUtil.getSyncPromiseMap().remove(responseKey);
|
||||
}
|
||||
|
||||
if (response == null) {
|
||||
log.warn("【启动充电结果】订单号:{}, 桩号:{}, 枪号:{}, 结果:等待充电桩响应超时(3s),桩可能未收到指令或未回复",
|
||||
transactionCode, pileSn, connectorCode);
|
||||
} else {
|
||||
log.info("【启动充电结果】订单号:{}, 桩号:{}, 枪号:{}, 结果:{}",
|
||||
transactionCode, pileSn, connectorCode, new String(response, java.nio.charset.StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user