update debug facilities
This commit is contained in:
1 parent
1196ba52ba
commit
7fbe44cd31
6 files changed
+222
-5
No files matched your search
@@ -83,15 +83,18 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// DEBUG HELPER
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_DEBUG == 3
|
||||
#if CFG_DEBUG == 2
|
||||
#define malloc_named( name, size ) ({ printf("[malloc] %s : %d\r\n", name, size); malloc(size); })
|
||||
#else
|
||||
#define malloc_named( name, size ) malloc ( size )
|
||||
#endif
|
||||
|
||||
int cprintf(const char * format, ...);
|
||||
|
||||
#if CFG_DEBUG
|
||||
|
||||
#define PRINT_LOCATION() cprintf("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__)
|
||||
#define PRINT_MESS(x) cprintf("%s: %d: " x " \n" , __PRETTY_FUNCTION__, __LINE__)
|
||||
#define PRINT_MESS(x) cprintf("%s: %d: %s \n" , __PRETTY_FUNCTION__, __LINE__, (char*)(x))
|
||||
#define PRTNT_HEAP() if (CFG_DEBUG == 3) cprintf("\n%s: %d: Heap free: %d\n", __PRETTY_FUNCTION__, __LINE__, util_heap_get_free_size())
|
||||
#define PRINT_STR(x) cprintf("%s: %d: " #x " = %s\n" , __PRETTY_FUNCTION__, __LINE__, (char*)(x) )
|
||||
#define PRINT_INT(x) cprintf("%s: %d: " #x " = %ld\n" , __PRETTY_FUNCTION__, __LINE__, (uint32_t) (x) )
|
||||
@@ -112,6 +115,18 @@ int cprintf(const char * format, ...);
|
||||
Serial.println();\
|
||||
}while(0)
|
||||
|
||||
#else
|
||||
|
||||
#define PRINT_LOCATION()
|
||||
#define PRINT_MESS(x)
|
||||
#define PRTNT_HEAP()
|
||||
#define PRINT_STR(x)
|
||||
#define PRINT_INT(x)
|
||||
#define PRINT_HEX(x)
|
||||
#define PRINT_BUFFER(buf, n)
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INLINE FUNCTION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@@ -150,3 +150,86 @@ void dbgMemInfo(void)
|
||||
Serial.println(buf);
|
||||
rtos_free(buf);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/*
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
#if CFG_DEBUG
|
||||
|
||||
#include "ble.h"
|
||||
#include "ble_hci.h"
|
||||
|
||||
// Common BLE Event base
|
||||
static const char* _base_evt_str[] =
|
||||
{
|
||||
"BLE_EVT_TX_COMPLETE" ,
|
||||
"BLE_EVT_USER_MEM_REQUEST" ,
|
||||
"BLE_EVT_USER_MEM_RELEASE" ,
|
||||
};
|
||||
|
||||
static const char* _gap_evt_str[] =
|
||||
{
|
||||
"BLE_GAP_EVT_CONNECTED" ,
|
||||
"BLE_GAP_EVT_DISCONNECTED" ,
|
||||
"BLE_GAP_EVT_CONN_PARAM_UPDATE" ,
|
||||
"BLE_GAP_EVT_SEC_PARAMS_REQUEST" ,
|
||||
"BLE_GAP_EVT_SEC_INFO_REQUEST" ,
|
||||
"BLE_GAP_EVT_PASSKEY_DISPLAY" ,
|
||||
"BLE_GAP_EVT_KEY_PRESSED" ,
|
||||
"BLE_GAP_EVT_AUTH_KEY_REQUEST" ,
|
||||
"BLE_GAP_EVT_LESC_DHKEY_REQUEST" ,
|
||||
"BLE_GAP_EVT_AUTH_STATUS" ,
|
||||
"BLE_GAP_EVT_CONN_SEC_UPDATE" ,
|
||||
"BLE_GAP_EVT_TIMEOUT" ,
|
||||
"BLE_GAP_EVT_RSSI_CHANGED" ,
|
||||
"BLE_GAP_EVT_ADV_REPORT" ,
|
||||
"BLE_GAP_EVT_SEC_REQUEST" ,
|
||||
"BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST" ,
|
||||
"BLE_GAP_EVT_SCAN_REQ_REPORT" ,
|
||||
};
|
||||
|
||||
// GATTC Event
|
||||
static const char* _gattc_evt_str[] =
|
||||
{
|
||||
"BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP" ,
|
||||
"BLE_GATTC_EVT_REL_DISC_RSP" ,
|
||||
"BLE_GATTC_EVT_CHAR_DISC_RSP" ,
|
||||
"BLE_GATTC_EVT_DESC_DISC_RSP" ,
|
||||
"BLE_GATTC_EVT_ATTR_INFO_DISC_RSP" ,
|
||||
"BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP" ,
|
||||
"BLE_GATTC_EVT_READ_RSP" ,
|
||||
"BLE_GATTC_EVT_CHAR_VALS_READ_RSP" ,
|
||||
"BLE_GATTC_EVT_WRITE_RSP" ,
|
||||
"BLE_GATTC_EVT_HVX" ,
|
||||
"BLE_GATTC_EVT_TIMEOUT"
|
||||
};
|
||||
|
||||
// GATTS Event
|
||||
static const char* _gatts_evt_str[] =
|
||||
{
|
||||
"BLE_GATTS_EVT_WRITE" ,
|
||||
"BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST" ,
|
||||
"BLE_GATTS_EVT_SYS_ATTR_MISSING" ,
|
||||
"BLE_GATTS_EVT_HVC" ,
|
||||
"BLE_GATTS_EVT_SC_CONFIRM" ,
|
||||
"BLE_GATTS_EVT_TIMEOUT" ,
|
||||
};
|
||||
|
||||
const char* dbg_ble_event_str(uint16_t evt_id)
|
||||
{
|
||||
if ( is_within(BLE_EVT_BASE, evt_id, BLE_EVT_LAST) )
|
||||
return _base_evt_str[evt_id-BLE_EVT_BASE];
|
||||
else if ( is_within(BLE_GAP_EVT_BASE, evt_id, BLE_GAP_EVT_LAST) )
|
||||
return _gap_evt_str[evt_id-BLE_GAP_EVT_BASE];
|
||||
else if ( is_within(BLE_GATTC_EVT_BASE, evt_id, BLE_GATTC_EVT_LAST) )
|
||||
return _gattc_evt_str[evt_id-BLE_GATTC_EVT_BASE];
|
||||
else if ( is_within(BLE_GATTS_EVT_BASE, evt_id, BLE_GATTS_EVT_LAST) )
|
||||
return _gatts_evt_str[evt_id-BLE_GATTS_EVT_BASE];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,6 +39,10 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#if CFG_DEBUG
|
||||
const char* dbg_ble_event_str(uint16_t evt_id);
|
||||
#endif
|
||||
|
||||
int dbgHeapTotal(void);
|
||||
int dbgHeapUsed(void);
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file utilities.c
|
||||
@author hathach
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2017, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/*!
|
||||
@brief Find the corresponding data from the key
|
||||
@param
|
||||
*/
|
||||
/******************************************************************************/
|
||||
void const * lookup_find(lookup_table_t const* p_table, uint32_t key)
|
||||
{
|
||||
for(uint16_t i=0; i<p_table->count; i++)
|
||||
{
|
||||
if (p_table->items[i].key == key) return p_table->items[i].data;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file utilities.h
|
||||
@author hathach
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2017, Adafruit Industries (adafruit.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#ifndef UTILITIES_H_
|
||||
#define UTILITIES_H_
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t key;
|
||||
void const * data;
|
||||
}lookup_entry_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t count;
|
||||
uint16_t data_size;
|
||||
|
||||
lookup_entry_t const* items;
|
||||
} lookup_table_t;
|
||||
|
||||
void const * lookup_find(lookup_table_t const* p_table, uint32_t key);
|
||||
|
||||
#endif /* UTILITIES_H_ */
|
||||
@@ -600,6 +600,13 @@ void AdafruitBluefruit::_poll(void)
|
||||
}
|
||||
else if( ERROR_NONE == err)
|
||||
{
|
||||
#if CFG_DEBUG
|
||||
Serial.print("[BLE]: ");
|
||||
if ( dbg_ble_event_str(evt->header.evt_id) ) Serial.print(dbg_ble_event_str(evt->header.evt_id));
|
||||
else Serial.printf("0x04X", evt->header.evt_id);
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
switch ( evt->header.evt_id )
|
||||
{
|
||||
case BLE_GAP_EVT_CONNECTED:
|
||||
@@ -770,9 +777,7 @@ void AdafruitBluefruit::_poll(void)
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
//PRINT_HEX(evt->header.evt_id);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Central Event Handler
|
||||
|
||||
Reference in new issue
Block a user