Browse Source

recode

sunlight
zhaohe 11 months ago
parent
commit
5ff84db1ea
  1. 3
      .vscode/settings.json
  2. 3
      app_protocols/app_protocols.h
  3. 5
      app_protocols/bean/hand_acid_remoter_key_event.h
  4. 54
      app_protocols/ble_through/ble_cmd_app.h
  5. 71
      app_protocols/ble_through/ble_cmd_public.h
  6. 89
      app_protocols/ble_through/ble_proto.h
  7. 54
      app_protocols/ble_through/ble_proto_packet.h
  8. 66
      app_protocols/ble_through/ble_proto_utils.c
  9. 22
      app_protocols/ble_through/ble_proto_utils.h
  10. 1
      uappbase/appdep.hpp
  11. 2
      uappbase/base.hpp
  12. 50
      usrc/service/remote_controler.cpp
  13. 11
      usrc/service/remote_controler.hpp
  14. 4
      usrc/service/remote_controler_event_processer.cpp
  15. 2
      usrc/service/remote_controler_event_processer.hpp

3
.vscode/settings.json

@ -82,7 +82,8 @@
"pin.h": "c",
"stm32.h": "c",
"stm32f4xx_it.h": "c",
"ble_proto_utils.h": "c"
"ble_proto_utils.h": "c",
"ble_proto.h": "c"
},
"files.autoGuessEncoding": false,
"files.encoding": "gb2312"

3
app_protocols/app_protocols.h

@ -4,4 +4,5 @@
//
#include "zscanprotocol/zscanprotocol.h"
#include "hand_acid_val_protocol/hand_acid_val_protocol.h"
#include "ble_through/ble_proto.h"
#include "ble_through/ble_proto.h"
#include "ble_through/ble_proto_utils.h"

5
app_protocols/bean/hand_acid_remoter_key_event.h

@ -0,0 +1,5 @@
#pragma once
typedef enum {
hand_acid_remoter_kevent_add_liquid = 0, //
hand_acid_remoter_kevent_change_next_mode = 1, //
} hand_acid_remoter_key_event_t;

54
app_protocols/ble_through/ble_cmd_app.h

@ -1,54 +0,0 @@
#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

71
app_protocols/ble_through/ble_cmd_public.h

@ -1,71 +0,0 @@
#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

89
app_protocols/ble_through/ble_proto.h

@ -6,13 +6,88 @@
#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"
#define PACKET_H1 (0xAA)
#define PACKET_H2 (0xBB)
#define PACKET_TAIL (0xCC)
typedef enum {
kzble_proto_cmd = 1,
kzble_proto_cmd_receipt = 2,
kzble_proto_report = 3,
kzble_proto_error_receipt = 4,
} zble_proto_packet_type_t;
typedef enum {
kzble_upper = 1,
kzble_master = 2,
kzble_slave = 3,
} zble_proto_role_t;
/***********************************************************************************************************************
* ENUM *
***********************************************************************************************************************/
#pragma pack(1)
typedef struct {
uint8_t h1;
uint8_t h2;
uint8_t packetlen;
uint8_t frameType;
uint8_t frameIndex;
uint16_t cmd;
uint8_t from;
uint8_t to;
uint8_t data[];
} zble_proto_packet_t;
typedef enum {
kzble_cmd_reset = 100, //
kzble_cmd_read_version = 101, // param:{} receipt:ble_master_read_version_t
kzble_cmd_start_scan = 102, // param:zble_start_scan_t receipt:{}
kzble_cmd_stop_scan = 103, // param:{} receipt:{}
kzble_cmd_enter_dfu_scan = 104, // param:{} receipt:{}
kzble_cmd_clear_reset_flag = 105, //
kzble_report_connected_event = 150, // zble_connected_event_t
kzble_report_scan_result = 151, // zble_scan_result_t
kzble_report_power_on = 152, //
kzble_report_heart = 153, // zble_heart_t
kzble_app_cmd_set_state = 200, // params:workmode(hand_acid_mode_t),pumpworkstate(0:notwork,1:work)
kzble_app_report_key_event = 250, // params:hand_acid_remoter_key_event_t
} ble_app_proto_cmd_t;
typedef struct {
uint8_t auto_connect;
uint8_t auto_connect_client_name[20];
} zble_start_scan_t;
typedef struct {
uint8_t connected;
char blename[20];
char bleid[20];
} zble_connected_event_t;
typedef struct {
char blename[20];
char bleid[20];
uint8_t rssi;
} zble_scan_result_t;
typedef struct {
int32_t firmware_version;
int32_t blestack_version;
int32_t bootloader_version;
int32_t hardware_version;
} zble_read_version_t;
typedef struct {
uint8_t reset_flag;
uint8_t connected_flag;
} zble_heart_t;
#pragma pack()
#ifdef __cplusplus
}
#endif

54
app_protocols/ble_through/ble_proto_packet.h

