mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-17 16:28:41 +08:00
解析报文
This commit is contained in:
@@ -20,6 +20,7 @@ public class YKCUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean checkMsg(byte[] msg) {
|
public static boolean checkMsg(byte[] msg) {
|
||||||
|
// log.info("checkMsg:{}", BytesUtil.binary(msg, 16));
|
||||||
// 起始标志
|
// 起始标志
|
||||||
byte[] head = BytesUtil.copyBytes(msg, 0, 1);
|
byte[] head = BytesUtil.copyBytes(msg, 0, 1);
|
||||||
// 数据长度
|
// 数据长度
|
||||||
@@ -66,6 +67,11 @@ public class YKCUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
byte[] length = new byte[]{0x22};
|
||||||
|
System.out.println(BytesUtil.bytesToIntLittle(length));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换电压电流以及起始soc
|
* 转换电压电流以及起始soc
|
||||||
* 精确到小数点后一位;待机置零
|
* 精确到小数点后一位;待机置零
|
||||||
@@ -127,46 +133,6 @@ public class YKCUtils {
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String frameTypeStr = "0x01";
|
|
||||||
byte[] bytes = frameTypeStr2Bytes(frameTypeStr);
|
|
||||||
System.out.println("转为byte数组:" + Arrays.toString(bytes));
|
|
||||||
String frameType2Str = frameType2Str(bytes);
|
|
||||||
System.out.println("转为Str:" + frameType2Str);
|
|
||||||
|
|
||||||
// String hexString = "681E0000003388000000000027012302081602434533880000000000270101008361";
|
|
||||||
// byte[] byteArray = new byte[hexString.length() / 2];
|
|
||||||
// for (int i = 0; i < byteArray.length; i++) {
|
|
||||||
// int index = i * 2;
|
|
||||||
// int j = Integer.parseInt(hexString.substring(index, index + 2), 16);
|
|
||||||
// byteArray[i] = (byte) j;
|
|
||||||
// }
|
|
||||||
// System.out.println(byteArray);
|
|
||||||
// String binary = BytesUtil.binary(byteArray, 16);
|
|
||||||
// String aaa = DatatypeConverter.printHexBinary(byteArray);
|
|
||||||
// System.out.println(binary);
|
|
||||||
// System.out.println(aaa);
|
|
||||||
|
|
||||||
// String targetCRC = "0abb";
|
|
||||||
// String substring = StringUtils.substring(targetCRC, 0, 2);
|
|
||||||
// String substring1 = StringUtils.substring(targetCRC, 2, 4);
|
|
||||||
// String crc = substring1 + substring;
|
|
||||||
//
|
|
||||||
// String hexString = "4f";
|
|
||||||
// byte[] bytes = new byte[]{0x4f};
|
|
||||||
//
|
|
||||||
// String s = transitionTemperature(bytes);
|
|
||||||
// System.out.println(s);
|
|
||||||
//
|
|
||||||
// byte[] bytess = new byte[]{(byte) 0x80, (byte) 0x1A, 0x06, 0x00};
|
|
||||||
// String s1 = convertDecimalPoint(bytess, 5);
|
|
||||||
// System.out.println(s1);
|
|
||||||
//
|
|
||||||
// String amount = "1000";
|
|
||||||
// byte[] priceByte = getPriceByte(amount, 2);
|
|
||||||
// System.out.println(BytesUtil.bin2HexStr(priceByte));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换温度
|
* 转换温度
|
||||||
* BIN 码 1 整形,偏移量-50;待机置零
|
* BIN 码 1 整形,偏移量-50;待机置零
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class StartAndLengthFieldFrameDecoder extends ByteToMessageDecoder {
|
|||||||
// 处理68协议消息
|
// 处理68协议消息
|
||||||
private void decode68Message(ByteBuf buffer, List<Object> out, int beginReader) {
|
private void decode68Message(ByteBuf buffer, List<Object> out, int beginReader) {
|
||||||
// 检查剩余数据是否足够
|
// 检查剩余数据是否足够
|
||||||
if (buffer.readableBytes() < HEADER_LENGTH_68 + 1) {
|
if (buffer.readableBytes() < HEADER_LENGTH_68 + 1 + 2) {
|
||||||
buffer.readerIndex(beginReader);
|
buffer.readerIndex(beginReader);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -96,14 +96,14 @@ public class StartAndLengthFieldFrameDecoder extends ByteToMessageDecoder {
|
|||||||
// 获取消息长度
|
// 获取消息长度
|
||||||
int length = buffer.getUnsignedByte(beginReader + HEADER_LENGTH_68);
|
int length = buffer.getUnsignedByte(beginReader + HEADER_LENGTH_68);
|
||||||
// 检查剩余数据是否足够
|
// 检查剩余数据是否足够
|
||||||
if (buffer.readableBytes() < HEADER_LENGTH_68 + 1 + length) {
|
if (buffer.readableBytes() < HEADER_LENGTH_68 + 1 + length + 2) {
|
||||||
buffer.readerIndex(beginReader);
|
buffer.readerIndex(beginReader);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取 data 数据
|
// 读取 data 数据 最后+2是帧校验域长度
|
||||||
ByteBuf frame = buffer.retainedSlice(beginReader, HEADER_LENGTH_68 + 1 + length);
|
ByteBuf frame = buffer.retainedSlice(beginReader, HEADER_LENGTH_68 + 1 + length + 2);
|
||||||
buffer.readerIndex(beginReader + HEADER_LENGTH_68 + 1 + length);
|
buffer.readerIndex(beginReader + HEADER_LENGTH_68 + 1 + length + 2);
|
||||||
out.add(frame);
|
out.add(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user