mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 12:55:31 +08:00
refs #192, JSON samples and fixed one other sample
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "sampleschangeobject.h"
|
#include "sampleschangeobject.h"
|
||||||
#include "samplesmetadata.h"
|
#include "samplesmetadata.h"
|
||||||
#include "samplescontainer.h"
|
#include "samplescontainer.h"
|
||||||
|
#include "samplesjson.h"
|
||||||
#include "blackmisc/blackmiscfreefunctions.h"
|
#include "blackmisc/blackmiscfreefunctions.h"
|
||||||
#include "blackmisc/pqallquantities.h"
|
#include "blackmisc/pqallquantities.h"
|
||||||
|
|
||||||
@@ -20,8 +21,9 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
BlackMisc::initResources();
|
BlackMisc::initResources();
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
CSamplesChangeObject::samples();
|
CSamplesJson::samples();
|
||||||
CSamplesContainer::samples();
|
// CSamplesChangeObject::samples();
|
||||||
CSamplesMetadata::samples();
|
// CSamplesContainer::samples();
|
||||||
|
// CSamplesMetadata::samples();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
88
samples/blackmisc/samplesjson.cpp
Normal file
88
samples/blackmisc/samplesjson.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#include "samplesjson.h"
|
||||||
|
#include "blackmisc/avatcstationlist.h"
|
||||||
|
#include "blackmisc/avaircraft.h"
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackMisc::Aviation;
|
||||||
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
|
using namespace BlackMisc::Geo;
|
||||||
|
using namespace BlackMisc::Network;
|
||||||
|
|
||||||
|
namespace BlackMiscTest
|
||||||
|
{
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Samples
|
||||||
|
*/
|
||||||
|
int CSamplesJson::samples()
|
||||||
|
{
|
||||||
|
QTextStream cin(stdin);
|
||||||
|
CLength l(123.456, CLengthUnit::NM());
|
||||||
|
QJsonObject json = l.toJson();
|
||||||
|
l = CLength(); //convert back
|
||||||
|
l.fromJson(json);
|
||||||
|
qDebug() << json << l;
|
||||||
|
qDebug() << "-------";
|
||||||
|
QDateTime dtFrom = QDateTime::currentDateTimeUtc();
|
||||||
|
QDateTime dtUntil = dtFrom.addSecs(60 * 60.0); // 1 hour
|
||||||
|
CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21′ 13″ N", "11° 47′ 09″ E", CLength(1487, CLengthUnit::ft()));
|
||||||
|
CAtcStation station(CCallsign("eddm_twr"), CUser("123456", "Joe Doe"),
|
||||||
|
CFrequency(118.7, CFrequencyUnit::MHz()), geoPos, CLength(50, CLengthUnit::km()), false, dtFrom, dtUntil);
|
||||||
|
json = station.toJson();
|
||||||
|
QJsonDocument doc(json);
|
||||||
|
qDebug() << doc.toJson(QJsonDocument::Indented);
|
||||||
|
qDebug() << "-------";
|
||||||
|
|
||||||
|
station = CAtcStation();
|
||||||
|
station.fromJson(json);
|
||||||
|
qDebug() << station;
|
||||||
|
qDebug() << "------- Enter -----";
|
||||||
|
cin.readLine();
|
||||||
|
|
||||||
|
CAircraftSituation situation(geoPos, CAltitude(1000, CAltitude::AboveGround, CLengthUnit::ft()),
|
||||||
|
CHeading(10, CHeading::True, CAngleUnit::deg()),
|
||||||
|
CAngle(12, CAngleUnit::deg()), CAngle(5, CAngleUnit::deg()),
|
||||||
|
CSpeed(111, CSpeedUnit::km_h()));
|
||||||
|
CAircraft aircraft(CCallsign("DAMBZ"), CUser("123456", "Joe Pilot"), situation);
|
||||||
|
aircraft.setCom1System(CComSystem::getCom1System(122.8, 118.75));
|
||||||
|
aircraft.setCom2System(CComSystem::getCom2System(123.8, 124.00));
|
||||||
|
aircraft.setTransponder(CTransponder::getStandardTransponder(7000, CTransponder::ModeS));
|
||||||
|
aircraft.setIcaoInfo(CAircraftIcao("B737", "L2J", "DLH", "FREIGHT", "CCDDFF"));
|
||||||
|
|
||||||
|
json = aircraft.toJson();
|
||||||
|
doc = QJsonDocument(json);
|
||||||
|
qDebug() << doc.toJson(QJsonDocument::Indented);
|
||||||
|
qDebug() << "-------";
|
||||||
|
|
||||||
|
aircraft = CAircraft();
|
||||||
|
aircraft.fromJson(json);
|
||||||
|
qDebug() << aircraft;
|
||||||
|
qDebug() << "------- Enter -----";
|
||||||
|
cin.readLine();
|
||||||
|
|
||||||
|
CAtcStationList stations;
|
||||||
|
stations.push_back(station);
|
||||||
|
station.setCallsign(CCallsign("eddn_gnd"));
|
||||||
|
stations.push_back(station);
|
||||||
|
json = stations.toJson();
|
||||||
|
doc.setObject(json);
|
||||||
|
qDebug() << doc.toJson(QJsonDocument::Indented);
|
||||||
|
qDebug() << "------- Enter -----";
|
||||||
|
cin.readLine();
|
||||||
|
|
||||||
|
stations.clear();
|
||||||
|
stations.fromJson(json);
|
||||||
|
qDebug() << stations;
|
||||||
|
|
||||||
|
qDebug() << "-----------------------------------------------";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
24
samples/blackmisc/samplesjson.h
Normal file
24
samples/blackmisc/samplesjson.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifndef BLACKMISCTEST_SAMPLESJSON_H
|
||||||
|
#define BLACKMISCTEST_SAMPLESJSON_H
|
||||||
|
|
||||||
|
namespace BlackMiscTest {
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Samples for metadata
|
||||||
|
*/
|
||||||
|
class CSamplesJson
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* \brief Run the samples
|
||||||
|
*/
|
||||||
|
static int samples();
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -38,12 +38,6 @@ namespace BlackMiscTest
|
|||||||
qDebug() << c1;
|
qDebug() << c1;
|
||||||
c1.setActiveUnicom();
|
c1.setActiveUnicom();
|
||||||
qDebug() << c1;
|
qDebug() << c1;
|
||||||
|
|
||||||
if (!CComSystem::tryGetComSystem(c1, "Test", -1.0))
|
|
||||||
qDebug() << c1 << "is reset to default as expected";
|
|
||||||
else
|
|
||||||
qDebug() << "Something is wrong here";
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// uncomment to test assert
|
// uncomment to test assert
|
||||||
|
|||||||
Reference in New Issue
Block a user