update 电单车协议

This commit is contained in:
Guoqs
2024-09-18 11:41:26 +08:00
parent d0332d5fd0
commit cd4973a183
36 changed files with 702 additions and 1619 deletions

View File

@@ -1,28 +0,0 @@
package com.jsowell.netty.decoder;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
@Slf4j
public class MessageDecode extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
// 检查是否有足够的字节可以读取
if (in.readableBytes() < 14) { // 最小长度包头3 + 长度2 + 物理ID4 + 消息ID2 + 命令1 + 校验2
return;
}
// 读取所有可读字节
byte[] bytes = new byte[in.readableBytes()];
in.readBytes(bytes);
// 解析字节数组
AbsEBikeMessage message = AbsEBikeMessage.parseMessage(bytes);
out.add(message);
}
}

View File

@@ -129,6 +129,8 @@ public class StartAndLengthFieldFrameDecoder extends ByteToMessageDecoder {
// 读取 data 数据
ByteBuf frame = buffer.retainedSlice(beginReader, HEADER_LENGTH_DNY + length + 2);
buffer.readerIndex(beginReader + HEADER_LENGTH_DNY + length + 2);
out.add(frame);
}

View File

@@ -5,7 +5,6 @@ import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.EBikeOperateFactory;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd22;
import io.netty.channel.ChannelHandlerContext;
@@ -36,10 +35,10 @@ public class DeviceGetServerTimeHandler extends AbstractEBikeHandler {
@Override
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
// 解析字节数组
EBikeMessageCmd22 message = (EBikeMessageCmd22) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
log.info("设备 获取服务器时间:{}", JSON.toJSONString(message));
EBikeMessageCmd22 eBikeMessageCmd22 = new EBikeMessageCmd22(dataProtocol.getBytes());
log.info("设备 获取服务器时间:{}", JSON.toJSONString(eBikeMessageCmd22));
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
saveLastTimeAndCheckChannel(eBikeMessageCmd22.getPhysicalId() + "", ctx);
// 获取当前服务器10位时间戳
byte[] timeBytes = BytesUtil.getIntBytes((int) (System.currentTimeMillis() / 1000));

View File

@@ -6,7 +6,6 @@ import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
import com.jsowell.common.enums.ebike.PortStatusEnum;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.EBikeOperateFactory;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd21;
import com.jsowell.pile.service.PileBasicInfoService;
@@ -47,15 +46,12 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
@Override
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
// 解析字节数组
EBikeMessageCmd21 message = (EBikeMessageCmd21) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
EBikeMessageCmd21 eBikeMessageCmd21 = new EBikeMessageCmd21(dataProtocol.getBytes());
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
log.info("设备心跳包:{}", JSON.toJSONString(message));
updatePileStatus(message);
saveLastTimeAndCheckChannel(eBikeMessageCmd21.getPhysicalId() + "", ctx);
log.info("设备心跳包:{}", JSON.toJSONString(eBikeMessageCmd21));
// 更新充电桩状态
updatePileStatus(eBikeMessageCmd21);
return getResult(dataProtocol, Constants.zeroByteArray);
}
@@ -65,9 +61,8 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
*/
private void updatePileStatus(EBikeMessageCmd21 message) {
String pileSn = message.getPhysicalId() + "";
EBikeMessageCmd21.DeviceHeartbeat deviceHeartbeat = message.getDeviceHeartbeat();
int portNumber = deviceHeartbeat.getPortNumber();
List<String> portStatus = deviceHeartbeat.getPortStatus();
int portNumber = message.getPortNumber();
List<String> portStatus = message.getPortStatus();
for (int i = 0; i < portNumber; i++) {
// 组装pile_connector_info表数据
String connectorCode = String.format("%1$02d", i + 1);
@@ -77,5 +72,4 @@ public class HeartbeatHandler extends AbstractEBikeHandler {
pileConnectorInfoService.updateConnectorStatus(pileConnectorCode, PortStatusEnum.eBikeStatusTransformDBStatus(eBikeStatus));
}
}
}

View File

@@ -5,7 +5,6 @@ import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.EBikeOperateFactory;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd12;
import io.netty.channel.ChannelHandlerContext;
@@ -36,7 +35,7 @@ public class HostGetServerTimeHandler extends AbstractEBikeHandler {
@Override
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
// 解析字节数组
EBikeMessageCmd12 message = (EBikeMessageCmd12) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
EBikeMessageCmd12 message = new EBikeMessageCmd12(dataProtocol.getBytes());
log.info("主机 获取服务器时间:{}", JSON.toJSONString(message));
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);

View File

@@ -8,7 +8,6 @@ import com.jsowell.common.enums.ebike.PortStatusEnum;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.EBikeOperateFactory;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd06;
import com.jsowell.pile.service.PileBasicInfoService;
@@ -47,19 +46,14 @@ public class PowerHeartbeatHandler extends AbstractEBikeHandler {
@Override
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
// 解析字节数组
EBikeMessageCmd06 message = (EBikeMessageCmd06) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
EBikeMessageCmd06 message = new EBikeMessageCmd06(dataProtocol.getBytes());
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
EBikeMessageCmd06.PowerHeartbeat powerHeartbeat = message.getPowerHeartbeat();
log.info("端口充电时功率心跳包:{}", JSON.toJSONString(message));
// 更新枪口状态
updatePileStatus(message);
// 保存实时监控数据
saveRealTimeMonitorData(message);
return getResult(dataProtocol, Constants.zeroByteArray);
}
@@ -68,16 +62,15 @@ public class PowerHeartbeatHandler extends AbstractEBikeHandler {
* @param message
*/
private void saveRealTimeMonitorData(EBikeMessageCmd06 message) {
EBikeMessageCmd06.PowerHeartbeat powerHeartbeat = message.getPowerHeartbeat();
// 组装数据
RealTimeMonitorData realTimeMonitorData = new RealTimeMonitorData();
realTimeMonitorData.setPileSn(message.getPhysicalId() + "");
realTimeMonitorData.setConnectorCode(powerHeartbeat.getPort());
realTimeMonitorData.setConnectorCode(message.getPort());
realTimeMonitorData.setPileConnectorCode(realTimeMonitorData.getPileSn() + realTimeMonitorData.getConnectorCode());
realTimeMonitorData.setTransactionCode(powerHeartbeat.getOrderCode());
realTimeMonitorData.setConnectorStatus(powerHeartbeat.getPortStatus());
realTimeMonitorData.setOutputVoltage(powerHeartbeat.getVoltage());
realTimeMonitorData.setOutputCurrent(powerHeartbeat.getCurrent());
realTimeMonitorData.setTransactionCode(message.getOrderCode());
realTimeMonitorData.setConnectorStatus(message.getPortStatus());
realTimeMonitorData.setOutputVoltage(message.getVoltage());
realTimeMonitorData.setOutputCurrent(message.getCurrent());
// realTimeMonitorData.setOutputPower("");
realTimeMonitorData.setDateTime(DateUtils.getDateTime());
@@ -90,9 +83,8 @@ public class PowerHeartbeatHandler extends AbstractEBikeHandler {
*/
private void updatePileStatus(EBikeMessageCmd06 message) {
String pileSn = message.getPhysicalId() + "";
EBikeMessageCmd06.PowerHeartbeat powerHeartbeat = message.getPowerHeartbeat();
String connectorCode = powerHeartbeat.getPort();
String portStatus = powerHeartbeat.getPortStatus();
String connectorCode = message.getPort();
String portStatus = message.getPortStatus();
pileConnectorInfoService.updateConnectorStatus(pileSn + connectorCode, PortStatusEnum.eBikeStatusTransformDBStatus(portStatus));
}

View File

@@ -5,7 +5,6 @@ import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ebike.EBikeDataProtocol;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.factory.EBikeOperateFactory;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd20;
import com.jsowell.pile.service.PileBasicInfoService;
@@ -41,10 +40,9 @@ public class RegistrationHandler extends AbstractEBikeHandler {
@Override
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
// 解析字节数组
EBikeMessageCmd20 message = (EBikeMessageCmd20) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
EBikeMessageCmd20 message = new EBikeMessageCmd20(dataProtocol.getBytes());
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister();
log.info("设备注册包:{}", JSON.toJSONString(message));
pileBasicInfoService.registrationEBikePile(message);
return getResult(dataProtocol, Constants.zeroByteArray);

View File

@@ -11,7 +11,6 @@ import com.jsowell.common.util.YKCUtils;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.netty.factory.EBikeOperateFactory;
import com.jsowell.pile.domain.OrderBasicInfo;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.EBikeCommandEnum;
import com.jsowell.pile.domain.ebike.deviceupload.EBikeMessageCmd03;
import com.jsowell.pile.service.OrderBasicInfoService;
@@ -58,13 +57,11 @@ public class SettlementUploadHandler extends AbstractEBikeHandler {
@Override
public byte[] supplyProcess(EBikeDataProtocol dataProtocol, ChannelHandlerContext ctx) {
// 解析字节数组
EBikeMessageCmd03 message = (EBikeMessageCmd03) AbsEBikeMessage.parseMessage(dataProtocol.getBytes());
EBikeMessageCmd03 message = new EBikeMessageCmd03(dataProtocol.getBytes());
// 保存时间
saveLastTimeAndCheckChannel(message.getPhysicalId() + "", ctx);
EBikeMessageCmd03.SettlementInfo settlementInfo = message.getSettlementInfo();
log.info("结算消费信息上传:{}", JSON.toJSONString(message));
String transactionCode = settlementInfo.getOrderNumber();
String transactionCode = message.getOrderNumber();
// 处理订单加锁/结算电单车订单
String lockKey = "settle_order_" + transactionCode;
String uuid = IdUtils.fastUUID();
@@ -81,7 +78,6 @@ public class SettlementUploadHandler extends AbstractEBikeHandler {
redisCache.unLock(lockKey);
}
}
// 返回结果
return getResult(dataProtocol, Constants.zeroByteArray);
}
@@ -90,13 +86,12 @@ public class SettlementUploadHandler extends AbstractEBikeHandler {
* 收到交易记录 处理订单
*/
private void processOrder(EBikeMessageCmd03 message) {
EBikeMessageCmd03.SettlementInfo settlementInfo = message.getSettlementInfo();
String transactionCode = settlementInfo.getOrderNumber();
String transactionCode = message.getOrderNumber();
// 根据交易流水号查询订单信息
OrderBasicInfo orderBasicInfo = orderBasicInfoService.getOrderInfoByTransactionCode(transactionCode);
if (orderBasicInfo != null) {
// 平台存在订单
int stopReason = settlementInfo.getStopReason();
int stopReason = message.getStopReason();
orderBasicInfo.setReason(EBikeChargingStopReasonEnum.getMsgByCode(stopReason));
// 如果订单状态为 异常,则改为 待结算
if (StringUtils.equals(OrderStatusEnum.ABNORMAL.getValue(), orderBasicInfo.getOrderStatus())) {

View File

@@ -1,115 +0,0 @@
package com.jsowell.pile.domain.ebike;
import com.alibaba.fastjson2.JSON;
import com.jsowell.common.YouDianUtils;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.deviceupload.*;
import lombok.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class AbsEBikeMessage {
protected String header; // 包头 (3字节)
protected int length; // 长度 (2字节)
protected int physicalId; // 物理ID (4字节)
protected int messageId; // 消息ID (2字节)
protected String command; // 命令 (1字节)
protected Object payload; // 数据 (n字节)
protected int checksum; // 校验 (2字节)
public void parsePayload(byte[] dataBytes) {
};
private static AbsEBikeMessage createMessageInstance(String command, String header, int length, int physicalId, int messageId, int checksum, byte[] dataBytes) {
switch (command) {
case "02":
return new EBikeMessageCmd02(header, length, physicalId, messageId, command, null, checksum, new EBikeMessageCmd02.CreditCardInfo(dataBytes));
case "03":
return new EBikeMessageCmd03(header, length, physicalId, messageId, command, null, checksum, new EBikeMessageCmd03.SettlementInfo(dataBytes));
case "04":
return new EBikeMessageCmd04(header, length, physicalId, messageId, command, null, checksum, new EBikeMessageCmd04.ConfirmOrder(dataBytes));
case "06":
return new EBikeMessageCmd06(header, length, physicalId, messageId, command, null, checksum, new EBikeMessageCmd06.PowerHeartbeat(dataBytes));
case "12":
return new EBikeMessageCmd12(header, length, physicalId, messageId, command, null, checksum);
case "20":
return new EBikeMessageCmd20(header, length, physicalId, messageId, command, null, checksum, new EBikeMessageCmd20.DeviceRegister(dataBytes));
case "21":
return new EBikeMessageCmd21(header, length, physicalId, messageId, command, null, checksum, new EBikeMessageCmd21.DeviceHeartbeat(dataBytes));
case "22":
return new EBikeMessageCmd22(header, length, physicalId, messageId, command, null, checksum);
default:
throw new IllegalArgumentException("Unsupported command: " + command);
}
}
public static AbsEBikeMessage parseMessage(byte[] messageBytes) {
if (messageBytes == null || messageBytes.length < 14 || messageBytes.length > 256) {
throw new IllegalArgumentException("Invalid message bytes");
}
try {
// 读取包头
byte[] headerBytes = Arrays.copyOfRange(messageBytes, 0, 3);
String header = new String(headerBytes, StandardCharsets.UTF_8);
// 读取长度
byte[] lengthBytes = Arrays.copyOfRange(messageBytes, 3, 5);
int length = BytesUtil.bytesToIntLittle(lengthBytes);
// 验证长度
if (length != (messageBytes.length - 5)) {
throw new IllegalArgumentException("Invalid message length");
}
// 读取物理ID
byte[] physicalIdBytes = Arrays.copyOfRange(messageBytes, 5, 9);
int physicalId = YouDianUtils.convertToPhysicalId(physicalIdBytes);
// 读取消息ID
byte[] messageIdBytes = Arrays.copyOfRange(messageBytes, 9, 11);
int messageId = BytesUtil.bytesToIntLittle(messageIdBytes);
// 读取命令
byte commandByte = messageBytes[11];
String command = BytesUtil.bcd2StrLittle(new byte[]{commandByte});
// 读取数据
byte[] dataBytes = Arrays.copyOfRange(messageBytes, 12, messageBytes.length - 2);
// 读取校验
byte[] checksumBytes = Arrays.copyOfRange(messageBytes, messageBytes.length - 2, messageBytes.length);
int checksum = BytesUtil.bytesToIntLittle(checksumBytes);
// 根据命令创建相应的子类实例
AbsEBikeMessage parsedMessage = createMessageInstance(command, header, length, physicalId, messageId, checksum, dataBytes);
parsedMessage.parsePayload(dataBytes);
return parsedMessage;
} catch (Exception e) {
throw new IllegalArgumentException("Error parsing message", e);
}
}
public byte[] getMessageBytes() {
return null;
};
public static void main(String[] args) {
String s = "444e593200198bca0782000600018e030700015a0b6b0b190b480b1327388101240913141035606593918397006e0b73083f055f002d0b";
String msg82 = "44 4E 59 26 00 3B 37 AB 04 02 00 82 00 64 01 00 00 01 01 00 00 12 34 56 78 12 34 56 78 12 34 56 78 12 34 56 78 80 70 88 13 F8 08";
s = s.replace(" ", "");
byte[] messageBytes = BytesUtil.hexStringToByteArray(s);
AbsEBikeMessage absEBikeMessage = parseMessage(messageBytes);
System.out.println(JSON.toJSONString(absEBikeMessage));
}
}

View File

@@ -68,4 +68,8 @@ public class AbsEBikeMessage2 {
byte[] checksumBytes = Arrays.copyOfRange(messageBytes, messageBytes.length - 2, messageBytes.length);
this.checksum = BytesUtil.bytesToIntLittle(checksumBytes);
}
public byte[] getMessageBytes() {
return null;
};
}

View File

@@ -24,7 +24,7 @@ public enum EBikeCommandEnum {
REMOTE_CONTROL_COMMAND(0x82, "服务器开始、停止充电操作", EBikeMessageCmd82.class),
;
EBikeCommandEnum(int code, String desc, Class<? extends AbsEBikeMessage> msgClass) {
EBikeCommandEnum(int code, String desc, Class<? extends AbsEBikeMessage2> msgClass) {
this.code = code;
this.desc = desc;
this.msgClass = msgClass;
@@ -32,7 +32,7 @@ public enum EBikeCommandEnum {
private final int code; // 帧类型code
private final String desc; // 帧类型名称
private final Class<? extends AbsEBikeMessage> msgClass;
private final Class<? extends AbsEBikeMessage2> msgClass;
public int getCode() {
return code;
@@ -42,7 +42,7 @@ public enum EBikeCommandEnum {
return desc;
}
public Class<? extends AbsEBikeMessage> getMsgClass() {
public Class<? extends AbsEBikeMessage2> getMsgClass() {
return msgClass;
}

View File

@@ -1,81 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* 刷卡操作02指令
*/
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd02 extends AbsEBikeMessage2 {
/**
* 卡片ID
*/
private String cardId;
/**
* 卡片类型
*/
private String cardType;
/**
* 端口号
*/
private String portNumber;
/**
* 余额卡内金额
*/
private String cardBalance;
/**
* 时间戳
*/
// private String timestamp;
/**
* 卡号2字节数
*/
private int card2Length;
/**
* 卡号2
*/
private String card2Code;
public Cmd02(byte[] messageBytes) {
super(messageBytes);
int startIndex = 12;
int length = 4;
this.cardId = BytesUtil.bcd2Str(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
this.cardType = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.cardBalance = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
// length = 4;
// this.timestamp = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
if (messageBytes.length > startIndex) {
startIndex += length;
length = 1;
card2Length = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
this.card2Code = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
}
}
}

View File

@@ -1,68 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.YouDianUtils;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd03 extends AbsEBikeMessage2 {
private int chargingTime; // 充电时长, 单位:"秒"
private int maxPower; // 最大功率, 单位:"0.1W"
private int consumedEnergy; // 耗电量, 单位:"0.01度"
private String portNumber; // 端口号
private int startMode; // 在线/离线启动/验证码
private int cardNumberOrVerificationCode; // 卡号/验证码
private int stopReason; // 停止原因
private String orderNumber; // 订单编号
private int secondMaxPower; // 第二最大功率
// private String timestamp; // 时间戳 上发指令当时的时间,有时候不准确,该字段属于调试使用,服务器无需关心此字段
// private String placeholderDuration; // 占位时长 充电柜专用,其他设备忽略此字段 表示充满后占用设备的时长,单位为分钟
public Cmd03(byte[] messageBytes) {
super(messageBytes);
int startIndex = 12;
int length = 2;
this.chargingTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.maxPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.consumedEnergy = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.portNumber = YouDianUtils.convertPortNumberToString(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)));
startIndex += length;
length = 1;
this.startMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 4;
this.cardNumberOrVerificationCode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.stopReason = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 16;
this.orderNumber = BytesUtil.bcd2Str(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.secondMaxPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
// this.timestamp = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(messageBytes, 31, 35)) + "";
// this.placeholderDuration = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(messageBytes, 35, 37)) + "";
}
}

View File

@@ -1,61 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd04 extends AbsEBikeMessage2 {
/**
* 端口号
*/
private String portNumber;
/**
* 在线/离线启动
*/
private String startMode;
/**
* 卡片ID
*/
private String cardId;
/**
* 充电时长
*/
private String chargingTime;
/**
* 订单编号
*/
private String orderCode;
public Cmd04(byte[] messageBytes) {
super(messageBytes);
int startIndex = 12;
int length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
this.startMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 4;
this.cardId = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.chargingTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 16;
this.orderCode = BytesUtil.bcd2StrLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
}
}

View File

@@ -1,187 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.YouDianUtils;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.math.BigDecimal;
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd06 extends AbsEBikeMessage2 {
/**
* 端口号当前充电的端口号。注00表示1号端口01表示2号端口; port+1为实际端口
*/
private String port;
/**
* 各端口状态: 1=充电中, 2=已扫码暂未检测到功率等待插入充电器充电柜专有如单车桩出现此值为出错值请忽略3=有充电器但未充电已充满电5=浮充,其他值=出错值请忽略
*/
private String portStatus;
/**
* 充电时长:开始充电到当前为止,已经充电多长时间
*/
private String chargingTime;
/**
* 当前订单累计电量:当前端口的订单,开始充电到当前为止,已经消耗的电量
*/
private String totalUsedElectricity;
/**
* 在线/离线启动:=0表示启动时处于离线状态 =1表示启动时处于在线状态 3=验证码启动(仅支持带按键和屏幕的机型)
*/
private String startMode;
/**
* 实时功率:心跳包发送时的当前功率
*/
private String realTimePower;
/**
* 心跳包期间最大功率:心跳包期间出现过的最大功率
*/
private String maxPower;
/**
* 心跳包期间最小功率:心跳包期间出现过的最小功率
*/
private String minPower;
/**
* 心跳包期间平均功率:心跳包期间出现过的平均功率
*/
private String avgPower;
/**
* 订单编号:当前充电的订单编号
*/
private String orderCode;
/**
* 该时间段内消耗电量此数据需除以4800后才是真实的电量该字段属于调试使用服务器无需关心此字段
*/
private String timePeriodElectricity;
/**
* 峰值功率:整个充电过程中出现过的最大功率,有些版本无此字段
*/
private String peakPower;
/**
* 设备的当前电压
*/
private String voltage;
/**
* 设备的当前电流,可以计量芯片采集也可以通过计算得出,0.001A为单位1000表示1A电流
*/
private String current;
/**
* 设备的当前环境温度,仅针对有此功能的机型
*/
private String ambientTemperature;
/**
* 端口温度,仅针对有此功能的机型
*/
private String portTemperature;
/**
* 上发指令当时的时间,有时候不准确,该字段属于调试使用,服务器无需关心此字段
*/
// private String timestamp;
/**
* 占位时长:(充电柜专用,其他设备忽略此字段)表示充满后占用设备的时长,单位为分钟
*/
private String occupancyTime;
public Cmd06(byte[] messageBytes) {
super(messageBytes);
int startIndex = 12;
int length = 1;
this.port = YouDianUtils.convertPortNumberToString(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)));
startIndex += length;
length = 1;
this.portStatus = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.chargingTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.totalUsedElectricity = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.01")).toString();
startIndex += length;
length = 1;
this.startMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.realTimePower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.maxPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.minPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.avgPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 16;
this.orderCode = BytesUtil.bcd2Str(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.timePeriodElectricity = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.peakPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.voltage = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.current = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.001")).toString();
startIndex += length;
length = 1;
this.ambientTemperature = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.subtract(new BigDecimal("65")).toString();
startIndex += length;
length = 1;
this.portTemperature = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.subtract(new BigDecimal("65")).toString();
startIndex += length;
length = 2;
this.occupancyTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
}
}

View File

@@ -1,13 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd11 extends AbsEBikeMessage2 {
}

View File

@@ -1,12 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd12 extends AbsEBikeMessage2 {
}

View File

@@ -1,73 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.math.BigDecimal;
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd20 extends AbsEBikeMessage2 {
/**
* 固件版本如100则表示V1.00版本
*/
private String firmwareVersion;
/**
* 端口数量 表示设备总共有多少个端口
*/
private int portNumber;
/**
* 虚拟ID需要内部组网的设备的本地地址如485、LORA系列如不需组网的设备默认为00
*/
private String virtualId;
/**
* 设备类型: 见01指令中的设备类型表
*/
private String deviceType;
/**
* 工作模式第0位0=联网1=刷卡。第1位0=RN82091=BL0939。第2位0=无短路预检1=有短路预检。第3位0=光耦检测模式1=带灯模式。
*/
private String workMode;
/**
* 电源板版本号电源板的固件版本号如没有电源板的机型则为0
*/
private String powerBoardVersion;
public Cmd20(byte[] messageBytes) {
super(messageBytes);
int startIndex = 12;
int length = 2;
this.firmwareVersion = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.virtualId = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
this.deviceType = BytesUtil.printHexBinary(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.workMode = BytesUtil.bcd2StrLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.powerBoardVersion = BytesUtil.bcd2StrLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
}
}

View File

@@ -1,91 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.google.common.collect.Lists;
import com.jsowell.common.enums.ebike.PortStatusEnum;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.math.BigDecimal;
import java.util.List;
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd21 extends AbsEBikeMessage2 {
/**
* 电压:设备的当前电压(打包发送心跳包指令时的当前时间点的实时电压)
* 2024年8月26日15点02分 已经转为标准单位V
*/
private String voltage;
/**
* 端口数量:表示设备总共有多少个端口,和后面的“端口状态”配套
*/
private int portNumber;
/**
* 注4、各端口状态一个字节表示一个端口和“端口数量”匹配
* 如端口数量是16则“各端口状态”为16字节
* 每个字节表示的意思,
* 0=空闲1=充电中2=有充电器但未充电用户未启动充电3=有充电器但未充电(已充满电) 4=该路无法计量5=浮充6=存储器损坏,
* 7插座弹片卡住故障8接触不良或保险丝烧断故障9(算法-继电器粘连)0x0A=霍尔开关损坏(即插入检测传感器)。
* 0x0B=(预检-继电器坏或保险丝断0x0D=(预检-负载短路。0x0E=(过滤性预检-继电器粘连),0x0F=(刷卡芯片损坏故障)0x10=(检测电路故障)
*/
private List<String> portStatus;
private List<String> statusDescList;
/**
* 信号强度指分机与主机之间的无线信号强度如LORA信号。00则为有线组网或无信号强度功能
*/
private String rssi;
/**
* 当前环境温度表示当前设备内的温度可能和真正的当前环境温度有一定的误差如00则表示无此功能
*/
private String temperature;
public Cmd21(byte[] messageBytes) {
super(messageBytes);
// 读取结果
int startIndex = 12;
int length = 2;
this.voltage = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = this.portNumber;
byte[] statusBytes = BytesUtil.copyBytes(messageBytes, startIndex, length);
// 解析
List<String> statusList = Lists.newArrayList();
List<String> statusDescList = Lists.newArrayList();
for (byte statusByte : statusBytes) {
int status = BytesUtil.bytesToIntLittle(new byte[]{statusByte});
statusList.add(String.valueOf(status));
statusDescList.add(PortStatusEnum.getDescriptionByValue(status));
}
this.portStatus = statusList;
this.statusDescList = statusDescList;
startIndex += length;
length = 1;
this.rssi = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
int i = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
if (i > 65) {
i = i - 65;
}
this.temperature = i + "";
}
}

View File

@@ -1,12 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd22 extends AbsEBikeMessage2 {
}

View File

@@ -1,12 +0,0 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString(callSuper = true)
public class Cmd35 extends AbsEBikeMessage2 {
}

View File

@@ -1,101 +1,81 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import java.util.Arrays;
import lombok.ToString;
/**
* 刷卡操作02指令
* 特别注意上报的端口号如果不是FF为端口请求充电服务器需应答刷卡指令后如果服务器需要给当前端口启动充电的需要下发82指令来启动充电
* CreditCard
*/
public class EBikeMessageCmd02 extends AbsEBikeMessage {
@Getter
@Setter
@ToString(callSuper = true)
public class EBikeMessageCmd02 extends AbsEBikeMessage2 {
/**
* 卡片ID
*/
private String cardId;
private CreditCardInfo creditCardInfo;
/**
* 卡片类型
*/
private String cardType;
public EBikeMessageCmd02(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum, CreditCardInfo creditCardInfo) {
super(header, length, physicalId, messageId, command, payload, checksum);
this.creditCardInfo = creditCardInfo;
}
/**
* 端口号
*/
private String portNumber;
@Override
public void parsePayload(byte[] dataBytes) {
this.creditCardInfo = new CreditCardInfo(dataBytes);
}
/**
* 余额卡内金额
*/
private String cardBalance;
@Override
public byte[] getMessageBytes() {
return null;
}
/**
* 时间戳
*/
// private String timestamp;
public CreditCardInfo getCreditCardInfo() {
return creditCardInfo;
}
/**
* 卡号2字节数
*/
private int card2Length;
@Getter
@Setter
public static class CreditCardInfo {
/**
* 卡片ID
*/
private String cardId;
/**
* 卡号2
*/
private String card2Code;
/**
* 卡片类型
*/
private String cardType;
public EBikeMessageCmd02(byte[] messageBytes) {
super(messageBytes);
/**
* 端口号
*/
private String portNumber;
int startIndex = 12;
int length = 4;
this.cardId = BytesUtil.bcd2Str(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
/**
* 余额卡内金额
*/
private String cardBalance;
startIndex += length;
length = 1;
this.cardType = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
/**
* 时间戳
*/
// private String timestamp;
startIndex += length;
length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
/**
* 卡号2字节数
*/
private int card2Length;
startIndex += length;
length = 2;
this.cardBalance = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
/**
* 卡号2
*/
private String card2Code;
public CreditCardInfo(byte[] dataBytes) {
int startIndex = 0;
int length = 4;
this.cardId = BytesUtil.bcd2Str(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
// length = 4;
// this.timestamp = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
if (messageBytes.length > startIndex) {
startIndex += length;
length = 1;
this.cardType = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
card2Length = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
length = 2;
this.cardBalance = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
// length = 4;
// this.timestamp = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
if (dataBytes.length > startIndex) {
length = 1;
card2Length = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length));
this.card2Code = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, card2Length)) + "";
}
this.card2Code = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
}
}
}
}

View File

@@ -2,89 +2,67 @@ package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.YouDianUtils;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import lombok.Data;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* 结算消费信息上传03指令
*/
public class EBikeMessageCmd03 extends AbsEBikeMessage {
@Getter
@Setter
@ToString(callSuper = true)
public class EBikeMessageCmd03 extends AbsEBikeMessage2 {
private int chargingTime; // 充电时长, 单位:"秒"
private int maxPower; // 最大功率, 单位:"0.1W"
private int consumedEnergy; // 耗电量, 单位:"0.01度"
private String portNumber; // 端口号
private int startMode; // 在线/离线启动/验证码
private int cardNumberOrVerificationCode; // 卡号/验证码
private int stopReason; // 停止原因
private String orderNumber; // 订单编号
private int secondMaxPower; // 第二最大功率
// private String timestamp; // 时间戳 上发指令当时的时间,有时候不准确,该字段属于调试使用,服务器无需关心此字段
// private String placeholderDuration; // 占位时长 充电柜专用,其他设备忽略此字段 表示充满后占用设备的时长,单位为分钟
private SettlementInfo settlementInfo;
public EBikeMessageCmd03(byte[] messageBytes) {
super(messageBytes);
public EBikeMessageCmd03(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum, SettlementInfo settlementInfo) {
super(header, length, physicalId, messageId, command, payload, checksum);
this.settlementInfo = settlementInfo;
int startIndex = 12;
int length = 2;
this.chargingTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.maxPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.consumedEnergy = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.portNumber = YouDianUtils.convertPortNumberToString(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)));
startIndex += length;
length = 1;
this.startMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 4;
this.cardNumberOrVerificationCode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.stopReason = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 16;
this.orderNumber = BytesUtil.bcd2Str(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.secondMaxPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
// this.timestamp = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(messageBytes, 31, 35)) + "";
// this.placeholderDuration = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(messageBytes, 35, 37)) + "";
}
@Override
public void parsePayload(byte[] dataBytes) {
this.settlementInfo = new SettlementInfo(dataBytes);
}
@Override
public byte[] getMessageBytes() {
return new byte[0];
}
public SettlementInfo getSettlementInfo() {
return settlementInfo;
}
@Data
public static class SettlementInfo {
private int chargingTime; // 充电时长, 单位:"秒"
private int maxPower; // 最大功率, 单位:"0.1W"
private int consumedEnergy; // 耗电量, 单位:"0.01度"
private String portNumber; // 端口号
private int startMode; // 在线/离线启动/验证码
private int cardNumberOrVerificationCode; // 卡号/验证码
private int stopReason; // 停止原因
private String orderNumber; // 订单编号
private int secondMaxPower; // 第二最大功率
// private String timestamp; // 时间戳 上发指令当时的时间,有时候不准确,该字段属于调试使用,服务器无需关心此字段
// private String placeholderDuration; // 占位时长 充电柜专用,其他设备忽略此字段 表示充满后占用设备的时长,单位为分钟
public SettlementInfo(byte[] dataBytes) {
int startIndex = 0;
int length = 2;
this.chargingTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length));
startIndex += length;
length = 2;
this.maxPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length));
startIndex += length;
length = 2;
this.consumedEnergy = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length));
startIndex += length;
length = 1;
this.portNumber = YouDianUtils.convertPortNumberToString(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)));
startIndex += length;
length = 1;
this.startMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length));
startIndex += length;
length = 4;
this.cardNumberOrVerificationCode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length));
startIndex += length;
length = 1;
this.stopReason = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length));
startIndex += length;
length = 16;
this.orderNumber = BytesUtil.bcd2Str(BytesUtil.copyBytes(dataBytes, startIndex, length));
startIndex += length;
length = 2;
this.secondMaxPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length));
// this.timestamp = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 31, 35)) + "";
// this.placeholderDuration = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 35, 37)) + "";
}
}
}
}

