Skip to content

Commit 42e67f6

Browse files
committed
Dependency Injection for GroundStationCommunication
1 parent 3c349c2 commit 42e67f6

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

SystemManager/Src/SystemManager.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "sbus_defines.h"
1212
#include "sbus_receiver.hpp"
1313
#include "tim.h"
14+
#include "GroundStationCommunication.hpp"
1415

1516

1617
#define TIMEOUT_CYCLES 250000 // 25k = 1 sec fro testing 10/14/2023 => 250k = 10 sec
@@ -51,9 +52,23 @@ SystemManager::SystemManager()
5152
float pitchspeed = 0;
5253
float yawspeed = 0;
5354

55+
// Creating parameters for the GroundStationCommunication that will be passed to telemetryManager
56+
TMCircularBuffer* DMAReceiveBuffer = &(new TMCircularBuffer(rfd900_circular_buffer));
57+
58+
// the buffer that stores non_routine/low_priority bytes (ex. Battery Voltage) to be sent to the
59+
// ground station.
60+
uint8_t* lowPriorityTransmitBuffer = new uint8_t[RFD900_BUF_SIZE];
61+
62+
// the buffer that stores routine/high_priority bytes (ex. heading, general state data) to be
63+
// sent to the ground station.
64+
uint8_t* highPriorityTransmitBuffer = new uint8_t[RFD900_BUF_SIZE];
65+
66+
GroundStationCommunication GSC = new GroundStationCommunication(DMAReceiveBuffer, lowPriorityTransmitBuffer,
67+
highPriorityTransmitBuffer, RFD900_BUF_SIZE);
68+
5469
this->telemetryManager =
5570
new TelemetryManager(lat, lon, alt, relative_alt, vx, vy, vz, hdg, time_boot_ms, state,
56-
mode, roll, pitch, yaw, rollspeed, pitchspeed, yawspeed);
71+
mode, roll, pitch, yaw, rollspeed, pitchspeed, yawspeed, GSC);
5772
this->telemetryManager->init();
5873
// IDK WHERE SM PLANS TO DO THIS, BUT telemetryManager.update() NEEDS TO BE CALLED AT A SEMI
5974
// REGULAR INTERVAL AS IT DEALS WITH MESSAGE DECODING AND LOW PRIORITY DATA TRANSMISSION

TelemetryManager/Inc/TelemetryManager.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323

2424
class TelemetryManager {
2525
public:
26-
GroundStationCommunication GSC;
26+
2727
MavlinkTranslator MT;
2828
// the buffer that stores the bytes received from the ground station.
29-
TMCircularBuffer* DMAReceiveBuffer;
30-
// the buffer that stores non_routine/low_priority bytes (ex. Battery Voltage) to be sent to the
31-
// ground station.
32-
uint8_t* lowPriorityTransmitBuffer;
33-
// the buffer that stores routine/high_priority bytes (ex. heading, general state data) to be
34-
// sent to the ground station.
35-
uint8_t* highPriorityTransmitBuffer;
29+
30+
// The object that facilitates communication with the ground station (?)
31+
// I'm not 100% sure what GroundStationCommunication does
32+
GroundStationCommunication& GSC;
3633

3734
/*References to variables that contain the state of the drone (lat, lng, yaw, pitch, etc..).
3835
* They are updated by System Manager*/
@@ -137,7 +134,7 @@ class TelemetryManager {
137134
TelemetryManager(int32_t& lat, int32_t& lon, int32_t& alt, int32_t& relative_alt, int16_t& vx,
138135
int16_t& vy, int16_t& vz, uint16_t& hdg, int32_t& time_boot_ms,
139136
MAV_STATE& state, MAV_MODE_FLAG& mode, float& roll, float& pitch, float& yaw,
140-
float& rollspeed, float& pitchspeed, float& yawspeed);
137+
float& rollspeed, float& pitchspeed, float& yawspeed, GroundStationCommunication& GSC);
141138

142139
/**
143140
* @brief Destroy the Telemetry Manager object. Also destroys the FreeRTOS tasks associated with

TelemetryManager/Src/TelemetryManager.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ TelemetryManager::TelemetryManager(int32_t& lat, int32_t& lon, int32_t& alt, int
88
int16_t& vx, int16_t& vy, int16_t& vz, uint16_t& hdg,
99
int32_t& time_boot_ms, MAV_STATE& state, MAV_MODE_FLAG& mode,
1010
float& roll, float& pitch, float& yaw, float& rollspeed,
11-
float& pitchspeed, float& yawspeed)
12-
: DMAReceiveBuffer(new TMCircularBuffer(rfd900_circular_buffer)),
13-
lowPriorityTransmitBuffer(new uint8_t[RFD900_BUF_SIZE]),
14-
highPriorityTransmitBuffer(new uint8_t[RFD900_BUF_SIZE]),
15-
GSC(*DMAReceiveBuffer, lowPriorityTransmitBuffer, highPriorityTransmitBuffer,
16-
RFD900_BUF_SIZE),
11+
float& pitchspeed, float& yawspeed, GroundStationCommunication& GSC)
12+
: GSC(GSC)
1713
lat(lat),
1814
lon(lon),
1915
alt(alt),

0 commit comments

Comments
 (0)