[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:
SG
2021-10-12 21:48:34 +10:00
committed by GitHub
parent 841e18dfec
commit b85a50f912
29 changed files with 2565 additions and 18 deletions

View File

@@ -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,