@@ -1408,22 +1408,16 @@ class BLEAdvCallbacks: public NimBLEAdvertisedDeviceCallbacks {
1408
1408
1409
1409
// call anyone who asked about advertisements
1410
1410
for (int i = 0 ; i < advertismentCallbacks.size (); i++) {
1411
- try {
1412
- ADVERTISMENT_CALLBACK* pFN;
1413
- pFN = advertismentCallbacks[i];
1414
- int res = pFN (&BLEAdvertisment);
1411
+ ADVERTISMENT_CALLBACK* pFN;
1412
+ pFN = advertismentCallbacks[i];
1413
+ int res = pFN (&BLEAdvertisment);
1415
1414
1416
- // if this callback wants to stop here, then do so.
1417
- if (1 == res) break ;
1415
+ // if this callback wants to stop here, then do so.
1416
+ if (1 == res) break ;
1418
1417
1419
- // if this callback wants to kill this device
1420
- if (2 == res) {
1421
- // BLEScan->erase(address);
1422
- }
1423
- } catch (const std::exception& e){
1424
- #ifdef BLE_ESP32_DEBUG
1425
- AddLog (LOG_LEVEL_ERROR,PSTR (" BLE: exception in advertismentCallbacks" ));
1426
- #endif
1418
+ // if this callback wants to kill this device
1419
+ if (2 == res) {
1420
+ // BLEScan->erase(address);
1427
1421
}
1428
1422
}
1429
1423
@@ -1444,17 +1438,11 @@ static void BLEscanEndedCB(NimBLEScanResults results){
1444
1438
if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: Scan ended" ));
1445
1439
#endif
1446
1440
for (int i = 0 ; i < scancompleteCallbacks.size (); i++){
1447
- try {
1448
- SCANCOMPLETE_CALLBACK *pFn = scancompleteCallbacks[i];
1449
- int callbackres = pFn (results);
1450
- #ifdef BLE_ESP32_DEBUG
1451
- if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: scancompleteCallbacks %d %d" ), i, callbackres);
1452
- #endif
1453
- } catch (const std::exception& e){
1441
+ SCANCOMPLETE_CALLBACK *pFn = scancompleteCallbacks[i];
1442
+ int callbackres = pFn (results);
1454
1443
#ifdef BLE_ESP32_DEBUG
1455
- AddLog (LOG_LEVEL_ERROR ,PSTR (" BLE: exception in operationsCallbacks " ) );
1444
+ if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG ,PSTR (" BLE: scancompleteCallbacks %d %d " ), i, callbackres );
1456
1445
#endif
1457
- }
1458
1446
}
1459
1447
1460
1448
BLERunningScan = 2 ;
@@ -1659,23 +1647,17 @@ static void BLETaskStopStartNimBLE(NimBLEClient **ppClient, bool start = true){
1659
1647
1660
1648
(*ppClient)->setClientCallbacks (nullptr , false );
1661
1649
1662
- try {
1663
- if ((*ppClient)->isConnected ()){
1664
- #ifdef BLE_ESP32_DEBUG
1665
- AddLog (LOG_LEVEL_INFO,PSTR (" BLE: disconnecting connected client" ));
1666
- #endif
1667
- (*ppClient)->disconnect ();
1668
- }
1669
- NimBLEDevice::deleteClient ((*ppClient));
1670
- (*ppClient) = nullptr ;
1650
+ if ((*ppClient)->isConnected ()){
1671
1651
#ifdef BLE_ESP32_DEBUG
1672
- AddLog (LOG_LEVEL_INFO,PSTR (" BLE: deleted client" ));
1652
+ AddLog (LOG_LEVEL_INFO,PSTR (" BLE: disconnecting connected client" ));
1673
1653
#endif
1674
- } catch (const std::exception& e){
1654
+ (*ppClient)->disconnect ();
1655
+ }
1656
+ NimBLEDevice::deleteClient ((*ppClient));
1657
+ (*ppClient) = nullptr ;
1675
1658
#ifdef BLE_ESP32_DEBUG
1676
- AddLog (LOG_LEVEL_ERROR ,PSTR (" BLE: Stopping NimBLE:exception in delete client" ));
1659
+ AddLog (LOG_LEVEL_INFO ,PSTR (" BLE: deleted client" ));
1677
1660
#endif
1678
- }
1679
1661
1680
1662
if (ble32Scan){
1681
1663
ble32Scan->setAdvertisedDeviceCallbacks (nullptr ,true );
@@ -2089,47 +2071,41 @@ static void BLETaskRunCurrentOperation(BLE_ESP32::generic_sensor_t** pCurrentOpe
2089
2071
2090
2072
// for safety's sake, only call from the run task
2091
2073
static void BLETaskRunTaskDoneOperation (BLE_ESP32::generic_sensor_t ** op, NimBLEClient **ppClient){
2092
- try {
2093
- if ((*ppClient)->isConnected ()){
2074
+ if ((*ppClient)->isConnected ()){
2094
2075
#ifdef BLE_ESP32_DEBUG
2095
- if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: runTaskDoneOperation: disconnecting connected client" ));
2076
+ if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: runTaskDoneOperation: disconnecting connected client" ));
2096
2077
#endif
2097
- (*ppClient)->disconnect ();
2098
- // wait for 1/2 second after disconnect
2099
- int waits = 0 ;
2100
- do {
2101
- vTaskDelay (500 / portTICK_PERIOD_MS);
2102
- if (waits) {
2103
- // (*ppClient)->disconnect();
2104
- // we will stall here forever!!! - as testing
2078
+ (*ppClient)->disconnect ();
2079
+ // wait for 1/2 second after disconnect
2080
+ int waits = 0 ;
2081
+ do {
2082
+ vTaskDelay (500 / portTICK_PERIOD_MS);
2083
+ if (waits) {
2084
+ // (*ppClient)->disconnect();
2085
+ // we will stall here forever!!! - as testing
2105
2086
#ifdef BLE_ESP32_DEBUG
2106
- AddLog (LOG_LEVEL_ERROR,PSTR (" BLE: wait discon%d" ), waits);
2087
+ AddLog (LOG_LEVEL_ERROR,PSTR (" BLE: wait discon%d" ), waits);
2107
2088
#endif
2108
- vTaskDelay (500 / portTICK_PERIOD_MS);
2109
- }
2110
- waits++;
2111
- if (waits == 5 ){
2112
- int conn_id = (*ppClient)->getConnId ();
2113
- ble_gap_conn_broken (conn_id, -1 );
2089
+ vTaskDelay (500 / portTICK_PERIOD_MS);
2090
+ }
2091
+ waits++;
2092
+ if (waits == 5 ){
2093
+ int conn_id = (*ppClient)->getConnId ();
2094
+ ble_gap_conn_broken (conn_id, -1 );
2114
2095
#ifdef BLE_ESP32_DEBUG
2115
- AddLog (LOG_LEVEL_ERROR,PSTR (" BLE: wait discon%d - kill connection" ), waits);
2096
+ AddLog (LOG_LEVEL_ERROR,PSTR (" BLE: wait discon%d - kill connection" ), waits);
2116
2097
#endif
2117
- }
2118
- if (waits == 60 ){
2119
- AddLog (LOG_LEVEL_ERROR,PSTR (" BLE: >60s waiting -> BLE Failed, restart Tasmota %d" ), waits);
2120
- BLEStop = 1 ;
2121
- BLEStopAt = esp_timer_get_time ();
2098
+ }
2099
+ if (waits == 60 ){
2100
+ AddLog (LOG_LEVEL_ERROR,PSTR (" BLE: >60s waiting -> BLE Failed, restart Tasmota %d" ), waits);
2101
+ BLEStop = 1 ;
2102
+ BLEStopAt = esp_timer_get_time ();
2122
2103
2123
- BLERestartTasmota = 10 ;
2124
- BLERestartTasmotaReason = BLE_RESTART_TEAMOTA_REASON_BLE_DISCONNECT_FAIL;
2125
- break ;
2126
- }
2127
- } while ((*ppClient)->isConnected ());
2128
- }
2129
- } catch (const std::exception& e){
2130
- #ifdef BLE_ESP32_DEBUG
2131
- AddLog (LOG_LEVEL_ERROR,PSTR (" BLE: runTaskDoneOperation: exception in disconnect" ));
2132
- #endif
2104
+ BLERestartTasmota = 10 ;
2105
+ BLERestartTasmotaReason = BLE_RESTART_TEAMOTA_REASON_BLE_DISCONNECT_FAIL;
2106
+ break ;
2107
+ }
2108
+ } while ((*ppClient)->isConnected ());
2133
2109
}
2134
2110
2135
2111
@@ -3322,35 +3298,23 @@ static void mainThreadOpCallbacks() {
3322
3298
3323
3299
if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: op->completecallback is %u opid %d" ), op->completecallback , op->opid );
3324
3300
if (op->completecallback ){
3325
- try {
3326
- OPCOMPLETE_CALLBACK *pFn = (OPCOMPLETE_CALLBACK *)(op->completecallback );
3327
- callbackres = pFn (op);
3301
+ OPCOMPLETE_CALLBACK *pFn = (OPCOMPLETE_CALLBACK *)(op->completecallback );
3302
+ callbackres = pFn (op);
3328
3303
#ifdef BLE_ESP32_DEBUG
3329
- if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: op->completecallback %d opid %d" ), callbackres, op->opid );
3304
+ if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: op->completecallback %d opid %d" ), callbackres, op->opid );
3330
3305
#endif
3331
- } catch (const std::exception& e){
3332
- #ifdef BLE_ESP32_DEBUG
3333
- AddLog (LOG_LEVEL_ERROR,PSTR (" BLE: exception in op->completecallback" ));
3334
- #endif
3335
- }
3336
3306
}
3337
3307
3338
3308
if (!callbackres){
3339
3309
for (int i = 0 ; i < operationsCallbacks.size (); i++){
3340
- try {
3341
- if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: operationsCallbacks %d is %u" ), i, operationsCallbacks[i]);
3342
- OPCOMPLETE_CALLBACK *pFn = operationsCallbacks[i];
3343
- callbackres = pFn (op);
3344
- #ifdef BLE_ESP32_DEBUG
3345
- if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: operationsCallbacks %d %d" ), i, callbackres);
3346
- #endif
3347
- if (callbackres){
3348
- break ; // this callback ate the op.
3349
- }
3350
- } catch (const std::exception& e){
3310
+ if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG,PSTR (" BLE: operationsCallbacks %d is %u" ), i, operationsCallbacks[i]);
3311
+ OPCOMPLETE_CALLBACK *pFn = operationsCallbacks[i];
3312
+ callbackres = pFn (op);
3351
3313
#ifdef BLE_ESP32_DEBUG
3352
- AddLog (LOG_LEVEL_ERROR ,PSTR (" BLE: exception in operationsCallbacks " ) );
3314
+ if (BLEDebugMode > 0 ) AddLog (LOG_LEVEL_DEBUG ,PSTR (" BLE: operationsCallbacks %d %d " ), i, callbackres );
3353
3315
#endif
3316
+ if (callbackres){
3317
+ break ; // this callback ate the op.
3354
3318
}
3355
3319
}
3356
3320
}
0 commit comments