Browse Source

update

master^2^2
zhaohe 1 year ago
parent
commit
c2c565b6eb
  1. 2
      ble_through/ble_proto.h
  2. 5
      ble_through/ble_proto_packet.h
  3. 44
      ble_through/ble_proto_utils.c
  4. 17
      ble_through/ble_proto_utils.h
  5. 2
      protocol.h

2
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

5
ble_through/ble_proto_packet.h

@ -1,5 +1,4 @@
#pragma once
#pragma once
#include <stdbool.h>
#include <stdint.h>
//
@ -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

44
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;
}

17
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); \
}
}
typedef struct {
uint8_t cmd;
uint8_t length;
} cmd_info_t;
cmd_info_t *getcmdinfo(uint8_t cmd);
#ifdef __cplusplus
}
#endif

2
protocol.h

@ -4,3 +4,5 @@
#include "ble_through/ble_proto.h"
#include "errorcode.h"
Loading…
Cancel
Save