all bms comunicating with nucleo board and balancing
Fork of Can_sniffer_BMS_GER by
Diff: main.cpp
- Revision:
- 41:dcd47ac5ffdf
- Parent:
- 40:54d07c794d87
- Child:
- 42:db111f4ddfff
--- a/main.cpp Fri Nov 25 23:26:37 2016 +0000 +++ b/main.cpp Tue Nov 29 09:05:06 2016 +0000 @@ -130,6 +130,7 @@ DigitalOut led(PA_5); +DigitalOut controller_key_switch(PA_6); Timer timer; volatile bool msgAvailable = false; @@ -155,13 +156,13 @@ * @retval */ -bool key_switch = 0; +//bool key_switch = 0; void refresh() { - key_switch = !key_switch; - led = key_switch; + //key_switch = !key_switch; + led = controller_key_switch; to_send=1; //printf("controller switch\r\n"); // to_send = 1; @@ -224,9 +225,18 @@ printf("\r\n""""""""""""""""""""""""""""""""""""""""""""""""\r\n"); } + +void flip() +{ + controller_key_switch = !controller_key_switch; + led = controller_key_switch; +} + + Ticker refresher; Ticker printer; Ticker printer2; +InterruptIn button(PC_13); typedef union can_union { int i[2]; @@ -243,12 +253,14 @@ 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 - + button.rise(&flip); printer.attach(&cvprint, 20); // turn on o printer2.attach(&ctprint, 50); // turn on o - - led=key_switch; + //led=key_switch; + controller_key_switch=0; + led=controller_key_switch; + timer.start(); // start timer printf("started\r\n"); @@ -291,7 +303,12 @@ cellst[(rxMsg.id-21)*32+rxMsg.data[4]-1]=data.f[0]; //printf("temp: %d \r\n", rxMsg.data[1]); - } + }else if(rxMsg.id==8){ + controller_key_switch=0; + led=controller_key_switch; + printf("alarm! contactors disconnected\r\n"); + + } } if(to_send) { @@ -305,7 +322,7 @@ txMsg.clear(); txMsg.id = 9; //BMS1=>ID:11; BMS2=>ID:12; BMS3=>ID:13. txMsg.len = 1; - motostate = (0b00000001 & key_switch)|((0b00000001 & charging)<<1); + motostate = (0b00000001 & controller_key_switch)|((0b00000001 & charging)<<1); txMsg.data[0] = motostate; //------------------------------------------------