rtde_parser.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019, FZI Forschungszentrum Informatik (refactor)
3  *
4  * Copyright 2017, 2018 Simon Rasmussen (refactor)
5  *
6  * Copyright 2015, 2016 Thomas Timm Andersen (original version)
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #pragma once
22 #include <vector>
26 
36 
37 namespace urcl
38 {
39 namespace rtde_interface
40 {
45 class RTDEParser : public comm::Parser<RTDEPackage>
46 {
47 public:
48  RTDEParser() = delete;
54  RTDEParser(const std::vector<std::string>& recipe) : recipe_(recipe), protocol_version_(1)
55  {
56  }
57  virtual ~RTDEParser() = default;
58 
68  bool parse(comm::BinParser& bp, std::vector<std::unique_ptr<RTDEPackage>>& results)
69 
70  {
72  PackageType type;
73  bp.parse(size);
74  bp.parse(type);
75 
76  if (!bp.checkSize(size - sizeof(size) - sizeof(type)))
77  {
78  URCL_LOG_ERROR("Buffer len shorter than expected packet length");
79  return false;
80  }
81 
82  switch (type)
83  {
85  {
86  std::unique_ptr<RTDEPackage> package(new DataPackage(recipe_));
87 
88  if (!package->parseWith(bp))
89  {
90  URCL_LOG_ERROR("Package parsing of type %d failed!", static_cast<int>(type));
91  return false;
92  }
93  results.push_back(std::move(package));
94  break;
95  }
96  default:
97  {
98  std::unique_ptr<RTDEPackage> package(packageFromType(type));
99  if (!package->parseWith(bp))
100  {
101  URCL_LOG_ERROR("Package parsing of type %d failed!", static_cast<int>(type));
102  return false;
103  }
104 
105  results.push_back(std::move(package));
106  break;
107  }
108  }
109  if (!bp.empty())
110  {
111  URCL_LOG_ERROR("Package of type %d was not parsed completely!", static_cast<int>(type));
112  bp.debug();
113  return false;
114  }
115 
116  return true;
117  }
118 
119  void setProtocolVersion(uint16_t protocol_version)
120  {
121  protocol_version_ = protocol_version;
122  }
123 
124 private:
125  std::vector<std::string> recipe_;
127  {
128  switch (type)
129  {
131  return new TextMessage(protocol_version_);
132  break;
134  return new GetUrcontrolVersion;
135  break;
137  return new RequestProtocolVersion;
138  break;
140  return new ControlPackagePause;
141  break;
143  return new ControlPackageSetupInputs;
144  break;
146  return new ControlPackageSetupOutputs;
147  break;
149  return new ControlPackageStart;
150  break;
151  default:
152  return new RTDEPackage(type);
153  }
154  }
156 };
157 
158 } // namespace rtde_interface
159 } // namespace urcl
void setProtocolVersion(uint16_t protocol_version)
Definition: rtde_parser.h:119
void debug()
Logs debugging information about the BinParser object.
Definition: bin_parser.h:369
#define URCL_LOG_ERROR(...)
Definition: log.h:37
void parse(T &val)
Parses the next bytes as given type.
Definition: bin_parser.h:139
This class handles the robot&#39;s response to a requested start in RTDE data package communication...
bool empty()
Checks if no unparsed bytes remain in the buffer.
Definition: bin_parser.h:361
The BinParser class handles a byte buffer and functionality to iteratively parse the content...
Definition: bin_parser.h:44
std::vector< std::string > recipe_
Definition: rtde_parser.h:125
This class handles RTDE text messages sent by the robot.
Definition: text_message.h:40
The parser is a general paser. The namsepace rtde_interface and primary_interface both iclude classes...
Definition: parser.h:36
PackageType
Possible package types.
This class handles the package detailing the UR control version sent by the robot.
bool checkSize(size_t bytes)
Checks if at least a given number of bytes is still remaining unparsed in the buffer.
Definition: bin_parser.h:339
bool parse(comm::BinParser &bp, std::vector< std::unique_ptr< RTDEPackage >> &results)
Uses the given BinParser to create package objects from the contained serialization.
Definition: rtde_parser.h:68
The RTDE specific parser. Interprets a given byte stream as serialized RTDE packages and parses it ac...
Definition: rtde_parser.h:45
This class handles the robot&#39;s response to a requested stop in RTDE data package communication.
This class handles the robot&#39;s response to a requested output recipe setup.
This class handles the robot&#39;s response after trying to set the used RTDE protocol version...
RTDEParser(const std::vector< std::string > &recipe)
Creates a new RTDEParser object, registering the used recipe.
Definition: rtde_parser.h:54
RTDEPackage * packageFromType(PackageType type)
Definition: rtde_parser.h:126
This class handles the robot&#39;s response to a requested input recipe setup.
The DataPackage class handles communication in the form of RTDE data packages both to and from the ro...
Definition: data_package.h:59


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Sun May 9 2021 02:16:26