Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit cfcbd14

Browse files
authored
Added GSC functionality (#56)
1 parent a152bff commit cfcbd14

File tree

5 files changed

+20
-36
lines changed

5 files changed

+20
-36
lines changed

Drivers/common/drivers_config/inc/drivers_config.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ extern SBUSReceiver* sbus_pointer;
1717
extern UARTDevice* pRFD900;
1818
extern CircularBuffer *rfd900_circular_buffer;
1919

20+
#define RFD900_BUF_SIZE 11200 // 40 * 280(max Mavlink message size)
21+
2022
#endif

Drivers/common/drivers_config/src/drivers_config.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ SBUSReceiver* sbus_pointer = &sbus_instance;
99
/*
1010
creating RFD900 instance
1111
*/
12-
const uint8_t RFD900_BUF_SIZE = 280;
1312
uint8_t rfd900_buf[RFD900_BUF_SIZE];
1413
CircularBuffer rfd900_circular_buffer_inst(rfd900_buf, RFD900_BUF_SIZE);
1514

TelemetryManager/Inc/GroundStationCommunication.hpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
* implementation.
2626
*/
2727
class GroundStationCommunication {
28+
private:
29+
uint8_t internalBuffer_[RFD900_BUF_SIZE];
30+
2831
public:
2932
/**
3033
* @brief Construct a new Ground Station Communication object. Do whatever needs to be done
@@ -37,14 +40,7 @@ class GroundStationCommunication {
3740
GroundStationCommunication(TMCircularBuffer& DMAReceiveBuffer, uint8_t* lowPriorityTransmitBuffer, uint8_t* highPriorityTransmitBuffer, int length);
3841
~GroundStationCommunication();
3942

40-
41-
/**
42-
* To make c++ happy while using rfd900_circular_buffer from drivers_config.hpp, we need to
43-
* create a pointer to the buffer. Then we dereference it.
44-
*/
45-
// TMCircularBuffer* DMAReceiveBufferPtr = new TMCircularBuffer(rfd900_circular_buffer);
46-
47-
/*
43+
/*
4844
* When the DMA interrupt is triggered the data should be stored in the DMAReceiveBuffer
4945
* IF there is space.
5046
*/
@@ -69,13 +65,6 @@ class GroundStationCommunication {
6965
* to the ground station
7066
*/
7167
void transmit(TMCircularBuffer& transmissionBuffer);
72-
73-
/**
74-
* @brief This is the Interrupt Service Routine (ISR) for when the RFD 900 receives data from
75-
* the ground station and stores bytes from the transmission into the GSC.DMAReceiveBuffer if
76-
* there is space. Otherwise the data is discarded.
77-
*/
78-
void receiveInterruptServiceRoutine();
7968
};
8069

8170
#endif // GROUNDSTATIONCOMMS_H

TelemetryManager/Inc/TMCircularBuffer.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ class TMCircularBuffer : public CircularBuffer {
5656
bool enqueue(MAVLinkByte byte);
5757

5858
/**
59-
* @brief Get the index of the last full message in the queue determined by the end flag
60-
* in the MAVLink message. This is so if we have a partial message in the queue because
61-
* an ISR was triggered while we were in the middle of enqueuing a message, we
62-
* only send completed messages and keep the partial message to be finished after the ISR.
59+
* @brief Get the number of bytes until the end of the last full message in the queue
60+
* determined by the end flag in the MAVLink message. This is so if we have a partial message
61+
* in the queue because an ISR was triggered while we were in the middle of enqueuing a message,
62+
* we only send completed messages and keep the partial message to be finished after the ISR.
6363
* These partial messages once filled will be sent during the next transmission.
6464
*
6565
* @return int The index of the last full message in the queue determined by the end flag

TelemetryManager/Src/GroundStationCommunication.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,18 @@ GroundStationCommunication::~GroundStationCommunication() {
2222

2323
void GroundStationCommunication::transmit(TMCircularBuffer &transmissionBuffer) {
2424
// START: Send the bytes in transmissionBuffer to the ground station via RFD900
25+
int bytesToTransmit = transmissionBuffer.bytesUntilLastMessageEnd();
26+
27+
if (bytesToTransmit > RFD900_BUF_SIZE) {
28+
bytesToTransmit = RFD900_BUF_SIZE;
29+
}
30+
31+
for (int i {0}; i < bytesToTransmit; ++i) {
32+
internalBuffer_[i] = transmissionBuffer.dequeue();
33+
}
34+
pRFD900->transmit(internalBuffer_, bytesToTransmit);
2535

2636
// END: Send the bytes in transmissionBuffer to the ground station via RFD900
2737

2838
return;
2939
}
30-
31-
void GroundStationCommunication::receiveInterruptServiceRoutine() {
32-
int bytesReceived = 0; // replace with actual number of bytes received
33-
34-
// if GSC.DMAReceiveBuffer has enough space for the new data add it
35-
// otherwise discard the data
36-
if (DMAReceiveBuffer.remainingMemory() > bytesReceived) {
37-
// add the new data to GSC.DMAReceiveBuffer
38-
} else {
39-
// discard the new data
40-
// not a great way to handle this, but it's a start
41-
}
42-
43-
// end of ISR
44-
return;
45-
}

0 commit comments

Comments
 (0)