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 
31 static constexpr uint16_t REGISTER_VALUE_BRAKETEST_NOT_REQUIRED{0};
32 static constexpr uint16_t REGISTER_VALUE_BRAKETEST_REQUIRED{1};
33 
41 {
42 public:
43  ModbusMsgBrakeTestWrapper(const ModbusMsgInStampedConstPtr& modbus_msg_raw,
44  const ModbusApiSpec& api_spec);
45 
52  virtual void checkStructuralIntegrity() const override;
53 
59  pilz_msgs::IsBrakeTestRequiredResult::_value_type getBrakeTestRequirementStatus() const;
60 
61 private:
62 
68  bool hasBrakeTestRequiredFlag() const;
69 };
70 
71 inline ModbusMsgBrakeTestWrapper::ModbusMsgBrakeTestWrapper(const ModbusMsgInStampedConstPtr& modbus_msg_raw,
72  const ModbusApiSpec& api_spec):
73 ModbusMsgWrapper(modbus_msg_raw, api_spec)
74 {
75 }
76 
78 {
79  return hasRegister(getApiSpec().getRegisterDefinition(modbus_api_spec::BRAKETEST_REQUEST));
80 }
81 
82 inline pilz_msgs::IsBrakeTestRequiredResult::_value_type ModbusMsgBrakeTestWrapper::getBrakeTestRequirementStatus() const
83 {
84  switch(getRegister(getApiSpec().getRegisterDefinition(modbus_api_spec::BRAKETEST_REQUEST)))
85  {
87  return pilz_msgs::IsBrakeTestRequiredResult::NOT_REQUIRED;
88 
90  return pilz_msgs::IsBrakeTestRequiredResult::REQUIRED;
91 
92  default:
93  return pilz_msgs::IsBrakeTestRequiredResult::UNKNOWN;
94  }
95 }
96 
98 {
100 
102  {
103  throw ModbusMsgBrakeTestWrapperException("Received message does not contain a brake test status.");
104  }
105 }
106 
107 }
108 
109 #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 Thu Feb 13 2020 03:16:51