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.

143 lines
5.0 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. //
  2. // Created by zwsd
  3. //
  4. #pragma once
  5. #include "cmd.hpp"
  6. #include "iflytop/core/core.hpp"
  7. #include "zcanreceiverhost.hpp"
  8. namespace iflytop {
  9. using namespace std;
  10. using namespace zcr;
  11. using namespace core;
  12. typedef enum {
  13. kcmd_ping = 0,
  14. kcmd_read_io = 1,
  15. kcmd_set_io = 2,
  16. kcmd_readadc_raw = 3,
  17. kcmd_m211887_operation = 1000, // 维萨拉压力传感器
  18. kcmd_read_presure_sensor = 1001,
  19. kcmd_triple_warning_light_ctl = 1002,
  20. kcmd_high_power_electrical_ctl = 1003,
  21. kcmd_peristaltic_pump_ctl = 1004,
  22. kcmd_read_huacheng_pressure_sensor = 1005,
  23. kcmd_set_proportional_valve = 1006, // 设置比例阀 {4:valveId,4:valveValue}
  24. kcmd_air_compressor_ch_select = 1007, // 空压机通道选择 {4:val}
  25. kcmd_air_compressor_valve1_set = 1008, // 空压机阀门1控制 {4:val}
  26. kcmd_air_compressor_valve2_set = 1009, // 空压机阀门2控制 {4:val}
  27. kcmd_air_compressor_read_pressure = 1010, // 空压机阀读取压力 {}{4:val}
  28. } CmdID_t;
  29. class ZCanHost {
  30. ENABLE_LOGGER(ZCanHost);
  31. public:
  32. private:
  33. shared_ptr<ZCanReceiverHost> m_zcanReceiverHost;
  34. map<string, function<bool(int argc, char** argv, string& retval)>> m_cmdMap;
  35. bool m_writeio_cache[255];
  36. int16_t m_pumpc1004_speed_cache[255];
  37. public:
  38. void initialize(string can_if_name, int baudrate, bool enablLoopback);
  39. bool execcmd(string cmd, string& retval);
  40. /*******************************************************************************
  41. * CMD *
  42. *******************************************************************************/
  43. /**
  44. * @brief 0-1000 Command support
  45. */
  46. int32_t ping(int board_id);
  47. int32_t readio(int id, bool& value);
  48. int32_t writeio(int id, bool value);
  49. bool read_writeio_state_cache(int id);
  50. int32_t readadc(int id, int& value);
  51. // 读取M211887(维萨拉)传感器信息
  52. typedef struct {
  53. int16_t hydrogen_peroxide_volume; // ppm 0x0100 过氧化氢浓度
  54. int16_t h2o_h2o2_rs; // %RS * 100 0x0101 过氧化氢相对饱和度
  55. int16_t temperature1; // °C * 100 0x0102 温度
  56. int16_t relative_humidity; // %RH * 100 0x0103 相对湿度
  57. int16_t absolute_hydrogen_peroxide; // mg/m3 0x0104
  58. int16_t h2o_h2o2dew_point_temperature; // °C * 100
  59. int16_t reserved1; //
  60. int16_t water_volume; // ppm
  61. int16_t water_vapor_pressure; // hpa
  62. int16_t absolute_humidity; // g/m3
  63. int16_t water_vapor_saturation_pressure_h2o; // hpa
  64. int16_t temperature2; // °C * 100
  65. int16_t h2o2_vapor_pressure; // hpa
  66. int16_t water_vapor_saturation_pressure_h2o_h2o2; // hpa
  67. } hpp272_data_t;
  68. int32_t hpp272_read_c1000(int sensorid, hpp272_data_t& value);
  69. /**
  70. * @brief
  71. *
  72. * @param sensorid
  73. * @param r
  74. * @param g
  75. * @param b
  76. * @param w
  77. */
  78. int32_t warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, uint8_t b, uint8_t w);
  79. // 1004
  80. int32_t pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm);
  81. int32_t pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm, int8_t idlepower, int8_t power);
  82. int16_t pumpctrl_c1004_get_speed_cache(int id);
  83. /**
  84. * @brief
  85. *
  86. * @param sensorid
  87. * @param value
  88. */
  89. typedef struct {
  90. uint8_t precision; // 0,1,2,3
  91. uint8_t unit; // 0-Mpa ,1-Kpa ,2-Pa ,3-Bar ,4-Mbar ,5-kg/cm2 ,6-psi ,7-mh2o ,8-mmh2o
  92. int16_t value; // value, realvalue = value / 10^precision unit
  93. int16_t zero; // 零点
  94. int16_t full; // 满量程
  95. } huacheng_pressure_sensor_read_c1005_t;
  96. int32_t huacheng_pressure_sensor_get_pa(huacheng_pressure_sensor_read_c1005_t* rawdata) {
  97. if (rawdata->unit == 0) {
  98. int32_t pa = (int32_t)rawdata->value / (pow(10.0, rawdata->precision)) * 1000000;
  99. return pa;
  100. } else if (rawdata->unit == 1) {
  101. int32_t pa = (int32_t)rawdata->value / (pow(10.0, rawdata->precision)) * 1000;
  102. return pa;
  103. } else if (rawdata->unit == 2) {
  104. int32_t pa = (int32_t)rawdata->value / (pow(10.0, rawdata->precision));
  105. return pa;
  106. }
  107. return -1;
  108. }
  109. int32_t huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressure_sensor_read_c1005_t& value);
  110. int32_t call(int32_t cmdid);
  111. int32_t call(int32_t cmdid, int32_t val0);
  112. int32_t call(int32_t cmdid, int32_t val0, int32_t val1);
  113. int32_t call(int32_t cmdid, int32_t* ack);
  114. int32_t call(int32_t cmdid, int32_t val0, int32_t* ack);
  115. int32_t call(int32_t cmdid, int32_t val0, int32_t val1, int32_t* ack);
  116. private:
  117. int32_t call(int32_t cmdid, int32_t* val0, int32_t nval, int32_t* ack, int32_t* acknum);
  118. };
  119. } // namespace iflytop