Jonathan Jones
/
Radios
Radio Structures in OOP
Embed:
(wiki syntax)
Show/hide line numbers
CommModule.h
00001 #ifndef COMMUNICATION_MODULE_H 00002 #define COMMUNICATION_MODULE_H 00003 00004 #include "mbed.h" 00005 #include "cmsis_os.h" 00006 #include "RTP.h" 00007 #include "ThreadHelper.h" 00008 #include "MailHelper.h" 00009 #include "Logger.h" 00010 #include "FunctionPointerRJ.h" 00011 00012 #include <algorithm> // std::binary_search, std::sort 00013 #include <vector> 00014 00015 #define COMM_MODULE_TX_QUEUE_SIZE 20 00016 #define COMM_MODULE_RX_QUEUE_SIZE 4 00017 #define COMM_MODULE_NBR_PORTS 15 00018 #define COMM_MODULE_SIGNAL_START_THREAD 0x01 00019 00020 class CommLink; 00021 00022 // Base class for a communication module 00023 class CommModule 00024 { 00025 public: 00026 // Default Constructor 00027 CommModule(); 00028 00029 // Deconstructor 00030 virtual ~CommModule(); 00031 00032 // Class constants - set in CommModule.cpp 00033 static const int NBR_PORTS; 00034 static const int TX_QUEUE_SIZE; 00035 static const int RX_QUEUE_SIZE; 00036 00037 // Open a socket connection for communicating. 00038 template <typename T> 00039 void TxHandler(T *tptr, void(T::*mptr)(RTP_t*), uint8_t portNbr) { 00040 _txH_called = true; 00041 ready(); 00042 _tx_handles[portNbr].attach(tptr, mptr); 00043 } 00044 00045 template <typename T> 00046 void RxHandler(T *tptr, void(T::*mptr)(RTP_t*), uint8_t portNbr) { 00047 ready(); 00048 _rx_handles[portNbr].attach(tptr, mptr); 00049 } 00050 00051 void TxHandler(void(*)(RTP_t*), uint8_t); 00052 void RxHandler(void(*)(RTP_t*), uint8_t); 00053 00054 void RxHandler(void(*)(void), uint8_t); 00055 00056 void openSocket(uint8_t); 00057 00058 template <class T> 00059 void openSocket(T*, void(T::*)(RTP_t*), uint8_t); 00060 00061 void openSocket(CommLink*, void(*)(void const*), uint8_t); 00062 00063 // 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 00064 void send(RTP_t&); 00065 void receive(RTP_t&); 00066 00067 //osThreadId rxID(void); 00068 00069 protected: 00070 // NOP function for keeping a oommunication link active 00071 void nopFunc(void); 00072 00073 // Memory Queue IDs 00074 osMailQId _txQueue; 00075 osMailQId _rxQueue; 00076 00077 // Thread IDs 00078 osThreadId _txID; 00079 osThreadId _rxID; 00080 00081 std::vector<uint8_t> *_open_ports; 00082 00083 private: 00084 // Used to help define the class's threads in the constructor 00085 friend void define_thread(osThreadDef_t&, void(*task)(void const *arg), osPriority, uint32_t, unsigned char*); 00086 00087 // The working threads for handeling rx and tx data queues 00088 static void txThread(void const*); 00089 static void rxThread(void const*); 00090 00091 void ready(void); 00092 00093 static bool isReady; 00094 00095 // Thread and Mail defintion data structures 00096 osThreadDef_t _txDef; 00097 osThreadDef_t _rxDef; 00098 osMailQDef_t _txQDef; 00099 osMailQDef_t _rxQDef; 00100 00101 // Mail helper objects 00102 MailHelper<RTP_t, COMM_MODULE_TX_QUEUE_SIZE> _txQueueHelper; 00103 MailHelper<RTP_t, COMM_MODULE_RX_QUEUE_SIZE> _rxQueueHelper; 00104 00105 CommLink *_link[COMM_MODULE_NBR_PORTS]; 00106 00107 FunctionPointerRJ _rx_handles[COMM_MODULE_NBR_PORTS]; 00108 FunctionPointerRJ _tx_handles[COMM_MODULE_NBR_PORTS]; 00109 00110 bool _txH_called; 00111 00112 // Ignore for now 00113 // bool _dynamic_stack; 00114 00115 }; 00116 00117 #endif // COMMUNICATION_MODULE_H
Generated on Mon Jul 18 2022 20:09:01 by 1.7.2