|
@ -15,7 +15,7 @@ public class A8kPacket { |
|
|
// uint8_t packetType; |
|
|
// uint8_t packetType; |
|
|
// uint16_t cmdid; |
|
|
// uint16_t cmdid; |
|
|
// uint8_t moduleId; |
|
|
// uint8_t moduleId; |
|
|
// uint8_t index; |
|
|
|
|
|
|
|
|
// uint16_t index; |
|
|
// uint8_t datalen; |
|
|
// uint8_t datalen; |
|
|
// uint8_t data[]; |
|
|
// uint8_t data[]; |
|
|
// /* int8_t checksum;*/ |
|
|
// /* int8_t checksum;*/ |
|
@ -30,14 +30,21 @@ public class A8kPacket { |
|
|
//} zcan_cmd_packet_type_t; |
|
|
//} zcan_cmd_packet_type_t; |
|
|
// |
|
|
// |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @WARNING |
|
|
|
|
|
* 1. 修改这里时,需要注意连同createPacket一起修改 |
|
|
|
|
|
* 2. PACKET_MIN_LEN 比Header多一个字节,是因为还有一个字节的校验位 |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
public static final int PACKET_TYPE_OFFSET = 0; |
|
|
public static final int PACKET_TYPE_OFFSET = 0; |
|
|
public static final int CMDID_OFFSET = 1; |
|
|
public static final int CMDID_OFFSET = 1; |
|
|
public static final int MODULE_ID_OFFSET = 3; |
|
|
public static final int MODULE_ID_OFFSET = 3; |
|
|
public static final int INDEX_OFFSET = 4; |
|
|
public static final int INDEX_OFFSET = 4; |
|
|
public static final int DATA_LEN_OFFSET = 5; |
|
|
|
|
|
public static final int DATA_OFFSET = 6; |
|
|
|
|
|
|
|
|
public static final int DATA_LEN_OFFSET = 6; |
|
|
|
|
|
public static final int DATA_OFFSET = 7; |
|
|
|
|
|
|
|
|
public static final int PACKET_MIN_LEN = 7; |
|
|
|
|
|
|
|
|
public static final int PACKET_MIN_LEN = 8;// |
|
|
|
|
|
|
|
|
public static final int CMD_OVERTIME = 1500; |
|
|
public static final int CMD_OVERTIME = 1500; |
|
|
|
|
|
|
|
@ -57,14 +64,14 @@ public class A8kPacket { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setPacketIndex(int packetIndex) { |
|
|
public void setPacketIndex(int packetIndex) { |
|
|
ByteArray.setU8(raw, INDEX_OFFSET, packetIndex); |
|
|
|
|
|
|
|
|
ByteArray.setU16bit(raw, INDEX_OFFSET, packetIndex); |
|
|
int checkcode = computeCheckcode(); |
|
|
int checkcode = computeCheckcode(); |
|
|
ByteArray.setU8(raw, raw.length - 1, checkcode); |
|
|
ByteArray.setU8(raw, raw.length - 1, checkcode); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getPacketIndex() { |
|
|
public int getPacketIndex() { |
|
|
return ByteArray.readU8bit(raw, INDEX_OFFSET); |
|
|
|
|
|
|
|
|
return ByteArray.readU16bit(raw, INDEX_OFFSET); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int getCmdId() { |
|
|
public int getCmdId() { |
|
@ -197,7 +204,8 @@ public class A8kPacket { |
|
|
buffer.put((byte) (packetType & 0xff)); // packetType |
|
|
buffer.put((byte) (packetType & 0xff)); // packetType |
|
|
buffer.putShort((short) (cmdId & 0xffff)); // cmdid |
|
|
buffer.putShort((short) (cmdId & 0xffff)); // cmdid |
|
|
buffer.put((byte) (moduleId & 0xFF)); // moduleId |
|
|
buffer.put((byte) (moduleId & 0xFF)); // moduleId |
|
|
buffer.put((byte) 0); // index |
|
|
|
|
|
|
|
|
buffer.put((byte) 0x4C); // index |
|
|
|
|
|
buffer.put((byte) 0x00); // index |
|
|
buffer.put((byte) (params.length * 4)); // datalen |
|
|
buffer.put((byte) (params.length * 4)); // datalen |
|
|
for (int value : params) { |
|
|
for (int value : params) { |
|
|
buffer.putInt(value); |
|
|
buffer.putInt(value); |
|
@ -211,4 +219,9 @@ public class A8kPacket { |
|
|
return new A8kPacket(buffer.array()); |
|
|
return new A8kPacket(buffer.array()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
var packet = createPacket(41, A8kPacket.PACKET_TYPE_CMD, CmdId.module_stop.index, new Integer[]{}); |
|
|
|
|
|
logger.info("{}", packet.toByteString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |