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 
28 
30 {
36 {
37 public:
38  ScannerConfigurationBuilder(const std::string& scanner_ip); // IP is mandatory
40 
41 public:
42  ScannerConfigurationBuilder& hostIP(const std::string& host_ip);
43  ScannerConfigurationBuilder& hostDataPort(const int& host_data_port);
44  ScannerConfigurationBuilder& hostControlPort(const int& host_control_port);
45  ScannerConfigurationBuilder& scannerIp(const std::string& scanner_ip);
46  ScannerConfigurationBuilder& scannerDataPort(const int& scanner_data_port);
47  ScannerConfigurationBuilder& scannerControlPort(const int& scanner_control_port);
53  ScannerConfigurationBuilder& nrSubscribers(const uint8_t& nr_subscribers);
54  operator ScannerConfiguration();
55 
56 private:
57  static uint16_t convertPort(const int& port);
58 
59 private:
61 };
62 
64 {
65  scannerIp(scanner_ip);
66 }
67 
69 {
70  if (!config_.isComplete())
71  {
72  throw std::runtime_error("Scanner configuration not complete");
73  }
74  else if (!config_.isValid())
75  {
76  throw std::invalid_argument("Scanner configuration not valid");
77  }
78 
79  return config_;
80 }
81 
83 {
84  if (!ip.empty() && ip != "auto")
85  {
86  config_.host_ip_ = util::convertIP(ip);
87  }
88  return *this;
89 }
90 
92 {
94  return *this;
95 }
96 
98 {
100  return *this;
101 }
102 
104 {
105  config_.scanner_ip_ = util::convertIP(ip);
106  return *this;
107 }
108 
110 {
112  return *this;
113 }
114 
116 {
118  return *this;
119 }
120 
122 {
123  config_.scan_range_ = scan_range;
124  return *this;
125 }
126 
129 {
130  if (scan_resolution < util::TenthOfDegree(1) || scan_resolution > util::TenthOfDegree(100))
131  {
132  throw std::invalid_argument("Scan resolution has to be between 0.1 and 10 degrees.");
133  }
134  config_.scan_resolution_ = scan_resolution;
135  return *this;
136 }
137 
139 {
140  config_.diagnostics_enabled_ = enable;
141  return *this;
142 }
143 
145 {
146  config_.intensities_enabled_ = enable;
147  return *this;
148 }
149 
151 {
152  config_.fragmented_scans_ = enable;
153  return *this;
154 }
155 
157 {
158  if (nr_subscribers > configuration::MAX_NR_SUBSCRIBERS)
159  {
160  throw std::invalid_argument("No more than 3 subscribers are supported.");
161  }
162  config_.nr_subscribers_ = nr_subscribers;
163  return *this;
164 }
165 
166 ScannerConfigurationBuilder::operator ScannerConfiguration()
167 {
168  return build();
169 }
170 
171 } // namespace psen_scan_v2_standalone
172 
173 #endif // PSEN_SCAN_V2_STANDALONE_SCANNER_CONFIG_BUILDER_H
scan_range.h
psen_scan_v2_standalone::ScannerConfigurationBuilder::hostIP
ScannerConfigurationBuilder & hostIP(const std::string &host_ip)
Definition: scanner_config_builder.h:82
psen_scan_v2_standalone::ScannerConfigurationBuilder::ScannerConfigurationBuilder
ScannerConfigurationBuilder(const std::string &scanner_ip)
Definition: scanner_config_builder.h:63
ip_conversion.h
psen_scan_v2_standalone::ScannerConfigurationBuilder::nrSubscribers
ScannerConfigurationBuilder & nrSubscribers(const uint8_t &nr_subscribers)
Definition: scanner_config_builder.h:156
psen_scan_v2_standalone::ScannerConfiguration::scanner_control_port_
uint16_t scanner_control_port_
Definition: scanner_configuration.h:75
psen_scan_v2_standalone::configuration::MAX_NR_SUBSCRIBERS
static const int MAX_NR_SUBSCRIBERS
Definition: scanner_ids.h:40
psen_scan_v2_standalone::ScannerConfigurationBuilder::enableDiagnostics
ScannerConfigurationBuilder & enableDiagnostics(const bool &enable)
Definition: scanner_config_builder.h:138
psen_scan_v2_standalone::ScannerConfiguration::scanner_ip_
boost::optional< uint32_t > scanner_ip_
Definition: scanner_configuration.h:73
psen_scan_v2_standalone::ScannerConfiguration::fragmented_scans_
bool fragmented_scans_
Definition: scanner_configuration.h:82
scanner_configuration.h
psen_scan_v2_standalone::ScannerConfigurationBuilder::config_
ScannerConfiguration config_
Definition: scanner_config_builder.h:60
psen_scan_v2_standalone::ScannerConfigurationBuilder::convertPort
static uint16_t convertPort(const int &port)
psen_scan_v2_standalone::ScannerConfigurationBuilder::scanRange
ScannerConfigurationBuilder & scanRange(const ScanRange &scan_range)
Definition: scanner_config_builder.h:121
psen_scan_v2_standalone::ScannerConfiguration::host_ip_
boost::optional< uint32_t > host_ip_
Definition: scanner_configuration.h:69
psen_scan_v2_standalone::ScannerConfigurationBuilder::scanResolution
ScannerConfigurationBuilder & scanResolution(const util::TenthOfDegree &scan_resolution)
Definition: scanner_config_builder.h:128
psen_scan_v2_standalone::ScannerConfiguration::diagnostics_enabled_
bool diagnostics_enabled_
Definition: scanner_configuration.h:80
psen_scan_v2_standalone::ScannerConfigurationBuilder::build
ScannerConfiguration build() const
Definition: scanner_config_builder.h:68
psen_scan_v2_standalone::ScannerConfigurationBuilder::scannerDataPort
ScannerConfigurationBuilder & scannerDataPort(const int &scanner_data_port)
Definition: scanner_config_builder.h:109
psen_scan_v2_standalone::ScannerConfigurationBuilder::scannerIp
ScannerConfigurationBuilder & scannerIp(const std::string &scanner_ip)
Definition: scanner_config_builder.h:103
psen_scan_v2_standalone::ScannerConfigurationBuilder::enableIntensities
ScannerConfigurationBuilder & enableIntensities(const bool &enable)
Definition: scanner_config_builder.h:144
psen_scan_v2_standalone::ScannerConfigurationBuilder::scannerControlPort
ScannerConfigurationBuilder & scannerControlPort(const int &scanner_control_port)
Definition: scanner_config_builder.h:115
psen_scan_v2_standalone::ScannerConfiguration::isComplete
bool isComplete() const
Definition: scanner_configuration.h:86
psen_scan_v2_standalone::ScannerConfiguration::scan_resolution_
util::TenthOfDegree scan_resolution_
Definition: scanner_configuration.h:78
psen_scan_v2_standalone::util::convertPort
uint16_t convertPort(const int &port)
Definition: ip_conversion.h:62
psen_scan_v2_standalone::ScannerConfiguration::scanner_data_port_
uint16_t scanner_data_port_
Definition: scanner_configuration.h:74
scanner_ids.h
psen_scan_v2_standalone::ScannerConfigurationBuilder
Helper class to simplify/improve the construction of the psen_scan_v2_standalone::ScannerConfiguratio...
Definition: scanner_config_builder.h:35
psen_scan_v2_standalone
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
psen_scan_v2_standalone::ScannerConfiguration::scan_range_
boost::optional< ScanRange > scan_range_
Definition: scanner_configuration.h:77
psen_scan_v2_standalone::ScanRangeTemplated
Higher level data type storing the range in which the scanner takes measurements.
Definition: scan_range.h:31
psen_scan_v2_standalone::ScannerConfigurationBuilder::enableFragmentedScans
ScannerConfigurationBuilder & enableFragmentedScans(const bool &enable)
Definition: scanner_config_builder.h:150
angle_conversions.h
psen_scan_v2_standalone::ScannerConfiguration::host_control_port_
uint16_t host_control_port_
Definition: scanner_configuration.h:71
psen_scan_v2_standalone::ScannerConfigurationBuilder::hostDataPort
ScannerConfigurationBuilder & hostDataPort(const int &host_data_port)
Definition: scanner_config_builder.h:91
psen_scan_v2_standalone::util::TenthOfDegree
Helper class representing angles in tenth of degree.
Definition: tenth_of_degree.h:34
psen_scan_v2_standalone::ScannerConfiguration::intensities_enabled_
bool intensities_enabled_
Definition: scanner_configuration.h:81
psen_scan_v2_standalone::ScannerConfiguration::nr_subscribers_
uint8_t nr_subscribers_
Definition: scanner_configuration.h:83
psen_scan_v2_standalone::ScannerConfigurationBuilder::hostControlPort
ScannerConfigurationBuilder & hostControlPort(const int &host_control_port)
Definition: scanner_config_builder.h:97
psen_scan_v2_standalone::ScannerConfiguration::host_data_port_
uint16_t host_data_port_
Definition: scanner_configuration.h:70
psen_scan_v2_standalone::ScannerConfiguration
Higher level data type storing the configuration details of the scanner like scanner IP,...
Definition: scanner_configuration.h:34
psen_scan_v2_standalone::ScannerConfiguration::isValid
bool isValid() const
Definition: scanner_configuration.h:91


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Jun 22 2024 02:46:12