rs485.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 6 // 决定处理要素模型条数
  15. #define stemp "stemp"
  16. #define humi "humi"
  17. #define airpre "airpre"
  18. #define lux "lux"
  19. #define rain "rain"
  20. // #define weight "weight"
  21. /*********************↑ define ↑************************/
  22. /**
  23. *
  24. *
  25. *
  26. *
  27. * */
  28. /*********************↓ include ↓************************/
  29. /*********************↑ include ↑************************/
  30. /**
  31. *
  32. *
  33. *
  34. *
  35. * */
  36. /*********************↓ extern ↓************************/
  37. /*********************↑ extern ↑************************/
  38. /**
  39. *
  40. *
  41. *
  42. *
  43. * */
  44. /********************↓ declaration ↓***********************/
  45. typedef struct
  46. {
  47. char eKey[5]; //传感器通道号
  48. uint8_t sensor_addr; //从机地址
  49. uint16_t start_reg; //寄存器起始位置
  50. uint8_t count; //读取寄存器数量
  51. uint8_t d_pos; //数据偏移量
  52. int factor; //修正因子
  53. uint8_t d_length; //数据长度(单位uint16)
  54. int32_t value; //传感器数值
  55. char eName[15]; //传感器名称
  56. char eValue[10]; //传感器字符串形式数据
  57. // char eNum[5]; //服务器端 传感器代号
  58. uint8_t cfged; //参数已配置
  59. uint8_t online; //是否在线
  60. // uint8_t en_corr; //是否使能要素修正
  61. // int16_t plus; // +
  62. // int16_t minus; // -
  63. // int16_t times; // *
  64. // int16_t divide; // /
  65. }Sensor;
  66. typedef enum
  67. {
  68. s_Temp = 0,
  69. s_Humi ,
  70. s_Airpre,
  71. s_Lux ,
  72. s_Rain ,
  73. s_weight,
  74. s_ALL ,
  75. s_TypeMAX
  76. }Sensor_Read_Type;
  77. void RS485_SEND(uint8_t *buf, uint16_t size);
  78. Sensor_Read_Type get_sensor_num(char *cmd);
  79. int8_t READ_MODBUS_DATA_1(Sensor_Read_Type srt);
  80. /********************↑ declaration ↑***********************/
  81. /**
  82. *
  83. *
  84. *
  85. *
  86. * */
  87. /*********************↓ global variables ↓************************/
  88. /*********************↑ global variables ↑************************/
  89. /**
  90. *
  91. *
  92. *
  93. *
  94. * */
  95. #endif /* APPLICATIONS_RS485_H_ */