30 changed files with 638 additions and 30 deletions
-
11.vscode/settings.json
-
10README.md
-
6app_protocols/app_protocols.h
-
53app_protocols/appecode/errorcode.c
-
55app_protocols/appecode/errorcode.h
-
0app_protocols/bean/hand_acid_mode.c
-
6app_protocols/bean/hand_acid_mode.h
-
54app_protocols/ble_through/ble_cmd_app.h
-
71app_protocols/ble_through/ble_cmd_public.h
-
18app_protocols/ble_through/ble_proto.h
-
54app_protocols/ble_through/ble_proto_packet.h
-
80app_protocols/ble_through/ble_proto_utils.c
-
33app_protocols/ble_through/ble_proto_utils.h
-
0app_protocols/hand_acid_val_protocol/hand_acid_val_protocol.h
-
2app_protocols/zscanprotocol
-
2stm32basic
-
2stm32components
-
4uappbase/appcfg/appcfg.hpp
-
6uappbase/appdep.hpp
-
11uappbase/base.hpp
-
2uappbase/bean/bean.hpp
-
24uappbase/bean/event.hpp
-
34uappbase/service/app_event_bus.cpp
-
28uappbase/service/app_event_bus.hpp
-
60uappbase/service/gstate_mgr.hpp
-
2usrc/appcfg/appcfg.hpp
-
2usrc/apphal/apphal.cpp
-
1usrc/apphal/apphal.hpp
-
35usrc/service/app_core.cpp
-
2usrc/service/app_core.hpp
@ -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" |
@ -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]); } |
||||
|
|
@ -0,0 +1,55 @@ |
|||||
|
#pragma once |
||||
|
#include <stdint.h> |
||||
|
|
||||
|
#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 |
@ -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; |
@ -0,0 +1,54 @@ |
|||||
|
#pragma once |
||||
|
#include <stdbool.h> |
||||
|
#include <stdint.h> |
||||
|
// |
||||
|
#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 |
@ -0,0 +1,71 @@ |
|||||
|
#pragma once |
||||
|
#include <stdbool.h> |
||||
|
#include <stdint.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 { |
||||
|
|
||||
|
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 |
@ -0,0 +1,18 @@ |
|||||
|
#pragma once |
||||
|
#include <stdbool.h> |
||||
|
#include <stdint.h> |
||||
|
// |
||||
|
|
||||
|
#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 |
@ -0,0 +1,54 @@ |
|||||
|
#pragma once |
||||
|
#include <stdbool.h> |
||||
|
#include <stdint.h> |
||||
|
// |
||||
|
#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 |
@ -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 |
@ -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 |
@ -1 +1 @@ |
|||||
Subproject commit 8a3aeaf8883a3c7d01594e0399fbe96bf8b9cf72 |
|
||||
|
Subproject commit 81529a15c57000f73cc5bd4b7276f567099b9988 |
@ -1 +1 @@ |
|||||
Subproject commit 219877a3ae5cfabe04211a9121eac9519b6081cc |
|
||||
|
Subproject commit 4daae70c942165377837d26b688bab9d6236d453 |
@ -1 +1 @@ |
|||||
Subproject commit a3069a8005dcb8277f95d0341551c145fac2a046 |
|
||||
|
Subproject commit a58887133a2b2fe939f9f7245e059adb49f9e4eb |
@ -0,0 +1,4 @@ |
|||||
|
#pragma once
|
||||
|
#include "project_configs.h"
|
||||
|
|
||||
|
#define MAX_USR_NAME_SIZE 5
|
@ -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"
|
@ -1,5 +1,8 @@ |
|||||
#pragma once
|
#pragma once
|
||||
#include "stm32basic/stm32basic.hpp"
|
|
||||
#include "stm32halport/stm32halport.hpp"
|
|
||||
#include "ucomponents/ucomponents.hpp"
|
|
||||
#include "main.h"
|
|
||||
|
#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"
|
@ -0,0 +1,2 @@ |
|||||
|
#pragma once
|
||||
|
#include "event.hpp"
|
@ -0,0 +1,24 @@ |
|||||
|
#pragma once
|
||||
|
#include <stdint.h>
|
||||
|
|
||||
|
#include <functional>
|
||||
|
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
|
@ -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"); |
||||
|
} |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
#pragma once
|
||||
|
#include "uappbase/appdep.hpp"
|
||||
|
#include "uappbase/bean/bean.hpp"
|
||||
|
//
|
||||
|
namespace iflytop { |
||||
|
|
||||
|
typedef function<void(AppEvent_t* event)> 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
|
@ -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
|
@ -1,2 +0,0 @@ |
|||||
#pragma once
|
|
||||
#include "project_configs.h"
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue