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 <prbt_hardware_support/ModbusMsgInStamped.h>
24 
25 namespace prbt_hardware_support
26 {
27 
28 static constexpr uint16_t REGISTER_VALUE_BRAKETEST_NOT_REQUIRED{0};
29 static constexpr uint16_t REGISTER_VALUE_BRAKETEST_REQUIRED{1};
30 
38 {
39 public:
40  ModbusMsgBrakeTestWrapper(const ModbusMsgInStampedConstPtr& modbus_msg_raw,
41  const ModbusApiSpec& api_spec);
42 
49  virtual void checkStructuralIntegrity() const override;
50 
56  IsBrakeTestRequiredResponse::_result_type getBrakeTestRequirementStatus() const;
57 
58 private:
59 
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 IsBrakeTestRequiredResponse::_result_type ModbusMsgBrakeTestWrapper::getBrakeTestRequirementStatus() const
80 {
81  switch(getRegister(getApiSpec().getRegisterDefinition(modbus_api_spec::BRAKETEST_REQUEST)))
82  {
84  return IsBrakeTestRequiredResponse::NOT_REQUIRED;
85 
87  return IsBrakeTestRequiredResponse::REQUIRED;
88 
89  default:
90  return IsBrakeTestRequiredResponse::UNKNOWN;
91  }
92 }
93 
95 {
97 
99  {
100  throw ModbusMsgBrakeTestWrapperException("Received message does not contain a brake test status.");
101  }
102 }
103 
104 }
105 
106 #endif // MODBUS_MSG_BRAKE_TEST_WRAPPER_H
const ModbusApiSpec & getApiSpec() const
uint16_t getRegister(uint32_t reg) const
static const std::string BRAKETEST_REQUEST
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 constexpr uint16_t REGISTER_VALUE_BRAKETEST_NOT_REQUIRED
Expection thrown upon construction of ModbusMsgBrakeTestWrapper of the message does not contain the r...
static constexpr uint16_t REGISTER_VALUE_BRAKETEST_REQUIRED
IsBrakeTestRequiredResponse::_result_type getBrakeTestRequirementStatus() const
Get the brake test required flag from the Modbus message.
bool hasBrakeTestRequiredFlag() const
Check if the message contains a brake test required definition.
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 Tue Feb 2 2021 03:50:17