Jonathan Jones
/
Radios
Radio Structures in OOP
Diff: modules/CommModule/CommModule.h
- Revision:
- 4:989d51f3e6ef
- Parent:
- 3:dc7e9c6bc26c
- Child:
- 5:146523a0d1f4
--- a/modules/CommModule/CommModule.h Sat Jan 03 04:35:32 2015 +0000 +++ b/modules/CommModule/CommModule.h Sat Jan 03 11:04:31 2015 +0000 @@ -36,15 +36,33 @@ // Open a socket connection for communicating. template <typename T> - void TxHandler(T*, void(T::*)(RTP_t*), uint8_t); + void TxHandler(T *tptr, void(T::*mptr)(RTP_t*), uint8_t portNbr) { + _txH_called = true; + ready(); + _tx_handles[portNbr].attach(tptr, mptr); + } + template <typename T> + void RxHandler(T *tptr, void(T::*mptr)(RTP_t*), uint8_t portNbr) { + _rxH_called = true; + ready(); + _rx_handles[portNbr].attach(tptr, mptr); + } + void TxHandler(void(*)(RTP_t*), uint8_t); - - void openSocket(CommLink*, uint8_t, void(*)(void const*)); + void RxHandler(void(*)(RTP_t*), uint8_t); + void RxHandler(void(*)(void), uint8_t); + + void openSocket(uint8_t); + + template <class T> + void openSocket(T*, void(T::*)(RTP_t*), uint8_t); + + void openSocket(CommLink*, void(*)(void const*), uint8_t); // 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 void send(RTP_t&); - + void receive(RTP_t&); protected: @@ -58,35 +76,39 @@ // Thread IDs osThreadId _txID; osThreadId _rxID; - + std::vector<uint8_t> *_open_ports; private: // Used to help define the class's threads in the constructor friend void define_thread(osThreadDef_t&, void(*task)(void const *arg), osPriority, uint32_t, unsigned char*); - - MailHelper<RTP_t, COMM_MODULE_TX_QUEUE_SIZE> _txQueueHelper; - MailHelper<RTP_t, COMM_MODULE_RX_QUEUE_SIZE> _rxQueueHelper; // The working threads for handeling rx and tx data queues static void txThread(void const*); static void rxThread(void const*); + void ready(void); + + static bool isReady; + // Thread and Mail defintion data structures osThreadDef_t _txDef; osThreadDef_t _rxDef; osMailQDef_t _txQDef; osMailQDef_t _rxQDef; + // Mail helper objects + MailHelper<RTP_t, COMM_MODULE_TX_QUEUE_SIZE> _txQueueHelper; + MailHelper<RTP_t, COMM_MODULE_RX_QUEUE_SIZE> _rxQueueHelper; + CommLink *_link[COMM_MODULE_NBR_PORTS]; - + FunctionPointerRJ _rx_handles[COMM_MODULE_NBR_PORTS]; FunctionPointerRJ _tx_handles[COMM_MODULE_NBR_PORTS]; - static bool isReady; - - void ready(void); - + bool _txH_called; + bool _rxH_called; + // Ignore for now // bool _dynamic_stack;