Internal_Datalogger but with USB support removed (for MAX40108 Demo board), proof of concept that MAX32625 can be used successfully with VDDB(USB) left unpowered, as long as the USB library is not used.

Dependencies:   max32625pico CmdLine

Revision:
40:330b28116178
Parent:
39:4d285e961435
Child:
41:13a6a097502c
--- a/DataLogger_Internal.cpp	Wed May 05 12:29:39 2021 -0700
+++ b/DataLogger_Internal.cpp	Fri May 07 01:54:54 2021 -0700
@@ -2063,7 +2063,6 @@
 int g_timer_interval_msec = 500; // trigger_Timer
 int g_timer_interval_count = 10; // trigger_Timer
 int g_timer_interval_counter = 0; // trigger_Timer
-// TODO: USE_DATALOGGER_SLEEP -- support sleep modes in Datalogger_Trigger
 //
 // TODO: configuration for trigger_PlatformDigitalInput
 //
@@ -5315,7 +5314,7 @@
 //
 #if 1 // USE_AUX_SERIAL_CMD_FORWARDING && (HAS_AUX_SERIAL || HAS_DAPLINK_SERIAL)
         // TODO WIP Command forwarding to Auxiliary serial port TX/RX #257 -- main_menu_onEOLcommandParser
-        case '>':
+        case '>': case '<': // > send and receive; < receive without sending anything
         {
             // prefer cmdLine_AUXserial if available, else cmdLine_DAPLINKserial; else we don't have this feature
 # if HAS_AUX_SERIAL
@@ -5330,6 +5329,15 @@
 #warning "USE_AUX_SERIAL_CMD_FORWARDING should not be enabled without HAS_AUX_SERIAL or HAS_DAPLINK_SERIAL"
 # endif // HAS_AUX_SERIAL HAS_DAPLINK_SERIAL
             //
+            int g_auxSerialCom_outgoing_string_cr = 1; // option to send CR after outgoing_string
+            int g_auxSerialCom_outgoing_string_lf = 0; // option to send LF after outgoing_string (breaks remote datalogger LR!)
+            int g_auxSerialCom_rx_string_verbose_crlf = 0; // option to display \r\n as "\\r\\n" in rx_string_buf
+            int g_auxSerialCom_rx_string_verbose_ctrl = 1; // option to display control codes as \xXX
+            const char* g_auxSerialCom_display_tx_prefix = "\r\n->|"; // "\r\n >";
+            const char* g_auxSerialCom_display_rx_prefix = "\r\n<-|"; // "\r\n< ";
+            //
+            bool need_g_auxSerialCom_display_rx_prefix = 1; // temp
+            //
             // >> suppress key=value parsing
             bool suppress_parsing = (cmdLine[1] == '>');
             if (suppress_parsing == false) {
@@ -5394,21 +5402,31 @@
                 }
             }
             // Command forwarding to AUX serial TX/RX cmdLine_AuxSerial #257 -- send outgoing_string
-            char* outgoing_string = (char*)cmdLine.str();
-            // > use key=value parsing
-            // >> suppress key=value parsing
-            if (suppress_parsing) {
-                cmdLine.serial().printf("\r\n  suppress_parsing outgoing_string=\"%s\"", outgoing_string);
-                outgoing_string++; // skip the first '>'
-                outgoing_string++; // skip the second '>'
-            } else {
-                // TODO: after parsing, key=value pairs should be deleted, but outgoing_string=">xyzzy abc=def"
-                cmdLine.serial().printf("\r\n  after parsing, outgoing_string=\"%s\"", outgoing_string);
-                outgoing_string++; // skip the first '>'
-            }
+            char* outgoing_string = "";
+            if (cmdLine[0] == '>') {
+                outgoing_string = (char*)cmdLine.str();
+                // > use key=value parsing
+                // >> suppress key=value parsing
+                if (suppress_parsing) {
+                    cmdLine.serial().printf("\r\n  suppress_parsing outgoing_string=\"%s\"", outgoing_string);
+                    outgoing_string++; // skip the first '>'
+                    outgoing_string++; // skip the second '>'
+                } else {
+                    // TODO: after parsing, key=value pairs should be deleted, but outgoing_string=">xyzzy abc=def"
+                    cmdLine.serial().printf("\r\n  after parsing, outgoing_string=\"%s\"", outgoing_string);
+                    outgoing_string++; // skip the first '>'
+                }
+            } // if (cmdLine[0] == '>')
             static char rx_string_buf[RX_STRING_BUF_SIZE];
             unsigned int rx_string_length = 0;
-            cmdLine.serial().printf("\r\n  >%s\r\n  <", outgoing_string);
+            //cmdLine.serial().printf("\r\n  >%s\r\n  <", outgoing_string);
+            //char* g_auxSerialCom_display_tx_prefix = "\r\n >";
+            //char* g_auxSerialCom_display_rx_prefix = "\r\n< ";
+            cmdLine.serial().printf("%s%s%s", 
+                    g_auxSerialCom_display_tx_prefix, // "\r\n  >"
+                    outgoing_string,
+                    g_auxSerialCom_display_rx_prefix  // "\r\n  <"
+                );
             rx_string_buf[0] = '\0';
             rx_string_length = 0;
             //
