rs485.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-09-10 RuoFeng the first version
  9. */
  10. #ifndef APPLICATIONS_RS485_H_
  11. #define APPLICATIONS_RS485_H_
  12. /*********************↓ define ↓************************/
  13. #define rs_buf_max 64 // 串口接收缓存
  14. #define MAX_SENSOR_NUM (5 + 9) // 决定处理要素模型条数
  15. #define stemp "stemp"
  16. #define humi "humi"
  17. #define airpre "airpre"
  18. #define lux "lux"
  19. #define rain "rain"
  20. #define Stemp1 "soil_temp-1"
  21. #define Shumi1 "soil_humi-1"
  22. #define Stemp2 "soil_temp-2"
  23. #define Shumi2 "soil_humi-2"
  24. #define Stemp3 "soil_temp-3"
  25. #define Shumi3 "soil_humi-3"
  26. #define S_PH "soil_ph"
  27. #define S_Sail "salinity"
  28. #define S_SWP "SWP"
  29. /*********************↑ define ↑************************/
  30. /**
  31. *
  32. *
  33. *
  34. *
  35. * */
  36. /*********************↓ include ↓************************/
  37. /*********************↑ include ↑************************/
  38. /**
  39. *
  40. *
  41. *
  42. *
  43. * */
  44. /*********************↓ extern ↓************************/
  45. /*********************↑ extern ↑************************/
  46. /**
  47. *
  48. *
  49. *
  50. *
  51. * */
  52. /********************↓ declaration ↓***********************/
  53. typedef struct
  54. {
  55. char eKey[5]; // 传感器通道号
  56. uint8_t sensor_addr; // 从机地址
  57. uint16_t start_reg; // 寄存器起始位置
  58. uint8_t count; // 读取寄存器数量
  59. uint8_t d_pos; // 数据偏移量
  60. int factor; // 修正因子
  61. uint8_t d_length; // 数据长度(单位uint16)
  62. int32_t value; // 传感器数值
  63. char eName[15]; // 传感器名称
  64. char eValue[10]; // 传感器字符串形式数据
  65. // char eNum[5]; //服务器端 传感器代号
  66. uint8_t cfged; // 参数已配置
  67. uint8_t online; // 是否在线
  68. // uint8_t en_corr; //是否使能要素修正
  69. // int16_t plus; // +
  70. // int16_t minus; // -
  71. // int16_t times; // *
  72. // int16_t divide; // /
  73. } Sensor;
  74. typedef enum
  75. {
  76. s_Temp = 0,
  77. s_Humi,
  78. s_Airpre,
  79. s_Lux,
  80. s_Rain,
  81. //250816 开始新增
  82. s_Stemp1,
  83. s_Shumi1,
  84. s_Stemp2,
  85. s_Shumi2,
  86. s_Stemp3,
  87. s_Shumi3,
  88. s_S_PH,
  89. s_S_sail,
  90. s_SWP,
  91. s_ALL,
  92. s_TypeMAX
  93. } Sensor_Read_Type;
  94. void RS485_SEND(uint8_t *buf, uint16_t size);
  95. Sensor_Read_Type get_sensor_num(char *cmd);
  96. int8_t READ_MODBUS_DATA_1(Sensor_Read_Type srt);
  97. /********************↑ declaration ↑***********************/
  98. /**
  99. *
  100. *
  101. *
  102. *
  103. * */
  104. /*********************↓ global variables ↓************************/
  105. /*********************↑ global variables ↑************************/
  106. /**
  107. *
  108. *
  109. *
  110. *
  111. * */
  112. #endif /* APPLICATIONS_RS485_H_ */