Jonathan Jones
/
Radios
Radio Structures in OOP
modules/CommLink/CommLink.cpp
- Committer:
- jjones646
- Date:
- 2014-12-28
- Revision:
- 2:7d523bdd2f50
- Child:
- 3:dc7e9c6bc26c
File content as of revision 2:7d523bdd2f50:
#include "CommLink.h" // Set the class's constants for streamlined use in other areas of the code const int CommLink::TX_QUEUE_SIZE = COMM_LINK_TX_QUEUE_SIZE; const int CommLink::RX_QUEUE_SIZE = COMM_LINK_RX_QUEUE_SIZE; // Default constructor CommLink::CommLink() { /* { // [] - 1 - Initialize the hardware for communication // [] - 2 - Create small tx & rx queues // The size allocations for each queue are dependent upon what interface that communication is occuring on (radio/serial/usb/etc.) // [] - 3 - Create and start thread operations for handeling data exchanges from the queues } */ // Disable interface by default _enabled = false; // Define the data queues [THESE ARE MACROS] osMailQDef(_txQueue, COMM_LINK_TX_QUEUE_SIZE, RTP_t); osMailQDef(_rxQueue, COMM_LINK_RX_QUEUE_SIZE, RTP_t); //osMailQId _rxQueue__; //osMailQId _txQueue__; // [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, &CommLink::txThread); define_thread(_rxDef, &CommLink::rxThread); // Create the thread and pass it a pointer to the created object _txID = osThreadCreate(&_txDef, (void*)this); _rxID = osThreadCreate(&_rxDef, (void*)this); } // Deconstructor CommLink::~CommLink() { } // Task operations for sending data over the hardware link when a new item is placed in the queue void CommLink::txThread(void const *arg) { CommLink *inst = (CommLink*)arg; // Only continue past this point once at least one (1) hardware link is initialized while(1) { // [] - 1 - Wait until the CommModule class sends a signal to begin operation on new data being placed in its txQueue // [] - 2 - Copy the packet from the CommModule txQueue into the CommLink txQueue // [] - 3 - Call the method for sending the packet over a hardware communication link // This should be done with the pure virtual method 1sendPacket(RTP_t* p)1 // 3 - Blink the TX LED for the hardware link } } // Task operations for placing received data into the received data queue void CommLink::rxThread(void const *arg) { CommLink *inst = (CommLink*)arg; // Only continue past this point once at least one (1) hardware link is initialized while(1) { // [] - 1 - Wait until new data is placed in the rxQueue before beginning any operations (the derived classes from CommLink are responsible for properly signaling when new data is present) // [] - 2 - Read the packet from the rxQueue and pass it to the CommModule class's rxQueue // [] - 3 - Signal to the CommModule class that a new packet has been received (this will begin operations for its rxThread) // [] - 4 - Blink the RX LED for the hardware link } } // Will enable/disable the currently active hardware communication link to ensure only one (1) perheripial is communicating at any given time // A static member variable might help here for tracking the active hardware communication links uint32_t CommLink::enable(bool en) { this->_enabled = en; return 1; }