modbus_adapter_operation_mode.cpp
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 
19 
20 #include <ros/time.h>
21 
22 #include <sstream>
23 #include <functional>
24 
25 namespace prbt_hardware_support
26 {
27 using std::placeholders::_1;
28 
31  , api_spec_(api_spec)
32  , filter_pipeline_(new FilterPipeline(nh, std::bind(&ModbusAdapterOperationMode::modbusMsgCallback, this, _1)))
33 {
34 }
35 
37 {
38  OperationModes op_mode;
39  op_mode.time_stamp = ros::Time::now();
40  op_mode.value = OperationModes::UNKNOWN;
41  return op_mode;
42 }
43 
44 void ModbusAdapterOperationMode::modbusMsgCallback(const ModbusMsgInStampedConstPtr& msg_raw)
45 {
47 
48  if (msg.isDisconnect())
49  {
51  return;
52  }
53 
54  try
55  {
56  msg.checkStructuralIntegrity();
57  }
59  {
60  ROS_ERROR_STREAM(ex.what());
62  return;
63  }
64 
65  if (msg.getVersion() != MODBUS_API_VERSION_REQUIRED)
66  {
67  std::ostringstream os;
68  os << "Received Modbus message of unsupported API Version: " << msg.getVersion()
69  << ", required Version: " << MODBUS_API_VERSION_REQUIRED;
70  os << "\n";
71  os << "Can not determine OperationMode from Modbus message.";
72  ROS_ERROR_STREAM(os.str());
74  return;
75  }
76 
77  updateOperationMode(msg.getTimeStampedOperationMode());
78 }
79 
80 } // namespace prbt_hardware_support
msg
void modbusMsgCallback(const ModbusMsgInStampedConstPtr &msg_raw)
Called whenever a new modbus messages arrives.
An abstraction of a series of filters which ensures that only Modbus messages with different timestam...
void updateOperationMode(const OperationModes &mode)
Stores the operation mode and publishes it, if it has changed.
Listens to the modbus_read topic and offers a service informing about the active operation mode...
Wrapper class to add semantic to a raw ModbusMsgInStamped.
ModbusAdapterOperationMode(ros::NodeHandle &nh, const ModbusApiSpec &api_spec)
Expection thrown upon construction of ModbusMsgWrapperBase of the message does not contain the requir...
static Time now()
#define ROS_ERROR_STREAM(args)
Publishes information on the active operation mode. Also offers a service for querying the operation ...
Specifies the meaning of the holding registers.


prbt_hardware_support
Author(s):
autogenerated on Sat May 16 2020 03:13:49