@ -1,54 +0,0 @@
#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

66
app_protocols/ble_through/ble_proto_utils.c

@ -1,11 +1,11 @@
#include "ble_proto_utils.h"
#include <stdio.h>
#include <string.h>
#include "ble_proto_packet.h"
bool ble_through_proto_check_packet(ble_through_proto_t *packet) {
bool ble_through_proto_check_packet(zble_proto_packet_t *packet) {
uint8_t *pu8 = (uint8_t *)packet;
if (packet->packetlen < (BLE_PACKET_BASE_SIZE())) {
if (packet->packetlen < (BLE_THROUGH_PACKET_BASE_SIZE())) {
return false;
}
if (packet->h1 != PACKET_H1 || packet->h2 != PACKET_H2) {
@ -26,7 +26,7 @@ bool ble_through_proto_check_packet(ble_through_proto_t *packet) {
return true;
}
uint8_t ble_through_proto_sum(ble_through_proto_t *packet) {
uint8_t ble_through_proto_sum(zble_proto_packet_t *packet) {
uint8_t *_packet = (uint8_t *)packet;
uint8_t sum = 0;
for (int i = 0; i < packet->packetlen - 2; i++) {
@ -35,46 +35,18 @@ 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
#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;
void zble_proto_utils_create_cmd_packet(zble_proto_packet_t *packet, uint16_t cmd, uint8_t index, uint8_t *data, int32_t datalen) {
int32_t packetlen = BLE_THROUGH_PACKET_BASE_SIZE() + datalen;
packet->h1 = PACKET_H1;
packet->h2 = PACKET_H2;
packet->packetlen = packetlen;
packet->frameType = kzble_proto_cmd;
packet->frameIndex = index;
packet->cmd = cmd;
memcpy((void *)packet->data, data, datalen);
BLE_THROUGH_PACKET_SET_CHECKSUM(packet);
BLE_THROUGH_PACKET_SET_TAIL(packet);
}
#endif
void zble_proto_utils_create_cmd_packet_int32(zble_proto_packet_t *packet, uint16_t cmd, uint8_t index, int32_t *data, int32_t ndata) { zble_proto_utils_create_cmd_packet(packet, cmd, index, (uint8_t *)data, ndata * 4); }

22
app_protocols/ble_through/ble_proto_utils.h

@ -1,32 +1,30 @@
#pragma once
#include "ble_proto_packet.h"
#include "ble_proto.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; \
#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;
#define BLE_THROUGH_PACKET_BASE_SIZE() (sizeof(zble_proto_packet_t) + 1)
bool ble_through_proto_check_packet(zble_proto_packet_t *packet);
uint8_t ble_through_proto_sum(zble_proto_packet_t *packet);
cmd_info_t *getcmdinfo(uint8_t cmd);
void zble_proto_utils_create_cmd_packet(zble_proto_packet_t *packet, uint16_t cmd, uint8_t index, uint8_t *data, int32_t datalen);
void zble_proto_utils_create_cmd_packet_int32(zble_proto_packet_t *packet, uint16_t cmd, uint8_t index, int32_t *data, int32_t ndata);
#ifdef __cplusplus
}

1
uappbase/appdep.hpp

@ -2,5 +2,6 @@
#include "stm32basic/stm32basic.hpp"
#include "stm32halport/stm32halport.hpp"
#include "stm32components/stm32components.hpp"
#include "app_protocols/app_protocols.h"
//
#include "main.h"

2
uappbase/base.hpp

@ -6,4 +6,4 @@
#include "service/app_core.hpp"
#include "service/app_event_bus.hpp"
#include "service/gstate_mgr.hpp"
#include "service/config_service.hpp"
#include "service/config_service.hpp"

50
usrc/service/remote_controler.cpp

@ -1,11 +1,11 @@
#include "remote_controler.hpp"
#include "app_protocols/ble_through/ble_proto_utils.h"
using namespace iflytop;
#define UART_RX_OVERTIME 3
#define TAG "RemoteControler"
#define CMD_OVERTIME 500
static ZQueue<RemoteControlerReportPacket_t> ackQueue;
@ -70,12 +70,15 @@ void RemoteControler::startSchedule() {
}
if (rxpacket.datalen != 0) {
pre_processrxpacket(&rxpacket);
preProcessrxpacket(&rxpacket);
}
osDelay(1);
}
});
/**
* @brief
*/
eventProcessThread.start([this]() {
while (1) {
static RemoteControlerReportPacket_t packet;
@ -87,28 +90,25 @@ void RemoteControler::startSchedule() {
}
});
}
extern "C"{
bool ble_through_proto_check_packet(ble_through_proto_t *packet);
}
void RemoteControler::pre_processrxpacket(RemoteControlerReportPacket_t* packet) {
void RemoteControler::preProcessrxpacket(RemoteControlerReportPacket_t* packet) {
// 判断包是否合法
#if DEBUG
ZLOGI(TAG, "[rx-thread] : rx :%s(%d)", zhex2str(packet->data, packet->datalen), packet->datalen);
#endif
ble_through_proto_t* p_packet = (ble_through_proto_t*)packet->data;
zble_proto_packet_t* p_packet = (zble_proto_packet_t*)packet->data;
if (!ble_through_proto_check_packet(p_packet)) {
ZLOGI(TAG, "rx invalid packet %s", zhex2str(packet->data, packet->datalen));
return;
}
bool suc = true;
if (p_packet->frame_type == kproto_cmd) {
if (p_packet->frameType == kzble_proto_cmd) {
// suc = ackQueue.send(packet, 10);
} else if (p_packet->frame_type == kproto_report) {
} else if (p_packet->frameType == kzble_proto_report) {
suc = eventQueue.send(packet, 10);
} else if (p_packet->frame_type == kproto_error_receipt || p_packet->frame_type == kproto_cmd_receipt) {
} else if (p_packet->frameType == kzble_proto_error_receipt || p_packet->frameType == kzble_proto_cmd_receipt) {
if (m_isWaitingForAck) {
suc = ackQueue.send(packet, 10);
m_isWaitingForAck = false;
@ -128,24 +128,6 @@ void RemoteControler::processRxEventPacket(RemoteControlerReportPacket_t* packet
// }
callOnReport(packet->data, packet->datalen);
}
#if 0
bool RemoteControler::cmd_set_state(hand_acid_mode_t mode, hand_pump_working_state_t state) {
ble_through_proto_t* packet = (ble_through_proto_t*)txbuf;
int32_t packetlen = HAND_ACID_BLE_BASE_SIZE + 2 + sizeof(packet->data.set_state);
packet->h1 = PACKET_H1;
packet->h2 = PACKET_H2;
packet->packetlen = packetlen;
packet->frame_type = kproto_cmd;
packet->frame_index = 1;
packet->cmd = kproto_cmd_set_state;
packet->data.set_state.hand_acid_mode = (uint8_t)mode;
packet->data.set_state.hand_pump_working_state = (uint8_t)state;
PACKET_SET_CHECKSUM(packet);
PACKET_SET_TAIL(packet);
return txcmd(txbuf, packetlen);
}
#endif
bool RemoteControler::txcmd(uint8_t* data, uint32_t len) {
/**
* @brief
@ -171,3 +153,15 @@ bool RemoteControler::txcmd(uint8_t* data, uint32_t len) {
HAL_UART_DMAStop(m_uart);
return true;
}
/***********************************************************************************************************************
* CMD *
***********************************************************************************************************************/
bool RemoteControler::setRemoterState(hand_acid_mode_t mode, bool state) {
zble_proto_packet_t* packet = (zble_proto_packet_t*)txbuf;
int32_t param[2] = {mode, state};
zble_proto_utils_create_cmd_packet_int32(packet, kzble_app_cmd_set_state, m_index++, param, 2);
bool suc = txcmd(txbuf, packet->packetlen);
return suc;
}

11
usrc/service/remote_controler.hpp

@ -22,10 +22,11 @@ class RemoteControler {
RemoteControlerReportPacket_t ackcache;
uint8_t txbuf[255];
uint8_t m_index = 0;
public:
RemoteControler(){};
~RemoteControler(){};
RemoteControler() {};
~RemoteControler() {};
static RemoteControler* ins() {
static RemoteControler instance;
@ -41,10 +42,12 @@ class RemoteControler {
private:
bool txcmd(uint8_t* data, uint32_t len);
void pre_processrxpacket(RemoteControlerReportPacket_t* packet);
void preProcessrxpacket(RemoteControlerReportPacket_t* packet);
void processRxEventPacket(RemoteControlerReportPacket_t* packet);
void callOnReport(uint8_t* rx, int32_t len);
public:
bool setRemoterState(hand_acid_mode_t mode, bool state);
};
} // namespace iflytop

4
usrc/service/remote_controler_event_processer.cpp

@ -4,11 +4,11 @@ using namespace iflytop;
void RemoterControlerEventProcesser::initialize() {
//
RemoteControler::ins()->regOnReport([this](uint8_t* rx, int32_t len) { //
onPacket((ble_through_proto_t*)rx);
onPacket((zble_proto_packet_t*)rx);
});
}
void RemoterControlerEventProcesser::onPacket(ble_through_proto_t* packet) {
void RemoterControlerEventProcesser::onPacket(zble_proto_packet_t* packet) {
// kproto_report_key_event
// kproto_report_connected_event

2
usrc/service/remote_controler_event_processer.hpp

@ -15,7 +15,7 @@ class RemoterControlerEventProcesser {
void initialize();
private:
void onPacket(ble_through_proto_t* packet);
void onPacket(zble_proto_packet_t* packet);
};
} // namespace iflytop
Loading…
Cancel
Save