Tufts Hybrid Racing Control Node
Revision 0:9b224b68e7c7, committed 2012-01-12
- Comitter:
- wsalis01
- Date:
- Thu Jan 12 20:44:16 2012 +0000
- Child:
- 1:edb687d65942
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CANProtocol.lib Thu Jan 12 20:44:16 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/wsalis01/code/CANProtocol/#f25554922a25
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ControlNode.cpp Thu Jan 12 20:44:16 2012 +0000 @@ -0,0 +1,101 @@ +/* + * File: ControlNode/ControlNode.cpp + * Author: William Jessup Salisbury + * Company: Tufts Hybrid Racing Team + * Copyright: CC BY-NC-SA 3.0 + * Date: 1/12/2012 + */ + +#include "mbed.h" +#include "CANProtocol.h" +#include "ControlNode.h" + +ControlNode::ControlNode() : _can(CAN_RX, CAN_TX), _console(USBTX, USBRX), _syncID(0) { + /* CAN initialization */ + _can.attach(this, &ControlNode::canReceive); + + /* Ticker initialization */ + _syncTimer.attach_us(this, &ControlNode::canSync, tickerTimeout_us); + + /* Print startup message */ + _console.printf("%s\r\n", "ControlNode instantiated."); +} + +ControlNode::~ControlNode() { + _syncTimer.detach(); +} + +void ControlNode::canReset() { + CANMessage msg; + msg.id = CAN_RESET; + msg.len = 0; + if (_can.write(msg)) { + _console.printf("%s\r\n", "Reset message sent."); + } else { + _console.printf("%s\r\n", "Reset message send failure."); + } +} + +void ControlNode::canSync() { + CANMessage msg(CAN_SYNC); + msg.len = 1; + msg.data[0] = (++_syncID % 0xFF); + if (_can.write(msg)) { + _console.printf("%s\r\n", "Sync message sent."); + } else { + _console.printf("%s\r\n", "Sync message send failure."); + } +} + +void ControlNode::canSend() { + CANMessage msg; + + + if (_can.write(msg)) { + _console.printf("%s\r\n", "Message sent."); + } else { + _console.printf("%s\r\n", "Message send failure."); + } +} + +void ControlNode::canReceive() { + CANMessage msg; + + if (_can.read(msg)) { + + _console.printf("%s\r\n", "Message received."); + + if (msg.data[0] != _syncID) { + _console.printf("%s\r\n", "'_syncID' mismatch."); + return; + } + + switch (msg.id) { + case CAN_BRAKE: + break; + + case CAN_ACCEL: + break; + + case CAN_FLWS: + break; + + case CAN_FRWS: + break; + + case CAN_RLWS: + break; + + case CAN_RRWS: + break; + + case CAN_STATUS: + break; + + default: + break; + } + } else { + _console.printf("%s\r\n", "Message recieve failure."); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ControlNode.h Thu Jan 12 20:44:16 2012 +0000 @@ -0,0 +1,34 @@ +/* + * File: ControlNode/ControlNode.h + * Author: William Jessup Salisbury + * Company: Tufts Hybrid Racing Team + * Copyright: CC BY-NC-SA 3.0 + * Date: 1/12/2012 + */ + +#ifndef CONTROL_NODE_H +#define CONTROL_NODE_H +#include "mbed.h" + +const PinName CAN_RX = p9; +const PinName CAN_TX = p10; + +const int tickerTimeout_us = 1000; + +class ControlNode { +public: + ControlNode(); + ~ControlNode(); +private: + void canReset(); + void canSync(); + void canSend(); + void canReceive(); + + CAN _can; + Serial _console; + Ticker _syncTimer; + char _syncID; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 12 20:44:16 2012 +0000 @@ -0,0 +1,17 @@ +/* + * File : ControlNode/main.cpp + * Author: William Jessup Salisbury + * Company: Tufts Hybrid Racing Team + * Copyright: CC BY-NC-SA 3.0 + * Date: 1/12/2012 + */ + +#include "mbed.h" +#include "ControlNode.h" + +ControlNode cn; + +int main() { + while (true) + __WFI(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jan 12 20:44:16 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/5364839841bd