Fixes + UUIDs

This commit is contained in:
leo 2023-06-24 16:33:36 +02:00
parent 70daef58f8
commit c879e0dd70
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
3 changed files with 81 additions and 5 deletions

16
BLEh.c
View File

@ -1,6 +1,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
#include "nimble/nimble_port.h"
@ -28,8 +29,8 @@ static struct ble_hs_adv_fields adv_fields = {
.tx_pwr_lvl_is_present = 1,
.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO,
.flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP,
.name = (uint8_t*)&"Power Profiler"[0],
.name_len = 15,
.name = NULL,
.name_len = 0,
.name_is_complete = 1,
};
@ -110,11 +111,15 @@ void set_gatt_services(struct ble_gatt_svc_def* svcs, uint16_t num){
for(int svc_ind = 0; svc_ind < svcs_num; svc_ind++){
struct ble_gatt_chr_def chr = svc.characteristics[0];
svcs_sizes = realloc(svcs_sizes, svc_ind * sizeof(uint16_t));
svcs_sizes = realloc(svcs_sizes, (svc_ind + 1) * sizeof(uint16_t));
int chr_ind;
for(chr_ind = 0; chr.uuid != NULL; chr_ind++) ;
for(chr_ind = 0; chr.uuid != NULL; chr_ind++){
chr = svc.characteristics[chr_ind];
}
svcs_sizes[svc_ind] = chr_ind - 1;
ESP_LOGI(TAG, "Service n°%d found %d characteristics", svc_ind, svcs_sizes[svc_ind]);
}
//then we allocate
@ -139,6 +144,9 @@ void set_gatt_services(struct ble_gatt_svc_def* svcs, uint16_t num){
}
void initBLE(char* name){
adv_fields.name = (uint8_t*)name;
adv_fields.name_len = strlen(name);
nimble_port_init();
ble_hs_cfg.sync_cb = ble_on_sync;

63
include/BLE_UUID.h Normal file
View File

@ -0,0 +1,63 @@
#pragma once
#define METROLOGY_SERVICE 0x1878
#define CONFIGURATION_SERVICE 0x1879
#define METROLOGY_RANGE_SERVICE 0x1880
#define ELECTRIC_CURRENT_CHAR 0x2AEE
#define VOLTAGE_CHAR 0x2B18
#define SAMPLING_RATE_CHAR 0x2C12
#define ZERO_CALI_CHAR 0x2C13
#define ZERO_CALI_RESET 0x2C16
#define ZERO_CALI_NSAMP 0x2C14
#define ELECTRIC_CURRENT_RANGE_CHAR 0x2AEF
#define AUTO_RANGE_CHAR 0x2C15
#define SWITCHING_FREQUENCY_CHAR 0x2C17
#define CHAR_PRES_FORMAT 0x2904
#define SOURCE_GAIN_DESCR 0x2920
#define PPM_UNIT_UUID 0x27C4
#define PERCENT_UNIT_UUID 0x27AD
#define POWER_UNIT_UUID 0x2726
#define TESLA_UNIT_UUID 0x272D
#define AMPERE_UNIT_UUID 0x2704
#define VOLTS_UNIT_UUID 0x2728
#define HERTZ_UNIT_UUID 0x2722
#define SECONDS_UNIT_UUID 0x2703
#define UNITLESS_UNIT_UUID 0x2700
#define NSP_DESC_MAIN 0x0106
#define NSP_DESC_INSIDE 0x010B
#define NSP_DESC_OUTSIDE 0x010C
enum {
FORMAT_RFU,
FORMAT_BOOL,
FORMAT_UINT2,
FORMAT_UINT4,
FORMAT_UINT8,
FORMAT_UINT12,
FORMAT_UINT16,
FORMAT_UINT24,
FORMAT_UINT32,
FORMAT_UINT48,
FORMAT_UINT64,
FORMAT_UINT128,
FORMAT_INT8,
FORMAT_INT12,
FORMAT_INT16,
FORMAT_INT24,
FORMAT_INT32,
FORMAT_INT48,
FORMAT_INT64,
FORMAT_INT128,
FORMAT_FLOAT32,
FORMAT_FLOAT64,
FORMAT_IEEE11073_SFLOAT16,
FORMAT_IEEE11073_FLOAT32,
FORMAT_IEEE20601,
FORMAT_UTF8,
FORMAT_UTF16,
FORMAT_OPAQUE,
};

View File

@ -1,2 +1,7 @@
#include <stdint.h>
#include "host/ble_gatt.h"
void initBLE(char* name);
void ble_advertise(void);
void ble_advertise(void);
void set_gatt_services(struct ble_gatt_svc_def* svcs, uint16_t num);