From ddd73b10f1b1a37e9070413b8c8ccdf6fe23e08a Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 26 Aug 2024 17:00:44 +0800 Subject: [PATCH] update --- .vscode/settings.json | 11 ++- README.md | 10 --- app_protocols/app_protocols.h | 6 ++ app_protocols/appecode/errorcode.c | 53 ++++++++++++++ app_protocols/appecode/errorcode.h | 55 +++++++++++++++ app_protocols/bean/hand_acid_mode.c | 0 app_protocols/bean/hand_acid_mode.h | 6 ++ app_protocols/ble_through/ble_cmd_app.h | 54 +++++++++++++++ app_protocols/ble_through/ble_cmd_public.h | 71 +++++++++++++++++++ app_protocols/ble_through/ble_proto.h | 18 +++++ app_protocols/ble_through/ble_proto_packet.h | 54 +++++++++++++++ app_protocols/ble_through/ble_proto_utils.c | 80 ++++++++++++++++++++++ app_protocols/ble_through/ble_proto_utils.h | 33 +++++++++ .../hand_acid_val_protocol.h | 0 app_protocols/zscanprotocol | 2 +- stm32basic | 2 +- stm32components | 2 +- uappbase/appcfg/appcfg.hpp | 4 ++ uappbase/appdep.hpp | 6 ++ uappbase/base.hpp | 11 +-- uappbase/bean/bean.hpp | 2 + uappbase/bean/event.hpp | 24 +++++++ uappbase/service/app_event_bus.cpp | 34 +++++++++ uappbase/service/app_event_bus.hpp | 28 ++++++++ uappbase/service/gstate_mgr.hpp | 60 ++++++++++++++++ usrc/appcfg/appcfg.hpp | 2 - usrc/apphal/apphal.cpp | 2 +- usrc/apphal/apphal.hpp | 1 - usrc/service/app_core.cpp | 35 +++++++++- usrc/service/app_core.hpp | 2 +- 30 files changed, 638 insertions(+), 30 deletions(-) create mode 100644 app_protocols/app_protocols.h create mode 100644 app_protocols/appecode/errorcode.c create mode 100644 app_protocols/appecode/errorcode.h create mode 100644 app_protocols/bean/hand_acid_mode.c create mode 100644 app_protocols/bean/hand_acid_mode.h create mode 100644 app_protocols/ble_through/ble_cmd_app.h create mode 100644 app_protocols/ble_through/ble_cmd_public.h create mode 100644 app_protocols/ble_through/ble_proto.h create mode 100644 app_protocols/ble_through/ble_proto_packet.h create mode 100644 app_protocols/ble_through/ble_proto_utils.c create mode 100644 app_protocols/ble_through/ble_proto_utils.h create mode 100644 app_protocols/hand_acid_val_protocol/hand_acid_val_protocol.h create mode 100644 uappbase/appcfg/appcfg.hpp create mode 100644 uappbase/appdep.hpp create mode 100644 uappbase/bean/bean.hpp create mode 100644 uappbase/bean/event.hpp create mode 100644 uappbase/service/app_event_bus.cpp create mode 100644 uappbase/service/app_event_bus.hpp create mode 100644 uappbase/service/gstate_mgr.hpp delete mode 100644 usrc/appcfg/appcfg.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json index dbc3db6..7d1ac7e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -79,12 +79,11 @@ "usart.h": "c", "gins.h": "c", "common_hardware_init.h": "c", - "public_service.h": "c", - "stm32irq.h": "c", - "project_configs.h": "c", - "*.bak": "c", - "zflash.h": "c" + "pin.h": "c", + "stm32.h": "c", + "stm32f4xx_it.h": "c", + "ble_proto_utils.h": "c" }, "files.autoGuessEncoding": false, - "files.encoding": "utf8" + "files.encoding": "gb2312" } \ No newline at end of file diff --git a/README.md b/README.md index 1795bf3..407d286 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,6 @@ ``` -app/ 应用目录 -app/mainboard/basic 存放基础数据结构,基础数据服务,不涉及业务的基础服务。 - 例如结构体,不含有方法的类,数据存储。 - -BASIC_BOARD -BASIC -SERVICE/BOARD/ -SERVICE/PAGE,SERVICE - -UTILS diff --git a/app_protocols/app_protocols.h b/app_protocols/app_protocols.h new file mode 100644 index 0000000..5b150c5 --- /dev/null +++ b/app_protocols/app_protocols.h @@ -0,0 +1,6 @@ +#pragma once +#include "bean/hand_acid_mode.h" +#include "appecode/errorcode.h" +// +#include "zscanprotocol/zscanprotocol.h" +#include "hand_acid_val_protocol/hand_acid_val_protocol.h" \ No newline at end of file diff --git a/app_protocols/appecode/errorcode.c b/app_protocols/appecode/errorcode.c new file mode 100644 index 0000000..db148c2 --- /dev/null +++ b/app_protocols/appecode/errorcode.c @@ -0,0 +1,53 @@ +#include "errorcode.h" + +#define ERR2STR(code) \ + case code: \ + return #code; + + +#define ERR_ITERM(enum) \ + { enum, #enum } + +static ecode_table_item_t table[] = { + + ERR_ITERM(ksucc), + ERR_ITERM(kfail), + ERR_ITERM(kparam_out_of_range), + ERR_ITERM(kcmd_not_support), + ERR_ITERM(kdevice_is_busy), + ERR_ITERM(kdevice_is_offline), + ERR_ITERM(kovertime), + ERR_ITERM(knoack), + ERR_ITERM(kerrorack), + ERR_ITERM(kdevice_offline), + ERR_ITERM(ksubdevice_overtime), + ERR_ITERM(kbuffer_not_enough), + ERR_ITERM(kcmd_param_num_error), + ERR_ITERM(kcheckcode_is_error), + ERR_ITERM(killegal_operation), + + ERR_ITERM(kstep_motor_not_found_zero_point), + ERR_ITERM(kstep_motor_not_go_zero), + ERR_ITERM(kstep_motor_over_temperature), + ERR_ITERM(kstep_motor_over_voltage), + ERR_ITERM(kstep_motor_run_overtime), + ERR_ITERM(kstep_motor_not_enable), + ERR_ITERM(kstep_motor_ioindex_out_of_range), + ERR_ITERM(kstep_motor_subic_reset), + ERR_ITERM(kstep_motor_drv_err), + ERR_ITERM(kstep_motor_uv_cp), + ERR_ITERM(kstep_motor_not_found_point_edge), +}; + +const char* error2str(int32_t code) { + for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++) { + if (table[i].index == code) { + return table[i].info; + } + } + return "unknown error"; +} + +ecode_table_item_t* error_get_table() { return table; } +int error_get_table_size() { return sizeof(table) / sizeof(table[0]); } + diff --git a/app_protocols/appecode/errorcode.h b/app_protocols/appecode/errorcode.h new file mode 100644 index 0000000..d7c3ed4 --- /dev/null +++ b/app_protocols/appecode/errorcode.h @@ -0,0 +1,55 @@ +#pragma once +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define ERROR_CODE(errortype, suberrorcode) (errortype + suberrorcode) + +typedef enum { + + ksucc = 0, + kfail = 1, + + kparam_out_of_range = 102, + kcmd_not_support = 103, + kdevice_is_busy = 104, + kdevice_is_offline = 105, + kovertime = 106, + knoack = 107, + kerrorack = 108, + kdevice_offline = 109, + ksubdevice_overtime = 111, + kbuffer_not_enough = 112, + kcmd_param_num_error = 114, + kcheckcode_is_error = 115, + killegal_operation = 116, + + kstep_motor_not_found_zero_point = 600, + kstep_motor_not_go_zero = 601, + kstep_motor_over_temperature = 602, + kstep_motor_over_voltage = 603, + kstep_motor_run_overtime = 604, + kstep_motor_not_enable = 605, + kstep_motor_ioindex_out_of_range = 606, + kstep_motor_subic_reset = 607, + kstep_motor_drv_err = 608, + kstep_motor_uv_cp = 609, + kstep_motor_not_found_point_edge = 610, + +} error_t; + +typedef struct { + int index; + const char* info; +} ecode_table_item_t; + +const char* error2str(int32_t code); + +ecode_table_item_t* error_get_table(); +int error_get_table_size(); + +#ifdef __cplusplus +} +#endif diff --git a/app_protocols/bean/hand_acid_mode.c b/app_protocols/bean/hand_acid_mode.c new file mode 100644 index 0000000..e69de29 diff --git a/app_protocols/bean/hand_acid_mode.h b/app_protocols/bean/hand_acid_mode.h new file mode 100644 index 0000000..0d4dd1e --- /dev/null +++ b/app_protocols/bean/hand_acid_mode.h @@ -0,0 +1,6 @@ +#pragma once +typedef enum { + khand_acid_m_unset_mode = 0, // unset_mode + khand_acid_m_jog_mode = 1, // jog_mode + khand_acid_m_continuous_mode = 2, // continuous_mode +} hand_acid_mode_t; \ No newline at end of file diff --git a/app_protocols/ble_through/ble_cmd_app.h b/app_protocols/ble_through/ble_cmd_app.h new file mode 100644 index 0000000..34b2558 --- /dev/null +++ b/app_protocols/ble_through/ble_cmd_app.h @@ -0,0 +1,54 @@ +#pragma once +#include +#include +// +#include "app_protocols/bean/hand_acid_mode.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief + * + * cmd: + * 000->049 app_cmd + * 050->099 app_event_report + * + * 100->149 public_cmd + * 150->199 public_event_report + * + * + */ + +typedef enum { + kble_app_proto_cmd_sync_state = 1, // set_state + kble_app_proto_cmd_trigger_pump_start_event = 3, // + kble_app_proto_cmd_trigger_pump_stop_event = 4, // + kble_app_proto_cmd_trigger_reflux_start_event = 5, // + kble_app_proto_cmd_trigger_reflux_stop_event = 6, // + kble_app_proto_cmd_trigger_prepare_start_event = 7, // + kble_app_proto_cmd_trigger_prepare_stop_event = 8, // + kble_app_proto_cmd_read_version = 9, // + + kble_app_proto_report_reflux_butt_short_press_event = 50, // key_event + kble_app_proto_report_reflux_butt_long_press_event = 51, // key_event + kble_app_proto_report_action_butt_short_press_event = 52, // key_event + kble_app_proto_report_action_butt_long_press_event = 53, // key_event + kble_app_proto_report_client_heart = 54, // + +} ble_app_proto_cmd_t; +/*********************************************************************************************************************** + * ENUM * + ***********************************************************************************************************************/ +typedef struct { + uint8_t mode; +} ble_app_proto_cmd_sync_state_t; + +typedef struct { + uint8_t placeholder; +} ble_app_proto_report_client_heart_t; + +#ifdef __cplusplus +} +#endif diff --git a/app_protocols/ble_through/ble_cmd_public.h b/app_protocols/ble_through/ble_cmd_public.h new file mode 100644 index 0000000..a52e03b --- /dev/null +++ b/app_protocols/ble_through/ble_cmd_public.h @@ -0,0 +1,71 @@ +#pragma once +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief + * + * cmd: + * 000->049 app_cmd + * 050->099 app_event_report + * + * 100->149 public_cmd + * 150->199 public_event_report + * + * + */ + +typedef enum { + + kproto_cmd_ble_master_reset = 100, // process by ble master + kproto_cmd_ble_master_read_version = 101, // process by ble master ble_read_version_t + kproto_cmd_ble_master_start_scan = 102, // process by ble master + kproto_cmd_ble_master_stop_scan = 103, // process by ble master + kproto_cmd_ble_master_enter_dfu = 104, // process by ble master + kproto_cmd_ble_master_clear_reset_flag = 105, // process by ble master + + kproto_report_ble_master_connected_event = 150, // generator from ble master ble_connected_event_t + kproto_report_ble_master_scan_result = 151, // generator from ble master ble_scan_result_t + kproto_report_ble_master_power_on = 152, // generator from ble master ble_scan_result_t + kproto_report_ble_master_heart = 153, // generator from ble master ble_scan_result_t + +} ble_proto_public_cmd_t; +/*********************************************************************************************************************** + * ENUM * + ***********************************************************************************************************************/ +typedef struct { + uint8_t auto_connect; + uint8_t auto_connect_client_name[20]; +} ble_master_start_scan_t; + +typedef struct { + uint8_t connected; + char blename[20]; + char bleid[20]; +} ble_master_connected_event_t; + +typedef struct { + char blename[20]; + char bleid[20]; + uint8_t rssi; +} ble_master_scan_result_t; + +typedef struct { + int32_t firmware_version; + int32_t blestack_version; + int32_t bootloader_version; + int32_t hardware_version; +} ble_master_read_version_t; + +typedef struct { + uint8_t reset_flag; + uint8_t connected_flag; +} ble_master_heart_t; + +#ifdef __cplusplus +} +#endif diff --git a/app_protocols/ble_through/ble_proto.h b/app_protocols/ble_through/ble_proto.h new file mode 100644 index 0000000..402d22f --- /dev/null +++ b/app_protocols/ble_through/ble_proto.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include +// + +#ifdef __cplusplus +extern "C" { +#endif +#include "ble_cmd_app.h" +// +#include "ble_cmd_public.h" +// +#include "ble_proto_packet.h" +// +#include "ble_proto_utils.h" +#ifdef __cplusplus +} +#endif diff --git a/app_protocols/ble_through/ble_proto_packet.h b/app_protocols/ble_through/ble_proto_packet.h new file mode 100644 index 0000000..640a932 --- /dev/null +++ b/app_protocols/ble_through/ble_proto_packet.h @@ -0,0 +1,54 @@ +#pragma once +#include +#include +// +#include "ble_cmd_app.h" +#include "ble_cmd_public.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PACKET_H1 (0xAA) +#define PACKET_H2 (0xBB) +#define PACKET_TAIL (0xCC) +typedef enum { + kproto_cmd = 1, + kproto_cmd_receipt = 2, + kproto_report = 3, + kproto_error_receipt = 4, +} hand_acid_ble_proto_packet_type_t; + +/*********************************************************************************************************************** + * ENUM * + ***********************************************************************************************************************/ + +#pragma pack(1) +typedef struct { + uint8_t h1; + uint8_t h2; + uint8_t packetlen; + uint8_t frame_type; + uint8_t frame_index; + uint8_t cmd; + union { + // + ble_master_start_scan_t ble_master_start_scan; + ble_master_connected_event_t ble_master_connected_event; + ble_master_scan_result_t ble_master_scan_result; + ble_master_read_version_t ble_master_read_version; + ble_master_heart_t ble_master_heart; + uint8_t placeholder; + int32_t errorcode; + } d; +} ble_through_proto_t; + +#pragma pack() + +#define BLE_PACKET_BASE_SIZE() (sizeof(ble_through_proto_t) - sizeof(((ble_through_proto_t*)(0))->d) + 2) + +#define BLE_PACKET_MAX_SIZE() (230) + +#ifdef __cplusplus +} +#endif diff --git a/app_protocols/ble_through/ble_proto_utils.c b/app_protocols/ble_through/ble_proto_utils.c new file mode 100644 index 0000000..19394d0 --- /dev/null +++ b/app_protocols/ble_through/ble_proto_utils.c @@ -0,0 +1,80 @@ +#include "ble_proto_utils.h" + +#include "ble_proto_packet.h" + +bool ble_through_proto_check_packet(ble_through_proto_t *packet) { + uint8_t *pu8 = (uint8_t *)packet; + + if (packet->packetlen < (BLE_PACKET_BASE_SIZE())) { + return false; + } + if (packet->h1 != PACKET_H1 || packet->h2 != PACKET_H2) { + return false; + } + if (pu8[packet->packetlen - 1] != PACKET_TAIL) { + return false; + } + + uint8_t checksum = 0; + for (int i = 0; i < packet->packetlen - 2; i++) { + checksum += pu8[i]; + } + if (checksum != pu8[packet->packetlen - 2]) { + return false; + } + + return true; +} + +uint8_t ble_through_proto_sum(ble_through_proto_t *packet) { + uint8_t *_packet = (uint8_t *)packet; + uint8_t sum = 0; + for (int i = 0; i < packet->packetlen - 2; i++) { + sum += _packet[i]; + } + return sum; +} + +#define ITERM(_cmd, content) \ + { .cmd = _cmd, .length = BLE_PACKET_BASE_SIZE() + sizeof(content) } + +#define EMPTY_CONTENT uint8_t +#if 0 + +static cmd_info_t cmdinfos[] = { + ITERM(kproto_cmd_ble_master_reset, EMPTY_CONTENT), + ITERM(kproto_cmd_ble_master_read_version, ble_master_read_version_t), + ITERM(kproto_cmd_ble_master_start_scan, ble_master_start_scan_t), + ITERM(kproto_cmd_ble_master_stop_scan, EMPTY_CONTENT), + ITERM(kproto_cmd_ble_master_enter_dfu, EMPTY_CONTENT), + ITERM(kproto_cmd_ble_master_clear_reset_flag, EMPTY_CONTENT), + ITERM(kproto_report_ble_master_connected_event, ble_master_connected_event_t), + ITERM(kproto_report_ble_master_scan_result, ble_master_scan_result_t), + ITERM(kproto_report_ble_master_power_on, EMPTY_CONTENT), + ITERM(kproto_report_ble_master_heart, ble_master_heart_t), + + ITERM(kble_app_proto_cmd_sync_state, ble_app_proto_cmd_sync_state_t), + ITERM(kble_app_proto_cmd_trigger_pump_start_event, EMPTY_CONTENT), + ITERM(kble_app_proto_cmd_trigger_pump_stop_event, EMPTY_CONTENT), + ITERM(kble_app_proto_cmd_trigger_reflux_start_event, EMPTY_CONTENT), + ITERM(kble_app_proto_cmd_trigger_reflux_stop_event, EMPTY_CONTENT), + ITERM(kble_app_proto_cmd_trigger_prepare_start_event, EMPTY_CONTENT), + ITERM(kble_app_proto_cmd_trigger_prepare_stop_event, EMPTY_CONTENT), + ITERM(kble_app_proto_cmd_read_version, ble_app_proto_cmd_read_version_t), + ITERM(kble_app_proto_report_reflux_butt_short_press_event, EMPTY_CONTENT), + ITERM(kble_app_proto_report_reflux_butt_long_press_event, EMPTY_CONTENT), + ITERM(kble_app_proto_report_action_butt_short_press_event, EMPTY_CONTENT), + ITERM(kble_app_proto_report_action_butt_long_press_event, EMPTY_CONTENT), + ITERM(kble_app_proto_report_client_heart, ble_app_proto_report_client_heart_t), + +}; + +cmd_info_t *getcmdinfo(uint8_t cmd) { + for (int i = 0; i < sizeof(cmdinfos) / sizeof(cmd_info_t); i++) { + if (cmdinfos[i].cmd == cmd) { + return &cmdinfos[i]; + } + } + return NULL; +} +#endif diff --git a/app_protocols/ble_through/ble_proto_utils.h b/app_protocols/ble_through/ble_proto_utils.h new file mode 100644 index 0000000..da240f8 --- /dev/null +++ b/app_protocols/ble_through/ble_proto_utils.h @@ -0,0 +1,33 @@ +#pragma once + +#include "ble_proto_packet.h" + +#ifdef __cplusplus +extern "C" { +#endif + +bool ble_through_proto_check_packet(ble_through_proto_t *packet); +uint8_t ble_through_proto_sum(ble_through_proto_t *packet); + +#define BLE_THROUGH_PACKET_SET_TAIL(packet) \ + { \ + uint8_t *__data = (uint8_t *)packet; \ + __data[packet->packetlen - 1] = PACKET_TAIL; \ + } + +#define BLE_THROUGH_PACKET_SET_CHECKSUM(packet) \ + { \ + uint8_t *__data = (uint8_t *)packet; \ + __data[packet->packetlen - 2] = ble_through_proto_sum(packet); \ + } + +typedef struct { + uint8_t cmd; + uint8_t length; +} cmd_info_t; + +cmd_info_t *getcmdinfo(uint8_t cmd); + +#ifdef __cplusplus +} +#endif diff --git a/app_protocols/hand_acid_val_protocol/hand_acid_val_protocol.h b/app_protocols/hand_acid_val_protocol/hand_acid_val_protocol.h new file mode 100644 index 0000000..e69de29 diff --git a/app_protocols/zscanprotocol b/app_protocols/zscanprotocol index 8a3aeaf..81529a1 160000 --- a/app_protocols/zscanprotocol +++ b/app_protocols/zscanprotocol @@ -1 +1 @@ -Subproject commit 8a3aeaf8883a3c7d01594e0399fbe96bf8b9cf72 +Subproject commit 81529a15c57000f73cc5bd4b7276f567099b9988 diff --git a/stm32basic b/stm32basic index 219877a..4daae70 160000 --- a/stm32basic +++ b/stm32basic @@ -1 +1 @@ -Subproject commit 219877a3ae5cfabe04211a9121eac9519b6081cc +Subproject commit 4daae70c942165377837d26b688bab9d6236d453 diff --git a/stm32components b/stm32components index a3069a8..a588871 160000 --- a/stm32components +++ b/stm32components @@ -1 +1 @@ -Subproject commit a3069a8005dcb8277f95d0341551c145fac2a046 +Subproject commit a58887133a2b2fe939f9f7245e059adb49f9e4eb diff --git a/uappbase/appcfg/appcfg.hpp b/uappbase/appcfg/appcfg.hpp new file mode 100644 index 0000000..95a193a --- /dev/null +++ b/uappbase/appcfg/appcfg.hpp @@ -0,0 +1,4 @@ +#pragma once +#include "project_configs.h" + +#define MAX_USR_NAME_SIZE 5 \ No newline at end of file diff --git a/uappbase/appdep.hpp b/uappbase/appdep.hpp new file mode 100644 index 0000000..0f54cdd --- /dev/null +++ b/uappbase/appdep.hpp @@ -0,0 +1,6 @@ +#pragma once +#include "stm32basic/stm32basic.hpp" +#include "stm32halport/stm32halport.hpp" +#include "stm32components/sysmgr/sys_mgr.hpp" +#include "ucomponents/ucomponents.hpp" +#include "main.h" \ No newline at end of file diff --git a/uappbase/base.hpp b/uappbase/base.hpp index 13f3e36..e2be790 100644 --- a/uappbase/base.hpp +++ b/uappbase/base.hpp @@ -1,5 +1,8 @@ #pragma once -#include "stm32basic/stm32basic.hpp" -#include "stm32halport/stm32halport.hpp" -#include "ucomponents/ucomponents.hpp" -#include "main.h" \ No newline at end of file +#include "appdep.hpp" +#include "bean/bean.hpp" +#include "appcfg/appcfg.hpp" +// +#include "service/app_core.hpp" +#include "service/app_event_bus.hpp" +#include "service/gstate_mgr.hpp" \ No newline at end of file diff --git a/uappbase/bean/bean.hpp b/uappbase/bean/bean.hpp new file mode 100644 index 0000000..d9e8166 --- /dev/null +++ b/uappbase/bean/bean.hpp @@ -0,0 +1,2 @@ +#pragma once +#include "event.hpp" \ No newline at end of file diff --git a/uappbase/bean/event.hpp b/uappbase/bean/event.hpp new file mode 100644 index 0000000..fe302dd --- /dev/null +++ b/uappbase/bean/event.hpp @@ -0,0 +1,24 @@ +#pragma once +#include + +#include +namespace iflytop { +using namespace std; +typedef enum { + kPumpStart, + kPumpStop, + + kAppEvent_RemoterControlerConnected, + kAppEvent_RemoterControlerDisConnected, +} AppEventType_t; + +typedef struct { + AppEventType_t type; + union event { + uint32_t placeholder; + } d; + +} AppEvent_t; + + +} // namespace iflytop \ No newline at end of file diff --git a/uappbase/service/app_event_bus.cpp b/uappbase/service/app_event_bus.cpp new file mode 100644 index 0000000..46df8c1 --- /dev/null +++ b/uappbase/service/app_event_bus.cpp @@ -0,0 +1,34 @@ +#include "app_event_bus.hpp" + +#include "cmsis_os.h" +using namespace iflytop; +using namespace std; +static QueueHandle_t xQueue; +#define TAG "AppEventBus" +void AppEventBus::initialize() { + thread.init("AppEventBus", 1024); + xQueue = xQueueCreate(10, sizeof(AppEvent_t)); + + thread.start([this]() { + AppEvent_t event; + while (1) { + if (xQueueReceive(xQueue, &event, portMAX_DELAY) == pdTRUE) { + for (int i = 0; i < cbNum; i++) { + m_cbs[i](&event); + } + } + } + }); +} + +void AppEventBus::regOnEvent(onAppEventCB_t onEvent) { + m_cbs[cbNum] = onEvent; + cbNum++; +} +void AppEventBus::pushEvent(AppEvent_t& event) { + xQueueSend(xQueue, &event, 0); + + if (xQueueSend(xQueue, &event, 100) != pdPASS) { + ZLOGE(TAG, "xQueueSend failed"); + } +} \ No newline at end of file diff --git a/uappbase/service/app_event_bus.hpp b/uappbase/service/app_event_bus.hpp new file mode 100644 index 0000000..911b617 --- /dev/null +++ b/uappbase/service/app_event_bus.hpp @@ -0,0 +1,28 @@ +#pragma once +#include "uappbase/appdep.hpp" +#include "uappbase/bean/bean.hpp" +// +namespace iflytop { + +typedef function onAppEventCB_t; + +class AppEventBus { + ZThread thread; + + private: + onAppEventCB_t m_cbs[50]; + int32_t cbNum = 0; + + public: + static AppEventBus* ins() { + static AppEventBus instance; + return &instance; + } + + void initialize(); + + void regOnEvent(onAppEventCB_t onEvent); + void pushEvent(AppEvent_t& event); +}; + +} // namespace iflytop diff --git a/uappbase/service/gstate_mgr.hpp b/uappbase/service/gstate_mgr.hpp new file mode 100644 index 0000000..a057d7d --- /dev/null +++ b/uappbase/service/gstate_mgr.hpp @@ -0,0 +1,60 @@ +#pragma once +#include "uappbase/appcfg/appcfg.hpp" +#include "uappbase/appdep.hpp" +#include "uappbase/bean/bean.hpp" +// +#include "app_protocols/ble_through/ble_proto.h" + +namespace iflytop { +using namespace std; +#define GSM GStateMgr::ins() + +class GStateMgr { + private: + /* data */ + bool m_isAdmin; + bool m_isLogin; + char m_loginUsr[MAX_USR_NAME_SIZE + 1]; + + int32_t m_AcidState; // ҺͰ״̬ 1:,0: + int32_t m_RemoterS; // ң״̬ 1:,0: + hand_acid_mode_t m_RunMode; // ģʽ + + bool pumpSelectState[4] = {false}; + + public: + static GStateMgr* ins() { + static GStateMgr instance; + return &instance; + } + + void setLogin(bool isAdmin, const char* loginUsr) { + m_isLogin = true; + m_isAdmin = isAdmin; + if (loginUsr) { + strncpy(this->m_loginUsr, loginUsr, MAX_USR_NAME_SIZE); + } + } + void setUnLogin() { + m_isLogin = false; + m_isAdmin = false; + memset(m_loginUsr, 0, MAX_USR_NAME_SIZE + 1); + } + + bool isLogin() { return m_isLogin; } + bool isAdmin() { return m_isAdmin; } + const char* getLoginUsr() { return m_loginUsr; } + + void setAcidState(int32_t state) { m_AcidState = state; } + void setRemoterS(int32_t state) { m_RemoterS = state; } + void setRunMode(hand_acid_mode_t mode) { m_RunMode = mode; } + + int32_t getAcidState() { return m_AcidState; } + int32_t getRemoterS() { return m_RemoterS; } + hand_acid_mode_t getRunMode() { return m_RunMode; } + + void setPumpSelectState(int32_t index, bool state) { pumpSelectState[index] = state; } + bool getPumpSelectState(int32_t index) { return pumpSelectState[index]; } +}; + +} // namespace iflytop \ No newline at end of file diff --git a/usrc/appcfg/appcfg.hpp b/usrc/appcfg/appcfg.hpp deleted file mode 100644 index 6569ff4..0000000 --- a/usrc/appcfg/appcfg.hpp +++ /dev/null @@ -1,2 +0,0 @@ -#pragma once -#include "project_configs.h" \ No newline at end of file diff --git a/usrc/apphal/apphal.cpp b/usrc/apphal/apphal.cpp index 0cfd937..55a887d 100644 --- a/usrc/apphal/apphal.cpp +++ b/usrc/apphal/apphal.cpp @@ -48,7 +48,7 @@ void AppHal::MX_TIM7_Init(void) { } #define EARLY_ASSERT(exptr) \ - if (!exptr) { \ + if (!(exptr)) { \ while (true) { \ } \ } diff --git a/usrc/apphal/apphal.hpp b/usrc/apphal/apphal.hpp index 0a511dd..af30068 100644 --- a/usrc/apphal/apphal.hpp +++ b/usrc/apphal/apphal.hpp @@ -1,5 +1,4 @@ #pragma once -#include "appcfg/appcfg.hpp" #include "uappbase/base.hpp" namespace iflytop { class AppHal { diff --git a/usrc/service/app_core.cpp b/usrc/service/app_core.cpp index 64a2d8a..8f098d6 100644 --- a/usrc/service/app_core.cpp +++ b/usrc/service/app_core.cpp @@ -4,20 +4,51 @@ #include #define TAG "main" +using namespace iflytop; extern "C" { void umain() { AppCore::ins()->initialize(); } } -using namespace iflytop; +static iflytop::ZGPIO debuglight; +static bool errorFlag; + +void AppCore::debugLightLoop() { + static bool light = false; + static uint32_t lastcall = 0; + + if (errorFlag) { + if (zos_haspassedms(lastcall) > 30) { + light = !light; + debuglight.write(light); + lastcall = zos_get_tick(); + } + } else { + if (zos_haspassedms(lastcall) > 300) { + light = !light; + debuglight.write(light); + lastcall = zos_get_tick(); + } + } +} + void AppCore::initialize() { AppHal::MX_TIM6_Init(); AppHal::MX_TIM7_Init(); AppHal::DEBUG_UART_INIT(PA9, PA10, 460800); - AppHal::MX_IWDG_Init(); ZLOGI(TAG, "======================= boardinfo ==================== "); ZLOGI(TAG, "project : %s ", PROJECT); ZLOGI(TAG, "version : %d ", SOFTWARE_VERSION); ZLOGI(TAG, "sn : %s", sn_get_str()); ZLOGI(TAG, "="); + + SysMgr::ins()->initedFinished(); + SysMgr::ins()->dumpSysInfo(); + AppHal::MX_IWDG_Init(); + + while (true) { + osDelay(1); + debugLightLoop(); + HAL_IWDG_Refresh(&hiwdg); + } } diff --git a/usrc/service/app_core.hpp b/usrc/service/app_core.hpp index 95a32c7..442092f 100644 --- a/usrc/service/app_core.hpp +++ b/usrc/service/app_core.hpp @@ -1,6 +1,5 @@ #pragma once -#include "appcfg/appcfg.hpp" #include "apphal/apphal.hpp" #include "uappbase/base.hpp" @@ -16,6 +15,7 @@ class AppCore { return &ins; } void initialize(); + void debugLightLoop(); }; } // namespace iflytop \ No newline at end of file