View File

@@ -1,71 +1,61 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import lombok.Data;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.Arrays;
@Getter
@Setter
@ToString(callSuper = true)
public class EBikeMessageCmd04 extends AbsEBikeMessage2 {
/**
* 端口号
*/
private String portNumber;
/**
* 充电端口订单确认04指令
* 这是老版本指令和06相对应有06指令时无此命令2019年6月份后生产的机型已无此指令
*/
public class EBikeMessageCmd04 extends AbsEBikeMessage {
/**
* 在线/离线启动
*/
private String startMode;
private ConfirmOrder confirmOrder;
/**
* 卡片ID
*/
private String cardId;
public EBikeMessageCmd04(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum, ConfirmOrder confirmOrder) {
super(header, length, physicalId, messageId, command, payload, checksum);
this.confirmOrder = confirmOrder;
/**
* 充电时长
*/
private String chargingTime;
/**
* 订单编号
*/
private String orderCode;
public EBikeMessageCmd04(byte[] messageBytes) {
super(messageBytes);
int startIndex = 12;
int length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
this.startMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 4;
this.cardId = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.chargingTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 16;
this.orderCode = BytesUtil.bcd2StrLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
}
@Override
public void parsePayload(byte[] dataBytes) {
this.confirmOrder = new ConfirmOrder(dataBytes);
}
@Override
public byte[] getMessageBytes() {
return new byte[0];
}
public ConfirmOrder getSettlementInfo() {
return confirmOrder;
}
@Data
public static class ConfirmOrder {
/**
* 端口号
*/
private String portNumber;
/**
* 在线/离线启动
*/
private String startMode;
/**
* 卡片ID
*/
private String cardId;
/**
* 充电时长
*/
private String chargingTime;
/**
* 订单编号
*/
private String orderCode;
public ConfirmOrder(byte[] dataBytes) {
this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 0, 1)) + "";
this.startMode = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 1, 2)) + "";
this.cardId = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 2, 6)) + "";
this.chargingTime = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 6, 8)) + "";
this.orderCode = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 8, 24));
}
}
}
}

