modbus_msg_in_builder.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Pilz GmbH & Co. KG
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MODBUS_MSG_IN_BUILDER_H
19 #define MODBUS_MSG_IN_BUILDER_H
20 
21 #include <map>
22 
23 #include <std_msgs/MultiArrayLayout.h>
24 
25 #include <prbt_hardware_support/ModbusMsgInStamped.h>
28 
29 namespace prbt_hardware_support
30 {
38 {
39 public:
40  ModbusMsgInBuilder(const ModbusApiSpec& api_spec);
41 
42 public:
43  void setRegister(const unsigned int register_n, const uint16_t value);
44 
45  ModbusMsgInBuilder& setRunPermitted(const uint16_t run_permitted);
46  ModbusMsgInBuilder& setOperationMode(const uint16_t mode);
47  ModbusMsgInBuilder& setApiVersion(const uint16_t version);
48 
49  ModbusMsgInStampedPtr build(const ros::Time& time) const;
50 
51 public:
56  static ModbusMsgInStampedPtr createDefaultModbusMsgIn(const std_msgs::MultiArrayLayout::_data_offset_type& offset,
57  const RegCont& holding_register);
58 
59  static void setDefaultLayout(std_msgs::MultiArrayLayout* layout,
60  const std_msgs::MultiArrayLayout::_data_offset_type& offset,
61  const RegCont::size_type& size);
62 
63 private:
65  std::map<unsigned int, uint16_t> register_values_;
66 };
67 
68 // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
69 inline ModbusMsgInBuilder& ModbusMsgInBuilder::setRunPermitted(const uint16_t run_permitted)
70 {
72  return *this;
73 }
74 
76 {
78  return *this;
79 }
80 
82 {
84  return *this;
85 }
86 
87 inline void ModbusMsgInBuilder::setRegister(const unsigned int register_n, const uint16_t value)
88 {
89  register_values_[register_n] = value;
90 }
91 
92 } // namespace prbt_hardware_support
93 
94 #endif // MODBUS_MSG_IN_BUILDER_H
std::vector< uint16_t > RegCont
Convenience data type defining the data type for a collection of registers.
unsigned short getRegisterDefinition(const std::string &key) const
ModbusMsgInBuilder & setOperationMode(const uint16_t mode)
static const std::string OPERATION_MODE
ModbusMsgInBuilder(const ModbusApiSpec &api_spec)
static const std::string RUN_PERMITTED
static ModbusMsgInStampedPtr createDefaultModbusMsgIn(const std_msgs::MultiArrayLayout::_data_offset_type &offset, const RegCont &holding_register)
Creates a standard ModbusMsgIn which contains default values for all essential elements of the messag...
std::map< unsigned int, uint16_t > register_values_
Help on construction for ModbusMsgIn Messages.
ModbusMsgInStampedPtr build(const ros::Time &time) const
static void setDefaultLayout(std_msgs::MultiArrayLayout *layout, const std_msgs::MultiArrayLayout::_data_offset_type &offset, const RegCont::size_type &size)
void setRegister(const unsigned int register_n, const uint16_t value)
ModbusMsgInBuilder & setRunPermitted(const uint16_t run_permitted)
ModbusMsgInBuilder & setApiVersion(const uint16_t version)
Specifies the meaning of the holding registers.


prbt_hardware_support
Author(s):
autogenerated on Sat Jul 4 2020 03:11:50