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.

63 lines
1.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #pragma once
  2. #include <stdint.h>
  3. #include "zaf_ecode.h"
  4. #include "zaf_port.h"
  5. #include "zaf_regs.hpp"
  6. #pragma pack(1)
  7. #define VERSION(main, sub, fix) (main << 16 | sub << 8 | fix << 0)
  8. #define VERSION_MAIN(v) ((v >> 16) & 0xFF)
  9. #define VERSION_SUB(v) ((v >> 8) & 0xFF)
  10. #define VERSION_FIX(v) ((v >> 0) & 0xFF)
  11. #define PACKET_HEADER 0x5A5A
  12. #define PACKET_TAIL 0xA5A5
  13. typedef struct {
  14. uint16_t packet_header;
  15. uint16_t packet_type; // zaf_protocol_packet_type_t
  16. uint16_t index; //
  17. uint16_t cmd; // zaf_protocol_cmd_t
  18. uint16_t ndata; //
  19. uint32_t data[]; // first is always checksum
  20. } zaf_packet_header_t;
  21. #pragma pack()
  22. /**
  23. * @brief CMD
  24. */
  25. typedef enum {
  26. kzaf_cmd_none = 0,
  27. kzaf_cmd_reg_read = 1,
  28. kzaf_cmd_reg_write = 2,
  29. kzaf_cmd_reg_read_regs = 3,
  30. kzaf_cmd_generator_new_mac = 4,
  31. kzaf_cmd_factory_reset = 5,
  32. kzaf_cmd_reboot = 6,
  33. kzaf_cmd_storage_cfg = 7,
  34. } zaf_protocol_cmd_t;
  35. typedef enum {
  36. kzaf_packet_type_cmd = 0,
  37. kzaf_packet_type_receipt = 1,
  38. kzaf_packet_type_report = 2,
  39. kzaf_packet_type_heart = 3,
  40. } zaf_protocol_packet_type_t;
  41. typedef enum {
  42. obtaining_ip_mode_type_static = 0,
  43. obtaining_ip_mode_type_dhcp = 1,
  44. } obtaining_ip_mode_t;
  45. static inline const char* obtaining_ip_mode_to_string(obtaining_ip_mode_t mode) {
  46. switch (mode) {
  47. case obtaining_ip_mode_type_static:
  48. return "static";
  49. case obtaining_ip_mode_type_dhcp:
  50. return "dhcp";
  51. default:
  52. return "unknown";
  53. }
  54. }