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.

54 lines
1.6 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. #pragma once
  2. #include <stdint.h>
  3. #define ZCANCMD_PACKET_MAX_LEN 64
  4. namespace iflytop {
  5. typedef enum {
  6. kboard = 0, // 板子
  7. khbot_module = 1, // hbot模块
  8. kwater_cooling_temperature_ctrl_module = 2, // 水冷温度控制
  9. kfan_ctrl_module = 3, // 风扇控制
  10. kcode_scaner = 4, // 扫码器
  11. ktmc_step_motor = 5, // 步进电机
  12. kmini_servo_motor_module = 6, // 舵机
  13. kpipette_ctrl_module = 7, // 移液体枪控制
  14. ka8000_optical_module = 100, // a8000光学模组
  15. ka8000_idcard_reader = 101, // id卡读卡器
  16. ka8000_plate_code_scaner = 102, // 反应板条扫码器
  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. uint16_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