Skip to content

Commit

Permalink
Added GSC functionality (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Penguronik authored Jul 6, 2024
1 parent a152bff commit cfcbd14
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 36 deletions.
2 changes: 2 additions & 0 deletions Drivers/common/drivers_config/inc/drivers_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion Drivers/common/drivers_config/src/drivers_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 4 additions & 15 deletions TelemetryManager/Inc/GroundStationCommunication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand All @@ -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
8 changes: 4 additions & 4 deletions TelemetryManager/Inc/TMCircularBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 10 additions & 16 deletions TelemetryManager/Src/GroundStationCommunication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit cfcbd14

Please sign in to comment.