From cfcbd14387c37d3cf9fa7639cf14a79af6e872d8 Mon Sep 17 00:00:00 2001 From: Roni Kant <35043400+Penguronik@users.noreply.github.com> Date: Sat, 6 Jul 2024 10:07:45 -0400 Subject: [PATCH] Added GSC functionality (#56) --- .../drivers_config/inc/drivers_config.hpp | 2 ++ .../drivers_config/src/drivers_config.cpp | 1 - .../Inc/GroundStationCommunication.hpp | 19 +++----------- TelemetryManager/Inc/TMCircularBuffer.hpp | 8 +++--- .../Src/GroundStationCommunication.cpp | 26 +++++++------------ 5 files changed, 20 insertions(+), 36 deletions(-) diff --git a/Drivers/common/drivers_config/inc/drivers_config.hpp b/Drivers/common/drivers_config/inc/drivers_config.hpp index 20d63a73..b1c25a27 100644 --- a/Drivers/common/drivers_config/inc/drivers_config.hpp +++ b/Drivers/common/drivers_config/inc/drivers_config.hpp @@ -17,4 +17,6 @@ extern SBUSReceiver* sbus_pointer; extern UARTDevice* pRFD900; extern CircularBuffer *rfd900_circular_buffer; +#define RFD900_BUF_SIZE 11200 // 40 * 280(max Mavlink message size) + #endif \ No newline at end of file diff --git a/Drivers/common/drivers_config/src/drivers_config.cpp b/Drivers/common/drivers_config/src/drivers_config.cpp index 6f290eeb..f37a0544 100644 --- a/Drivers/common/drivers_config/src/drivers_config.cpp +++ b/Drivers/common/drivers_config/src/drivers_config.cpp @@ -9,7 +9,6 @@ SBUSReceiver* sbus_pointer = &sbus_instance; /* creating RFD900 instance */ -const uint8_t RFD900_BUF_SIZE = 280; uint8_t rfd900_buf[RFD900_BUF_SIZE]; CircularBuffer rfd900_circular_buffer_inst(rfd900_buf, RFD900_BUF_SIZE); diff --git a/TelemetryManager/Inc/GroundStationCommunication.hpp b/TelemetryManager/Inc/GroundStationCommunication.hpp index 0470b2e2..b3c1e275 100644 --- a/TelemetryManager/Inc/GroundStationCommunication.hpp +++ b/TelemetryManager/Inc/GroundStationCommunication.hpp @@ -25,6 +25,9 @@ * implementation. */ class GroundStationCommunication { + private: + uint8_t internalBuffer_[RFD900_BUF_SIZE]; + public: /** * @brief Construct a new Ground Station Communication object. Do whatever needs to be done @@ -37,14 +40,7 @@ class GroundStationCommunication { GroundStationCommunication(TMCircularBuffer& DMAReceiveBuffer, uint8_t* lowPriorityTransmitBuffer, uint8_t* highPriorityTransmitBuffer, int length); ~GroundStationCommunication(); - - /** - * To make c++ happy while using rfd900_circular_buffer from drivers_config.hpp, we need to - * create a pointer to the buffer. Then we dereference it. - */ - // TMCircularBuffer* DMAReceiveBufferPtr = new TMCircularBuffer(rfd900_circular_buffer); - -/* + /* * When the DMA interrupt is triggered the data should be stored in the DMAReceiveBuffer * IF there is space. */ @@ -69,13 +65,6 @@ class GroundStationCommunication { * to the ground station */ void transmit(TMCircularBuffer& transmissionBuffer); - - /** - * @brief This is the Interrupt Service Routine (ISR) for when the RFD 900 receives data from - * the ground station and stores bytes from the transmission into the GSC.DMAReceiveBuffer if - * there is space. Otherwise the data is discarded. - */ - void receiveInterruptServiceRoutine(); }; #endif // GROUNDSTATIONCOMMS_H diff --git a/TelemetryManager/Inc/TMCircularBuffer.hpp b/TelemetryManager/Inc/TMCircularBuffer.hpp index 9ab5f41f..58badaa5 100644 --- a/TelemetryManager/Inc/TMCircularBuffer.hpp +++ b/TelemetryManager/Inc/TMCircularBuffer.hpp @@ -56,10 +56,10 @@ class TMCircularBuffer : public CircularBuffer { bool enqueue(MAVLinkByte byte); /** - * @brief Get the index of the last full message in the queue determined by the end flag - * in the MAVLink message. This is so if we have a partial message in the queue because - * an ISR was triggered while we were in the middle of enqueuing a message, we - * only send completed messages and keep the partial message to be finished after the ISR. + * @brief Get the number of bytes until the end of the last full message in the queue + * determined by the end flag in the MAVLink message. This is so if we have a partial message + * in the queue because an ISR was triggered while we were in the middle of enqueuing a message, + * we only send completed messages and keep the partial message to be finished after the ISR. * These partial messages once filled will be sent during the next transmission. * * @return int The index of the last full message in the queue determined by the end flag diff --git a/TelemetryManager/Src/GroundStationCommunication.cpp b/TelemetryManager/Src/GroundStationCommunication.cpp index b1413f76..be870fa3 100644 --- a/TelemetryManager/Src/GroundStationCommunication.cpp +++ b/TelemetryManager/Src/GroundStationCommunication.cpp @@ -22,24 +22,18 @@ GroundStationCommunication::~GroundStationCommunication() { void GroundStationCommunication::transmit(TMCircularBuffer &transmissionBuffer) { // START: Send the bytes in transmissionBuffer to the ground station via RFD900 + int bytesToTransmit = transmissionBuffer.bytesUntilLastMessageEnd(); + + if (bytesToTransmit > RFD900_BUF_SIZE) { + bytesToTransmit = RFD900_BUF_SIZE; + } + + for (int i {0}; i < bytesToTransmit; ++i) { + internalBuffer_[i] = transmissionBuffer.dequeue(); + } + pRFD900->transmit(internalBuffer_, bytesToTransmit); // END: Send the bytes in transmissionBuffer to the ground station via RFD900 return; } - -void GroundStationCommunication::receiveInterruptServiceRoutine() { - int bytesReceived = 0; // replace with actual number of bytes received - - // if GSC.DMAReceiveBuffer has enough space for the new data add it - // otherwise discard the data - if (DMAReceiveBuffer.remainingMemory() > bytesReceived) { - // add the new data to GSC.DMAReceiveBuffer - } else { - // discard the new data - // not a great way to handle this, but it's a start - } - - // end of ISR - return; -} \ No newline at end of file