![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Firmware for UT Robotex 2018 basketball robot
RFManager/RFManager.h@0:ef6268629f0b, 2018-09-28 (annotated)
- Committer:
- Reiko
- Date:
- Fri Sep 28 10:46:57 2018 +0000
- Revision:
- 0:ef6268629f0b
Firmware for UT Robotex 2018 basketball robot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Reiko | 0:ef6268629f0b | 1 | #ifndef RFMANAGER_H |
Reiko | 0:ef6268629f0b | 2 | #define RFMANAGER_H |
Reiko | 0:ef6268629f0b | 3 | |
Reiko | 0:ef6268629f0b | 4 | #include "mbed.h" |
Reiko | 0:ef6268629f0b | 5 | #include "CircularBuffer2.h" |
Reiko | 0:ef6268629f0b | 6 | |
Reiko | 0:ef6268629f0b | 7 | class RFManager { |
Reiko | 0:ef6268629f0b | 8 | protected: |
Reiko | 0:ef6268629f0b | 9 | FunctionPointer _callback; |
Reiko | 0:ef6268629f0b | 10 | |
Reiko | 0:ef6268629f0b | 11 | public: |
Reiko | 0:ef6268629f0b | 12 | RFManager(PinName txPinName, PinName rxPinName); |
Reiko | 0:ef6268629f0b | 13 | |
Reiko | 0:ef6268629f0b | 14 | void baud(int baudrate); |
Reiko | 0:ef6268629f0b | 15 | |
Reiko | 0:ef6268629f0b | 16 | char *read(); |
Reiko | 0:ef6268629f0b | 17 | |
Reiko | 0:ef6268629f0b | 18 | void send(char *sendData); |
Reiko | 0:ef6268629f0b | 19 | |
Reiko | 0:ef6268629f0b | 20 | void send(char *sendData, int length); |
Reiko | 0:ef6268629f0b | 21 | |
Reiko | 0:ef6268629f0b | 22 | void update(); |
Reiko | 0:ef6268629f0b | 23 | |
Reiko | 0:ef6268629f0b | 24 | void handleMessage(); |
Reiko | 0:ef6268629f0b | 25 | |
Reiko | 0:ef6268629f0b | 26 | void setShortCommandMode(bool isEnabled); |
Reiko | 0:ef6268629f0b | 27 | |
Reiko | 0:ef6268629f0b | 28 | bool readable(); |
Reiko | 0:ef6268629f0b | 29 | |
Reiko | 0:ef6268629f0b | 30 | void attach(void (*function)(void)) { |
Reiko | 0:ef6268629f0b | 31 | _callback.attach(function); |
Reiko | 0:ef6268629f0b | 32 | } |
Reiko | 0:ef6268629f0b | 33 | |
Reiko | 0:ef6268629f0b | 34 | template<typename T> |
Reiko | 0:ef6268629f0b | 35 | void attach(T *object, void (T::*member)(void)) { |
Reiko | 0:ef6268629f0b | 36 | _callback.attach( object, member ); |
Reiko | 0:ef6268629f0b | 37 | } |
Reiko | 0:ef6268629f0b | 38 | |
Reiko | 0:ef6268629f0b | 39 | private: |
Reiko | 0:ef6268629f0b | 40 | Serial serial; |
Reiko | 0:ef6268629f0b | 41 | |
Reiko | 0:ef6268629f0b | 42 | int serialId; |
Reiko | 0:ef6268629f0b | 43 | |
Reiko | 0:ef6268629f0b | 44 | void rxHandler(void); |
Reiko | 0:ef6268629f0b | 45 | |
Reiko | 0:ef6268629f0b | 46 | bool messageAvailable; |
Reiko | 0:ef6268629f0b | 47 | |
Reiko | 0:ef6268629f0b | 48 | void serialWrite(char *sendData, int length); |
Reiko | 0:ef6268629f0b | 49 | char serialReadChar(); |
Reiko | 0:ef6268629f0b | 50 | |
Reiko | 0:ef6268629f0b | 51 | CircularBuffer2<char> buf; |
Reiko | 0:ef6268629f0b | 52 | |
Reiko | 0:ef6268629f0b | 53 | unsigned int receiveCounter; |
Reiko | 0:ef6268629f0b | 54 | char receiveBuffer[16]; |
Reiko | 0:ef6268629f0b | 55 | |
Reiko | 0:ef6268629f0b | 56 | char receivedMessage[16]; |
Reiko | 0:ef6268629f0b | 57 | |
Reiko | 0:ef6268629f0b | 58 | bool shortCommandsEnabled; |
Reiko | 0:ef6268629f0b | 59 | unsigned int commandLength; |
Reiko | 0:ef6268629f0b | 60 | unsigned int shortCommandLength; |
Reiko | 0:ef6268629f0b | 61 | unsigned int longCommandLength; |
Reiko | 0:ef6268629f0b | 62 | }; |
Reiko | 0:ef6268629f0b | 63 | |
Reiko | 0:ef6268629f0b | 64 | |
Reiko | 0:ef6268629f0b | 65 | #endif //RFManager_H |