Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: CanControl.cpp
- Revision:
- 0:274e6fb7df45
- Child:
- 2:d7776fa70ef5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CanControl.cpp Fri May 12 20:19:32 2017 +0000 @@ -0,0 +1,45 @@ +#include "PowerControl.h" + +extern RawSerial pc; +extern CAN can; + +CanControl::CanControl(PinName buckCan): + _buckCan(buckCan), _canEnable(CAN_ENABLE) +{ + enabled = false; + repeat.attach(this, &CanControl::relay, 1.0); +} + +bool CanControl::disable(void){ +#ifdef DEBUG + pc.printf("disabling CAN\r\n"); +#endif + enabled = false; + can.write(CANMessage(BMSCANADDRESS, "0")); + wait_ms(100); + _canEnable = 0; + _buckCan = 0; + return true; +} + +bool CanControl::enable(void){ +#ifdef DEBUG + pc.printf("enabling CAN\r\n"); +#endif + enabled = true; + _buckCan = 1; + _canEnable = 1; + wait_ms(100); + can.write(CANMessage(BMSCANADDRESS, "1")); + return true; +} + +void CanControl::relay(void){ + if(enabled){ +#ifdef DEBUG + pc.printf("CANMessage sent: BMSCANADDRESS, \"1\"\r\n"); +#endif + can.write(CANMessage(BMSCANADDRESS, "1")); + } +} +