mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-03 17:40:13 +08:00
update 电单车协议
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package com.jsowell.common;
|
package com.jsowell.common;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Bytes;
|
||||||
|
import com.jsowell.common.enums.ebike.EBikeTypeEnum;
|
||||||
import com.jsowell.common.util.BytesUtil;
|
import com.jsowell.common.util.BytesUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -88,6 +90,18 @@ public class YouDianUtils {
|
|||||||
return BytesUtil.intToBytesLittle(calculatedChecksum);
|
return BytesUtil.intToBytesLittle(calculatedChecksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取物理IDbyte数组
|
||||||
|
* @param deviceNumber
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static byte[] getPhysicalIdBytes(int deviceNumber) {
|
||||||
|
byte[] physicalIdBytes = BytesUtil.intToBytes(deviceNumber, 3);
|
||||||
|
// 拼接识别码, 12路插座
|
||||||
|
byte[] concat = Bytes.concat(EBikeTypeEnum.socket_12way.getBytes(), physicalIdBytes);
|
||||||
|
return BytesUtil.reverse(concat);
|
||||||
|
}
|
||||||
|
|
||||||
// public static String convertPortNumberToHex(int portNumber) {
|
// public static String convertPortNumberToHex(int portNumber) {
|
||||||
// if (portNumber < 1 || portNumber > 16) {
|
// if (portNumber < 1 || portNumber > 16) {
|
||||||
// throw new IllegalArgumentException("Port number must be between 1 and 16.");
|
// throw new IllegalArgumentException("Port number must be between 1 and 16.");
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.jsowell.common.enums.ebike;
|
package com.jsowell.common.enums.ebike;
|
||||||
|
|
||||||
|
import com.jsowell.common.util.BytesUtil;
|
||||||
|
|
||||||
public enum EBikeTypeEnum {
|
public enum EBikeTypeEnum {
|
||||||
|
|
||||||
socket_1way(0x03, "单路插座"),
|
socket_1way(0x03, "单路插座"),
|
||||||
@@ -23,6 +25,10 @@ public enum EBikeTypeEnum {
|
|||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] getBytes() {
|
||||||
|
return BytesUtil.intToBytesLittle(value, 1);
|
||||||
|
}
|
||||||
|
|
||||||
EBikeTypeEnum(int value, String desc) {
|
EBikeTypeEnum(int value, String desc) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.desc = desc;
|
this.desc = desc;
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ public class BytesUtil {
|
|||||||
*/
|
*/
|
||||||
public static byte[] str2BcdLittle(String asc) {
|
public static byte[] str2BcdLittle(String asc) {
|
||||||
byte[] temp = str2Bcd(asc);
|
byte[] temp = str2Bcd(asc);
|
||||||
return revert(temp);
|
return reverse(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -494,7 +494,7 @@ public class BytesUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String ascii2StrLittle(byte[] ascs) {
|
public static String ascii2StrLittle(byte[] ascs) {
|
||||||
byte[] data = revert(ascs);
|
byte[] data = reverse(ascs);
|
||||||
String asciiStr = null;
|
String asciiStr = null;
|
||||||
try {
|
try {
|
||||||
asciiStr = new String(data, "ISO8859-1");
|
asciiStr = new String(data, "ISO8859-1");
|
||||||
@@ -526,7 +526,7 @@ public class BytesUtil {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static byte[] str2AscLittle(String str) {
|
public static byte[] str2AscLittle(String str) {
|
||||||
return revert(str2Asc(str));
|
return reverse(str2Asc(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -550,7 +550,7 @@ public class BytesUtil {
|
|||||||
* @param temp
|
* @param temp
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static byte[] revert(byte[] temp) {
|
public static byte[] reverse(byte[] temp) {
|
||||||
byte[] ret = new byte[temp.length];
|
byte[] ret = new byte[temp.length];
|
||||||
for (int i = 0; i < temp.length; i++) {
|
for (int i = 0; i < temp.length; i++) {
|
||||||
ret[temp.length - i - 1] = temp[i];
|
ret[temp.length - i - 1] = temp[i];
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class EBikeMessageCmd82 extends AbsEBikeMessage {
|
|||||||
// 包头
|
// 包头
|
||||||
byte[] headerBytes = BytesUtil.stringToHexBytes(header, 3);
|
byte[] headerBytes = BytesUtil.stringToHexBytes(header, 3);
|
||||||
// 物理ID
|
// 物理ID
|
||||||
byte[] physicalIdBytes = BytesUtil.intToBytesLittle(physicalId, 4);
|
byte[] physicalIdBytes = YouDianUtils.getPhysicalIdBytes(physicalId);
|
||||||
// 消息ID
|
// 消息ID
|
||||||
byte[] messageIdBytes = BytesUtil.intToBytesLittle(messageId, 2);
|
byte[] messageIdBytes = BytesUtil.intToBytesLittle(messageId, 2);
|
||||||
// 命令
|
// 命令
|
||||||
|
|||||||
Reference in New Issue
Block a user