From 5edb904d7cfb541e15bef7acd7dd06b63aa07a3b Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Mon, 21 Dec 2020 19:41:25 +0100 Subject: [PATCH] remove all ESP_ERROR_CHECK(x) --- src/blecsan.cpp | 50 +++++++++++++++++++++++++----------------------- src/lorawan.cpp | 2 +- src/main.cpp | 6 +++--- src/power.cpp | 10 +++++----- src/spislave.cpp | 3 +-- src/wifiscan.cpp | 27 ++++++++++++-------------- 6 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/blecsan.cpp b/src/blecsan.cpp index 5deb6004..33d303dc 100644 --- a/src/blecsan.cpp +++ b/src/blecsan.cpp @@ -128,7 +128,7 @@ IRAM_ATTR void gap_callback_handler(esp_gap_ble_cb_event_t event, switch (event) { case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: // restart scan - ESP_ERROR_CHECK(esp_ble_gap_start_scanning(BLESCANTIME)); + esp_ble_gap_start_scanning(BLESCANTIME); break; case ESP_GAP_BLE_SCAN_RESULT_EVT: @@ -136,7 +136,7 @@ IRAM_ATTR void gap_callback_handler(esp_gap_ble_cb_event_t event, if (p->scan_rst.search_evt == ESP_GAP_SEARCH_INQ_CMPL_EVT) // Inquiry complete, scan is done { // restart scan - ESP_ERROR_CHECK(esp_ble_gap_start_scanning(BLESCANTIME)); + esp_ble_gap_start_scanning(BLESCANTIME); return; } @@ -219,8 +219,8 @@ esp_err_t register_ble_callback(bool unregister = false) { if (unregister) { ESP_LOGI(TAG, "Unregister GAP callback..."); - ESP_ERROR_CHECK(esp_ble_gap_stop_scanning()); - ESP_ERROR_CHECK(esp_ble_gap_register_callback(NULL)); + esp_ble_gap_stop_scanning(); + esp_ble_gap_register_callback(NULL); } @@ -230,23 +230,25 @@ esp_err_t register_ble_callback(bool unregister = false) { // This function is called when gap event occurs, such as scan result. // register the scan callback function to the gap module - ESP_ERROR_CHECK(esp_ble_gap_register_callback(&gap_callback_handler)); + esp_ble_gap_register_callback(&gap_callback_handler); static esp_ble_scan_params_t ble_scan_params = { .scan_type = BLE_SCAN_TYPE_PASSIVE, .own_addr_type = BLE_ADDR_TYPE_RANDOM, .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, -/* - #if (MACFILTER) - .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR, - // ADV_IND, ADV_NONCONN_IND, ADV_SCAN_IND packets are used for broadcasting - // data in broadcast applications (e.g., Beacons), so we don't want them in - // macfilter mode - #else - .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, - #endif -*/ + /* + #if (MACFILTER) + .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR, + // ADV_IND, ADV_NONCONN_IND, ADV_SCAN_IND packets are used + for broadcasting + // data in broadcast applications (e.g., Beacons), so we + don't want them in + // macfilter mode + #else + .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, + #endif + */ .scan_interval = (uint16_t)(cfg.blescantime * 10 / 0.625), // Time = N * 0.625 msec @@ -257,7 +259,7 @@ esp_err_t register_ble_callback(bool unregister = false) { ESP_LOGI(TAG, "Set GAP scan parameters"); // This function is called to set scan parameters. - ESP_ERROR_CHECK(esp_ble_gap_set_scan_params(&ble_scan_params)); + esp_ble_gap_set_scan_params(&ble_scan_params); } return ESP_OK; @@ -269,11 +271,11 @@ void start_BLEscan(void) { ESP_LOGI(TAG, "Initializing bluetooth scanner ..."); // Initialize BT controller to allocate task and other resource. if (btStart()) { // enable bt_controller - ESP_ERROR_CHECK(esp_coex_preference_set(ESP_COEX_PREFER_BT)); - ESP_ERROR_CHECK(esp_bluedroid_init()); - ESP_ERROR_CHECK(esp_bluedroid_enable()); + esp_coex_preference_set(ESP_COEX_PREFER_BT); + esp_bluedroid_init(); + esp_bluedroid_enable(); // Register callback function for capturing bluetooth packets - ESP_ERROR_CHECK(register_ble_callback(false)); + register_ble_callback(false); ESP_LOGI(TAG, "Bluetooth scanner started"); #endif // BLECOUNTER } else { @@ -286,16 +288,16 @@ void start_BLEscan(void) { void stop_BLEscan(void) { #if (BLECOUNTER) ESP_LOGI(TAG, "Shutting down bluetooth scanner ..."); - ESP_ERROR_CHECK(register_ble_callback(true)); // unregister capture function + register_ble_callback(true); // unregister capture function ESP_LOGD(TAG, "bluedroid disable..."); - ESP_ERROR_CHECK(esp_bluedroid_disable()); + esp_bluedroid_disable(); ESP_LOGD(TAG, "bluedroid deinit..."); - ESP_ERROR_CHECK(esp_bluedroid_deinit()); + esp_bluedroid_deinit(); if (!btStop()) { // disable bt_controller ESP_LOGE(TAG, "Bluetooth controller stop failed. Resetting device"); do_reset(true); } - ESP_ERROR_CHECK(esp_coex_preference_set(ESP_COEX_PREFER_WIFI)); + esp_coex_preference_set(ESP_COEX_PREFER_WIFI); ESP_LOGI(TAG, "Bluetooth scanner stopped"); #endif // BLECOUNTER } // stop_BLEscan diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 23d3f612..aa0e9ccd 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -106,7 +106,7 @@ breaking change // DevEUI generator using devices's MAC address void gen_lora_deveui(uint8_t *pdeveui) { uint8_t *p = pdeveui, dmac[6]; - ESP_ERROR_CHECK(esp_efuse_mac_get_default(dmac)); + esp_efuse_mac_get_default(dmac); // deveui is LSB, we reverse it so TTN DEVEUI display // will remain the same as MAC address // MAC is 6 bytes, devEUI 8, set middle 2 ones diff --git a/src/main.cpp b/src/main.cpp index b92a5dba..2ce13018 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -304,9 +304,9 @@ void setup() { #else // remove bluetooth stack to gain more free memory btStop(); - ESP_ERROR_CHECK(esp_bt_mem_release(ESP_BT_MODE_BTDM)); - ESP_ERROR_CHECK(esp_coex_preference_set( - ESP_COEX_PREFER_WIFI)); // configure Wifi/BT coexist lib + esp_bt_mem_release(ESP_BT_MODE_BTDM); + esp_coex_preference_set( + ESP_COEX_PREFER_WIFI); // configure Wifi/BT coexist lib #endif // initialize gps diff --git a/src/power.cpp b/src/power.cpp index 3dee573c..7d49f5be 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -171,11 +171,11 @@ void calibrate_voltage(void) { #ifdef BAT_MEASURE_ADC // configure ADC #ifndef BAT_MEASURE_ADC_UNIT // ADC1 - ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12)); - ESP_ERROR_CHECK(adc1_config_channel_atten(adc_channel, atten)); + adc1_config_width(ADC_WIDTH_BIT_12); + adc1_config_channel_atten(adc_channel, atten); #else // ADC2 - // ESP_ERROR_CHECK(adc2_config_width(ADC_WIDTH_BIT_12)); - ESP_ERROR_CHECK(adc2_config_channel_atten(adc_channel, atten)); + // adc2_config_width(ADC_WIDTH_BIT_12); + adc2_config_channel_atten(adc_channel, atten); #endif // calibrate ADC esp_adc_cal_value_t val_type = esp_adc_cal_characterize( @@ -210,7 +210,7 @@ uint16_t read_voltage(void) { #else // ADC2 int adc_buf = 0; for (int i = 0; i < NO_OF_SAMPLES; i++) { - ESP_ERROR_CHECK(adc2_get_raw(adc_channel, ADC_WIDTH_BIT_12, &adc_buf)); + adc2_get_raw(adc_channel, ADC_WIDTH_BIT_12, &adc_buf); adc_reading += adc_buf; } #endif // BAT_MEASURE_ADC_UNIT diff --git a/src/spislave.cpp b/src/spislave.cpp index bee8497e..57b36614 100644 --- a/src/spislave.cpp +++ b/src/spislave.cpp @@ -91,8 +91,7 @@ void spi_slave_task(void *param) { // wait until spi master clocks out the data, and read results in rx buffer ESP_LOGI(TAG, "Prepared SPI transaction for %zu byte(s)", transaction_size); ESP_LOG_BUFFER_HEXDUMP(TAG, txbuf, transaction_size, ESP_LOG_DEBUG); - ESP_ERROR_CHECK_WITHOUT_ABORT( - spi_slave_transmit(HSPI_HOST, &spi_transaction, portMAX_DELAY)); + spi_slave_transmit(HSPI_HOST, &spi_transaction, portMAX_DELAY); ESP_LOG_BUFFER_HEXDUMP(TAG, rxbuf, transaction_size, ESP_LOG_DEBUG); ESP_LOGI(TAG, "Transaction finished with size %zu bits", spi_transaction.trans_len); diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index ada8255a..c876803c 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -64,15 +64,13 @@ void wifi_sniffer_init(void) { WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA}; - ESP_ERROR_CHECK(esp_wifi_init(&wifi_cfg)); // start Wifi task - ESP_ERROR_CHECK( - esp_wifi_set_country(&wifi_country)); // set locales for RF and channels - ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM)); - ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); - ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE)); // no modem power saving - ESP_ERROR_CHECK( - esp_wifi_set_promiscuous_filter(&wifi_filter)); // set frame filter - ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler)); + esp_wifi_init(&wifi_cfg); // start Wifi task + esp_wifi_set_country(&wifi_country); // set locales for RF and channels + esp_wifi_set_storage(WIFI_STORAGE_RAM); + esp_wifi_set_mode(WIFI_MODE_NULL); + esp_wifi_set_ps(WIFI_PS_NONE); // no modem power saving + esp_wifi_set_promiscuous_filter(&wifi_filter); // set frame filter + esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler); // setup wifi channel hopping timer WifiChanTimer = @@ -85,10 +83,9 @@ void wifi_sniffer_init(void) { void switch_wifi_sniffer(uint8_t state) { if (state) { // start sniffer - ESP_ERROR_CHECK(esp_wifi_start()); - ESP_ERROR_CHECK(esp_wifi_set_promiscuous(true)); - ESP_ERROR_CHECK( - esp_wifi_set_channel(WIFI_CHANNEL_MIN, WIFI_SECOND_CHAN_NONE)); + esp_wifi_start(); + esp_wifi_set_promiscuous(true); + esp_wifi_set_channel(WIFI_CHANNEL_MIN, WIFI_SECOND_CHAN_NONE); // start channel hopping timer if (cfg.wifichancycle > 0) xTimerStart(WifiChanTimer, (TickType_t)0); @@ -97,7 +94,7 @@ void switch_wifi_sniffer(uint8_t state) { if (xTimerIsTimerActive(WifiChanTimer) != pdFALSE) xTimerStop(WifiChanTimer, (TickType_t)0); // stop sniffer - ESP_ERROR_CHECK(esp_wifi_set_promiscuous(false)); - ESP_ERROR_CHECK(esp_wifi_stop()); + esp_wifi_set_promiscuous(false); + esp_wifi_stop(); } } \ No newline at end of file