/SmartIrrigation.h

https://github.com/ahappyforest/SmartIrrigation · C Header · 67 lines · 52 code · 11 blank · 4 comment · 0 complexity · e06e4a03c06aea7981ba5f4fc5826524 MD5 · raw file

  1. #ifndef SMART_IRRIGATION_H
  2. #define SMART_IRRIGATION_H
  3. #define RESERVED_LEN 1
  4. #define OFF 0
  5. #define ON 1
  6. #define AUTO 2
  7. #define REBOOT 3
  8. enum {
  9. AM_SENSOR_MSG = 7,
  10. AM_REQUEST_MSG = 8,
  11. AM_REPLY_MSG = 9,
  12. DISSEMINATE_REQ_KEY = 0x33,
  13. DISSEMINATE_REPLY_KEY = 0x44,
  14. // list of operation -> request_code
  15. SET_SWITCH_STATUS_REQUEST = 0x01, // 设置传感器开关
  16. GET_SWITCH_STATUS_REQUEST = 0x02, // 获取开关状态
  17. GET_READING_REQUEST = 0x03, // 获取传感器采集的数据
  18. SET_READING_PERIOD_REQUEST = 0x04, // 设置采集的周期
  19. GET_READING_PERIOD_REQUEST = 0x05, // 获取采集的周期
  20. SET_READING_THRESHOLD_REQUEST = 0x06, // 设置阈值
  21. GET_READING_THRESHOLD_REQUEST = 0x07, // 获取阈值
  22. // list of device number -> request_device
  23. SOLENOIDVALVES = 0x01, // 电磁阀门
  24. YL69 = 0x02, // 土壤湿度传感器
  25. LIGHT = 0x03, // 光照
  26. THERMISTOR = 0x04, // 空气中的温度
  27. DS18B20 = 0x05, // 土壤中的温度
  28. // 新添加
  29. WATERPUMP = 0x06, // 水泵
  30. };
  31. typedef struct sensor_msg {
  32. nx_uint16_t node_id;
  33. nx_uint8_t sensor_type;
  34. nx_uint32_t sensor_value;
  35. nx_uint16_t reserved[RESERVED_LEN];
  36. } sensor_msg_t;
  37. typedef struct request_msg {
  38. nx_uint16_t node_id;
  39. nx_uint16_t transaction_number;
  40. nx_uint8_t request_code;
  41. nx_uint8_t request_device;
  42. nx_uint16_t request_data;
  43. nx_uint16_t reserved[RESERVED_LEN];
  44. } request_msg_t;
  45. typedef struct reply_msg {
  46. nx_uint16_t node_id;
  47. nx_uint16_t transaction_number;
  48. // copy from request_msg
  49. nx_uint16_t request_code;
  50. nx_uint16_t request_device;
  51. nx_uint16_t request_data;
  52. nx_uint8_t status;
  53. nx_uint16_t remark; // 备注, 出现错误, 给出更具体的提示, 备用
  54. nx_uint16_t reserved[RESERVED_LEN];
  55. } reply_msg_t;
  56. #endif