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 <prbt_hardware_support/ModbusMsgInStamped.h>
21 #include <prbt_hardware_support/OperationModes.h>
25 
26 namespace prbt_hardware_support
27 {
28 
36 {
37 public:
38  ModbusMsgOperationModeWrapper(const ModbusMsgInStampedConstPtr& modbus_msg_raw, const ModbusApiSpec& api_spec);
39 
46  virtual void checkStructuralIntegrity() const override;
47 
53  int8_t getOperationMode() const;
54 
58  OperationModes getTimeStampedOperationMode() const;
59 
60 private:
61 
67  bool hasOperationMode() const;
68 };
69 
70 inline ModbusMsgOperationModeWrapper::ModbusMsgOperationModeWrapper(const ModbusMsgInStampedConstPtr& modbus_msg_raw,
71  const ModbusApiSpec& api_spec):
72  ModbusMsgWrapper(modbus_msg_raw, api_spec)
73 {
74 }
75 
77 {
78  return hasRegister(getApiSpec().getRegisterDefinition(modbus_api_spec::OPERATION_MODE));
79 }
80 
82 {
83  switch(getRegister(getApiSpec().getRegisterDefinition(modbus_api_spec::OPERATION_MODE)))
84  {
85  case 0:
86  return OperationModes::UNKNOWN;
87  case 1:
88  return OperationModes::T1;
89  case 2:
90  return OperationModes::T2;
91  case 3:
92  return OperationModes::AUTO;
93  default:
94  return OperationModes::UNKNOWN;
95  }
96 }
97 
99 {
100  OperationModes op_mode;
101  op_mode.time_stamp = getTimeStamp();
102  op_mode.value = getOperationMode();
103  return op_mode;
104 }
105 
107 {
109 
110  if(!hasOperationMode())
111  {
112  throw ModbusMsgOperationModeWrapperException("Received message does not contain information about the operation mode.");
113  }
114 }
115 
116 }
117 
118 #endif // MODBUS_MSG_OPERATION_MODE_WRAPPER_H
const ModbusApiSpec & getApiSpec() const
virtual void checkStructuralIntegrity() const override
Calls ModbusMsgWrapper::checkStructuralIntegrity().
uint16_t getRegister(uint32_t reg) const
virtual void checkStructuralIntegrity() const
Checks that the Modbus messages consists of all registers needed.
bool hasRegister(uint32_t reg) const
Check if a certain holding register is define in the Modbus message.
static const std::string OPERATION_MODE
Expection thrown upon construction of ModbusMsgOperationModeWrapper of the message does not contain t...
int8_t getOperationMode() const
Get the operation mode field from the Modbus message.
bool hasOperationMode() const
Check if the message contains a operation mode definition.
Wrapper class to add semantic to a raw ModbusMsgInStamped.
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 Tue Feb 2 2021 03:50:17