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.

74 lines
2.0 KiB

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. /*******************************************************************************
  8. * ָͨ *
  9. *******************************************************************************/
  10. #define PACKET_HEADER 0x5A5A
  11. #define PACKET_TAIL 0xA5A5
  12. #define PROTOCOL_VERSION 1
  13. /**
  14. *
  15. * ЭΪ:
  16. * ͷ(2Byte) (2Byte) Index(2Byte) ָ(2Byte ndata(2byte) data[...] У(1Byte) β(2Byte)
  17. *
  18. */
  19. typedef struct {
  20. uint16_t packet_header;
  21. uint16_t packet_type; // zaf_protocol_packet_type_t
  22. uint16_t index; //
  23. uint16_t cmd; // zaf_protocol_cmd_t
  24. uint16_t ndata; //
  25. uint32_t data[]; // first is always checksum
  26. } zaf_packet_header_t;
  27. #pragma pack()
  28. /**
  29. * @brief CMD
  30. */
  31. typedef enum {
  32. kzaf_cmd_none = 0,
  33. kzaf_cmd_reg_read = 1,
  34. kzaf_cmd_reg_write = 2,
  35. kzaf_cmd_reg_read_regs = 3,
  36. kzaf_cmd_generator_new_mac = 4,
  37. kzaf_cmd_factory_reset = 5,
  38. kzaf_cmd_reboot = 6,
  39. kzaf_cmd_storage_cfg = 7,
  40. } zaf_protocol_cmd_t;
  41. /**
  42. * @brief
  43. */
  44. typedef enum {
  45. kzaf_packet_type_cmd = 0,
  46. kzaf_packet_type_receipt = 1,
  47. kzaf_packet_type_report = 2,
  48. } zaf_protocol_packet_type_t;
  49. /*******************************************************************************
  50. * ҵ߼ö *
  51. *******************************************************************************/
  52. typedef enum {
  53. obtaining_ip_mode_type_static = 0,
  54. obtaining_ip_mode_type_dhcp = 1,
  55. } obtaining_ip_mode_t;
  56. static inline const char* obtaining_ip_mode_to_string(obtaining_ip_mode_t mode) {
  57. switch (mode) {
  58. case obtaining_ip_mode_type_static:
  59. return "static";
  60. case obtaining_ip_mode_type_dhcp:
  61. return "dhcp";
  62. default:
  63. return "unknown";
  64. }
  65. }