1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

OP-1122 OP-1158 added facility to update a CRC with uavobject data (ground side)

This commit is contained in:
Philippe Renon 2014-01-12 15:08:12 +01:00
parent 48aa89d2e7
commit 78fabdd4c3
2 changed files with 25 additions and 2 deletions

View File

@ -26,9 +26,14 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "uavobject.h"
#include <utils/crc.h>
#include <QtEndian>
#include <QDebug>
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

View File

@ -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();