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
Diff: outDiagnostics/outDiagnostics.cpp
- Revision:
- 31:7eaa5e881b56
- Parent:
- 30:91af74a299e1
- Child:
- 33:6bc82b6b62e5
diff -r 91af74a299e1 -r 7eaa5e881b56 outDiagnostics/outDiagnostics.cpp
--- a/outDiagnostics/outDiagnostics.cpp Thu Nov 13 10:53:10 2014 +0000
+++ b/outDiagnostics/outDiagnostics.cpp Fri Nov 14 06:05:59 2014 +0000
@@ -1,4 +1,5 @@
#include "outDiagnostics.h"
+#include "CAN_TxIDs.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
@@ -69,17 +70,17 @@
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, " ", ' '); 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, " ", ' '); 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
@@ -88,14 +89,89 @@
for (int i = 0; i < strlen(buff); i++) {
pc.putc(buff[i]);
}
+ // Erase screen every 5sec to remove glitches
+ static int count=0;
+ if (count%50==0) {
+ pc.printf("\033[2J"); // Clear the screen
+ }
+ count++;
Thread::wait(100);
}
}
+template <typename T>
+void sendCAN(int ID, T dat) {
+ CANMessage msg;
+ msg.id = ID;
+ msg.len = sizeof(T);
+ memcpy(&msg.data[0], (void*)&dat, sizeof(T));
+ if (!can.txWrite(msg)) data.canFault = true;
+ xbee.receive(msg);
+}
+
void outDiagnostics::thread_canOut(void const *args) {
+
while(1) {
CANMessage msg;
+ // Sys Mgmt Error Frame
+ sendCAN(SYS_ERROR_ID, data.errorFrame);
+
+ // Xbee1 Counter
+ msg.id = SYS_XBEE1_ID;
+ msg.len = 2*sizeof(int);
+ memcpy(&msg.data[0], (void*)&data.xbee1MessagesIn, sizeof(int));
+ memcpy(&msg.data[4], (void*)&data.xbee1MessagesOut, sizeof(int));
+ if (!can.txWrite(msg)) data.canFault = true;
+ xbee.receive(msg);
+
+ // Xbee2 Counter
+ msg.id = SYS_XBEE2_ID;
+ msg.len = 2*sizeof(int);
+ memcpy(&msg.data[0], (void*)&data.xbee2MessagesIn, sizeof(int));
+ memcpy(&msg.data[4], (void*)&data.xbee2MessagesOut, sizeof(int));
+ if (!can.txWrite(msg)) data.canFault = true;
+ xbee.receive(msg);
+
+ // Internal temperature
+ sendCAN(SYS_TEMP_ID, data.internalTemp);
+
+ // GLV Battery
+ sendCAN(SYS_GLV_CURRENT_ID, data.glvCurrent);
+ sendCAN(SYS_GLV_CAPACITY_ID, data.glvCapacity);
+ sendCAN(SYS_GLV_AH_ID, data.glvAmphours);
+ sendCAN(SYS_GLV_SOC_ID, data.glvSOC);
+
+ // DC-DC Converter
+ sendCAN(SYS_DCDC_CURRENT_ID, data.dcdcCurrent);
+ sendCAN(SYS_DCDC_STATUS_ID, data.dcdcStatus);
+
+ // PWM Channels
+ msg.id = SYS_PWM_FAN_ID;
+ msg.len = 2*sizeof(float);
+ memcpy(&msg.data[0], (void*)&data.dcdcFan1Duty, sizeof(float));
+ memcpy(&msg.data[4], (void*)&data.dcdcFan2Duty, sizeof(float));
+ if (!can.txWrite(msg)) data.canFault = true;
+ xbee.receive(msg);
+
+ msg.id = SYS_PWM_PUMP_ID;
+ msg.len = 2*sizeof(float);
+ memcpy(&msg.data[0], (void*)&data.dcdcPump1Duty, sizeof(float));
+ memcpy(&msg.data[4], (void*)&data.dcdcPump2Duty, sizeof(float));
+ if (!can.txWrite(msg)) data.canFault = true;
+ xbee.receive(msg);
+
+ // IMD
+ sendCAN(SYS_IMD_STATUS_ID, data.imdStatus);
+ sendCAN(SYS_IMD_RESIST_ID, data.imdResistance);
+
+ // Latches
+ sendCAN(SYS_IMD_LATCH_ID, data.IMDlatchError);
+ sendCAN(SYS_AMS_LATCH_ID, data.AMSlatchError);
+
+ // Shutdown Switches
+ sendCAN(SYS_SWITCHES_ID, data.switchState);
+
Thread::wait(100);
}
}
\ No newline at end of file
