diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobject.cpp b/ground/openpilotgcs/src/plugins/uavobjects/uavobject.cpp index a43f893ef..275a9708b 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobject.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobject.cpp @@ -26,9 +26,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "uavobject.h" + +#include + #include #include +using namespace Utils; + // Constants #define UAVOBJ_ACCESS_SHIFT 0 #define UAVOBJ_GCS_ACCESS_SHIFT 1 @@ -54,6 +59,8 @@ UAVObject::UAVObject(quint32 objID, bool isSingleInst, const QString & name) this->instID = 0; this->isSingleInst = isSingleInst; this->name = name; + this->data = 0; + this->numBytes = 0; this->mutex = new QMutex(QMutex::Recursive); } @@ -163,7 +170,6 @@ void UAVObject::setCategory(const QString & category) this->category = category; } - /** * Get the total number of bytes of the object's data */ @@ -280,7 +286,8 @@ UAVObjectField *UAVObject::getField(const QString & name) } } // If this point is reached then the field was not found - qWarning() << "UAVObject::getField Non existant field" << name << "requested. This indicates a bug. Make sure you also have null checking for non-debug code."; + qWarning() << "UAVObject::getField Non existant field" << name << "requested." + << "This indicates a bug. Make sure you also have null checking for non-debug code."; return NULL; } @@ -319,6 +326,21 @@ qint32 UAVObject::unpack(const quint8 *dataIn) return numBytes; } +/** + * Update a CRC with the object data + * @returns The updated CRC + */ +quint8 UAVObject::updateCRC(quint8 crc) +{ + QMutexLocker locker(mutex); + + //crc = Crc::updateCRC(crc, (quint8 *) &objID, sizeof(objID)); + //crc = Crc::updateCRC(crc, (quint8 *) &instID, sizeof(instID)); + crc = Crc::updateCRC(crc, data, numBytes); + + return crc; +} + /** * Save the object data to the file. * The file will be created in the current directory diff --git a/ground/openpilotgcs/src/plugins/uavobjects/uavobject.h b/ground/openpilotgcs/src/plugins/uavobjects/uavobject.h index 4217992bf..9c34271c0 100644 --- a/ground/openpilotgcs/src/plugins/uavobjects/uavobject.h +++ b/ground/openpilotgcs/src/plugins/uavobjects/uavobject.h @@ -109,6 +109,7 @@ public: quint32 getNumBytes(); qint32 pack(quint8 *dataOut); qint32 unpack(const quint8 *dataIn); + quint8 updateCRC(quint8 crc = 0); bool save(); bool save(QFile & file); bool load();