Commit e09a4395 by 谢海旭

实现 Ocpp16Helper.strToAscii 方法

1 parent b3abfe49
......@@ -175,27 +175,26 @@ public class Ocpp16Helper {
return bcdBytes;
}
public static byte[] strToAscii(String input, byte[] bcdBytes) {
int len = input.length();
int mod = len % 2;
if (mod != 0) {
input = "0" + input; // 补齐偶数位
len = input.length();
/**
* 字符串 转ascii字节数组
* 不足指定长度,默认后面补零
*
* @param str 字符串
* @param asciiBytes ascii字节数组(长度限定)
* @return
*/
public static byte[] strToAscii(String str, byte[] asciiBytes) {
if (str.length() > asciiBytes.length) {
throw new IllegalArgumentException("The str length is greater than the asciiBytes length");
}
for (int i = 0; i < len; i += 2) {
char highChar = input.charAt(i);
char lowChar = input.charAt(i + 1);
int high = Character.digit(highChar, 10);
int low = Character.digit(lowChar, 10);
byte bcdByte = (byte) ((high << 4) | low);
bcdBytes[i / 2] = bcdByte;
char[] charArray = str.toCharArray();
int length = charArray.length;
for (int i = 0; i < length; i++) {
asciiBytes[i] = (byte) charArray[i];
}
return bcdBytes;
return asciiBytes;
}
public static byte[] binToBytes(String binaryString) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!