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
scan_range.h
psen_scan_v2_standalone::ScannerConfigurationBuilder::hostIP
ScannerConfigurationBuilder & hostIP(const std::string &host_ip)
Definition: scanner_config_builder.h:80
psen_scan_v2_standalone::ScannerConfigurationBuilder::ScannerConfigurationBuilder
ScannerConfigurationBuilder(const std::string &scanner_ip)
Definition: scanner_config_builder.h:61
ip_conversion.h
psen_scan_v2_standalone::ScannerConfiguration::scanner_control_port_
uint16_t scanner_control_port_
Definition: scanner_configuration.h:74
psen_scan_v2_standalone::ScannerConfigurationBuilder::enableDiagnostics
ScannerConfigurationBuilder & enableDiagnostics(const bool &enable)
Definition: scanner_config_builder.h:136
psen_scan_v2_standalone::ScannerConfiguration::scanner_ip_
boost::optional< uint32_t > scanner_ip_
Definition: scanner_configuration.h:72
psen_scan_v2_standalone::ScannerConfiguration::fragmented_scans_
bool fragmented_scans_
Definition: scanner_configuration.h:81
scanner_configuration.h
psen_scan_v2_standalone::ScannerConfigurationBuilder::config_
ScannerConfiguration config_
Definition: scanner_config_builder.h:58
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:119
psen_scan_v2_standalone::ScannerConfiguration::host_ip_
boost::optional< uint32_t > host_ip_
Definition: scanner_configuration.h:68
psen_scan_v2_standalone::ScannerConfigurationBuilder::scanResolution
ScannerConfigurationBuilder & scanResolution(const util::TenthOfDegree &scan_resolution)
Definition: scanner_config_builder.h:126
psen_scan_v2_standalone::ScannerConfiguration::diagnostics_enabled_
bool diagnostics_enabled_
Definition: scanner_configuration.h:79
psen_scan_v2_standalone::ScannerConfigurationBuilder::build
ScannerConfiguration build() const
Definition: scanner_config_builder.h:66
psen_scan_v2_standalone::ScannerConfigurationBuilder::scannerDataPort
ScannerConfigurationBuilder & scannerDataPort(const int &scanner_data_port)
Definition: scanner_config_builder.h:107
psen_scan_v2_standalone::ScannerConfigurationBuilder::scannerIp
ScannerConfigurationBuilder & scannerIp(const std::string &scanner_ip)
Definition: scanner_config_builder.h:101
psen_scan_v2_standalone::ScannerConfigurationBuilder::enableIntensities
ScannerConfigurationBuilder & enableIntensities(const bool &enable)
Definition: scanner_config_builder.h:142
psen_scan_v2_standalone::ScannerConfigurationBuilder::scannerControlPort
ScannerConfigurationBuilder & scannerControlPort(const int &scanner_control_port)
Definition: scanner_config_builder.h:113
psen_scan_v2_standalone::ScannerConfiguration::isComplete
bool isComplete() const
Definition: scanner_configuration.h:84
psen_scan_v2_standalone::ScannerConfiguration::scan_resolution_
util::TenthOfDegree scan_resolution_
Definition: scanner_configuration.h:77
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:73
psen_scan_v2_standalone::ScannerConfigurationBuilder
Helper class to simplify/improve the construction of the psen_scan_v2_standalone::ScannerConfiguratio...
Definition: scanner_config_builder.h:34
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:76
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:148
angle_conversions.h
psen_scan_v2_standalone::ScannerConfiguration::host_control_port_
uint16_t host_control_port_
Definition: scanner_configuration.h:70
psen_scan_v2_standalone::ScannerConfigurationBuilder::hostDataPort
ScannerConfigurationBuilder & hostDataPort(const int &host_data_port)
Definition: scanner_config_builder.h:89
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:80
psen_scan_v2_standalone::ScannerConfigurationBuilder::hostControlPort
ScannerConfigurationBuilder & hostControlPort(const int &host_control_port)
Definition: scanner_config_builder.h:95
psen_scan_v2_standalone::ScannerConfiguration::host_data_port_
uint16_t host_data_port_
Definition: scanner_configuration.h:69
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:89


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Nov 25 2023 03:46:26