| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. | 
| 4 | ** Contact: http://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the QtSerialBus module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or later as published by the Free | 
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in | 
| 29 | ** the packaging of this file. Please review the following information to | 
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be | 
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. | 
| 32 | ** | 
| 33 | ** $QT_END_LICENSE$ | 
| 34 | ** | 
| 35 | ****************************************************************************/ | 
| 36 |  | 
| 37 | #ifndef QMODBUSDEVICEIDENTIFICATION_P_H | 
| 38 | #define QMODBUSDEVICEIDENTIFICATION_P_H | 
| 39 |  | 
| 40 | #include <QtCore/qmap.h> | 
| 41 | #include <QtCore/qmetatype.h> | 
| 42 | #include <QtSerialBus/qtserialbusglobal.h> | 
| 43 |  | 
| 44 | QT_BEGIN_NAMESPACE | 
| 45 |  | 
| 46 | class QModbusDeviceIdentification | 
| 47 | { | 
| 48 | public: | 
| 49 |     enum ObjectId { | 
| 50 |         /* Basic mandatory */ | 
| 51 |         VendorNameObjectId = 0x00, | 
| 52 |         ProductCodeObjectId = 0x01, | 
| 53 |         MajorMinorRevisionObjectId = 0x02, | 
| 54 |  | 
| 55 |         /* Regular optional */ | 
| 56 |         VendorUrlObjectId = 0x03, | 
| 57 |         ProductNameObjectId = 0x04, | 
| 58 |         ModelNameObjectId = 0x05, | 
| 59 |         UserApplicationNameObjectId = 0x06, | 
| 60 |         ReservedObjectId = 0x07, | 
| 61 |  | 
| 62 |         /* Extended optional */ | 
| 63 |         ProductDependentObjectId = 0x80, | 
| 64 |  | 
| 65 |         UndefinedObjectId = 0x100 | 
| 66 |     }; | 
| 67 |  | 
| 68 |     enum ReadDeviceIdCode { | 
| 69 |         BasicReadDeviceIdCode = 0x01, | 
| 70 |         RegularReadDeviceIdCode = 0x02, | 
| 71 |         ExtendedReadDeviceIdCode = 0x03, | 
| 72 |         IndividualReadDeviceIdCode = 0x04 | 
| 73 |     }; | 
| 74 |  | 
| 75 |     enum ConformityLevel { | 
| 76 |         BasicConformityLevel = 0x01, | 
| 77 |         RegularConformityLevel = 0x02, | 
| 78 |         ExtendedConformityLevel = 0x03, | 
| 79 |         BasicIndividualConformityLevel = 0x81, | 
| 80 |         RegularIndividualConformityLevel = 0x82, | 
| 81 |         ExtendedIndividualConformityLevel = 0x83 | 
| 82 |     }; | 
| 83 |  | 
| 84 |     QModbusDeviceIdentification() = default; | 
| 85 |  | 
| 86 |     bool isValid() const { | 
| 87 |         return !m_objects.value(akey: VendorNameObjectId).isEmpty() | 
| 88 |             && !m_objects.value(akey: ProductCodeObjectId).isEmpty() | 
| 89 |             && !m_objects.value(akey: MajorMinorRevisionObjectId).isEmpty(); | 
| 90 |     } | 
| 91 |  | 
| 92 |     QList<int> objectIds() const { return m_objects.keys(); } | 
| 93 |     void remove(uint objectId) { m_objects.remove(akey: objectId); } | 
| 94 |     bool contains(uint objectId) const { return m_objects.contains(akey: objectId); } | 
| 95 |  | 
| 96 |     bool insert(uint objectId, const QByteArray &data) { | 
| 97 |         if ((data.size() > 245) || (objectId >= ObjectId::UndefinedObjectId)) | 
| 98 |             return false; | 
| 99 |         m_objects[objectId] = data; | 
| 100 |         return true; | 
| 101 |     } | 
| 102 |     QByteArray value(uint objectId) const { return m_objects.value(akey: objectId); } | 
| 103 |  | 
| 104 |     ConformityLevel conformityLevel() const { return m_conformityLevel; } | 
| 105 |     void setConformityLevel(ConformityLevel level) { m_conformityLevel = level; } | 
| 106 |  | 
| 107 |     static Q_SERIALBUS_EXPORT QModbusDeviceIdentification fromByteArray(const QByteArray &ba); | 
| 108 |  | 
| 109 | private: | 
| 110 |     QMap<int, QByteArray> m_objects; | 
| 111 |     ConformityLevel m_conformityLevel = BasicConformityLevel; | 
| 112 | }; | 
| 113 | Q_DECLARE_TYPEINFO(QModbusDeviceIdentification, Q_MOVABLE_TYPE); | 
| 114 | Q_DECLARE_TYPEINFO(QModbusDeviceIdentification::ObjectId, Q_PRIMITIVE_TYPE); | 
| 115 | Q_DECLARE_TYPEINFO(QModbusDeviceIdentification::ReadDeviceIdCode, Q_PRIMITIVE_TYPE); | 
| 116 | Q_DECLARE_TYPEINFO(QModbusDeviceIdentification::ConformityLevel, Q_PRIMITIVE_TYPE); | 
| 117 |  | 
| 118 | QT_END_NAMESPACE | 
| 119 |  | 
| 120 | Q_DECLARE_METATYPE(QModbusDeviceIdentification) | 
| 121 |  | 
| 122 | #endif // QMODBUSDEVICEIDENTIFICATION_P_H | 
| 123 |  |