Radio Structures in OOP

Dependencies:   mbed mbed-rtos

Revision:
3:dc7e9c6bc26c
Parent:
2:7d523bdd2f50
Child:
4:989d51f3e6ef
--- a/modules/CommModule/CommModule.h	Sun Dec 28 06:05:17 2014 +0000
+++ b/modules/CommModule/CommModule.h	Sat Jan 03 04:35:32 2015 +0000
@@ -4,12 +4,20 @@
 #include "mbed.h"
 #include "cmsis_os.h"
 #include "RTP.h"
-#include "CommLink.h"
 #include "ThreadHelper.h"
+#include "MailHelper.h"
+#include "Logger.h"
+#include "FunctionPointerRJ.h"
 
-#define COMM_MODULE_TX_QUEUE_SIZE 20
-#define COMM_MODULE_RX_QUEUE_SIZE 4
-#define COMM_MODULE_NBR_PORTS 15
+#include <algorithm>    // std::binary_search, std::sort
+#include <vector>
+
+#define COMM_MODULE_TX_QUEUE_SIZE           20
+#define COMM_MODULE_RX_QUEUE_SIZE           4
+#define COMM_MODULE_NBR_PORTS               15
+#define COMM_MODULE_SIGNAL_START_THREAD     0x01
+
+class CommLink;
 
 // Base class for a communication module
 class CommModule
@@ -19,53 +27,69 @@
     CommModule();
 
     // Deconstructor
-    virtual ~CommModule() {};
-    
+    virtual ~CommModule();
+
     // Class constants - set in CommModule.cpp
     static const int NBR_PORTS;
     static const int TX_QUEUE_SIZE;
     static const int RX_QUEUE_SIZE;
 
-    // Let the CommModule class know of a hardware link that is can use for implementing communication
-    void setLink(CommLink*);
+    // Open a socket connection for communicating.
+    template <typename T>
+    void TxHandler(T*, void(T::*)(RTP_t*), uint8_t);
     
-    // Open a socket connection for communicating. 
-    void openSocket(uint8_t, void(*task)(void const *arg));
+    void TxHandler(void(*)(RTP_t*), uint8_t);
     
+    void openSocket(CommLink*, uint8_t, void(*)(void const*));
+
     // 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:
-    // Memory management using memory structures from the CMSIS-RTOS API
+    // NOP function for keeping a oommunication link active
+    void nopFunc(void);
+
+    // Memory Queue IDs
     osMailQId   _txQueue;
     osMailQId   _rxQueue;
 
-    // Used for storing the open socket's callback functions
-    // volatile CUSTOM callbacks[NBR_PORTS];
+    // 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*);
 
-    // NOP function for keeping a oommunication link active
-    void nopFunc(void);
-
-    // Pointer for maintaining the active communication link
-    CommLink*       _link;
-
-    // Thread definitions and IDs
+    // Thread and Mail defintion data structures
     osThreadDef_t   _txDef;
     osThreadDef_t   _rxDef;
-    osThreadId      _txID;
-    osThreadId      _rxID;
+    osMailQDef_t    _txQDef;
+    osMailQDef_t    _rxQDef;
 
+    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);
+    
     // Ignore for now
     // bool _dynamic_stack;
-    
+
 };
 
 #endif  // COMMUNICATION_MODULE_H