Swimate V2 without RTOS code
Dependencies: Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL
comms.h.orig@24:f2503d1256ad, 2014-06-09 (annotated)
- Committer:
- ellingjp
- Date:
- Mon Jun 09 04:55:16 2014 +0000
- Revision:
- 24:f2503d1256ad
- Parent:
- 22:9350752f5414
Using RTC filenames
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ellingjp | 22:9350752f5414 | 1 | #ifndef _COMMS_H |
ellingjp | 22:9350752f5414 | 2 | #define _COMMS_H |
ellingjp | 22:9350752f5414 | 3 | |
ellingjp | 22:9350752f5414 | 4 | #include "mbed.h" |
ellingjp | 22:9350752f5414 | 5 | #include "MODSERIAL.h" |
ellingjp | 22:9350752f5414 | 6 | #include <limits.h> |
ellingjp | 22:9350752f5414 | 7 | |
ellingjp | 22:9350752f5414 | 8 | class Packet; // forward declaration |
ellingjp | 22:9350752f5414 | 9 | |
ellingjp | 22:9350752f5414 | 10 | class Comms { |
ellingjp | 22:9350752f5414 | 11 | public: |
ellingjp | 22:9350752f5414 | 12 | Comms() : bt(P0_19, P0_18) { bt.baud(115200); } |
ellingjp | 22:9350752f5414 | 13 | |
ellingjp | 22:9350752f5414 | 14 | int receivePacket(Packet **p, int timeout); |
ellingjp | 22:9350752f5414 | 15 | void sendPacket(Packet *p); |
ellingjp | 22:9350752f5414 | 16 | |
ellingjp | 22:9350752f5414 | 17 | private: |
ellingjp | 22:9350752f5414 | 18 | Timer timer; |
ellingjp | 22:9350752f5414 | 19 | void sendByte(uint8_t byte); |
ellingjp | 22:9350752f5414 | 20 | void sendBytes(uint8_t *bytes, int nElms); |
ellingjp | 22:9350752f5414 | 21 | bool getByte(uint8_t *c, int timeout = INT_MAX); |
ellingjp | 22:9350752f5414 | 22 | bool getBytes(uint8_t *buf, int nElms, int timeout = INT_MAX); |
ellingjp | 22:9350752f5414 | 23 | MODSERIAL bt; // tx, rx |
ellingjp | 22:9350752f5414 | 24 | }; |
ellingjp | 22:9350752f5414 | 25 | |
ellingjp | 22:9350752f5414 | 26 | class Packet { |
ellingjp | 22:9350752f5414 | 27 | public: |
ellingjp | 22:9350752f5414 | 28 | static Packet *create(uint8_t cmd, uint16_t packetNumber, uint16_t dataLength, uint8_t *data); |
ellingjp | 22:9350752f5414 | 29 | static Packet *createAndVerify(uint8_t cmd, uint16_t packetNumber, uint16_t dataLength, uint8_t *data, uint16_t checkSum); |
ellingjp | 22:9350752f5414 | 30 | ~Packet(); |
ellingjp | 22:9350752f5414 | 31 | |
ellingjp | 22:9350752f5414 | 32 | uint8_t cmd; |
ellingjp | 22:9350752f5414 | 33 | uint16_t packetNumber; |
ellingjp | 22:9350752f5414 | 34 | uint16_t dataLength; |
ellingjp | 22:9350752f5414 | 35 | uint8_t *data; |
ellingjp | 22:9350752f5414 | 36 | uint16_t checkSum; |
ellingjp | 22:9350752f5414 | 37 | |
ellingjp | 22:9350752f5414 | 38 | static const int HEADER_SIZE; |
ellingjp | 22:9350752f5414 | 39 | private: |
ellingjp | 22:9350752f5414 | 40 | Packet(uint8_t cmd, uint16_t packetNumber, uint16_t dataLength, uint8_t *data); |
ellingjp | 22:9350752f5414 | 41 | }; |
ellingjp | 22:9350752f5414 | 42 | |
ellingjp | 22:9350752f5414 | 43 | #endif // _COMMS_H |