messages_parser.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017, 2018 Simon Rasmussen (refactor)
3  *
4  * Copyright 2015, 2016 Thomas Timm Andersen (original version)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 #include <vector>
22 #include "ur_modern_driver/log.h"
26 
27 class URMessageParser : public URParser<MessagePacket>
28 {
29 public:
30  bool parse(BinParser& bp, std::vector<unique_ptr<MessagePacket>>& results)
31  {
32  int32_t packet_size;
33  message_type type;
34  bp.parse(packet_size);
35  bp.parse(type);
36 
37  if (type != message_type::ROBOT_MESSAGE)
38  {
39  LOG_WARN("Invalid message type recieved: %u", static_cast<uint8_t>(type));
40  return false;
41  }
42 
43  uint64_t timestamp;
44  uint8_t source;
46 
47  bp.parse(timestamp);
48  bp.parse(source);
49  bp.parse(message_type);
50 
51  std::unique_ptr<MessagePacket> result;
52  bool parsed = false;
53 
54  switch (message_type)
55  {
57  {
58  VersionMessage* vm = new VersionMessage(timestamp, source);
59  parsed = vm->parseWith(bp);
60  result.reset(vm);
61  break;
62  }
63 
64  default:
65  return false;
66  }
67 
68  results.push_back(std::move(result));
69  return parsed;
70  }
71 };
robot_message_type
Definition: messages.h:26
message_type
Definition: state.h:41
void parse(T &val)
Definition: bin_parser.h:96
#define LOG_WARN(format,...)
Definition: log.h:34
bool parse(BinParser &bp, std::vector< unique_ptr< MessagePacket >> &results)
virtual bool parseWith(BinParser &bp)
Definition: messages.cpp:22


ur_modern_driver
Author(s): Thomas Timm Andersen, Simon Rasmussen
autogenerated on Fri Jun 26 2020 03:37:00