Working on rewriting how we acquire data from LTC chip and sending all temp data over serial for python logging

Dependencies:   MODSERIAL mbed

Fork of TCTF_Control_Main by Rivian Irvine Team

Revision:
16:a7fd53ab4199
Parent:
15:74a01aaeb60e
Child:
17:5098d8fbb298
--- a/main.cpp	Mon Jun 11 21:10:14 2018 +0000
+++ b/main.cpp	Thu Jun 14 18:28:52 2018 +0000
@@ -9,30 +9,30 @@
 #include <string>
 
 //DEFINITIVE VARIABLES
-#define DEBUG            0
-#define DEBUG1           0
-#define DEBUG2           0
-#define DEBUG3           1
-#define DEBUG5           0
-#define CHN_COUNT        8
-#define MIN_TEMP         10
-#define MAX_TEMP         65
-#define TEMP_MARGIN      20
-#define HYST_LOW         0.3
-#define HYST_HIGH        1
-#define SAMPLES          5
-#define I2C_Freq         2000
-#define VALVE            1
-#define HEATER           2
-#define STATUS_GOOD      3
-#define STATUS_BAD       0
-#define sizeLUT          34
-#define BACK_THERM       0
-#define FRONT_THERM      1
-#define HEAT_FET_AMP     2
-#define VALVE_FET_AMP    3
-#define FET_ON_CURRENT   1.12
-#define ROOM_TEMP        22
+#define DEBUG                0
+#define DEBUG1               0
+#define DEBUG2               0
+#define DEBUG3               1
+#define DEBUG5               0
+#define CHN_COUNT            8
+#define MIN_TEMP             10
+#define MAX_TEMP             65
+#define TEMP_MARGIN          20
+#define HYST_LOW             0.3
+#define HYST_HIGH            1
+#define SAMPLES              5
+#define I2C_Freq             2000
+#define VALVE                1
+#define HEATER               2
+#define STATUS_GOOD          3
+#define STATUS_BAD           0
+#define sizeLUT              34
+#define BACK_THERM           0
+#define FRONT_THERM          1
+#define HEAT_FET_AMP         2
+#define VALVE_FET_AMP        3
+#define FET_ON_CURRENT       1.12
+#define ROOM_TEMP            22
 #define MAX_HEATER_ON_TIME   25
 #define MAX_CHILL_TIME       10 //10sec
 
@@ -95,6 +95,15 @@
 } RESPONSE_CMD;
 
 typedef struct {
+    unsigned char SOF_flag;
+    unsigned char cmd_type;
+    unsigned char len;
+    unsigned char Delim;
+    float chTemp[CHN_COUNT];
+    unsigned char EOF_flag;
+} RESPONSE_TEMP_CMD;
+
+typedef struct {
     HOST_CMD_HEADER cmd_header;
     unsigned char chanIDSel;
     unsigned char chanDelim;
@@ -272,6 +281,14 @@
     {2284,125}
 };
 
+//TCTF CHANNEL TEMPERATURE
+typedef struct{
+   float currTempFront;
+   float currTempBack;
+}CHNL_TEMP;
+
+CHNL_TEMP channelTempData[CHN_COUNT];
+
 //SERIAL COMMUNICATION SETUP
 MODSERIAL pc(USBTX, USBRX);
 
@@ -586,17 +603,27 @@
 //***************************************************************
 // Build packet with temperature readings to send to GUI
 //***************************************************************
