From c2c565b6ebdf8be06d95f4dcd120443bb81ad287 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 10 Jul 2024 21:19:50 +0800 Subject: [PATCH] update --- ble_through/ble_proto.h | 2 ++ ble_through/ble_proto_packet.h | 5 ++++- ble_through/ble_proto_utils.c | 44 ++++++++++++++++++++++++++++++++++++++++++ ble_through/ble_proto_utils.h | 17 +++++++++++++++- protocol.h | 2 ++ 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/ble_through/ble_proto.h b/ble_through/ble_proto.h index 394663a..402d22f 100644 --- a/ble_through/ble_proto.h +++ b/ble_through/ble_proto.h @@ -5,6 +5,7 @@ #ifdef __cplusplus extern "C" { +#endif #include "ble_cmd_app.h" // #include "ble_cmd_public.h" @@ -12,5 +13,6 @@ extern "C" { #include "ble_proto_packet.h" // #include "ble_proto_utils.h" +#ifdef __cplusplus } #endif diff --git a/ble_through/ble_proto_packet.h b/ble_through/ble_proto_packet.h index 2863a37..7189e5f 100644 --- a/ble_through/ble_proto_packet.h +++ b/ble_through/ble_proto_packet.h @@ -1,5 +1,4 @@ #pragma once -#pragma once #include #include // @@ -38,6 +37,8 @@ typedef struct { 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; @@ -45,6 +46,8 @@ typedef struct { #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/ble_through/ble_proto_utils.c b/ble_through/ble_proto_utils.c index b75dfff..9f08738 100644 --- a/ble_through/ble_proto_utils.c +++ b/ble_through/ble_proto_utils.c @@ -1,3 +1,5 @@ +#include "ble_proto_utils.h" + #include "ble_proto_packet.h" bool ble_through_proto_check_packet(ble_through_proto_t *packet) { @@ -32,3 +34,45 @@ uint8_t ble_through_proto_sum(ble_through_proto_t *packet) { } return sum; } + +#define ITERM(_cmd, content) \ + { .cmd = _cmd, .length = BLE_PACKET_BASE_SIZE() + sizeof(content) } + +#define EMPTY_CONTENT uint8_t + +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; +} diff --git a/ble_through/ble_proto_utils.h b/ble_through/ble_proto_utils.h index 69eb0f8..21fa503 100644 --- a/ble_through/ble_proto_utils.h +++ b/ble_through/ble_proto_utils.h @@ -2,6 +2,10 @@ #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); @@ -15,4 +19,15 @@ uint8_t ble_through_proto_sum(ble_through_proto_t *packet); { \ uint8_t *__data = (uint8_t *)packet; \ __data[packet->packetlen - 2] = hand_acid_ble_proto_sum(packet); \ - } \ No newline at end of file + } + +typedef struct { + uint8_t cmd; + uint8_t length; +} cmd_info_t; + +cmd_info_t *getcmdinfo(uint8_t cmd); + +#ifdef __cplusplus +} +#endif diff --git a/protocol.h b/protocol.h index 8b1f31e..78c4e9c 100644 --- a/protocol.h +++ b/protocol.h @@ -4,3 +4,5 @@ #include "ble_through/ble_proto.h" #include "errorcode.h" + +