Library for Modtronix NZ32 STM32 boards, like the NZ32-SC151, NZ32-SB072, NZ32-SE411 and others

Revision:
13:328bfac0e686
Parent:
9:5000feb4b46f
Child:
17:86034c970ea0
--- a/mx_cmd_buffer.h	Thu Sep 17 11:53:01 2015 +1000
+++ b/mx_cmd_buffer.h	Wed Oct 21 14:53:20 2015 +1100
@@ -22,47 +22,80 @@
 #define SRC_MX_CMD_BUFFER_H_
 
 // This file contains an ASCII command buffer. It is used to store ASCII commands.
+//
 // Each command ends with a ';' character. CR(0x0a='\r') and LF(0x0d='\n') are converted to ';' characters.
+//
 // A ASCII command is an ASCII Formatted String, with Escape Sequences (Control Characters).
-// It uses 2 upper case characters to represent a single hex character.
-// Strings must be enclosed within single quotation marks(').
-// Lower case characters 'a' to 'z' are used to represent "Control characters". It has the following format:
+// It uses 2 upper case characters to represent a single hex character, and can have embedded strings (enclosed
+// within single quotation marks = ') and "Control Characters" (Lower case characters 'a' to 'z')
+//
+// It has the following format:
 // HH   = Two upper case characters representing a single byte (hex value).
-// XHH  = Same as HH
-// NDD  = Decimal number. For example "N100" = decimal 100 t0='500'
-// c    = Lower case character 'a' to 'z' represents a "control character".
-// s, p = 's' an 'p' control characters represent the start and stop of a message.
+// XHH  = **Not Implemented Yet** Same as HH
+// NDD  = **Not Implemented Yet**  Decimal number. For example "N100" = decimal 100 t0='500'
+// c    = **Not Implemented Yet** Lower case character 'a' to 'z' represents a "control character".
+// '    = Enclose string with single quotes. A double ' character will not end the string, but represents a
+//        single ' character.
 // ^^   = Two "escape characters" represents a single '^' character.
 // ^x   = Use this format to represent a "control character" that is not lower. Lower case characters do not have
 //        to be escaped. Currently not used, but reserved for future use!
-// '    = Enclose string with single quotes. A double ' character will not end the string, but represents a
-//        single ' character.
+//
+//
+// ===== Examples when NOT using "Escape Character" =====
+// 0156A9BC; is decoded as:
+//  0x01, 0x56, 0xA9, 0xBC
+//
+// BC56'Hello'; is decoded as:
+//  0xBC, 0x56, H, e, l, l, o
+//
+// A1'Hi^'; is decoded as:
+//  0xA1, H, i, ^
 //
-// Some Examples:
-// 30A8'abc' = 2 bytes (0x30, 0xA8), and 3 characters = 'abc'
-// 50800C'Hello'0A'World' = 3 bytes, 5 characters('Hello'), 1 byte, 5 characters('World')
-// 5588;
+// s6A52p; is decoded as("lower case" control characters NOT supported without "Escape Character"):
+//  0x6A, 0x52
+//
+//
+// ===== Examples when using "Escape Character" '^' =====
+// s6A52p; is decoded as:
+//  ^, s, 0x6A, 0x52, ^, p
+//
+// s50'Hi'p; is decoded as:
+//  ^, s, 0x50, H, i, ^, p
+//
+// 'Hi^'; is decoded as:
+//  H, i, ^, ^
 
 #include "mx_buffer_base.h"
 #include "mx_circular_buffer.h"
 
+
+// Debugging //////////////////////////////////////////////////////////////////
+// To enable debug output from this file, define MX_DEBUG and DEBUG_ENABLE_MX_CMD_BUFFER before
+// including this file.
+//
 //Defines for MXH_DEBUG - debugging for include file
-#define DEBUG_ENABLE_MX_CMD_BUFFER          1
-#define DEBUG_ENABLE_INFO_MX_CMD_BUFFER     0
+#if !defined(DEBUG_ENABLE_MX_CMD_BUFFER)
+    #define DEBUG_ENABLE_MX_CMD_BUFFER          0
+#endif
+#if !defined(DEBUG_ENABLE_INFO_MX_CMD_BUFFER)
+    #define DEBUG_ENABLE_INFO_MX_CMD_BUFFER     0
+#endif
 
 #if !defined(MXH_DEBUG)
-#if (DEBUG_ENABLE_MX_CMD_BUFFER == 1)
-    #define MXH_DEBUG   MX_DEBUG
-    #if (DEBUG_ENABLE_INFO_MX_CMD_BUFFER == 1)
-        #define MXH_DEBUG_INFO   MX_DEBUG
+    #if defined(MX_DEBUG) && (DEBUG_ENABLE_MX_CMD_BUFFER==1)
+        #define MXH_DEBUG MX_DEBUG
+    #else
+        #define MXH_DEBUG(format, args...) ((void)0)
+    #endif
+#endif
+
+#if !defined(MXH_DEBUG_INFO)
+    #if defined(MX_DEBUG) && (DEBUG_ENABLE_MX_CMD_BUFFER==1) && (DEBUG_ENABLE_INFO_MX_CMD_BUFFER==1)
+        #define MXH_DEBUG_INFO MX_DEBUG
     #else
         #define MXH_DEBUG_INFO(format, args...) ((void)0)
     #endif
-#else
-    #define MXH_DEBUG(format, args...) ((void)0)
-    #define MXH_DEBUG_INFO(format, args...) ((void)0)
-#endif  // #if (DEBUG_ENABLE_MX_CMD_BUFFER == 1)
-#endif  // #if !defined(MXH_DEBUG)
+#endif
 
 
 /** Templated Circular buffer class
@@ -644,12 +677,11 @@
     //MxCircularBuffer <uint16_t, Commands, uint16_t> cmdEndsBuf;   //Creates larger code
 };
 
-
 #if defined(MXH_DEBUG)
-#undef MXH_DEBUG
+    #undef MXH_DEBUG
 #endif
 #if defined(MXH_DEBUG_INFO)
-#undef MXH_DEBUG_INFO
+    #undef MXH_DEBUG_INFO
 #endif