split value server char pres format
This commit is contained in:
parent
2ce2ec0e5a
commit
3a8c03a7d3
10
BLEh.c
10
BLEh.c
@ -19,6 +19,7 @@
|
||||
#define TAG "BLEh"
|
||||
|
||||
static uint16_t conn_handle;
|
||||
static uint8_t conn_state;
|
||||
|
||||
static struct ble_gatt_svc_def* gatt_svr_svcs;
|
||||
static uint16_t svcs_num;
|
||||
@ -72,14 +73,17 @@ static int ble_gap_event(struct ble_gap_event *event, void* arg){
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
if(event->connect.status)
|
||||
ble_advertise();
|
||||
else
|
||||
else{
|
||||
conn_handle = event->connect.conn_handle;
|
||||
conn_state = 1;
|
||||
}
|
||||
break;
|
||||
case BLE_GAP_EVENT_DISCONNECT:
|
||||
conn_state = 0;
|
||||
ble_advertise();
|
||||
break;
|
||||
case BLE_GAP_EVENT_SUBSCRIBE:
|
||||
ESP_LOGI(TAG, "Subscribe %d", event->subscribe.attr_handle);
|
||||
ESP_LOGI(TAG, "Subscribe %d %d", event->subscribe.attr_handle, event->subscribe.cur_notify);
|
||||
uint8_t* target_state = get_notify_state(event->subscribe.attr_handle);
|
||||
if(target_state == NULL)
|
||||
ESP_LOGE(TAG, "Unknown notification requested");
|
||||
@ -212,6 +216,8 @@ void print_service(struct ble_gatt_svc_def* svcs){
|
||||
}
|
||||
|
||||
void notify(uint16_t svc_ind, uint16_t chr_ind, void* value, size_t value_size){
|
||||
if(!conn_state) return;
|
||||
|
||||
uint16_t handle = get_att_handle(svc_ind, chr_ind);
|
||||
|
||||
uint8_t state = *get_notify_state_from_indices(svc_ind, chr_ind);
|
||||
|
@ -6,9 +6,18 @@
|
||||
#include "BLEh.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef void* gatt_value_server_handle_t;
|
||||
struct serve_conf {
|
||||
uint8_t* value;
|
||||
size_t value_size;
|
||||
struct char_pres_format* format;
|
||||
uint16_t svc_ind;
|
||||
uint16_t chr_ind;
|
||||
};
|
||||
|
||||
gatt_value_server_handle_t simple_gatt_value_server(void* values, int values_num, size_t values_size, struct char_pres_format format, struct ble_gatt_svc_def* svc, uint16_t svc_ind, ble_uuid_t* uuid);
|
||||
typedef struct serve_conf** gatt_value_server_handle_t;
|
||||
|
||||
gatt_value_server_handle_t simple_gatt_value_server(void* values, size_t values_size, int values_num, struct char_pres_format* format[], struct ble_gatt_svc_def* svc, uint16_t svc_ind, ble_uuid_t* uuid);
|
||||
gatt_value_server_handle_t simple_gatt_identical_values_server(void* values, size_t values_size, int values_num, struct char_pres_format* format, struct ble_gatt_svc_def* svc, uint16_t svc_ind, ble_uuid_t* uuid);
|
||||
void simple_gatt_value_server_deinit();
|
||||
|
||||
void simple_gatt_value_server_notify(gatt_value_server_handle_t handle, int values_num);
|
@ -11,22 +11,13 @@
|
||||
|
||||
#include "BLE_UUID.h"
|
||||
#include "BLEh.h"
|
||||
#include "simple_gatt_value_server.h"
|
||||
|
||||
#define TAG "GATT value server"
|
||||
|
||||
struct serve_conf {
|
||||
uint8_t* value;
|
||||
size_t value_size;
|
||||
struct char_pres_format* format;
|
||||
uint16_t svc_ind;
|
||||
uint16_t chr_ind;
|
||||
};
|
||||
|
||||
static struct serve_conf** serve_confs;
|
||||
typedef struct serve_conf** gatt_value_server_handle_t;
|
||||
|
||||
static uint16_t svcs_num = 0;
|
||||
struct char_pres_format* formats;
|
||||
struct ble_gatt_chr_def** chars;
|
||||
struct ble_gatt_dsc_def** descrs;
|
||||
|
||||
@ -53,21 +44,18 @@ int read_handler(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_acc
|
||||
|
||||
ble_uuid_t* char_pres_format = BLE_UUID16_DECLARE(CHAR_PRES_FORMAT);
|
||||
|
||||
gatt_value_server_handle_t simple_gatt_value_server(uint8_t* values, size_t value_size, int values_num, struct char_pres_format format, struct ble_gatt_svc_def* svc, uint16_t svc_ind, ble_uuid_t* char_uuid){
|
||||
gatt_value_server_handle_t simple_gatt_value_server(void* values, size_t value_size, int values_num, struct char_pres_format* format[], struct ble_gatt_svc_def* svc, uint16_t svc_ind, ble_uuid_t* char_uuid){
|
||||
struct ble_gatt_chr_def* chrs = malloc((values_num + 1) * sizeof(struct ble_gatt_chr_def));
|
||||
|
||||
formats = realloc(formats, (svcs_num + 1) * sizeof(struct char_pres_format));
|
||||
chars = realloc(chars, (svcs_num + 1) * sizeof(struct ble_gatt_chr_def*));
|
||||
chars[svcs_num] = chrs;
|
||||
|
||||
memcpy(&formats[svcs_num], &format, sizeof(format));
|
||||
|
||||
for(int i = 0; i < values_num; i++){
|
||||
serve_confs = realloc(serve_confs, (serve_num + 1) * sizeof(struct serve_conf*));
|
||||
serve_confs[serve_num] = malloc(sizeof(struct serve_conf));
|
||||
serve_confs[serve_num]->value = values+(i*value_size);
|
||||
serve_confs[serve_num]->value_size = value_size;
|
||||
serve_confs[serve_num]->format = &formats[svcs_num];
|
||||
serve_confs[serve_num]->format = format[i];
|
||||
serve_confs[serve_num]->svc_ind = svc_ind;
|
||||
serve_confs[serve_num]->chr_ind = i;
|
||||
|
||||
@ -103,10 +91,16 @@ gatt_value_server_handle_t simple_gatt_value_server(uint8_t* values, size_t valu
|
||||
return &serve_confs[serve_num - values_num];
|
||||
}
|
||||
|
||||
gatt_value_server_handle_t simple_gatt_identical_values_server(void* values, size_t values_size, int values_num, struct char_pres_format* format, struct ble_gatt_svc_def* svc, uint16_t svc_ind, ble_uuid_t* uuid){
|
||||
struct char_pres_format* formats[values_num];
|
||||
for(int i = 0; i < values_num; i++) formats[i] = format;
|
||||
|
||||
return simple_gatt_value_server(values, values_size, values_num, formats, svc, svc_ind, uuid);
|
||||
}
|
||||
|
||||
void simple_gatt_value_server_deinit(){
|
||||
for(int i = 0; i < serve_num; i++) free(serve_confs[i]);
|
||||
free(serve_confs);
|
||||
free(formats);
|
||||
for(int i = 0; i < svcs_num; i++)
|
||||
free(chars[i]);
|
||||
free(chars);
|
||||
|
Loading…
x
Reference in New Issue
Block a user