diff options
author | Lars Schmertmann <Lars.Schmertmann@governikus.de> | 2016-12-25 19:28:52 +0100 |
---|---|---|
committer | Lars Schmertmann <lars.schmertmann@governikus.de> | 2017-01-14 11:19:12 +0000 |
commit | 44401721f66bdd72da197a14241a66fdb3d11cf4 (patch) | |
tree | 4f26e73d752099121f72746127103d9d0e95470c /src/nfc | |
parent | f9e85fb10a0560563e3106c4e8f6e269ece67659 (diff) |
Avoid code duplication by using checksum calculation from qtbase
Since qtbase supports checksum calculation defined in
ITU-V.41 an own implementation is not longer needed.
Change-Id: I0f62c872b4fb517493ba43a9bb7a6d35481fa40d
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/nfc')
-rw-r--r-- | src/nfc/qnearfieldtarget.cpp | 22 | ||||
-rw-r--r-- | src/nfc/qnearfieldtarget.h | 5 | ||||
-rw-r--r-- | src/nfc/qnearfieldtarget_emulator.cpp | 15 | ||||
-rw-r--r-- | src/nfc/targetemulator.cpp | 13 |
4 files changed, 20 insertions, 35 deletions
diff --git a/src/nfc/qnearfieldtarget.cpp b/src/nfc/qnearfieldtarget.cpp index 274ef175..ecd845f6 100644 --- a/src/nfc/qnearfieldtarget.cpp +++ b/src/nfc/qnearfieldtarget.cpp @@ -126,15 +126,7 @@ QT_BEGIN_NAMESPACE \value CommandError Failed to send a command to the target. */ -// Copied from qbytearray.cpp -// Modified to initialize the crc with 0x6363 instead of 0xffff and to not invert the final result. -static const quint16 crc_tbl[16] = { - 0x0000, 0x1081, 0x2102, 0x3183, - 0x4204, 0x5285, 0x6306, 0x7387, - 0x8408, 0x9489, 0xa50a, 0xb58b, - 0xc60c, 0xd68d, 0xe70e, 0xf78f -}; - +#if QT_DEPRECATED_SINCE(5, 9) /*! \relates QNearFieldTarget @@ -142,17 +134,9 @@ static const quint16 crc_tbl[16] = { */ quint16 qNfcChecksum(const char *data, uint len) { - quint16 crc = 0x6363; - uchar c; - const uchar *p = reinterpret_cast<const uchar *>(data); - while (len--) { - c = *p++; - crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)]; - c >>= 4; - crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)]; - } - return crc; + return qChecksum(data, len, Qt::ChecksumItuV41); } +#endif /*! \fn void QNearFieldTarget::disconnected() diff --git a/src/nfc/qnearfieldtarget.h b/src/nfc/qnearfieldtarget.h index 620ea813..040b9719 100644 --- a/src/nfc/qnearfieldtarget.h +++ b/src/nfc/qnearfieldtarget.h @@ -40,9 +40,10 @@ #ifndef QNEARFIELDTARGET_H #define QNEARFIELDTARGET_H -#include <QtCore/QObject> +#include <QtCore/QByteArray> #include <QtCore/QList> #include <QtCore/QMetaType> +#include <QtCore/QObject> #include <QtCore/QSharedDataPointer> #include <QtNfc/qnfcglobal.h> @@ -162,7 +163,9 @@ private: QNearFieldTargetPrivate *d_ptr; }; +#if QT_DEPRECATED_SINCE(5, 9) Q_NFC_EXPORT quint16 qNfcChecksum(const char * data, uint len); +#endif Q_DECLARE_OPERATORS_FOR_FLAGS(QNearFieldTarget::AccessMethods) diff --git a/src/nfc/qnearfieldtarget_emulator.cpp b/src/nfc/qnearfieldtarget_emulator.cpp index 96462b0d..29b1f74d 100644 --- a/src/nfc/qnearfieldtarget_emulator.cpp +++ b/src/nfc/qnearfieldtarget_emulator.cpp @@ -40,11 +40,12 @@ #include "qnearfieldtarget_emulator_p.h" #include "qnearfieldtarget_p.h" -#include <QtCore/QDirIterator> -#include <QtCore/QSettings> -#include <QtCore/QMutex> +#include <QtCore/QByteArray> #include <QtCore/QCoreApplication> #include <QtCore/QDateTime> +#include <QtCore/QDirIterator> +#include <QtCore/QMutex> +#include <QtCore/QSettings> QT_BEGIN_NAMESPACE @@ -87,7 +88,7 @@ QNearFieldTarget::RequestId TagType1::sendCommand(const QByteArray &command) return id; } - quint16 crc = qNfcChecksum(command.constData(), command.length()); + quint16 crc = qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41); QByteArray response = m_tag->processCommand(command + char(crc & 0xff) + char(crc >> 8)); @@ -99,7 +100,7 @@ QNearFieldTarget::RequestId TagType1::sendCommand(const QByteArray &command) } // check crc - if (qNfcChecksum(response.constData(), response.length()) != 0) { + if (qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41) != 0) { QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, Q_ARG(QNearFieldTarget::Error, ChecksumMismatchError), Q_ARG(QNearFieldTarget::RequestId, id)); @@ -157,7 +158,7 @@ QNearFieldTarget::RequestId TagType2::sendCommand(const QByteArray &command) return id; } - quint16 crc = qNfcChecksum(command.constData(), command.length()); + quint16 crc = qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41); QByteArray response = m_tag->processCommand(command + char(crc & 0xff) + char(crc >> 8)); @@ -166,7 +167,7 @@ QNearFieldTarget::RequestId TagType2::sendCommand(const QByteArray &command) if (response.length() > 1) { // check crc - if (qNfcChecksum(response.constData(), response.length()) != 0) { + if (qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41) != 0) { QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, Q_ARG(QNearFieldTarget::Error, ChecksumMismatchError), Q_ARG(QNearFieldTarget::RequestId, id)); diff --git a/src/nfc/targetemulator.cpp b/src/nfc/targetemulator.cpp index ffc2c1b5..80555593 100644 --- a/src/nfc/targetemulator.cpp +++ b/src/nfc/targetemulator.cpp @@ -44,9 +44,6 @@ #include <QtCore/QDebug> -// Implementation of qNfcChecksum -#include "qnearfieldtarget.h" - QT_BEGIN_NAMESPACE TagBase::TagBase() @@ -157,7 +154,7 @@ QByteArray NfcTagType1::processCommand(const QByteArray &command) QByteArray uid = command.mid(3, 4); // check checksum - if (qNfcChecksum(command.constData(), command.length()) != 0) + if (qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41) != 0) return QByteArray(); // check UID @@ -226,7 +223,7 @@ QByteArray NfcTagType1::processCommand(const QByteArray &command) QByteArray uid = command.mid(10, 4); // check checksum - if (qNfcChecksum(command.constData(), command.length()) != 0) + if (qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41) != 0) return QByteArray(); // check UID @@ -280,7 +277,7 @@ QByteArray NfcTagType1::processCommand(const QByteArray &command) } if (!response.isEmpty()) { - quint16 crc = qNfcChecksum(response.constData(), response.length()); + quint16 crc = qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41); response.append(quint8(crc & 0xff)); response.append(quint8(crc >> 8)); } @@ -324,7 +321,7 @@ QByteArray NfcTagType2::processCommand(const QByteArray &command) QByteArray response; // check checksum - if (qNfcChecksum(command.constData(), command.length()) != 0) + if (qChecksum(command.constData(), command.length(), Qt::ChecksumItuV41) != 0) return QByteArray(); if (expectPacket2) { @@ -381,7 +378,7 @@ QByteArray NfcTagType2::processCommand(const QByteArray &command) } if (!response.isEmpty()) { - quint16 crc = qNfcChecksum(response.constData(), response.length()); + quint16 crc = qChecksum(response.constData(), response.length(), Qt::ChecksumItuV41); response.append(quint8(crc & 0xff)); response.append(quint8(crc >> 8)); } |