You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
935 B

#pragma once
#include <stdint.h>
namespace iflytop {
namespace zcr {
#pragma pack(push, 1)
typedef struct {
uint8_t packetType;
uint16_t cmdid;
uint8_t moduleId;
uint8_t index;
uint8_t datalen;
uint8_t data[];
/* int8_t checksum;*/
} zcr_cmd_header_t;
#pragma pack(pop)
typedef enum {
kptv2_cmd = 0x70,
kptv2_ack = 0x71,
kptv2_error_ack = 0x72,
kptv2_event = 0x73,
} zcan_cmd_packet_type_t;
static inline bool zcr_cmd_checkpacket(const zcr_cmd_header_t* header, int len) {
if (len < sizeof(zcr_cmd_header_t)) {
return false;
}
if ((header->datalen + sizeof(zcr_cmd_header_t) + 1) != len) {
return false;
}
uint8_t* rawpacket = (uint8_t*)header;
uint8_t checksum = 0;
for (int i = 0; i < len - 1; i++) {
checksum += rawpacket[i];
}
if (checksum != rawpacket[len - 1]) {
return false;
}
return true;
}
} // namespace zcr
} // namespace iflytop