modbus_msg_operation_mode_wrapper.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 #ifndef MODBUS_MSG_OPERATION_MODE_WRAPPER_H
18 #define MODBUS_MSG_OPERATION_MODE_WRAPPER_H
19 
20 #include <pilz_msgs/OperationModes.h>
21 
22 #include <prbt_hardware_support/ModbusMsgInStamped.h>
27 
28 namespace prbt_hardware_support
29 {
30 using namespace modbus_api::v3;
31 
39 {
40 public:
41  ModbusMsgOperationModeWrapper(const ModbusMsgInStampedConstPtr& modbus_msg_raw, const ModbusApiSpec& api_spec);
42 
49  virtual void checkStructuralIntegrity() const override;
50 
56  int8_t getOperationMode() const;
57 
61  pilz_msgs::OperationModes getTimeStampedOperationMode() const;
62 
63 private:
69  bool hasOperationMode() const;
70 };
71 
72 inline ModbusMsgOperationModeWrapper::ModbusMsgOperationModeWrapper(const ModbusMsgInStampedConstPtr& modbus_msg_raw,
73  const ModbusApiSpec& api_spec)
74  : ModbusMsgWrapper(modbus_msg_raw, api_spec)
75 {
76 }
77 
79 {
80  return hasRegister(getApiSpec().getRegisterDefinition(modbus_api_spec::OPERATION_MODE));
81 }
82 
84 {
85  switch (getRegister(getApiSpec().getRegisterDefinition(modbus_api_spec::OPERATION_MODE)))
86  {
88  return pilz_msgs::OperationModes::UNKNOWN;
90  return pilz_msgs::OperationModes::T1;
92  return pilz_msgs::OperationModes::T2;
94  return pilz_msgs::OperationModes::AUTO;
95  default:
96  return pilz_msgs::OperationModes::UNKNOWN;
97  }
98 }
99 
100 inline pilz_msgs::OperationModes ModbusMsgOperationModeWrapper::getTimeStampedOperationMode() const
101 {
102  pilz_msgs::OperationModes op_mode;
103  op_mode.time_stamp = getTimeStamp();
104  op_mode.value = getOperationMode();
105  return op_mode;
106 }
107 
109 {
111 
112  if (!hasOperationMode())
113  {
114  throw ModbusMsgOperationModeWrapperException("Received message does not contain information about the operation "
115  "mode.");
116  }
117 }
118 
119 } // namespace prbt_hardware_support
120 
121 #endif // MODBUS_MSG_OPERATION_MODE_WRAPPER_H
virtual void checkStructuralIntegrity() const override
Calls ModbusMsgWrapper::checkStructuralIntegrity().
bool hasRegister(uint32_t reg) const
Check if a certain holding register is define in the Modbus message.
int8_t getOperationMode() const
Get the operation mode field from the Modbus message.
static constexpr uint16_t MODBUS_OPERATION_MODE_T1
static constexpr uint16_t MODBUS_OPERATION_MODE_AUTO
static const std::string OPERATION_MODE
uint16_t getRegister(uint32_t reg) const
static constexpr uint16_t MODBUS_OPERATION_MODE_T2
Expection thrown upon construction of ModbusMsgOperationModeWrapper of the message does not contain t...
bool hasOperationMode() const
Check if the message contains a operation mode definition.
virtual void checkStructuralIntegrity() const
Checks that the Modbus messages consists of all registers needed.
const ModbusApiSpec & getApiSpec() const
Wrapper class to add semantic to a raw ModbusMsgInStamped.
static constexpr uint16_t MODBUS_OPERATION_MODE_NONE
ModbusMsgOperationModeWrapper(const ModbusMsgInStampedConstPtr &modbus_msg_raw, const ModbusApiSpec &api_spec)
Wrapper class to add semantic to a raw ModbusMsgInStamped.
Specifies the meaning of the holding registers.


prbt_hardware_support
Author(s):
autogenerated on Mon Feb 28 2022 23:14:34