-void sendTempReadings (int chan, float currentTemp)
+void sendTempReadings()
 {
-    RESPONSE_CMD response;
+    RESPONSE_TEMP_CMD response;
     unsigned char *ptr = (unsigned char *)&response;
     int i;
 
     response.SOF_flag = TX_SOF;
     response.cmd_type = TEMP_DATA;
-    response.len = 9;
+    response.len = 5+(sizeof(response.chTemp));
     response.Delim = DELIMETER;
-    response.data = (float)currentTemp;
+    response.chTemp[0] = channelTempData[0].currTempBack;
+    response.chTemp[1] = channelTempData[1].currTempBack;
+    response.chTemp[2] = channelTempData[2].currTempBack;
+    response.chTemp[3] = channelTempData[3].currTempBack;
+    response.chTemp[4] = channelTempData[4].currTempBack;
+    response.chTemp[5] = channelTempData[5].currTempBack;
+    response.chTemp[6] = channelTempData[6].currTempBack;
+    response.chTemp[7] = channelTempData[7].currTempBack;
+    /*float *dst = (float *)&response.chTemp[0];
+    float *src = (float *)&channelTempData[0];
+    memcpy(dst, src, sizeof(channelTempData));*/
     response.EOF_flag = TX_EOF;
 
     // Send response to GUI
@@ -744,7 +771,7 @@
             pc.printf("DBG: <%f>[UID: %04X%08X%08X] PSTARTED\n", t.read(), UIDMH, UIDML, UIDL);
         }
 
-        //setup timer used to track how long the heater is on
+        //SETUP TIMER USED TO TRACK HOW LONG THE HEATER IS ON
         float time_sec = t.read();
 
         if(time_sec >= 60){
@@ -757,8 +784,10 @@
            time_min = 0;
         }
 
-        //pc.printf("Time: %f \r\n", time_sec);
+        //SEND TEMPERATURE DATA FOR LOGGING
+        sendTempReadings();
 
+        //CONTROL LOOP: LOOPS THROUGH EVERY CHANNEL AND CONTROLS THE FIXTURE IN RESPONSE
         for(int chnl = 0; chnl < CHN_COUNT; chnl++){
             float currentTempFront = get_temp(chnl, FRONT_THERM);
 
@@ -776,21 +805,22 @@
             float currentTempBack = get_temp(chnl, BACK_THERM);
             float currentTemp = currentTempBack;
 
-            if (chnl == chanSel_SendTemp){
-                //Send temp readings for selected chan to GUI
-                sendTempReadings(currChan, currentTemp);
-            }
+            //update channel temperature data
+            channelTempData[chnl].currTempFront = currentTempFront;
+            channelTempData[chnl].currTempBack = currentTempBack;
 
             //Error check on fixture
             error_check(chnl, currentTempFront, currentTempBack, time_min);
 
+            pc.printf("TEMPERATURE: [%d] Temp: F: %f B: %f\r\n", chnl, currentTempFront, currentTempBack);
+            
             //CONTROL LOOP:
             if(chnlStatus[chnl].status == 1){
                 if(DEBUG) pc.printf("DBG: [%d] Temp: F: %f B: %f\r\n", chnl, currentTempFront, currentTempBack);
                 //main loop for channels
                 if(chnlStatus[chnl].error == 0){
                     if(currentTemp > ((chnlStatus[chnl].setTemp)+HYST_HIGH)){
-                        if(DEBUG3) pc.printf("DBG: [%d] Chiller ON \r\n", chnl);
+                        if(DEBUG) pc.printf("DBG: [%d] Chiller ON \r\n", chnl);
                         //reset heater on time
                         chnlStatus[chnl].heater_init_time = 0;
                         //reset cooling timer
@@ -819,7 +849,7 @@
                         }
                     }
                     else if (currentTemp < ((chnlStatus[chnl].setTemp)-HYST_LOW)){
-                        if(DEBUG3) pc.printf("DBG: [%d] Heater ON \r\n", chnl);
+                        if(DEBUG) pc.printf("DBG: [%d] Heater ON \r\n", chnl);
                         //establish starting time for heater
                         if(chnlStatus[chnl].heater_init_time == 0){ //check if it is the first time that heater has turned on
                             //make sure time isn't zero, otherwise keeping looping until we are not at 0
@@ -832,7 +862,7 @@
                         turn_heater_on(chnl);
                     }
                     else{
-                        if(DEBUG3) pc.printf("DBG: [%d] All OFF \r\n", chnl);
+                        if(DEBUG) pc.printf("DBG: [%d] All OFF \r\n", chnl);
                         //reset heater on time
                         chnlStatus[chnl].heater_init_time = 0;
                         //turn off chiller