System Management code

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Files at this revision

API Documentation at this revision

Comitter:
martydd3
Date:
Fri Nov 07 01:26:13 2014 +0000
Parent:
19:3a817d2cef11
Child:
21:2e83002d452d
Commit message:
Moved code over from another testing project

Changed in this revision

IOobjects.cpp Show annotated file Show diff for this revision Revisions of this file
IOobjects.h Show annotated file Show diff for this revision Revisions of this file
SerialDiagnostics/SerialDiagnostics.cpp Show annotated file Show diff for this revision Revisions of this file
SerialDiagnostics/SerialDiagnostics.h Show diff for this revision Revisions of this file
SysMngmt.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/IOobjects.cpp	Sat Oct 25 16:48:09 2014 +0000
+++ b/IOobjects.cpp	Fri Nov 07 01:26:13 2014 +0000
@@ -4,4 +4,6 @@
 MODSERIAL pc(USBTX, USBRX, 4096, 256);                  // Software buffered serial, 4kB buffer
 CANBuffer can(CAN2, MEDIUM, p0_6);                      // Software buffered CAN
 Watchdog wdt(0.11);                                     // Watchdog timer set to 110ms
-DigitalOut debugLED(LED4);
\ No newline at end of file
+PollSwitch pollSwitch;
+IMD imd;
+CoulombCounter coulombCounter(10, 0, 0);
\ No newline at end of file
--- a/IOobjects.h	Sat Oct 25 16:48:09 2014 +0000
+++ b/IOobjects.h	Fri Nov 07 01:26:13 2014 +0000
@@ -6,9 +6,15 @@
 #include "CANBuffer.h"
 #include "Watchdog.h"
 
+#include "PollSwitch.h"
+#include "IMD.h"
+#include "CoulombCounter.h"
+
 extern CANBuffer can;
 extern MODSERIAL pc;
 extern Watchdog wdt;
-extern DigitalOut debugLED;
+extern PollSwitch pollSwitch;
+extern IMD imd;
+extern CoulombCounter coulombCounter;
  
 #endif
\ No newline at end of file
--- a/SerialDiagnostics/SerialDiagnostics.cpp	Sat Oct 25 16:48:09 2014 +0000
+++ b/SerialDiagnostics/SerialDiagnostics.cpp	Fri Nov 07 01:26:13 2014 +0000
@@ -16,6 +16,7 @@
 }
 
 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
@@ -32,6 +33,56 @@
         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 
         
+        
+    // Polling Switches -----------------------------------------------------------------------------------------------//
+    
+        padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE     // Generate blank line 
+        padCenter(line, max_charsPerLine-2, " Poll Switches ", '*'); ADD_LINE
+        
+        char binary_out[12];
+        uint16_t poll = pollSwitch.poll();
+        
+        for(int i = 0; i < 10; i++){
+            binary_out[i] = (poll & 0x1) ? '1' : '0';
+            poll = poll >> 1;
+        }
+        binary_out[11] = '\0';
+        
+        sprintf(temp, "Switch Bits: %s", binary_out); ADD_SPRINTF_LINE
+        
+    // Reading IMD status and resistance -------------------------------------------------------------------------------//
+    
+        padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE     // Generate blank line 
+        padCenter(line, max_charsPerLine-2, " IMD ", '*'); ADD_LINE
+        
+        char status = imd.status();
+        
+        switch(status){
+        case OFF:
+            sprintf(temp, "IMD Status: OFF"); ADD_SPRINTF_LINE break;
+        case NORMAL:
+            sprintf(temp, "IMD Status: NORMAL"); ADD_SPRINTF_LINE break;
+        case UNDERVOLT:
+            sprintf(temp, "IMD Status: UNDERVOLT"); ADD_SPRINTF_LINE break;
+        case SPEEDSTART:
+            sprintf(temp, "IMD Status: SPEEDSTART"); ADD_SPRINTF_LINE break;
+        case ERROR:
+            sprintf(temp, "IMD Status: ERROR"); ADD_SPRINTF_LINE break;
+        case GROUNDERR:
+            sprintf(temp, "IMD Status: GROUNDERR"); ADD_SPRINTF_LINE break;
+        case INVALID:
+            sprintf(temp, "IMD Status: INVALID"); ADD_SPRINTF_LINE break;
+        default:
+            sprintf(temp, "IMD Status: UNKNOWN STATUS ERROR"); ADD_SPRINTF_LINE break;
+        }
+        
+    // Reading Coulomb Counter
+        
+        padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE     // Generate blank line 
+        padCenter(line, max_charsPerLine-2, " CoulombCounter ", '*'); ADD_LINE
+        
+        sprintf(temp, "Current: %f ampHours: %f Capacity: %f SOC: %f", coulombCounter.current(), coulombCounter.ampHours(), coulombCounter.capacity(), coulombCounter.SOC()); ADD_SPRINTF_LINE
+        
         // Write it all at once to output tx buffer
         for (int i = 0; i < strlen(buff); i++) {
             pc.putc(buff[i]);   
@@ -40,3 +91,13 @@
         Thread::wait(100);
     }
 }
+
+/*
+    Testing Notes
+    
+    Oct 25
+    Tested PollSwitch:
+        
+        Wasn't able to access pins p1_x, but tried out pollswitch with pins p0_x
+        Logic seems to work
+*/
\ No newline at end of file
--- a/SerialDiagnostics/SerialDiagnostics.h	Sat Oct 25 16:48:09 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-#ifndef _SERIAL_DIAGNOSTICS_H
-#define _SERIAL_DIAGNOSTICS_H
-
-#include "MODSERIAL.h"
-#include "rtos.h"
-#include "IOobjects.h"
-
-namespace SerialDiagnostics {
-    void thread_serialOut(void const *args);
-    
-}
-
-#endif
\ No newline at end of file
--- a/SysMngmt.cpp	Sat Oct 25 16:48:09 2014 +0000
+++ b/SysMngmt.cpp	Fri Nov 07 01:26:13 2014 +0000
@@ -1,19 +1,21 @@
-/*
-    Reads CAN Messages and various data inputs, outputs using Xbee radio modules
-
-    Revised Oct 19, 2014: First team repository version
-*/
-
 #include "mbed.h"
+#include "rtos.h"
+#include "IOobjects.h"
+#include "SerialDiagnostics.h"
 
-DigitalOut myled(LED1);
-
-int main(){
-
-    while(1){
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+int main() {
+    wdt.kick();                         // Kick the watchdog timer
+    pc.baud(921600);
+    pc.printf("\r\n\r\nPCM Reset\r\n");
+    
+    // Did a watchdog reset occur since last power cycle?
+    if (wdt.checkFlag()) {
+        pc.printf("Watchdog Reset\r\n");
+    }
+    
+    Thread serialThread(SerialDiagnostics::thread_serialOut, 0, osPriorityNormal, 6000);
+    
+    while(1) {
+        wdt.kick();
     }
 }