Ultima versão da banca de ensaios ECU Fev2017
Fork of Can_sniffer_BMS4 by
Diff: main.cpp
- Revision:
- 25:76c6f417eb48
- Parent:
- 24:c9c7dcdcbbc5
- Child:
- 26:3ac15dfbb66b
--- a/main.cpp Sun Oct 23 13:10:00 2016 +0000 +++ b/main.cpp Sun Oct 23 19:25:01 2016 +0000 @@ -54,10 +54,9 @@ DigitalOut led(PA_5); Timer timer; -int counter = 0; volatile bool msgAvailable = false; volatile bool to_send = false; - +float cellsv[36]; /** * @brief 'CAN receive-complete' interrup handler. * @note Called on arrival of new CAN message. @@ -79,7 +78,8 @@ bool key_switch = 0; -/*void flip() + +void flip() { key_switch = !key_switch; led = key_switch; @@ -92,20 +92,18 @@ // to_send = 1; } -*/ -volatile float cells[36]; - void cvprint(){ - - int i=0; - for(i=0; i<=35; i=i+1) - printf("data: %f, cell : %d\n", cells[i],i); - + int n; + 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]); + } + printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n"); } -//Ticker flipper; -Ticker cvprinter; +Ticker flipper; +Ticker printer; typedef union can_union { int i[2]; @@ -113,18 +111,14 @@ float f[2]; } data; - - - int main() { - - int n=0; can.frequency(1000000); // set bit rate to 1Mbps can.attach(&onMsgReceived); // attach 'CAN receive-complete' interrupt handler - // flipper.attach(&flip, 30); // turn on or off - cvprinter.attach(&cvprint, 30); + flipper.attach(&flip, 30); // turn on or off + + printer.attach(&cvprint, 20); // turn on o led=key_switch; timer.start(); // start timer @@ -132,7 +126,6 @@ while(true) { if(msgAvailable) { - static int counter = 0; data data; int len = can.read(rxMsg); data.bytes[0] = rxMsg.data[0]; @@ -140,39 +133,17 @@ 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]); - - - n = (rxMsg.id-11)*12+rxMsg.data[4]; - - cells[n]=data.f[0]; - //------------------------------ - - /* - - if(rxMsg.id==11){ - cells[rxMsg.data[4]]=data.f[0]; - } - if(rxMsg.id==12){ - cells[rxMsg.data[4]+12]=data.f[0]; - } - if(rxMsg.id==13){ - cells[rxMsg.data[4]+24]=data.f[0]; - } - */ - - //---------------------------- - + // 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"); - //counter++; - /*if(rxMsg.data[4] == 1) { //counter == 12 + // printf("\r\n"); + /* if(rxMsg.data[4] == 1) { //counter == 12 - counter = 0; printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n"); } */