Merge branch 'flipperdevices:dev' into dev

This commit is contained in:
Eng1n33r 2022-03-18 22:48:59 +03:00 committed by GitHub
commit 2c7df8ece5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 4 deletions

View File

@ -1,3 +1,3 @@
#pragma once #pragma once
#define PROTOBUF_MAJOR_VERSION 0 #define PROTOBUF_MAJOR_VERSION 0
#define PROTOBUF_MINOR_VERSION 1 #define PROTOBUF_MINOR_VERSION 2

@ -1 +1 @@
Subproject commit 93b9cf3af76664a27646494341a63281a9022740 Subproject commit 232e7e9a50b12a95f950fabb515204775e51b04a

View File

@ -3,15 +3,20 @@
#include "ble.h" #include "ble.h"
#include <furi.h> #include <furi.h>
#include <m-string.h>
#include <protobuf_version.h>
#define TAG "BtDevInfoSvc" #define TAG "BtDevInfoSvc"
#define DEV_INFO_RPC_VERSION_CHAR_MAX_SIZE (10)
typedef struct { typedef struct {
uint16_t service_handle; uint16_t service_handle;
uint16_t man_name_char_handle; uint16_t man_name_char_handle;
uint16_t serial_num_char_handle; uint16_t serial_num_char_handle;
uint16_t firmware_rev_char_handle; uint16_t firmware_rev_char_handle;
uint16_t software_rev_char_handle; uint16_t software_rev_char_handle;
uint16_t rpc_version_char_handle;
} DevInfoSvc; } DevInfoSvc;
static DevInfoSvc* dev_info_svc = NULL; static DevInfoSvc* dev_info_svc = NULL;
@ -22,6 +27,9 @@ static const char dev_info_firmware_rev_num[] = TOSTRING(TARGET);
static const char dev_info_software_rev_num[] = GIT_COMMIT " " GIT_BRANCH " " GIT_BRANCH_NUM static const char dev_info_software_rev_num[] = GIT_COMMIT " " GIT_BRANCH " " GIT_BRANCH_NUM
" " BUILD_DATE; " " BUILD_DATE;
static const uint8_t dev_info_rpc_version_uuid[] =
{0x33, 0xa9, 0xb5, 0x3e, 0x87, 0x5d, 0x1a, 0x8e, 0xc8, 0x47, 0x5e, 0xae, 0x6d, 0x66, 0xf6, 0x03};
void dev_info_svc_start() { void dev_info_svc_start() {
dev_info_svc = malloc(sizeof(DevInfoSvc)); dev_info_svc = malloc(sizeof(DevInfoSvc));
tBleStatus status; tBleStatus status;
@ -29,7 +37,7 @@ void dev_info_svc_start() {
// Add Device Information Service // Add Device Information Service
uint16_t uuid = DEVICE_INFORMATION_SERVICE_UUID; uint16_t uuid = DEVICE_INFORMATION_SERVICE_UUID;
status = aci_gatt_add_service( status = aci_gatt_add_service(
UUID_TYPE_16, (Service_UUID_t*)&uuid, PRIMARY_SERVICE, 9, &dev_info_svc->service_handle); UUID_TYPE_16, (Service_UUID_t*)&uuid, PRIMARY_SERVICE, 11, &dev_info_svc->service_handle);
if(status) { if(status) {
FURI_LOG_E(TAG, "Failed to add Device Information Service: %d", status); FURI_LOG_E(TAG, "Failed to add Device Information Service: %d", status);
} }
@ -95,6 +103,20 @@ void dev_info_svc_start() {
if(status) { if(status) {
FURI_LOG_E(TAG, "Failed to add software revision char: %d", status); FURI_LOG_E(TAG, "Failed to add software revision char: %d", status);
} }
status = aci_gatt_add_char(
dev_info_svc->service_handle,
UUID_TYPE_128,
(const Char_UUID_t*)dev_info_rpc_version_uuid,
DEV_INFO_RPC_VERSION_CHAR_MAX_SIZE,
CHAR_PROP_READ,
ATTR_PERMISSION_AUTHEN_READ,
GATT_DONT_NOTIFY_EVENTS,
10,
CHAR_VALUE_LEN_CONSTANT,
&dev_info_svc->rpc_version_char_handle);
if(status) {
FURI_LOG_E(TAG, "Failed to add rpc version characteristic: %d", status);
}
// Update characteristics // Update characteristics
status = aci_gatt_update_char_value( status = aci_gatt_update_char_value(
@ -133,6 +155,18 @@ void dev_info_svc_start() {
if(status) { if(status) {
FURI_LOG_E(TAG, "Failed to update software revision char: %d", status); FURI_LOG_E(TAG, "Failed to update software revision char: %d", status);
} }
string_t rpc_version;
string_init_printf(rpc_version, "%d.%d", PROTOBUF_MAJOR_VERSION, PROTOBUF_MINOR_VERSION);
status = aci_gatt_update_char_value(
dev_info_svc->service_handle,
dev_info_svc->rpc_version_char_handle,
0,
strlen(string_get_cstr(rpc_version)),
(uint8_t*)string_get_cstr(rpc_version));
if(status) {
FURI_LOG_E(TAG, "Failed to update rpc version char: %d", status);
}
string_clear(rpc_version);
} }
void dev_info_svc_stop() { void dev_info_svc_stop() {
@ -159,6 +193,11 @@ void dev_info_svc_stop() {
if(status) { if(status) {
FURI_LOG_E(TAG, "Failed to delete software revision char: %d", status); FURI_LOG_E(TAG, "Failed to delete software revision char: %d", status);
} }
status =
aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->rpc_version_char_handle);
if(status) {
FURI_LOG_E(TAG, "Failed to delete rpc version char: %d", status);
}
// Delete service // Delete service
status = aci_gatt_del_service(dev_info_svc->service_handle); status = aci_gatt_del_service(dev_info_svc->service_handle);
if(status) { if(status) {

View File

@ -3,15 +3,20 @@
#include "ble.h" #include "ble.h"
#include <furi.h> #include <furi.h>
#include <m-string.h>
#include <protobuf_version.h>
#define TAG "BtDevInfoSvc" #define TAG "BtDevInfoSvc"
#define DEV_INFO_RPC_VERSION_CHAR_MAX_SIZE (10)
typedef struct { typedef struct {
uint16_t service_handle; uint16_t service_handle;
uint16_t man_name_char_handle; uint16_t man_name_char_handle;
uint16_t serial_num_char_handle; uint16_t serial_num_char_handle;
uint16_t firmware_rev_char_handle; uint16_t firmware_rev_char_handle;
uint16_t software_rev_char_handle; uint16_t software_rev_char_handle;
uint16_t rpc_version_char_handle;
} DevInfoSvc; } DevInfoSvc;
static DevInfoSvc* dev_info_svc = NULL; static DevInfoSvc* dev_info_svc = NULL;
@ -22,6 +27,9 @@ static const char dev_info_firmware_rev_num[] = TOSTRING(TARGET);
static const char dev_info_software_rev_num[] = GIT_COMMIT " " GIT_BRANCH " " GIT_BRANCH_NUM static const char dev_info_software_rev_num[] = GIT_COMMIT " " GIT_BRANCH " " GIT_BRANCH_NUM
" " BUILD_DATE; " " BUILD_DATE;
static const uint8_t dev_info_rpc_version_uuid[] =
{0x33, 0xa9, 0xb5, 0x3e, 0x87, 0x5d, 0x1a, 0x8e, 0xc8, 0x47, 0x5e, 0xae, 0x6d, 0x66, 0xf6, 0x03};
void dev_info_svc_start() { void dev_info_svc_start() {
dev_info_svc = malloc(sizeof(DevInfoSvc)); dev_info_svc = malloc(sizeof(DevInfoSvc));
tBleStatus status; tBleStatus status;
@ -29,7 +37,7 @@ void dev_info_svc_start() {
// Add Device Information Service // Add Device Information Service
uint16_t uuid = DEVICE_INFORMATION_SERVICE_UUID; uint16_t uuid = DEVICE_INFORMATION_SERVICE_UUID;
status = aci_gatt_add_service( status = aci_gatt_add_service(
UUID_TYPE_16, (Service_UUID_t*)&uuid, PRIMARY_SERVICE, 9, &dev_info_svc->service_handle); UUID_TYPE_16, (Service_UUID_t*)&uuid, PRIMARY_SERVICE, 11, &dev_info_svc->service_handle);
if(status) { if(status) {
FURI_LOG_E(TAG, "Failed to add Device Information Service: %d", status); FURI_LOG_E(TAG, "Failed to add Device Information Service: %d", status);
} }
@ -95,6 +103,20 @@ void dev_info_svc_start() {
if(status) { if(status) {
FURI_LOG_E(TAG, "Failed to add software revision char: %d", status); FURI_LOG_E(TAG, "Failed to add software revision char: %d", status);
} }
status = aci_gatt_add_char(
dev_info_svc->service_handle,
UUID_TYPE_128,
(const Char_UUID_t*)dev_info_rpc_version_uuid,
DEV_INFO_RPC_VERSION_CHAR_MAX_SIZE,
CHAR_PROP_READ,
ATTR_PERMISSION_AUTHEN_READ,
GATT_DONT_NOTIFY_EVENTS,
10,
CHAR_VALUE_LEN_CONSTANT,
&dev_info_svc->rpc_version_char_handle);
if(status) {
FURI_LOG_E(TAG, "Failed to add rpc version characteristic: %d", status);
}
// Update characteristics // Update characteristics
status = aci_gatt_update_char_value( status = aci_gatt_update_char_value(
@ -133,6 +155,18 @@ void dev_info_svc_start() {
if(status) { if(status) {
FURI_LOG_E(TAG, "Failed to update software revision char: %d", status); FURI_LOG_E(TAG, "Failed to update software revision char: %d", status);
} }
string_t rpc_version;
string_init_printf(rpc_version, "%d.%d", PROTOBUF_MAJOR_VERSION, PROTOBUF_MINOR_VERSION);
status = aci_gatt_update_char_value(
dev_info_svc->service_handle,
dev_info_svc->rpc_version_char_handle,
0,
strlen(string_get_cstr(rpc_version)),
(uint8_t*)string_get_cstr(rpc_version));
if(status) {
FURI_LOG_E(TAG, "Failed to update rpc version char: %d", status);
}
string_clear(rpc_version);
} }
void dev_info_svc_stop() { void dev_info_svc_stop() {
@ -159,6 +193,11 @@ void dev_info_svc_stop() {
if(status) { if(status) {
FURI_LOG_E(TAG, "Failed to delete software revision char: %d", status); FURI_LOG_E(TAG, "Failed to delete software revision char: %d", status);
} }
status =
aci_gatt_del_char(dev_info_svc->service_handle, dev_info_svc->rpc_version_char_handle);
if(status) {
FURI_LOG_E(TAG, "Failed to delete rpc version char: %d", status);
}
// Delete service // Delete service
status = aci_gatt_del_service(dev_info_svc->service_handle); status = aci_gatt_del_service(dev_info_svc->service_handle);
if(status) { if(status) {