mirror of
https://gitee.com/san-bing/JChargePointProtocol
synced 2026-05-04 18:09:54 +08:00
!27 Merge branch 'master' into Feat_远程账户余额更新
* 离线卡数据同步(0x44) 离线卡数据同步应答(0x43) * Merge branch 'master' into Feat_远程账户余额更新 * 离线卡数据同步(0x44) 离线卡数据同步应答(0x43) * 下发卡个数 参数校验 * Merge branch 'master' into Feat_远程账户余额更新 * 离线卡数据同步(0x44) 离线卡数据同步应答(0x43) * 远程账户余额更新(0x42) 余额更新应答(0x41)
This commit is contained in:
@@ -41,6 +41,10 @@ public class AbstractYunKuaiChongCmdExe {
|
||||
|
||||
private static final DecimalFormat PRICING_ID_DECIMAL_FORMAT = new DecimalFormat("0000");
|
||||
|
||||
|
||||
protected static final String UNKNOWN_MSG = "未知的异常";
|
||||
|
||||
|
||||
protected static String decodeTradeNo(byte[] tradeNo) {
|
||||
String tradeNoStr = BCDUtil.toString(tradeNo);
|
||||
return CharSequenceUtil.strip(tradeNoStr, "0", null);
|
||||
|
||||
@@ -40,6 +40,11 @@ public enum YunKuaiChongDownlinkCmdEnum {
|
||||
|
||||
OTA_REQUEST(0x94),
|
||||
|
||||
LIMIT_UPDATE_REQUEST(0x42),
|
||||
|
||||
OFFLINE_CARD_SYNC_REQUEST(0x44),
|
||||
|
||||
|
||||
;
|
||||
private final Integer cmd;
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 开源代码,仅供学习和交流研究使用,商用请联系三丙
|
||||
* 微信:mohan_88888
|
||||
* 抖音:程序员三丙
|
||||
* 付费课程知识星球:https://t.zsxq.com/aKtXo
|
||||
*/
|
||||
package sanbing.jcpp.protocol.yunkuaichong.v150.cmd;
|
||||
|
||||
import static sanbing.jcpp.protocol.yunkuaichong.enums.YunKuaiChongDownlinkCmdEnum.LIMIT_UPDATE_REQUEST;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import sanbing.jcpp.infrastructure.util.codec.BCDUtil;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto;
|
||||
import sanbing.jcpp.protocol.ProtocolContext;
|
||||
import sanbing.jcpp.protocol.listener.tcp.TcpSession;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDownlinkCmdExe;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDwonlinkMessage;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.annotation.YunKuaiChongCmd;
|
||||
|
||||
|
||||
/**
|
||||
* 云快充1.5.0 远程账户余额更新
|
||||
*
|
||||
* @author bawan
|
||||
*/
|
||||
@Slf4j
|
||||
@YunKuaiChongCmd(0x42)
|
||||
public class YunKuaiChongV150LimitUpdateRequestDLCmd extends YunKuaiChongDownlinkCmdExe {
|
||||
|
||||
@Override
|
||||
public void execute(TcpSession tcpSession, YunKuaiChongDwonlinkMessage message, ProtocolContext ctx) {
|
||||
log.info("{} 云快充1.5.0 远程账户余额更新", tcpSession);
|
||||
|
||||
if (!message.getMsg().hasLimitUpdateRequest()) {
|
||||
log.error("云快充1.5.0 远程账户余额更新消息体为空");
|
||||
return;
|
||||
}
|
||||
|
||||
// 初始化 buf
|
||||
ByteBuf msgBody = Unpooled.buffer(20);
|
||||
ProtocolProto.LimitUpdateRequest request = message.getMsg().getLimitUpdateRequest();
|
||||
msgBody.writeBytes(encodePileCode(request.getPileCode()));
|
||||
msgBody.writeBytes(encodeGunCode(request.getGunCode()));
|
||||
msgBody.writeBytes(BCDUtil.toBytes(request.getCardNo()));
|
||||
msgBody.writeIntLE(new BigDecimal(request.getLimitYuan()).movePointRight(2).intValue());
|
||||
|
||||
super.encodeAndWriteFlush(LIMIT_UPDATE_REQUEST, msgBody, tcpSession);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 开源代码,仅供学习和交流研究使用,商用请联系三丙
|
||||
* 微信:mohan_88888
|
||||
* 抖音:程序员三丙
|
||||
* 付费课程知识星球:https://t.zsxq.com/aKtXo
|
||||
*/
|
||||
package sanbing.jcpp.protocol.yunkuaichong.v150.cmd;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import sanbing.jcpp.infrastructure.util.codec.BCDUtil;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto;
|
||||
import sanbing.jcpp.protocol.ProtocolContext;
|
||||
import sanbing.jcpp.protocol.listener.tcp.TcpSession;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongUplinkCmdExe;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongUplinkMessage;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.annotation.YunKuaiChongCmd;
|
||||
|
||||
|
||||
/**
|
||||
* 云快充1.5.0 余额更新应答
|
||||
*
|
||||
* @author bawan
|
||||
*/
|
||||
@Slf4j
|
||||
@YunKuaiChongCmd(0x41)
|
||||
public class YunKuaiChongV150LimitUpdateResponseULCmd extends YunKuaiChongUplinkCmdExe {
|
||||
|
||||
private static final Map<Byte, String> UPDATE_RESULT;
|
||||
|
||||
static {
|
||||
UPDATE_RESULT = Map.of(
|
||||
(byte) 0x00,"修改成功",
|
||||
(byte) 0x01,"设备编号错误",
|
||||
(byte) 0x02,"卡号错误"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(TcpSession tcpSession, YunKuaiChongUplinkMessage message, ProtocolContext ctx) {
|
||||
log.info("{} 云快充1.5.0 余额更新应答", tcpSession);
|
||||
|
||||
ByteBuf byteBuf = Unpooled.wrappedBuffer(message.getMsgBody());
|
||||
// 桩编号
|
||||
byte[] pileCodeBytes = new byte[7];
|
||||
byteBuf.readBytes(pileCodeBytes);
|
||||
String pileCode = BCDUtil.toString(pileCodeBytes);
|
||||
|
||||
// 物理卡号
|
||||
String cardNo = CharSequenceUtil.EMPTY;
|
||||
if(byteBuf.readableBytes() >= 8) {
|
||||
byte[] cardNoBytes = new byte[8];
|
||||
byteBuf.readBytes(cardNoBytes);
|
||||
cardNo = BCDUtil.toString(cardNoBytes);
|
||||
}
|
||||
|
||||
// 修改结果 0x00-修改成功 0x01-设备编号错误 0x02-卡号错误
|
||||
byte updateResult = byteBuf.readByte();
|
||||
|
||||
ProtocolProto.UplinkQueueMessage queueMessage = uplinkMessageBuilder(pileCode, tcpSession, message)
|
||||
.setLimitUpdateResponse(ProtocolProto.LimitUpdateResponse.newBuilder()
|
||||
.setPileCode(pileCode)
|
||||
.setCardNo(cardNo)
|
||||
.setSuccess(updateResult == 0x00)
|
||||
.setErrorMsg(UPDATE_RESULT.getOrDefault(updateResult,UNKNOWN_MSG))
|
||||
.build())
|
||||
.build();
|
||||
// 转发到后端
|
||||
tcpSession.getForwarder().sendMessage(queueMessage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 开源代码,仅供学习和交流研究使用,商用请联系三丙
|
||||
* 微信:mohan_88888
|
||||
* 抖音:程序员三丙
|
||||
* 付费课程知识星球:https://t.zsxq.com/aKtXo
|
||||
*/
|
||||
package sanbing.jcpp.protocol.yunkuaichong.v150.cmd;
|
||||
|
||||
import static sanbing.jcpp.protocol.yunkuaichong.enums.YunKuaiChongDownlinkCmdEnum.OFFLINE_CARD_SYNC_REQUEST;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import sanbing.jcpp.infrastructure.util.codec.BCDUtil;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto;
|
||||
import sanbing.jcpp.protocol.ProtocolContext;
|
||||
import sanbing.jcpp.protocol.listener.tcp.TcpSession;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDownlinkCmdExe;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDwonlinkMessage;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.annotation.YunKuaiChongCmd;
|
||||
|
||||
|
||||
/**
|
||||
* 云快充1.5.0 离线卡数据同步
|
||||
*
|
||||
* @author bawan
|
||||
*/
|
||||
@Slf4j
|
||||
@YunKuaiChongCmd(0x44)
|
||||
public class YunKuaiChongV150OfflineCardSyncRequestDLCmd extends YunKuaiChongDownlinkCmdExe {
|
||||
|
||||
@Override
|
||||
public void execute(TcpSession tcpSession, YunKuaiChongDwonlinkMessage message, ProtocolContext ctx) {
|
||||
log.info("{} 云快充1.5.0 离线卡数据同步", tcpSession);
|
||||
|
||||
if (!message.getMsg().hasOfflineCardSyncRequest()) {
|
||||
log.error("云快充1.5.0 离线卡数据同步消息体为空");
|
||||
return;
|
||||
}
|
||||
|
||||
ProtocolProto.OfflineCardSyncRequest request = message.getMsg().getOfflineCardSyncRequest();
|
||||
|
||||
if (request.getTotal() > 15) {
|
||||
log.error("云快充1.5.0 离线卡数据同步 下发卡个数最大支持: 15个当前: {}个", request.getTotal());
|
||||
return;
|
||||
}
|
||||
// 初始化 buf
|
||||
ByteBuf msgBody = Unpooled.buffer(bufferInitialCapacity(request));
|
||||
msgBody.writeBytes(encodePileCode(request.getPileCode()));
|
||||
msgBody.writeIntLE(request.getTotal());
|
||||
request.getCardInfoList().forEach(cardInfo -> {
|
||||
msgBody.writeBytes(BCDUtil.toBytes(cardInfo.getLogicCardNo()));
|
||||
msgBody.writeBytes(BCDUtil.toBytes(cardInfo.getCardNo()));
|
||||
});
|
||||
|
||||
super.encodeAndWriteFlush(OFFLINE_CARD_SYNC_REQUEST, msgBody, tcpSession);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 桩编号 BCD 码 7
|
||||
* 下发卡个数 BIN 码 1 最大 15 个
|
||||
* n卡逻辑卡号 BCD 码 8 离线卡逻辑卡号
|
||||
* ........ ........ ........ ........
|
||||
* n卡物理卡号 BIN 码 8 离线卡物理卡号
|
||||
* @param request request
|
||||
* @return bufferInitialCapacity
|
||||
*/
|
||||
private int bufferInitialCapacity(ProtocolProto.OfflineCardSyncRequest request) {
|
||||
return (8 + 8) * request.getCardInfoCount() + 7 + 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* 开源代码,仅供学习和交流研究使用,商用请联系三丙
|
||||
* 微信:mohan_88888
|
||||
* 抖音:程序员三丙
|
||||
* 付费课程知识星球:https://t.zsxq.com/aKtXo
|
||||
*/
|
||||
package sanbing.jcpp.protocol.yunkuaichong.v150.cmd;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import sanbing.jcpp.infrastructure.util.codec.BCDUtil;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto;
|
||||
import sanbing.jcpp.protocol.ProtocolContext;
|
||||
import sanbing.jcpp.protocol.listener.tcp.TcpSession;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongUplinkCmdExe;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongUplinkMessage;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.annotation.YunKuaiChongCmd;
|
||||
|
||||
|
||||
/**
|
||||
* 云快充1.5.0 离线卡数据同步应答
|
||||
*
|
||||
* @author bawan
|
||||
*/
|
||||
@Slf4j
|
||||
@YunKuaiChongCmd(0x43)
|
||||
public class YunKuaiChongV150OfflineCardSyncResponseULCmd extends YunKuaiChongUplinkCmdExe {
|
||||
|
||||
private static final Map<Byte, Map<Byte, String>> FAILURE_REASON;
|
||||
|
||||
|
||||
private static final String SUCCESS = "成功";
|
||||
|
||||
|
||||
static {
|
||||
FAILURE_REASON = Map.of(
|
||||
(byte) 0x00,Map.of((byte)0x01,"卡号格式错误",(byte)0x02,"储存空间不足"),
|
||||
(byte) 0x01,Map.of((byte)0x00,SUCCESS)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void execute(TcpSession tcpSession, YunKuaiChongUplinkMessage message, ProtocolContext ctx) {
|
||||
log.info("{} 云快充1.5.0 离线卡数据同步应答", tcpSession);
|
||||
|
||||
ByteBuf byteBuf = Unpooled.wrappedBuffer(message.getMsgBody());
|
||||
// 桩编号
|
||||
byte[] pileCodeBytes = new byte[7];
|
||||
byteBuf.readBytes(pileCodeBytes);
|
||||
String pileCode = BCDUtil.toString(pileCodeBytes);
|
||||
|
||||
// 保存结果 0x00-失败 0x01-成功
|
||||
byte saveResult = byteBuf.readByte();
|
||||
byte failureReason = 0x00;
|
||||
|
||||
if (byteBuf.readableBytes() >= 1) {
|
||||
// 失败原因 0x01-卡号格式错误 0x02-储存空间不足
|
||||
failureReason = byteBuf.readByte();
|
||||
}
|
||||
|
||||
ProtocolProto.UplinkQueueMessage queueMessage = uplinkMessageBuilder(pileCode, tcpSession, message)
|
||||
.setOfflineCardSyncResponse(ProtocolProto.OfflineCardSyncResponse.newBuilder()
|
||||
.setPileCode(pileCode)
|
||||
.setSuccess(saveResult == 0x01)
|
||||
.setErrorMsg(errorMsg(saveResult, failureReason))
|
||||
.build())
|
||||
.build();
|
||||
// 转发到后端
|
||||
tcpSession.getForwarder().sendMessage(queueMessage);
|
||||
}
|
||||
|
||||
|
||||
private String errorMsg(byte saveResult, byte failureReason) {
|
||||
if(saveResult == 0x01) {
|
||||
return SUCCESS;
|
||||
}
|
||||
Map<Byte, String> saveResultMap = FAILURE_REASON.get(saveResult);
|
||||
if(null == saveResultMap) {
|
||||
return UNKNOWN_MSG;
|
||||
}
|
||||
return saveResultMap.getOrDefault(failureReason,UNKNOWN_MSG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class YunKuaiChongV150OtaResponseULCmd extends YunKuaiChongUplinkCmdExe {
|
||||
.setOtaResponse(ProtocolProto.OtaResponse.newBuilder()
|
||||
.setPileCode(pileCode)
|
||||
.setSuccess(upgradeStatus == 0x00)
|
||||
.setErrorMsg(UPGRADE_STATUS.get(upgradeStatus))
|
||||
.setErrorMsg(UPGRADE_STATUS.getOrDefault(upgradeStatus,UNKNOWN_MSG))
|
||||
.build())
|
||||
.build();
|
||||
// 转发到后端
|
||||
|
||||
Reference in New Issue
Block a user