diff --git a/components/BLEh b/components/BLEh index cb5fe57..544c26f 160000 --- a/components/BLEh +++ b/components/BLEh @@ -1 +1 @@ -Subproject commit cb5fe57c53034b9adcb4f89270373156b80153e5 +Subproject commit 544c26fdfda6d679f07192b2358de1cefc998859 diff --git a/main/Alim1000W.c b/main/Alim1000W.c index 321e1a0..d6b2f6c 100644 --- a/main/Alim1000W.c +++ b/main/Alim1000W.c @@ -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_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){ 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; } +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){ adc_continuous_handle_cfg_t adc_h_conf = { .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); + add_on_char_read_handler(on_char_read_handler); + set_gatt_services(gatt_svcs, SVCS_NUM); initBLE("ALIM"); diff --git a/main/BLE.c b/main/BLE.c index 9a98fe3..b7b850e 100644 --- a/main/BLE.c +++ b/main/BLE.c @@ -1,23 +1,37 @@ #include "BLE.h" #include "BLE_UUID.h" +#include "BLEh.h" +#include "host/ble_att.h" #include "host/ble_gatt.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){ - case BLE_GATT_ACCESS_OP_READ_CHR: - ; - break; - case BLE_GATT_ACCESS_OP_READ_DSC: - ; - break; - } +struct char_pres_format frequency_char_pres_format = { + .format = FORMAT_UINT32, + .unit = HERTZ_UNIT_UUID, + .exponent = 0, + .namespc = 1, + .descrH = NSP_DESC_MAIN & 0xff, + .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[] = { [RAW_VALUES_SVC_ID] = { @@ -32,17 +46,34 @@ struct ble_gatt_svc_def gatt_svcs[] = { .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = BLE_UUID16_DECLARE(CONFIGURATION_SERVICE), .characteristics = (struct ble_gatt_chr_def[]){ - [0] = { + [SWITCHING_FREQUENCY_CHR_ID] = { .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, .min_key_size = 0, .arg = NULL, .descriptors = (struct ble_gatt_dsc_def[]){ [0] = { .uuid = BLE_UUID16_DECLARE(CHAR_PRES_FORMAT), - .att_flags = BLE_GATT_CHR_F_READ, - .access_cb = gatt_char_access_placeholder, + .att_flags = BLE_ATT_F_READ, + .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 }, }, diff --git a/main/BLE.h b/main/BLE.h index 1ea79b8..6cf9891 100644 --- a/main/BLE.h +++ b/main/BLE.h @@ -1,6 +1,10 @@ #pragma once +#include "BLE_UUID.h" #include "host/ble_gatt.h" 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]; diff --git a/sdkconfig b/sdkconfig index b2abece..2e5708c 100644 --- a/sdkconfig +++ b/sdkconfig @@ -1669,7 +1669,7 @@ CONFIG_PHASE3_CON_PIN=8 # CONFIG_SW_FREQ=800000 CONFIG_SW_RES=6 -CONFIG_UPD_DELAY=100 +CONFIG_UPD_DELAY=1000 # end of Controller parameters # end of This project config # end of Component config diff --git a/sdkconfig.old b/sdkconfig.old index 66039ce..6916e95 100644 --- a/sdkconfig.old +++ b/sdkconfig.old @@ -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_ERROR 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_DEBUG=y -CONFIG_BT_NIMBLE_LOG_LEVEL=0 +CONFIG_BT_NIMBLE_LOG_LEVEL_INFO=y +# CONFIG_BT_NIMBLE_LOG_LEVEL_DEBUG is not set +CONFIG_BT_NIMBLE_LOG_LEVEL=1 CONFIG_BT_NIMBLE_MAX_CONNECTIONS=3 CONFIG_BT_NIMBLE_MAX_BONDS=3 CONFIG_BT_NIMBLE_MAX_CCCDS=8