Updated EPS code with flowchart v2.3 (CDMS and HW faults)

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of QM_BAE_review_1_EPS_faults by Mohamed Azad

Revision:
1:446a959e36ce
Parent:
0:7b4c00e3912f
Child:
2:c823d84b4cb0
--- a/EPS.cpp	Thu Dec 24 19:15:43 2015 +0000
+++ b/EPS.cpp	Thu Dec 24 20:01:31 2015 +0000
@@ -103,7 +103,7 @@
 
 void FCTN_BATTERYGAUGE_MAIN(float Battery_parameters[4])
 {
-    
+        printf("\n\r battery gauge \n");
 
         float temp=25;    //=Battery_temp  (from temp sensor on battery board)       //value of battery temperature in C currently given a dummy value. Should be updated everytime.
         tempCompensation(temp);
@@ -143,6 +143,21 @@
         return (buff[0] << 8) | buff[1];
     }
  
+ unsigned short read_soc(char reg , bool ack = true)
+    {
+         
+         //Create a temporary buffer
+        char buff[2];
+ 
+        //Select the register
+        m_I2C.write(m_ADDR, &reg, 1, true);
+ 
+        //Read the 16-bit register
+        ack = m_I2C.read(m_ADDR, buff, 2);
+ 
+        //Return the combined 16-bit value
+        return (buff[0] << 8) | buff[1];
+    }
     
     void write(char reg, unsigned short data)
     {
@@ -344,6 +359,7 @@
     // Get the current cell voltage measurement of the MAX17049
     float vcell()
     {
+        
         //Read the 16-bit raw Vcell value
         unsigned short value = read(REG_VCELL);
  
@@ -354,27 +370,17 @@
     // Get the current state of charge measurement of the MAX17049 as a float
     float soc()
     {
-        unsigned short value;
+        //unsigned short value;
         char buff[2];
- 
-        //Select the register
-        m_I2C.write(m_ADDR, &REG_SOC, 1, true);
- 
-        //Read the 16-bit register
-        bool ack = true; 
-        ack = m_I2C.read(m_ADDR, buff, 2);
- 
-        //Return the combined 16-bit value
-        value =  (buff[0] << 8) | buff[1];
-       /* 
+        bool ack;
         //Read the 16-bit raw SOC value
-        unsigned short value = read(REG_SOC);*/
+        unsigned short value = read_soc(REG_SOC, ack);
  
         //Return SOC in percent
-        if(ack == 0)
+       // if(ack == 0)
         return value * 0.00390625;
-        else 
-        return 200;
+        //else 
+        //return 200;
     }