rs485.h 2.6 KB

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