-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRocketLink.hpp
111 lines (94 loc) · 4.56 KB
/
RocketLink.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef ROCKETLINK_CORE_ROCKETLINK_HPP
#define ROCKETLINK_CORE_ROCKETLINK_HPP
#include "AVC/AVCProtocol.hpp"
#include "SCALPEL/Packet.hpp"
#include "PhysicalLayer/RadioInterface.hpp"
#include "Management/CommandManager.hpp"
#include "Management/TelemetryBuffer.hpp"
#include "Diagnostics/Diagnostics.hpp"
#include "API/Callbacks.hpp"
#include "Utils/Logger.hpp"
#include <thread>
#include <atomic>
#include <mutex>
#include <condition_variable>
#include <memory>
namespace RocketLink {
namespace Core {
/**
* @brief The RocketLink class serves as the main interface for the RocketLink package.
* It provides methods for initializing the communication system, sending commands,
* receiving telemetry data, and handling event callbacks.
*/
class RocketLink {
public:
/**
* @brief Constructs a RocketLink instance with the specified radio interface.
* @param radio A shared pointer to a RadioInterface implementation.
*/
explicit RocketLink(std::shared_ptr<Radio::RadioInterface> radio);
/**
* @brief Destructor to clean up resources and stop internal threads.
*/
~RocketLink();
/**
* @brief Initializes all components, including the selected radio module.
* Sets up necessary threads for handling communication.
* @return true on successful initialization, false otherwise.
*/
bool initialize();
/**
* @brief Queues a command for transmission to the rocket.
* @param cmd The Command object to send.
* @return true if the command is successfully queued, false otherwise.
*/
bool sendCommand(const AVC::Command& cmd);
/**
* @brief Allows users to register callback functions for various events.
* @param callbacks Pointer to a Callbacks instance containing user-defined callbacks.
*/
void registerCallbacks(API::Callbacks* callbacks);
/**
* @brief Provides access to the latest telemetry data received from the rocket.
* @return The most recent Telemetry object.
*/
AVC::Telemetry getTelemetry();
private:
/**
* @brief The main loop for sending commands from the CommandManager.
* Encodes commands, packetizes them, and transmits via the RadioInterface.
*/
void sendLoop();
/**
* @brief The main loop for receiving telemetry data.
* Listens for incoming packets, decodes telemetry, and triggers callbacks.
*/
void receiveLoop();
/**
* @brief Handles events such as new telemetry data, command acknowledgments, or errors.
* Invokes the corresponding user-defined callback functions.
* @param event The event type to handle.
*/
void handleEvent(const std::string& event);
// Component instances
std::shared_ptr<AVC::AVCProtocol> avcProtocol; ///< Manages AVC protocol operations
SCALPEL::Packet packetHandler; ///< Handles SCALPEL packet operations
std::shared_ptr<Radio::RadioInterface> radio; ///< Abstracted radio interface
std::shared_ptr<AVC::CommandManager> commandManager; ///< Manages command queue and retransmissions
AVC::TelemetryBuffer telemetryBuffer; ///< Buffers incoming telemetry data
Diagnostics::Diagnostics diagnostics; ///< Collects diagnostic information
API::Callbacks* userCallbacks; ///< User-registered callbacks
Logger& logger; ///< Logger instance for logging events
// Thread management
std::thread sendThread; ///< Thread for sending commands
std::thread receiveThread; ///< Thread for receiving telemetry
std::atomic<bool> isRunning; ///< Flag to control the running state
// Synchronization primitives
std::mutex callbackMutex; ///< Mutex for protecting userCallbacks
std::mutex telemetryMutex; ///< Mutex for accessing telemetry data
std::condition_variable sendCondition; ///< Condition variable for sending thread
std::mutex sendMutex; // Added as per the code block to apply changes from
};
} // namespace Core
} // namespace RocketLink
#endif // ROCKETLINK_CORE_ROCKETLINK_HPP