ble refact
This commit is contained in:
parent
629c8aa441
commit
7717393c2c
@ -1 +1 @@
|
|||||||
Subproject commit a15c1ca68e8bc601ae82f5b9184a5742e741ccee
|
Subproject commit 01063a014cc00c4ac1569f812cad0311ba758306
|
@ -1,8 +1,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "BLE_UUID.h"
|
#include "BLEh.h"
|
||||||
#include "esp_attr.h"
|
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
|
||||||
@ -16,9 +15,6 @@
|
|||||||
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
#include "BLEh.h"
|
|
||||||
#include "simple_gatt_value_server.h"
|
|
||||||
|
|
||||||
#include "BLE.h"
|
#include "BLE.h"
|
||||||
#include "measure.h"
|
#include "measure.h"
|
||||||
|
|
||||||
@ -30,7 +26,6 @@ static uint32_t duty_cycle = 50000000;
|
|||||||
static uint8_t adc_pins[] = {CONFIG_OUT_VOLT_PIN, CONFIG_OUT_CURR_PIN, CONFIG_PHASE1_CURR_PIN, CONFIG_PHASE2_CURR_PIN, CONFIG_PHASE3_CURR_PIN};
|
static uint8_t adc_pins[] = {CONFIG_OUT_VOLT_PIN, CONFIG_OUT_CURR_PIN, CONFIG_PHASE1_CURR_PIN, CONFIG_PHASE2_CURR_PIN, CONFIG_PHASE3_CURR_PIN};
|
||||||
|
|
||||||
void on_char_read_handler(int svc_ind, int chr_ind, void** value, size_t* value_size){
|
void on_char_read_handler(int svc_ind, int chr_ind, void** value, size_t* value_size){
|
||||||
ESP_LOGI(TAG, "char read handler");
|
|
||||||
switch(svc_ind){
|
switch(svc_ind){
|
||||||
case CONFIGURATION_SVC_ID:
|
case CONFIGURATION_SVC_ID:
|
||||||
switch (chr_ind){
|
switch (chr_ind){
|
||||||
@ -48,7 +43,6 @@ void on_char_read_handler(int svc_ind, int chr_ind, void** value, size_t* value_
|
|||||||
}
|
}
|
||||||
|
|
||||||
int on_char_write_handler(int svc_ind, int chr_ind, struct os_mbuf* os){
|
int on_char_write_handler(int svc_ind, int chr_ind, struct os_mbuf* os){
|
||||||
ESP_LOGI(TAG, "char write handler");
|
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
|
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@ -82,58 +76,23 @@ void app_main(void){
|
|||||||
nvs_flash_init();
|
nvs_flash_init();
|
||||||
|
|
||||||
uint32_t raw_mv_meas[CONFIG_ADC_IN_PIN_NUM];
|
uint32_t raw_mv_meas[CONFIG_ADC_IN_PIN_NUM];
|
||||||
|
|
||||||
struct char_pres_format mv_char_pres_format = {
|
|
||||||
.format = FORMAT_UINT32,
|
|
||||||
.unit = VOLTS_UNIT_UUID,
|
|
||||||
.exponent = -3,
|
|
||||||
.namespc = 1,
|
|
||||||
.descrH = NSP_DESC_MAIN & 0xff,
|
|
||||||
.descrL = (NSP_DESC_MAIN>>8) & 0xff,
|
|
||||||
};
|
|
||||||
|
|
||||||
gatt_value_server_handle_t raw_mv_serve_handle = simple_gatt_identical_values_server(raw_mv_meas, sizeof(uint32_t), CONFIG_ADC_IN_PIN_NUM, &mv_char_pres_format, &gatt_svcs[RAW_VALUES_SVC_ID], RAW_VALUES_SVC_ID, BLE_UUID16_DECLARE(VOLTAGE_CHAR));
|
|
||||||
|
|
||||||
uint32_t calc_meas[CONFIG_ADC_IN_PIN_NUM];
|
uint32_t calc_meas[CONFIG_ADC_IN_PIN_NUM];
|
||||||
|
|
||||||
struct char_pres_format mA_char_pres_format = {
|
gatt_value_server_handle_t raw_mv_serve_handle, calc_meas_serve_handle;
|
||||||
.format = FORMAT_UINT32,
|
init_ble_app_services(raw_mv_meas, calc_meas, adc_pins, &raw_mv_serve_handle, &calc_meas_serve_handle);
|
||||||
.unit = AMPERE_UNIT_UUID,
|
|
||||||
.exponent = -3,
|
|
||||||
.namespc = 1,
|
|
||||||
.descrH = NSP_DESC_MAIN & 0xff,
|
|
||||||
.descrL = (NSP_DESC_MAIN>>8) & 0xff,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct char_pres_format* calc_meas_formats[CONFIG_ADC_IN_PIN_NUM];
|
set_gatt_services(gatt_svcs, SVCS_NUM);
|
||||||
|
|
||||||
ble_uuid_t* calc_meas_char_uuid[CONFIG_ADC_IN_PIN_NUM];
|
|
||||||
|
|
||||||
for(int i = 0; i < CONFIG_ADC_IN_PIN_NUM; i++){
|
|
||||||
switch(adc_pins[i]){
|
|
||||||
case CONFIG_OUT_VOLT_PIN:
|
|
||||||
calc_meas_formats[i] = &mv_char_pres_format;
|
|
||||||
calc_meas_char_uuid[i] = BLE_UUID16_DECLARE(VOLTAGE_CHAR);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
calc_meas_formats[i] = &mA_char_pres_format;
|
|
||||||
calc_meas_char_uuid[i] = BLE_UUID16_DECLARE(ELECTRIC_CURRENT_CHAR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gatt_value_server_handle_t calc_meas_serve_handle = simple_gatt_value_server(calc_meas, sizeof(uint32_t), CONFIG_ADC_IN_PIN_NUM, calc_meas_formats, &gatt_svcs[CALC_VALUES_SVC_ID], CALC_VALUES_SVC_ID, calc_meas_char_uuid);
|
|
||||||
|
|
||||||
set_on_char_read_handler(on_char_read_handler);
|
set_on_char_read_handler(on_char_read_handler);
|
||||||
set_on_char_write_handler(on_char_write_handler);
|
set_on_char_write_handler(on_char_write_handler);
|
||||||
|
|
||||||
set_gatt_services(gatt_svcs, SVCS_NUM);
|
|
||||||
|
|
||||||
initBLE("ALIM");
|
initBLE("ALIM");
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
fetch_measures();
|
fetch_measures();
|
||||||
get_measures_raw_mV(raw_mv_meas);
|
get_measures_raw_mV(raw_mv_meas);
|
||||||
get_measures_calc(calc_meas);
|
get_measures_calc(calc_meas);
|
||||||
|
ESP_LOGI(TAG, "meas %lu %lu %lu %lu %lu", raw_mv_meas[0], raw_mv_meas[1], raw_mv_meas[2], raw_mv_meas[3], raw_mv_meas[4]);
|
||||||
|
|
||||||
simple_gatt_value_server_notify(raw_mv_serve_handle, CONFIG_ADC_IN_PIN_NUM);
|
simple_gatt_value_server_notify(raw_mv_serve_handle, CONFIG_ADC_IN_PIN_NUM);
|
||||||
simple_gatt_value_server_notify(calc_meas_serve_handle, CONFIG_ADC_IN_PIN_NUM);
|
simple_gatt_value_server_notify(calc_meas_serve_handle, CONFIG_ADC_IN_PIN_NUM);
|
||||||
|
59
main/BLE.c
59
main/BLE.c
@ -1,11 +1,20 @@
|
|||||||
#include "BLE.h"
|
#include <stdint.h>
|
||||||
#include "BLE_UUID.h"
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
#include "BLEh.h"
|
|
||||||
#include "host/ble_att.h"
|
#include "host/ble_att.h"
|
||||||
#include "host/ble_gatt.h"
|
#include "host/ble_gatt.h"
|
||||||
#include "host/ble_uuid.h"
|
#include "host/ble_uuid.h"
|
||||||
|
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
#include "BLE_UUID.h"
|
||||||
|
#include "BLEh.h"
|
||||||
|
#include "simple_gatt_value_server.h"
|
||||||
|
|
||||||
|
#include "BLE.h"
|
||||||
|
|
||||||
|
#define TAG "BLE"
|
||||||
|
|
||||||
struct char_pres_format frequency_char_pres_format = {
|
struct char_pres_format frequency_char_pres_format = {
|
||||||
.format = FORMAT_UINT32,
|
.format = FORMAT_UINT32,
|
||||||
@ -83,3 +92,47 @@ struct ble_gatt_svc_def gatt_svcs[] = {
|
|||||||
},
|
},
|
||||||
{ 0 },
|
{ 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct char_pres_format mv_char_pres_format = {
|
||||||
|
.format = FORMAT_UINT32,
|
||||||
|
.unit = VOLTS_UNIT_UUID,
|
||||||
|
.exponent = -3,
|
||||||
|
.namespc = 1,
|
||||||
|
.descrH = NSP_DESC_MAIN & 0xff,
|
||||||
|
.descrL = (NSP_DESC_MAIN>>8) & 0xff,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct char_pres_format mA_char_pres_format = {
|
||||||
|
.format = FORMAT_UINT32,
|
||||||
|
.unit = AMPERE_UNIT_UUID,
|
||||||
|
.exponent = -3,
|
||||||
|
.namespc = 1,
|
||||||
|
.descrH = NSP_DESC_MAIN & 0xff,
|
||||||
|
.descrL = (NSP_DESC_MAIN>>8) & 0xff,
|
||||||
|
};
|
||||||
|
|
||||||
|
ble_uuid_t* voltage_char_uuid = BLE_UUID16_DECLARE(VOLTAGE_CHAR);
|
||||||
|
ble_uuid_t* current_char_uuid = BLE_UUID16_DECLARE(ELECTRIC_CURRENT_CHAR);
|
||||||
|
|
||||||
|
void init_ble_app_services(uint32_t raw_mv_meas[], uint32_t calc_meas[], uint8_t adc_pins[], gatt_value_server_handle_t* raw_mv_serve_handle, gatt_value_server_handle_t* calc_meas_serve_handle){
|
||||||
|
|
||||||
|
*raw_mv_serve_handle = simple_gatt_identical_values_server(raw_mv_meas, sizeof(uint32_t), CONFIG_ADC_IN_PIN_NUM, &mv_char_pres_format, &gatt_svcs[RAW_VALUES_SVC_ID], RAW_VALUES_SVC_ID, voltage_char_uuid);
|
||||||
|
|
||||||
|
struct char_pres_format* calc_meas_formats[CONFIG_ADC_IN_PIN_NUM];
|
||||||
|
|
||||||
|
ble_uuid_t* calc_meas_char_uuid[CONFIG_ADC_IN_PIN_NUM];
|
||||||
|
|
||||||
|
for(int i = 0; i < CONFIG_ADC_IN_PIN_NUM; i++){
|
||||||
|
switch(adc_pins[i]){
|
||||||
|
case CONFIG_OUT_VOLT_PIN:
|
||||||
|
calc_meas_formats[i] = &mv_char_pres_format;
|
||||||
|
calc_meas_char_uuid[i] = voltage_char_uuid;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
calc_meas_formats[i] = &mA_char_pres_format;
|
||||||
|
calc_meas_char_uuid[i] = current_char_uuid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*calc_meas_serve_handle = simple_gatt_value_server(calc_meas, sizeof(uint32_t), CONFIG_ADC_IN_PIN_NUM, calc_meas_formats, &gatt_svcs[CALC_VALUES_SVC_ID], CALC_VALUES_SVC_ID, calc_meas_char_uuid);
|
||||||
|
}
|
@ -1,10 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "BLE_UUID.h"
|
|
||||||
#include "host/ble_gatt.h"
|
#include "host/ble_gatt.h"
|
||||||
|
|
||||||
|
#include "simple_gatt_value_server.h"
|
||||||
|
|
||||||
enum {RAW_VALUES_SVC_ID, CALC_VALUES_SVC_ID, CONFIGURATION_SVC_ID, SVCS_NUM};
|
enum {RAW_VALUES_SVC_ID, CALC_VALUES_SVC_ID, CONFIGURATION_SVC_ID, SVCS_NUM};
|
||||||
|
|
||||||
enum {SWITCHING_FREQUENCY_CHR_ID, DUTY_CYCLE_CHR_ID, CONFIGURATION_SVC_CHR_NUM};
|
enum {SWITCHING_FREQUENCY_CHR_ID, DUTY_CYCLE_CHR_ID, CONFIGURATION_SVC_CHR_NUM};
|
||||||
|
|
||||||
extern struct ble_gatt_svc_def gatt_svcs[SVCS_NUM + 1];
|
extern struct ble_gatt_svc_def gatt_svcs[SVCS_NUM + 1];
|
||||||
|
|
||||||
|
void init_ble_app_services(uint32_t raw_mv_meas[], uint32_t calc_meas[], uint8_t adc_pins[], gatt_value_server_handle_t* raw_mv_serve_handle, gatt_value_server_handle_t* calc_meas_serve_handle);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user