parameters.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The urg_stamped Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SCIP2_RESPONSE_PARAMETERS_H
18 #define SCIP2_RESPONSE_PARAMETERS_H
19 
20 #include <boost/asio.hpp>
21 
22 #include <string>
23 #include <map>
24 
26 #include <scip2/logger.h>
27 #include <scip2/param.h>
28 
29 namespace scip2
30 {
31 class ResponseParams : public Response
32 {
33 public:
34  using Callback = boost::function<void(
35  const boost::posix_time::ptime&,
36  const std::string&,
37  const std::string&,
38  const std::map<std::string, std::string>&)>;
39 
40 protected:
42 
43 public:
44  virtual std::string getCommandCode() const = 0;
45  void operator()(
46  const boost::posix_time::ptime& time_read,
47  const std::string& echo_back,
48  const std::string& status,
49  std::istream& stream)
50  {
51  std::map<std::string, std::string> params;
52  if (status != "00")
53  {
54  if (cb_)
55  cb_(time_read, echo_back, status, params);
56  return;
57  }
58  std::string line;
59  while (std::getline(stream, line))
60  {
61  if (line.size() == 0)
62  break;
63 
64  const ParsedParam p = parseParamLine(line);
65  if (!p.parsed)
66  {
67  logger::error() << "Parameter decode error: " << p.error << std::endl;
68  return;
69  }
70  if (!p.checksum_matched)
71  {
72  logger::error() << "Checksum mismatch; parameters dropped: " << p.error << std::endl;
73  return;
74  }
75  params[p.key] = p.value;
76  }
77  if (cb_)
78  cb_(time_read, echo_back, status, params);
79  }
81  {
82  cb_ = cb;
83  }
84 };
85 
86 class ResponsePP : public ResponseParams
87 {
88 public:
89  std::string getCommandCode() const
90  {
91  return std::string("PP");
92  }
93 };
94 
95 class ResponseVV : public ResponseParams
96 {
97 public:
98  std::string getCommandCode() const
99  {
100  return std::string("VV");
101  }
102 };
103 
105 {
106 public:
107  std::string getCommandCode() const
108  {
109  return std::string("II");
110  }
111 };
112 
113 } // namespace scip2
114 
115 #endif // SCIP2_RESPONSE_PARAMETERS_H
scip2::ResponseParams::cb_
Callback cb_
Definition: parameters.h:41
scip2::ResponsePP
Definition: parameters.h:86
scip2::Response
Definition: abstract.h:27
scip2::ResponseParams::registerCallback
void registerCallback(Callback cb)
Definition: parameters.h:80
logger.h
scip2::ResponseParams::Callback
boost::function< void(const boost::posix_time::ptime &, const std::string &, const std::string &, const std::map< std::string, std::string > &)> Callback
Definition: parameters.h:38
scip2::ParsedParam::key
std::string key
Definition: param.h:30
scip2::ParsedParam::value
std::string value
Definition: param.h:31
scip2::ResponseParams::getCommandCode
virtual std::string getCommandCode() const =0
scip2::ResponseVV
Definition: parameters.h:95
scip2
Definition: connection.h:30
scip2::ParsedParam::error
std::string error
Definition: param.h:32
scip2::ResponseII
Definition: parameters.h:104
scip2::parseParamLine
static ParsedParam parseParamLine(const std::string &line)
Definition: param.h:41
param.h
params
std::vector< urg_sim::URGSimulator::Params > params({ { .model=urg_sim::URGSimulator::Model::UTM,.boot_duration=0.01,.comm_delay_base=0.0002,.comm_delay_sigma=0.0004,.scan_interval=0.02505,.clock_rate=1.0,.hex_ii_timestamp=false,.angle_resolution=1440,.angle_min=0,.angle_max=1080,.angle_front=540, }, { .model=urg_sim::URGSimulator::Model::UTM,.boot_duration=0.01,.comm_delay_base=0.0002,.comm_delay_sigma=0.0004,.scan_interval=0.02505,.clock_rate=1.001,.hex_ii_timestamp=false,.angle_resolution=1440,.angle_min=0,.angle_max=1080,.angle_front=540, }, { .model=urg_sim::URGSimulator::Model::UTM,.boot_duration=0.01,.comm_delay_base=0.0002,.comm_delay_sigma=0.0004,.scan_interval=0.02505,.clock_rate=0.999,.hex_ii_timestamp=false,.angle_resolution=1440,.angle_min=0,.angle_max=1080,.angle_front=540, }, { .model=urg_sim::URGSimulator::Model::UST_UUST1,.boot_duration=0.01,.comm_delay_base=0.0005,.comm_delay_sigma=0.0005,.scan_interval=0.02505,.clock_rate=1.0,.hex_ii_timestamp=true,.angle_resolution=1440,.angle_min=0,.angle_max=1080,.angle_front=540, }, { .model=urg_sim::URGSimulator::Model::UST_UUST1,.boot_duration=0.01,.comm_delay_base=0.0005,.comm_delay_sigma=0.0005,.scan_interval=0.02505,.clock_rate=1.001,.hex_ii_timestamp=true,.angle_resolution=1440,.angle_min=0,.angle_max=1080,.angle_front=540, }, { .model=urg_sim::URGSimulator::Model::UST_UUST1,.boot_duration=0.01,.comm_delay_base=0.0005,.comm_delay_sigma=0.0005,.scan_interval=0.02505,.clock_rate=0.999,.hex_ii_timestamp=true,.angle_resolution=1440,.angle_min=0,.angle_max=1080,.angle_front=540, }, { .model=urg_sim::URGSimulator::Model::UST_UUST2,.boot_duration=0.01,.comm_delay_base=0.0002,.comm_delay_sigma=0.0002,.scan_interval=0.02505,.clock_rate=1.0,.hex_ii_timestamp=true,.angle_resolution=1440,.angle_min=0,.angle_max=1080,.angle_front=540, }, { .model=urg_sim::URGSimulator::Model::UST_UUST2,.boot_duration=0.01,.comm_delay_base=0.0002,.comm_delay_sigma=0.0002,.scan_interval=0.02505,.clock_rate=1.001,.hex_ii_timestamp=true,.angle_resolution=1440,.angle_min=0,.angle_max=1080,.angle_front=540, }, { .model=urg_sim::URGSimulator::Model::UST_UUST2,.boot_duration=0.01,.comm_delay_base=0.0002,.comm_delay_sigma=0.0002,.scan_interval=0.02505,.clock_rate=0.999,.hex_ii_timestamp=true,.angle_resolution=1440,.angle_min=0,.angle_max=1080,.angle_front=540, }, })
scip2::ResponseParams::operator()
void operator()(const boost::posix_time::ptime &time_read, const std::string &echo_back, const std::string &status, std::istream &stream)
Definition: parameters.h:45
scip2::ParsedParam::parsed
bool parsed
Definition: param.h:28
scip2::ParsedParam
Definition: param.h:26
scip2::ParsedParam::checksum_matched
bool checksum_matched
Definition: param.h:29
scip2::ResponsePP::getCommandCode
std::string getCommandCode() const
Definition: parameters.h:89
abstract.h
scip2::ResponseParams
Definition: parameters.h:31
scip2::ResponseVV::getCommandCode
std::string getCommandCode() const
Definition: parameters.h:98
scip2::ResponseII::getCommandCode
std::string getCommandCode() const
Definition: parameters.h:107
scip2::logger::error
std::ostream & error()
Definition: logger.cpp:105


urg_stamped
Author(s): Atsushi Watanabe
autogenerated on Wed Dec 18 2024 03:10:57