View File

@@ -2,217 +2,186 @@ package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.YouDianUtils;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.math.BigDecimal;
/**
* 端口充电时功率心跳包06指令
* 这是新版本指令和04相对应有04指令时无此命令
* 此命令设备开始充电后82命令应答后每隔设5分钟发送1次无重发机制 充电结束后即停止发送
*/
public class EBikeMessageCmd06 extends AbsEBikeMessage {
private PowerHeartbeat powerHeartbeat;
public EBikeMessageCmd06(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum, PowerHeartbeat powerHeartbeat) {
super(header, length, physicalId, messageId, command, payload, checksum);
this.powerHeartbeat = powerHeartbeat;
}
@Override
public void parsePayload(byte[] dataBytes) {
this.powerHeartbeat = new PowerHeartbeat(dataBytes);
}
@Override
public byte[] getMessageBytes() {
return new byte[0];
}
public PowerHeartbeat getPowerHeartbeat() {
return powerHeartbeat;
}
@Getter
@Setter
@ToString(callSuper = true)
public class EBikeMessageCmd06 extends AbsEBikeMessage2 {
/**
* 端口号当前充电的端口号。注00表示1号端口01表示2号端口; port+1为实际端口
*/
private String port;
/**
* 功率心跳包
* 各端口状态: 1=充电中, 2=已扫码暂未检测到功率等待插入充电器充电柜专有如单车桩出现此值为出错值请忽略3=有充电器但未充电已充满电5=浮充,其他值=出错值请忽略
*/
@Getter
@Setter
public static class PowerHeartbeat {
/**
* 端口号当前充电的端口号。注00表示1号端口01表示2号端口; port+1为实际端口
*/
private String port;
private String portStatus;
/**
* 各端口状态: 1=充电中, 2=已扫码暂未检测到功率等待插入充电器充电柜专有如单车桩出现此值为出错值请忽略3=有充电器但未充电已充满电5=浮充,其他值=出错值请忽略
*/
private String portStatus;
/**
* 充电时长:开始充电到当前为止,已经充电多长时间
*/
private String chargingTime;
/**
* 充电时长:开始充电到当前为止,已经充电多长时间
*/
private String chargingTime;
/**
* 当前订单累计电量:当前端口的订单,开始充电到当前为止,已经消耗的电量
*/
private String totalUsedElectricity;
/**
* 当前订单累计电量:当前端口的订单,开始充电到当前为止,已经消耗的电量
*/
private String totalUsedElectricity;
/**
* 在线/离线启动:=0表示启动时处于离线状态 =1表示启动时处于在线状态 3=验证码启动(仅支持带按键和屏幕的机型)
*/
private String startMode;
/**
* 在线/离线启动:=0表示启动时处于离线状态 =1表示启动时处于在线状态 3=验证码启动(仅支持带按键和屏幕的机型)
*/
private String startMode;
/**
* 实时功率:心跳包发送时的当前功率
*/
private String realTimePower;
/**
* 实时功率:心跳包发送时的当前功率
*/
private String realTimePower;
/**
* 心跳包期间最大功率:心跳包期间出现过的最大功率
*/
private String maxPower;
/**
* 心跳包期间最功率:心跳包期间出现过的最功率
*/
private String maxPower;
/**
* 心跳包期间最功率:心跳包期间出现过的最功率
*/
private String minPower;
/**
* 心跳包期间最小功率:心跳包期间出现过的最小功率
*/
private String minPower;
/**
* 心跳包期间平均功率:心跳包期间出现过的平均功率
*/
private String avgPower;
/**
* 心跳包期间平均功率:心跳包期间出现过的平均功率
*/
private String avgPower;
/**
* 订单编号:当前充电的订单编号
*/
private String orderCode;
/**
* 订单编号:当前充电的订单编号
*/
private String orderCode;
/**
* 该时间段内消耗电量此数据需除以4800后才是真实的电量该字段属于调试使用服务器无需关心此字段
*/
private String timePeriodElectricity;
/**
* 该时间段内消耗电量此数据需除以4800后才是真实的电量该字段属于调试使用服务器无需关心此字段
*/
private String timePeriodElectricity;
/**
* 峰值功率:整个充电过程中出现过的最大功率,有些版本无此字段
*/
private String peakPower;
/**
* 峰值功率:整个充电过程中出现过的最大功率,有些版本无此字段
*/
private String peakPower;
/**
* 设备的当前电压
*/
private String voltage;
/**
* 设备的当前电
*/
private String voltage;
/**
* 设备的当前电流,可以计量芯片采集也可以通过计算得出,0.001A为单位1000表示1A电流
*/
private String current;
/**
* 设备的当前电流,可以计量芯片采集也可以通过计算得出,0.001A为单位1000表示1A电流
*/
private String current;
/**
* 设备的当前环境温度,仅针对有此功能的机型
*/
private String ambientTemperature;
/**
* 设备的当前环境温度,仅针对有此功能的机型
*/
private String ambientTemperature;
/**
* 端口温度,仅针对有此功能的机型
*/
private String portTemperature;
/**
* 端口温度,仅针对有此功能的机型
*/
private String portTemperature;
/**
* 上发指令当时的时间,有时候不准确,该字段属于调试使用,服务器无需关心此字段
*/
// private String timestamp;
/**
* 上发指令当时的时间,有时候不准确,该字段属于调试使用,服务器无需关心此字段
*/
// private String timestamp;
/**
* 占位时长:(充电柜专用,其他设备忽略此字段)表示充满后占用设备的时长,单位为分钟
*/
private String occupancyTime;
/**
* 占位时长:(充电柜专用,其他设备忽略此字段)表示充满后占用设备的时长,单位为分钟
*/
private String occupancyTime;
public EBikeMessageCmd06(byte[] messageBytes) {
super(messageBytes);
int startIndex = 12;
int length = 1;
this.port = YouDianUtils.convertPortNumberToString(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)));
public PowerHeartbeat(byte[] dataBytes) {
int startIndex = 0;
int length = 1;
this.port = YouDianUtils.convertPortNumberToString(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)));
startIndex += length;
length = 1;
this.portStatus = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
// this.portStatus = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
this.portStatus = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.chargingTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.chargingTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.totalUsedElectricity = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.01")).toString();
startIndex += length;
length = 2;
this.totalUsedElectricity = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.01")).toString();
startIndex += length;
length = 1;
this.startMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
this.startMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.realTimePower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.realTimePower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.maxPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.maxPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.minPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.minPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.avgPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.avgPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 16;
this.orderCode = BytesUtil.bcd2Str(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 16;
this.orderCode = BytesUtil.bcd2Str(BytesUtil.copyBytes(dataBytes, startIndex, length));
startIndex += length;
length = 2;
this.timePeriodElectricity = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.timePeriodElectricity = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)) + "";
startIndex += length;
length = 2;
this.peakPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.peakPower = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.voltage = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.voltage = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 2;
this.current = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.001")).toString();
startIndex += length;
length = 2;
this.current = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.multiply(new BigDecimal("0.001")).toString();
startIndex += length;
length = 1;
this.ambientTemperature = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.subtract(new BigDecimal("65")).toString();
startIndex += length;
length = 1;
this.ambientTemperature = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.subtract(new BigDecimal("65")).toString();
startIndex += length;
length = 1;
this.portTemperature = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.subtract(new BigDecimal("65")).toString();
startIndex += length;
length = 1;
this.portTemperature = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)))
.subtract(new BigDecimal("65")).toString();
startIndex += length;
length = 2;
this.occupancyTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(dataBytes, startIndex, length)) + "";
}
startIndex += length;
length = 2;
this.occupancyTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
}
}
}

