Jonathan Jones
/
Radios
Radio Structures in OOP
modules/CommModule/CommModule.h@4:989d51f3e6ef, 2015-01-03 (annotated)
- Committer:
- jjones646
- Date:
- Sat Jan 03 11:04:31 2015 +0000
- Revision:
- 4:989d51f3e6ef
- Parent:
- 3:dc7e9c6bc26c
- Child:
- 5:146523a0d1f4
adding separate methods for setting rx/tx callback functions with both regular and object functions and methods.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jjones646 | 2:7d523bdd2f50 | 1 | #ifndef COMMUNICATION_MODULE_H |
jjones646 | 2:7d523bdd2f50 | 2 | #define COMMUNICATION_MODULE_H |
jjones646 | 2:7d523bdd2f50 | 3 | |
jjones646 | 2:7d523bdd2f50 | 4 | #include "mbed.h" |
jjones646 | 2:7d523bdd2f50 | 5 | #include "cmsis_os.h" |
jjones646 | 2:7d523bdd2f50 | 6 | #include "RTP.h" |
jjones646 | 2:7d523bdd2f50 | 7 | #include "ThreadHelper.h" |
jjones646 | 3:dc7e9c6bc26c | 8 | #include "MailHelper.h" |
jjones646 | 3:dc7e9c6bc26c | 9 | #include "Logger.h" |
jjones646 | 3:dc7e9c6bc26c | 10 | #include "FunctionPointerRJ.h" |
jjones646 | 2:7d523bdd2f50 | 11 | |
jjones646 | 3:dc7e9c6bc26c | 12 | #include <algorithm> // std::binary_search, std::sort |
jjones646 | 3:dc7e9c6bc26c | 13 | #include <vector> |
jjones646 | 3:dc7e9c6bc26c | 14 | |
jjones646 | 3:dc7e9c6bc26c | 15 | #define COMM_MODULE_TX_QUEUE_SIZE 20 |
jjones646 | 3:dc7e9c6bc26c | 16 | #define COMM_MODULE_RX_QUEUE_SIZE 4 |
jjones646 | 3:dc7e9c6bc26c | 17 | #define COMM_MODULE_NBR_PORTS 15 |
jjones646 | 3:dc7e9c6bc26c | 18 | #define COMM_MODULE_SIGNAL_START_THREAD 0x01 |
jjones646 | 3:dc7e9c6bc26c | 19 | |
jjones646 | 3:dc7e9c6bc26c | 20 | class CommLink; |
jjones646 | 2:7d523bdd2f50 | 21 | |
jjones646 | 2:7d523bdd2f50 | 22 | // Base class for a communication module |
jjones646 | 2:7d523bdd2f50 | 23 | class CommModule |
jjones646 | 2:7d523bdd2f50 | 24 | { |
jjones646 | 2:7d523bdd2f50 | 25 | public: |
jjones646 | 2:7d523bdd2f50 | 26 | // Default Constructor |
jjones646 | 2:7d523bdd2f50 | 27 | CommModule(); |
jjones646 | 2:7d523bdd2f50 | 28 | |
jjones646 | 2:7d523bdd2f50 | 29 | // Deconstructor |
jjones646 | 3:dc7e9c6bc26c | 30 | virtual ~CommModule(); |
jjones646 | 3:dc7e9c6bc26c | 31 | |
jjones646 | 2:7d523bdd2f50 | 32 | // Class constants - set in CommModule.cpp |
jjones646 | 2:7d523bdd2f50 | 33 | static const int NBR_PORTS; |
jjones646 | 2:7d523bdd2f50 | 34 | static const int TX_QUEUE_SIZE; |
jjones646 | 2:7d523bdd2f50 | 35 | static const int RX_QUEUE_SIZE; |
jjones646 | 2:7d523bdd2f50 | 36 | |
jjones646 | 3:dc7e9c6bc26c | 37 | // Open a socket connection for communicating. |
jjones646 | 3:dc7e9c6bc26c | 38 | template <typename T> |
jjones646 | 4:989d51f3e6ef | 39 | void TxHandler(T *tptr, void(T::*mptr)(RTP_t*), uint8_t portNbr) { |
jjones646 | 4:989d51f3e6ef | 40 | _txH_called = true; |
jjones646 | 4:989d51f3e6ef | 41 | ready(); |
jjones646 | 4:989d51f3e6ef | 42 | _tx_handles[portNbr].attach(tptr, mptr); |
jjones646 | 4:989d51f3e6ef | 43 | } |
jjones646 | 2:7d523bdd2f50 | 44 | |
jjones646 | 4:989d51f3e6ef | 45 | template <typename T> |
jjones646 | 4:989d51f3e6ef | 46 | void RxHandler(T *tptr, void(T::*mptr)(RTP_t*), uint8_t portNbr) { |
jjones646 | 4:989d51f3e6ef | 47 | _rxH_called = true; |
jjones646 | 4:989d51f3e6ef | 48 | ready(); |
jjones646 | 4:989d51f3e6ef | 49 | _rx_handles[portNbr].attach(tptr, mptr); |
jjones646 | 4:989d51f3e6ef | 50 | } |
jjones646 | 4:989d51f3e6ef | 51 | |
jjones646 | 3:dc7e9c6bc26c | 52 | void TxHandler(void(*)(RTP_t*), uint8_t); |
jjones646 | 4:989d51f3e6ef | 53 | void RxHandler(void(*)(RTP_t*), uint8_t); |
jjones646 | 4:989d51f3e6ef | 54 | void RxHandler(void(*)(void), uint8_t); |
jjones646 | 4:989d51f3e6ef | 55 | |
jjones646 | 4:989d51f3e6ef | 56 | void openSocket(uint8_t); |
jjones646 | 4:989d51f3e6ef | 57 | |
jjones646 | 4:989d51f3e6ef | 58 | template <class T> |
jjones646 | 4:989d51f3e6ef | 59 | void openSocket(T*, void(T::*)(RTP_t*), uint8_t); |
jjones646 | 4:989d51f3e6ef | 60 | |
jjones646 | 4:989d51f3e6ef | 61 | void openSocket(CommLink*, void(*)(void const*), uint8_t); |
jjones646 | 3:dc7e9c6bc26c | 62 | |
jjones646 | 2:7d523bdd2f50 | 63 | // Send a RTP packet. The details of exactly how the packet will be sent are determined from the RTP packet's port and subclass values |
jjones646 | 2:7d523bdd2f50 | 64 | void send(RTP_t&); |
jjones646 | 4:989d51f3e6ef | 65 | |
jjones646 | 3:dc7e9c6bc26c | 66 | void receive(RTP_t&); |
jjones646 | 2:7d523bdd2f50 | 67 | |
jjones646 | 2:7d523bdd2f50 | 68 | protected: |
jjones646 | 3:dc7e9c6bc26c | 69 | // NOP function for keeping a oommunication link active |
jjones646 | 3:dc7e9c6bc26c | 70 | void nopFunc(void); |
jjones646 | 3:dc7e9c6bc26c | 71 | |
jjones646 | 3:dc7e9c6bc26c | 72 | // Memory Queue IDs |
jjones646 | 2:7d523bdd2f50 | 73 | osMailQId _txQueue; |
jjones646 | 2:7d523bdd2f50 | 74 | osMailQId _rxQueue; |
jjones646 | 2:7d523bdd2f50 | 75 | |
jjones646 | 3:dc7e9c6bc26c | 76 | // Thread IDs |
jjones646 | 3:dc7e9c6bc26c | 77 | osThreadId _txID; |
jjones646 | 3:dc7e9c6bc26c | 78 | osThreadId _rxID; |
jjones646 | 4:989d51f3e6ef | 79 | |
jjones646 | 3:dc7e9c6bc26c | 80 | std::vector<uint8_t> *_open_ports; |
jjones646 | 3:dc7e9c6bc26c | 81 | |
jjones646 | 2:7d523bdd2f50 | 82 | private: |
jjones646 | 2:7d523bdd2f50 | 83 | // Used to help define the class's threads in the constructor |
jjones646 | 2:7d523bdd2f50 | 84 | friend void define_thread(osThreadDef_t&, void(*task)(void const *arg), osPriority, uint32_t, unsigned char*); |
jjones646 | 2:7d523bdd2f50 | 85 | |
jjones646 | 2:7d523bdd2f50 | 86 | // The working threads for handeling rx and tx data queues |
jjones646 | 2:7d523bdd2f50 | 87 | static void txThread(void const*); |
jjones646 | 2:7d523bdd2f50 | 88 | static void rxThread(void const*); |
jjones646 | 2:7d523bdd2f50 | 89 | |
jjones646 | 4:989d51f3e6ef | 90 | void ready(void); |
jjones646 | 4:989d51f3e6ef | 91 | |
jjones646 | 4:989d51f3e6ef | 92 | static bool isReady; |
jjones646 | 4:989d51f3e6ef | 93 | |
jjones646 | 3:dc7e9c6bc26c | 94 | // Thread and Mail defintion data structures |
jjones646 | 2:7d523bdd2f50 | 95 | osThreadDef_t _txDef; |
jjones646 | 2:7d523bdd2f50 | 96 | osThreadDef_t _rxDef; |
jjones646 | 3:dc7e9c6bc26c | 97 | osMailQDef_t _txQDef; |
jjones646 | 3:dc7e9c6bc26c | 98 | osMailQDef_t _rxQDef; |
jjones646 | 2:7d523bdd2f50 | 99 | |
jjones646 | 4:989d51f3e6ef | 100 | // Mail helper objects |
jjones646 | 4:989d51f3e6ef | 101 | MailHelper<RTP_t, COMM_MODULE_TX_QUEUE_SIZE> _txQueueHelper; |
jjones646 | 4:989d51f3e6ef | 102 | MailHelper<RTP_t, COMM_MODULE_RX_QUEUE_SIZE> _rxQueueHelper; |
jjones646 | 4:989d51f3e6ef | 103 | |
jjones646 | 3:dc7e9c6bc26c | 104 | CommLink *_link[COMM_MODULE_NBR_PORTS]; |
jjones646 | 4:989d51f3e6ef | 105 | |
jjones646 | 3:dc7e9c6bc26c | 106 | FunctionPointerRJ _rx_handles[COMM_MODULE_NBR_PORTS]; |
jjones646 | 3:dc7e9c6bc26c | 107 | FunctionPointerRJ _tx_handles[COMM_MODULE_NBR_PORTS]; |
jjones646 | 3:dc7e9c6bc26c | 108 | |
jjones646 | 4:989d51f3e6ef | 109 | bool _txH_called; |
jjones646 | 4:989d51f3e6ef | 110 | bool _rxH_called; |
jjones646 | 4:989d51f3e6ef | 111 | |
jjones646 | 2:7d523bdd2f50 | 112 | // Ignore for now |
jjones646 | 2:7d523bdd2f50 | 113 | // bool _dynamic_stack; |
jjones646 | 3:dc7e9c6bc26c | 114 | |
jjones646 | 2:7d523bdd2f50 | 115 | }; |
jjones646 | 2:7d523bdd2f50 | 116 | |
jjones646 | 2:7d523bdd2f50 | 117 | #endif // COMMUNICATION_MODULE_H |