diff options
author | Sze Howe Koh <szehowe.koh@gmail.com> | 2013-09-09 11:33:48 +0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-09 11:43:07 +0200 |
commit | a589ae4f2f525686efa9f031a82390433b0e606d (patch) | |
tree | 3b63f67555864b5a0b1d69ee64177e79515599e0 /src/nfc/qnearfieldtarget.cpp | |
parent | 4384387f9ec995fdcc7b2e2f4a2cd7e56142930e (diff) |
Move qNfcChecksum() definition into a .cpp file
The function is public; doesn't make sense to implement it in a private
header.
This patch also resolves the multiply-defined-symbols issue when trying
to build some Qt NFC autotests without the "QtNfc" namespace.
Change-Id: I4ba1dc31d93bb66454c7dcd043c18f81dc2ad680
Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
Diffstat (limited to 'src/nfc/qnearfieldtarget.cpp')
-rw-r--r-- | src/nfc/qnearfieldtarget.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/nfc/qnearfieldtarget.cpp b/src/nfc/qnearfieldtarget.cpp index f95d2ee1..542b66fe 100644 --- a/src/nfc/qnearfieldtarget.cpp +++ b/src/nfc/qnearfieldtarget.cpp @@ -130,13 +130,34 @@ QT_BEGIN_NAMESPACE_NFC */ /*! - \fn qNfcChecksum(const char *data, uint len) + \fn quint16 qNfcChecksum(const char *data, uint len) \relates QNearFieldTarget Returns the NFC checksum of the first \a len bytes of \a data. */ -#include "checksum_p.h" +// 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 +}; + +quint16 qNfcChecksum(const char *data, uint len) +{ + register 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; +} /*! \fn void QNearFieldTarget::disconnected() |