[FL-1792] RPC service (#698)
* Lib: added nanopb * Hal rfid: fixed confused arguments * Lib: update makefile, include nanopb * Lib: remove nanopb * Lib: add nanopb as submodule * Assets: remove protobuf * Assets: add protobuf message definitions as submodule * WIP: [FL-1792] Add Protobuf RPC * WIP: RPC add ping * Add Ping * Fix Ping, Add (WIP) storage * Update submodule * ble-glue: add ptotobuf to ble * WIP: Add storage list test * revert applications.mk * Add Storage List command * ble-glue: fix fast updating rx charachteristic * ble serial: split long ble packets * Add Storage Read/Write/Mkdir/Delete * Disable tests * Rename Element -> File * Add md5sum, fix test leak * Regenerate Protobuf * Fix review comments * ble-glue: sync f7 target Co-authored-by: Albert Kharisov <albert@flipperdevices.com> Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "serial_service.h"
|
||||
|
||||
#include <applications/bt/bt_service/bt.h>
|
||||
#include <applications/rpc/rpc.h>
|
||||
#include <furi-hal.h>
|
||||
|
||||
#define GAP_TAG "BLE"
|
||||
@@ -34,6 +35,8 @@ typedef struct {
|
||||
osMutexId_t state_mutex;
|
||||
uint8_t mac_address[BD_ADDR_SIZE_LOCAL];
|
||||
Bt* bt;
|
||||
Rpc* rpc;
|
||||
RpcSession* rpc_session;
|
||||
osTimerId advertise_timer;
|
||||
osThreadAttr_t thread_attr;
|
||||
osThreadId_t thread_id;
|
||||
@@ -81,7 +84,8 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
|
||||
if (disconnection_complete_event->Connection_Handle == gap->gap_svc.connection_handle) {
|
||||
gap->gap_svc.connection_handle = 0;
|
||||
gap->state = GapStateIdle;
|
||||
FURI_LOG_I(GAP_TAG, "Disconnect from client");
|
||||
FURI_LOG_I(GAP_TAG, "Disconnect from client. Close RPC session");
|
||||
rpc_close_session(gap->rpc_session);
|
||||
}
|
||||
if(gap->enable_adv) {
|
||||
// Restart advertising
|
||||
@@ -116,7 +120,9 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
|
||||
case EVT_LE_CONN_COMPLETE:
|
||||
furi_hal_power_insomnia_enter();
|
||||
hci_le_connection_complete_event_rp0* connection_complete_event = (hci_le_connection_complete_event_rp0 *) meta_evt->data;
|
||||
FURI_LOG_I(GAP_TAG, "Connection complete for connection handle 0x%x", connection_complete_event->Connection_Handle);
|
||||
FURI_LOG_I(GAP_TAG, "Connection complete for connection handle 0x%x. Start RPC session", connection_complete_event->Connection_Handle);
|
||||
gap->rpc_session = rpc_open_session(gap->rpc);
|
||||
serial_svc_set_rpc_session(gap->rpc_session);
|
||||
|
||||
// Stop advertising as connection completed
|
||||
osTimerStop(gap->advertise_timer);
|
||||
@@ -377,8 +383,9 @@ bool gap_init() {
|
||||
|
||||
gap = furi_alloc(sizeof(Gap));
|
||||
srand(DWT->CYCCNT);
|
||||
// Open Bt record
|
||||
// Open records
|
||||
gap->bt = furi_record_open("bt");
|
||||
gap->rpc = furi_record_open("rpc");
|
||||
// Create advertising timer
|
||||
gap->advertise_timer = osTimerNew(gap_advetise_timer_callback, osTimerOnce, NULL, NULL);
|
||||
// Initialization of GATT & GAP layer
|
||||
|
@@ -12,6 +12,8 @@ typedef struct {
|
||||
uint16_t svc_handle;
|
||||
uint16_t rx_char_handle;
|
||||
uint16_t tx_char_handle;
|
||||
RpcSession* rpc_session;
|
||||
osSemaphoreId_t rpc_sem;
|
||||
} SerialSvc;
|
||||
|
||||
static SerialSvc* serial_svc;
|
||||
@@ -20,6 +22,21 @@ static const uint8_t service_uuid[] = {0x00, 0x00, 0xfe, 0x60, 0xcc, 0x7a, 0x48,
|
||||
static const uint8_t char_rx_uuid[] = {0x00, 0x00, 0xfe, 0x61, 0x8e, 0x22, 0x45, 0x41, 0x9d, 0x4c, 0x21, 0xed, 0xae, 0x82, 0xed, 0x19};
|
||||
static const uint8_t char_tx_uuid[] = {0x00, 0x00, 0xfe, 0x62, 0x8e, 0x22, 0x45, 0x41, 0x9d, 0x4c, 0x21, 0xed, 0xae, 0x82, 0xed, 0x19};
|
||||
|
||||
void serial_svc_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t bytes_len) {
|
||||
size_t bytes_sent = 0;
|
||||
while(bytes_sent < bytes_len) {
|
||||
size_t bytes_remain = bytes_len - bytes_sent;
|
||||
if(bytes_remain > SERIAL_SVC_DATA_LEN_MAX) {
|
||||
serial_svc_update_rx(&bytes[bytes_sent], SERIAL_SVC_DATA_LEN_MAX);
|
||||
bytes_sent += SERIAL_SVC_DATA_LEN_MAX;
|
||||
} else {
|
||||
serial_svc_update_rx(&bytes[bytes_sent], bytes_remain);
|
||||
bytes_sent += bytes_remain;
|
||||
}
|
||||
osSemaphoreAcquire(serial_svc->rpc_sem, osWaitForever);
|
||||
}
|
||||
}
|
||||
|
||||
static SVCCTL_EvtAckStatus_t serial_svc_event_handler(void *event) {
|
||||
SVCCTL_EvtAckStatus_t ret = SVCCTL_EvtNotAck;
|
||||
hci_event_pckt* event_pckt = (hci_event_pckt *)(((hci_uart_pckt*)event)->data);
|
||||
@@ -34,10 +51,12 @@ static SVCCTL_EvtAckStatus_t serial_svc_event_handler(void *event) {
|
||||
FURI_LOG_D(SERIAL_SERVICE_TAG, "TX descriptor event");
|
||||
} else if(attribute_modified->Attr_Handle == serial_svc->tx_char_handle + 1) {
|
||||
FURI_LOG_D(SERIAL_SERVICE_TAG, "Received %d bytes", attribute_modified->Attr_Data_Length);
|
||||
serial_svc_update_rx(attribute_modified->Attr_Data, attribute_modified->Attr_Data_Length);
|
||||
rpc_feed_bytes(serial_svc->rpc_session, attribute_modified->Attr_Data, attribute_modified->Attr_Data_Length, 1000);
|
||||
// serial_svc_update_rx(attribute_modified->Attr_Data, attribute_modified->Attr_Data_Length);
|
||||
ret = SVCCTL_EvtAckFlowEnable;
|
||||
}
|
||||
} else if(blecore_evt->ecode == ACI_GATT_SERVER_CONFIRMATION_VSEVT_CODE) {
|
||||
osSemaphoreRelease(serial_svc->rpc_sem);
|
||||
FURI_LOG_D(SERIAL_SERVICE_TAG, "Ack received", blecore_evt->ecode);
|
||||
ret = SVCCTL_EvtAckFlowEnable;
|
||||
}
|
||||
@@ -45,9 +64,10 @@ static SVCCTL_EvtAckStatus_t serial_svc_event_handler(void *event) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void serial_svc_start() {
|
||||
void serial_svc_start(Rpc* rpc) {
|
||||
tBleStatus status;
|
||||
serial_svc = furi_alloc(sizeof(SerialSvc));
|
||||
serial_svc->rpc_sem = osSemaphoreNew(1, 0, NULL);
|
||||
// Register event handler
|
||||
SVCCTL_RegisterSvcHandler(serial_svc_event_handler);
|
||||
|
||||
@@ -106,12 +126,20 @@ void serial_svc_stop() {
|
||||
}
|
||||
}
|
||||
|
||||
void serial_svc_set_rpc_session(RpcSession* rpc_session) {
|
||||
furi_assert(rpc_session);
|
||||
// Set session
|
||||
serial_svc->rpc_session = rpc_session;
|
||||
// Set callback
|
||||
rpc_set_send_bytes_callback(serial_svc->rpc_session, serial_svc_rpc_send_bytes_callback, NULL);
|
||||
}
|
||||
|
||||
|
||||
bool serial_svc_update_rx(uint8_t* data, uint8_t data_len) {
|
||||
if(data_len > SERIAL_SVC_DATA_LEN_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FURI_LOG_D(SERIAL_SERVICE_TAG, "Updating char %d len", data_len);
|
||||
tBleStatus result = aci_gatt_update_char_value(serial_svc->svc_handle,
|
||||
serial_svc->rx_char_handle,
|
||||
0,
|
||||
|
@@ -3,12 +3,17 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void serial_svc_start();
|
||||
|
||||
void serial_svc_set_rpc_session(RpcSession* rpc_session);
|
||||
|
||||
void serial_svc_stop();
|
||||
|
||||
bool serial_svc_update_rx(uint8_t* data, uint8_t data_len);
|
||||
|
Reference in New Issue
Block a user