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:
Wed Oct 08 20:56:41 2014 +0000
Parent:
4:e31528929150
Child:
6:6a04210a3f4f
Commit message:
Added 10 Hz update threads for DC-DC and fans/pumps

Changed in this revision

SysMngmt.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SysMngmt.cpp	Wed Oct 08 00:38:41 2014 +0000
+++ b/SysMngmt.cpp	Wed Oct 08 20:56:41 2014 +0000
@@ -178,21 +178,9 @@
     CANMessage Txmsg_Status(423,status,sizeof(status));
     CAN_SysM.write(Txmsg_Status);
 }    
-
-void Battery()
-{
-    RTCStore reg;
-    ftc send;
+*/    
 
-    send.FLOAT=reg.read(0);
-    CANMessage Txmsg_BATmA_Hr(440,send.C_FLOAT,sizeof(send.C_FLOAT));
-    CAN_SysM.write(Txmsg_BATmA_Hr);
-    
-    send.FLOAT=reg.read(1);
-    CANMessage Txmsg_DCA_msec(442,send.C_FLOAT,sizeof(send.C_FLOAT));     
-    CAN_SysM.write(Txmsg_DCA_msec);
-}    
-
+/*
     Activates a whole crapload of functions and pins on the chip
 
 void Init()
@@ -291,14 +279,16 @@
 PwmOut fan2_pwm(P2_2);
 PwmOut fan3_pwm(P2_3);
 
+char fan1_duty = 0;
+char fan2_duty = 0;
+char fan3_duty = 0;
+char pump_duty = 0;
+
+int tx_fan_id = ((int)sys_src_id << 8)&((int)fan_id);
+
 // duty goes from 0 to 100
 void rampFans(void const *arg){
     
-    static char fan1_duty = 0;
-    static char fan2_duty = 0;
-    static char fan3_duty = 0;
-    static char pump_duty = 0;
-    
     char *data = (char *)arg;
     
     // bounds checking
@@ -350,10 +340,25 @@
     }
 }
 
-char dc_CAN_id = 0;                   // first byte of CANData, last byte states whether to toggle on (1) or off (0)
+void updateFans(void const *arg){
+    char data[4] = {0, 0, 0, 0};
+    while(1){
+        data[0] = pump_duty;
+        data[1] = fan1_duty;
+        data[2] = fan2_duty;
+        data[3] = fan3_duty;
+        CANMessage txMessage(tx_fan_id, data, 4);
+        rxBuffer.txWrite(txMessage);
+        Thread::wait(100);
+    }    
+}
+
+char dc_id = 0;                   // first byte of CANData, last byte states whether to toggle on (1) or off (0)
 DigitalOut dcPin(p20);
 bool dc_on = false;
 
+int tx_dc_id = ((int)sys_src_id << 8)&((int)dc_id);
+
 void toggleDC_DC(bool toggle){
     
     //dcPin turns on DC_DC converter when 0, off when 1
@@ -367,12 +372,26 @@
     }
 }
 
+void updateDC(void const *arg){
+    char data[4] = {0, 0, 0, 0};
+    while(1){
+        data[0] = dc_on;
+        CANMessage txMessage(tx_dc_id, data, 4);
+        rxBuffer.txWrite(txMessage);
+        Thread::wait(100);
+    }  
+}
+
 int main() {
     CANMessage rx_msg;    
 
     //turn off DC-DC converter on startup
     toggleDC_DC(false);
 
+    //CANMessage update threads
+    Thread fan_update(updateFans);
+    Thread dc_update(updateDC);
+
     while(1)
     {
         if(rxBuffer.rxRead(rx_msg)){
@@ -400,7 +419,7 @@
                     fan_threads[pin_id] = new Thread(rampFans, rx_msg.data);
                 }
                 
-                if(cont_id == dc_CAN_id){
+                if(cont_id == dc_id){
                     toggleDC_DC(rx_msg.data[0]);
                 }