CuteHMI - Modbus (CuteHMI.Modbus.4)
functions.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_INTERNAL_FUNCTIONS_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_INTERNAL_FUNCTIONS_HPP
3
4#include "common.hpp"
5
6#include <QtEndian>
7
8namespace cutehmi {
9namespace modbus {
10namespace internal {
11
12template <typename T>
14{
15 // Will use Qt endian functions, but need to assert that uchar is 8 bit wide. Qt implementation seems to be unaware that
16 // sizeof(char) == 1 byte == not necessarily 8 bits.
17 static_assert(std::numeric_limits<uchar>::digits == 8, "uchar must be 8 bit wide");
18
19 return qToBigEndian(src);
20}
21
22template <typename T>
24{
25 // Will use Qt endian functions, but need to assert that uchar is 8 bit wide. Qt implementation seems to be unaware that
26 // sizeof(char) == 1 byte == not necessarily 8 bits.
27 static_assert(std::numeric_limits<uchar>::digits == 8, "uchar must be 8 bit wide");
28
29 return qFromBigEndian(src);
30}
31
32template <typename T>
34{
35 // Will use Qt endian functions, but need to assert that uchar is 8 bit wide. Qt implementation seems to be unaware that
36 // sizeof(char) == 1 byte == not necessarily 8 bits.
37 static_assert(std::numeric_limits<uchar>::digits == 8, "uchar must be 8 bit wide");
38
39 return qToLittleEndian(src);
40}
41
42template <typename T>
44{
45 // Will use Qt endian functions, but need to assert that uchar is 8 bit wide. Qt implementation seems to be unaware that
46 // sizeof(char) == 1 byte == not necessarily 8 bits.
47 static_assert(std::numeric_limits<uchar>::digits == 8, "uchar must be 8 bit wide");
48
49 return qFromLittleEndian(src);
50}
51
61quint16 CUTEHMI_MODBUS_PRIVATE intToUint16(int value);
62
70quint16 CUTEHMI_MODBUS_PRIVATE int16ToUint16(qint16 value);
71
79qint16 CUTEHMI_MODBUS_PRIVATE int16FromUint16(quint16 value);
80
81}
82}
83}
84
85#endif
86
87//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
88//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
89//(c)C: This file is a part of CuteHMI.
90//(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
91//(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
92//(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
93//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
94//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
95//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
96//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
T internal(T... args)
T fromLittleEndian(T src)
Definition: functions.hpp:43
quint16 CUTEHMI_MODBUS_PRIVATE intToUint16(int value)
Store integer as 16 bit unsigned integer.
Definition: functions.cpp:11
T toLittleEndian(T src)
Definition: functions.hpp:33
qint16 CUTEHMI_MODBUS_PRIVATE int16FromUint16(quint16 value)
Restore 16 bit integer from 16 bit unsigned integer.
Definition: functions.cpp:38
T fromBigEndian(T src)
Definition: functions.hpp:23
T toBigEndian(T src)
Definition: functions.hpp:13
quint16 CUTEHMI_MODBUS_PRIVATE int16ToUint16(qint16 value)
Store 16 bit integer as 16 bit unsigned integer.
Definition: functions.cpp:22