36 if (_airframeMetaDataLoaded) {
40 qCDebug(PX4AirframeLoaderLog) <<
"Loading PX4 airframe fact meta data";
43 qCWarning(PX4AirframeLoaderLog) <<
"Internal error";
47 QString airframeFilename;
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;
83 QString airframeClass;
85 int xmlState = XmlStateNone;
87 while (!xml.atEnd()) {
88 if (xml.isStartElement()) {
89 QString elementName = xml.name().toString();
91 if (elementName ==
"airframes") {
92 if (xmlState != XmlStateNone) {
93 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
96 xmlState = XmlStateFoundAirframes;
98 }
else if (elementName ==
"version") {
99 if (xmlState != XmlStateFoundAirframes) {
100 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
103 xmlState = XmlStateFoundVersion;
106 QString strVersion = xml.readElementText();
107 int intVersion = strVersion.toInt(&convertOk);
109 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
112 if (intVersion < 1) {
114 qDebug() <<
"Airframe version stamp too old, skipping load. Found:" << intVersion <<
"Want: 3 File:" << airframeFilename;
118 }
else if (elementName ==
"airframe_version_major") {
120 }
else if (elementName ==
"airframe_version_minor") {
123 }
else if (elementName ==
"airframe_group") {
124 if (xmlState != XmlStateFoundVersion) {
126 qDebug() <<
"Parameter version stamp not found, skipping load" << airframeFilename;
129 xmlState = XmlStateFoundGroup;
131 if (!xml.attributes().hasAttribute(
"name") || !xml.attributes().hasAttribute(
"image")) {
132 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
135 airframeGroup = xml.attributes().value(
"name").toString();
136 image = xml.attributes().value(
"image").toString();
137 qCDebug(PX4AirframeLoaderLog) <<
"Found group: " << airframeGroup <<
" image:" << image;
139 }
else if (elementName ==
"airframe") {
140 if (xmlState != XmlStateFoundGroup) {
141 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
144 xmlState = XmlStateFoundAirframe;
146 if (!xml.attributes().hasAttribute(
"name") || !xml.attributes().hasAttribute(
"id")) {
147 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
151 QString name = xml.attributes().value(
"name").toString();
152 QString
id = xml.attributes().value(
"id").toString();
154 qCDebug(PX4AirframeLoaderLog) <<
"Found airframe name:" << name <<
" type:" << airframeGroup <<
" id:" << id;
158 airframeId =
id.toInt();
159 airframeClass.clear();
163 if (xmlState != XmlStateFoundAirframe) {
164 qCWarning(PX4AirframeLoaderLog) <<
"Badly formed XML";
167 if (elementName ==
"class") {
168 airframeClass = xml.readElementText();
171 }
else if (xml.isEndElement()) {
172 QString elementName = xml.name().toString();
174 if (elementName ==
"airframe") {
178 xmlState = XmlStateFoundGroup;
179 }
else if (elementName ==
"airframe_group") {
180 xmlState = XmlStateFoundVersion;
181 }
else if (elementName ==
"airframes") {
182 xmlState = XmlStateFoundAirframes;
188 _airframeMetaDataLoaded =
true;