2 ******************************************************************************
4 * @file uavobjectfield.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @see The GNU Public License (GPL) Version 3
7 * @addtogroup GCSPlugins GCS Plugins
9 * @addtogroup UAVObjectsPlugin UAVObjects Plugin
11 * @brief The UAVUObjects GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "uavobjectfield.h"
32 #include <QXmlStreamWriter>
33 #include <QXmlStreamReader>
34 #include <QJsonObject>
37 UAVObjectField::UAVObjectField(const QString
& name
, const QString
& description
, const QString
& units
, FieldType type
, quint32 numElements
, const QStringList
& options
, const QString
&limits
)
39 QStringList elementNames
;
42 for (quint32 n
= 0; n
< numElements
; ++n
) {
43 elementNames
.append(QString("%1").arg(n
));
46 constructorInitialize(name
, description
, units
, type
, elementNames
, options
, limits
);
49 UAVObjectField::UAVObjectField(const QString
& name
, const QString
& description
, const QString
& units
, FieldType type
, const QStringList
& elementNames
, const QStringList
& options
, const QString
&limits
)
51 constructorInitialize(name
, description
, units
, type
, elementNames
, options
, limits
);
54 void UAVObjectField::constructorInitialize(const QString
& name
, const QString
& description
, const QString
& units
, FieldType type
, const QStringList
& elementNames
, const QStringList
& options
, const QString
&limits
)
58 this->description
= description
;
61 this->options
= options
;
62 this->numElements
= elementNames
.length();
66 this->elementNames
= elementNames
;
70 numBytesPerElement
= sizeof(qint8
);
73 numBytesPerElement
= sizeof(qint16
);
76 numBytesPerElement
= sizeof(qint32
);
79 numBytesPerElement
= sizeof(quint8
);
82 numBytesPerElement
= sizeof(quint16
);
85 numBytesPerElement
= sizeof(quint32
);
88 numBytesPerElement
= sizeof(quint32
);
91 numBytesPerElement
= sizeof(quint8
);
94 numBytesPerElement
= sizeof(quint8
);
95 this->options
= QStringList() << tr("0") << tr("1");
98 numBytesPerElement
= sizeof(quint8
);
101 numBytesPerElement
= 0;
103 limitsInitialize(limits
);
106 void UAVObjectField::limitsInitialize(const QString
&limits
)
108 // Limit string format:
110 // XXXX - optional BOARD_TYPE and BOARD_REVISION (4 hex digits)
111 // TY - rule type (EQ-equal, NE-not equal, BE-between, BI-bigger, SM-smaller)
112 // VAL - values for TY separated by colon
113 // , - rule separator (may have leading or trailing spaces)
114 // ; - element separator (may have leading or trailing spaces)
117 // Disable few flight modes for Revo (00903):
118 // "%0903NE:Autotune:VelocityControl:PositionHold:ReturnToBase:Land:PathPlanner"
119 // Original CC board (rev 1), first element bigger than 3 and second element inside [2.3-5.0]:
120 // "%0401BI:3; %BE:2.3:5"
121 // Set applicable range [0-500] for 3 elements of array for all boards:
122 // "%BE:0:500; %BE:0:500; %BE:0:500"
123 if (limits
.isEmpty()) {
126 QStringList stringPerElement
= limits
.split(";");
128 foreach(QString str
, stringPerElement
) {
129 QStringList ruleList
= str
.split(",");
131 QList
<LimitStruct
> limitList
;
132 foreach(QString rule
, ruleList
) {
133 QString _str
= rule
.trimmed();
135 if (_str
.isEmpty()) {
138 QStringList valuesPerElement
= _str
.split(":");
140 bool startFlag
= valuesPerElement
.at(0).startsWith("%");
141 bool maxIndexFlag
= (int)(index
) < (int)numElements
;
142 bool elemNumberSizeFlag
= valuesPerElement
.at(0).size() == 3;
144 valuesPerElement
.at(0).mid(1, 4).toInt(&aux
, 16);
145 bool b4
= ((valuesPerElement
.at(0).size()) == 7 && aux
);
146 if (startFlag
&& maxIndexFlag
&& (elemNumberSizeFlag
|| b4
)) {
148 lstruc
.board
= valuesPerElement
.at(0).mid(1, 4).toInt(&aux
, 16);
152 if (valuesPerElement
.at(0).right(2) == "EQ") {
154 } else if (valuesPerElement
.at(0).right(2) == "NE") {
155 lstruc
.type
= NOT_EQUAL
;
156 } else if (valuesPerElement
.at(0).right(2) == "BE") {
157 lstruc
.type
= BETWEEN
;
158 } else if (valuesPerElement
.at(0).right(2) == "BI") {
159 lstruc
.type
= BIGGER
;
160 } else if (valuesPerElement
.at(0).right(2) == "SM") {
161 lstruc
.type
= SMALLER
;
163 qDebug() << "limits parsing failed (invalid property) on UAVObjectField" << name
;
165 valuesPerElement
.removeAt(0);
166 foreach(QString _value
, valuesPerElement
) {
167 QString value
= _value
.trimmed();
174 lstruc
.values
.append((quint32
)value
.toULong());
179 lstruc
.values
.append((qint32
)value
.toLong());
182 lstruc
.values
.append((float)value
.toFloat());
185 lstruc
.values
.append((QString
)value
);
188 lstruc
.values
.append((QString
)value
);
191 lstruc
.values
.append(QVariant());
194 limitList
.append(lstruc
);
196 if (!valuesPerElement
.at(0).isEmpty() && !startFlag
) {
197 qDebug() << "limits parsing failed (property doesn't start with %) on UAVObjectField" << name
;
198 } else if (!maxIndexFlag
) {
199 qDebug() << "limits parsing failed (index>numelements) on UAVObjectField" << name
<< "index" << index
<< "numElements" << numElements
;
200 } else if (!elemNumberSizeFlag
|| !b4
) {
201 qDebug() << "limits parsing failed limit not starting with %XX or %YYYYXX where XX is the limit type and YYYY is the board type on UAVObjectField" << name
;
205 elementLimits
.insert(index
, limitList
);
208 // foreach(QList<LimitStruct> limitList, elementLimits) {
209 // foreach(LimitStruct limit, limitList) {
210 // qDebug() << "Limit type" << limit.type << "for board" << limit.board << "for field" << getName();
211 // foreach(QVariant var, limit.values) {
212 // qDebug() << "value" << var;
217 bool UAVObjectField::isWithinLimits(QVariant var
, quint32 index
, int board
)
219 if (!elementLimits
.keys().contains(index
)) {
223 foreach(LimitStruct struc
, elementLimits
.value(index
)) {
224 if ((struc
.board
!= board
) && board
!= 0 && struc
.board
!= 0) {
227 switch (struc
.type
) {
233 foreach(QVariant vars
, struc
.values
) {
234 if (var
.toInt() == vars
.toInt()) {
245 foreach(QVariant vars
, struc
.values
) {
246 if (var
.toUInt() == vars
.toUInt()) {
255 foreach(QVariant vars
, struc
.values
) {
256 if (var
.toString() == vars
.toString()) {
264 foreach(QVariant vars
, struc
.values
) {
265 if (var
.toFloat() == vars
.toFloat()) {
281 foreach(QVariant vars
, struc
.values
) {
282 if (var
.toInt() == vars
.toInt()) {
293 foreach(QVariant vars
, struc
.values
) {
294 if (var
.toUInt() == vars
.toUInt()) {
303 foreach(QVariant vars
, struc
.values
) {
304 if (var
.toString() == vars
.toString()) {
312 foreach(QVariant vars
, struc
.values
) {
313 if (var
.toFloat() == vars
.toFloat()) {
325 if (struc
.values
.length() < 2) {
326 qDebug() << __FUNCTION__
<< "between limit with less than 1 pair, aborting; field:" << name
;
329 if (struc
.values
.length() > 2) {
330 qDebug() << __FUNCTION__
<< "between limit with more than 1 pair, using first; field" << name
;
336 if (!(var
.toInt() >= struc
.values
.at(0).toInt() && var
.toInt() <= struc
.values
.at(1).toInt())) {
346 if (!(var
.toUInt() >= struc
.values
.at(0).toUInt() && var
.toUInt() <= struc
.values
.at(1).toUInt())) {
353 if (!(options
.indexOf(var
.toString()) >= options
.indexOf(struc
.values
.at(0).toString()) && options
.indexOf(var
.toString()) <= options
.indexOf(struc
.values
.at(1).toString()))) {
364 if (!(var
.toFloat() >= struc
.values
.at(0).toFloat() && var
.toFloat() <= struc
.values
.at(1).toFloat())) {
375 if (struc
.values
.length() < 1) {
376 qDebug() << __FUNCTION__
<< "BIGGER limit with less than 1 value, aborting; field:" << name
;
379 if (struc
.values
.length() > 1) {
380 qDebug() << __FUNCTION__
<< "BIGGER limit with more than 1 value, using first; field" << name
;
386 if (!(var
.toInt() >= struc
.values
.at(0).toInt())) {
396 if (!(var
.toUInt() >= struc
.values
.at(0).toUInt())) {
403 if (!(options
.indexOf(var
.toString()) >= options
.indexOf(struc
.values
.at(0).toString()))) {
414 if (!(var
.toFloat() >= struc
.values
.at(0).toFloat())) {
429 if (!(var
.toInt() <= struc
.values
.at(0).toInt())) {
439 if (!(var
.toUInt() <= struc
.values
.at(0).toUInt())) {
446 if (!(options
.indexOf(var
.toString()) <= options
.indexOf(struc
.values
.at(0).toString()))) {
457 if (!(var
.toFloat() <= struc
.values
.at(0).toFloat())) {
473 QString
UAVObjectField::getLimitsAsString(quint32 index
, int board
)
477 if (elementLimits
.keys().contains(index
)) {
478 foreach(LimitStruct struc
, elementLimits
.value(index
)) {
479 if ((struc
.board
!= board
) && board
!= 0 && struc
.board
!= 0) {
482 switch (struc
.type
) {
485 limitString
.append(tr("one of")).append(" [");
487 foreach(QVariant var
, struc
.values
) {
489 limitString
.append(", ");
491 limitString
.append(var
.toString());
494 return limitString
.append("]");
498 limitString
.append(tr("none of")).append(" [");
500 foreach(QVariant var
, struc
.values
) {
502 limitString
.append(", ");
504 limitString
.append(var
.toString());
507 return limitString
.append("]");
509 case BIGGER
: return limitString
.append(QString("%1 %2").arg(tr("more than"), struc
.values
.at(0).toString()));
511 case BETWEEN
: return limitString
.append(QString("%1 %2 %3 %4")
512 .arg(tr("between"), struc
.values
.at(0).toString(),
513 tr(" and "), struc
.values
.at(1).toString()));
515 case SMALLER
: return limitString
.append(QString("%1 %2").arg(tr("less than"), struc
.values
.at(0).toString()));
525 QVariant
UAVObjectField::getMaxLimit(quint32 index
, int board
)
527 if (!elementLimits
.keys().contains(index
)) {
530 foreach(LimitStruct struc
, elementLimits
.value(index
)) {
531 if ((struc
.board
!= board
) && board
!= 0 && struc
.board
!= 0) {
534 switch (struc
.type
) {
541 return struc
.values
.at(1);
544 return struc
.values
.at(0);
552 QVariant
UAVObjectField::getMinLimit(quint32 index
, int board
)
554 if (!elementLimits
.keys().contains(index
)) {
557 foreach(LimitStruct struc
, elementLimits
.value(index
)) {
558 if ((struc
.board
!= board
) && board
!= 0 && struc
.board
!= 0) {
561 switch (struc
.type
) {
568 return struc
.values
.at(0);
571 return struc
.values
.at(0);
579 void UAVObjectField::initialize(quint8
*data
, quint32 dataOffset
, UAVObject
*obj
)
582 this->offset
= dataOffset
;
587 UAVObjectField::FieldType
UAVObjectField::getType()
592 QString
UAVObjectField::getTypeAsString()
595 case UAVObjectField::INT8
:
598 case UAVObjectField::INT16
:
601 case UAVObjectField::INT32
:
604 case UAVObjectField::UINT8
:
607 case UAVObjectField::UINT16
:
610 case UAVObjectField::UINT32
:
613 case UAVObjectField::FLOAT32
:
616 case UAVObjectField::ENUM
:
619 case UAVObjectField::BITFIELD
:
622 case UAVObjectField::STRING
:
630 QStringList
UAVObjectField::getElementNames()
635 UAVObject
*UAVObjectField::getObject()
640 void UAVObjectField::clear()
642 QMutexLocker
locker(obj
->getMutex());
646 memset(&data
[offset
], 0, numBytesPerElement
* ((quint32
)(1 + (numElements
- 1) / 8)));
649 memset(&data
[offset
], 0, numBytesPerElement
* numElements
);
654 QString
UAVObjectField::getName()
659 QString
UAVObjectField::getDescription()
664 QString
UAVObjectField::getUnits()
669 QStringList
UAVObjectField::getOptions()
674 quint32
UAVObjectField::getNumElements()
679 quint32
UAVObjectField::getDataOffset()
684 quint32
UAVObjectField::getNumBytes()
688 return numBytesPerElement
* ((quint32
)(1 + (numElements
- 1) / 8));
692 return numBytesPerElement
* numElements
;
698 QString
UAVObjectField::toString()
702 sout
.append(QString("%1: [ ").arg(name
));
703 for (unsigned int n
= 0; n
< numElements
; ++n
) {
704 sout
.append(QString("%1 ").arg(getDouble(n
)));
706 sout
.append(QString("] %1\n").arg(units
));
710 void UAVObjectField::toXML(QXmlStreamWriter
*xmlWriter
)
712 xmlWriter
->writeStartElement("field");
713 xmlWriter
->writeAttribute("name", getName());
714 xmlWriter
->writeAttribute("type", getTypeAsString());
715 if (!getUnits().isEmpty()) {
716 xmlWriter
->writeAttribute("unit", getUnits());
718 for (unsigned int n
= 0; n
< numElements
; ++n
) {
719 xmlWriter
->writeStartElement("value");
720 if (getElementNames().size() > 1) {
721 xmlWriter
->writeAttribute("name", getElementNames().at(n
));
723 xmlWriter
->writeCharacters(getValue(n
).toString());
724 xmlWriter
->writeEndElement(); // value
726 xmlWriter
->writeEndElement(); // field
729 void UAVObjectField::fromXML(QXmlStreamReader
*xmlReader
)
731 // Assert we have the correct field by name
732 Q_ASSERT(xmlReader
->name() == "field");
733 Q_ASSERT(xmlReader
->attributes().value("name") == getName());
734 // Read values, skip overflowing ones if any
735 while (xmlReader
->readNextStartElement()) {
736 if (xmlReader
->name() == "value") {
737 int index
= getElementNames().indexOf(xmlReader
->attributes().value("name").toString());
739 setValue(xmlReader
->readElementText(), index
);
745 void UAVObjectField::toJson(QJsonObject
&jsonObject
)
747 jsonObject
["name"] = getName();
748 jsonObject
["type"] = getTypeAsString();
749 jsonObject
["unit"] = getUnits();
751 for (unsigned int n
= 0; n
< numElements
; ++n
) {
753 value
["name"] = getElementNames().at(n
);
754 value
["value"] = QJsonValue::fromVariant(getValue(n
));
755 values
.append(value
);
757 jsonObject
["values"] = values
;
760 void UAVObjectField::fromJson(const QJsonObject
&jsonObject
)
762 Q_ASSERT(jsonObject
["name"].toString() == getName());
763 QJsonArray jsonValues
= jsonObject
["values"].toArray();
764 for (int i
= 0; i
< jsonValues
.size(); i
++) {
765 QJsonObject jsonValue
= jsonValues
.at(i
).toObject();
766 int index
= getElementNames().indexOf(jsonValue
["name"].toString());
768 setValue(((QJsonValue
)jsonValue
["value"]).toVariant(), index
);
773 qint32
UAVObjectField::pack(quint8
*dataOut
)
775 QMutexLocker
locker(obj
->getMutex());
777 // Pack each element in output buffer
780 memcpy(dataOut
, &data
[offset
], numElements
);
783 for (quint32 index
= 0; index
< numElements
; ++index
) {
785 memcpy(&value
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
786 qToLittleEndian
<qint16
>(value
, &dataOut
[numBytesPerElement
* index
]);
790 for (quint32 index
= 0; index
< numElements
; ++index
) {
792 memcpy(&value
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
793 qToLittleEndian
<qint32
>(value
, &dataOut
[numBytesPerElement
* index
]);
797 for (quint32 index
= 0; index
< numElements
; ++index
) {
798 dataOut
[numBytesPerElement
* index
] = data
[offset
+ numBytesPerElement
* index
];
802 for (quint32 index
= 0; index
< numElements
; ++index
) {
804 memcpy(&value
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
805 qToLittleEndian
<quint16
>(value
, &dataOut
[numBytesPerElement
* index
]);
809 for (quint32 index
= 0; index
< numElements
; ++index
) {
811 memcpy(&value
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
812 qToLittleEndian
<quint32
>(value
, &dataOut
[numBytesPerElement
* index
]);
816 for (quint32 index
= 0; index
< numElements
; ++index
) {
818 memcpy(&value
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
819 qToLittleEndian
<quint32
>(value
, &dataOut
[numBytesPerElement
* index
]);
823 for (quint32 index
= 0; index
< numElements
; ++index
) {
824 dataOut
[numBytesPerElement
* index
] = data
[offset
+ numBytesPerElement
* index
];
828 for (quint32 index
= 0; index
< (quint32
)(1 + (numElements
- 1) / 8); ++index
) {
829 dataOut
[numBytesPerElement
* index
] = data
[offset
+ numBytesPerElement
* index
];
833 memcpy(dataOut
, &data
[offset
], numElements
);
837 return getNumBytes();
840 qint32
UAVObjectField::unpack(const quint8
*dataIn
)
842 QMutexLocker
locker(obj
->getMutex());
844 // Unpack each element from input buffer
847 memcpy(&data
[offset
], dataIn
, numElements
);
850 for (quint32 index
= 0; index
< numElements
; ++index
) {
852 value
= qFromLittleEndian
<qint16
>(&dataIn
[numBytesPerElement
* index
]);
853 memcpy(&data
[offset
+ numBytesPerElement
* index
], &value
, numBytesPerElement
);
857 for (quint32 index
= 0; index
< numElements
; ++index
) {
859 value
= qFromLittleEndian
<qint32
>(&dataIn
[numBytesPerElement
* index
]);
860 memcpy(&data
[offset
+ numBytesPerElement
* index
], &value
, numBytesPerElement
);
864 for (quint32 index
= 0; index
< numElements
; ++index
) {
865 data
[offset
+ numBytesPerElement
* index
] = dataIn
[numBytesPerElement
* index
];
869 for (quint32 index
= 0; index
< numElements
; ++index
) {
871 value
= qFromLittleEndian
<quint16
>(&dataIn
[numBytesPerElement
* index
]);
872 memcpy(&data
[offset
+ numBytesPerElement
* index
], &value
, numBytesPerElement
);
876 for (quint32 index
= 0; index
< numElements
; ++index
) {
878 value
= qFromLittleEndian
<quint32
>(&dataIn
[numBytesPerElement
* index
]);
879 memcpy(&data
[offset
+ numBytesPerElement
* index
], &value
, numBytesPerElement
);
883 for (quint32 index
= 0; index
< numElements
; ++index
) {
885 value
= qFromLittleEndian
<quint32
>(&dataIn
[numBytesPerElement
* index
]);
886 memcpy(&data
[offset
+ numBytesPerElement
* index
], &value
, numBytesPerElement
);
890 for (quint32 index
= 0; index
< numElements
; ++index
) {
891 data
[offset
+ numBytesPerElement
* index
] = dataIn
[numBytesPerElement
* index
];
895 for (quint32 index
= 0; index
< (quint32
)(1 + (numElements
- 1) / 8); ++index
) {
896 data
[offset
+ numBytesPerElement
* index
] = dataIn
[numBytesPerElement
* index
];
900 memcpy(&data
[offset
], dataIn
, numElements
);
904 return getNumBytes();
907 bool UAVObjectField::isNumeric()
926 bool UAVObjectField::isInteger()
943 bool UAVObjectField::isText()
956 QVariant
UAVObjectField::getValue(quint32 index
)
958 QMutexLocker
locker(obj
->getMutex());
960 // Check that index is not out of bounds
961 if (index
>= numElements
) {
969 memcpy(&tmpint8
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
970 return QVariant(tmpint8
);
977 memcpy(&tmpint16
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
978 return QVariant(tmpint16
);
985 memcpy(&tmpint32
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
986 return QVariant(tmpint32
);
993 memcpy(&tmpuint8
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
994 return QVariant(tmpuint8
);
1001 memcpy(&tmpuint16
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
1002 return QVariant(tmpuint16
);
1009 memcpy(&tmpuint32
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
1010 return QVariant(tmpuint32
);
1017 memcpy(&tmpfloat
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
1018 return QVariant(tmpfloat
);
1025 memcpy(&tmpenum
, &data
[offset
+ numBytesPerElement
* index
], numBytesPerElement
);
1026 if (tmpenum
>= options
.length()) {
1027 qDebug() << "Invalid enum" << tmpenum
<< "for field" << (obj
->getName() + ":" + name
+ "[" + elementNames
[index
] + "]");
1030 return QVariant(options
[tmpenum
]);
1037 memcpy(&tmpbitfield
, &data
[offset
+ numBytesPerElement
* ((quint32
)(index
/ 8))], numBytesPerElement
);
1038 tmpbitfield
= (tmpbitfield
>> (index
% 8)) & 1;
1039 return QVariant(tmpbitfield
);
1045 data
[offset
+ numElements
- 1] = '\0';
1046 QString
str((char *)&data
[offset
]);
1047 return QVariant(str
);
1052 // If this point is reached then we got an invalid type
1056 bool UAVObjectField::checkValue(const QVariant
& value
, quint32 index
)
1058 QMutexLocker
locker(obj
->getMutex());
1060 // Check that index is not out of bounds
1061 if (index
>= numElements
) {
1065 UAVObject::Metadata mdata
= obj
->getMetadata();
1066 // Update value if the access mode permits
1067 if (UAVObject::GetFlightAccess(mdata
) == UAVObject::ACCESS_READWRITE
) {
1083 qint8 tmpenum
= options
.indexOf(value
.toString());
1084 return (tmpenum
< 0) ? false : true;
1089 qDebug() << "checkValue: other types" << type
;
1090 Q_ASSERT(0); // To catch any programming errors where we tried to test invalid values
1097 void UAVObjectField::setValue(const QVariant
& value
, quint32 index
)
1099 QMutexLocker
locker(obj
->getMutex());
1101 // Check that index is not out of bounds
1102 if (index
>= numElements
) {
1106 UAVObject::Metadata mdata
= obj
->getMetadata();
1107 // Update value if the access mode permits
1108 if (UAVObject::GetGcsAccess(mdata
) == UAVObject::ACCESS_READWRITE
) {
1112 qint8 tmpint8
= value
.toInt();
1113 memcpy(&data
[offset
+ numBytesPerElement
* index
], &tmpint8
, numBytesPerElement
);
1118 qint16 tmpint16
= value
.toInt();
1119 memcpy(&data
[offset
+ numBytesPerElement
* index
], &tmpint16
, numBytesPerElement
);
1124 qint32 tmpint32
= value
.toInt();
1125 memcpy(&data
[offset
+ numBytesPerElement
* index
], &tmpint32
, numBytesPerElement
);
1130 quint8 tmpuint8
= value
.toUInt();
1131 memcpy(&data
[offset
+ numBytesPerElement
* index
], &tmpuint8
, numBytesPerElement
);
1136 quint16 tmpuint16
= value
.toUInt();
1137 memcpy(&data
[offset
+ numBytesPerElement
* index
], &tmpuint16
, numBytesPerElement
);
1142 quint32 tmpuint32
= value
.toUInt();
1143 memcpy(&data
[offset
+ numBytesPerElement
* index
], &tmpuint32
, numBytesPerElement
);
1148 float tmpfloat
= value
.toFloat();
1149 memcpy(&data
[offset
+ numBytesPerElement
* index
], &tmpfloat
, numBytesPerElement
);
1154 qint8 tmpenum
= options
.indexOf(value
.toString());
1155 // try case insensitive
1157 QRegExp
regexp(value
.toString(), Qt::CaseInsensitive
);
1158 tmpenum
= options
.indexOf(regexp
);
1160 qWarning() << "Enum value" << value
.toString() << "should be" << options
.at(tmpenum
);
1163 // Default to 0 on invalid values.
1166 qWarning() << "Enum value" << value
.toString() << "not found";
1168 memcpy(&data
[offset
+ numBytesPerElement
* index
], &tmpenum
, numBytesPerElement
);
1174 memcpy(&tmpbitfield
, &data
[offset
+ numBytesPerElement
* ((quint32
)(index
/ 8))], numBytesPerElement
);
1175 tmpbitfield
= (tmpbitfield
& ~(1 << (index
% 8))) | ((value
.toUInt() != 0 ? 1 : 0) << (index
% 8));
1176 memcpy(&data
[offset
+ numBytesPerElement
* ((quint32
)(index
/ 8))], &tmpbitfield
, numBytesPerElement
);
1181 QString str
= value
.toString();
1182 QByteArray barray
= str
.toLatin1();
1184 for (index
= 0; index
< (quint32
)barray
.length() && index
< (numElements
- 1); ++index
) {
1185 data
[offset
+ index
] = barray
[index
];
1187 barray
[index
] = '\0';
1194 double UAVObjectField::getDouble(quint32 index
)
1196 return getValue(index
).toDouble();
1199 void UAVObjectField::setDouble(double value
, quint32 index
)
1201 setValue(QVariant(value
), index
);