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
outDiagnostics/outDiagnostics.cpp
- Committer:
- pspatel321
- Date:
- 2014-11-13
- Revision:
- 30:91af74a299e1
- Child:
- 31:7eaa5e881b56
File content as of revision 30:91af74a299e1:
#include "outDiagnostics.h"
// Macros for working with the string
#define ADD_LINE len+=sprintf(buff+len,"%s\r\n",line); // Add newlines, add it to the working buffer
#define ADD_SPRINTF_LINE padCenter(line,max_charsPerLine-2,temp,' '); len+=sprintf(buff+len,"%s\r\n",line); // Add newlines, add it to the working buffer
#define BOOL(VAR) (VAR)?"ERR":"OK"
// 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
}
// Generates the serial dashboard, uses MODDMA MODSERIAL to speed up printing
void outDiagnostics::thread_serialOut(void const *args) {
const int max_charsPerLine = 81; // Max chars per line
const int max_lines = 35; // 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 -'s
padCenter(line, max_charsPerLine-2, " Penn Electric Racing - REV0 System Management Controller Serial Dashboard ", '-'); ADD_LINE
padCenter(line, max_charsPerLine-2, "-", '-'); ADD_LINE // Generate a line full of -'s
padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE // Generate blank line
padCenter(line, max_charsPerLine-2, " GLV Battery ", '*'); ADD_LINE
sprintf(temp, "Current: %4.3fA Capacity: %4.3fAh", data.glvCurrent, data.glvCapacity); ADD_SPRINTF_LINE
sprintf(temp, "Amphours: %4.3fAh SOC: %5.1f%% Overcurrent: %s", data.glvAmphours, data.glvSOC*100.0, BOOL(data.glvOverCurrent)); ADD_SPRINTF_LINE
char DCDC = data.dcdcStatus;
char dcdcModesStr[5][12] = {"INVALID","POWER-UP","POWER-DOWN","ON","OFF"};
int dcdcMode = 0;
if (DCDC & PowerUp) dcdcMode = 1;
else if (DCDC & PowerDown) dcdcMode = 2;
else if (DCDC & SetOn) dcdcMode = 3;
else if (!(DCDC & SetOn)) dcdcMode = 4;
padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE // Generate blank line
padCenter(line, max_charsPerLine-2, " DC-DC Converter ", '*'); ADD_LINE
sprintf(temp, "Current: %5.3fA Overcurrent: %s SensorFault: %s", data.dcdcCurrent, BOOL(DCDC & OverCurrent), BOOL(DCDC & SensorFault)); ADD_SPRINTF_LINE
sprintf(temp, "Active: %s Mode: %s AIRS: %s StatusByte: 0x%x", (DCDC & ConvOn)?"YES":"NO", dcdcModesStr[dcdcMode], CANdata.airsClosed?"CLOSED":"OPEN", DCDC); ADD_SPRINTF_LINE
sprintf(temp, "StartFault: %s StopFault: %s CritErrors: %s", BOOL(DCDC & FailStart), BOOL(DCDC & FailStop), BOOL(data.dcdcError)); ADD_SPRINTF_LINE
padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE // Generate blank line
padCenter(line, max_charsPerLine-2, " PWM Channels ", '*'); ADD_LINE
sprintf(temp, "Actual: FAN1: %5.1f%% FAN2: %5.1f%% PUMP1: %5.1f%% PUMP2: %5.1f%%", data.dcdcFan1Duty*100.0, data.dcdcFan2Duty*100.0, data.dcdcPump1Duty*100.0, data.dcdcPump2Duty*100.0); ADD_SPRINTF_LINE
sprintf(temp, "Requestd: FAN1: %5.1f%% FAN2: %5.1f%% PUMP1: %5.1f%% PUMP2: %5.1f%%", CANdata.dcdcFan1Duty*100.0, CANdata.dcdcFan2Duty*100.0, CANdata.dcdcPump1Duty*100.0, CANdata.dcdcPump2Duty*100.0); ADD_SPRINTF_LINE
const char IMDstr[7][12] = {"OFF","NORMAL","UNDERVOLT","SPEEDSTART","ERROR","GROUNDFLT","INVALID"};
padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE // Generate blank line
padCenter(line, max_charsPerLine-2, " IMD ", '*'); ADD_LINE
sprintf(temp, "Status: %s Resistance: %7.0fkohm CritError: %s",IMDstr[data.imdStatus], data.imdResistance/1e3, BOOL(data.imdError)); ADD_SPRINTF_LINE
char AMSerr = data.AMSlatchError;
char IMDerr = data.IMDlatchError;
padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE // Generate blank line
padCenter(line, max_charsPerLine-2, " Latch Circuits ", '*'); ADD_LINE
sprintf(temp, "AMS: OK: %s Latch: %s SoftFault: %s HardFault: %s", (AMSerr & 1)?"LOW":"HIGH", (AMSerr & 2)?"OPEN":"OK", BOOL(AMSerr & 4), BOOL(AMSerr & 8)); ADD_SPRINTF_LINE
sprintf(temp, "IMD: OK: %s Latch: %s SoftFault: %s HardFault: %s", (IMDerr & 1)?"LOW":"HIGH", (IMDerr & 2)?"OPEN":"OK", BOOL(IMDerr & 4), BOOL(IMDerr & 8)); ADD_SPRINTF_LINE
char switches = data.switchState;
const char switchNames[12][26] = {"FUSE","AMS LATCH","IMD LATCH","PCM RELAY","BRAKE PLAUSIBILITY RELAY","LEFT E-STOP","INERTIA SWITCH","BRAKE OVER-TRAVEL SWITCH","COCKPIT E-STOP","RIGHT E-STOP","HVD","TSMS"};
padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE // Generate blank line
padCenter(line, max_charsPerLine-2, " Shutdown Switches ", '*'); ADD_LINE
if (switches == 0) sprintf(temp, "All switches are CLOSED.");
else sprintf(temp, "%s is OPEN.", switchNames[switches-1]);
ADD_SPRINTF_LINE
padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE // Generate blank line
padCenter(line, max_charsPerLine-2, " Telemetry ", '*'); ADD_LINE
sprintf(temp, "Channel 1: MessagesIn: %d MessagesOut: %d", data.xbee1MessagesIn, data.xbee1MessagesOut); ADD_SPRINTF_LINE
sprintf(temp, "Channel 2: MessagesIn: %d MessagesOut: %d", data.xbee2MessagesIn, data.xbee2MessagesOut); ADD_SPRINTF_LINE
padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE // Generate blank line
padCenter(line, max_charsPerLine-2, " Miscellaneous ", '*'); ADD_LINE
sprintf(temp, "Temp: %5.1fC OverTemp: %s canFault: %s WatchdogReset: %s ErrorFrame: 0x%x", data.internalTemp, BOOL(data.internalOverTemp), BOOL(data.canFault), BOOL(data.watchdogReset), data.errorFrame); ADD_SPRINTF_LINE
// Write it all at once to output tx buffer
for (int i = 0; i < strlen(buff); i++) {
pc.putc(buff[i]);
}
Thread::wait(100);
}
}
void outDiagnostics::thread_canOut(void const *args) {
while(1) {
CANMessage msg;
Thread::wait(100);
}
}
