TelemetryForwarder.cpp
Go to the documentation of this file.
4 
5 using namespace swarmros;
6 using namespace swarmros::bridge;
7 
9 {
10  if (message->GetType() == _message)
11  {
12  _telemetryService.SetValue(_name, message->GetValue());
13  }
14  else
15  {
16  throw MessageMismatchException("Invalid message type received from topic", _subscriber.getTopic(), _message, message->GetType());
17  }
18 }
19 
20 TelemetryForwarder::TelemetryForwarder(ros::NodeHandle& nodeHandle, const std::string& source, const std::string& message, swarmio::services::telemetry::Service& telemetryService, const std::string& name, bool includeInStatus)
21  : _telemetryService(telemetryService), _name(name)
22 {
23  // Register schema
24  const auto& serializer = introspection::MessageSerializer::MessageSerializerForType(message, "swarmros");
25  swarmio::data::discovery::Field fieldDescriptor;
26  *fieldDescriptor.mutable_schema() = serializer.GetSchemaDescriptor(serializer.HasHeader() ? 1 : 0);
27  _telemetryService.SetFieldDefinitionForKey(name, fieldDescriptor, includeInStatus);
28 
29  // Save message type
30  _message = serializer.GetFullName();
31 
32  // Subscribe
34 }
35 
37 {
38  // Stop subscription
40 
41  // Remove definition and value
44 }
void RemoveValue(const std::string &key)
Remove a value from the local telemetry cache.
swarmio::services::telemetry::Service & _telemetryService
Telemetry service.
Telemetry Service can subscribe to receive updates from remote nodes on named values.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
TelemetryForwarder(ros::NodeHandle &nodeHandle, const std::string &source, const std::string &message, swarmio::services::telemetry::Service &telemetryService, const std::string &name, bool includeInStatus)
Construct a new TelemetryForwarder object.
void SetValue(const std::string &key, const data::Variant &value)
Add or update a value in the local telemetry cache.
void SetFieldDefinitionForKey(const std::string &key, const data::discovery::Field &field, bool includeInStatus)
Add field to the schema.
static const MessageSerializer & MessageSerializerForType(const std::string &type, const std::string &parentPackage)
Look up or build a reader for a message type.
virtual ~TelemetryForwarder() override
Destroy the TelemetryForwarder object.
std::string _message
Message type.
std::string getTopic() const
void RemoveFieldDefinitionForKey(const std::string &key)
Remove a field from the schema.
Exception thrown when the expected type of a message does not match the actual type.
void UpdateReceived(const introspection::VariantMessage::ConstPtr &message)
Called whenever the topic is updated.
ros::Subscriber _subscriber
ROS topic subscriber.
std::string _name
Telemetry key.
VariantMessage implements an interface with the ROS type system to send and receive messages of any k...


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:48