mirror of
https://gitee.com/san-bing/JChargePointProtocol
synced 2026-05-03 17:39:55 +08:00
!29 云快充主动对时设置0x56、对时应答0x55
* 删除错误代码 * 修改冲突编号 * Merge branch 'master' into Feat_TimeSync * 修改冲突编号 * Merge branch 'master' into Feat_TimeSync * 云快充对时设置 * 云快充对时设置
This commit is contained in:
@@ -16,6 +16,7 @@ import sanbing.jcpp.proto.gen.ProtocolProto;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -205,4 +206,10 @@ public class TestController {
|
||||
return ResponseEntity.ok("success");
|
||||
}
|
||||
|
||||
@GetMapping("/api/timeSync")
|
||||
public ResponseEntity<String> timeSync() {
|
||||
pileProtocolService.timeSync("20231212000010", LocalDateTime.now());
|
||||
return ResponseEntity.ok("success");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import sanbing.jcpp.proto.gen.ProtocolProto.SetPricingRequest;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto.UplinkQueueMessage;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author baigod
|
||||
@@ -157,4 +158,8 @@ public interface PileProtocolService {
|
||||
* 离线卡数据同步应答
|
||||
*/
|
||||
void onOfflineCardSyncResponse(UplinkQueueMessage uplinkQueueMessage, Callback callback);
|
||||
void timeSync(String pileCode, LocalDateTime time);
|
||||
|
||||
void onTimeSync(UplinkQueueMessage uplinkQueueMessage, Callback callback);
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
package sanbing.jcpp.app.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -27,6 +28,7 @@ import sanbing.jcpp.proto.gen.ProtocolProto.*;
|
||||
import sanbing.jcpp.protocol.domain.DownlinkCmdEnum;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.*;
|
||||
|
||||
@@ -430,7 +432,37 @@ public class DefaultPileProtocolService implements PileProtocolService {
|
||||
bmsBatteryType, bmsPowerCapacity, additionalInfo);
|
||||
|
||||
// TODO 处理相关业务逻辑,比如保存握手信息到数据库
|
||||
|
||||
|
||||
callback.onSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void timeSync(String pileCode, LocalDateTime time) {
|
||||
UUID messageId = UUID.randomUUID();
|
||||
UUID requestId = UUID.randomUUID();
|
||||
DownlinkRequestMessage.Builder downlinkRequestMessageBuilder = DownlinkRequestMessage.newBuilder()
|
||||
.setMessageIdMSB(messageId.getMostSignificantBits())
|
||||
.setMessageIdLSB(messageId.getLeastSignificantBits())
|
||||
.setPileCode(pileCode)
|
||||
.setRequestIdMSB(requestId.getMostSignificantBits())
|
||||
.setRequestIdLSB(requestId.getLeastSignificantBits())
|
||||
.setDownlinkCmd(DownlinkCmdEnum.SYNC_TIME_REQUEST.name())
|
||||
.setTimeSyncRequest(TimeSyncRequest.newBuilder()
|
||||
.setPileCode(pileCode)
|
||||
.setTime(DateUtil.formatLocalDateTime(time))
|
||||
.build());
|
||||
downlinkCallService.sendDownlinkMessage(downlinkRequestMessageBuilder, pileCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeSync(UplinkQueueMessage uplinkQueueMessage, Callback callback) {
|
||||
log.info("对时设置应答 {}", uplinkQueueMessage);
|
||||
TimeSyncResponse timeSyncResponse = uplinkQueueMessage.getTimeSyncResponse();
|
||||
String pileCode = timeSyncResponse.getPileCode();
|
||||
String time = timeSyncResponse.getTime();
|
||||
log.info("对时设置应答: 桩编码: {}, 时间: {}", pileCode, time);
|
||||
// TODO 处理相关业务逻辑
|
||||
|
||||
callback.onSuccess();
|
||||
}
|
||||
|
||||
@@ -450,6 +482,7 @@ public class DefaultPileProtocolService implements PileProtocolService {
|
||||
|
||||
// TODO 处理相关业务逻辑,比如保存地锁状态信息到数据库
|
||||
|
||||
|
||||
callback.onSuccess();
|
||||
}
|
||||
|
||||
|
||||
@@ -232,6 +232,10 @@ public class ProtocolUplinkConsumerService extends AbstractConsumerService imple
|
||||
|
||||
pileProtocolService.onOfflineCardSyncResponse(uplinkQueueMsg, callback);
|
||||
|
||||
} else if (uplinkQueueMsg.hasTimeSyncResponse()) {
|
||||
|
||||
pileProtocolService.onTimeSync(uplinkQueueMsg, callback);
|
||||
|
||||
} else {
|
||||
|
||||
callback.onSuccess();
|
||||
|
||||
@@ -76,6 +76,7 @@ message UplinkQueueMessage {
|
||||
GroundLockStatusProto groundLockStatusProto = 39;
|
||||
OfflineCardBalanceUpdateResponse offlineCardBalanceUpdateResponse = 40;
|
||||
OfflineCardSyncResponse offlineCardSyncResponse = 41;
|
||||
TimeSyncResponse timeSyncResponse = 42;
|
||||
|
||||
}
|
||||
|
||||
@@ -101,6 +102,7 @@ message DownlinkRequestMessage {
|
||||
OtaRequest otaRequest = 29;
|
||||
OfflineCardBalanceUpdateRequest offlineCardBalanceUpdateRequest = 30;
|
||||
OfflineCardSyncRequest offlineCardSyncRequest = 31;
|
||||
TimeSyncRequest timeSyncRequest = 32;
|
||||
}
|
||||
|
||||
message DownlinkResponseMessage {
|
||||
@@ -469,4 +471,14 @@ message OfflineCardSyncResponse {
|
||||
string pileCode = 1; // 充电桩编码
|
||||
bool success = 3;
|
||||
optional string errorMsg = 4;
|
||||
}
|
||||
}
|
||||
|
||||
message TimeSyncRequest {
|
||||
string pileCode = 1;
|
||||
string time = 2;
|
||||
}
|
||||
|
||||
message TimeSyncResponse {
|
||||
string pileCode = 1;
|
||||
string time = 2;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ public enum DownlinkCmdEnum {
|
||||
|
||||
OTA_REQUEST,
|
||||
|
||||
SYNC_TIME_REQUEST,
|
||||
|
||||
OFFLINE_CARD_BALANCE_UPDATE_REQUEST,
|
||||
|
||||
OFFLINE_CARD_SYNC_REQUEST
|
||||
|
||||
@@ -117,4 +117,11 @@
|
||||
#### 成功
|
||||
`68 0d 19 00 00 43 20 23 12 12 00 00 10 01 00 38 83`
|
||||
#### 失败
|
||||
`68 0d 19 00 00 43 20 23 12 12 00 00 10 00 01 f8 d3`
|
||||
`68 0d 19 00 00 43 20 23 12 12 00 00 10 00 01 f8 d3`
|
||||
---
|
||||
|
||||
#### 0x56 对时设置
|
||||
`68 12 01 00 00 56 20 23 12 12 00 00 10 E0 2E 0C 0C 15 08 19 E8 36`
|
||||
|
||||
#### 0x55 对时设置应答
|
||||
`68 12 01 00 00 55 20 23 12 12 00 00 10 E0 2E 0C 0C 15 08 19 AB 37`
|
||||
|
||||
@@ -45,6 +45,8 @@ public enum YunKuaiChongDownlinkCmdEnum {
|
||||
OFFLINE_CARD_SYNC_REQUEST(0x44),
|
||||
|
||||
|
||||
SYNC_TIME_REQUEST(0x56),
|
||||
|
||||
;
|
||||
private final Integer cmd;
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package sanbing.jcpp.protocol.yunkuaichong.v150.cmd;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import sanbing.jcpp.infrastructure.util.codec.CP56Time2aUtil;
|
||||
import sanbing.jcpp.proto.gen.ProtocolProto;
|
||||
import sanbing.jcpp.protocol.ProtocolContext;
|
||||
import sanbing.jcpp.protocol.listener.tcp.TcpSession;
|
||||
import sanbing.jcpp.protocol.listener.tcp.enums.SequenceNumberLength;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDownlinkCmdExe;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongDwonlinkMessage;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.annotation.YunKuaiChongCmd;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static sanbing.jcpp.protocol.yunkuaichong.enums.YunKuaiChongDownlinkCmdEnum.SYNC_TIME;
|
||||
|
||||
/**
|
||||
* 云快充1.5.0对时设置
|
||||
*
|
||||
* @author 发财
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
@YunKuaiChongCmd(0x56)
|
||||
public class YunKuaiChongV150TimeSyncDLCmd extends YunKuaiChongDownlinkCmdExe {
|
||||
@Override
|
||||
public void execute(TcpSession tcpSession, YunKuaiChongDwonlinkMessage yunKuaiChongDwonlinkMessage, ProtocolContext ctx) {
|
||||
log.info("云快充1.5.0对时设置");
|
||||
if (!yunKuaiChongDwonlinkMessage.getMsg().hasTimeSyncRequest()) {
|
||||
return;
|
||||
}
|
||||
ProtocolProto.TimeSyncRequest timeSyncRequest = yunKuaiChongDwonlinkMessage.getMsg().getTimeSyncRequest();
|
||||
String pileCode = timeSyncRequest.getPileCode();
|
||||
String time = timeSyncRequest.getTime();
|
||||
ByteBuf syncTimeMsgBody = Unpooled.buffer(14);
|
||||
syncTimeMsgBody.writeBytes(encodePileCode(pileCode));
|
||||
syncTimeMsgBody.writeBytes(CP56Time2aUtil.encode(DateUtil.parseLocalDateTime(time)));
|
||||
encodeAndWriteFlush(SYNC_TIME, syncTimeMsgBody, tcpSession);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package sanbing.jcpp.protocol.yunkuaichong.v150.cmd;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
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.infrastructure.util.codec.CP56Time2aUtil;
|
||||
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.YunKuaiChongUplinkCmdExe;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.YunKuaiChongUplinkMessage;
|
||||
import sanbing.jcpp.protocol.yunkuaichong.annotation.YunKuaiChongCmd;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 云快充1.5.0 对时结果
|
||||
*
|
||||
* @author 发财
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
@YunKuaiChongCmd(0x55)
|
||||
public class YunKuaiChongV150TimeSyncResultULCmd extends YunKuaiChongUplinkCmdExe {
|
||||
|
||||
@Override
|
||||
public void execute(TcpSession tcpSession, YunKuaiChongUplinkMessage yunKuaiChongUplinkMessage, ProtocolContext ctx) {
|
||||
log.info("{} 云快充1.5.0 对时结果", tcpSession);
|
||||
ByteBuf byteBuf = Unpooled.wrappedBuffer(yunKuaiChongUplinkMessage.getMsgBody());
|
||||
byte[] pileCodeBytes = new byte[7];
|
||||
byteBuf.readBytes(pileCodeBytes);
|
||||
String pileCode = BCDUtil.toString(pileCodeBytes);
|
||||
byte[] timeBytes = new byte[7];
|
||||
byteBuf.readBytes(timeBytes);
|
||||
LocalDateTime dateTime = CP56Time2aUtil.decode(timeBytes);
|
||||
String time = DateUtil.formatLocalDateTime(dateTime);
|
||||
ProtocolProto.TimeSyncResponse timeSyncResponse = ProtocolProto.TimeSyncResponse.newBuilder()
|
||||
.setPileCode(pileCode)
|
||||
.setTime(time)
|
||||
.build();
|
||||
ProtocolProto.UplinkQueueMessage uplinkQueueMessage = uplinkMessageBuilder(pileCode, tcpSession, yunKuaiChongUplinkMessage)
|
||||
.setTimeSyncResponse(timeSyncResponse)
|
||||
.build();
|
||||
tcpSession.getForwarder().sendMessage(uplinkQueueMessage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user