configuration read handler
This commit is contained in:
parent
8f81be8e71
commit
8f74dda224
@ -1 +1 @@
|
|||||||
Subproject commit cb5fe57c53034b9adcb4f89270373156b80153e5
|
Subproject commit 544c26fdfda6d679f07192b2358de1cefc998859
|
@ -36,6 +36,9 @@ static uint8_t channel_index[ADC_IN_PIN_NUM];
|
|||||||
static uint32_t meas_res[ADC_IN_PIN_NUM];
|
static uint32_t meas_res[ADC_IN_PIN_NUM];
|
||||||
static uint32_t meas_nb[ADC_IN_PIN_NUM];
|
static uint32_t meas_nb[ADC_IN_PIN_NUM];
|
||||||
|
|
||||||
|
static uint32_t switching_frequency = CONFIG_SW_FREQ;
|
||||||
|
static uint32_t duty_cycle = 50000000;
|
||||||
|
|
||||||
static bool IRAM_ATTR on_conv_done(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data){
|
static bool IRAM_ATTR on_conv_done(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data){
|
||||||
adc_digi_output_data_t* res = (adc_digi_output_data_t*)edata->conv_frame_buffer;
|
adc_digi_output_data_t* res = (adc_digi_output_data_t*)edata->conv_frame_buffer;
|
||||||
|
|
||||||
@ -48,6 +51,24 @@ static bool IRAM_ATTR on_conv_done(adc_continuous_handle_t handle, const adc_con
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
case CONFIGURATION_SVC_ID:
|
||||||
|
switch (chr_ind){
|
||||||
|
case SWITCHING_FREQUENCY_CHR_ID:
|
||||||
|
*value = &switching_frequency;
|
||||||
|
*value_size = sizeof(switching_frequency);
|
||||||
|
break;
|
||||||
|
case DUTY_CYCLE_CHR_ID:
|
||||||
|
*value = &duty_cycle;
|
||||||
|
*value_size = sizeof(duty_cycle);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void app_main(void){
|
void app_main(void){
|
||||||
adc_continuous_handle_cfg_t adc_h_conf = {
|
adc_continuous_handle_cfg_t adc_h_conf = {
|
||||||
.conv_frame_size = SOC_ADC_DIGI_DATA_BYTES_PER_CONV,
|
.conv_frame_size = SOC_ADC_DIGI_DATA_BYTES_PER_CONV,
|
||||||
@ -153,6 +174,8 @@ void app_main(void){
|
|||||||
|
|
||||||
gatt_value_server_handle_t calc_meas_serve_handle = simple_gatt_value_server(calc_meas, sizeof(uint32_t), ADC_IN_PIN_NUM, calc_meas_formats, &gatt_svcs[CALC_VALUES_SVC_ID], CALC_VALUES_SVC_ID, calc_meas_char_uuid);
|
gatt_value_server_handle_t calc_meas_serve_handle = simple_gatt_value_server(calc_meas, sizeof(uint32_t), ADC_IN_PIN_NUM, calc_meas_formats, &gatt_svcs[CALC_VALUES_SVC_ID], CALC_VALUES_SVC_ID, calc_meas_char_uuid);
|
||||||
|
|
||||||
|
add_on_char_read_handler(on_char_read_handler);
|
||||||
|
|
||||||
set_gatt_services(gatt_svcs, SVCS_NUM);
|
set_gatt_services(gatt_svcs, SVCS_NUM);
|
||||||
|
|
||||||
initBLE("ALIM");
|
initBLE("ALIM");
|
||||||
|
63
main/BLE.c
63
main/BLE.c
@ -1,23 +1,37 @@
|
|||||||
#include "BLE.h"
|
#include "BLE.h"
|
||||||
#include "BLE_UUID.h"
|
#include "BLE_UUID.h"
|
||||||
|
|
||||||
|
#include "BLEh.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"
|
||||||
|
|
||||||
int gatt_char_access_placeholder(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg){
|
|
||||||
int rc = 0;
|
|
||||||
|
|
||||||
switch(ctxt->op){
|
struct char_pres_format frequency_char_pres_format = {
|
||||||
case BLE_GATT_ACCESS_OP_READ_CHR:
|
.format = FORMAT_UINT32,
|
||||||
;
|
.unit = HERTZ_UNIT_UUID,
|
||||||
break;
|
.exponent = 0,
|
||||||
case BLE_GATT_ACCESS_OP_READ_DSC:
|
.namespc = 1,
|
||||||
;
|
.descrH = NSP_DESC_MAIN & 0xff,
|
||||||
break;
|
.descrL = (NSP_DESC_MAIN>>8) & 0xff,
|
||||||
}
|
};
|
||||||
|
struct dsc_content switching_frequency_dsc = {
|
||||||
|
.data = &frequency_char_pres_format,
|
||||||
|
.data_size = CHAR_PRESENTATION_FORMAT_SIZE,
|
||||||
|
};
|
||||||
|
|
||||||
return rc ? BLE_ATT_ERR_INSUFFICIENT_RES : 0;
|
struct char_pres_format duty_cycle_char_pres_format = {
|
||||||
}
|
.format = FORMAT_UINT32,
|
||||||
|
.unit = UNITLESS_UNIT_UUID,
|
||||||
|
.exponent = -6,
|
||||||
|
.namespc = 1,
|
||||||
|
.descrH = NSP_DESC_MAIN & 0xff,
|
||||||
|
.descrL = (NSP_DESC_MAIN>>8) & 0xff,
|
||||||
|
};
|
||||||
|
struct dsc_content duty_cycle_dsc = {
|
||||||
|
.data = &duty_cycle_char_pres_format,
|
||||||
|
.data_size = CHAR_PRESENTATION_FORMAT_SIZE,
|
||||||
|
};
|
||||||
|
|
||||||
struct ble_gatt_svc_def gatt_svcs[] = {
|
struct ble_gatt_svc_def gatt_svcs[] = {
|
||||||
[RAW_VALUES_SVC_ID] = {
|
[RAW_VALUES_SVC_ID] = {
|
||||||
@ -32,17 +46,34 @@ struct ble_gatt_svc_def gatt_svcs[] = {
|
|||||||
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
||||||
.uuid = BLE_UUID16_DECLARE(CONFIGURATION_SERVICE),
|
.uuid = BLE_UUID16_DECLARE(CONFIGURATION_SERVICE),
|
||||||
.characteristics = (struct ble_gatt_chr_def[]){
|
.characteristics = (struct ble_gatt_chr_def[]){
|
||||||
[0] = {
|
[SWITCHING_FREQUENCY_CHR_ID] = {
|
||||||
.uuid = BLE_UUID16_DECLARE(SWITCHING_FREQUENCY_CHAR),
|
.uuid = BLE_UUID16_DECLARE(SWITCHING_FREQUENCY_CHAR),
|
||||||
.access_cb = gatt_char_access_placeholder,
|
.access_cb = NULL,
|
||||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
|
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
|
||||||
.min_key_size = 0,
|
.min_key_size = 0,
|
||||||
.arg = NULL,
|
.arg = NULL,
|
||||||
.descriptors = (struct ble_gatt_dsc_def[]){
|
.descriptors = (struct ble_gatt_dsc_def[]){
|
||||||
[0] = {
|
[0] = {
|
||||||
.uuid = BLE_UUID16_DECLARE(CHAR_PRES_FORMAT),
|
.uuid = BLE_UUID16_DECLARE(CHAR_PRES_FORMAT),
|
||||||
.att_flags = BLE_GATT_CHR_F_READ,
|
.att_flags = BLE_ATT_F_READ,
|
||||||
.access_cb = gatt_char_access_placeholder,
|
.access_cb = NULL,
|
||||||
|
.arg = &switching_frequency_dsc,
|
||||||
|
},
|
||||||
|
{ 0 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[DUTY_CYCLE_CHR_ID] = {
|
||||||
|
.uuid = BLE_UUID16_DECLARE(DUTY_CYCLE_FREQUENCY_CHAR),
|
||||||
|
.access_cb = NULL,
|
||||||
|
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
|
||||||
|
.min_key_size = 0,
|
||||||
|
.arg = NULL,
|
||||||
|
.descriptors = (struct ble_gatt_dsc_def[]){
|
||||||
|
[0] = {
|
||||||
|
.uuid = BLE_UUID16_DECLARE(CHAR_PRES_FORMAT),
|
||||||
|
.att_flags = BLE_ATT_F_READ,
|
||||||
|
.access_cb = NULL,
|
||||||
|
.arg = &duty_cycle_dsc,
|
||||||
},
|
},
|
||||||
{ 0 },
|
{ 0 },
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "BLE_UUID.h"
|
||||||
#include "host/ble_gatt.h"
|
#include "host/ble_gatt.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};
|
||||||
|
|
||||||
extern struct ble_gatt_svc_def gatt_svcs[SVCS_NUM + 1];
|
extern struct ble_gatt_svc_def gatt_svcs[SVCS_NUM + 1];
|
||||||
|
@ -1669,7 +1669,7 @@ CONFIG_PHASE3_CON_PIN=8
|
|||||||
#
|
#
|
||||||
CONFIG_SW_FREQ=800000
|
CONFIG_SW_FREQ=800000
|
||||||
CONFIG_SW_RES=6
|
CONFIG_SW_RES=6
|
||||||
CONFIG_UPD_DELAY=100
|
CONFIG_UPD_DELAY=1000
|
||||||
# end of Controller parameters
|
# end of Controller parameters
|
||||||
# end of This project config
|
# end of This project config
|
||||||
# end of Component config
|
# end of Component config
|
||||||
|
@ -408,9 +408,9 @@ CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL=y
|
|||||||
# CONFIG_BT_NIMBLE_LOG_LEVEL_NONE is not set
|
# CONFIG_BT_NIMBLE_LOG_LEVEL_NONE is not set
|
||||||
# CONFIG_BT_NIMBLE_LOG_LEVEL_ERROR is not set
|
# CONFIG_BT_NIMBLE_LOG_LEVEL_ERROR is not set
|
||||||
# CONFIG_BT_NIMBLE_LOG_LEVEL_WARNING is not set
|
# CONFIG_BT_NIMBLE_LOG_LEVEL_WARNING is not set
|
||||||
# CONFIG_BT_NIMBLE_LOG_LEVEL_INFO is not set
|
CONFIG_BT_NIMBLE_LOG_LEVEL_INFO=y
|
||||||
CONFIG_BT_NIMBLE_LOG_LEVEL_DEBUG=y
|
# CONFIG_BT_NIMBLE_LOG_LEVEL_DEBUG is not set
|
||||||
CONFIG_BT_NIMBLE_LOG_LEVEL=0
|
CONFIG_BT_NIMBLE_LOG_LEVEL=1
|
||||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=3
|
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=3
|
||||||
CONFIG_BT_NIMBLE_MAX_BONDS=3
|
CONFIG_BT_NIMBLE_MAX_BONDS=3
|
||||||
CONFIG_BT_NIMBLE_MAX_CCCDS=8
|
CONFIG_BT_NIMBLE_MAX_CCCDS=8
|
||||||
|
Loading…
x
Reference in New Issue
Block a user