all bms comunicating with nucleo board and balancing

Dependencies:   CANnucleo mbed

Fork of Can_sniffer_BMS_GER by Joao Vieira

Revision:
36:00ea3ae2cead
Parent:
35:a8940aaa101f
Child:
37:1e1f3131fef5
diff -r a8940aaa101f -r 00ea3ae2cead main.cpp
--- a/main.cpp	Sat Oct 29 00:38:36 2016 +0000
+++ b/main.cpp	Wed Nov 09 10:14:03 2016 +0000
@@ -135,6 +135,7 @@
 volatile bool           msgAvailable = false;
 volatile bool           to_send = false;
 float cellsv[36]; 
+int cellst[96]; 
 /**
  * @brief   'CAN receive-complete' interrup handler.
  * @note    Called on arrival of new CAN message.
@@ -160,7 +161,7 @@
 void refresh()
 {
     key_switch = !key_switch;
-   // led = key_switch;
+    led = key_switch;
     to_send=1;
     //printf("controller switch\r\n");
     // to_send = 1;
@@ -172,20 +173,29 @@
     for(n=35; n>=0; n--){
         //printf("cellsv0: %f    cvprint\r\n", cellsv[0]);    
         printf("cell: %d   voltage: %f   \r\n", n+1,cellsv[n]);
-        
+               
         if(cellsv[n]>=0.1)
         {
         soma=cellsv[n]+soma;
         }
     }
         
-           printf("Total battery voltage: %f   \r\n", soma);     
+        printf("Total battery voltage: %f   \r\n", soma);     
         printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n");
     }
 
+void ctprint(){
+    int n;
+    for(n=95; n>=0; n--){
+        //printf("cellsv0: %f    cvprint\r\n", cellsv[0]);    
+        printf("ntc: %d   temperature: %d   \r\n", n+1,cellst[n]);
+    }
+    printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n");
+}
 
 Ticker refresher;
 Ticker printer;
+Ticker printer2;
 
 typedef union can_union {
     int i[2];
@@ -193,19 +203,26 @@
     float f[2];
 } data;
 
+typedef union can_union2 {
+    int i[2];
+    char bytes[8];
+    float f[2];
+} data2;
+
 //bool to_charge_or_not_to_charge=true;           // false = discharge
 bool charging = false;
 
 uint8_t motostate=0;
 
-int main()
-
-{
+int main(){
     can.frequency(1000000);                     // set bit rate to 1Mbps
     can.attach(&onMsgReceived);                 // attach 'CAN receive-complete' interrupt handler
     refresher.attach(&refresh, 5);                 // turn on or off
     
         printer.attach(&cvprint, 20);                 // turn on o
+        printer2.attach(&ctprint, 50);                 // turn on o
+        
+        
     led=key_switch;
     timer.start();  // start timer
 
@@ -214,27 +231,45 @@
 
         if(msgAvailable) {
             data data;
+            data2 data2;
             int len = can.read(rxMsg);
-            data.bytes[0] = rxMsg.data[0];
-            data.bytes[1] = rxMsg.data[1];
-            data.bytes[2] = rxMsg.data[2];
-            data.bytes[3] = rxMsg.data[3];
-            msgAvailable = false;               // reset flag for next use
-           // printf(" Id: %d, data: %f, counter : %d\n", rxMsg.id, data.f[0],rxMsg.data[4]);
-            cellsv[(rxMsg.id-11)*12+rxMsg.data[4]-1]=data.f[0];
-            //printf("cell: %d\r\n", rxMsg.data[4]);
-            /*
-            printf("\r\nreceived message ID: \t%d\n\r", rxMsg.id);
-            for(int i=0; i<len; i++) {
-                printf("\t%x",rxMsg.data[i]);
-            }*/
-           // printf("\r\n");
-           /* if(rxMsg.data[4] == 1) {  //counter == 12
-
-                printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n");
+            
+            if((rxMsg.id==11)||(rxMsg.id==12)||(rxMsg.id==13)){
+                data.bytes[0] = rxMsg.data[0];
+                data.bytes[1] = rxMsg.data[1];
+                data.bytes[2] = rxMsg.data[2];
+                data.bytes[3] = rxMsg.data[3];
+                msgAvailable = false;               // reset flag for next use
+               // printf(" Id: %d, data: %f, counter : %d\n", rxMsg.id, data.f[0],rxMsg.data[4]);
+                cellsv[(rxMsg.id-11)*12+rxMsg.data[4]-1]=data.f[0];
+                //printf("cell: %d\r\n", rxMsg.data[4]);
+                /*
+                printf("\r\nreceived message ID: \t%d\n\r", rxMsg.id);
+                for(int i=0; i<len; i++) {
+                    printf("\t%x",rxMsg.data[i]);
+                }*/
+               // printf("\r\n");
+               /* if(rxMsg.data[4] == 1) {  //counter == 12
+    
+                    printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n");
+                }
+                */
+                // Filtering performed by software:
             }
-            */
-            // Filtering performed by software:
+            
+            
+           if((rxMsg.id==21)||(rxMsg.id==22)||(rxMsg.id==23)){
+                int len = can.read(rxMsg);       
+                //printf("olaola\r\n");
+           //     cellst[(rxMsg.id-21)*32+rxMsg.data[4]-1]=data.f[0];
+                data2.bytes[0] = rxMsg.data[0];
+                data2.bytes[1] = rxMsg.data[1];
+                msgAvailable = false;        
+                cellst[(rxMsg.id-21)*32+rxMsg.data[2]-1]=data2.i[0];
+                
+                //printf("temp: %d   \r\n", rxMsg.data[1]);
+            }
+            
         }
         if(to_send) {
             to_send = 0;