@@ -5425,8 +5443,15 @@
             //~ cmdLine_AuxSerial.serial().printf("\r\n*** TODO forward %s ***\r\n", outgoing_string);
             //
             // TODO: send whole string or send character-by-character?
-            cmdLine_AuxSerial.serial().printf("%s", outgoing_string);
-            cmdLine_AuxSerial.serial().printf("\r\n");
+            if (cmdLine[0] == '>') {
+                cmdLine_AuxSerial.serial().printf("%s", outgoing_string);
+                //
+                // TODO: send CRLF or just send CR line end?
+                if (g_auxSerialCom_outgoing_string_cr) { cmdLine_AuxSerial.serial().printf("\r"); }
+                if (g_auxSerialCom_outgoing_string_lf) { cmdLine_AuxSerial.serial().printf("\n"); }
+                // cmdLine_AuxSerial.serial().printf("\r\n");
+            } // if (cmdLine[0] == '>')
+            //
             g_auxSerialCom_Timer.start();
             g_auxSerialCom_Timer_begin_message_ms = g_auxSerialCom_Timer.read_ms(); // start of message
             g_auxSerialCom_Timer_begin_rx_idle_ms = g_auxSerialCom_Timer.read_ms(); // recent RX character timestamp
@@ -5448,7 +5473,36 @@
                     char ch = AuxSerial.getc();
                     rx_string_buf[rx_string_length++] = ch;
                     rx_string_buf[rx_string_length] = '\0'; // null terminate buffer
-                    cmdLine.serial().printf("%s", &(rx_string_buf[rx_string_length-1]) ); // immediate character echo
+                    //
+                    #if 1
+                    // immediate character echo
+                    for (char* cp = &(rx_string_buf[rx_string_length-1]); *cp != '\0'; cp++)
+                    {
+                        //cmdLine.serial().printf("\r\n  <%s\r\n", rx_string_buf);
+                        if (need_g_auxSerialCom_display_rx_prefix) {
+                            cmdLine.serial().printf(g_auxSerialCom_display_rx_prefix); // "\r\n< " g_auxSerialCom_rx_string display prefix
+                            need_g_auxSerialCom_display_rx_prefix = 0;
+                        }
+                        if ((*cp) == '\r') {
+                            if (g_auxSerialCom_rx_string_verbose_crlf) { cmdLine.serial().printf("\\r"); }
+                            // if (*(cp+1) != '\n') { need_g_auxSerialCom_display_rx_prefix = 1; }
+                        } else if ((*cp) == '\n') {
+                            if (g_auxSerialCom_rx_string_verbose_crlf) { cmdLine.serial().printf("\\n"); }
+                            need_g_auxSerialCom_display_rx_prefix = 1;
+                            if (*(cp-1) != '\r') { need_g_auxSerialCom_display_rx_prefix = 1; }
+                        } else if ((*cp) < 0x20) {
+                            if (g_auxSerialCom_rx_string_verbose_ctrl) { cmdLine.serial().printf("\\x%2.2x", *cp); }
+                        } else if ((*cp) >= 0x7f) {
+                            if (g_auxSerialCom_rx_string_verbose_ctrl) { cmdLine.serial().printf("\\x%2.2x", *cp); }
+                        } else {
+                            cmdLine.serial().printf("%c", *cp);
+                        }
+                    }
+                    #else
+                    // immediate character echo
+                    cmdLine.serial().printf("%s", &(rx_string_buf[rx_string_length-1]) );
+                    #endif
+                    //
                     if (g_auxSerialCom_rx_eot != aux_serial_cmd_forwarding_rx_eot_not_used) {
                         if (ch == g_auxSerialCom_rx_eot) {
                             cmdLine.serial().printf("\r\n  rx_eot %d", g_auxSerialCom_rx_eot);
@@ -5457,11 +5511,41 @@
                     }
                 }
             } // end while (rx_string_length < (RX_STRING_BUF_SIZE-1))
-            #if 1
+            #if 0
             // print summary. is this needed? we already print aux rx as it is received.
             rx_string_buf[rx_string_length] = '\0'; // null terminate buffer
