!18 远程更新 远程更新应答

* 远程更新应答 补充 onRemoteUpdate  去掉 UpgradeStatusEnum 枚举 用hashMap 处理升级结果返回 领域模型优化 代码优化
* Merge branch 'master' of gitee.com:san-bing/JChargePointProtocol into Feat_远程更新
* 远程更新 远程更新应答
This commit is contained in:
八万
2025-08-13 10:47:49 +00:00
committed by 三丙
parent ca536a55f2
commit 80fb741692
10 changed files with 230 additions and 1 deletions

View File

@@ -153,4 +153,22 @@ public class AbstractYunKuaiChongCmdExe {
return new BigDecimal(value).divide(new BigDecimal(magnification), scale, RoundingMode.HALF_UP);
}
protected static ByteBuf writeParamFillZero(String param,int maxLength) {
if (param.length() > maxLength) {
throw new IllegalArgumentException(String.format("云快充1.5.0 param: %s too large",param));
}
ByteBuf msgBody = Unpooled.buffer(maxLength);
msgBody.writeBytes(param.getBytes());
msgBody.writeZero(maxLength-param.length());
return msgBody;
}
protected static ByteBuf writeParamFillZero(int param,int maxLength) {
ByteBuf msgBody = Unpooled.buffer(maxLength);
msgBody.writeByte(param);
int index = msgBody.writerIndex();
msgBody.writeZero(maxLength-index);
return msgBody;
}
}

View File

@@ -36,8 +36,11 @@ public enum YunKuaiChongDownlinkCmdEnum {
REMOTE_PARALLEL_START_CHARGING(0xA4),
REMOTE_RESTART_PILE(0x92);
REMOTE_RESTART_PILE(0x92),
REMOTE_UPDATE(0x94),
;
private final Integer cmd;
}

View File

@@ -0,0 +1,62 @@
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(0x93)
public class YunKuaiChongV150RemoteUpdateAckULCmd extends YunKuaiChongUplinkCmdExe {
private static final Map<Byte, String> UPGRADE_STATUS;
static {
UPGRADE_STATUS = Map.of(
(byte) 0x00,"成功",
(byte) 0x01,"编号错误",
(byte) 0x02,"程序与桩型号不符",
(byte) 0x03, "下载更新文件超时"
);
}
@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编号错误 0x01程序与桩型号不符 0x01下载更新文件超时
byte upgradeStatus = byteBuf.readByte();
ProtocolProto.UplinkQueueMessage queueMessage = uplinkMessageBuilder(pileCode, tcpSession, message)
.setOtaResponse(ProtocolProto.OtaResponse.newBuilder()
.setPileCode(pileCode)
.setSuccess(upgradeStatus == 0x00)
.setErrorMsg(UPGRADE_STATUS.get(upgradeStatus))
.build())
.build();
// 转发到后端
tcpSession.getForwarder().sendMessage(queueMessage);
}
}

View File

@@ -0,0 +1,52 @@
package sanbing.jcpp.protocol.yunkuaichong.v150.cmd;
import static sanbing.jcpp.protocol.yunkuaichong.enums.YunKuaiChongDownlinkCmdEnum.REMOTE_UPDATE;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.extern.slf4j.Slf4j;
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(0x94)
public class YunKuaiChongV150RemoteUpdateDLCmd extends YunKuaiChongDownlinkCmdExe {
@Override
public void execute(TcpSession tcpSession, YunKuaiChongDwonlinkMessage message, ProtocolContext ctx) {
log.info("{} 云快充1.5.0 远程更新", tcpSession);
// check
if (message.getMsg().hasOtaRequest()) {
log.error("云快充1.5.0 远程更新消息体为空");
return;
}
// 初始化 buf
ByteBuf msgBody = Unpooled.buffer(94);
// buf 转换
ProtocolProto.OtaRequest request = message.getMsg().getOtaRequest();
msgBody.writeBytes(encodePileCode(request.getPileCode()));
msgBody.writeByte(request.getPileModel());
msgBody.writeBytes(writeParamFillZero(request.getPilePower(),2));
msgBody.writeBytes(writeParamFillZero(request.getAddress(),16));
msgBody.writeBytes(writeParamFillZero(request.getPort(),2));
msgBody.writeBytes(writeParamFillZero(request.getUsername(),16));
msgBody.writeBytes(writeParamFillZero(request.getPassword(),16));
msgBody.writeBytes(writeParamFillZero(request.getFilePath(),32));
msgBody.writeByte(request.getExecutionControl());
msgBody.writeByte(request.getDownloadTimeout());
super.encodeAndWriteFlush(REMOTE_UPDATE,msgBody,tcpSession);
}
}