@@ -105,7 +105,6 @@ void setup()
105105 // Initialize LED, interrupt input, and serial port.
106106 // LED defaults to off:
107107 initHardware ();
108-
109108#ifdef ENABLE_NVRAM_STORAGE
110109 // Load previously-set logging parameters from nvram:
111110 initLoggingParams ();
@@ -126,6 +125,10 @@ void setup()
126125 // Get the next, available log file name
127126 logFileName = nextLogFile ();
128127 }
128+
129+ // For production testing only
130+ // To catch a "$" and enter testing mode
131+ Serial1.begin (9600 );
129132}
130133
131134void loop ()
@@ -152,6 +155,14 @@ void loop()
152155 // If logging (to either UART and SD card) is enabled
153156 if ( enableSerialLogging || enableSDLogging)
154157 logIMUData (); // Log new data
158+
159+ // Check for production mode testing message, "$"
160+ // This will be sent to board from testbed, and should be heard on hadware serial port Serial1
161+ if ( Serial1.available () )
162+ {
163+ if ( Serial1.read () == ' $' ) production_testing ();
164+ }
165+
155166}
156167
157168void logIMUData (void )
@@ -548,4 +559,135 @@ void parseSerialInput(char c)
548559 }
549560 }
550561#endif
562+
563+ // All the code and functions below are used for production, and can be removed if desired while still maintaining all product functionality.
564+
565+ // PRODUCTION TESTING VARIABLES
566+ int net_1_pins[] = {11 ,A0,A2,A4,9 };
567+ int net_2_pins[] = {12 ,10 ,A1,A3,8 };
568+ char input;
569+ int failures = 0 ;
570+
571+ // PRODUCTION TESTING FUNCTION
572+ void production_testing (void )
573+ {
574+ digitalWrite (HW_LED_PIN, HIGH); // Turn on Blue STAT LED for visual inspection
575+
576+ while (1 ) // stay here, until a hard reset happens
577+ {
578+ // check for new serial input:
579+ if ( Serial1.available () )
580+ {
581+ // If new input is available on serial1 port
582+ // These are connected to the RX/TX on Serial2 on the testbed mega2560.
583+ input = Serial1.read (); // grab it
584+ switch (input)
585+ {
586+ case ' $' :
587+ failures = 0 ; // reset
588+ Serial1.print (" h" ); // "h" for "hello"
589+ break ;
590+ case ' 1' :
591+ if (net_1_test () == true ) Serial1.print (" a" );
592+ else Serial1.print (" F" );
593+ break ;
594+ case ' 2' :
595+ if (net_2_test () == true )
596+ {
597+ Serial1.print (" b" );
598+ if (uSD_ping () == true ) Serial1.print (" c" );
599+ else Serial1.print (" F" );
600+ }
601+ else Serial1.print (" F" );
602+ break ;
603+ }
604+ }
605+ }
606+ }
607+
608+
609+ // PRODUCTION TESTING FUNCTION
610+ // Test that the SD card is there and remove log file
611+ // I use the result of the SD.remove() function to know if it deleted the file properly
612+ // Note, this requires that the 9dof wake up and start logging to a new file (even just for a microsecond)
613+ bool uSD_ping (void )
614+ {
615+ // Serial1.print("nextLogFile: ");
616+ // Serial1.print( nextLogFile() );
617+
618+ // Serial1.print("logFileName: ");
619+ // Serial1.print( String(logFileName) );
620+
621+ bool remove_log_file_result = SD.remove (logFileName);
622+ // Serial1.print("r: ");
623+ // Serial1.print( remove_log_file_result , BIN);
624+
625+ if (remove_log_file_result == true ) return true ;
626+ else
627+ {
628+ return false ;
629+ }
630+ }
631+
632+ // PRODUCTION TESTING FUNCTION
633+ bool net_1_test ()
634+ {
635+ set_nets_all_inputs ();
636+ // check all net 1 is low
637+ for (int i = 0 ; i <= 4 ; i++)
638+ {
639+ bool result;
640+ result = digitalRead (net_1_pins[i]);
641+ // Serial1.print(result);
642+ if (result == true ) failures++;
643+ }
644+ Serial1.println (" " );
645+ // check all net 2 is high
646+ for (int i = 0 ; i <= 4 ; i++)
647+ {
648+ bool result;
649+ result = digitalRead (net_2_pins[i]);
650+ // Serial1.print(result);
651+ if (result == false ) failures++;
652+ }
653+ Serial1.println (" " );
654+ if (failures == 0 ) return true ;
655+ else return false ;
656+ }
657+
658+ // PRODUCTION TESTING FUNCTION
659+ bool net_2_test ()
660+ {
661+ set_nets_all_inputs ();
662+ // check all net 1 is high
663+ for (int i = 0 ; i <= 4 ; i++)
664+ {
665+ bool result;
666+ result = digitalRead (net_1_pins[i]);
667+ // Serial1.print(result);
668+ if (result == false ) failures++;
669+ }
670+ // Serial1.println(" ");
671+ // check all net 2 is low
672+ for (int i = 0 ; i <= 4 ; i++)
673+ {
674+ bool result;
675+ result = digitalRead (net_2_pins[i]);
676+ // Serial1.print(result);
677+ if (result == true ) failures++;
678+ }
679+ // Serial1.println(" ");
680+ if (failures == 0 ) return true ;
681+ else return false ;
682+ }
683+
684+ // PRODUCTION TESTING FUNCTION
685+ void set_nets_all_inputs ()
686+ {
687+ for (int i = 0 ; i <= 4 ; i++)
688+ {
689+ pinMode (net_1_pins[i], INPUT);
690+ pinMode (net_2_pins[i], INPUT);
691+ }
692+ }
551693
0 commit comments