scanner_config_builder.h
Go to the documentation of this file.
1 // Copyright (c) 2020-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 #ifndef PSEN_SCAN_V2_STANDALONE_SCANNER_CONFIG_BUILDER_H
17 #define PSEN_SCAN_V2_STANDALONE_SCANNER_CONFIG_BUILDER_H
18 
19 #include <cmath>
20 #include <stdexcept>
21 #include <string>
22 
27 
29 {
35 {
36 public:
37  ScannerConfigurationBuilder(const std::string& scanner_ip); // IP is mandatory
39 
40 public:
41  ScannerConfigurationBuilder& hostIP(const std::string& host_ip);
42  ScannerConfigurationBuilder& hostDataPort(const int& host_data_port);
43  ScannerConfigurationBuilder& hostControlPort(const int& host_control_port);
44  ScannerConfigurationBuilder& scannerIp(const std::string& scanner_ip);
45  ScannerConfigurationBuilder& scannerDataPort(const int& scanner_data_port);
46  ScannerConfigurationBuilder& scannerControlPort(const int& scanner_control_port);
52  operator ScannerConfiguration();
53 
54 private:
55  static uint16_t convertPort(const int& port);
56 
57 private:
59 };
60 
62 {
63  scannerIp(scanner_ip);
64 }
65 
67 {
68  if (!config_.isComplete())
69  {
70  throw std::runtime_error("Scanner configuration not complete");
71  }
72  else if (!config_.isValid())
73  {
74  throw std::invalid_argument("Scanner configuration not valid");
75  }
76 
77  return config_;
78 }
79 
81 {
82  if (!ip.empty() && ip != "auto")
83  {
84  config_.host_ip_ = util::convertIP(ip);
85  }
86  return *this;
87 }
88 
90 {
92  return *this;
93 }
94 
96 {
98  return *this;
99 }
100 
102 {
103  config_.scanner_ip_ = util::convertIP(ip);
104  return *this;
105 }
106 
108 {
110  return *this;
111 }
112 
114 {
116  return *this;
117 }
118 
120 {
121  config_.scan_range_ = scan_range;
122  return *this;
123 }
124 
127 {
128  if (scan_resolution < util::TenthOfDegree(1) || scan_resolution > util::TenthOfDegree(100))
129  {
130  throw std::invalid_argument("Scan resolution has to be between 0.1 and 10 degrees.");
131  }
132  config_.scan_resolution_ = scan_resolution;
133  return *this;
134 }
135 
137 {
138  config_.diagnostics_enabled_ = enable;
139  return *this;
140 }
141 
143 {
144  config_.intensities_enabled_ = enable;
145  return *this;
146 }
147 
149 {
150  config_.fragmented_scans_ = enable;
151  return *this;
152 }
153 
154 ScannerConfigurationBuilder::operator ScannerConfiguration()
155 {
156  return build();
157 }
158 
159 } // namespace psen_scan_v2_standalone
160 
161 #endif // PSEN_SCAN_V2_STANDALONE_SCANNER_CONFIG_BUILDER_H
ScannerConfigurationBuilder & hostIP(const std::string &host_ip)
ScannerConfigurationBuilder & scannerIp(const std::string &scanner_ip)
ScannerConfigurationBuilder & enableDiagnostics(const bool &enable)
uint16_t convertPort(const int &port)
Definition: ip_conversion.h:62
ScannerConfigurationBuilder & hostDataPort(const int &host_data_port)
Higher level data type storing the configuration details of the scanner like scanner IP...
ScannerConfigurationBuilder & scannerControlPort(const int &scanner_control_port)
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
static uint16_t convertPort(const int &port)
Higher level data type storing the range in which the scanner takes measurements. ...
Definition: scan_range.h:31
ScannerConfigurationBuilder & hostControlPort(const int &host_control_port)
ScannerConfigurationBuilder & scannerDataPort(const int &scanner_data_port)
ScannerConfigurationBuilder & enableIntensities(const bool &enable)
Helper class to simplify/improve the construction of the psen_scan_v2_standalone::ScannerConfiguratio...
ScannerConfigurationBuilder & scanRange(const ScanRange &scan_range)
ScannerConfigurationBuilder & scanResolution(const util::TenthOfDegree &scan_resolution)
ScannerConfigurationBuilder & enableFragmentedScans(const bool &enable)
Helper class representing angles in tenth of degree.


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