From a2dc4e648f8cf55f1c4fb34ff6179dcb6a8b5ba5 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 12 May 2024 21:37:08 +0800 Subject: [PATCH] init --- usrc/base/device_info.cpp | 15 +++++++++++++-- usrc/base/hardware.cpp | 26 ++++++++++++++++++++++++-- usrc/base/hardware.hpp | 15 ++++++++++++++- usrc/project_configs.h | 21 +++++++++++---------- usrc/protocol_impl/protocol_impl_service.cpp | 19 +++++++++++++++++++ zsdk | 2 +- 6 files changed, 82 insertions(+), 16 deletions(-) diff --git a/usrc/base/device_info.cpp b/usrc/base/device_info.cpp index 3fcf499..09a1711 100644 --- a/usrc/base/device_info.cpp +++ b/usrc/base/device_info.cpp @@ -1,9 +1,20 @@ #include "device_info.hpp" #include "iflytop_canbus_protocol/iflytop_canbus_protocol.hpp" +#include "zsdk/zsdk.hpp" -uint16_t deviceInfo_init() { return 0; } -uint16_t deviceInfo_getBoardId() { return DEVICE_ID; } +using namespace iflytop; + +static ZGPIO id_from_machine; // 消毒机上的开关 + +uint16_t deviceInfo_init() { + id_from_machine.initAsInput(DEVICE_ID_OFF_PIN, kxs_gpio_nopull, kxs_gpio_no_irq, false); + return 0; +} +uint16_t deviceInfo_getBoardId() { + int32_t off = id_from_machine.read() ? 1 : 0; + return DEVICE_ID_START + off; +} uint16_t deviceInfo_getProjectId() { return PROJECT_ID; } uint16_t deviceInfo_getBoardType() { return BOARD_TYPE; } uint16_t deviceInfo_getProtocolVersion() { return PROTOCOL_VERSION; } diff --git a/usrc/base/hardware.cpp b/usrc/base/hardware.cpp index 6c22290..aae59c6 100644 --- a/usrc/base/hardware.cpp +++ b/usrc/base/hardware.cpp @@ -11,12 +11,13 @@ using namespace iflytop; ***********************************************************************************************************************/ static osThreadId H2O2CaptureThreadId; -static osThreadId AdcCaptureThreadId; +static osThreadId AlarmLightThreadId; /*********************************************************************************************************************** * FUNC * ***********************************************************************************************************************/ static void c_onH2O2CaptureThread(void const* argument) { Hardware::ins().onH2O2CaptureThread(); } +static void c_onAlarmLightThread(void const* argument) { Hardware::ins().onAlarmLightThread(); } int32_t Hardware::readSwitchGroup() { int32_t id = 0; @@ -33,6 +34,8 @@ void Hardware::setAlarmLight(bool r, bool g, bool y) { m_alarmLightY.write(y); } +void Hardware::setAlarmLight(light_state_t state) { m_alarmLightState = state; } + void Hardware::init() { m_alarmLightR.initAsOutput(PD7, kxs_gpio_nopull, true, false); m_alarmLightG.initAsOutput(PD9, kxs_gpio_nopull, true, false); @@ -48,6 +51,7 @@ void Hardware::init() { ZLOGI(TAG, "switch group:%d id_from_machine %d", readSwitchGroup(), id_from_machine.read()); + setAlarmLight(kdisconnected); /** * @brief 探测HMP110 */ @@ -92,6 +96,9 @@ void Hardware::init() { osThreadDef(H2O2CaptureThread, c_onH2O2CaptureThread, osPriorityNormal, 0, 1024); H2O2CaptureThreadId = osThreadCreate(osThread(H2O2CaptureThread), NULL); + + osThreadDef(AlarmLightThread, c_onAlarmLightThread, osPriorityNormal, 0, 1024); + AlarmLightThreadId = osThreadCreate(osThread(AlarmLightThread), NULL); } /*********************************************************************************************************************** @@ -207,4 +214,19 @@ void Hardware::onH2O2CaptureThread() { } #endif } -} \ No newline at end of file +} + +void Hardware::onAlarmLightThread() { + while (1) { + osDelay(100); + if (m_alarmLightState == kdisconnected) { + static bool state; + setAlarmLight(false, state, false); + state = !state; + } else if (m_alarmLightState == kconnected) { + setAlarmLight(true, true, false); + } else if (m_alarmLightState == kerror) { + setAlarmLight(true, false, false); + } + } +} diff --git a/usrc/base/hardware.hpp b/usrc/base/hardware.hpp index f040581..29ceb81 100644 --- a/usrc/base/hardware.hpp +++ b/usrc/base/hardware.hpp @@ -15,7 +15,15 @@ void hardware_init(); namespace iflytop { + +typedef enum { + kdisconnected, + kconnected, + kerror, +} light_state_t; + class Hardware { + public: #ifdef H2O2_SENSOR_TYPE_HMP110 ModbusBlockHost m_H2o2Sensor_ModbusBlockHost; // ZADC m_H2o2Sensor_H2O2Adc; // H2O2传感器控制 @@ -42,6 +50,8 @@ class Hardware { ZGPIO id_from_machine; // 消毒机上的开关 + light_state_t m_alarmLightState = kdisconnected; + public: static Hardware& ins() { static Hardware ins; @@ -50,9 +60,11 @@ class Hardware { void init(); - void setAlarmLight(bool r, bool g, bool y); int32_t readSwitchGroup(); + void setAlarmLight(bool r, bool g, bool y); + void setAlarmLight(light_state_t state); + bool h2o2_sensor_is_online(); int32_t h2o2_sensor_read_calibration_date(int32_t* year, int32_t* month, int32_t* day); int32_t h2o2_sensor_read_sub_ic_errorcode(); @@ -61,6 +73,7 @@ class Hardware { public: void onH2O2CaptureThread(); + void onAlarmLightThread(); }; } // namespace iflytop diff --git a/usrc/project_configs.h b/usrc/project_configs.h index d2268ff..4eca88e 100644 --- a/usrc/project_configs.h +++ b/usrc/project_configs.h @@ -18,16 +18,17 @@ * @brief 基础配置 * */ -#define SOFTWARE_VERSION 1 // 软件版本 -#define HARDWARE_VERSION 1 // 硬件版本 -#define PROJECT "h2o2_ext_sensor" // 工程名称 -#define SN_HEADER "SN" // SN号前缀 -#define DEVICE_ID (kFixBoardId_H2O2SensorStart) // 设备ID -#define PROJECT_ID kh2o2_ext_sensor // 项目ID -#define BOARD_TYPE kBoardType_H2O2Sensor // 板子类型 -#define DEBUG_UART huart1 // 调试串口 -#define DEBUG_LIGHT_GPIO PE2 // 调试指示灯 - +#define SOFTWARE_VERSION 1 // 软件版本 +#define HARDWARE_VERSION 1 // 硬件版本 +#define PROJECT "h2o2_ext_sensor" // 工程名称 +#define SN_HEADER "SN" // SN号前缀 +#define PROJECT_ID kh2o2_ext_sensor // 项目ID +#define BOARD_TYPE kBoardType_H2O2Sensor // 板子类型 +#define DEBUG_UART huart1 // 调试串口 +#define DEBUG_LIGHT_GPIO PE2 // 调试指示灯 // #define H2O2_SENSOR_TYPE_HPP272 #define H2O2_SENSOR_TYPE_HMP110 + +#define DEVICE_ID_START (kFixBoardId_H2O2SensorStart) // 设备ID +#define DEVICE_ID_OFF_PIN PE8 // 设备ID偏移引脚 \ No newline at end of file diff --git a/usrc/protocol_impl/protocol_impl_service.cpp b/usrc/protocol_impl/protocol_impl_service.cpp index f75c495..20578e8 100644 --- a/usrc/protocol_impl/protocol_impl_service.cpp +++ b/usrc/protocol_impl/protocol_impl_service.cpp @@ -10,6 +10,7 @@ using namespace iflytop; ***********************************************************************************************************************/ static osThreadId PacketRxThreadId; +static osThreadId DeviceStateMonitorThreadId; static void onPacketRxThreadStart(void const* argument) { while (true) { @@ -18,6 +19,21 @@ static void onPacketRxThreadStart(void const* argument) { } } +static void onDeviceStateMonitorThreadStart(void const* argument) { + while (true) { + osDelay(1000); + if (Hardware::ins().h2o2_sensor_read_sub_ic_errorcode() != 0) { + Hardware::ins().setAlarmLight(kerror); + } else { + if (zcanbus_is_connected()) { + Hardware::ins().setAlarmLight(kconnected); + } else { + Hardware::ins().setAlarmLight(kdisconnected); + } + } + } +} + static void zcanbus_on_rx(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { // zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; ZLOGI(TAG, "process packet from %d to %d, function_id %d, len %d", from, to, packet->function_id, len); @@ -62,4 +78,7 @@ void protocol_impl_service_init() { // osThreadDef(PacketRxThread, onPacketRxThreadStart, osPriorityNormal, 0, 1024); PacketRxThreadId = osThreadCreate(osThread(PacketRxThread), NULL); + + osThreadDef(DeviceStateMonitorThread, onDeviceStateMonitorThreadStart, osPriorityNormal, 0, 1024); + DeviceStateMonitorThreadId = osThreadCreate(osThread(DeviceStateMonitorThread), NULL); } diff --git a/zsdk b/zsdk index c2474e3..71777bf 160000 --- a/zsdk +++ b/zsdk @@ -1 +1 @@ -Subproject commit c2474e3a744e93d4deec57effbc10f66f187b7eb +Subproject commit 71777bf1162edf229517047c572d2a401ce37ee3