|
|
//
// Created by zwsd
//
#pragma once
#include "cmd.hpp"
#include "iflytop/core/core.hpp"
#include "zcanreceiverhost.hpp"
namespace iflytop {
using namespace std; using namespace zcr; using namespace core; typedef enum { kcmd_ping = 0, kcmd_read_io = 1, kcmd_set_io = 2, kcmd_readadc_raw = 3,
kcmd_m211887_operation = 1000, // 维萨拉压力传感器
kcmd_read_presure_sensor = 1001, kcmd_triple_warning_light_ctl = 1002, kcmd_high_power_electrical_ctl = 1003, kcmd_peristaltic_pump_ctl = 1004, kcmd_read_huacheng_pressure_sensor = 1005, kcmd_set_proportional_valve = 1006, // 设置比例阀 {4:valveId,4:valveValue}
kcmd_air_compressor_ch_select = 1007, // 空压机通道选择 {4:val}
kcmd_air_compressor_valve1_set = 1008, // 空压机阀门1控制 {4:val}
kcmd_air_compressor_valve2_set = 1009, // 空压机阀门2控制 {4:val}
kcmd_air_compressor_read_pressure = 1010, // 空压机阀读取压力 {}{4:val}
} CmdID_t;
class ZCanHost { ENABLE_LOGGER(ZCanHost);
public: private: shared_ptr<ZCanReceiverHost> m_zcanReceiverHost;
map<string, function<bool(int argc, char** argv, string& retval)>> m_cmdMap;
bool m_writeio_cache[255];
int16_t m_pumpc1004_speed_cache[255];
public: void initialize(string can_if_name, int baudrate, bool enablLoopback); bool execcmd(string cmd, string& retval);
/*******************************************************************************
* CMD * *******************************************************************************/ /**
* @brief 0-1000 Command support */ int32_t ping(int board_id);
int32_t readio(int id, bool& value);
int32_t writeio(int id, bool value); bool read_writeio_state_cache(int id);
int32_t readadc(int id, int& value);
// 读取M211887(维萨拉)传感器信息
typedef struct { int16_t hydrogen_peroxide_volume; // ppm 0x0100 过氧化氢浓度
int16_t h2o_h2o2_rs; // %RS * 100 0x0101 过氧化氢相对饱和度
int16_t temperature1; // °C * 100 0x0102 温度
int16_t relative_humidity; // %RH * 100 0x0103 相对湿度
int16_t absolute_hydrogen_peroxide; // mg/m3 0x0104
int16_t h2o_h2o2dew_point_temperature; // °C * 100
int16_t reserved1; //
int16_t water_volume; // ppm
int16_t water_vapor_pressure; // hpa
int16_t absolute_humidity; // g/m3
int16_t water_vapor_saturation_pressure_h2o; // hpa
int16_t temperature2; // °C * 100
int16_t h2o2_vapor_pressure; // hpa
int16_t water_vapor_saturation_pressure_h2o_h2o2; // hpa
} hpp272_data_t;
int32_t hpp272_read_c1000(int sensorid, hpp272_data_t& value);
/**
* @brief 报警三色指示灯控制 * * @param sensorid * @param r * @param g * @param b * @param w */ int32_t warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, uint8_t b, uint8_t w); // 1004
int32_t pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm); int32_t pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm, int8_t idlepower, int8_t power);
int16_t pumpctrl_c1004_get_speed_cache(int id);
/**
* @brief 读取华成压力传感器数值 * * @param sensorid * @param value */ typedef struct { uint8_t precision; // 0,1,2,3
uint8_t unit; // 0-Mpa ,1-Kpa ,2-Pa ,3-Bar ,4-Mbar ,5-kg/cm2 ,6-psi ,7-mh2o ,8-mmh2o
int16_t value; // value, realvalue = value / 10^precision unit
int16_t zero; // 零点
int16_t full; // 满量程
} huacheng_pressure_sensor_read_c1005_t; int32_t huacheng_pressure_sensor_get_pa(huacheng_pressure_sensor_read_c1005_t* rawdata) { if (rawdata->unit == 0) { int32_t pa = (int32_t)rawdata->value / (pow(10.0, rawdata->precision)) * 1000000; return pa; } else if (rawdata->unit == 1) { int32_t pa = (int32_t)rawdata->value / (pow(10.0, rawdata->precision)) * 1000; return pa; } else if (rawdata->unit == 2) { int32_t pa = (int32_t)rawdata->value / (pow(10.0, rawdata->precision)); return pa; } return -1; } int32_t huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressure_sensor_read_c1005_t& value);
int32_t call(int32_t cmdid); int32_t call(int32_t cmdid, int32_t val0); int32_t call(int32_t cmdid, int32_t val0, int32_t val1);
int32_t call(int32_t cmdid, int32_t* ack); int32_t call(int32_t cmdid, int32_t val0, int32_t* ack); int32_t call(int32_t cmdid, int32_t val0, int32_t val1, int32_t* ack);
private: int32_t call(int32_t cmdid, int32_t* val0, int32_t nval, int32_t* ack, int32_t* acknum); };
} // namespace iflytop
|