control_package_setup_outputs.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2019 FZI Forschungszentrum Informatik
5 // Created on behalf of Universal Robots A/S
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // -- END LICENSE BLOCK ------------------------------------------------
19 
20 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 
30 
31 namespace urcl
32 {
33 namespace rtde_interface
34 {
36 {
37  if (protocol_version_ == 2)
38  {
41  }
42  else if (protocol_version_ == 1)
43  {
45  }
46  else
47  {
48  std::stringstream ss;
49  ss << "Unknown protocol version, protocol version is " << protocol_version_;
50  URCL_LOG_ERROR(ss.str().c_str());
51  return false;
52  }
53 
54  return true;
55 }
57 {
58  std::stringstream ss;
59  if (protocol_version_ == 2)
60  {
61  ss << "output recipe id: " << static_cast<int>(output_recipe_id_) << std::endl;
62  ss << "variable types: " << variable_types_;
63  }
64  else if (protocol_version_ == 1)
65  {
66  ss << "variable types: " << variable_types_;
67  }
68  else
69  {
70  ss << "Unknown protocol version, protocol version is " << protocol_version_ << std::endl;
71  }
72 
73  return ss.str();
74 }
75 
76 size_t ControlPackageSetupOutputsRequest::generateSerializedRequest(uint8_t* buffer, double output_frequency,
77  std::vector<std::string> variable_names)
78 {
79  if (variable_names.size() == 0)
80  {
81  return 0;
82  }
83  std::string variables;
84  for (const auto& piece : variable_names)
85  variables += (piece + ",");
86  variables.pop_back();
87  uint16_t payload_size = sizeof(double) + variables.size();
88 
89  size_t size = 0;
90  size += PackageHeader::serializeHeader(buffer, PACKAGE_TYPE, payload_size);
91  size += comm::PackageSerializer::serialize(buffer + size, output_frequency);
92  size += comm::PackageSerializer::serialize(buffer + size, variables);
93 
94  return size;
95 }
96 
98  std::vector<std::string> variable_names)
99 {
100  if (variable_names.size() == 0)
101  {
102  return 0;
103  }
104  std::string variables;
105  for (const auto& piece : variable_names)
106  variables += (piece + ",");
107  variables.pop_back();
108  uint16_t payload_size = variables.size();
109 
110  size_t size = 0;
111  size += PackageHeader::serializeHeader(buffer, PACKAGE_TYPE, payload_size);
112  size += comm::PackageSerializer::serialize(buffer + size, variables);
113 
114  return size;
115 }
116 
117 } // namespace rtde_interface
118 } // namespace urcl
static size_t generateSerializedRequest(uint8_t *buffer, double output_frequency, std::vector< std::string > variable_names)
Generates a serialized package.
virtual std::string toString() const
Produces a human readable representation of the package object.
#define URCL_LOG_ERROR(...)
Definition: log.h:26
void parse(T &val)
Parses the next bytes as given type.
Definition: bin_parser.h:139
void parseRemainder(std::string &val)
Parses the remaining bytes as a string.
Definition: bin_parser.h:255
The BinParser class handles a byte buffer and functionality to iteratively parse the content...
Definition: bin_parser.h:44
static size_t serialize(uint8_t *buffer, T val)
A generalized serialization method for arbitrary datatypes.
virtual bool parseWith(comm::BinParser &bp)
Sets the attributes of the package by parsing a serialized representation of the package.
static size_t serializeHeader(uint8_t *buffer, PackageType package_type, uint16_t payload_length)
Creates a serialization of a header based on given values.


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47