| 1 | // Copyright (C) 2021 The Qt Company Ltd. | 
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | 
| 3 |  | 
| 4 | #ifndef QMODBUSCOMMEVENT_P_H | 
| 5 | #define QMODBUSCOMMEVENT_P_H | 
| 6 |  | 
| 7 | #include <QtSerialBus/qtserialbusglobal.h> | 
| 8 | #include <QtCore/private/qglobal_p.h> | 
| 9 |  | 
| 10 | // | 
| 11 | //  W A R N I N G | 
| 12 | //  ------------- | 
| 13 | // | 
| 14 | // This file is not part of the Qt API.  It exists purely as an | 
| 15 | // implementation detail.  This header file may change from version to | 
| 16 | // version without notice, or even be removed. | 
| 17 | // | 
| 18 | // We mean it. | 
| 19 | // | 
| 20 |  | 
| 21 | QT_BEGIN_NAMESPACE | 
| 22 |  | 
| 23 | class QModbusCommEvent | 
| 24 | { | 
| 25 | public: | 
| 26 |     enum struct SendFlag : quint8 { | 
| 27 |         ReadExceptionSent = 0x01, | 
| 28 |         ServerAbortExceptionSent = 0x02, | 
| 29 |         ServerBusyExceptionSent = 0x04, | 
| 30 |         ServerProgramNAKExceptionSent = 0x08, | 
| 31 |         WriteTimeoutErrorOccurred = 0x10, | 
| 32 |         CurrentlyInListenOnlyMode = 0x20, | 
| 33 |     }; | 
| 34 |  | 
| 35 |     enum struct ReceiveFlag : quint8 { | 
| 36 |         /* Unused */ | 
| 37 |         CommunicationError = 0x02, | 
| 38 |         /* Unused */ | 
| 39 |         /* Unused */ | 
| 40 |         CharacterOverrun = 0x10, | 
| 41 |         CurrentlyInListenOnlyMode = 0x20, | 
| 42 |         BroadcastReceived = 0x40 | 
| 43 |     }; | 
| 44 |  | 
| 45 |     enum EventByte { | 
| 46 |         SentEvent = 0x40, | 
| 47 |         ReceiveEvent = 0x80, | 
| 48 |         EnteredListenOnlyMode = 0x04, | 
| 49 |         InitiatedCommunicationRestart = 0x00 | 
| 50 |     }; | 
| 51 |  | 
| 52 |     constexpr QModbusCommEvent(QModbusCommEvent::EventByte byte) noexcept | 
| 53 |         : m_eventByte(byte) {} | 
| 54 |  | 
| 55 |     operator quint8() const { return m_eventByte; } | 
| 56 |     operator QModbusCommEvent::EventByte() const { | 
| 57 |         return static_cast<QModbusCommEvent::EventByte> (m_eventByte); | 
| 58 |     } | 
| 59 |  | 
| 60 |     inline QModbusCommEvent &operator=(QModbusCommEvent::EventByte byte) { | 
| 61 |         m_eventByte = byte; | 
| 62 |         return *this; | 
| 63 |     } | 
| 64 |     inline QModbusCommEvent &operator|=(QModbusCommEvent::SendFlag sf) { | 
| 65 |         m_eventByte |= quint8(sf); | 
| 66 |         return *this; | 
| 67 |     } | 
| 68 |     inline QModbusCommEvent &operator|=(QModbusCommEvent::ReceiveFlag rf) { | 
| 69 |         m_eventByte |= quint8(rf); | 
| 70 |         return *this; | 
| 71 |     } | 
| 72 |  | 
| 73 | private: | 
| 74 |     quint8 m_eventByte; | 
| 75 | }; | 
| 76 |  | 
| 77 | inline QModbusCommEvent::EventByte operator|(QModbusCommEvent::EventByte b, | 
| 78 |     QModbusCommEvent::SendFlag sf) { return QModbusCommEvent::EventByte(quint8(b) | quint8(sf)); } | 
| 79 | inline QModbusCommEvent::EventByte operator|(QModbusCommEvent::SendFlag sf, | 
| 80 |     QModbusCommEvent::EventByte b) { return operator|(b, sf); } | 
| 81 | inline QModbusCommEvent::EventByte operator|(QModbusCommEvent::EventByte b, | 
| 82 |     QModbusCommEvent::ReceiveFlag rf) { return QModbusCommEvent::EventByte(quint8(b) | quint8(rf)); } | 
| 83 | inline QModbusCommEvent::EventByte operator|(QModbusCommEvent::ReceiveFlag rf, | 
| 84 |     QModbusCommEvent::EventByte b) { return operator|(b, rf); } | 
| 85 |  | 
| 86 | QT_END_NAMESPACE | 
| 87 |  | 
| 88 | #endif // QMODBUSCOMMEVENT_P_H | 
| 89 |  |