From c53933c3c61141011284014e3cb4c4a1b7d6111a Mon Sep 17 00:00:00 2001 From: ZhuRui <1602972632@qq.com> Date: Wed, 17 Jan 2024 10:09:31 +0800 Subject: [PATCH 1/2] depth.c --- main/stm32/config.h | 2 +- main/stm32/depth.c | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/main/stm32/config.h b/main/stm32/config.h index ec24afe..a441ce4 100644 --- a/main/stm32/config.h +++ b/main/stm32/config.h @@ -27,7 +27,7 @@ #define DEPTH_RESET_ADDR 510 #define REBOOT_REW_ADDR 511 - +#define TIME 264 typedef struct { uint16_t magic; diff --git a/main/stm32/depth.c b/main/stm32/depth.c index c493e95..e1ce748 100644 --- a/main/stm32/depth.c +++ b/main/stm32/depth.c @@ -28,7 +28,7 @@ #include #include - +#include "esp_timer.h" static const char *TAG = "depth"; @@ -118,6 +118,7 @@ typedef struct{ uint8_t TAG; int16_t flow[2]; uint32_t total_flow[2]; + uint16_t time; }send_to_bt_t2; #pragma pack() @@ -128,8 +129,9 @@ typedef struct int16_t depth; // 14 uint16_t sample_count; // 15 uint16_t depth_flow[2]; // 16~17 - uint32_t last_total_flow[2]; // 18~21 + uint32_t last_total_flow[2]; // int16_t depth_offset; // 22 + uint16_t one_pile_work_time;//23 系统工作时间 // uint32_t update_time; // int16_t tilt_x; // int16_t tilt_y; @@ -336,6 +338,11 @@ void send_data_to_bt(void){ send_to_bt2.flow[1] = pflow[1].flow; send_to_bt2.total_flow[0] = pflow[0].total_flow; send_to_bt2.total_flow[1] = pflow[1].total_flow; + + /*计算开启后持续时间,并传给EC600U*/ + uint16_t time = 0; + gWordVar[TIME] = time; + send_to_bt2.time = time; #endif ESP_LOGI(TAG, "flow 1 :%d\n",send_to_bt2.flow[0]); ESP_LOGI(TAG, "flow 2 :%d\n",send_to_bt2.flow[1]); @@ -371,7 +378,7 @@ void depth_task(void *arg) int time_diff = 0; int speed_timeout = 0; int last_speed_enc_value = 0; // 上次速度计算的编码器值 - int speed_enc_update_time = 0; // 上次速度计算的编码器值 + int speed_enc_update_time = 0; int speed_calc_count = 0; int enc_value = 0; //int count = 0; @@ -383,9 +390,14 @@ void depth_task(void *arg) //send_to_bt1.pile_id = ++last_pile_id; gWordVar[LAST_PILE_ID_ADDR] = last_pile_id; + + /*获取当前时间*/ + uint16_t last_work_time = 0; + uint16_t current_work_time = 0; + uint8_t is_work = 0; + while (1) - { - + { if (_enc1_update_time != enc1_update_time) { ESP_LOGI(TAG, "_enc1_update_time != enc1_update_time\n"); @@ -445,8 +457,26 @@ void depth_task(void *arg) } } } + if (depth_data->up_down > STOP) { + is_work ++; + if(is_work == 1){ + depth_data->one_pile_work_time = 0; + last_work_time = (uint16_t)(esp_timer_get_time()/1000000); + } + if(is_work > 1){ + current_work_time = (uint16_t)(esp_timer_get_time()/1000000); + depth_data->one_pile_work_time = current_work_time - last_work_time; + if(depth_data->one_pile_work_time < 0){ + depth_data->one_pile_work_time = 0; + } + last_work_time = current_work_time; + } + + depth_data->one_pile_work_time = current_work_time - last_work_time; + + last_work_time = current_work_time; ESP_LOGI(TAG, "depth_data->up_down > STOP\n"); if (enc_value > last_enc_value) { // 下钻,深度增加 @@ -545,6 +575,10 @@ void depth_task(void *arg) } } } + else{ + is_work = 0; + depth_data->one_pile_work_time = 0; + } prev_depth = depth_data->depth; prev_update_time = enc_update_time; last_enc_value = enc_value; From 919ba55fe16c9c2d0303e9833d43ed8741a98c80 Mon Sep 17 00:00:00 2001 From: ZhuRui <1602972632@qq.com> Date: Sat, 20 Jan 2024 17:44:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=97=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vs/VSWorkspaceState.json | 6 - .vs/pile_cm_esp32/v15/.suo | Bin 12288 -> 0 bytes .vs/slnx.sqlite | Bin 77824 -> 0 bytes .vscode/settings.json | 6 - .../motor_ctrl_timer/motor_ctrl_timer.c | 1 + .../motor_ctrl_timer/motor_ctrl_timer.h | 1 - main/bt_server.c | 2 +- main/can_network.c | 2 +- main/main.c | 46 +-- main/stm32/ModbusS.c | 25 +- main/stm32/ads1220.c | 5 +- main/stm32/capture.c | 4 +- main/stm32/comm.c | 1 - main/stm32/config.c | 1 + main/stm32/config.h | 4 +- main/stm32/depth.c | 337 ++++++++++++++++-- main/stm32/flow.c | 2 +- main/stm32/uart0_modbus_slave.c | 42 ++- main/uart_example.c | 2 +- main/wifi_softap.c | 11 +- sdkconfig | 14 +- sdkconfig.old | 22 +- 22 files changed, 415 insertions(+), 119 deletions(-) delete mode 100644 .vs/VSWorkspaceState.json delete mode 100644 .vs/pile_cm_esp32/v15/.suo delete mode 100644 .vs/slnx.sqlite delete mode 100644 .vscode/settings.json diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json deleted file mode 100644 index 6b61141..0000000 --- a/.vs/VSWorkspaceState.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "ExpandedNodes": [ - "" - ], - "PreviewInSolutionExplorer": false -} \ No newline at end of file diff --git a/.vs/pile_cm_esp32/v15/.suo b/.vs/pile_cm_esp32/v15/.suo deleted file mode 100644 index c326bd09a2099709728ac7cfe9356259d9eb1a73..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeHNTW=dh6h3yjm1|2OKwH3sP|784ZcVBpDrg)85>~1vPI-ugQeRRxc5Hc_q(MAX zz$^R!#0x)xR~{c{fBtc6*(q*`^V)Gt2}1q<%Gz?cxKt&{{B8+F^}vp9ibVxE*1Rhl8^=2#JwiF zWM$wq0x2-Vr9AkhYw_<&_wM}`dz_V?)-|sIu_CwS6QCE6TaY_`O|-llk@x{V`_WRN zO~D+>AigRYeBxH6gdWr+4_d-ptby`wy-v3=iO0I? z+@A$K=RTV@hWEjpfnMtWiNd!-{fBN0lKvaXq&=V=FuHGa`Z&s|*X{J5Hq_KN?eP96 z%I)W2esE`i{4>OLgn7yWc}N)`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qCT|C2Sa0UVvsdFh#t(g3+i^hQLIbt(ZDe~ zn}r&$^X+m~)gF|bhauwq)AR~G!-OAuc!Eh;LCmeL3eS(6K0O7zk4uq0_L+9U6RlVB=1g-}?~aJA1;LIzF_GCo{(s`P4HSR? z2!H?xfB*=900@8p2!H?xfWXWVpwIsc^M6WYKU)4v`fp257r!PKc!2;2fB*>mSO|Q+ z@|O6s&CSI>J~=UskLjrZdRoRw!kNa9zxIBC-qqA65??3j!%XUlR)0v2`zVcSP1{u` zW%4!e_!T{9R3pcml)A(x2DFZpuSxgyp?BiT%?N6p4QX1+fyygx(!v!9n$Uzxq}qNe zZCA@X6L$@g!z3YEE(MpamccdEymB)}y{O1`?dJK_o#?_*|I<&U8^5_Bk&ntvf0$$( z;ZfU9gSPJYxT&Pll|V)-mB{h7Uy}oE6C|kQc8#1r3#7?lVrJ=sus$?n#IVz!|5I#s zYd3$f!RbBp4I`6!nX+e5lBhaOx5+so2Ktbk!;3c-Nvk=T^zr(NnA?+uu^t@ZaB_$R z-PU7{UpTq-01uVA63sD1E2nkg=bfVBH2oBmFvQJ`eJ4#V|Nc1Zq|v`z)HxhBBN} zPidb25WxjFWfVCpjI+7X!;tQg8Gk9@ q52F76oXy4m|L@1L#fKgs00JNY0w4eaAOHd&00JNY0wD1E2>b`on{O2W diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index cf19cad..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "idf.adapterTargetName": "esp32s3", - "files.associations": { - "can_network.h": "c" - } -} \ No newline at end of file diff --git a/components/motor_ctrl_timer/motor_ctrl_timer.c b/components/motor_ctrl_timer/motor_ctrl_timer.c index 1a76ad2..4c3e943 100644 --- a/components/motor_ctrl_timer/motor_ctrl_timer.c +++ b/components/motor_ctrl_timer/motor_ctrl_timer.c @@ -12,6 +12,7 @@ #include "esp_check.h" #define MOTOR_CTRL_TIMER_DIVIDER (16) // Hardware timer clock divider +#define TIMER_BASE_CLK (160) #define MOTOR_CTRL_TIMER_SCALE (TIMER_BASE_CLK / MOTOR_CTRL_TIMER_DIVIDER) // convert counter value to seconds #define MOTOR_CONTROL_TIMER_GROUP TIMER_GROUP_0 diff --git a/components/motor_ctrl_timer/motor_ctrl_timer.h b/components/motor_ctrl_timer/motor_ctrl_timer.h index ca9646f..222cad0 100644 --- a/components/motor_ctrl_timer/motor_ctrl_timer.h +++ b/components/motor_ctrl_timer/motor_ctrl_timer.h @@ -16,7 +16,6 @@ extern "C" { #include "freertos/FreeRTOS.h" #include "freertos/queue.h" #include "driver/timer.h" - typedef struct { int (*get_pulse_callback)(void *); void *callback_args; diff --git a/main/bt_server.c b/main/bt_server.c index 639ef49..25155a9 100644 --- a/main/bt_server.c +++ b/main/bt_server.c @@ -6,7 +6,6 @@ CONDITIONS OF ANY KIND, either express or implied. */ - #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/event_groups.h" @@ -22,6 +21,7 @@ #include "esp_bt_defs.h" #include "esp_bt_main.h" #include "bt_server.h" + #define SPP_DEBUG_MODE 1 #define GATTS_TABLE_TAG "GATTS_SPP_DEMO" diff --git a/main/can_network.c b/main/can_network.c index 93f4358..d0e9b89 100644 --- a/main/can_network.c +++ b/main/can_network.c @@ -101,7 +101,7 @@ static void twai_receive_task(void *arg) { index += sprintf(&msg_data_str[i], "%02x ", rx_msg.data[i]); } - ESP_LOGI(TAG, "recive msg id=%x,len=%d,data=[%s]", rx_msg.identifier, rx_msg.data_length_code, msg_data_str); + ESP_LOGI(TAG, "recive msg id= %u,len=%d,data=[%s]", rx_msg.identifier, rx_msg.data_length_code, msg_data_str); } } } diff --git a/main/main.c b/main/main.c index df114a2..95b094c 100644 --- a/main/main.c +++ b/main/main.c @@ -27,12 +27,12 @@ #include "driver/mcpwm.h" /*蓝牙相关的头文件*/ -#include "esp_bt.h" +#include "../../../components/bt/include/esp32/include/esp_bt.h" #include "driver/uart.h" -#include "esp_gap_ble_api.h" -#include "esp_gatts_api.h" -#include "esp_bt_defs.h" -#include "esp_bt_main.h" +#include "../../../components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h" +#include "../../../components/bt/host/bluedroid/api/include/api/esp_gatts_api.h" +#include "../../../components/bt/host/bluedroid/api/include/api/esp_bt_defs.h" +#include "../../../components/bt/host/bluedroid/api/include/api/esp_bt_main.h" /* The examples use WiFi configuration that you can set via project configuration menu @@ -70,6 +70,8 @@ #define WIFI_CONNECTED_BIT BIT0 #define WIFI_FAIL_BIT BIT1 #define GPIO_4G_PWR GPIO_NUM_4 +#define PWR_4G_ON (0) +#define PWR_4G_OFF (1) static const char *TAG = "main"; @@ -77,7 +79,6 @@ static const char *TAG = "main"; extern void wifi_init_softap(void); -void ads1220_init(void); void PWR_4G_Init(void); extern void can_init(void); extern void FLOW_init(); @@ -103,10 +104,10 @@ void app_main(void) } ESP_ERROR_CHECK(ret); ESP_ERROR_CHECK(i2c_master_init()); - config_load(); + config_load();//读取保存在FRAM里的数据 ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); rtc_clk_apb_freq = rtc_clk_apb_freq_get(); - ESP_LOGI(TAG, "rtc_clk_apb_freq=%d", rtc_clk_apb_freq); + ESP_LOGI(TAG, "rtc_clk_apb_freq=%u", rtc_clk_apb_freq); wifi_init_softap();//ok // wifi_init_sta(); @@ -130,19 +131,22 @@ void app_main(void) void PWR_4G_Init(void) { // zero-initialize the config structure. - gpio_config_t io_conf = {}; - // disable interrupt - io_conf.intr_type = GPIO_INTR_DISABLE; - // set as output mode - io_conf.mode = GPIO_MODE_OUTPUT; - // bit mask of the pins that you want to set,e.g.GPIO18/19 - io_conf.pin_bit_mask = GPIO_4G_PWR; - // disable pull-down mode - io_conf.pull_down_en = 0; - // disable pull-up mode - io_conf.pull_up_en = 0; + gpio_config_t io_conf = { + // disable interrupt + .intr_type = GPIO_INTR_DISABLE, + // set as output mode + .mode = GPIO_MODE_OUTPUT, + // bit mask of the pins that you want to set,e.g.GPIO18/19 + .pin_bit_mask = GPIO_4G_PWR, + // disable pull-down mode + .pull_down_en = 0, + // disable pull-up mode + .pull_up_en = 0, + }; + // configure GPIO with the given settings gpio_config(&io_conf); - - gpio_set_level(GPIO_4G_PWR, 0); + gpio_set_level(GPIO_4G_PWR, PWR_4G_OFF); + vTaskDelay(pdMS_TO_TICKS(1000)); + gpio_set_level(GPIO_4G_PWR, PWR_4G_ON); } \ No newline at end of file diff --git a/main/stm32/ModbusS.c b/main/stm32/ModbusS.c index d4fb4ab..31f2016 100644 --- a/main/stm32/ModbusS.c +++ b/main/stm32/ModbusS.c @@ -131,10 +131,10 @@ void ModBusWordWriteHook(uint16_t addr, uint16_t length) save_flow_cfg(); } else if(addr == DEPTH_CONFIG_ADDR && gWordVar[DEPTH_CONFIG_ADDR] == 0x55aa){ - save_depth_cfg(); + save_depth_cfg(); } else if(addr == CAL_4_20MA_ADDR && gWordVar[CAL_4_20MA_ADDR] == 0x55aa){ - save_cal_4_20ma(); + save_cal_4_20ma(); } else if(addr == REBOOT_REW_ADDR ){ if(gWordVar[REBOOT_REW_ADDR] == 0x55aa){ @@ -166,21 +166,24 @@ int ModbusSlaveProcess(uint8_t *txbuf, uint8_t *rxbuf, uint16_t rxLen, int is_cr int i; uint8_t *pDat; uint16_t *pWordVar; - if(rxLen<4) + + if(rxLen<4){ return 0; - if((rxbuf[0]==modbus_addr) || (rxbuf[0]==255)) - { - if(is_crc != 0) - { + } + + /*地址校验*/ + if((rxbuf[0]==modbus_addr) || (rxbuf[0]==255)){ + + /*crc校验*/ + if(is_crc != 0){ crcData = rxbuf[rxLen-1]+(rxbuf[rxLen-2]<<8); crcChk = crc16(rxbuf,rxLen-2); - if( crcData != crcChk) - { + if( crcData != crcChk){ return 0; } } + add = ((uint16_t)rxbuf[2]<<8)+ rxbuf[3]; - //if(Length != length = (rxbuf[4]<<8) | rxbuf[5]; txbuf[0] = rxbuf[0]; @@ -275,7 +278,7 @@ int ModbusSlaveProcess(uint8_t *txbuf, uint8_t *rxbuf, uint16_t rxLen, int is_cr out_len = 3; break; } - gWordVar[add] = (rxbuf[4]<<8)+rxbuf[5]; + gWordVar[add] = (rxbuf[4]<<8)+rxbuf[5]; memcpy(txbuf,rxbuf,6); ModBusWordWriteHook(add,1); out_len = 6; diff --git a/main/stm32/ads1220.c b/main/stm32/ads1220.c index a0f590b..36f3da9 100644 --- a/main/stm32/ads1220.c +++ b/main/stm32/ads1220.c @@ -95,7 +95,7 @@ int ads1220_watchdog = 0; extern xQueueHandle gpio_evt_queue; xQueueHandle gpio_evt_queue = NULL; -uint16_t gWordVar[gWORD_SIZE]; +extern uint16_t gWordVar[gWORD_SIZE]; int ad_value[4]; uint32_t ad_update_time[4]; uint8_t ad_watchdog_cnt = 0; @@ -387,10 +387,11 @@ extern flow_config_t *flow_config; extern flow_t *pflow; extern uint8_t timeout[2]; extern int flow_rem[2]; + void ads1220_task(void) { uint32_t io_num; - static uint32_t ad_flow_tick = 10; + // static uint32_t ad_flow_tick = 10; while (1) { // ESP_LOGI(TAG, "xQueueReceive before\n "); diff --git a/main/stm32/capture.c b/main/stm32/capture.c index 5f23411..1fdf044 100644 --- a/main/stm32/capture.c +++ b/main/stm32/capture.c @@ -9,7 +9,9 @@ #include "esp_check.h" #include "soc/rtc.h" #include "driver/mcpwm.h" - +#include "../../../components/hal/include/hal/gpio_types.h" +// #include "../../../components/driver/gpio/include/driver/gpio.h" +#include "driver/gpio.h" const static char *TAG = "capture"; typedef struct capture_event diff --git a/main/stm32/comm.c b/main/stm32/comm.c index e24e70c..a2d0f71 100644 --- a/main/stm32/comm.c +++ b/main/stm32/comm.c @@ -6,7 +6,6 @@ // #include "SEGGER_RTT.h" #include "ModbusM.h" -uint32_t TickDiff(uint32_t comptime); extern void modbus_master_poll(int n); extern int modbus_master_on_revice(int ch, uint8_t *rxbuf, int length); diff --git a/main/stm32/config.c b/main/stm32/config.c index fe9f66b..40fd1c2 100644 --- a/main/stm32/config.c +++ b/main/stm32/config.c @@ -136,6 +136,7 @@ void config_load(void) } } +//恢复默认配置 void restore_default(void) { memcpy(cal_4_20ma, &default_cal_4_20ma, sizeof(default_cal_4_20ma)); diff --git a/main/stm32/config.h b/main/stm32/config.h index a441ce4..e1dad48 100644 --- a/main/stm32/config.h +++ b/main/stm32/config.h @@ -19,8 +19,8 @@ #define RECORD_REG_ADDR 32 #define CAL_4_20MA_ADDR 384 -#define FLOW_CONFIG_ADDR (CAL_4_20MA_ADDR + (sizeof(cal_4_20ma_t) + 15) / 16 * 8) -#define DEPTH_CONFIG_ADDR (FLOW_CONFIG_ADDR + (sizeof(flow_config_t) + 15) / 16 * 8) +#define FLOW_CONFIG_ADDR (CAL_4_20MA_ADDR + (sizeof(cal_4_20ma_t) + 15) / 16 * 8) +#define DEPTH_CONFIG_ADDR (FLOW_CONFIG_ADDR + (sizeof(flow_config_t) + 15) / 16 * 8) #define AD_RAW_REG_ADDR 444 #define LAST_PILE_ID_ADDR 509 diff --git a/main/stm32/depth.c b/main/stm32/depth.c index e1ce748..e991ba9 100644 --- a/main/stm32/depth.c +++ b/main/stm32/depth.c @@ -12,13 +12,13 @@ #include "ModbusS.h" #include "rotary_encoder.h" - #include "esp_log.h" #include "esp_check.h" #include "soc/rtc.h" #include "driver/mcpwm.h" +// #include "driver/mcpwm_prelude.h" #include "config.h" -#include "esp_gatts_api.h" +#include "../../../../components/bt/host/bluedroid/api/include/api/esp_gatts_api.h" #include "bt_server.h" #include "esp_system.h" @@ -58,6 +58,14 @@ typedef struct capture_event #define DEPTH_PIN_ENC_B 41 // 深度控制GPIO端口 TIM3_CH2 #define SEND_DATA_TEST 0 +#define PILE_STATE_STOP 0x0100 +#define PILE_STATE_PAUSE 0x0200 +#define PILE_STATE_WORK 0x0300 + +#define PILE_DIR_NONE 0x01 +#define PILE_DIR_UP 0x02 +#define PILE_DIR_DOWN 0x03 + // #define DEPTH_PIN_ENC_A 36 // 深度脉冲GPIO端口 // #define DEPTH_PIN_ENC_B 35 // 深度控制GPIO端口 @@ -124,7 +132,7 @@ typedef struct{ typedef struct { - int16_t up_down; // 12 + uint16_t pile_work_state_and_direction; // 12 int16_t speed; // 13 int16_t depth; // 14 uint16_t sample_count; // 15 @@ -188,7 +196,8 @@ void capture_depth_init() .cap_edge = MCPWM_NEG_EDGE, .cap_prescale = 1, .capture_cb = depth_isr_handler, // 绑定深度中断处理函数 - .user_data = NULL}; + .user_data = NULL + }; if (depth_config->input_type > 1) { conf.cap_edge = MCPWM_BOTH_EDGE; @@ -254,7 +263,7 @@ void depth_init(void) // // HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); // } depth_data->depth_offset = -depth_config->depth_offset; - depth_data->up_down = 1; // 默认工作 + depth_data->pile_work_state_and_direction = (PILE_STATE_STOP | PILE_DIR_NONE); // 默认不工作 } enum @@ -318,7 +327,7 @@ void send_data_to_bt(void){ ESP_LOGI(TAG, "use real time data that send to bt\n"); send_to_bt1.TAG = 1; send_to_bt1.tilt_x = (short)gWordVar[TILT_SENSER_ADDR]; - send_to_bt1.tilt_y = (short)gWordVar[TILT_SENSER_ADDR + 1]; + send_to_bt1.tilt_y = (short)gWordVar[TILT_SENSER_ADDR + 1]; send_to_bt1.speed = depth_data->speed; send_to_bt1.depth = depth_data->depth; if (depth_config->move_current_channel == 2){ @@ -344,10 +353,10 @@ void send_data_to_bt(void){ gWordVar[TIME] = time; send_to_bt2.time = time; #endif - ESP_LOGI(TAG, "flow 1 :%d\n",send_to_bt2.flow[0]); - ESP_LOGI(TAG, "flow 2 :%d\n",send_to_bt2.flow[1]); - ESP_LOGI(TAG, "total_flow 1 :%d\n",send_to_bt2.total_flow[0]); - ESP_LOGI(TAG, "total_flow 2 :%d\n",send_to_bt2.total_flow[1]); + // ESP_LOGI(TAG, "flow 1 :%d\n",send_to_bt2.flow[0]); + // ESP_LOGI(TAG, "flow 2 :%d\n",send_to_bt2.flow[1]); + // ESP_LOGI(TAG, "total_flow 1 :%u\n",send_to_bt2.total_flow[0]); + // ESP_LOGI(TAG, "total_flow 2 :%u\n",send_to_bt2.total_flow[1]); if(is_connected == true){ ESP_LOGI(TAG, "is connected\n"); esp_err_t err = esp_ble_gatts_send_indicate(spp_gatts_if, @@ -371,6 +380,257 @@ void send_data_to_bt(void){ } +/** + * _enc1_update_time 编码器1上一次更新时间 + * enc1_update_time 编码器1当前更新时间 + * time_diff 两次编码器更新时间的绝对差值 + * depth_config 预设好的深度数据 + * enc1_value 编码器1值,在深度中断中获得 + * prev_depth 上一次的深度 +*/ +void depth_task(void *arg) +{ + ESP_LOGI(TAG, "depth_task start\n"); + + int time_diff = 0; + int speed_timeout = 0; + int last_speed_enc_value = 0; // 上次速度计算的编码器值 + int speed_enc_update_time = 0; + int speed_calc_count = 0; + int enc_value = 0; + int bt_time_count = 0; + int64_t work_start_time = 0; + uint16_t last_work_state = 0; + + depth_data->depth_offset = -depth_config->depth_offset; + depth_data->pile_work_state_and_direction = 0x0300; + last_work_state = depth_data->pile_work_state_and_direction; + record->pile_id = ++last_pile_id; + + gWordVar[LAST_PILE_ID_ADDR] = last_pile_id; + + while(1) + { + ESP_LOGI(TAG, "pile_work_state_and_direction = 0x%04x\n",gWordVar[12]); + + if (_enc1_update_time != enc1_update_time) + { + ESP_LOGI(TAG, "_enc1_update_time != enc1_update_time\n"); + enc_update_time = enc1_update_time; + enc_value = enc1_value; + time_diff = abs_sub(enc_update_time, _enc1_update_time); + _enc1_update_time = enc_update_time; + } + + if (time_diff != 0) + { + ESP_LOGI(TAG, "time_diff = %d\n",time_diff); + int16_t depth = enc_value * depth_config->N / depth_config->M; // 1mm + depth_data->depth = depth - depth_data->depth_offset; + + /*深度补偿修正*/ + if (depth_data->depth > depth_config->max_depth) + { + ESP_LOGI(TAG, "depth_data->depth > depth_config->max_depth\n"); + depth_data->depth_offset = depth - depth_config->max_depth; + depth_data->depth = depth_config->max_depth; + } + else if (depth_data->depth < depth_config->min_depth) + { + ESP_LOGI(TAG, "depth_data->depth < depth_config->min_depth\n"); + depth_data->depth_offset = depth - depth_config->min_depth; + depth_data->depth = depth_config->min_depth; + } + + /*更新记录值*/ + if (depth_data->depth > record->max_depth) + { + ESP_LOGI(TAG, "depth_data->depth > record->max_depth\n"); + record->max_depth = depth_data->depth; + //send_to_bt1.max_depth = depth_data->depth; + } + + // 500ms计算一次速度 + if (speed_calc_count++ > 50) + { + ESP_LOGI(TAG, "speed_calc_count++ > 50\n"); + speed_calc_count = 0; + int speed_time_diff = abs_sub(enc_update_time, speed_enc_update_time); + int time_diff_us = speed_time_diff / (APB_CLK_FREQ / 1000000); + if (time_diff_us > 0 && time_diff_us < 5000000) + { + ESP_LOGI(TAG, "time_diff_us:%d,dist_diff=%d", time_diff_us, enc_value - last_speed_enc_value); + // speed = dist_diff / speed_time_diff speed 单位mm/min dist_diff 单位mm speed_time_diff 单位us + depth_data->speed = (enc_value - last_speed_enc_value) * depth_config->N / depth_config->M * 600000ll / time_diff_us; + speed_timeout = 0; + speed_enc_update_time = enc_update_time; + last_speed_enc_value = enc_value; + } + else + { + if (++speed_timeout > 10) + { + depth_data->speed = 0; + speed_timeout = 0; + speed_enc_update_time = enc_update_time; + last_speed_enc_value = enc_value; + } + } + } + + uint16_t pile_work_state = (depth_data->pile_work_state_and_direction & 0xff00); + if (pile_work_state == PILE_STATE_WORK) + { + ESP_LOGI(TAG, "pile_work_state == PILE_STATE_WORK\n"); + /*如果机器从停止状态->工作状态,则重新记录工作开始时间*/ + if(last_work_state == PILE_STATE_STOP){ + work_start_time = esp_timer_get_time(); + depth_data->one_pile_work_time = 0; + } + int64_t current_work_time = esp_timer_get_time(); + if(work_start_time != 0){ + depth_data->one_pile_work_time = (uint16_t)((current_work_time - work_start_time)/1000000); + } + + /*下钻,深度增加*/ + if (enc_value > last_enc_value) + { + ESP_LOGI(TAG, "enc_value > last_enc_value\n"); + uint8_t pile_work_dir = (depth_data->pile_work_state_and_direction & 0xff); + if(pile_work_dir != PILE_DIR_DOWN) + { + // 方向改变,更新目标采样深度 + depth_data->pile_work_state_and_direction = ((depth_data->pile_work_state_and_direction & 0xff00) | PILE_DIR_DOWN); + target_sample_depth = (depth_data->depth / depth_config->sample_depth) * depth_config->sample_depth; + + // 小于半个采样长度的合并到下一个采样点 + if (abs(depth_data->depth - target_sample_depth) < depth_config->sample_depth / 2) + { + target_sample_depth += depth_config->sample_depth; + } + } + + // 到达或超过目标采样点 + if (depth_data->depth >= target_sample_depth) + { + // 由于编码器精度问题不能确保数据在采样点上,需要通过插值计算采样点 + // 当使用10线编码器时每个脉冲深度达6.25cm,当采样间隔为10cm时抖动值太大 + if ((prev_depth - depth_data->depth) != 0) + { + int i; + //uint32_t time = (target_sample_depth - prev_depth) * (enc_update_time - prev_update_time) / (depth_data->depth - prev_depth) + prev_update_time; + for (i = 0; i < 2; i++) + { + // int total_flow = get_total_flow_by_time(i, time); + int total_flow = get_total_flow_by_time(i, pflow[i].update_time); + int flow = total_flow - depth_data->last_total_flow[i]; + if (flow < 0) + { + flow = 0; + } + depth_data->depth_flow[i] = flow; + depth_data->last_total_flow[i] = total_flow; + } + depth_data->sample_count++; + target_sample_depth += depth_config->sample_depth; + add_recod_item(); + } + } + } + /*上钻,深度减少*/ + else if (enc_value < last_enc_value) + { + ESP_LOGI(TAG, "enc_value < last_enc_value\n"); + uint8_t pile_work_dir = (depth_data->pile_work_state_and_direction & 0xff); + if (pile_work_dir != PILE_DIR_UP) + { + // 方向改变 + depth_data->pile_work_state_and_direction = ((depth_data->pile_work_state_and_direction & 0xff00) | PILE_DIR_UP); + target_sample_depth = (depth_data->depth / depth_config->sample_depth - 1) * depth_config->sample_depth; + + if (abs(depth_data->depth - target_sample_depth) < depth_config->sample_depth / 2) + { + // 小于半个采样长度的合并到下一个采样点 + target_sample_depth -= depth_config->sample_depth; + } + } + if (depth_data->depth <= target_sample_depth) + { + // 由于编码器精度问题不能确保数据在采样点上,需要通过插值计算采样点 + // 当使用10线编码器时每个脉冲深度达7.6cm,当采样间隔为10cm时抖动值太大 + if ((prev_depth - depth_data->depth) != 0) + { + int i; + //uint32_t time = (prev_depth - target_sample_depth) * (enc_update_time - prev_update_time) / (prev_depth - depth_data->depth) + prev_update_time; + for (i = 0; i < 2; i++) + { + // int total_flow = get_total_flow_by_time(i, time); + int total_flow = get_total_flow_by_time(i, pflow[i].update_time); + int flow = total_flow - depth_data->last_total_flow[i]; + if (flow < 0) + { + flow = 0; + } + depth_data->depth_flow[i] = flow; + depth_data->last_total_flow[i] = total_flow; + } + depth_data->sample_count++; + add_recod_item(); + target_sample_depth -= depth_config->sample_depth; + + } + } + } + else + { + depth_data->pile_work_state_and_direction = ((depth_data->pile_work_state_and_direction & 0xff00) | PILE_DIR_NONE); + } + + if (depth_data->depth < depth_config->inc_pile_depth) // 小于指定深度时才允许行走清零 + { + if (pMoveCtx->pile_inc_req == 1) + { + pMoveCtx->pile_inc_req = 0; + reset_depth(); + } + } + else + { + if (pMoveCtx->pile_inc_req == 1) + { + pMoveCtx->pile_inc_req = 0; + } + } + } + else if((depth_data->pile_work_state_and_direction & 0xff00) == PILE_STATE_PAUSE) + { + + } + else if((depth_data->pile_work_state_and_direction & 0xff00) == PILE_STATE_STOP) + { + work_start_time = 0; + } + last_work_state = pile_work_state; + prev_depth = depth_data->depth; + prev_update_time = enc_update_time; + last_enc_value = enc_value; + } + else{ + ESP_LOGI(TAG, "time diff = 0\n"); + vTaskDelay(100); + } + + //每隔500ms向蓝牙发送一次数据 + // if(bt_time_count++ > 50){ + // ESP_LOGI(TAG, "bt_time_count++ > 50\n"); + // bt_time_count = 0; + // send_data_to_bt(); + // } + vTaskDelay(10); + } +} + +#if 0 void depth_task(void *arg) { ESP_LOGI(TAG, "go to depth_task sucessfully\n"); @@ -392,8 +652,7 @@ void depth_task(void *arg) gWordVar[LAST_PILE_ID_ADDR] = last_pile_id; /*获取当前时间*/ - uint16_t last_work_time = 0; - uint16_t current_work_time = 0; + uint16_t work_start_time = 0; uint8_t is_work = 0; while (1) @@ -410,9 +669,11 @@ void depth_task(void *arg) if (time_diff != 0) { - ESP_LOGI(TAG, "time_diff != 0\n"); + ESP_LOGI(TAG, "time_diff = %d\n",time_diff); int16_t depth = enc_value * depth_config->N / depth_config->M; // 1mm - depth_data->depth = depth - depth_data->depth_offset; + depth_data->depth = depth - depth_data->depth_offset;//为什么要减去深度偏移 + + /*深度补偿修正*/ if (depth_data->depth > depth_config->max_depth) { ESP_LOGI(TAG, "depth_data->depth > depth_config->max_depth\n"); @@ -425,13 +686,16 @@ void depth_task(void *arg) depth_data->depth_offset = depth - depth_config->min_depth; depth_data->depth = depth_config->min_depth; } + /*更新记录值*/ if (depth_data->depth > record->max_depth) { ESP_LOGI(TAG, "depth_data->depth > record->max_depth\n"); record->max_depth = depth_data->depth; //send_to_bt1.max_depth = depth_data->depth; } - if (speed_calc_count++ > 50) // 500ms计算一次速度 + + // 500ms计算一次速度 + if (speed_calc_count++ > 50) { ESP_LOGI(TAG, "speed_calc_count++ > 50\n"); speed_calc_count = 0; @@ -462,35 +726,42 @@ void depth_task(void *arg) { is_work ++; if(is_work == 1){ - depth_data->one_pile_work_time = 0; - last_work_time = (uint16_t)(esp_timer_get_time()/1000000); - } - if(is_work > 1){ - current_work_time = (uint16_t)(esp_timer_get_time()/1000000); - depth_data->one_pile_work_time = current_work_time - last_work_time; - if(depth_data->one_pile_work_time < 0){ - depth_data->one_pile_work_time = 0; + int64_t time = esp_timer_get_time(); + if(time < 0){ + work_start_time = 0; + } + work_start_time = (uint16_t)(time/1000000); + depth_data->one_pile_work_time = 0; + } + else{ + int64_t time = esp_timer_get_time(); + if(time > 0){ + if((uint16_t)(time/1000000) > work_start_time){ + depth_data->one_pile_work_time = ((uint16_t)(time/1000000) - work_start_time); + } } - last_work_time = current_work_time; } - - depth_data->one_pile_work_time = current_work_time - last_work_time; - last_work_time = current_work_time; ESP_LOGI(TAG, "depth_data->up_down > STOP\n"); + // 下钻,深度增加 if (enc_value > last_enc_value) - { // 下钻,深度增加 + { if (depth_data->up_down != 1) - { // 方向改变 + { + // 方向改变,更新目标采样深度 depth_data->up_down = 1; target_sample_depth = (depth_data->depth / depth_config->sample_depth) * depth_config->sample_depth; + + // 小于半个采样长度的合并到下一个采样点 if (abs(depth_data->depth - target_sample_depth) < depth_config->sample_depth / 2) - { // 小于半个采样长度的合并到下一个采样点 + { target_sample_depth += depth_config->sample_depth; } } + + // 到达或超过目标采样点 if (depth_data->depth >= target_sample_depth) - { // 到达或超过目标采样点 + { // 由于编码器精度问题不能确保数据在采样点上,需要通过插值计算采样点 // 当使用10线编码器时每个脉冲深度达6.25cm,当采样间隔为10cm时抖动值太大 if ((prev_depth - depth_data->depth) != 0) @@ -599,7 +870,7 @@ void depth_task(void *arg) vTaskDelay(10); } } - +#endif void add_recod_item(void) { //每10cm计算一次 @@ -663,7 +934,7 @@ void reset_depth(void) depth_data->depth = depth_config->depth_offset; enc1_value = 0; enc1_update_time = 0; - depth_data->up_down = 1; // 默认工作 + depth_data->pile_work_state_and_direction = PILE_STATE_STOP | PILE_DIR_NONE; // 默认不工作 } void DEPTH_init() diff --git a/main/stm32/flow.c b/main/stm32/flow.c index 7615ff0..81eaf94 100644 --- a/main/stm32/flow.c +++ b/main/stm32/flow.c @@ -200,7 +200,7 @@ void flow_task(void *arg) ccr = ccr / (rtc_clk_apb_freq / 1000000); // __enable_irq(); time_diff = ccr - last_ccr[ch]; - ESP_LOGI(TAG, "(type2) t15_ccr_times[%d]: %u %u time_diff: %u", ch, ccr, ccr_times, time_diff); + ESP_LOGI(TAG, "(type2) t15_ccr_times[%d]: %u %d time_diff: %d", ch, ccr, ccr_times, time_diff); printf("rtc_clk_apb_freq : %u\n", rtc_clk_apb_freq); if (time_diff != 0) { diff --git a/main/stm32/uart0_modbus_slave.c b/main/stm32/uart0_modbus_slave.c index 8562b29..b02480e 100644 --- a/main/stm32/uart0_modbus_slave.c +++ b/main/stm32/uart0_modbus_slave.c @@ -27,6 +27,22 @@ static const char *TAG = "UART0"; uint8_t txbuf[BUF_SIZE]; uint8_t rxbuf[BUF_SIZE]; extern int ModbusSlaveProcess(uint8_t *txbuf, uint8_t *rxbuf, uint16_t rxLen, int is_crc); +extern uint16_t gWordVar[]; + +void LED1_Toggle(void) +{ + static unsigned char flg = 1; + if (flg) + { + gpio_set_level(LED1_GPIO_PIN, 0); + flg = 0; + } + else + { + gpio_set_level(LED1_GPIO_PIN, 1); + flg = 1; + } +} void uart0_init(void) { @@ -61,26 +77,14 @@ void uart0_init(void) ESP_ERROR_CHECK(uart_set_rx_timeout(uart_num, UART_READ_TOUT)); } -void LED1_Toggle(void) -{ - static unsigned char flg = 1; - if (flg) - { - gpio_set_level(LED1_GPIO_PIN, 0); - flg = 0; - } - else - { - gpio_set_level(LED1_GPIO_PIN, 1); - flg = 1; - } -} - void uart0_modbus_slave_task(void *arg) { + uart0_init(); + // uint8_t count = 0; while (1) { + // ESP_LOGI("modbus_slave","enter while"); // Read data from UART int txlen = 0; int len = uart_read_bytes(UART_PORT_NUM, rxbuf, BUF_SIZE, UART_READ_TOUT); @@ -88,15 +92,20 @@ void uart0_modbus_slave_task(void *arg) // Write data back to UART if (len > 0) { + ESP_LOGI("modbus_slave","len = %d",len); // uart_write_bytes(UART_PORT_NUM, rxbuf, len); // ESP_LOGI(TAG, "uart_read_bytes len=%d", len); txlen = ModbusSlaveProcess(txbuf, rxbuf, len, 1); if (txlen > 0) { + ESP_LOGI("modbus_slave","txlen = %d",txlen); LED1_Toggle(); - uart_write_bytes(UART_PORT_NUM, txbuf, txlen); + int uart_write_length = uart_write_bytes(UART_PORT_NUM, txbuf, txlen); + ESP_LOGI("modbus_slave","uart_write_length = %d",uart_write_length); + ESP_LOGI("modbus_slave","gWordVar[12] = 0x%04x",gWordVar[12]); } } + // if (tick - last_rxtick >= PACKET_READ_TICS) // { // com_poll_modbus_master_poll(0); @@ -120,6 +129,5 @@ void uart0_modbus_slave_task(void *arg) void uart0_modbus_slave_init(void) { - uart0_init(); xTaskCreate(uart0_modbus_slave_task, "uart0_modbus_slave_task", 4096, NULL, 10, NULL); } diff --git a/main/uart_example.c b/main/uart_example.c index 7247c49..de7364e 100644 --- a/main/uart_example.c +++ b/main/uart_example.c @@ -50,7 +50,7 @@ #define PRINT_UART_BAUD_RATE (115200) #define PRINT_TASK_STACK_SIZE (1024) -static const char *TAG = "UART"; +// static const char *TAG = "UART"; #define BUF_SIZE (1024) diff --git a/main/wifi_softap.c b/main/wifi_softap.c index a6c9318..0932dc6 100644 --- a/main/wifi_softap.c +++ b/main/wifi_softap.c @@ -11,17 +11,16 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_system.h" -#include "esp_wifi.h" +#include "../../../components/esp_wifi/include/esp_wifi.h" #include "esp_event.h" #include "esp_log.h" #include "nvs_flash.h" #include "lwip/err.h" #include "lwip/sys.h" - #include "driver/ledc.h" #include "esp_err.h" - +#include "../../../components/esp_hw_support/include/esp_mac.h" /* The examples use WiFi configuration that you can set via project configuration menu. If you'd rather not, just change the below entries to strings with @@ -48,14 +47,12 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base, if (event_id == WIFI_EVENT_AP_STACONNECTED) { wifi_event_ap_staconnected_t *event = (wifi_event_ap_staconnected_t *)event_data; - ESP_LOGI(TAG, "station " MACSTR " join, AID=%d", - MAC2STR(event->mac), event->aid); + ESP_LOGI(TAG, "station " MACSTR " join, AID=%d",MAC2STR(event->mac), event->aid); } else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) { wifi_event_ap_stadisconnected_t *event = (wifi_event_ap_stadisconnected_t *)event_data; - ESP_LOGI(TAG, "station " MACSTR " leave, AID=%d", - MAC2STR(event->mac), event->aid); + ESP_LOGI(TAG, "station " MACSTR " leave, AID=%d",MAC2STR(event->mac), event->aid); } } extern void ModBusTCPSlave_init(void); diff --git a/sdkconfig b/sdkconfig index a6b055e..c422f60 100644 --- a/sdkconfig +++ b/sdkconfig @@ -221,7 +221,10 @@ CONFIG_BT_CTRL_HCI_MODE_VHCI=y # CONFIG_BT_CTRL_HCI_MODE_UART_H4 is not set CONFIG_BT_CTRL_HCI_TL=1 CONFIG_BT_CTRL_ADV_DUP_FILT_MAX=30 -# CONFIG_BT_CTRL_HW_CCA is not set +CONFIG_BT_BLE_CCA_MODE_NONE=y +# CONFIG_BT_BLE_CCA_MODE_HW is not set +# CONFIG_BT_BLE_CCA_MODE_SW is not set +CONFIG_BT_BLE_CCA_MODE=0 CONFIG_BT_CTRL_HW_CCA_VAL=20 CONFIG_BT_CTRL_HW_CCA_EFF=0 CONFIG_BT_CTRL_CE_LENGTH_TYPE_ORIG=y @@ -301,6 +304,9 @@ CONFIG_BT_GATT_MAX_SR_ATTRIBUTES=100 # CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL is not set CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO=y CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0 +# CONFIG_BT_GATTS_ROBUST_CACHING_ENABLED is not set +# CONFIG_BT_GATTS_DEVICE_NAME_WRITABLE is not set +# CONFIG_BT_GATTS_APPEARANCE_WRITABLE is not set CONFIG_BT_GATTC_ENABLE=y CONFIG_BT_GATTC_MAX_CACHE_CHAR=40 # CONFIG_BT_GATTC_CACHE_NVS_FLASH is not set @@ -491,8 +497,10 @@ CONFIG_BT_SMP_ENABLE=y # CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30 CONFIG_BT_MAX_DEVICE_NAME_LEN=32 +CONFIG_BT_BLE_RPA_TIMEOUT=900 # CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y +# CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL is not set # end of Bluedroid Options # end of Bluetooth @@ -781,6 +789,7 @@ CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE=y # CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION is not set CONFIG_ESP_PHY_MAX_WIFI_TX_POWER=20 CONFIG_ESP_PHY_MAX_TX_POWER=20 +# CONFIG_ESP_PHY_REDUCE_TX_POWER is not set CONFIG_ESP_PHY_ENABLE_USB=y CONFIG_ESP_PHY_RF_CAL_PARTIAL=y # CONFIG_ESP_PHY_RF_CAL_NONE is not set @@ -977,7 +986,7 @@ CONFIG_FREERTOS_TICK_SUPPORT_SYSTIMER=y CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL1=y # CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL3 is not set CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER=y -CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_HZ=100 CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y # CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set # CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set @@ -1826,6 +1835,7 @@ CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y # CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 CONFIG_ESP32_PHY_MAX_TX_POWER=20 +# CONFIG_ESP32_REDUCE_PHY_TX_POWER is not set CONFIG_ESP_SYSTEM_PM_POWER_DOWN_CPU=y # CONFIG_ESP32S2_PANIC_PRINT_HALT is not set CONFIG_ESP32S2_PANIC_PRINT_REBOOT=y diff --git a/sdkconfig.old b/sdkconfig.old index 24b20cd..4fa920a 100644 --- a/sdkconfig.old +++ b/sdkconfig.old @@ -221,7 +221,10 @@ CONFIG_BT_CTRL_HCI_MODE_VHCI=y # CONFIG_BT_CTRL_HCI_MODE_UART_H4 is not set CONFIG_BT_CTRL_HCI_TL=1 CONFIG_BT_CTRL_ADV_DUP_FILT_MAX=30 -# CONFIG_BT_CTRL_HW_CCA is not set +CONFIG_BT_BLE_CCA_MODE_NONE=y +# CONFIG_BT_BLE_CCA_MODE_HW is not set +# CONFIG_BT_BLE_CCA_MODE_SW is not set +CONFIG_BT_BLE_CCA_MODE=0 CONFIG_BT_CTRL_HW_CCA_VAL=20 CONFIG_BT_CTRL_HW_CCA_EFF=0 CONFIG_BT_CTRL_CE_LENGTH_TYPE_ORIG=y @@ -301,6 +304,9 @@ CONFIG_BT_GATT_MAX_SR_ATTRIBUTES=100 # CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL is not set CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_AUTO=y CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MODE=0 +# CONFIG_BT_GATTS_ROBUST_CACHING_ENABLED is not set +# CONFIG_BT_GATTS_DEVICE_NAME_WRITABLE is not set +# CONFIG_BT_GATTS_APPEARANCE_WRITABLE is not set CONFIG_BT_GATTC_ENABLE=y CONFIG_BT_GATTC_MAX_CACHE_CHAR=40 # CONFIG_BT_GATTC_CACHE_NVS_FLASH is not set @@ -491,8 +497,10 @@ CONFIG_BT_SMP_ENABLE=y # CONFIG_BT_BLE_ACT_SCAN_REP_ADV_SCAN is not set CONFIG_BT_BLE_ESTAB_LINK_CONN_TOUT=30 CONFIG_BT_MAX_DEVICE_NAME_LEN=32 +CONFIG_BT_BLE_RPA_TIMEOUT=900 # CONFIG_BT_BLE_50_FEATURES_SUPPORTED is not set CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y +# CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL is not set # end of Bluedroid Options # end of Bluetooth @@ -781,6 +789,7 @@ CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE=y # CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION is not set CONFIG_ESP_PHY_MAX_WIFI_TX_POWER=20 CONFIG_ESP_PHY_MAX_TX_POWER=20 +# CONFIG_ESP_PHY_REDUCE_TX_POWER is not set CONFIG_ESP_PHY_ENABLE_USB=y CONFIG_ESP_PHY_RF_CAL_PARTIAL=y # CONFIG_ESP_PHY_RF_CAL_NONE is not set @@ -827,14 +836,17 @@ CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y # CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set CONFIG_ESP_MAIN_TASK_AFFINITY=0x0 CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048 -# CONFIG_ESP_CONSOLE_UART_DEFAULT is not set +CONFIG_ESP_CONSOLE_UART_DEFAULT=y # CONFIG_ESP_CONSOLE_USB_CDC is not set -CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y +# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set # CONFIG_ESP_CONSOLE_UART_CUSTOM is not set # CONFIG_ESP_CONSOLE_NONE is not set -CONFIG_ESP_CONSOLE_SECONDARY_NONE=y +# CONFIG_ESP_CONSOLE_SECONDARY_NONE is not set +CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG=y +CONFIG_ESP_CONSOLE_UART=y CONFIG_ESP_CONSOLE_MULTIPLE_UART=y -CONFIG_ESP_CONSOLE_UART_NUM=-1 +CONFIG_ESP_CONSOLE_UART_NUM=0 +CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 CONFIG_ESP_INT_WDT=y CONFIG_ESP_INT_WDT_TIMEOUT_MS=300 CONFIG_ESP_INT_WDT_CHECK_CPU1=y