+            # if 1 // support multi-line rx_string_buf response 
+            if (cmdLine[0] == '>') {
+                cmdLine.serial().printf("%s%s", g_auxSerialCom_display_tx_prefix, outgoing_string);
+            } // if (cmdLine[0] == '>')
+            // cmdLine.serial().printf("\r\n  <"); // prefix
+            need_g_auxSerialCom_display_rx_prefix = 1;
+            for (char* cp = rx_string_buf; *cp != '\0'; cp++)
+            {
+                //cmdLine.serial().printf("\r\n  <%s\r\n", rx_string_buf);
+                if (need_g_auxSerialCom_display_rx_prefix) {
+                    cmdLine.serial().printf(g_auxSerialCom_display_rx_prefix); // "\r\n< " g_auxSerialCom_rx_string display prefix
+                    need_g_auxSerialCom_display_rx_prefix = 0;
+                }
+                if ((*cp) == '\r') {
+                    if (g_auxSerialCom_rx_string_verbose_crlf) { cmdLine.serial().printf("\\r"); }
+                    if (*(cp+1) != '\n') { need_g_auxSerialCom_display_rx_prefix = 1; }
+                } else if ((*cp) == '\n') {
+                    if (g_auxSerialCom_rx_string_verbose_crlf) { cmdLine.serial().printf("\\n"); }
+                    need_g_auxSerialCom_display_rx_prefix = 1;
+                } else if ((*cp) < 0x20) {
+                    if (g_auxSerialCom_rx_string_verbose_ctrl) { cmdLine.serial().printf("\\x%2.2x", *cp); }
+                } else if ((*cp) >= 0x7f) {
+                    if (g_auxSerialCom_rx_string_verbose_ctrl) { cmdLine.serial().printf("\\x%2.2x", *cp); }
+                } else {
+                    cmdLine.serial().printf("%c", *cp);
+                }
+            }
+            cmdLine.serial().printf("\r\n");
+            # else
             cmdLine.serial().printf("\r\n  >%s", outgoing_string);
             cmdLine.serial().printf("\r\n  <%s\r\n", rx_string_buf);
+            # endif
             #endif
             //
         }
@@ -5728,7 +5812,8 @@
                                 case condition_if_AINn_ne_threshold:
                                     cmdLine.serial().printf(" if=%d", Datalogger_action_table[i].condition);
                                     cmdLine.serial().printf(" ch=%d", Datalogger_action_table[i].condition_channel);
-                                    cmdLine.serial().printf(" x=%f", Datalogger_action_table[i].condition_threshold);
+                                    // our voltage measurement is around 1mV at best
+                                    cmdLine.serial().printf(" x=%1.4f", Datalogger_action_table[i].condition_threshold);
                                     break;
                             }
                             cmdLine.serial().printf(" -- ");
@@ -5746,19 +5831,16 @@
                                     cmdLine.serial().printf(" D%d", Datalogger_action_table[i].digitalOutPin);
                                     break;
                                 case action_button:  // pin = button index 1, 2, 3
-                                    cmdLine.serial().printf("button");
-                                    cmdLine.serial().printf(" %d", Datalogger_action_table[i].digitalOutPin);
+                                    cmdLine.serial().printf("button %%B%d!", Datalogger_action_table[i].digitalOutPin);
                                     break;
                                 case action_trigger_Halt:
-                                    cmdLine.serial().printf("trigger_Halt");
+                                    cmdLine.serial().printf("Halt");
                                     break;
                                 case action_trigger_FreeRun:
-                                    cmdLine.serial().printf("trigger_FreeRun");
+                                    cmdLine.serial().printf("LR");
                                     break;
                                 case action_trigger_Timer:
-                                    cmdLine.serial().printf("trigger_Timer");
-                                    // print configuration for trigger_Timer
-                                    cmdLine.serial().printf("(%d x %dmsec)", g_timer_interval_count, g_timer_interval_msec);
+                                    cmdLine.serial().printf("LT count=%d base=%dms sleep=%d", g_timer_interval_count, g_timer_interval_msec, g_timer_sleepmode);
                                     break;
                                 case action_trigger_PlatformDigitalInput:
                                     cmdLine.serial().printf("trigger_PlatformDigitalInput");
@@ -5778,40 +5860,40 @@
                                     cmdLine.serial().printf(" always");
                                     break;
                                 case condition_if_An_gt_threshold:
-                                    cmdLine.serial().printf(" if A%d > %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if A%d > %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_An_lt_threshold:
-                                    cmdLine.serial().printf(" if A%d < %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if A%d < %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_An_eq_threshold:
-                                    cmdLine.serial().printf(" if A%d == %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if A%d == %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_An_ge_threshold:
-                                    cmdLine.serial().printf(" if A%d >= %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if A%d >= %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_An_le_threshold:
-                                    cmdLine.serial().printf(" if A%d <= %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if A%d <= %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_An_ne_threshold:
-                                    cmdLine.serial().printf(" if A%d != %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if A%d != %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_AINn_gt_threshold:
-                                    cmdLine.serial().printf(" if AIN%d > %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if AIN%d > %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_AINn_lt_threshold:
-                                    cmdLine.serial().printf(" if AIN%d < %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if AIN%d < %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_AINn_eq_threshold:
-                                    cmdLine.serial().printf(" if AIN%d == %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if AIN%d == %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_AINn_ge_threshold:
-                                    cmdLine.serial().printf(" if AIN%d >= %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if AIN%d >= %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_AINn_le_threshold:
-                                    cmdLine.serial().printf(" if AIN%d <= %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if AIN%d <= %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                                 case condition_if_AINn_ne_threshold:
-                                    cmdLine.serial().printf(" if AIN%d != %f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
+                                    cmdLine.serial().printf(" if AIN%d != %1.2f", Datalogger_action_table[i].condition_channel, Datalogger_action_table[i].condition_threshold);
                                     break;
                             } // switch(Datalogger_action_table[i].condition)
                         } // for ...Datalogger_action_table_row_count // Print the contents of Datalogger_action_table