ros2_canopen master
C++ ROS CANopen Library
Loading...
Searching...
No Matches
word_accessor.hpp
Go to the documentation of this file.
1// Copyright 2023 Christoph Hellmann Santos
2// Copyright 2014-2022 Authors of ros_canopen
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU 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 General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16//
17
18#ifndef WORD_ACCESSOR_HPP
19#define WORD_ACCESSOR_HPP
20
21#include <cstdint>
22
23namespace ros2_canopen
24{
25template <uint16_t MASK>
27{
28 uint16_t & word_;
29
30public:
31 WordAccessor(uint16_t & word) : word_(word) {}
32 bool set(uint8_t bit)
33 {
34 uint16_t val = MASK & (1 << bit);
35 word_ |= val;
36 return val;
37 }
38 bool reset(uint8_t bit)
39 {
40 uint16_t val = MASK & (1 << bit);
41 word_ &= ~val;
42 return val;
43 }
44 bool get(uint8_t bit) const { return word_ & (1 << bit); }
45 uint16_t get() const { return word_ & MASK; }
46 WordAccessor & operator=(const uint16_t & val)
47 {
48 word_ = (word_ & ~MASK) | (val & MASK);
49 return *this;
50 }
51};
52} // namespace ros2_canopen
53
54#endif // WORD_ACCESSOR_HPP
Definition word_accessor.hpp:27
bool reset(uint8_t bit)
Definition word_accessor.hpp:38
WordAccessor(uint16_t &word)
Definition word_accessor.hpp:31
bool set(uint8_t bit)
Definition word_accessor.hpp:32
bool get(uint8_t bit) const
Definition word_accessor.hpp:44
WordAccessor & operator=(const uint16_t &val)
Definition word_accessor.hpp:46
uint16_t get() const
Definition word_accessor.hpp:45
Definition configuration_manager.hpp:28