mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 19:45:09 +08:00
update 电单车协议
This commit is contained in:
@@ -6,6 +6,8 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
@@ -24,37 +26,64 @@ public class ChargingPileMessage {
|
||||
private byte[] data; // 数据 (n字节)
|
||||
private int checksum; // 校验 (2字节)
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.JSON_STYLE)
|
||||
.append("header", header)
|
||||
.append("length", length)
|
||||
.append("physicalId", physicalId)
|
||||
.append("messageId", messageId)
|
||||
.append("command", command)
|
||||
.append("data", data)
|
||||
.append("checksum", checksum)
|
||||
.toString();
|
||||
}
|
||||
|
||||
// 从字节数组解析消息
|
||||
public static ChargingPileMessage parseMessage(byte[] messageBytes) {
|
||||
log.info("parseMessage:{}", BytesUtil.binary(messageBytes, 16));
|
||||
ChargingPileMessage message = new ChargingPileMessage();
|
||||
// log.info("parseMessage:{}", BytesUtil.binary(messageBytes, 16));
|
||||
// 读取包头
|
||||
byte[] headerBytes = Arrays.copyOfRange(messageBytes, 0, 3);
|
||||
System.out.println(new String(headerBytes, StandardCharsets.UTF_8));
|
||||
String header = new String(headerBytes, StandardCharsets.UTF_8);
|
||||
message.setHeader(header);
|
||||
// System.out.println("包头:" + header);
|
||||
|
||||
// 读取长度
|
||||
byte[] lengthBytes = {messageBytes[3], messageBytes[4]};
|
||||
System.out.println(BytesUtil.bcd2StrLittle(lengthBytes));
|
||||
int length = BytesUtil.bytesToIntLittle(lengthBytes);
|
||||
message.setLength(length);
|
||||
// System.out.println("长度:" + length);
|
||||
|
||||
// 读取物理ID
|
||||
byte[] physicalIdBytes = Arrays.copyOfRange(messageBytes, 5, 9);
|
||||
System.out.println(BytesUtil.bcd2StrLittle(physicalIdBytes));
|
||||
int physicalId = BytesUtil.bytesToIntLittle(physicalIdBytes);
|
||||
message.setPhysicalId(physicalId);
|
||||
// System.out.println("物理ID:" + physicalId);
|
||||
|
||||
// 读取消息ID
|
||||
byte[] messageIdBytes = {messageBytes[9], messageBytes[10]};
|
||||
System.out.println(BytesUtil.bcd2StrLittle(messageIdBytes));
|
||||
int messageId = BytesUtil.bytesToIntLittle(messageIdBytes);
|
||||
message.setMessageId(messageId);
|
||||
// System.out.println("消息ID:" + messageId);
|
||||
|
||||
// 读取命令
|
||||
byte command = messageBytes[11];
|
||||
System.out.println(BytesUtil.bcd2StrLittle(new byte[] {command}));
|
||||
message.setChecksum(command);
|
||||
// System.out.println("命令:" + BytesUtil.bcd2StrLittle(new byte[] {command}));
|
||||
|
||||
// 读取数据
|
||||
byte[] data = Arrays.copyOfRange(messageBytes, 12, messageBytes.length - 2);
|
||||
System.out.println(BytesUtil.bcd2StrLittle(data));
|
||||
byte[] dataBytes = Arrays.copyOfRange(messageBytes, 12, messageBytes.length - 2);
|
||||
message.setData(dataBytes);
|
||||
String data = BytesUtil.bcd2StrLittle(dataBytes);
|
||||
// System.out.println("数据:" + data);
|
||||
|
||||
// 读取校验
|
||||
byte[] checksumBytes = {messageBytes[messageBytes.length - 2], messageBytes[messageBytes.length - 1]};
|
||||
System.out.println(BytesUtil.bcd2StrLittle(checksumBytes));
|
||||
|
||||
return null;
|
||||
int checksum = BytesUtil.bytesToIntLittle(checksumBytes);
|
||||
message.setChecksum(checksum);
|
||||
// System.out.println("校验:" + checksum);
|
||||
log.info("报文:{}, parseMessage:{}", BytesUtil.binary(messageBytes, 16), message.toString());
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,6 @@ public class ReservationChargingStartupResultHandler extends AbstractHandler{
|
||||
log.info("[===预约充电启动结果上送===]交易流水号:{}, 桩编号:{}, 枪号:{}, vin:{}, 启动结果:{}, 失败原因:{}",
|
||||
transactionCode, pileSn, connectorCode, vinCode, startupResultMsg, failReasonMsg);
|
||||
|
||||
|
||||
ReservationChargingStartupResult chargingStartupResult = ReservationChargingStartupResult.builder()
|
||||
.transactionCode(transactionCode)
|
||||
.pileSn(pileSn)
|
||||
@@ -97,14 +96,12 @@ public class ReservationChargingStartupResultHandler extends AbstractHandler{
|
||||
.build();
|
||||
pileBasicInfoService.startupResult(chargingStartupResult);
|
||||
|
||||
|
||||
/*
|
||||
应答
|
||||
确认结果 0x00 成功 0x01 失败
|
||||
*/
|
||||
byte[] confirmResultBytes = Constants.zeroByteArray;
|
||||
byte[] concatMsgBody = Bytes.concat(transactionCodeByteArr, pileSnByteArr, connectorCodeByteArr, confirmResultBytes);
|
||||
|
||||
return getResult(ykcDataProtocol, concatMsgBody);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user