Jonathan Jones
/
Radios
Radio Structures in OOP
Diff: modules/CommModule/CommModule.cpp
- Revision:
- 2:7d523bdd2f50
- Child:
- 3:dc7e9c6bc26c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/CommModule/CommModule.cpp Sun Dec 28 06:05:17 2014 +0000 @@ -0,0 +1,113 @@ +#include "CommModule.h" +#include "ThreadHelper.h" + +// Set the class's constants for streamlined use in other areas of the code +const int CommModule::TX_QUEUE_SIZE = COMM_MODULE_TX_QUEUE_SIZE; +const int CommModule::RX_QUEUE_SIZE = COMM_MODULE_RX_QUEUE_SIZE; +const int CommModule::NBR_PORTS = COMM_MODULE_NBR_PORTS; + +// Default constructor +CommModule::CommModule() +{ + // [X] - 2 - Setup everything for RTP packets + + // [X] - 3 - Set the default radio link + + // [] - 4 - Define the tx/rx task threads and start their operations + + // [] - 4 - Setup the services for all of the ports (sockets) + + // Define the data queues [THESE ARE MACROS] + osMailQDef(_txQueue_, COMM_MODULE_TX_QUEUE_SIZE, RTP_t); + osMailQDef(_rxQueue_, COMM_MODULE_RX_QUEUE_SIZE, RTP_t); + + // [THIS CURRENTLY CAUSES AN MBED RUNTIME ERROR] + // Create the data queues + //_txQueue = osMailCreate(osMailQ(_txQueue_), NULL); + //_rxQueue = osMailCreate(osMailQ(_rxQueue_), NULL); + + // Outline the thread definitions + define_thread(_txDef, &CommModule::txThread); + define_thread(_rxDef, &CommModule::rxThread); + + // Create the thread and pass it a pointer to the created object + _txID = osThreadCreate(&_txDef, (void*)this); + _rxID = osThreadCreate(&_rxDef, (void*)this); + + // Set the default hardware link to nothing + _link = NULL; +} + +void CommModule::txThread(void const *arg) +{ + CommModule *inst = (CommModule*)arg; + + // Only continue past this point once at least one (1) hardware link is initialized + + while(1) { + // When a new RTP packet is put in the tx queue, begin operations (does nothing if no new data in queue) + osEvent evt = osMailGet(inst->_txQueue, osWaitForever); + + if (evt.status == osEventMail) { + + // Get a pointer to the packet's memory location + RTP_t *packet = (RTP_t*)evt.value.p; + + // Send the packet on the active communication link + inst->_link->sendPacket(packet); + + // Release the allocated memory once data is sent + osMailFree(inst->_txQueue, packet); + } + } +} + +void CommModule::rxThread(void const *arg) +{ + CommModule *inst = (CommModule*)arg; + + // Only continue past this point once at least one (1) hardware link is initialized + + // RTP_t p; + while(1) { + + // Wait until new data is placed in the class's rxQueue from a CommLink class + + /* + // Read a new packet from the active interface + link->receivePacket(&p); + + if (p.port) { + // write the received packet to it's respective port's queue + // rxQueue[p.port] + } + + if (callbacks[p.port]) { + // call the respective port's function for executing the correct task + // callbacks[p.port](&p); + } + */ + + } +} + + +void CommModule::setLink(CommLink *link) +{ + // Update the currently active hardware communication link + _link = link; +} + +void CommModule::openSocket(uint8_t portNbr, void(*task)(void const *arg)) +{ + // [] - 1 - Associate the given port number with the passed function pointer (set this in the class's variables) + + // [] - 2 - The function pointer should be called when a packet of its respective port number is received +} + +void CommModule::send(RTP_t& p) +{ + // [] - 1 - Place the passed packet into the txQueue + + // [] - 2 - Ensure that proper threads know that new information is available in the queue +} \ No newline at end of file