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.

53 lines
1.4 KiB

5 months ago
5 months ago
5 months ago
  1. #pragma once
  2. #include <stdint.h>
  3. #define ZCANCMD_PACKET_MAX_LEN 64
  4. namespace iflytop {
  5. typedef enum {
  6. khbot_module = 1, // hbot模块
  7. ktemperature_ctrl_module = 3, // 温度控制
  8. kfan_ctrl_module = 5, // 风扇控制
  9. kcode_scaner = 6, // 扫码器
  10. kpipette_ctrl_module = 7, // 移液体枪控制
  11. ka8000_optical_module = 8, // a8000光学模组
  12. ktmc_step_motor = 10, // 步进电机
  13. kmini_servo_motor_module = 11, // 舵机
  14. kboard = 12, // 板子
  15. ka8000_idcard_reader = 13, // id卡读卡器
  16. ka8000_plate_code_scaner = 14, // 反应板条扫码器
  17. } module_type_t;
  18. namespace zcr {
  19. #pragma pack(push, 1)
  20. typedef struct {
  21. uint8_t packetType;
  22. uint16_t cmdid;
  23. uint8_t moduleId;
  24. uint8_t index;
  25. uint8_t datalen;
  26. uint8_t data[];
  27. /* int8_t checksum;*/
  28. } zcr_cmd_header_t;
  29. #pragma pack(pop)
  30. typedef enum {
  31. kptv2_cmd = 0xA0,
  32. kptv2_ack = 0xA1,
  33. kptv2_error_ack = 0xA2,
  34. kptv2_event = 0xA3,
  35. } zcan_cmd_packet_type_t;
  36. static inline bool zcr_cmd_checkpacket(const zcr_cmd_header_t* header, int len) {
  37. if (len < (int)sizeof(zcr_cmd_header_t)) return false;
  38. if ((int)(header->datalen + sizeof(zcr_cmd_header_t) + 1) != len) return false;
  39. uint8_t checksum = 0;
  40. for (int i = 0; i < len - 1; i++) checksum += ((uint8_t*)header)[i];
  41. return checksum == ((uint8_t*)header)[len - 1];
  42. }
  43. } // namespace zcr
  44. } // namespace iflytop