Add missing undefined symbols to be sure to use mine
Dependents: DS130x_I2CApp MCP41xxxApp FM24Vxx_I2CApp MCP320xApp ... more
Revision 4:d03fcf494eb6, committed 2010-12-08
- Comitter:
- Yann
- Date:
- Wed Dec 08 13:16:16 2010 +0000
- Parent:
- 3:be0c7a9bd686
- Child:
- 5:7ddb6bca6d01
- Commit message:
- V0.0.0.5
Changed in this revision
| Debug.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Debug.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Debug.cpp Wed Nov 24 12:30:18 2010 +0000
+++ b/Debug.cpp Wed Dec 08 13:16:16 2010 +0000
@@ -9,13 +9,70 @@
va_start(argp, p_format);
vprintf(p_format, argp);
va_end(argp);
-}
+} // End of method DebugHelper::Debug
+
+void DebugHelper::HexaDump(unsigned char* p_buffer, int p_count, int p_offset) {
+
+ int currentIdx = p_offset;
+ unsigned short startAddress = ((unsigned short)(p_offset / 16)) * 16;
+
+ DEBUG(">>> %d - %d - %d - %d - %d", p_count, p_offset, p_count + p_offset, currentIdx / 16, currentIdx % 16);
+
+ // Display header
+ printf(" HEX | 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F : 0 1 2 3 4 5 6 7 8 9 A B C D E F \r\n");
+ printf("-----|+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+-:--+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r\n");
+ // 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
+ // 0 1 2 3 4 5 6 7 8 9
+ // Address offset padding
+ char line[91];
+ memset(line, 0x20, 91);
+ sprintf(line, "%04x |", (unsigned short)startAddress);
+ line[6] = 0x20; // Remove NULL character added by sprintf
+ int idx = 0;
+ int hexOffset = 7;
+ int charOffset = 58;
+ for ( ; idx < (int)(currentIdx % 16); idx++) {
+ line[hexOffset] = 0x30;
+ line[hexOffset + 1] = 0x30;
+ hexOffset += 3;
+ charOffset += 2;
+ }
+ // Fill line by line
+ int endOfDump = p_count + p_offset;
+ while(currentIdx < endOfDump) {
+ for ( ; (idx < 16) && (currentIdx < endOfDump); idx++) {
+ line[hexOffset] = DebugHelper::ToHexDigit(*(p_buffer + currentIdx) >> 4);
+ line[hexOffset + 1] = DebugHelper::ToHexDigit(*(p_buffer + currentIdx) & 0x0f);
+ line[charOffset] = DebugHelper::ToCharDigit(*(p_buffer + currentIdx));
+ // Prepare next byte
+ hexOffset += 3;
+ charOffset += 2;
+ currentIdx += 1;
+ }
+ // Display the line
+ line[56] = ':';
+ line[89] = 0x0d;
+ line[90] = 0x0a;
+ printf(line);
+ if (currentIdx < endOfDump) { // Prepare next line, one line = 16 digits
+ startAddress += 16;
+ memset(line, 0x20, 91);
+ sprintf(line, "%04x |", (unsigned short)startAddress);
+ line[6] = 0x20; // Remove NULL character added by sprintf
+ idx = 0;
+ hexOffset = 7;
+ charOffset = 58;
+ } else { // End of line padding
+ break;
+ }
+ } // End of 'while' statement
+} // End of method DebugHelper::HexaDump
void DebugHelper::BreakPoint(const char* p_file, int p_line) {
printf("Stop in %s at line %d\r\n", p_file, p_line);
fflush(stdout);
getchar();
fflush(stdin);
-}
+} // End of method DebugHelper::BreakPoint
#endif // __DEBUG
--- a/Debug.h Wed Nov 24 12:30:18 2010 +0000
+++ b/Debug.h Wed Dec 08 13:16:16 2010 +0000
@@ -27,7 +27,7 @@
/** The steps below describe how to use this library:
* 1. Import this library to your project 'As file', because you will need to modify this file as described in step 2
* 2. Edit this library
- * 3. Remove comment from line 58 (search for '//#define __DEBUG' in this file) to get the DEBUG macro defimed properly. By default, __DEBUG flahg is undef
+ * 3. Remove comment from line 64 (search for '//#define __DEBUG' in this file) to get the DEBUG macro defimed properly. By default, __DEBUG flahg is undef
* 4. Rebuild this library and use the debug macro as decribe in sample code
*
* IMPORTANT: If you modify this libray, please keep this comment up to date for future users
@@ -42,6 +42,12 @@
* int main() {
* DEBUG_ENTER("main") // Log the entry of the C function 'main'
* int counter = 0;
+ * std::string str("This is a sample for heaxdecimal dump using DebugLibrary");
+ * DEBUG(">>> Example:");
+ * HEXADUMP((unsigned char *)str.c_str(), str.length());
+ * DEBUG("===");
+ * HEXADUMP_OFFSET((unsigned char *)str.c_str(), str.length(), 19);
+ * DEBUG("<<<");
* while(1) {
* DEBUG("In loop [%d]", counter++) // A sample message
* myled = 1;
@@ -64,19 +70,31 @@
#ifdef __DEBUG
-/** This class implements debug functionalities based on USB console interface. V0.0.0.4
+/** This class implements debug functionalities based on USB console interface. V0.0.0.5
*
* Note that this class is based on Helper pattern
*/
class DebugHelper
{
+ static inline unsigned char ToHexDigit(unsigned char p_digit) { return ((p_digit < 10) ? (p_digit + 0x30) : (p_digit + 0x37)); };
+ static inline char ToCharDigit(unsigned char p_digit) { return (((p_digit < 0x20) || (p_digit > 0x80)) ? '.' : (char)p_digit); };
public:
- /** Log method
+ /** Standard log method
+ * @param p_format Format string compliant with C 'printf' format string
*/
- static void Debug(const char* format, ...);
+ static void Debug(const char* p_format, ...);
+ /** Log an hexadecimal buffer
+ *
+ * Note that parameters 'p_offset' and 'p_length' are not supported yet
+ *
+ * @param p_buffer The buffer to dump
+ * @param p_count Number of bytes to dump
+ * @param p_offset Offset to start the dump. Default: 0
+ */
+ static void HexaDump(unsigned char* p_buffer, int p_count, int p_offset = 0);
/** Break point method based on getchar() C function
*/
- static void BreakPoint(const char* file, int line);
+ static void BreakPoint(const char* p_file, int p_line);
}; // End of class DebugHelper
/** Used to log function/method entry (>> )
@@ -94,6 +112,16 @@
* Note that \ for multiline macro is not supported yet
*/
#define DEBUG(...) do { DebugHelper::Debug(__VA_ARGS__); DebugHelper::Debug("\r\n"); } while(false);
+/** Used to dump an hexadecimal buffer
+ *
+ * Note that \ for multiline macro is not supported yet
+ */
+#define HEXADUMP(p_buffer, p_count) DebugHelper::HexaDump(p_buffer, p_count);
+/** Used to dump an hexadecimal buffer with an offset
+ *
+ * Note that \ for multiline macro is not supported yet
+ */
+#define HEXADUMP_OFFSET(p_buffer, p_count, p_offset) DebugHelper::HexaDump(p_buffer, p_count, p_offset);
/** Used to log an error message (?? )
*
* Note that \ for multiline macro is not supported yet
@@ -124,6 +152,16 @@
/** Undefine DEBUG macro, used when __DEBUG is undefined
*/
#define DEBUG(...)
+/** Undefine DEBUG macro, used when __DEBUG is undefined
+ *
+ * Note that \ for multiline macro is not supported yet
+ */
+#define HEXADUMP(p_buffer, p_count)
+/** Undefine DEBUG macro, used when __DEBUG is undefined
+ *
+ * Note that \ for multiline macro is not supported yet
+ */
+#define HEXADUMP_OFFSET(p_buffer, p_count, p_offset)
/** Undefine DEBUG_ERROR macro, used when __DEBUG is undefined
*/
#define DEBUG_ERROR(...)
Yann Garcia