-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added JSON format output #59
Conversation
Thanks very much for that. I'll have a look at it and test it out soon. |
Getting there... if(settingsdialog->msgdisplayformat=="4")
{
ui->inputwidget->setLineWrapMode(QPlainTextEdit::NoWrap);
QString message=acarsitem.message;
message.replace('\r','\n');
message.replace("\n\n","\n");
if(message.right(1)=="\n")message.chop(1);
if(message.left(1)=="\n")message.remove(0,1);
message.replace("\n","\n\t");
QString utcdate = QDateTime::currentDateTime().toUTC().toString("yyyy-MM-dd hh:mm:ss");
if(acarsitem.TAK==0x15)TAKstr=((QString)"!").toLatin1();
uchar label1=acarsitem.LABEL[1];
if((uchar)acarsitem.LABEL[1]==127)label1='d';
//json object creation
QJsonObject json;
//add database lookup info if available
if(acarsitem.dblookupresult.size()==QMetaEnum::fromType<DataBaseTextUser::DataBaseSchema>().keyCount())
{
json["DB_MANUFACTURER"]=acarsitem.dblookupresult[DataBaseTextUser::DataBaseSchema::Manufacturer].trimmed();
json["DB_TYPE"]=acarsitem.dblookupresult[DataBaseTextUser::DataBaseSchema::Type].trimmed();
json["DB_OWNERS"]=acarsitem.dblookupresult[DataBaseTextUser::DataBaseSchema::RegisteredOwners].trimmed();
}
//add common things
json["TIME"]=utcdate;
json["NONACARS"]="false";
json["AESID"]=((QString)"").sprintf("%06X",acarsitem.isuitem.AESID);
json["GESID"]=((QString)"").sprintf("%02X",acarsitem.isuitem.GESID);
json["QNO"]=((QString)"").sprintf("%02X",acarsitem.isuitem.QNO);
json["REFNO"]=((QString)"").sprintf("%02X",acarsitem.isuitem.REFNO);
json["REG"]=(QString)acarsitem.PLANEREG;
//add acars message things
if(!acarsitem.nonacars)
{
json["MODE"]=(QString)acarsitem.MODE;
json["TAK"]=(QString)TAKstr;
json["LABEL"]=(((QString)"").sprintf("%c%c",(uchar)acarsitem.LABEL[0],label1));
json["BI"]=(QString)acarsitem.BI;
}
//if there is a message then add it and any parsing using arincparser
if(!message.isEmpty())
{
json["MESSAGE"]=message;
if(!arincparser.downlinkheader.flightid.isEmpty())json["FLIGHT"]=arincparser.downlinkheader.flightid;
if(arincparser.arincmessage.info.size()>2)json["ARINCPARSER_MESSAGE_INFO"]=arincparser.arincmessage.info;
}
//convert json object to string
humantext=QJsonDocument(json).toJson(QJsonDocument::Compact);
//output result to udp and screen
if((!settingsdialog->dropnontextmsgs)||(!message.isEmpty()&&(!acarsitem.nonacars)))
{
if(settingsdialog->udp_for_decoded_messages_enabled)
{
//send bottom text window to all udp sockects
for(int ii=0;ii<udpsockets_bottom_textedit.size();ii++)
{
if(ii>=settingsdialog->udp_for_decoded_messages_address.size())continue;
if(ii>=settingsdialog->udp_for_decoded_messages_port.size())continue;
QUdpSocket *sock=udpsockets_bottom_textedit[ii].data();
if((!sock->isOpen())||(!sock->isWritable()))
{
sock->close();
sock->connectToHost(settingsdialog->udp_for_decoded_messages_address[ii], settingsdialog->udp_for_decoded_messages_port[ii]);
}
if((sock->isOpen())&&(sock->isWritable()))sock->write((humantext+"\n").toLatin1().data());
}
}
ui->inputwidget->appendPlainText(humantext);
log(humantext);
}
} Now "\n" and " are handled correctly. DB info is added to the json object. It uses QJsonObject. And parsing done so "ARINCPARSER_MESSAGE_INFO" is added and derived from "MESSAGE" |
I stuffed up the merge. I was working on my main branch and not your fork. I then forced a push after I had merged your pull request. That deleted your work from the commit history. I tried to undo the forced commit but your commit history didn't appear. I then tried to revert the pull request but that just forced me to make another pull request and that was in my name not yours. I'm not that good with git when things go wrong. The changes are in the dev_json branch and it seems to work as far as I can tell. If you want to test it out that would be good. I'll leave it there for a day or two for you and others to test, after that I'll merge that branch into master and delete the dev_json branch. If you want to be part of the commit history resend me your pull request and I'll try again. |
I added some code for a JSON formatted output, as proposed in issue #45. I have not much experience with C++ so the code may be very ugly...