xml_configuration_parsing.h
Go to the documentation of this file.
1 // Copyright (c) 2021 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #include <string>
17 #include <stdexcept>
18 
19 #include <tinyxml2.h>
20 
22 
23 #ifndef PSEN_SCAN_V2_XML_CONFIGURATION_PARSER_H
24 #define PSEN_SCAN_V2_XML_CONFIGURATION_PARSER_H
25 
27 {
28 namespace configuration
29 {
34 namespace xml_config_parsing
35 {
36 class XMLConfigurationParserException : public std::runtime_error
37 {
38 public:
39  XMLConfigurationParserException(const std::string& msg) : std::runtime_error(msg)
40  {
41  }
42 };
43 
57 unsigned long ro_value_to_uint(const std::string& ro_value)
58 {
59  auto string_cpy = ro_value;
60  std::swap(string_cpy[0], string_cpy[2]);
61  std::swap(string_cpy[1], string_cpy[3]);
62  return std::stoul(string_cpy, nullptr, 16);
63 }
64 
74 std::vector<unsigned long> ro_string_to_vec(const std::string& ro_string)
75 {
76  std::vector<unsigned long> vec;
77 
78  try
79  {
80  for (size_t i = 0; i < ro_string.length(); i += 4)
81  {
82  const auto substr = ro_string.substr(i, 4);
83  if (substr.length() == 4)
84  {
85  vec.push_back(ro_value_to_uint(substr));
86  }
87  }
88  }
89  catch (const std::exception& e)
90  {
91  throw XMLConfigurationParserException(e.what());
92  }
93 
94  return vec;
95 }
96 
98 ZoneSetConfiguration parseString(const char* xml);
99 
100 } // namespace xml_config_parsing
101 } // namespace configuration
102 } // namespace psen_scan_v2_standalone
103 
104 #endif // PSEN_SCAN_V2_XML_CONFIGURATION_PARSER_H
filename
Contains the events needed to define and implement the scanner protocol.
unsigned long ro_value_to_uint(const std::string &ro_value)
Converts a quadrupel <ro> value into the respective length in mm.
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
std::vector< unsigned long > ro_string_to_vec(const std::string &ro_string)
Convert string from a <ro> element to values.


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Nov 5 2022 02:13:36