mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-13 11:49:49 +08:00
update 电单车协议
This commit is contained in:
@@ -2,8 +2,6 @@ package com.jsowell.netty.domain.ebike;
|
|||||||
|
|
||||||
import com.jsowell.common.util.BytesUtil;
|
import com.jsowell.common.util.BytesUtil;
|
||||||
import com.jsowell.netty.domain.ebike.deviceupload.*;
|
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.Getter;
|
||||||
import lombok.Setter;
|
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) {
|
private static AbsEBikeMessage createMessageInstance(String command, String header, int length, int physicalId, int messageId, int checksum, byte[] dataBytes) {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "82":
|
case "02":
|
||||||
return new EBikeMessageCmd82(header, length, physicalId, messageId, command, null, checksum, new SpecificDataCmd82(dataBytes));
|
return new EBikeMessageCmd02(header, length, physicalId, messageId, command, null, checksum, new CreditCardInfo(dataBytes));
|
||||||
case "03":
|
case "03":
|
||||||
return new EBikeMessageCmd03(header, length, physicalId, messageId, command, null, checksum, new SettlementInfo(dataBytes));
|
return new EBikeMessageCmd03(header, length, physicalId, messageId, command, null, checksum, new SettlementInfo(dataBytes));
|
||||||
case "20":
|
case "04":
|
||||||
return new EBikeMessageCmd20(header, length, physicalId, messageId, command, null, checksum, new DeviceRegister(dataBytes));
|
return new EBikeMessageCmd04(header, length, physicalId, messageId, command, null, checksum, new ConfirmOrder(dataBytes));
|
||||||
case "06":
|
case "06":
|
||||||
return new EBikeMessageCmd06(header, length, physicalId, messageId, command, null, checksum, new PowerHeartbeat(dataBytes));
|
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:
|
default:
|
||||||
throw new IllegalArgumentException("Unsupported command: " + command);
|
throw new IllegalArgumentException("Unsupported command: " + command);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)) + "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -115,22 +115,22 @@ public class PowerHeartbeat {
|
|||||||
this.chargingTime = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
|
this.chargingTime = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
|
||||||
|
|
||||||
length = 2;
|
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;
|
length = 1;
|
||||||
this.startMode = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
|
this.startMode = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
|
||||||
|
|
||||||
length = 2;
|
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;
|
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;
|
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;
|
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;
|
length = 16;
|
||||||
this.orderCode = BytesUtil.bcd2StrLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length));
|
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)) + "";
|
this.peakPower = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
|
||||||
|
|
||||||
length = 2;
|
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;
|
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;
|
length = 1;
|
||||||
this.ambientTemperature = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
|
this.ambientTemperature = BytesUtil.bytesToIntLittle(Arrays.copyOfRange(dataBytes, startIndex, startIndex = startIndex + length)) + "";
|
||||||
|
|||||||
Reference in New Issue
Block a user