Penn Electric Racing / Mbed 2 deprecated SystemManagement

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Revision:
19:3a817d2cef11
Child:
20:3dfa7e9461a0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SerialDiagnostics/SerialDiagnostics.cpp	Sat Oct 25 16:48:09 2014 +0000
@@ -0,0 +1,42 @@
+#include "SerialDiagnostics.h"
+
+// Macros for working with the string
+// Add newlines, add it to the working buffer 
+#define ADD_LINE                  len+=sprintf(buff+len,"%s\r\n",line);                                                    
+#define ADD_SPRINTF_LINE          padCenter(line,max_charsPerLine-2,temp,' '); len+=sprintf(buff+len,"%s\r\n",line);
+
+// Print to a string buffer, pad to maxLen chars and center it with char pad, str must be null terminated!
+void padCenter(char *buff, int LineLen, char *str, char pad) {
+    int len = strlen(str);
+    int padL = (LineLen-len)/2;                              // -1 to save room for the null terminator
+    for (int i=0; i<padL; i++) buff[i] = pad;                // Fill in the left padding chars
+    strcpy(buff+padL, str);
+    for (int i = padL+len; i<LineLen; i++) buff[i] = pad;    // Fill remaining with padding chars
+    buff[LineLen-1] = '\0';                                  // Add null terminator
+}
+
+void SerialDiagnostics::thread_serialOut(void const* args){
+    const int max_charsPerLine = 81;                 // Max chars per line
+    const int max_lines = 30;                        // Max lines that the layout prints out
+    pc.printf("\033[2J");                            // Clear the screen to get rid of reset message
+ 
+    char buff[max_charsPerLine*max_lines];           // Giant string to store the printout
+    char line[max_charsPerLine];                     // String buffer to work with one line at a time
+    char temp[max_charsPerLine];                     // String buffer to sprintf into
+    
+    while(1){
+        
+        int len = 0;
+        len += sprintf(buff+len, "\033[0;0H");                      // Home the cursor
+        padCenter(line, max_charsPerLine-2, "-", '-'); ADD_LINE     // Generate a line full of 80 -'s      
+        padCenter(line, max_charsPerLine-2, " Penn Electric Racing - REV0 System Management Module Serial Dashboard ", '-'); ADD_LINE
+        padCenter(line, max_charsPerLine-2, "-", '-'); ADD_LINE     // Generate a line full of 80 -'s 
+        
+        // Write it all at once to output tx buffer
+        for (int i = 0; i < strlen(buff); i++) {
+            pc.putc(buff[i]);   
+        }
+        
+        Thread::wait(100);
+    }
+}