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 
28 using std::placeholders::_1;
29 
32  , api_spec_(api_spec)
33  , filter_pipeline_(new FilterPipeline(nh, std::bind(&ModbusAdapterOperationMode::modbusMsgCallback, this, _1 )) )
34 {
35 
36 }
37 
39 {
40  OperationModes op_mode;
41  op_mode.time_stamp = ros::Time::now();
42  op_mode.value = OperationModes::UNKNOWN;
43  return op_mode;
44 }
45 
46 void ModbusAdapterOperationMode::modbusMsgCallback(const ModbusMsgInStampedConstPtr& msg_raw)
47 {
49 
50  if (msg.isDisconnect())
51  {
53  return;
54  }
55 
56  try
57  {
58  msg.checkStructuralIntegrity();
59  }
61  {
62  ROS_ERROR_STREAM(ex.what());
64  return;
65  }
66 
67  if(msg.getVersion() != MODBUS_API_VERSION_REQUIRED)
68  {
69  std::ostringstream os;
70  os << "Received Modbus message of unsupported API Version: "
71  << msg.getVersion()
72  << ", required Version: " << MODBUS_API_VERSION_REQUIRED;
73  os <<"\n";
74  os << "Can not determine OperationMode from Modbus message.";
75  ROS_ERROR_STREAM(os.str());
77  return;
78  }
79 
80  updateOperationMode(msg.getTimeStampedOperationMode());
81 }
82 
83 } // 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 Tue Feb 2 2021 03:50:17