final
hoverserial.h@0:ca040e149431, 2020-06-29 (annotated)
- Committer:
- sllez
- Date:
- Mon Jun 29 15:54:28 2020 +0000
- Revision:
- 0:ca040e149431
final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sllez | 0:ca040e149431 | 1 | #include "mbed.h" |
sllez | 0:ca040e149431 | 2 | #include "BufferedSerial.h" |
sllez | 0:ca040e149431 | 3 | |
sllez | 0:ca040e149431 | 4 | #define HOVERSERIAL_BAUD 38400 // [-] Baud rate for HoverSerial (used to communicate with the hoverboard) |
sllez | 0:ca040e149431 | 5 | #define START_FRAME 0xABCD // [-] Start frme definition for reliable serial communication |
sllez | 0:ca040e149431 | 6 | //#define DEBUG_RX // [-] Debug received data. Prints all bytes to serial (comment-out to disable) |
sllez | 0:ca040e149431 | 7 | |
sllez | 0:ca040e149431 | 8 | class HoverSerial { |
sllez | 0:ca040e149431 | 9 | public: |
sllez | 0:ca040e149431 | 10 | // @parm tx communication tx pin |
sllez | 0:ca040e149431 | 11 | // rx communocation rx pin |
sllez | 0:ca040e149431 | 12 | HoverSerial(PinName tx, PinName rx); |
sllez | 0:ca040e149431 | 13 | |
sllez | 0:ca040e149431 | 14 | typedef struct { //Structure for sending data to hoverboard |
sllez | 0:ca040e149431 | 15 | uint16_t start; |
sllez | 0:ca040e149431 | 16 | int16_t steer; |
sllez | 0:ca040e149431 | 17 | int16_t speed; |
sllez | 0:ca040e149431 | 18 | uint16_t checksum; |
sllez | 0:ca040e149431 | 19 | } SerialCommand; |
sllez | 0:ca040e149431 | 20 | SerialCommand Command; |
sllez | 0:ca040e149431 | 21 | |
sllez | 0:ca040e149431 | 22 | typedef struct { //Structure for feedback from hoverboard |
sllez | 0:ca040e149431 | 23 | uint16_t start; |
sllez | 0:ca040e149431 | 24 | int16_t cmd1; |
sllez | 0:ca040e149431 | 25 | int16_t cmd2; |
sllez | 0:ca040e149431 | 26 | int16_t speedR_meas; |
sllez | 0:ca040e149431 | 27 | int16_t speedL_meas; |
sllez | 0:ca040e149431 | 28 | int16_t batVoltage; |
sllez | 0:ca040e149431 | 29 | int16_t boardTemp; |
sllez | 0:ca040e149431 | 30 | uint16_t cmdLed; |
sllez | 0:ca040e149431 | 31 | uint16_t checksum; |
sllez | 0:ca040e149431 | 32 | } SerialFeedback; |
sllez | 0:ca040e149431 | 33 | SerialFeedback Feedback; |
sllez | 0:ca040e149431 | 34 | SerialFeedback NewFeedback; |
sllez | 0:ca040e149431 | 35 | |
sllez | 0:ca040e149431 | 36 | void sendData(int16_t uSteer, int16_t uSpeed); |
sllez | 0:ca040e149431 | 37 | |
sllez | 0:ca040e149431 | 38 | void receiveData(); |
sllez | 0:ca040e149431 | 39 | |
sllez | 0:ca040e149431 | 40 | private: |
sllez | 0:ca040e149431 | 41 | BufferedSerial hoverserial; |
sllez | 0:ca040e149431 | 42 | }; |