View File

@@ -1,6 +1,16 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
public class EBikeMessageCmd11 extends AbsEBikeMessage {
@Getter
@Setter
@ToString(callSuper = true)
public class EBikeMessageCmd11 extends AbsEBikeMessage2 {
public EBikeMessageCmd11(byte[] messageBytes) {
super(messageBytes);
}
}

View File

@@ -1,34 +1,16 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.util.bean.SerializationUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* 主机获取服务器时间0x12
* 此命令主机每次上电后就会发送直至服务器应答后就停止发送。如服务器无应答则每隔3分钟发送一次请求
* 每12小时从服务器获取一次时间如服务器不应答则每隔3分钟发送一次请求
* 不带RTC模块的主机不会发送此命令
* DE 5C A9 5F转小端模式=0x5FA95CDE=1604934878=2020-11-09 23:14:38
*/
@Getter
@Setter
public class EBikeMessageCmd12 extends AbsEBikeMessage {
@ToString(callSuper = true)
public class EBikeMessageCmd12 extends AbsEBikeMessage2 {
public EBikeMessageCmd12(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum) {
super(header, length, physicalId, messageId, command, payload, checksum);
public EBikeMessageCmd12(byte[] messageBytes) {
super(messageBytes);
}
@Override
public void parsePayload(byte[] dataBytes) {
}
@Override
public byte[] getMessageBytes() {
byte[] serialize = SerializationUtil.serialize(this);
return serialize;
}
}
}

View File

@@ -1,78 +1,73 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import lombok.Data;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.Arrays;
import java.math.BigDecimal;
/**
* 设备注册包20指令
*/
public class EBikeMessageCmd20 extends AbsEBikeMessage {
@Getter
@Setter
@ToString(callSuper = true)
public class EBikeMessageCmd20 extends AbsEBikeMessage2 {
/**
* 固件版本如100则表示V1.00版本
*/
private String firmwareVersion;
private DeviceRegister deviceRegister;
/**
* 端口数量 表示设备总共有多少个端口
*/
private int portNumber;
public EBikeMessageCmd20(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum, DeviceRegister deviceRegister) {
super(header, length, physicalId, messageId, command, payload, checksum);
this.deviceRegister = deviceRegister;
/**
* 虚拟ID需要内部组网的设备的本地地址如485、LORA系列如不需组网的设备默认为00
*/
private String virtualId;
/**
* 设备类型: 见01指令中的设备类型表
*/
private String deviceType;
/**
* 工作模式第0位0=联网1=刷卡。第1位0=RN82091=BL0939。第2位0=无短路预检1=有短路预检。第3位0=光耦检测模式1=带灯模式。
*/
private String workMode;
/**
* 电源板版本号电源板的固件版本号如没有电源板的机型则为0
*/
private String powerBoardVersion;
public EBikeMessageCmd20(byte[] messageBytes) {
super(messageBytes);
int startIndex = 12;
int length = 2;
this.firmwareVersion = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.virtualId = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
this.deviceType = BytesUtil.printHexBinary(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.workMode = BytesUtil.bcd2StrLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.powerBoardVersion = BytesUtil.bcd2StrLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
}
@Override
public void parsePayload(byte[] dataBytes) {
this.deviceRegister = new DeviceRegister(dataBytes);
}
@Override
public byte[] getMessageBytes() {
return new byte[0];
}
public DeviceRegister getDeviceRegister() {
return deviceRegister;
}
@Data
public static class DeviceRegister {
/**
* 固件版本如100则表示V1.00版本
*/
private String firmwareVersion;
/**
* 端口数量 表示设备总共有多少个端口
*/
private int portNumber;
/**
* 虚拟ID需要内部组网的设备的本地地址如485、LORA系列如不需组网的设备默认为00
*/
private String virtualId;
/**
* 设备类型: 见01指令中的设备类型表
*/
private String deviceType;
/**
* 工作模式第0位0=联网1=刷卡。第1位0=RN82091=BL0939。第2位0=无短路预检1=有短路预检。第3位0=光耦检测模式1=带灯模式。
*/
private String workMode;
/**
* 电源板版本号电源板的固件版本号如没有电源板的机型则为0
*/
private String powerBoardVersion;
public DeviceRegister(byte[] dataBytes) {
this.firmwareVersion = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 0, 2)) * 0.01 + "";
this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 2, 3));
this.virtualId = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 3, 4)) + "";
this.deviceType = BytesUtil.printHexBinary(Arrays.copyOfRange(dataBytes, 4, 5));
this.workMode = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 5, 6));
this.powerBoardVersion = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, 6, 8));
}
}
}
}

View File

