Jonathan Jones
/
Radios
Radio Structures in OOP
modules/CommModule/CommModule.h@5:146523a0d1f4, 2015-01-14 (annotated)
- Committer:
- jjones646
- Date:
- Wed Jan 14 17:46:44 2015 +0000
- Revision:
- 5:146523a0d1f4
- Parent:
- 4:989d51f3e6ef
- Child:
- 6:4a3dbfbc30f1
wrapping up functionality of sockets"
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 | ready(); |
jjones646 | 4:989d51f3e6ef | 48 | _rx_handles[portNbr].attach(tptr, mptr); |
jjones646 | 4:989d51f3e6ef | 49 | } |
jjones646 | 4:989d51f3e6ef | 50 | |
jjones646 | 3:dc7e9c6bc26c | 51 | void TxHandler(void(*)(RTP_t*), uint8_t); |
jjones646 | 4:989d51f3e6ef | 52 | void RxHandler(void(*)(RTP_t*), uint8_t); |
jjones646 | 4:989d51f3e6ef | 53 | void RxHandler(void(*)(void), uint8_t); |
jjones646 | 4:989d51f3e6ef | 54 | |
jjones646 | 4:989d51f3e6ef | 55 | void openSocket(uint8_t); |
jjones646 | 4:989d51f3e6ef | 56 | |
jjones646 | 4:989d51f3e6ef | 57 | template <class T> |
jjones646 | 4:989d51f3e6ef | 58 | void openSocket(T*, void(T::*)(RTP_t*), uint8_t); |
jjones646 | 4:989d51f3e6ef | 59 | |
jjones646 | 4:989d51f3e6ef | 60 | void openSocket(CommLink*, void(*)(void const*), uint8_t); |
jjones646 | 3:dc7e9c6bc26c | 61 | |
jjones646 | 2:7d523bdd2f50 | 62 | // 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 | 63 | void send(RTP_t&); |
jjones646 | 4:989d51f3e6ef | 64 | |
jjones646 | 3:dc7e9c6bc26c | 65 | void receive(RTP_t&); |
jjones646 | 5:146523a0d1f4 | 66 | |
jjones646 | 5:146523a0d1f4 | 67 | //osThreadId rxID(void); |
jjones646 | 2:7d523bdd2f50 | 68 | |
jjones646 | 2:7d523bdd2f50 | 69 | protected: |
jjones646 | 3:dc7e9c6bc26c | 70 | // NOP function for keeping a oommunication link active |
jjones646 | 3:dc7e9c6bc26c | 71 | void nopFunc(void); |
jjones646 | 3:dc7e9c6bc26c | 72 | |
jjones646 | 3:dc7e9c6bc26c | 73 | // Memory Queue IDs |
jjones646 | 2:7d523bdd2f50 | 74 | osMailQId _txQueue; |
jjones646 | 2:7d523bdd2f50 | 75 | osMailQId _rxQueue; |
jjones646 | 2:7d523bdd2f50 | 76 | |
jjones646 | 3:dc7e9c6bc26c | 77 | // Thread IDs |
jjones646 | 3:dc7e9c6bc26c | 78 | osThreadId _txID; |
jjones646 | 3:dc7e9c6bc26c | 79 | osThreadId _rxID; |
jjones646 | 4:989d51f3e6ef | 80 | |
jjones646 | 3:dc7e9c6bc26c | 81 | std::vector<uint8_t> *_open_ports; |
jjones646 | 3:dc7e9c6bc26c | 82 | |
jjones646 | 2:7d523bdd2f50 | 83 | private: |
jjones646 | 2:7d523bdd2f50 | 84 | // Used to help define the class's threads in the constructor |
jjones646 | 2:7d523bdd2f50 | 85 | friend void define_thread(osThreadDef_t&, void(*task)(void const *arg), osPriority, uint32_t, unsigned char*); |
jjones646 | 2:7d523bdd2f50 | 86 | |
jjones646 | 2:7d523bdd2f50 | 87 | // The working threads for handeling rx and tx data queues |
jjones646 | 2:7d523bdd2f50 | 88 | static void txThread(void const*); |
jjones646 | 2:7d523bdd2f50 | 89 | static void rxThread(void const*); |
jjones646 | 2:7d523bdd2f50 | 90 | |
jjones646 | 4:989d51f3e6ef | 91 | void ready(void); |
jjones646 | 4:989d51f3e6ef | 92 | |
jjones646 | 4:989d51f3e6ef | 93 | static bool isReady; |
jjones646 | 4:989d51f3e6ef | 94 | |
jjones646 | 3:dc7e9c6bc26c | 95 | // Thread and Mail defintion data structures |
jjones646 | 2:7d523bdd2f50 | 96 | osThreadDef_t _txDef; |
jjones646 | 2:7d523bdd2f50 | 97 | osThreadDef_t _rxDef; |
jjones646 | 3:dc7e9c6bc26c | 98 | osMailQDef_t _txQDef; |
jjones646 | 3:dc7e9c6bc26c | 99 | osMailQDef_t _rxQDef; |
jjones646 | 2:7d523bdd2f50 | 100 | |
jjones646 | 4:989d51f3e6ef | 101 | // Mail helper objects |
jjones646 | 4:989d51f3e6ef | 102 | MailHelper<RTP_t, COMM_MODULE_TX_QUEUE_SIZE> _txQueueHelper; |
jjones646 | 4:989d51f3e6ef | 103 | MailHelper<RTP_t, COMM_MODULE_RX_QUEUE_SIZE> _rxQueueHelper; |
jjones646 | 4:989d51f3e6ef | 104 | |
jjones646 | 3:dc7e9c6bc26c | 105 | CommLink *_link[COMM_MODULE_NBR_PORTS]; |
jjones646 | 4:989d51f3e6ef | 106 | |
jjones646 | 3:dc7e9c6bc26c | 107 | FunctionPointerRJ _rx_handles[COMM_MODULE_NBR_PORTS]; |
jjones646 | 3:dc7e9c6bc26c | 108 | FunctionPointerRJ _tx_handles[COMM_MODULE_NBR_PORTS]; |
jjones646 | 3:dc7e9c6bc26c | 109 | |
jjones646 | 4:989d51f3e6ef | 110 | bool _txH_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 |