pnd-cpp-sdk 1.2.0
Loading...
Searching...
No Matches
group.hpp
1#pragma once
2
3#include <functional>
4#include <memory>
5#include <mutex>
6#include <vector>
7
8#include "aios.h"
9
10namespace Pnd {
11
12class GroupFeedback;
13class GroupCommand;
14
15using GroupFeedbackHandler = std::function<void(const GroupFeedback &)>;
16
21class Group final {
22 public:
28 Group(PndGroupPtr group, float initial_feedback_frequency = 0.0f,
29 int32_t initial_command_lifetime = 0);
30
34 ~Group() noexcept;
35
39 int size();
40
44 bool setCommandLifetimeMs(int32_t ms);
45
57 bool sendCommand(const GroupCommand &group_command);
58
71 PndFeedbackCode feedbackCode = PndFeedbackAll);
72
88 bool getNextFeedback(GroupFeedback &feedback,
89 int32_t timeout_ms = DEFAULT_TIMEOUT_MS);
90
100 bool setFeedbackFrequencyHz(float frequency);
101
106
110 void addFeedbackHandler(GroupFeedbackHandler handler);
111
116
120 PndFeedbackErrorPtr getError(int idx);
121
122 private:
126 PndGroupPtr internal_;
127
131 const int number_of_modules_;
132
136 std::mutex handler_lock_;
137
141 std::vector<GroupFeedbackHandler> handlers_;
142
146 friend void callbackWrapper(PndGroupFeedbackPtr group_feedback,
147 void *user_data);
148
152 void callAttachedHandlers(PndGroupFeedbackPtr group_feedback);
153
154 public:
155 static const int32_t DEFAULT_TIMEOUT_MS = 500;
156};
157
158} // namespace Pnd
A list of Command objects appropriate for sending to a Group of modules; the size() must match the nu...
Definition groupCommand.hpp:14
A list of Feedback objects that can be received from a Group of modules; the size() must match the nu...
Definition groupFeedback.hpp:13
Represents a group of physical Pnd actuator, and allows Command, Feedback, and Info objects to be sen...
Definition group.hpp:21
friend void callbackWrapper(PndGroupFeedbackPtr group_feedback, void *user_data)
Definition group.cpp:8
bool setCommandLifetimeMs(int32_t ms)
Sets the command lifetime for the modules in this group.
Definition group.cpp:43
bool sendFeedbackRequest(PndFeedbackCode feedbackCode=PndFeedbackAll)
Requests feedback from the group.
Definition group.cpp:52
void clearFeedbackHandlers()
Definition group.cpp:79
bool getNextFeedback(GroupFeedback &feedback, int32_t timeout_ms=DEFAULT_TIMEOUT_MS)
Returns the most recently stored feedback from a sent feedback request, or returns the next one recei...
Definition group.cpp:57
float getFeedbackFrequencyHz()
Definition group.cpp:67
void addFeedbackHandler(GroupFeedbackHandler handler)
Definition group.cpp:71
PndFeedbackErrorPtr getError(int idx)
Gets the actuator error message.
Definition group.cpp:85
~Group() noexcept
Destructor cleans up group.
Definition group.cpp:35
bool setFeedbackFrequencyHz(float frequency)
Sets the frequency of the internal feedback request + callback thread.
Definition group.cpp:62
bool sendCommand(const GroupCommand &group_command)
Send a command to the given group, requesting an acknowledgement of transmission to be sent back.
Definition group.cpp:47
int size()
Returns the number of modules in the group.
Definition group.cpp:41