10 changed files with 280 additions and 208 deletions
-
10.cproject
-
1usrc/app_main.cpp
-
67usrc/module/heater_controller.cpp
-
70usrc/module/heater_controller.hpp
-
91usrc/module/pxxpsbus.cpp
-
91usrc/module/pxxpsbus.hpp
-
61usrc/module/warning_light_driver.cpp
-
57usrc/module/warning_light_driver.hpp
-
22usrc/module/water_sensor_mgr.cpp
-
18usrc/module/water_sensor_mgr.hpp
@ -0,0 +1,67 @@ |
|||
#include "heater_controller.hpp"
|
|||
|
|||
#include "base/appdep.hpp"
|
|||
using namespace iflytop; |
|||
using namespace transmit_disfection_protocol; |
|||
|
|||
void HeaterController::initialize(Pin_t ctrlGpio, ADC_HandleTypeDef* iadc, uint32_t ich, ADC_HandleTypeDef* tadc, uint32_t tch) { |
|||
m_ctrlGpio.initAsOutput(ctrlGpio, kxs_gpio_nopull, true, false); |
|||
m_iAdc.initialize("heater-idac", iadc, ich); |
|||
m_tempAdc.initialize("heater-tadc", iadc, tch); |
|||
m_isInitialized = true; |
|||
AppPeriodTaskMgr::ins()->regTask("Heater-ADC", [this]() { periodTask(); }, 1000); |
|||
|
|||
BIND_FN(HeaterController, this, fn_heater_ctrl); |
|||
BIND_FN(HeaterController, this, fn_heater_ctrl_safe_valve); |
|||
BIND_FN(HeaterController, this, fn_heater_read_ei); |
|||
BIND_FN(HeaterController, this, fn_heater_read_temperature_data); |
|||
BIND_FN(HeaterController, this, fn_heater_read_ei_adc_raw); |
|||
BIND_FN(HeaterController, this, fn_heater_read_temperature_data_adc_raw); |
|||
BIND_FN(HeaterController, this, fn_heater_is_open); |
|||
} |
|||
|
|||
bool HeaterController::isInitialized() { return m_isInitialized; } |
|||
|
|||
void HeaterController::heater_ctrl(int32_t val) { m_ctrlGpio.write(val); } |
|||
void HeaterController::heater_ctrl_safe_valve(int32_t val) {} |
|||
int32_t HeaterController::heater_read_temperature_data() { return heaterAdc2Temp(m_tempAdc.getCacheVal()); } |
|||
int32_t HeaterController::heater_read_ei() { return hearterAdcToCurrent(m_iAdc.getCacheVal()); } |
|||
int32_t HeaterController::heater_read_iadc() { return m_iAdc.getCacheVal(); } |
|||
int32_t HeaterController::heater_read_tadc() { return m_tempAdc.getCacheVal(); } |
|||
|
|||
// PP
|
|||
void HeaterController::fn_heater_ctrl(ProcessContext* cxt) { //
|
|||
heater_ctrl(GET_PARAM(0)); |
|||
zcanbus_send_ack(cxt->packet, NULL, 0); |
|||
} |
|||
void HeaterController::fn_heater_ctrl_safe_valve(ProcessContext* cxt) { //
|
|||
heater_ctrl_safe_valve(GET_PARAM(0)); |
|||
zcanbus_send_ack(cxt->packet, NULL, 0); |
|||
} |
|||
void HeaterController::fn_heater_read_ei(ProcessContext* cxt) { //
|
|||
auto val = heater_read_ei(); |
|||
zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); |
|||
} |
|||
void HeaterController::fn_heater_read_temperature_data(ProcessContext* cxt) { //
|
|||
auto val = heater_read_temperature_data(); |
|||
|
|||
zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); |
|||
} |
|||
|
|||
void HeaterController::fn_heater_read_ei_adc_raw(ProcessContext* cxt) { //
|
|||
auto val = m_iAdc.getCacheVal(); |
|||
zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); |
|||
} |
|||
|
|||
void HeaterController::fn_heater_read_temperature_data_adc_raw(ProcessContext* cxt) { //
|
|||
auto val = m_tempAdc.getCacheVal(); |
|||
zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); |
|||
} |
|||
void HeaterController::fn_heater_is_open(ProcessContext* cxt) { //
|
|||
zcanbus_send_ack(cxt->packet, m_ctrlGpio.read()); |
|||
} |
|||
|
|||
void HeaterController::periodTask() { |
|||
m_iAdc.updateAdcValToCache(); |
|||
m_tempAdc.updateAdcValToCache(); |
|||
} |
@ -0,0 +1,91 @@ |
|||
#include "pxxpsbus.hpp"
|
|||
using namespace iflytop; |
|||
using namespace transmit_disfection_protocol; |
|||
|
|||
void PXXPSBus::initialize(UART_HandleTypeDef* huart) { |
|||
psbus.init(huart); |
|||
m_isInitialized = true; |
|||
|
|||
osTimerDef(reportTimer, onTimer); |
|||
reportTimerId = osTimerCreate(osTimer(reportTimer), osTimerPeriodic, this); |
|||
|
|||
BIND_FN(PXXPSBus, this, fn_psbus_read_data); |
|||
BIND_FN(PXXPSBus, this, fn_psbus_scan); |
|||
BIND_FN(PXXPSBus, this, fn_psbus_start_report); |
|||
BIND_FN(PXXPSBus, this, fn_psbus_stop_report); |
|||
} |
|||
bool PXXPSBus::isInitialized() { return m_isInitialized; } |
|||
|
|||
void PXXPSBus::fn_psbus_read_data(ProcessContext* cxt) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 1); |
|||
int32_t index = GET_PARAM(0); |
|||
|
|||
int16_t val = 0; |
|||
int32_t reportVal = 0; |
|||
bool suc = psbus.readData(index, &val); |
|||
|
|||
reportVal = val; |
|||
|
|||
if (suc) { |
|||
zcanbus_send_ack(cxt->packet, (uint8_t*)&reportVal, sizeof(reportVal)); |
|||
} else { |
|||
zcanbus_send_errorack(cxt->packet, kerr_subdevice_offline); |
|||
} |
|||
} |
|||
void PXXPSBus::fn_psbus_scan(ProcessContext* cxt) { |
|||
auto* sensors = psbus.sensors; |
|||
int numSensor = psbus.sensorNum; |
|||
|
|||
static ack_psbus_scan_t result; |
|||
memset(&result, 0, sizeof(result)); |
|||
static_assert(ZARRAY_SIZE(result.sensor) == ZARRAY_SIZE(psbus.sensors)); |
|||
result.numOnlineId = numSensor; |
|||
for (int i = 0; i < PXX_PRESSURE_SENSOR_NUM; i++) { |
|||
if (sensors[i].online) { |
|||
result.sensor[i].ptype = sensors[i].type; |
|||
result.sensor[i].subid = sensors[i].id; |
|||
result.sensor[i].isOnline = 1; |
|||
result.sensor[i].precision = sensors[i].p100_sensor_info.precision; |
|||
result.sensor[i].uint = sensors[i].p100_sensor_info.pressure_unit; |
|||
result.sensor[i].zero = sensors[i].p100_sensor_info.zero_point; |
|||
result.sensor[i].full = sensors[i].p100_sensor_info.range_full_point; |
|||
} |
|||
} |
|||
zcanbus_send_ack(cxt->packet, (uint8_t*)&result, sizeof(result)); |
|||
} |
|||
|
|||
void PXXPSBus::fn_psbus_start_report(ProcessContext* cxt) { |
|||
int period = GET_PARAM(0); |
|||
if (period < 100) period = 100; |
|||
osTimerStop(reportTimerId); |
|||
osTimerStart(reportTimerId, period); |
|||
zcanbus_send_ack(cxt->packet, nullptr, 0); |
|||
} |
|||
|
|||
void PXXPSBus::fn_psbus_stop_report(ProcessContext* cxt) { |
|||
osTimerStop(reportTimerId); |
|||
zcanbus_send_ack(cxt->packet, nullptr, 0); |
|||
} |
|||
|
|||
void PXXPSBus::onTimer(const void* tid) { |
|||
PXXPSBus* bus = (PXXPSBus*)pvTimerGetTimerID((TimerHandle_t)tid); |
|||
bus->onTimer(); |
|||
} |
|||
void PXXPSBus::onTimer() { |
|||
int16_t val = 0; |
|||
|
|||
static uint8_t report_buf[100]; |
|||
report_pressure_data_t* reportData = (report_pressure_data_t*)report_buf; |
|||
|
|||
reportData->sensorDataNum = 0; |
|||
for (int i = 0; i < PXX_PRESSURE_SENSOR_NUM; i++) { |
|||
if (psbus.sensors[i].online) { |
|||
psbus.readData(i, &val); |
|||
reportData->data[reportData->sensorDataNum].subid = psbus.sensors[i].id; |
|||
reportData->data[reportData->sensorDataNum].pressureVal = val; |
|||
reportData->sensorDataNum++; |
|||
} |
|||
} |
|||
zcanbus_send_report(kreport_pressure_data, (uint8_t*)reportData, //
|
|||
sizeof(*reportData) + sizeof(reportData->data[0]) * reportData->sensorDataNum, 30); |
|||
} |
@ -0,0 +1,61 @@ |
|||
#include "warning_light_driver.hpp"
|
|||
|
|||
#include "base/appdep.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
using namespace transmit_disfection_protocol; |
|||
|
|||
void WarningLightDriver::initialize(Pin_t r, Pin_t g, Pin_t b, Pin_t beep) { |
|||
triLight_R.initAsOutput(r, kxs_gpio_nopull, false, false); |
|||
triLight_G.initAsOutput(g, kxs_gpio_nopull, false, false); |
|||
triLight_B.initAsOutput(b, kxs_gpio_nopull, false, false); |
|||
triLight_BEEP.initAsOutput(beep, kxs_gpio_nopull, false, false); |
|||
m_isInitialized = true; |
|||
BIND_FN(WarningLightDriver, this, fn_triple_warning_light_ctl); |
|||
BIND_FN(WarningLightDriver, this, fn_triple_warning_light_read_state); |
|||
} |
|||
bool WarningLightDriver::isInitialized() { return m_isInitialized; } |
|||
|
|||
void WarningLightDriver::setRGBW(int32_t r, int32_t g, int32_t b, int32_t beep) { |
|||
if (r > 0) |
|||
triLight_R.write(1); |
|||
else |
|||
triLight_R.write(0); |
|||
|
|||
if (g > 0) |
|||
triLight_G.write(1); |
|||
else |
|||
triLight_G.write(0); |
|||
|
|||
if (b > 0) |
|||
triLight_B.write(1); |
|||
else |
|||
triLight_B.write(0); |
|||
|
|||
if (beep > 0) |
|||
triLight_BEEP.write(1); |
|||
else |
|||
triLight_BEEP.write(0); |
|||
} |
|||
|
|||
void WarningLightDriver::fn_triple_warning_light_ctl(ProcessContext* cxt) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 4); |
|||
|
|||
int32_t r = GET_PARAM(0); |
|||
int32_t g = GET_PARAM(1); |
|||
int32_t b = GET_PARAM(2); |
|||
int32_t warning = GET_PARAM(3); |
|||
|
|||
ZLOGI("WarningLightDriver", "triple_warning_light_ctl: r:%d g:%d b:%d warning:%d", r, g, b, warning); |
|||
setRGBW(r, g, b, warning); |
|||
zcanbus_send_ack(cxt->packet, NULL, 0); |
|||
} |
|||
// kfn_triple_warning_light_read_state
|
|||
void WarningLightDriver::fn_triple_warning_light_read_state(ProcessContext* cxt) { |
|||
int32_t data[4] = {0}; |
|||
data[0] = triLight_R.read(); |
|||
data[1] = triLight_G.read(); |
|||
data[2] = triLight_B.read(); |
|||
data[3] = triLight_BEEP.read(); |
|||
zcanbus_send_ack(cxt->packet, (uint8_t*)&data, sizeof(data)); |
|||
} |
@ -0,0 +1,22 @@ |
|||
#include "water_sensor_mgr.hpp"
|
|||
|
|||
#include "base/appdep.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
using namespace transmit_disfection_protocol; |
|||
|
|||
void WaterSensorMgr::initialize(Pin_t evaporationBinWSPin, Pin_t deviceBottomWSPin) { |
|||
evaporationBinWS.initAsInput(evaporationBinWSPin, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/); |
|||
deviceBottomWS.initAsInput(deviceBottomWSPin, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/); |
|||
m_isInitialized = true; |
|||
} |
|||
bool WaterSensorMgr::isInitialized() { return m_isInitialized; } |
|||
|
|||
void WaterSensorMgr::fn_evaporation_tank_water_sensor_read_state(ProcessContext* cxt) { |
|||
int32_t val = evaporationBinWS.read(); |
|||
zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); |
|||
} |
|||
void WaterSensorMgr::fn_device_bottom_water_sensor_read_state(ProcessContext* cxt) { |
|||
int32_t val = deviceBottomWS.read(); |
|||
zcanbus_send_ack(cxt->packet, (uint8_t*)&val, sizeof(val)); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue