diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/AbsEBikeMessage.java b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/AbsEBikeMessage.java index dcc1d8133..550c91d98 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/AbsEBikeMessage.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/AbsEBikeMessage.java @@ -2,8 +2,6 @@ package com.jsowell.netty.domain.ebike; import com.jsowell.common.util.BytesUtil; import com.jsowell.netty.domain.ebike.deviceupload.*; -import com.jsowell.netty.domain.ebike.serversend.EBikeMessageCmd82; -import com.jsowell.netty.domain.ebike.serversend.SpecificDataCmd82; import lombok.Getter; import lombok.Setter; @@ -35,14 +33,20 @@ public abstract class AbsEBikeMessage { private static AbsEBikeMessage createMessageInstance(String command, String header, int length, int physicalId, int messageId, int checksum, byte[] dataBytes) { switch (command) { - case "82": - return new EBikeMessageCmd82(header, length, physicalId, messageId, command, null, checksum, new SpecificDataCmd82(dataBytes)); + case "02": + return new EBikeMessageCmd02(header, length, physicalId, messageId, command, null, checksum, new CreditCardInfo(dataBytes)); case "03": return new EBikeMessageCmd03(header, length, physicalId, messageId, command, null, checksum, new SettlementInfo(dataBytes)); - case "20": - return new EBikeMessageCmd20(header, length, physicalId, messageId, command, null, checksum, new DeviceRegister(dataBytes)); + case "04": + return new EBikeMessageCmd04(header, length, physicalId, messageId, command, null, checksum, new ConfirmOrder(dataBytes)); case "06": return new EBikeMessageCmd06(header, length, physicalId, messageId, command, null, checksum, new PowerHeartbeat(dataBytes)); + case "20": + return new EBikeMessageCmd20(header, length, physicalId, messageId, command, null, checksum, new DeviceRegister(dataBytes)); + case "21": + return new EBikeMessageCmd21(header, length, physicalId, messageId, command, null, checksum, new DeviceHeartbeat(dataBytes)); + case "22": + return new EBikeMessageCmd22(header, length, physicalId, messageId, command, null, checksum); default: throw new IllegalArgumentException("Unsupported command: " + command); } diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/CreditCardInfo.java b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/CreditCardInfo.java new file mode 100644 index 000000000..36d050a91 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/CreditCardInfo.java @@ -0,0 +1,69 @@ +package com.jsowell.netty.domain.ebike.deviceupload; + +import com.jsowell.common.util.BytesUtil; +import lombok.Data; + +import java.util.Arrays; + +@Data +public class CreditCardInfo { + /** + * 卡片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 CreditCardInfo(byte[] dataBytes) { + int startIndex = 0; + int length = 4; + this.cardId = BytesUtil.bcd2Str(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; + + length = 1; + this.cardType = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = 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)) + ""; + } + } +} diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/EBikeMessageCmd02.java b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/EBikeMessageCmd02.java new file mode 100644 index 000000000..064003a4e --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/EBikeMessageCmd02.java @@ -0,0 +1,27 @@ +package com.jsowell.netty.domain.ebike.deviceupload; + +import com.jsowell.netty.domain.ebike.AbsEBikeMessage; + +/** + * 刷卡操作(02指令) + * 特别注意:上报的端口号如果不是FF为端口请求充电,服务器需应答刷卡指令后,如果服务器需要给当前端口启动充电的,需要下发82指令来启动充电 + * CreditCard + */ +public class EBikeMessageCmd02 extends AbsEBikeMessage { + + private CreditCardInfo creditCardInfo; + + 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; + } + + @Override + public void parsePayload(byte[] dataBytes) { + this.creditCardInfo = new CreditCardInfo(dataBytes); + } + + public CreditCardInfo getCreditCardInfo() { + return creditCardInfo; + } +} \ No newline at end of file diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/EBikeMessageCmd22.java b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/EBikeMessageCmd22.java new file mode 100644 index 000000000..64790a271 --- /dev/null +++ b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/EBikeMessageCmd22.java @@ -0,0 +1,25 @@ +package com.jsowell.netty.domain.ebike.deviceupload; + +import com.jsowell.netty.domain.ebike.AbsEBikeMessage; +import lombok.Getter; +import lombok.Setter; + +/** + * 设备获取服务器时间(22指令) + * 此命令设备每次上电后就会发送,直至服务器应答后就停止发送。如服务器无应答,则每隔3分钟发送一次请求 + * 每12小时从服务器获取一次时间,如服务器不应答则每隔3分钟发送一次请求 + */ +@Getter +@Setter +public class EBikeMessageCmd22 extends AbsEBikeMessage { + + public EBikeMessageCmd22(String header, int length, int physicalId, int messageId, String command, Object payload, int checksum) { + super(header, length, physicalId, messageId, command, payload, checksum); + } + + @Override + public void parsePayload(byte[] dataBytes) { + + } + +} \ No newline at end of file diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/PowerHeartbeat.java b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/PowerHeartbeat.java index da6d0132c..05f02d28c 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/PowerHeartbeat.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ebike/deviceupload/PowerHeartbeat.java @@ -115,22 +115,22 @@ public class PowerHeartbeat { this.chargingTime = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; length = 2; - this.totalUsedElectricity = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)); + this.totalUsedElectricity = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) * 0.01 + ""; length = 1; this.startMode = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; length = 2; - this.realTimePower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; + this.realTimePower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) * 0.1 + ""; length = 2; - this.maxPower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; + this.maxPower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) * 0.1 + ""; length = 2; - this.minPower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; + this.minPower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) * 0.1 + ""; length = 2; - this.avgPower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; + this.avgPower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) * 0.1 + ""; length = 16; this.orderCode = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)); @@ -139,10 +139,10 @@ public class PowerHeartbeat { this.peakPower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; length = 2; - this.voltage = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; + this.voltage = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) * 0.1 + ""; length = 2; - this.current = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + ""; + this.current = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) * 0.0001 + ""; length = 1; this.ambientTemperature = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";