| pnd-cpp-sdk 1.4.4

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
10 namespace Pnd {
11
12 class GroupFeedback;
13 class GroupCommand;
14
15 using GroupFeedbackHandler = std::function<void(const GroupFeedback &)>;
16
21 class Group final {
22 public:
28 Group(PndGroupPtr group, float initial_feedback_frequency = 0.0f, int32_t initial_command_lifetime = 0);
29
33 ~Group() noexcept;
34
38 int size();
39
43 bool setCommandLifetimeMs(int32_t ms);
44
56 bool sendCommand(const GroupCommand &group_command);
57
69 bool sendFeedbackRequest(PndFeedbackCode feedbackCode = PndFeedbackAll);
70
86 bool getNextFeedback(GroupFeedback &feedback, int32_t timeout_ms = DEFAULT_TIMEOUT_MS);
87
97 bool setFeedbackFrequencyHz(float frequency);
98
102 float getFeedbackFrequencyHz();
103
107 void addFeedbackHandler(GroupFeedbackHandler handler);
108
112 void clearFeedbackHandlers();
113
117 PndFeedbackErrorPtr getError(int idx);
118
119 private:
123 PndGroupPtr internal_;
124
128 const int number_of_modules_;
129
133 std::mutex handler_lock_;
134
138 std::vector<GroupFeedbackHandler> handlers_;
139
143 friend void callbackWrapper(PndGroupFeedbackPtr group_feedback, void *user_data);
144
148 void callAttachedHandlers(PndGroupFeedbackPtr group_feedback);
149
150 public:
151 static const int32_t DEFAULT_TIMEOUT_MS = 500;
152};
153
154} // namespace Pnd
Pnd::GroupCommand
A list of Command objects appropriate for sending to a Group of modules; the size() must match the nu...
Definition groupCommand.hpp:14
Pnd::GroupFeedback
A list of Feedback objects that can be received from a Group of modules; the size() must match the nu...
Definition groupFeedback.hpp:13
Pnd::Group
Represents a group of physical Pnd actuator, and allows Command, Feedback, and Info objects to be sen...
Definition group.hpp:21
Pnd::Group::callbackWrapper
friend void callbackWrapper(PndGroupFeedbackPtr group_feedback, void *user_data)
Definition group.cpp:8
Pnd::Group::setCommandLifetimeMs
bool setCommandLifetimeMs(int32_t ms)
Sets the command lifetime for the modules in this group.
Definition group.cpp:40
Pnd::Group::sendFeedbackRequest
bool sendFeedbackRequest(PndFeedbackCode feedbackCode=PndFeedbackAll)
Requests feedback from the group.
Definition group.cpp:46
Pnd::Group::clearFeedbackHandlers
void clearFeedbackHandlers()
Definition group.cpp:67
Pnd::Group::getNextFeedback
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:50
Pnd::Group::getFeedbackFrequencyHz
float getFeedbackFrequencyHz()
Definition group.cpp:58
Pnd::Group::addFeedbackHandler
void addFeedbackHandler(GroupFeedbackHandler handler)
Definition group.cpp:60
Pnd::Group::getError
PndFeedbackErrorPtr getError(int idx)
Gets the actuator error message.
Definition group.cpp:73
Pnd::Group::~Group
~Group() noexcept
Destructor cleans up group.
Definition group.cpp:32
Pnd::Group::setFeedbackFrequencyHz
bool setFeedbackFrequencyHz(float frequency)
Sets the frequency of the internal feedback request + callback thread.
Definition group.cpp:54
Pnd::Group::sendCommand
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:42
Pnd::Group::size
int size()
Returns the number of modules in the group.
Definition group.cpp:38