@@ -218,19 +218,19 @@ void dbgDumpMemory(void const *buf, uint8_t size, uint16_t count, bool printOffs
218
218
Serial.println ();
219
219
}
220
220
221
- /* ------------------------------------------------------------------*/
222
- /*
223
- *------------------------------------------------------------------*/
224
-
225
221
#if CFG_DEBUG
226
222
227
223
#include " ble.h"
228
224
#include " ble_hci.h"
229
225
230
226
// TODO require update when upgrading SoftDevice
231
227
228
+ /* ------------------------------------------------------------------*/
229
+ /* Event String
230
+ *------------------------------------------------------------------*/
231
+
232
232
// Common BLE Event base
233
- static const char * _base_evt_str [] =
233
+ static const char * _evt_base_str [] =
234
234
{
235
235
#if SD_VER < 500
236
236
" BLE_EVT_TX_COMPLETE" ,
@@ -239,7 +239,7 @@ static const char* _base_evt_str[] =
239
239
" BLE_EVT_USER_MEM_RELEASE" ,
240
240
};
241
241
242
- static const char * _gap_evt_str [] =
242
+ static const char * _evt_gap_str [] =
243
243
{
244
244
" BLE_GAP_EVT_CONNECTED" ,
245
245
" BLE_GAP_EVT_DISCONNECTED" ,
@@ -265,7 +265,7 @@ static const char* _gap_evt_str[] =
265
265
};
266
266
267
267
// GATTC Event
268
- static const char * _gattc_evt_str [] =
268
+ static const char * _evt_gattc_str [] =
269
269
{
270
270
" BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP" ,
271
271
" BLE_GATTC_EVT_REL_DISC_RSP" ,
@@ -287,7 +287,7 @@ static const char* _gattc_evt_str[] =
287
287
};
288
288
289
289
// GATTS Event
290
- static const char * _gatts_evt_str [] =
290
+ static const char * _evt_gatts_str [] =
291
291
{
292
292
" BLE_GATTS_EVT_WRITE" ,
293
293
" BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST" ,
@@ -307,20 +307,107 @@ const char* dbg_ble_event_str(uint16_t evt_id)
307
307
{
308
308
static char unknown_evt[7 ] = {0 };
309
309
310
- if ( is_within (BLE_EVT_BASE, evt_id, BLE_EVT_BASE+arrcount (_base_evt_str )) )
311
- return _base_evt_str [evt_id-BLE_EVT_BASE];
312
- else if ( is_within (BLE_GAP_EVT_BASE, evt_id, BLE_GAP_EVT_BASE+arrcount (_gap_evt_str )) )
313
- return _gap_evt_str [evt_id-BLE_GAP_EVT_BASE];
314
- else if ( is_within (BLE_GATTC_EVT_BASE, evt_id, BLE_GATTC_EVT_BASE+arrcount (_gattc_evt_str ) ) )
315
- return _gattc_evt_str [evt_id-BLE_GATTC_EVT_BASE];
316
- else if ( is_within (BLE_GATTS_EVT_BASE, evt_id, BLE_GATTS_EVT_BASE+arrcount (_gatts_evt_str )) )
317
- return _gatts_evt_str [evt_id-BLE_GATTS_EVT_BASE];
310
+ if ( is_within (BLE_EVT_BASE, evt_id, BLE_EVT_BASE+arrcount (_evt_base_str )) )
311
+ return _evt_base_str [evt_id-BLE_EVT_BASE];
312
+ else if ( is_within (BLE_GAP_EVT_BASE, evt_id, BLE_GAP_EVT_BASE+arrcount (_evt_gap_str )) )
313
+ return _evt_gap_str [evt_id-BLE_GAP_EVT_BASE];
314
+ else if ( is_within (BLE_GATTC_EVT_BASE, evt_id, BLE_GATTC_EVT_BASE+arrcount (_evt_gattc_str ) ) )
315
+ return _evt_gattc_str [evt_id-BLE_GATTC_EVT_BASE];
316
+ else if ( is_within (BLE_GATTS_EVT_BASE, evt_id, BLE_GATTS_EVT_BASE+arrcount (_evt_gatts_str )) )
317
+ return _evt_gatts_str [evt_id-BLE_GATTS_EVT_BASE];
318
318
else
319
319
{
320
320
sprintf (unknown_evt, " 0x%04X" , evt_id);
321
321
return unknown_evt;
322
322
}
323
323
}
324
324
325
+ /* ------------------------------------------------------------------*/
326
+ /* Error String
327
+ *------------------------------------------------------------------*/
328
+ static lookup_entry_t const _err_lookup_items[] =
329
+ {
330
+ // General
331
+ { .key = NRF_ERROR_SVC_HANDLER_MISSING , .data = " NRF_ERROR_SVC_HANDLER_MISSING" },
332
+ { .key = NRF_ERROR_SOFTDEVICE_NOT_ENABLED , .data = " NRF_ERROR_SOFTDEVICE_NOT_ENABLED" },
333
+ { .key = NRF_ERROR_INTERNAL , .data = " NRF_ERROR_INTERNAL" },
334
+ { .key = NRF_ERROR_NO_MEM , .data = " NRF_ERROR_NO_MEM" },
335
+ { .key = NRF_ERROR_NOT_FOUND , .data = " NRF_ERROR_NOT_FOUND" },
336
+ { .key = NRF_ERROR_NOT_SUPPORTED , .data = " NRF_ERROR_NOT_SUPPORTED" },
337
+ { .key = NRF_ERROR_INVALID_PARAM , .data = " NRF_ERROR_INVALID_PARAM" },
338
+ { .key = NRF_ERROR_INVALID_STATE , .data = " NRF_ERROR_INVALID_STATE" },
339
+ { .key = NRF_ERROR_INVALID_LENGTH , .data = " NRF_ERROR_INVALID_LENGTH" },
340
+ { .key = NRF_ERROR_INVALID_FLAGS , .data = " NRF_ERROR_INVALID_FLAGS" },
341
+ { .key = NRF_ERROR_INVALID_DATA , .data = " NRF_ERROR_INVALID_DATA" },
342
+ { .key = NRF_ERROR_DATA_SIZE , .data = " NRF_ERROR_DATA_SIZE" },
343
+ { .key = NRF_ERROR_TIMEOUT , .data = " NRF_ERROR_TIMEOUT" },
344
+ { .key = NRF_ERROR_NULL , .data = " NRF_ERROR_NULL" },
345
+ { .key = NRF_ERROR_FORBIDDEN , .data = " NRF_ERROR_FORBIDDEN" },
346
+ { .key = NRF_ERROR_INVALID_ADDR , .data = " NRF_ERROR_INVALID_ADDR" },
347
+ { .key = NRF_ERROR_BUSY , .data = " NRF_ERROR_BUSY" },
348
+ { .key = NRF_ERROR_CONN_COUNT , .data = " NRF_ERROR_CONN_COUNT" },
349
+ { .key = NRF_ERROR_RESOURCES , .data = " NRF_ERROR_RESOURCES" },
350
+
351
+ // SDM
352
+ { .key = NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN , .data = " NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN" },
353
+ { .key = NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION , .data = " NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION" },
354
+ { .key = NRF_ERROR_SDM_INCORRECT_CLENR0 , .data = " NRF_ERROR_SDM_INCORRECT_CLENR0" },
355
+
356
+ // SOC
357
+ { .key = NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN , .data = " NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN" },
358
+ { .key = NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE , .data = " NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE" },
359
+ { .key = NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED , .data = " NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED" },
360
+ { .key = NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN , .data = " NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN" },
361
+ { .key = NRF_ERROR_SOC_POWER_MODE_UNKNOWN , .data = " NRF_ERROR_SOC_POWER_MODE_UNKNOWN" },
362
+ { .key = NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN , .data = " NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN" },
363
+ { .key = NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN , .data = " NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN" },
364
+ { .key = NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES , .data = " NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES" },
365
+ { .key = NRF_ERROR_SOC_PPI_INVALID_CHANNEL , .data = " NRF_ERROR_SOC_PPI_INVALID_CHANNEL" },
366
+ { .key = NRF_ERROR_SOC_PPI_INVALID_GROUP , .data = " NRF_ERROR_SOC_PPI_INVALID_GROUP" },
367
+
368
+ // BLE Generic
369
+ { .key = BLE_ERROR_NOT_ENABLED , .data = " BLE_ERROR_NOT_ENABLED" },
370
+ { .key = BLE_ERROR_INVALID_CONN_HANDLE , .data = " BLE_ERROR_INVALID_CONN_HANDLE" },
371
+ { .key = BLE_ERROR_INVALID_ATTR_HANDLE , .data = " BLE_ERROR_INVALID_ATTR_HANDLE" },
372
+ { .key = BLE_ERROR_INVALID_ROLE , .data = " BLE_ERROR_INVALID_ROLE" },
373
+
374
+ // BLE GAP
375
+ { .key = BLE_ERROR_GAP_UUID_LIST_MISMATCH , .data = " BLE_ERROR_GAP_UUID_LIST_MISMATCH" },
376
+ { .key = BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST , .data = " BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST" },
377
+ { .key = BLE_ERROR_GAP_INVALID_BLE_ADDR , .data = " BLE_ERROR_GAP_INVALID_BLE_ADDR" },
378
+ { .key = BLE_ERROR_GAP_WHITELIST_IN_USE , .data = " BLE_ERROR_GAP_WHITELIST_IN_USE" },
379
+ #if SD_VER >= 500
380
+ { .key = BLE_ERROR_GAP_DEVICE_IDENTITIES_IN_USE , .data = " BLE_ERROR_GAP_DEVICE_IDENTITIES_IN_USE" },
381
+ { .key = BLE_ERROR_GAP_DEVICE_IDENTITIES_DUPLICATE , .data = " BLE_ERROR_GAP_DEVICE_IDENTITIES_DUPLICATE" },
382
+ #endif
383
+
384
+ // BLE GATTC
385
+ { .key = BLE_ERROR_GATTC_PROC_NOT_PERMITTED , .data = " BLE_ERROR_GATTC_PROC_NOT_PERMITTED" },
386
+
387
+ // BLE GATTS
388
+ { .key = BLE_ERROR_GATTS_INVALID_ATTR_TYPE , .data = " BLE_ERROR_GATTS_INVALID_ATTR_TYPE" },
389
+ { .key = BLE_ERROR_GATTS_SYS_ATTR_MISSING , .data = " BLE_ERROR_GATTS_SYS_ATTR_MISSING" },
390
+ };
391
+
392
+ lookup_table_t const _err_table =
393
+ {
394
+ .count = arrcount (_err_lookup_items),
395
+ .items = _err_lookup_items
396
+ };
397
+
398
+ const char * dbg_err_str (uint32_t err_id)
399
+ {
400
+ const char * str = (const char *) lookup_find (&_err_table, err_id);
401
+ static char unknown_err[7 ] = {0 };
402
+
403
+ if ( str == NULL )
404
+ {
405
+ sprintf (unknown_err, " 0x%04X" , err_id);
406
+ str = unknown_err;
407
+ }
408
+
409
+ return str;
410
+ }
411
+
325
412
#endif
326
413
0 commit comments