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.

48 lines
936 B

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