36 if (_airframeMetaDataLoaded) {
40 qCDebug(PX4AirframeLoaderLog) <<
"Loading PX4 airframe fact meta data";
43 qCWarning(PX4AirframeLoaderLog) <<
"Internal error";
47 QString airframeFilename;
50 if (!
qgcApp()->runningUnitTests()) {
54 if (airframeFilename.isEmpty() || !QFile(airframeFilename).exists()) {
55 airframeFilename =
":/AutoPilotPlugins/PX4/AirframeFactMetaData.xml";
58 qCDebug(PX4AirframeLoaderLog) <<
"Loading meta data file:" << airframeFilename;
60 QFile xmlFile(airframeFilename);
61 if (!xmlFile.exists()) {
62 qCWarning(PX4AirframeLoaderLog) <<
"Internal error";
66 bool success = xmlFile.open(QIODevice::ReadOnly);
69 qCWarning(PX4AirframeLoaderLog) <<
"Failed opening airframe XML";
73 QXmlStreamReader xml(xmlFile.readAll());
76 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML" << xml.errorString();
80 QString airframeGroup;
82 int xmlState = XmlStateNone;
84 while (!xml.atEnd()) {
85 if (xml.isStartElement()) {
86 QString elementName = xml.name().toString();
88 if (elementName ==
"airframes") {
89 if (xmlState != XmlStateNone) {
90 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
93 xmlState = XmlStateFoundAirframes;
95 }
else if (elementName ==
"version") {
96 if (xmlState != XmlStateFoundAirframes) {
97 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
100 xmlState = XmlStateFoundVersion;
103 QString strVersion = xml.readElementText();
104 int intVersion = strVersion.toInt(&convertOk);
106 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
109 if (intVersion < 1) {
111 qDebug() <<
"Airframe version stamp too old, skipping load. Found:" << intVersion <<
"Want: 3 File:" << airframeFilename;
115 }
else if (elementName ==
"airframe_version_major") {
117 }
else if (elementName ==
"airframe_version_minor") {
120 }
else if (elementName ==
"airframe_group") {
121 if (xmlState != XmlStateFoundVersion) {
123 qDebug() <<
"Parameter version stamp not found, skipping load" << airframeFilename;
126 xmlState = XmlStateFoundGroup;
128 if (!xml.attributes().hasAttribute(
"name") || !xml.attributes().hasAttribute(
"image")) {
129 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
132 airframeGroup = xml.attributes().value(
"name").toString();
133 image = xml.attributes().value(
"image").toString();
134 qCDebug(PX4AirframeLoaderLog) <<
"Found group: " << airframeGroup <<
" image:" << image;
136 }
else if (elementName ==
"airframe") {
137 if (xmlState != XmlStateFoundGroup) {
138 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
141 xmlState = XmlStateFoundAirframe;
143 if (!xml.attributes().hasAttribute(
"name") || !xml.attributes().hasAttribute(
"id")) {
144 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
148 QString name = xml.attributes().value(
"name").toString();
149 QString
id = xml.attributes().value(
"id").toString();
151 qCDebug(PX4AirframeLoaderLog) <<
"Found airframe name:" << name <<
" type:" << airframeGroup <<
" id:" << id;
158 if (xmlState != XmlStateFoundAirframe) {
159 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
163 }
else if (xml.isEndElement()) {
164 QString elementName = xml.name().toString();
166 if (elementName ==
"airframe") {
168 xmlState = XmlStateFoundGroup;
169 }
else if (elementName ==
"airframe_group") {
170 xmlState = XmlStateFoundVersion;
171 }
else if (elementName ==
"airframes") {
172 xmlState = XmlStateFoundAirframes;
178 _airframeMetaDataLoaded =
true;