Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
SerialDiagnostics/SerialDiagnostics.cpp@19:3a817d2cef11, 2014-10-25 (annotated)
- Committer:
- martydd3
- Date:
- Sat Oct 25 16:48:09 2014 +0000
- Revision:
- 19:3a817d2cef11
- Child:
- 20:3dfa7e9461a0
Testing from basics;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| martydd3 | 19:3a817d2cef11 | 1 | #include "SerialDiagnostics.h" |
| martydd3 | 19:3a817d2cef11 | 2 | |
| martydd3 | 19:3a817d2cef11 | 3 | // Macros for working with the string |
| martydd3 | 19:3a817d2cef11 | 4 | // Add newlines, add it to the working buffer |
| martydd3 | 19:3a817d2cef11 | 5 | #define ADD_LINE len+=sprintf(buff+len,"%s\r\n",line); |
| martydd3 | 19:3a817d2cef11 | 6 | #define ADD_SPRINTF_LINE padCenter(line,max_charsPerLine-2,temp,' '); len+=sprintf(buff+len,"%s\r\n",line); |
| martydd3 | 19:3a817d2cef11 | 7 | |
| martydd3 | 19:3a817d2cef11 | 8 | // Print to a string buffer, pad to maxLen chars and center it with char pad, str must be null terminated! |
| martydd3 | 19:3a817d2cef11 | 9 | void padCenter(char *buff, int LineLen, char *str, char pad) { |
| martydd3 | 19:3a817d2cef11 | 10 | int len = strlen(str); |
| martydd3 | 19:3a817d2cef11 | 11 | int padL = (LineLen-len)/2; // -1 to save room for the null terminator |
| martydd3 | 19:3a817d2cef11 | 12 | for (int i=0; i<padL; i++) buff[i] = pad; // Fill in the left padding chars |
| martydd3 | 19:3a817d2cef11 | 13 | strcpy(buff+padL, str); |
| martydd3 | 19:3a817d2cef11 | 14 | for (int i = padL+len; i<LineLen; i++) buff[i] = pad; // Fill remaining with padding chars |
| martydd3 | 19:3a817d2cef11 | 15 | buff[LineLen-1] = '\0'; // Add null terminator |
| martydd3 | 19:3a817d2cef11 | 16 | } |
| martydd3 | 19:3a817d2cef11 | 17 | |
| martydd3 | 19:3a817d2cef11 | 18 | void SerialDiagnostics::thread_serialOut(void const* args){ |
| martydd3 | 19:3a817d2cef11 | 19 | const int max_charsPerLine = 81; // Max chars per line |
| martydd3 | 19:3a817d2cef11 | 20 | const int max_lines = 30; // Max lines that the layout prints out |
| martydd3 | 19:3a817d2cef11 | 21 | pc.printf("\033[2J"); // Clear the screen to get rid of reset message |
| martydd3 | 19:3a817d2cef11 | 22 | |
| martydd3 | 19:3a817d2cef11 | 23 | char buff[max_charsPerLine*max_lines]; // Giant string to store the printout |
| martydd3 | 19:3a817d2cef11 | 24 | char line[max_charsPerLine]; // String buffer to work with one line at a time |
| martydd3 | 19:3a817d2cef11 | 25 | char temp[max_charsPerLine]; // String buffer to sprintf into |
| martydd3 | 19:3a817d2cef11 | 26 | |
| martydd3 | 19:3a817d2cef11 | 27 | while(1){ |
| martydd3 | 19:3a817d2cef11 | 28 | |
| martydd3 | 19:3a817d2cef11 | 29 | int len = 0; |
| martydd3 | 19:3a817d2cef11 | 30 | len += sprintf(buff+len, "\033[0;0H"); // Home the cursor |
| martydd3 | 19:3a817d2cef11 | 31 | padCenter(line, max_charsPerLine-2, "-", '-'); ADD_LINE // Generate a line full of 80 -'s |
| martydd3 | 19:3a817d2cef11 | 32 | padCenter(line, max_charsPerLine-2, " Penn Electric Racing - REV0 System Management Module Serial Dashboard ", '-'); ADD_LINE |
| martydd3 | 19:3a817d2cef11 | 33 | padCenter(line, max_charsPerLine-2, "-", '-'); ADD_LINE // Generate a line full of 80 -'s |
| martydd3 | 19:3a817d2cef11 | 34 | |
| martydd3 | 19:3a817d2cef11 | 35 | // Write it all at once to output tx buffer |
| martydd3 | 19:3a817d2cef11 | 36 | for (int i = 0; i < strlen(buff); i++) { |
| martydd3 | 19:3a817d2cef11 | 37 | pc.putc(buff[i]); |
| martydd3 | 19:3a817d2cef11 | 38 | } |
| martydd3 | 19:3a817d2cef11 | 39 | |
| martydd3 | 19:3a817d2cef11 | 40 | Thread::wait(100); |
| martydd3 | 19:3a817d2cef11 | 41 | } |
| martydd3 | 19:3a817d2cef11 | 42 | } |
