modbus_msg_brake_test_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_BRAKE_TEST_WRAPPER_H
18 #define MODBUS_MSG_BRAKE_TEST_WRAPPER_H
19 
20 #include <pilz_msgs/IsBrakeTestRequired.h>
21 #include <pilz_msgs/IsBrakeTestRequiredResult.h>
22 
23 #include <prbt_hardware_support/ModbusMsgInStamped.h>
27 
28 namespace prbt_hardware_support
29 {
30 static constexpr uint16_t REGISTER_VALUE_BRAKETEST_NOT_REQUIRED{ 0 };
31 static constexpr uint16_t REGISTER_VALUE_BRAKETEST_REQUIRED{ 1 };
32 
40 {
41 public:
42  ModbusMsgBrakeTestWrapper(const ModbusMsgInStampedConstPtr& modbus_msg_raw, const ModbusApiSpec& api_spec);
43 
50  virtual void checkStructuralIntegrity() const override;
51 
57  pilz_msgs::IsBrakeTestRequiredResult::_value_type getBrakeTestRequirementStatus() const;
58 
59 private:
65  bool hasBrakeTestRequiredFlag() const;
66 };
67 
68 inline ModbusMsgBrakeTestWrapper::ModbusMsgBrakeTestWrapper(const ModbusMsgInStampedConstPtr& modbus_msg_raw,
69  const ModbusApiSpec& api_spec)
70  : ModbusMsgWrapper(modbus_msg_raw, api_spec)
71 {
72 }
73 
75 {
76  return hasRegister(getApiSpec().getRegisterDefinition(modbus_api_spec::BRAKETEST_REQUEST));
77 }
78 
79 inline pilz_msgs::IsBrakeTestRequiredResult::_value_type
81 {
82  switch (getRegister(getApiSpec().getRegisterDefinition(modbus_api_spec::BRAKETEST_REQUEST)))
83  {
85  return pilz_msgs::IsBrakeTestRequiredResult::NOT_REQUIRED;
86 
88  return pilz_msgs::IsBrakeTestRequiredResult::REQUIRED;
89 
90  default:
91  return pilz_msgs::IsBrakeTestRequiredResult::UNKNOWN;
92  }
93 }
94 
96 {
98 
100  {
101  throw ModbusMsgBrakeTestWrapperException("Received message does not contain a brake test status.");
102  }
103 }
104 
105 } // namespace prbt_hardware_support
106 
107 #endif // MODBUS_MSG_BRAKE_TEST_WRAPPER_H
bool hasRegister(uint32_t reg) const
Check if a certain holding register is define in the Modbus message.
static const std::string BRAKETEST_REQUEST
static constexpr uint16_t REGISTER_VALUE_BRAKETEST_NOT_REQUIRED
pilz_msgs::IsBrakeTestRequiredResult::_value_type getBrakeTestRequirementStatus() const
Get the brake test required flag from the Modbus message.
Expection thrown upon construction of ModbusMsgBrakeTestWrapper of the message does not contain the r...
uint16_t getRegister(uint32_t reg) const
virtual void checkStructuralIntegrity() const
Checks that the Modbus messages consists of all registers needed.
static constexpr uint16_t REGISTER_VALUE_BRAKETEST_REQUIRED
bool hasBrakeTestRequiredFlag() const
Check if the message contains a brake test required definition.
const ModbusApiSpec & getApiSpec() const
Wrapper class to add semantic to a raw ModbusMsgInStamped.
virtual void checkStructuralIntegrity() const override
Calls ModbusMsgWrapper::checkStructuralIntegrity().
ModbusMsgBrakeTestWrapper(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