Has base BMU code but sends dummy temperature and voltage readings to test CAN

Dependencies:   CUER_CAN DS1820 LTC2943 LTC6804 mbed

Fork of BMS_BMUCore_Max by CUER

Revision:
11:cf2db05cfa56
Parent:
10:1079f8e52d65
Child:
12:fa9b1a459e47
--- a/main.cpp	Mon Jun 19 12:00:03 2017 +0000
+++ b/main.cpp	Wed Jun 21 00:15:57 2017 +0000
@@ -38,27 +38,28 @@
 }
 
 int main()
-{
+{ 
     BMU_data measurements;
     uint16_t current_EEPROM_address;
     uint32_t status;
-    int c = 0;
     
     /*while(true)
     {
-        wait(0.05);
+        //wait(0.05);
         test_read_voltage_CAN();
     }*/
     init();
     
-    current_EEPROM_address = read_EEPROM_startup(measurements); // Read from the eeprom at startup to fill in the values of SoC
-    ltc2943.accumulatedCharge(measurements.percentage_SOC); // Initialise the LTC2943 with the current state of charge
+    
+    
+    //current_EEPROM_address = read_EEPROM_startup(measurements); // Read from the eeprom at startup to fill in the values of SoC
+    //ltc2943.accumulatedCharge(measurements.percentage_SOC); // Initialise the LTC2943 with the current state of charge
     
     while (true) {
-
+        
         // Take measurements from the sensors
         take_measurements(measurements);
-        // Dont want to read the temperature sensors during each iteration of the loop
+        /*// Dont want to read the temperature sensors during each iteration of the loop
         if (c == 0) {
             read_temperature_sensors(measurements);
         } else if(c >= 4) {
@@ -74,14 +75,21 @@
 
         //Store data in the eeprom
         write_SOC_EEPROM(measurements, current_EEPROM_address);
+        */
 
         // CAN bus
         transmit_data(measurements,status);
-
+        
+        /*
         // Conserve power - enter a low powered mode
         delay_finished = false;
         loop_delay.attach(loop_delay_callback, LOOP_DELAY_S);
         while (!delay_finished) sleep();
+        */
+        
+        //test_CAN_send();
+        //test_CAN_read();
+        wait(1);
     } 
 }
 
@@ -99,13 +107,16 @@
         //This is a slightly modified version of the Tritium BMS datasheet, to add an extra voltage reading set.
         msg = createVoltageTelemetry(repeating_unit_length*i+2, measurements.cell_voltages[i].voltages); 
         can.write(msg);
+        wait(0.1);
         //CONSIDER WAITS JUST IN CASE
         //+4 - 4 cell voltages sent per measurement
         msg = createVoltageTelemetry(repeating_unit_length*i+3, measurements.cell_voltages[i].voltages + 4); 
         can.write(msg);
+        wait(0.1);
         msg = createVoltageTelemetry(repeating_unit_length*i+4, measurements.cell_voltages[i].voltages + 8); 
         can.write(msg);
-        printf("Message id: %d \r\n", msg.id);
+        wait(0.1);
+        //printf("Message id: %d \r\n", msg.id);
     }
 
     // Create SOC CAN message
@@ -281,9 +292,9 @@
         }
         can_id = msg.id; 
         printf("CAN ID: %d \r\n", can_id);
-        offset = can_id - 1537; //1537 = 0x600
+        offset = can_id - 1536; //1536 = 0x600
         first_index = (offset - 1)/4; //offset of 2,3,4 is CMU 1; 6,7,8, is CMU 2; etc.
-        second_index = ((offset - 1) % 4); //Makes it so 0,1,2 represent each voltage set
+        second_index = ((offset - 1) % 4) - 1; //Makes it so 0,1,2 represent each voltage set //SID: subtracted 1 to make it work
         for(int i = 0; i < 4; i++)
         {
             printf("Cell_Voltage[%d][%d] = %d \r\n", first_index, second_index *4 + i, readings[i]);  
@@ -296,7 +307,7 @@
 void test_CAN_send()
 {
     CANMessage msg;
-    char value = 87;
+    char value = 142;
     msg = CANMessage(1, &value,1);
     if(can.write(msg))
         printf("Succesfully sent %d \r\n", value);