新增协议0x65预约充电启动结果上传

This commit is contained in:
Guoqs
2024-07-25 08:54:45 +08:00
parent 85aa953f56
commit 1adec0e1a5
3 changed files with 83 additions and 4 deletions

View File

@@ -1,9 +1,22 @@
package com.jsowell.netty.handler.yunkuaichong;
import com.alibaba.fastjson2.JSON;
import com.google.common.primitives.Bytes;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.YKCDataProtocol;
import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.YKCOperateFactory;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 预约充电启动结果上送
*/
@Slf4j
@Component
public class ReservationChargingStartupResultHandler extends AbstractHandler{
private final String type = YKCUtils.frameType2Str(YKCFrameTypeCode.RESERVATION_CHARGING_STARTUP_RESULT_CODE.getBytes());
@@ -12,4 +25,66 @@ public class ReservationChargingStartupResultHandler extends AbstractHandler{
public void afterPropertiesSet() throws Exception {
YKCOperateFactory.register(type, this);
}
@Override
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) {
log.info("[===预约充电启动结果上送===] param:{}, channel:{}", JSON.toJSONString(ykcDataProtocol), channel.toString());
// 消息体
byte[] msgBody = ykcDataProtocol.getMsgBody();
int startIndex = 0;
int length = 16;
// 交易流水号
byte[] transactionCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionCode = BytesUtil.bcd2Str(transactionCodeByteArr);
// 桩编码
startIndex += length;
length = 7;
byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String pileSn = BytesUtil.bcd2Str(pileSnByteArr);
// 保存时间
saveLastTimeAndCheckChannel(pileSn, channel);
// 枪号
startIndex += length;
length = 1;
byte[] connectorCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String connectorCode = BytesUtil.bcd2Str(connectorCodeByteArr);
// vin
startIndex += length;
length = 17;
byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String vinCode = BytesUtil.bcd2Str(vinCodeByteArr);
// 启动结果
startIndex += length;
length = 1;
byte[] startupResultByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String startupResult = BytesUtil.bcd2Str(startupResultByteArr);
// 失败原因
startIndex += length;
length = 1;
byte[] failReasonByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String failReason = BytesUtil.bcd2Str(failReasonByteArr);
log.info("[===预约充电启动结果上送===]交易流水号:{}, 桩编号:{}, 枪号:{}, vin:{}, 启动结果:{}, 失败原因:{}",
transactionCode, pileSn, connectorCode, vinCode, startupResult, failReason);
/*
应答
确认结果 0x00 成功 0x01 失败
*/
byte[] confirmResultBytes = Constants.zeroByteArray;
byte[] concatMsgBody = Bytes.concat(transactionCodeByteArr, pileSnByteArr, connectorCodeByteArr, confirmResultBytes);
return getResult(ykcDataProtocol, concatMsgBody);
}
}

View File

@@ -330,8 +330,8 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
int length = 16;
// 交易流水号
byte[] orderCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionCode = BytesUtil.bcd2Str(orderCodeByteArr);
byte[] transactionCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
String transactionCode = BytesUtil.bcd2Str(transactionCodeByteArr);
// 桩编码
startIndex += length;
@@ -582,7 +582,7 @@ public class TransactionRecordsRequestHandler extends AbstractHandler {
2022年12月15日11点28分发现返回 01非法账单充电桩会持续上传交易记录后面产生的交易记录被阻塞
*/
byte[] confirmResultBytes = Constants.zeroByteArray;
byte[] concatMsgBody = Bytes.concat(orderCodeByteArr, confirmResultBytes);
byte[] concatMsgBody = Bytes.concat(transactionCodeByteArr, confirmResultBytes);
return getResult(ykcDataProtocol, concatMsgBody);
}