From a53038c0a9d171ab76e31525b7e0b1e6765642e6 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 27 Aug 2024 15:33:22 +0800 Subject: [PATCH] remove some code --- .vscode/settings.json | 8 +- app/src/acid_dispenser_ble_slave_main.c | 180 ++++++++++++++++---------------- app/src/app_basic_service/basic/event.h | 2 +- app/src/ble_data_processer_utils.c | 98 ++++++++--------- app/src/ble_data_processer_utils.h | 10 +- 5 files changed, 152 insertions(+), 146 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 9b79d59..3b9ab74 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -222,7 +222,13 @@ "protocol.h": "c", "ble_data_processer_utils.h": "c", "gstate.h": "c", - "event.h": "c" + "event.h": "c", + "app_protocols.h": "c", + "ble_proto.h": "c", + "hand_acid_val_protocol.h": "c", + "zscanprotocol.h": "c", + "hand_acid_remoter_key_event.h": "c", + "ble_proto_utils.h": "c" }, "files.encoding": "gbk" } \ No newline at end of file diff --git a/app/src/acid_dispenser_ble_slave_main.c b/app/src/acid_dispenser_ble_slave_main.c index 5fbf841..5017220 100644 --- a/app/src/acid_dispenser_ble_slave_main.c +++ b/app/src/acid_dispenser_ble_slave_main.c @@ -3,7 +3,7 @@ #include "aproject_config/config.h" // #include "ify_hrs_protocol/heart_rate_sensor_protocol.h" -#include "protocol/protocol.h" +#include "app_protocols/app_protocols.h" #include "zdatachannel_service.h" // #include "app_basic_service/device_version_info_mgr.h" @@ -21,11 +21,11 @@ * GLOBAL * ***********************************************************************************************************************/ -static hand_acid_mode_t g_hand_acid_mode; -static hand_pump_working_state_t g_hand_pump_working_state; -static bool g_connected; -static int32_t m_longpress_trigger_time = 500; -static int32_t m_last_usr_operation_time = 0; +static hand_acid_mode_t g_hand_acid_mode; +static bool g_hand_pump_working_state; +static bool g_connected; +static int32_t m_longpress_trigger_time = 500; +static int32_t m_last_usr_operation_time = 0; // static void testlight_state(int val) { // int effect = val % 3; @@ -66,69 +66,69 @@ void on_zble_event(zble_event_t* event) { * À¶ÑÀÏûÏ¢´¦Àí * ***********************************************************************************************************************/ void one_conduction_process_rx_packet(uint8_t* rx, int len) { - hand_acid_ble_proto_t* rxheader = (hand_acid_ble_proto_t*)rx; - hand_acid_ble_proto_t* txheader = bletxbuf_get(); - hand_acid_ble_proto_cmd_t cmd = (hand_acid_ble_proto_cmd_t)rxheader->cmd; - - if (len < HAND_ACID_BLE_BASE_SIZE) { - ZLOGI("rx len error:%d", len); - return; - } + // hand_acid_ble_proto_t* rxheader = (hand_acid_ble_proto_t*)rx; + // hand_acid_ble_proto_t* txheader = bletxbuf_get(); + // hand_acid_ble_proto_cmd_t cmd = (hand_acid_ble_proto_cmd_t)rxheader->cmd; + + // if (len < HAND_ACID_BLE_BASE_SIZE) { + // ZLOGI("rx len error:%d", len); + // return; + // } bletxbuf_clear(); - txheader->cmd = rxheader->cmd; - txheader->frame_index = rxheader->frame_index; - txheader->frame_type = kproto_cmd_receipt; - - ZLOGI("rx cmd:%d index:%d paralen:%d", cmd, rxheader->frame_index, len - HAND_ACID_BLE_BASE_SIZE); - NRF_LOG_HEXDUMP_INFO(rx, len); - - /** - * @brief - * process cmd here - */ - - if (kproto_cmd_set_state == cmd) { - uint8_t hand_acid_mode = rxheader->data.set_state.hand_acid_mode; - uint8_t hand_pump_working_state = rxheader->data.set_state.hand_pump_working_state; - ZLOGI("update state mode:%d state:%d", hand_acid_mode, hand_pump_working_state); - - // push state_change_event event - { - static app_event_t event; - memset(&event, 0, sizeof(app_event_t)); - event.eventType = kappevent_device_state_change_event; - event.val.state_change_event.mode = hand_acid_mode; - event.val.state_change_event.state = hand_pump_working_state; - zapp_ebus_push_event(&event); - } - - send_success_receipt(txheader); - } else if (kproto_cmd_setlong_key_delayms == cmd) { - uint32_t longkeydelay = rxheader->data.setlong_key_delayms.longkeydelay; - if (longkeydelay < 500) { - longkeydelay = 500; - } - m_longpress_trigger_time = longkeydelay; - ZLOGI("set long key delay:%d", m_longpress_trigger_time); - } - - else if (kproto_cmd_reset == cmd) { - NVIC_SystemReset(); - } - - else if (kproto_cmd_read_power == cmd) { - txheader->data.read_power.power = 100; - send_success_receipt(txheader); - } - - else if (kproto_cmd_read_version == cmd) { - txheader->data.read_version.firmware_version = FIRMWARE_VERSION; - txheader->data.read_version.blestack_version = BLESTACK_VERSION; - txheader->data.read_version.bootloader_version = BOOTLOADER_VERSION; - txheader->data.read_version.hardware_version = HARDWARE_VERSION; - send_success_receipt(txheader); - } + // txheader->cmd = rxheader->cmd; + // txheader->frame_index = rxheader->frame_index; + // txheader->frame_type = kproto_cmd_receipt; + + // ZLOGI("rx cmd:%d index:%d paralen:%d", cmd, rxheader->frame_index, len - HAND_ACID_BLE_BASE_SIZE); + // NRF_LOG_HEXDUMP_INFO(rx, len); + + // /** + // * @brief + // * process cmd here + // */ + + // if (kproto_cmd_set_state == cmd) { + // uint8_t hand_acid_mode = rxheader->data.set_state.hand_acid_mode; + // uint8_t hand_pump_working_state = rxheader->data.set_state.hand_pump_working_state; + // ZLOGI("update state mode:%d state:%d", hand_acid_mode, hand_pump_working_state); + + // // push state_change_event event + // { + // static app_event_t event; + // memset(&event, 0, sizeof(app_event_t)); + // event.eventType = kappevent_device_state_change_event; + // event.val.state_change_event.mode = hand_acid_mode; + // event.val.state_change_event.state = hand_pump_working_state; + // zapp_ebus_push_event(&event); + // } + + // send_success_receipt(txheader); + // } else if (kproto_cmd_setlong_key_delayms == cmd) { + // uint32_t longkeydelay = rxheader->data.setlong_key_delayms.longkeydelay; + // if (longkeydelay < 500) { + // longkeydelay = 500; + // } + // m_longpress_trigger_time = longkeydelay; + // ZLOGI("set long key delay:%d", m_longpress_trigger_time); + // } + + // else if (kproto_cmd_reset == cmd) { + // NVIC_SystemReset(); + // } + + // else if (kproto_cmd_read_power == cmd) { + // txheader->data.read_power.power = 100; + // send_success_receipt(txheader); + // } + + // else if (kproto_cmd_read_version == cmd) { + // txheader->data.read_version.firmware_version = FIRMWARE_VERSION; + // txheader->data.read_version.blestack_version = BLESTACK_VERSION; + // txheader->data.read_version.bootloader_version = BOOTLOADER_VERSION; + // txheader->data.read_version.hardware_version = HARDWARE_VERSION; + // send_success_receipt(txheader); + // } } /*********************************************************************************************************************** @@ -198,17 +198,17 @@ void on_zapp_ebus_event(void* p_event_data, uint16_t event_size) { break; case kappevent_device_state_change_event: g_hand_acid_mode = (hand_acid_mode_t)p_event->val.state_change_event.mode; - g_hand_pump_working_state = (hand_pump_working_state_t)p_event->val.state_change_event.state; + // g_hand_pump_working_state = (hand_pump_working_state_t)p_event->val.state_change_event.state; update_light_state(); break; case kappevent_key_pressed: ZLOGI("key pressed:%d", p_event->val.keyid); - send_key_event(p_event->val.keyid, kkey_short_press_event); + // send_key_event(p_event->val.keyid, 1); zapp_state_machine_change_state(kstate_working_state); break; case kappevent_key_long_pressed: ZLOGI("key long pressed:%d", p_event->val.keyid); - send_key_event(p_event->val.keyid, kkey_long_press_event); + // send_key_event(p_event->val.keyid, 2); zapp_state_machine_change_state(kstate_working_state); break; } @@ -229,38 +229,38 @@ void on_zapp_ebus_event(void* p_event_data, uint16_t event_size) { case kappevent_ble_disconnected: ZLOGI("ble disconnected"); g_connected = false; - g_hand_pump_working_state = khand_acid_pump_is_idle; + // g_hand_pump_working_state = khand_acid_pump_is_idle; update_light_state(); break; case kappevent_device_state_change_event: - g_hand_acid_mode = (hand_acid_mode_t)p_event->val.state_change_event.mode; - g_hand_pump_working_state = (hand_pump_working_state_t)p_event->val.state_change_event.state; + // g_hand_acid_mode = (hand_acid_mode_t)p_event->val.state_change_event.mode; + // g_hand_pump_working_state = (hand_pump_working_state_t)p_event->val.state_change_event.state; update_light_state(); break; case kappevent_key_pressed: ZLOGI("key pressed:%d", p_event->val.keyid); - send_key_event(p_event->val.keyid, kkey_short_press_event); + // send_key_event(p_event->val.keyid, kkey_short_press_event); break; case kappevent_key_long_pressed: ZLOGI("key long pressed:%d", p_event->val.keyid); - send_key_event(p_event->val.keyid, kkey_long_press_event); + // send_key_event(p_event->val.keyid, kkey_long_press_event); break; } - if (g_hand_pump_working_state != khand_acid_pump_is_working) { - if (g_connected) { - if (znordic_haspassed_ms(m_last_usr_operation_time) > (5 * 60 * 1000)) { - ZLOGI("no operation over 5min, enter standby"); - zapp_state_machine_change_state(kstate_standby); - } - } else { - if (znordic_haspassed_ms(m_last_usr_operation_time) > (5 * 1000)) { - ZLOGI("no operation over 5s, enter standby"); - zapp_state_machine_change_state(kstate_standby); - } - } - } + // if (g_hand_pump_working_state != khand_acid_pump_is_working) { + // if (g_connected) { + // if (znordic_haspassed_ms(m_last_usr_operation_time) > (5 * 60 * 1000)) { + // ZLOGI("no operation over 5min, enter standby"); + // zapp_state_machine_change_state(kstate_standby); + // } + // } else { + // if (znordic_haspassed_ms(m_last_usr_operation_time) > (5 * 1000)) { + // ZLOGI("no operation over 5s, enter standby"); + // zapp_state_machine_change_state(kstate_standby); + // } + // } + // } } } } @@ -333,11 +333,11 @@ static void process_key(key_t* key) { static void state_machine_driver_tmr_cb(void* p_context) { // static key_t mode_and_action_butt = { - .keid = kkey_id_mode_and_action_butt, + .keid = 1, .read_key_state = key_read_acid_state, }; static key_t liquid_reflux_butt = { - .keid = kkey_id_liquid_reflux_butt, + .keid = 2, .read_key_state = key_liquid_reflux_butt_read_state, }; diff --git a/app/src/app_basic_service/basic/event.h b/app/src/app_basic_service/basic/event.h index 7a6057a..f5c1352 100644 --- a/app/src/app_basic_service/basic/event.h +++ b/app/src/app_basic_service/basic/event.h @@ -3,7 +3,7 @@ #include #include "aproject_config/config.h" -#include "protocol/protocol.h" +#include "app_protocols/app_protocols.h" #define ECG_DATA_REPORT_FRAME_NUM 50 diff --git a/app/src/ble_data_processer_utils.c b/app/src/ble_data_processer_utils.c index 1fdac4a..5009736 100644 --- a/app/src/ble_data_processer_utils.c +++ b/app/src/ble_data_processer_utils.c @@ -10,7 +10,7 @@ static uint8_t blereportbuf[BLE_MSG_BUF_SIZE]; // PACKET_TAIL void bletxbuf_clear() { memset(_bletxbuf, 0, BLE_MSG_BUF_SIZE); } -hand_acid_ble_proto_t* bletxbuf_get() { return (hand_acid_ble_proto_t*)_bletxbuf; } +zble_proto_packet_t* bletxbuf_get() { return (zble_proto_packet_t*)_bletxbuf; } static uint8_t compute_sum(uint8_t* data, size_t len) { uint8_t sum = 0; @@ -20,62 +20,62 @@ static uint8_t compute_sum(uint8_t* data, size_t len) { return sum; } -void send_error_receipt(hand_acid_ble_proto_t* rxpacket, int32_t errorcode) { - hand_acid_ble_proto_t* txheader = (hand_acid_ble_proto_t*)_bletxbuf; - uint16_t sendlen = HAND_ACID_BLE_BASE_SIZE + sizeof(txheader->data.errreceipt) + 2; - txheader->h1 = PACKET_H1; - txheader->h2 = PACKET_H2; - txheader->cmd = rxpacket->cmd; - txheader->frame_index = rxpacket->frame_index; - txheader->frame_type = kproto_error_receipt; - txheader->data.errreceipt.ecode = errorcode; - // 校验 - txheader->packetlen = sendlen; - _bletxbuf[sendlen - 2] = compute_sum(_bletxbuf, sendlen - 2); - _bletxbuf[sendlen - 1] = PACKET_TAIL; - zdatachannel_data_send2(_bletxbuf, sendlen); +void send_error_receipt(zble_proto_packet_t* rxpacket, int32_t errorcode) { + // zble_proto_packet_t* txheader = (zble_proto_packet_t*)_bletxbuf; + // uint16_t sendlen = HAND_ACID_BLE_BASE_SIZE + sizeof(txheader->data.errreceipt) + 2; + // txheader->h1 = PACKET_H1; + // txheader->h2 = PACKET_H2; + // txheader->cmd = rxpacket->cmd; + // txheader->frame_index = rxpacket->frame_index; + // txheader->frame_type = kproto_error_receipt; + // txheader->data.errreceipt.ecode = errorcode; + // // 校验 + // txheader->packetlen = sendlen; + // _bletxbuf[sendlen - 2] = compute_sum(_bletxbuf, sendlen - 2); + // _bletxbuf[sendlen - 1] = PACKET_TAIL; + zdatachannel_data_send2(_bletxbuf, 0); } -void send_success_receipt(hand_acid_ble_proto_t* rxpacket) { - hand_acid_ble_proto_t* txheader = (hand_acid_ble_proto_t*)_bletxbuf; - uint16_t sendlen = HAND_ACID_BLE_BASE_SIZE + 2; - txheader->h1 = PACKET_H1; - txheader->h2 = PACKET_H2; - txheader->cmd = rxpacket->cmd; - txheader->frame_index = rxpacket->frame_index; - txheader->frame_type = kproto_cmd_receipt; +void send_success_receipt(zble_proto_packet_t* rxpacket) { + // zble_proto_packet_t* txheader = (zble_proto_packet_t*)_bletxbuf; + // uint16_t sendlen = HAND_ACID_BLE_BASE_SIZE + 2; + // txheader->h1 = PACKET_H1; + // txheader->h2 = PACKET_H2; + // txheader->cmd = rxpacket->cmd; + // txheader->frame_index = rxpacket->frame_index; + // txheader->frame_type = kproto_cmd_receipt; - if (txheader->cmd == kproto_cmd_read_power) { - sendlen = HAND_ACID_BLE_BASE_SIZE + sizeof(txheader->data.read_power) + 2; - } else if (txheader->cmd == kproto_cmd_read_version) { - sendlen = HAND_ACID_BLE_BASE_SIZE + sizeof(txheader->data.read_version) + 2; - } else { - sendlen = HAND_ACID_BLE_BASE_SIZE + 2; - } - txheader->packetlen = sendlen; + // if (txheader->cmd == kproto_cmd_read_power) { + // sendlen = HAND_ACID_BLE_BASE_SIZE + sizeof(txheader->data.read_power) + 2; + // } else if (txheader->cmd == kproto_cmd_read_version) { + // sendlen = HAND_ACID_BLE_BASE_SIZE + sizeof(txheader->data.read_version) + 2; + // } else { + // sendlen = HAND_ACID_BLE_BASE_SIZE + 2; + // } + // txheader->packetlen = sendlen; - // 校验 - _bletxbuf[sendlen - 2] = compute_sum(_bletxbuf, sendlen - 2); - _bletxbuf[sendlen - 1] = PACKET_TAIL; + // // 校验 + // _bletxbuf[sendlen - 2] = compute_sum(_bletxbuf, sendlen - 2); + // _bletxbuf[sendlen - 1] = PACKET_TAIL; - zdatachannel_data_send2(_bletxbuf, sendlen); + zdatachannel_data_send2(_bletxbuf, 0); } void send_key_event(uint8_t keyid, uint8_t keyevent) { - static uint8_t report_index; - hand_acid_ble_proto_t* reportpacket = (hand_acid_ble_proto_t*)blereportbuf; - uint16_t sendlen = HAND_ACID_BLE_BASE_SIZE + sizeof(reportpacket->data.key_event) + 2; + // static uint8_t report_index; + // zble_proto_packet_t* reportpacket = (zble_proto_packet_t*)blereportbuf; + // uint16_t sendlen = HAND_ACID_BLE_BASE_SIZE + sizeof(reportpacket->data.key_event) + 2; - reportpacket->h1 = PACKET_H1; - reportpacket->h2 = PACKET_H2; - reportpacket->packetlen = sendlen; - reportpacket->frame_type = kproto_report; - reportpacket->frame_index = report_index++; - reportpacket->cmd = kproto_report_key_event; - reportpacket->data.key_event.keyid = keyid; - reportpacket->data.key_event.keyevent = keyevent; - blereportbuf[sendlen - 2] = compute_sum(blereportbuf, sendlen - 2); - blereportbuf[sendlen - 1] = PACKET_TAIL; + // reportpacket->h1 = PACKET_H1; + // reportpacket->h2 = PACKET_H2; + // reportpacket->packetlen = sendlen; + // reportpacket->frame_type = kproto_report; + // reportpacket->frame_index = report_index++; + // reportpacket->cmd = kproto_report_key_event; + // reportpacket->data.key_event.keyid = keyid; + // reportpacket->data.key_event.keyevent = keyevent; + // blereportbuf[sendlen - 2] = compute_sum(blereportbuf, sendlen - 2); + // blereportbuf[sendlen - 1] = PACKET_TAIL; - zdatachannel_data_send2(blereportbuf, sendlen); + zdatachannel_data_send2(blereportbuf, 0); } diff --git a/app/src/ble_data_processer_utils.h b/app/src/ble_data_processer_utils.h index 8fab550..48f26c3 100644 --- a/app/src/ble_data_processer_utils.h +++ b/app/src/ble_data_processer_utils.h @@ -2,16 +2,16 @@ #include #include "app_basic_service/zapp.h" -#include "protocol/protocol.h" +#include "app_protocols/app_protocols.h" #define BLE_MSG_BUF_SIZE 255 extern uint8_t bletxbuf[]; extern uint8_t blereportbuf[]; void bletxbuf_clear(); -hand_acid_ble_proto_t* bletxbuf_get(); +zble_proto_packet_t* bletxbuf_get(); -void send_error_receipt(hand_acid_ble_proto_t* rxpacket, int32_t errorcode); -void send_success_receipt(hand_acid_ble_proto_t* rxpacket); +void send_error_receipt(zble_proto_packet_t* rxpacket, int32_t errorcode); +void send_success_receipt(zble_proto_packet_t* rxpacket); -void send_key_event(uint8_t keyid, uint8_t keyevent); \ No newline at end of file +void send_key_event(uint8_t keyid, uint8_t keyevent);