@@ -3,100 +3,89 @@ package com.jsowell.pile.domain.ebike.deviceupload;
import com.google.common.collect.Lists;
import com.jsowell.common.enums.ebike.PortStatusEnum;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.util.Arrays;
import java.math.BigDecimal;
import java.util.List;
/**
* 设备注册包20指令
*/
@Getter
@Setter
public class EBikeMessageCmd21 extends AbsEBikeMessage {
private DeviceHeartbeat deviceHeartbeat;
public EBikeMessageCmd21(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum, DeviceHeartbeat deviceHeartbeat) {
super(header, length, physicalId, messageId, command, payload, checksum);
this.deviceHeartbeat = deviceHeartbeat;
}
@Override
public void parsePayload(byte[] dataBytes) {
this.deviceHeartbeat = new DeviceHeartbeat(dataBytes);
}
@Override
public byte[] getMessageBytes() {
return new byte[0];
}
@ToString(callSuper = true)
public class EBikeMessageCmd21 extends AbsEBikeMessage2 {
/**
* 电压:设备的当前电压(打包发送心跳包指令时的当前时间点的实时电压)
* 2024年8月26日15点02分 已经转为标准单位V
*/
private String voltage;
/**
* 此为心跳包间隔时间默认为3分钟方便服务器管理SocketIP
* 设备如2次收不到服务器应答则进入离线状态
* 端口数量:表示设备总共有多少个端口,和后面的“端口状态”配套
*/
@Getter
@Setter
public static class DeviceHeartbeat {
/**
* 电压:设备的当前电压(打包发送心跳包指令时的当前时间点的实时电压)
* 2024年8月26日15点02分 已经转为标准单位V
*/
private String voltage;
private int portNumber;
/**
* 端口数量:表示设备总共有多少个端口,和后面的“端口状态”配套
*/
private int portNumber;
/**
* 注4、各端口状态一个字节表示一个端口和“端口数量”匹配
* 如端口数量是16则“各端口状态”为16字节
* 每个字节表示的意思,
* 0=空闲1=充电中2=有充电器但未充电用户未启动充电3=有充电器但未充电(已充满电) 4=该路无法计量5=浮充6=存储器损坏,
* 7插座弹片卡住故障8接触不良或保险丝烧断故障9(算法-继电器粘连)0x0A=霍尔开关损坏(即插入检测传感器)。
* 0x0B=(预检-继电器坏或保险丝断0x0D=(预检-负载短路。0x0E=(过滤性预检-继电器粘连),0x0F=(刷卡芯片损坏故障)0x10=(检测电路故障)
*/
private List<String> portStatus;
/**
* 注4、各端口状态一个字节表示一个端口和“端口数量”匹配
* 如端口数量是16则“各端口状态”为16字节
* 每个字节表示的意思,
* 0=空闲1=充电中2=有充电器但未充电用户未启动充电3=有充电器但未充电(已充满电) 4=该路无法计量5=浮充6=存储器损坏,
* 7插座弹片卡住故障8接触不良或保险丝烧断故障9(算法-继电器粘连)0x0A=霍尔开关损坏(即插入检测传感器)。
* 0x0B=(预检-继电器坏或保险丝断0x0D=(预检-负载短路。0x0E=(过滤性预检-继电器粘连),0x0F=(刷卡芯片损坏故障)0x10=(检测电路故障)
*/
private List<String> portStatus;
private List<String> statusDescList;
private List<String> statusDescList;
/**
* 信号强度指分机与主机之间的无线信号强度如LORA信号。00则为有线组网或无信号强度功能
*/
private String rssi;
/**
* 信号强度指分机与主机之间的无线信号强度如LORA信号。00则为有线组网或无信号强度功能
*/
private String rssi;
/**
* 当前环境温度表示当前设备内的温度可能和真正的当前环境温度有一定的误差如00则表示无此功能
*/
private String temperature;
/**
* 当前环境温度表示当前设备内的温度可能和真正的当前环境温度有一定的误差如00则表示无此功能
*/
private String temperature;
public DeviceHeartbeat(byte[] dataBytes) {
this.voltage = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 0, 2)) * 0.1 + "";
this.portNumber = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, 2, 3));
public EBikeMessageCmd21(byte[] messageBytes) {
super(messageBytes);
byte[] statusBytes = BytesUtil.copyBytes(dataBytes, 3, this.portNumber);
List<String> statusList = Lists.newArrayList();
List<String> statusDescList = Lists.newArrayList();
for (byte statusByte : statusBytes) {
int status = BytesUtil.bytesToIntLittle(new byte[]{statusByte});
statusList.add(String.valueOf(status));
statusDescList.add(PortStatusEnum.getDescriptionByValue(status));
}
this.portStatus = statusList;
this.statusDescList = statusDescList;
this.rssi = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, dataBytes.length - 2, dataBytes.length - 1)) + "";
//
int i = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, dataBytes.length - 1, dataBytes.length));
if (i > 65) {
i = i - 65;
}
this.temperature = i + "";
// 读取结果
int startIndex = 12;
int length = 2;
this.voltage = new BigDecimal(BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)))
.multiply(new BigDecimal("0.1")).toString();
startIndex += length;
length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = this.portNumber;
byte[] statusBytes = BytesUtil.copyBytes(messageBytes, startIndex, length);
// 解析
List<String> statusList = Lists.newArrayList();
List<String> statusDescList = Lists.newArrayList();
for (byte statusByte : statusBytes) {
int status = BytesUtil.bytesToIntLittle(new byte[]{statusByte});
statusList.add(String.valueOf(status));
statusDescList.add(PortStatusEnum.getDescriptionByValue(status));
}
}
this.portStatus = statusList;
this.statusDescList = statusDescList;
}
startIndex += length;
length = 1;
this.rssi = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length)) + "";
startIndex += length;
length = 1;
int i = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
if (i > 65) {
i = i - 65;
}
this.temperature = i + "";
}
}

View File

@@ -1,32 +1,16 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.common.util.bean.SerializationUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* 设备获取服务器时间22指令
* 此命令设备每次上电后就会发送直至服务器应答后就停止发送。如服务器无应答则每隔3分钟发送一次请求
* 每12小时从服务器获取一次时间如服务器不应答则每隔3分钟发送一次请求
*/
@Getter
@Setter
public class EBikeMessageCmd22 extends AbsEBikeMessage {
@ToString(callSuper = true)
public class EBikeMessageCmd22 extends AbsEBikeMessage2 {
public EBikeMessageCmd22(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum) {
super(header, length, physicalId, messageId, command, payload, checksum);
public EBikeMessageCmd22(byte[] messageBytes) {
super(messageBytes);
}
@Override
public void parsePayload(byte[] dataBytes) {
}
@Override
public byte[] getMessageBytes() {
byte[] serialize = SerializationUtil.serialize(this);
return serialize;
}
}
}

View File

@@ -1,7 +1,15 @@
package com.jsowell.pile.domain.ebike.deviceupload;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
public class EBikeMessageCmd35 extends AbsEBikeMessage {
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString(callSuper = true)
public class EBikeMessageCmd35 extends AbsEBikeMessage2 {
public EBikeMessageCmd35(byte[] messageBytes) {
super(messageBytes);
}
}

View File

@@ -1,22 +1,16 @@
package com.jsowell.pile.domain.ebike.serversend;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
/**
* 查询设备联网状态81指令
* 注1、此命令应用于注册网络后通信过程中服务器主动查询设备状态
* 注2、此命令会触发设备发送“注册包”20、“设备心跳包”01和21指令上发时间会因设备不同而不同
*/
public class EBikeMessageCmd81 extends AbsEBikeMessage {
public class EBikeMessageCmd81 extends AbsEBikeMessage2 {
@Override
public void parsePayload(byte[] dataBytes) {
}
@Override
public byte[] getMessageBytes() {
return new byte[0];
public EBikeMessageCmd81(byte[] messageBytes) {
super(messageBytes);
}
}

View File

@@ -2,12 +2,12 @@ package com.jsowell.pile.domain.ebike.serversend;
import com.google.common.primitives.Bytes;
import com.jsowell.common.YouDianUtils;
import com.jsowell.common.constant.Constants;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import lombok.*;
import java.util.Arrays;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.avro.specific.SpecificData;
/**
* 服务器开始、停止充电操作82指令
@@ -15,179 +15,155 @@ import java.util.Arrays;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EBikeMessageCmd82 extends AbsEBikeMessage {
public class EBikeMessageCmd82 extends AbsEBikeMessage2 {
private SpecificData data;
@Override
public void parsePayload(byte[] dataBytes) {
this.data = new SpecificData(dataBytes);
// 费率模式:=0计时=1包月=2计量=3计次。包月、计次默认充满自停计时、计量可手动设置时长和电量
private int rateMode; // 费率模式 (1字节)
// 余额/有效期:设备仅仅用于语音播报作用,当费率模式为计时、计量、计次时,数据为余额;当费率模式为包月时,数据为有效期(时间戳), 大于100000000这个值会当成时间报有效期
private int balanceOrValidity; // 余额/有效期 (4字节)
// 端口号指充电桩的插口号端口号从0开始如0x00-0x0F则代表第1路-第16路0x00=第1路0x09=第十路0x0A=第十一路FF=设备智能选择端口(服务器下发)
private int portNumber; // 端口号 (指实际端口号, 发指令的时候自动转换为桩能识别的byte字节)
// 充电命令=0(停止充电)(远程停止充电需要下发对当前正在充电的订单号,如果订单号对不上则无法远程停止),=1(开始充电)设备充电与否依据此字段
private int chargeCommand; // 充电命令 (1字节)
// 告知设备的充电时长/电量, 如是0x0000则说明是充满自停, 其他数值则按照时长/电量充电, 且充满不会自停,
private int chargeTimeOrPower; // 充电时长/电量 (2字节)
// 生成给桩的交易流水号, 桩协议叫订单编号
private String transactionCode; // 订单编号 (16字节)
// 最大充电时长、过载功率只对当前端口当前订单有效不影响其他端口动态设置此参数如果参数为0表示不修改会使用设备的设置值默认10小时
private int maxChargeTime; // 最大充电时长 (2字节)
private int overloadPower; // 过载功率 (2字节)
// 二维码灯0打开1关闭针对部分有二维码灯的设备有效。此设置是针对下一次插头插入时是否点亮二维码背光灯保存在内存中断电重启后就会失效
private int qrCodeLight; // 二维码灯 (1字节)
// 长充模式特殊需求正常情况不需开启传0 即可)
private int longChargeMode; // 长充模式 (1字节)
// 额外浮充时间特殊需求正常情况不需开启传0 即可即额外增加的浮充时间单位秒如果下发的是0xFFFF则为取消浮充且检测绿灯统一改为5分钟
private int extraFloatChargeTime; // 额外浮充时间 (2字节)
private int skipShortCircuitDetection; // 是否跳过短路检测 (1字节)
private int noUserPullOutCheck; // 不判断用户拔出 (1字节)
private int forceAutoStopWhenFull; // 强制带充满自停 (1字节)
private int fullChargePower; // 充满功率 (1字节)
private int maxFullChargePowerCheckTime; // 充满功率最长判断时间 (1字节)
public EBikeMessageCmd82(byte[] messageBytes) {
super(messageBytes);
int startIndex = 12;
int length = 1;
this.rateMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 4;
this.balanceOrValidity = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.portNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.chargeCommand = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.chargeTimeOrPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 16;
this.transactionCode = BytesUtil.bcd2StrLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.maxChargeTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.overloadPower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.qrCodeLight = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.longChargeMode = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 2;
this.extraFloatChargeTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.skipShortCircuitDetection = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.noUserPullOutCheck = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.forceAutoStopWhenFull = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.fullChargePower = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
startIndex += length;
length = 1;
this.maxFullChargePowerCheckTime = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(messageBytes, startIndex, length));
}
public static void main(String[] args) {
int i = 0x82;
byte[] commandBytes = new byte[]{(byte) i};
System.out.println(BytesUtil.bcd2StrLittle(commandBytes));
int i2 = 82;
byte[] commandBytes2 = new byte[]{(byte) i2};
System.out.println(BytesUtil.bcd2StrLittle(commandBytes2));
}
@Override
// 获取字节数组
public byte[] getMessageBytes() {
// 包头
byte[] headerBytes = BytesUtil.stringToHexBytes(Constants.EBIKE_HEADER, 3);
// 物理ID
byte[] physicalIdBytes = YouDianUtils.getPhysicalIdBytes(physicalId);
// 消息ID
byte[] messageIdBytes = BytesUtil.intToBytesLittle(messageId, 2);
// 命令
byte[] commandBytes = new byte[]{(byte) 0x82};
// 数据
byte[] payloadBytes = data.getBytes();
// 长度 物理ID+消息ID+命令+数据(n) +校验(2)每包最多256字节
byte[] lengthBytes = BytesUtil.intToBytesLittle(9 + payloadBytes.length);
// 拼接
byte[] concat = Bytes.concat(headerBytes, lengthBytes, physicalIdBytes, messageIdBytes, commandBytes, payloadBytes);
// 校验和
byte[] checksumBytes = YouDianUtils.getCheckFieldBytes(concat);
return Bytes.concat(concat, checksumBytes);
// 费率模式
byte[] rateModeBytes = BytesUtil.intToBytesLittle(rateMode, 1);
// 余额/有效期
byte[] balanceOrValidityBytes = BytesUtil.intToBytesLittle(balanceOrValidity, 4);
// 端口号
byte[] portNumberBytes = YouDianUtils.convertPortNumberToBytes(portNumber);
// 充电命令
byte[] chargeCommandBytes = BytesUtil.intToBytesLittle(chargeCommand, 1);
// 充电时长/电量
byte[] chargeDurationOrPowerBytes = BytesUtil.intToBytesLittle(chargeTimeOrPower, 2);
// 订单编号
byte[] orderNumberBytes = BytesUtil.ensureLength(BytesUtil.str2Bcd(transactionCode), 16);
// 最大充电时长
byte[] maxChargeDurationBytes = BytesUtil.intToBytesLittle(maxChargeTime, 2);
// 过载功率
byte[] overloadPowerBytes = BytesUtil.intToBytesLittle(overloadPower, 2);
// 二维码灯
byte[] qrCodeLightBytes = BytesUtil.intToBytesLittle(qrCodeLight, 1);
// 长充模式
// byte[] longChargeModeBytes = BytesUtil.stringToHexBytes(longChargeMode, 1);
// 额外浮充时间
// byte[] extraFloatChargeTimeBytes = BytesUtil.stringToHexBytes(extraFloatChargeTime, 2);
// 是否跳过短路检测
// byte[] skipShortCircuitDetectionBytes = BytesUtil.stringToHexBytes(skipShortCircuitDetection, 1);
// 不判断用户拔出
// byte[] noUserPullOutCheckBytes = BytesUtil.stringToHexBytes(noUserPullOutCheck, 1);
// 强制带充满自停
// byte[] forceAutoStopWhenFullBytes = BytesUtil.stringToHexBytes(forceAutoStopWhenFull, 1);
// 充满功率
// byte[] fullChargePowerBytes = BytesUtil.stringToHexBytes(fullChargePower, 1);
// 最大充满功率最长判断时间
// byte[] maxFullChargePowerCheckTimeBytes = BytesUtil.stringToHexBytes(maxFullChargePowerCheckTime, 1);
return Bytes.concat(rateModeBytes, balanceOrValidityBytes, portNumberBytes, chargeCommandBytes,
chargeDurationOrPowerBytes, orderNumberBytes, maxChargeDurationBytes, overloadPowerBytes
// , qrCodeLightBytes, longChargeModeBytes, extraFloatChargeTimeBytes
// , skipShortCircuitDetectionBytes, noUserPullOutCheckBytes, forceAutoStopWhenFullBytes
// , fullChargePowerBytes, maxFullChargePowerCheckTimeBytes
);
}
public SpecificData getData() {
return data;
}
@Getter
@Setter
@NoArgsConstructor
public static class SpecificData {
// 费率模式:=0计时=1包月=2计量=3计次。包月、计次默认充满自停计时、计量可手动设置时长和电量
private int rateMode; // 费率模式 (1字节)
// 余额/有效期:设备仅仅用于语音播报作用,当费率模式为计时、计量、计次时,数据为余额;当费率模式为包月时,数据为有效期(时间戳), 大于100000000这个值会当成时间报有效期
private int balanceOrValidity; // 余额/有效期 (4字节)
// 端口号指充电桩的插口号端口号从0开始如0x00-0x0F则代表第1路-第16路0x00=第1路0x09=第十路0x0A=第十一路FF=设备智能选择端口(服务器下发)
private int portNumber; // 端口号 (指实际端口号, 发指令的时候自动转换为桩能识别的byte字节)
// 充电命令=0(停止充电)(远程停止充电需要下发对当前正在充电的订单号,如果订单号对不上则无法远程停止),=1(开始充电)设备充电与否依据此字段
private int chargeCommand; // 充电命令 (1字节)
// 告知设备的充电时长/电量, 如是0x0000则说明是充满自停, 其他数值则按照时长/电量充电, 且充满不会自停,
private int chargeTimeOrPower; // 充电时长/电量 (2字节)
// 生成给桩的交易流水号, 桩协议叫订单编号
private String transactionCode; // 订单编号 (16字节)
// 最大充电时长、过载功率只对当前端口当前订单有效不影响其他端口动态设置此参数如果参数为0表示不修改会使用设备的设置值默认10小时
private int maxChargeTime; // 最大充电时长 (2字节)
private int overloadPower; // 过载功率 (2字节)
// 二维码灯0打开1关闭针对部分有二维码灯的设备有效。此设置是针对下一次插头插入时是否点亮二维码背光灯保存在内存中断电重启后就会失效
private int qrCodeLight; // 二维码灯 (1字节)
// 长充模式特殊需求正常情况不需开启传0 即可)
private int longChargeMode; // 长充模式 (1字节)
// 额外浮充时间特殊需求正常情况不需开启传0 即可即额外增加的浮充时间单位秒如果下发的是0xFFFF则为取消浮充且检测绿灯统一改为5分钟
private int extraFloatChargeTime; // 额外浮充时间 (2字节)
private int skipShortCircuitDetection; // 是否跳过短路检测 (1字节)
private int noUserPullOutCheck; // 不判断用户拔出 (1字节)
private int forceAutoStopWhenFull; // 强制带充满自停 (1字节)
private int fullChargePower; // 充满功率 (1字节)
private int maxFullChargePowerCheckTime; // 充满功率最长判断时间 (1字节)
public SpecificData(byte[] dataBytes) {
byte rateModeBytes = dataBytes[0];
this.rateMode = BytesUtil.bytesToIntLittle(new byte[]{rateModeBytes});
byte[] balanceOrValidityBytes = Arrays.copyOfRange(dataBytes, 1, 5);
this.balanceOrValidity = BytesUtil.bytesToIntLittle(balanceOrValidityBytes);
byte portNumberBytes = dataBytes[5];
this.portNumber = BytesUtil.bytesToIntLittle(new byte[]{portNumberBytes});
byte chargeCommandBytes = dataBytes[6];
this.chargeCommand = BytesUtil.bytesToIntLittle(new byte[]{chargeCommandBytes});
byte[] chargeDurationOrPowerBytes = Arrays.copyOfRange(dataBytes, 7, 9);
this.chargeTimeOrPower = BytesUtil.bytesToIntLittle(chargeDurationOrPowerBytes);
byte[] orderNumberBytes = Arrays.copyOfRange(dataBytes, 9, 25);
this.transactionCode = BytesUtil.bcd2StrLittle(orderNumberBytes);
byte[] maxChargeDurationBytes = Arrays.copyOfRange(dataBytes, 25, 27);
this.maxChargeTime = BytesUtil.bytesToIntLittle(maxChargeDurationBytes);
byte[] overloadPowerBytes = Arrays.copyOfRange(dataBytes, 27, 29);
this.overloadPower = BytesUtil.bytesToIntLittle(overloadPowerBytes);
byte qrCodeLightBytes = dataBytes[29];
this.qrCodeLight = BytesUtil.bytesToIntLittle(new byte[]{qrCodeLightBytes});
byte longChargeModeBytes = dataBytes[30];
this.longChargeMode = BytesUtil.bytesToIntLittle(new byte[]{longChargeModeBytes});
byte[] extraFloatChargeTimeBytes = Arrays.copyOfRange(dataBytes, 31, 33);
this.extraFloatChargeTime = BytesUtil.bytesToIntLittle(extraFloatChargeTimeBytes);
byte skipShortCircuitDetectionBytes = dataBytes[33];
this.skipShortCircuitDetection = BytesUtil.bytesToIntLittle(new byte[]{skipShortCircuitDetectionBytes});
byte noUserPullOutCheckBytes = dataBytes[34];
this.noUserPullOutCheck = BytesUtil.bytesToIntLittle(new byte[]{noUserPullOutCheckBytes});
byte forceAutoStopWhenFullByte = dataBytes[35];
this.forceAutoStopWhenFull = BytesUtil.bytesToIntLittle(new byte[]{forceAutoStopWhenFullByte});
byte fullChargePowerBytes = dataBytes[36];
this.fullChargePower = BytesUtil.bytesToIntLittle(new byte[]{fullChargePowerBytes});
byte maxFullChargePowerCheckTimeBytes = dataBytes[37];
this.maxFullChargePowerCheckTime = BytesUtil.bytesToIntLittle(new byte[]{maxFullChargePowerCheckTimeBytes});
}
// 获取字节数组
public byte[] getBytes() {
// 费率模式
byte[] rateModeBytes = BytesUtil.intToBytesLittle(rateMode, 1);
// 余额/有效期
byte[] balanceOrValidityBytes = BytesUtil.intToBytesLittle(balanceOrValidity, 4);
// 端口号
byte[] portNumberBytes = YouDianUtils.convertPortNumberToBytes(portNumber);
// 充电命令
byte[] chargeCommandBytes = BytesUtil.intToBytesLittle(chargeCommand, 1);
// 充电时长/电量
byte[] chargeDurationOrPowerBytes = BytesUtil.intToBytesLittle(chargeTimeOrPower, 2);
// 订单编号
byte[] orderNumberBytes = BytesUtil.ensureLength(BytesUtil.str2Bcd(transactionCode), 16);
// 最大充电时长
byte[] maxChargeDurationBytes = BytesUtil.intToBytesLittle(maxChargeTime, 2);
// 过载功率
byte[] overloadPowerBytes = BytesUtil.intToBytesLittle(overloadPower, 2);
// 二维码灯
byte[] qrCodeLightBytes = BytesUtil.intToBytesLittle(qrCodeLight, 1);
// 长充模式
// byte[] longChargeModeBytes = BytesUtil.stringToHexBytes(longChargeMode, 1);
// 额外浮充时间
// byte[] extraFloatChargeTimeBytes = BytesUtil.stringToHexBytes(extraFloatChargeTime, 2);
// 是否跳过短路检测
// byte[] skipShortCircuitDetectionBytes = BytesUtil.stringToHexBytes(skipShortCircuitDetection, 1);
// 不判断用户拔出
// byte[] noUserPullOutCheckBytes = BytesUtil.stringToHexBytes(noUserPullOutCheck, 1);
// 强制带充满自停
// byte[] forceAutoStopWhenFullBytes = BytesUtil.stringToHexBytes(forceAutoStopWhenFull, 1);
// 充满功率
// byte[] fullChargePowerBytes = BytesUtil.stringToHexBytes(fullChargePower, 1);
// 最大充满功率最长判断时间
// byte[] maxFullChargePowerCheckTimeBytes = BytesUtil.stringToHexBytes(maxFullChargePowerCheckTime, 1);
return Bytes.concat(rateModeBytes, balanceOrValidityBytes, portNumberBytes, chargeCommandBytes,
chargeDurationOrPowerBytes, orderNumberBytes, maxChargeDurationBytes, overloadPowerBytes
// , qrCodeLightBytes, longChargeModeBytes, extraFloatChargeTimeBytes
// , skipShortCircuitDetectionBytes, noUserPullOutCheckBytes, forceAutoStopWhenFullBytes
// , fullChargePowerBytes, maxFullChargePowerCheckTimeBytes
);
}
}
}

View File

@@ -4,7 +4,7 @@ import com.jsowell.common.enums.ykc.PileChannelEntity;
import com.jsowell.common.protocol.SyncPromise;
import com.jsowell.common.util.*;
import com.jsowell.common.util.id.IdUtils;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage2;
import com.jsowell.pile.domain.ebike.deviceupload.ChargingOperationResponse;
import com.jsowell.pile.domain.ebike.serversend.EBikeMessageCmd82;
import com.jsowell.pile.domain.ykcCommond.StartChargingCommand;
@@ -46,36 +46,34 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
message.setMessageId(RandomUtil.getRandomNumber(4));
message.setCommand("82");
EBikeMessageCmd82.SpecificData data = new EBikeMessageCmd82.SpecificData();
// 充电模式
data.setRateMode(3);
message.setRateMode(3);
// 余额(分)或有效期
int balance = command.getChargeAmount().multiply(new BigDecimal("100")).intValue();
data.setBalanceOrValidity(balance);
message.setBalanceOrValidity(balance);
// 端口号
data.setPortNumber(Integer.parseInt(connectorCode));
message.setPortNumber(Integer.parseInt(connectorCode));
// 充电命令
data.setChargeCommand(1);
message.setChargeCommand(1);
// 充电时长/功率
int chargeDurationOrPower = 0;
data.setChargeTimeOrPower(chargeDurationOrPower);
message.setChargeTimeOrPower(chargeDurationOrPower);
// 订单编号
data.setTransactionCode(transactionCode);
message.setTransactionCode(transactionCode);
// 最大充电时长
data.setMaxChargeTime(0);
message.setMaxChargeTime(0);
// 过载功率
data.setOverloadPower(OVER_LOAD_POWER);
data.setQrCodeLight(0);
data.setLongChargeMode(0);
data.setExtraFloatChargeTime(0);
data.setSkipShortCircuitDetection(0);
data.setNoUserPullOutCheck(0);
data.setForceAutoStopWhenFull(0);
data.setFullChargePower(0);
data.setMaxFullChargePowerCheckTime(0);
message.setData(data);
message.setOverloadPower(OVER_LOAD_POWER);
message.setQrCodeLight(0);
message.setLongChargeMode(0);
message.setExtraFloatChargeTime(0);
message.setSkipShortCircuitDetection(0);
message.setNoUserPullOutCheck(0);
message.setForceAutoStopWhenFull(0);
message.setFullChargePower(0);
message.setMaxFullChargePowerCheckTime(0);
byte[] response = this.send(message);
log.info("电单车发送启动充电指令response:{}", BytesUtil.binary(response, 16));
return new ChargingOperationResponse(response);
@@ -97,35 +95,33 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
message.setMessageId(RandomUtil.getRandomNumber(4));
message.setCommand("82");
EBikeMessageCmd82.SpecificData data = new EBikeMessageCmd82.SpecificData();
// 充电模式
data.setRateMode(3);
message.setRateMode(3);
// 余额或有效期
data.setBalanceOrValidity(1234);
message.setBalanceOrValidity(1234);
// 端口号
data.setPortNumber(Integer.parseInt(connectorCode));
message.setPortNumber(Integer.parseInt(connectorCode));
// 充电命令
data.setChargeCommand(0);
message.setChargeCommand(0);
// 充电时长/功率
int chargeDurationOrPower = 0;
data.setChargeTimeOrPower(chargeDurationOrPower);
message.setChargeTimeOrPower(chargeDurationOrPower);
// 订单编号
data.setTransactionCode(transactionCode);
message.setTransactionCode(transactionCode);
// 最大充电时长
data.setMaxChargeTime(0);
message.setMaxChargeTime(0);
// 过载功率
data.setOverloadPower(OVER_LOAD_POWER);
data.setQrCodeLight(0);
data.setLongChargeMode(0);
data.setExtraFloatChargeTime(0);
data.setSkipShortCircuitDetection(0);
data.setNoUserPullOutCheck(0);
data.setForceAutoStopWhenFull(0);
data.setFullChargePower(0);
data.setMaxFullChargePowerCheckTime(0);
message.setData(data);
message.setOverloadPower(OVER_LOAD_POWER);
message.setQrCodeLight(0);
message.setLongChargeMode(0);
message.setExtraFloatChargeTime(0);
message.setSkipShortCircuitDetection(0);
message.setNoUserPullOutCheck(0);
message.setForceAutoStopWhenFull(0);
message.setFullChargePower(0);
message.setMaxFullChargePowerCheckTime(0);
byte[] response = this.send(message);
log.info("电单车发送停止充电指令response:{}", BytesUtil.binary(response, 16));
return new ChargingOperationResponse(response);
@@ -135,10 +131,10 @@ public class EBikeSendCommandServiceImpl implements EBikeSendCommandService {
* 公共方法, 发送指令
* @param msg
*/
private byte[] send(AbsEBikeMessage msg) throws Exception {
private byte[] send(AbsEBikeMessage2 msg) throws Exception {
return this.send(msg, 5, TimeUnit.SECONDS);
}
private byte[] send(AbsEBikeMessage msg, long timeout, TimeUnit unit) throws Exception {
private byte[] send(AbsEBikeMessage2 msg, long timeout, TimeUnit unit) throws Exception {
String pileSn = msg.getPhysicalId() + "";
byte[] messageBytes = msg.getMessageBytes();
String command = YKCUtils.frameType2Str(msg.getCommand());

View File

@@ -1279,8 +1279,7 @@ public class PileBasicInfoServiceImpl implements PileBasicInfoService {
basicInfo.setDelFlag(DelFlagEnum.NORMAL.getValue()); // 删除标识
basicInfoList.add(basicInfo);
EBikeMessageCmd20.DeviceRegister deviceRegister = message.getDeviceRegister();
int portNumber = deviceRegister.getPortNumber();
int portNumber = message.getPortNumber();
PileConnectorInfo connectorInfo;
for (int i = 1; i < portNumber + 1; i++) {
// 组装pile_connector_info表数据

View File

@@ -10,7 +10,10 @@ import com.jsowell.common.constant.Constants;
import com.jsowell.common.core.domain.ykc.RealTimeMonitorData;
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.enums.ykc.*;
import com.jsowell.common.enums.ykc.CardStatusEnum;
import com.jsowell.common.enums.ykc.OrderPayModeEnum;
import com.jsowell.common.enums.ykc.OrderPayRecordEnum;
import com.jsowell.common.enums.ykc.OrderStatusEnum;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.*;