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.

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