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.

49 lines
970 B

2 years ago
4 months ago
2 years ago
5 months ago
5 months ago
2 years ago
5 months ago
2 years ago
5 months ago
2 years ago
2 years ago
5 months ago
5 months ago
5 months ago
2 years ago
5 months ago
2 years ago
5 months ago
  1. #pragma once
  2. #include <stdint.h>
  3. #define ZCANCMD_PACKET_MAX_LEN 64
  4. namespace iflytop {
  5. namespace zcr {
  6. #pragma pack(push, 1)
  7. typedef struct {
  8. uint8_t packetType;
  9. uint16_t cmdid;
  10. uint8_t moduleId;
  11. uint8_t index;
  12. uint8_t datalen;
  13. uint8_t data[];
  14. /* int8_t checksum;*/
  15. } zcr_cmd_header_t;
  16. #pragma pack(pop)
  17. typedef enum {
  18. kptv2_cmd = 0xA0,
  19. kptv2_ack = 0xA1,
  20. kptv2_error_ack = 0xA2,
  21. kptv2_event = 0xA3,
  22. } zcan_cmd_packet_type_t;
  23. static inline bool zcr_cmd_checkpacket(const zcr_cmd_header_t* header, int len) {
  24. if (len < sizeof(zcr_cmd_header_t)) {
  25. return false;
  26. }
  27. if ((header->datalen + sizeof(zcr_cmd_header_t) + 1) != len) {
  28. return false;
  29. }
  30. uint8_t* rawpacket = (uint8_t*)header;
  31. uint8_t checksum = 0;
  32. for (int i = 0; i < len - 1; i++) {
  33. checksum += rawpacket[i];
  34. }
  35. if (checksum != rawpacket[len - 1]) {
  36. return false;
  37. }
  38. return true;
  39. }
  40. } // namespace zcr
  41. } // namespace iflytop