QStringmainHeader=QString("/** @file\n *\t@brief MAVLink comm protocol.\n *\t@see http://qgroundcontrol.org/mavlink/\n *\t Generated on %1\n */\n#ifndef "+pureFileName.toUpper()+"_H\n#define "+pureFileName.toUpper()+"_H\n\n").arg(date);// The main header includes all messages
// emit parseState(QString("<font color=\"red\">ERROR: Inclusion failed: XML syntax error in file %1. Wrong/misspelled XML?\nAbort.</font>").arg(fileName));
// return false;
// }
// }
// }
emitparseState(QString("<font color=\"green\">End of inclusion from file: %1</font>").arg(incFileName));
}
else
{
// Include file could not be opened
emitparseState(QString("<font color=\"red\">ERROR: Failed including file: %1, file is not readable. Wrong/misspelled filename?\nAbort.</font>").arg(fileName));
returnfalse;
}
}
// Handle all enum tags
elseif(e.tagName()=="version")
{
//QString fieldType = e.attribute("type", "");
//QString fieldName = e.attribute("name", "");
QStringfieldText=e.text();
// Check if version has been previously set
if(mavlinkVersion!=0)
{
emitparseState(QString("<font color=\"red\">ERROR: Protocol version tag set twice, please use it only once. First version was %1, second version is %2.\nAbort.</font>").arg(mavlinkVersion).arg(fieldText));
returnfalse;
}
boolok;
intversion=fieldText.toInt(&ok);
if(ok&&(version>0)&&(version<256))
{
// Set MAVLink version
mavlinkVersion=version;
}
else
{
emitparseState(QString("<font color=\"red\">ERROR: Reading version string failed: %1, string is not an integer number between 1 and 255.\nAbort.</font>").arg(fieldText));
returnfalse;
}
}
// Handle all enum tags
elseif(e.tagName()=="enums")
{
// One down into the enums list
p=n;
n=n.firstChild();
while(!n.isNull())
{
e=n.toElement();
QStringcurrEnum;
QStringcurrEnumEnd;
// Comment
QStringcomment;
if(!e.isNull()&&e.tagName()=="enum")
{
// Get enum name
QStringenumName=e.attribute("name","").toLower();
if(enumName.size()==0)
{
emitparseState(tr("<font color=\"red\">ERROR: Missing required name=\"\" attribute for tag %2 near line %1\nAbort.</font>").arg(QString::number(e.lineNumber()),e.tagName()));
returnfalse;
}
else
{
// Sanity check: Accept only enum names not used previously
if(usedEnumNames->contains(enumName))
{
emitparseState(tr("<font color=\"red\">ERROR: Enum name %1 used twice, second occurence near line %2 of file %3\nAbort.</font>").arg(enumName,QString::number(e.lineNumber()),fileName));
// If value was given, use it, if not, use the enum iterator
// value. The iterator value gets reset by manual values
QStringfieldName=e2.attribute("name","");
if(fieldValue.length()==0)
{
fieldValue=QString::number(nextEnumValue);
nextEnumValue++;
}
else
{
boolok;
nextEnumValue=fieldValue.toInt(&ok)+1;
if(!ok)
{
emitparseState(tr("<font color=\"red\">ERROR: Enum entry %1 has not a valid number (%2) in the value field.\nAbort.</font>").arg(fieldName,fieldValue));
emitparseState(tr("<font color=\"red\">ERROR: Missing required name=\"\" attribute for tag %2 near line %1\nAbort.</font>").arg(QString::number(e.lineNumber()),e.tagName()));
emitparseState(tr("Compiling message <strong>%1 \t(#%3)</strong> \tnear line %2").arg(messageName,QString::number(n.lineNumber()),QString::number(messageId)));
// Sanity check: Accept only message IDs not used previously
if(usedMessageIDs->contains(messageId))
{
emitparseState(tr("<font color=\"red\">ERROR: Message ID %1 used twice, second occurence near line %2 of file %3\nAbort.</font>").arg(QString::number(messageId),QString::number(e.lineNumber()),fileName));
returnfalse;
}
else
{
usedMessageIDs->append(messageId);
}
// Sanity check: Accept only message names not used previously
if(usedMessageNames->contains(messageName))
{
emitparseState(tr("<font color=\"red\">ERROR: Message name %1 used twice, second occurence near line %2 of file %3\nAbort.</font>").arg(messageName,QString::number(e.lineNumber()),fileName));
QStringcommentContainer("/**\n * @brief Pack a %1 message\n * @param system_id ID of this system\n * @param component_id ID of this component (e.g. 200 for IMU)\n * @param msg The MAVLink message to compress the data into\n *\n%2 * @return length of the message in bytes (excluding serial stream start sign)\n */\n");
QStringcommentPackChanContainer("/**\n * @brief Pack a %1 message\n * @param system_id ID of this system\n * @param component_id ID of this component (e.g. 200 for IMU)\n * @param chan The MAVLink channel this message was sent over\n * @param msg The MAVLink message to compress the data into\n%2 * @return length of the message in bytes (excluding serial stream start sign)\n */\n");
QStringcommentSendContainer("/**\n * @brief Send a %1 message\n * @param chan MAVLink channel to send the message\n *\n%2 */\n");
QStringcommentEncodeContainer("/**\n * @brief Encode a %1 struct into a message\n *\n * @param system_id ID of this system\n * @param component_id ID of this component (e.g. 200 for IMU)\n * @param msg The MAVLink message to compress the data into\n * @param %1 C-struct to read the message contents from\n */\n");
QStringcommentDecodeContainer("/**\n * @brief Decode a %1 message into a struct\n *\n * @param msg The message to decode\n * @param %1 C-struct to decode the message contents into\n */\n");
emitparseState(tr("<font color=\"red\">ERROR: Unable to calculate length for %2 near line %1\nAbort.</font>").arg(QString::number(e.lineNumber()),fieldType));
QStringmHeader=QString("/** @file\n *\t@brief MAVLink comm protocol.\n *\t@see http://pixhawk.ethz.ch/software/mavlink\n *\t Generated on %1\n */\n#ifndef MAVLINK_H\n#define MAVLINK_H\n\n").arg(date);// The main header includes all messages
msgBox.setText(QString("The C code / headers have been generated in folder\n%1").arg(m_ui->outputDirNameLabel->text().trimmed()));
msgBox.exec();
}else{
}
else
{
QMessageBox::critical(this,tr("C code generation failed, please see the compile log for further information"),QString("The C code / headers could not be written to folder\n%1").arg(m_ui->outputDirNameLabel->text().trimmed()),QMessageBox::Ok);