From 85e81a84a44c78aecae9bb5e6e829d71702fa76f Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Wed, 27 Aug 2014 21:09:50 -0700 Subject: [PATCH] Had to give up on bitfields --- src/uas/QGCUASFileManager.cc | 5 ++++- src/uas/QGCUASFileManager.h | 17 +++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/uas/QGCUASFileManager.cc b/src/uas/QGCUASFileManager.cc index 3541deaf5..ad07f3033 100644 --- a/src/uas/QGCUASFileManager.cc +++ b/src/uas/QGCUASFileManager.cc @@ -80,7 +80,7 @@ QGCUASFileManager::QGCUASFileManager(QObject* parent, UASInterface* uas, uint8_t _systemIdServer = _mav->getUASID(); // Make sure we don't have bad structure packing - Q_ASSERT(sizeof(RequestHeader) == 12); + Q_ASSERT(sizeof(RequestHeader) == 16); } /// @brief Calculates a 32 bit CRC for the specified request. @@ -95,6 +95,9 @@ quint32 QGCUASFileManager::crc32(Request* request, unsigned state) // Always calculate CRC with 0 initial CRC value quint32 crcSave = request->hdr.crc32; request->hdr.crc32 = 0; + request->hdr.padding[0] = 0; + request->hdr.padding[1] = 0; + request->hdr.padding[2] = 0; for (size_t i=0; i < cbData; i++) state = crctab[(state ^ data[i]) & 0xff] ^ (state >> 8); diff --git a/src/uas/QGCUASFileManager.h b/src/uas/QGCUASFileManager.h index 4c41eb34e..9571f11bf 100644 --- a/src/uas/QGCUASFileManager.h +++ b/src/uas/QGCUASFileManager.h @@ -75,16 +75,17 @@ public slots: protected: - /// @brief This is the fixed length portion of the protocol data. This structure is layed out such that it should not require - /// any special compiler packing to not consume extra space. + /// @brief This is the fixed length portion of the protocol data. Trying to pack structures across differing compilers is + /// questionable, so we pad the structure ourselves to 32 bit alignment which should get us what we want. struct RequestHeader { - uint16_t seqNumber; ///< sequence number for message - unsigned int session:4; ///< Session id for read and write commands - unsigned int opcode:4; ///< Command opcode - uint8_t size; ///< Size of data - uint32_t crc32; ///< CRC for entire Request structure, with crc32 set to 0 - uint32_t offset; ///< Offsets for List and Read commands + uint16_t seqNumber; ///< sequence number for message + uint8_t session; ///< Session id for read and write commands + uint8_t opcode; ///< Command opcode + uint8_t size; ///< Size of data + uint8_t padding[3]; + uint32_t crc32; ///< CRC for entire Request structure, with crc32 and padding set to 0 + uint32_t offset; ///< Offsets for List and Read commands }; struct Request -- 2.22.0