Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.90 KB | None | 0 0
  1.  
  2. FlightPlan * RequestManager::createFlightPlanFromJson(const QVariantMap &jsonObject)
  3. {
  4.     FlightPlan *fp = new FlightPlan();
  5.    
  6.     // M633 header timestamp
  7.    
  8.     fp->M633Header().timestamp().day(QDate::currentDate().day());
  9.     fp->M633Header().timestamp().month(QDate::currentDate().month());
  10.     fp->M633Header().timestamp().year(QDate::currentDate().year());
  11.     fp->M633Header().timestamp().hours(QTime::currentTime().hour());
  12.     fp->M633Header().timestamp().minutes(QTime::currentTime().minute());
  13.    
  14.     // M633 header version number
  15.    
  16.     fp->M633Header().versionNumber().base_value(3);
  17.    
  18.     // flight origin date
  19.    
  20.     QString jsonEtdString = jsonObject.value("estimatedOffBlockTime").toString();
  21.     QDateTime jsonEtd = QDateTime::fromString(jsonEtdString, Qt::ISODate).toUTC();
  22.    
  23.     fp->M633SupplementaryHeader().Flight().flightOriginDate().day(  jsonEtd.date().day());
  24.     fp->M633SupplementaryHeader().Flight().flightOriginDate().month(jsonEtd.date().month());
  25.     fp->M633SupplementaryHeader().Flight().flightOriginDate().year( jsonEtd.date().year());
  26.    
  27.     fp->M633SupplementaryHeader().Flight().scheduledTimeOfDeparture_present(true);
  28.     fp->M633SupplementaryHeader().Flight().scheduledTimeOfDeparture().day(    jsonEtd.date().day());
  29.     fp->M633SupplementaryHeader().Flight().scheduledTimeOfDeparture().month(  jsonEtd.date().month());
  30.     fp->M633SupplementaryHeader().Flight().scheduledTimeOfDeparture().year(   jsonEtd.date().year());
  31.     fp->M633SupplementaryHeader().Flight().scheduledTimeOfDeparture().hours(  jsonEtd.time().hour());
  32.     fp->M633SupplementaryHeader().Flight().scheduledTimeOfDeparture().minutes(jsonEtd.time().minute());
  33.    
  34.     // flight identification
  35.    
  36.     QString fid = jsonObject.value("aircraftId").toString();
  37.    
  38.     fp->M633SupplementaryHeader().Flight().FlightIdentification().choice_arm(FlightIdentificationType::sequence_tag);
  39.     fp->M633SupplementaryHeader().Flight().FlightIdentification().sequence().FlightIdentifier().basic_string::operator=(fid.toStdString());
  40.  
  41.     // departure airport
  42.    
  43.     QVariantMap jsonDeparture = jsonObject.value("departure").toMap();
  44.     QString depAirportName = jsonDeparture["airport"].toString();
  45.     QString depAirportIata = jsonDeparture["iata"].toString();
  46.     QString depAirportIcao = jsonDeparture["icao"].toString();
  47.    
  48.     fp->M633SupplementaryHeader().Flight().DepartureAirport().airportName_present(true);
  49.     fp->M633SupplementaryHeader().Flight().DepartureAirport().airportName().basic_string::operator=(depAirportName.toStdString());
  50.     fp->M633SupplementaryHeader().Flight().DepartureAirport().choice_arm(AirportIdentificationType::sequence_tag);
  51.     fp->M633SupplementaryHeader().Flight().DepartureAirport().sequence().AirportIATACode_present(true);
  52.     fp->M633SupplementaryHeader().Flight().DepartureAirport().sequence().AirportIATACode().basic_string::operator=(depAirportIata.toStdString());
  53.     fp->M633SupplementaryHeader().Flight().DepartureAirport().sequence().AirportICAOCode().basic_string::operator=(depAirportIcao.toStdString());
  54.    
  55.     // arrival airport
  56.    
  57.     QVariantMap jsonArrival = jsonObject.value("destination").toMap();
  58.     QString arrAirportName = jsonArrival["airport"].toString();
  59.     QString arrAirportIata = jsonArrival["iata"].toString();
  60.     QString arrAirportIcao = jsonArrival["icao"].toString();
  61.    
  62.     fp->M633SupplementaryHeader().Flight().ArrivalAirport().airportName_present(true);
  63.     fp->M633SupplementaryHeader().Flight().ArrivalAirport().airportName().basic_string::operator=(arrAirportName.toStdString());
  64.     fp->M633SupplementaryHeader().Flight().ArrivalAirport().choice_arm(AirportIdentificationType::sequence_tag);
  65.     fp->M633SupplementaryHeader().Flight().ArrivalAirport().sequence().AirportIATACode_present(true);
  66.     fp->M633SupplementaryHeader().Flight().ArrivalAirport().sequence().AirportIATACode().basic_string::operator=(arrAirportIata.toStdString());
  67.     fp->M633SupplementaryHeader().Flight().ArrivalAirport().sequence().AirportICAOCode().basic_string::operator=(arrAirportIcao.toStdString());
  68.    
  69.     // aircraft registration
  70.    
  71.     QString acReg = jsonObject.value("registrationMark").toString();
  72.     QString acType = jsonObject.value("aircraftType").toString();
  73.    
  74.     fp->M633SupplementaryHeader().Aircraft().aircraftRegistration().basic_string::operator=(acReg.toStdString());
  75.     fp->M633SupplementaryHeader().Aircraft().AircraftModel().AircraftICAOType().basic_string::operator=(acType.toStdString());
  76.    
  77.     // waypoints
  78.    
  79.     QVariantList waypoints = jsonObject.value("routeDetails").toMap().value("features").toList();
  80.    
  81.     fp->Waypoints(new Waypoints());
  82.     //qDebug() << waypoints.size();
  83.    
  84.     for (const QVariant &var_waypoint : waypoints)
  85.     {
  86.         QVariantMap jsonWaypointGeometry = var_waypoint.toMap().value("geometry").toMap();
  87.         QVariantMap jsonWaypointProperty = var_waypoint.toMap().value("properties").toMap();
  88.        
  89.         WaypointType * waypoint = new WaypointType();
  90.        
  91.         // sequence id and passed attribute
  92.        
  93.         int seq = jsonWaypointProperty.value("pointIndex").toDouble();
  94.        
  95.         waypoint->sequenceId_present(true);
  96.         waypoint->sequenceId(seq);
  97.        
  98.         waypoint->passed_present(true);
  99.         waypoint->passed(false);
  100.        
  101.         // icao, name and long name
  102.        
  103.         QString jsonName = jsonWaypointProperty.value("designator").toString();
  104.         QString jsonLongName = jsonWaypointProperty.value("pointName").toString();
  105.        
  106.         waypoint->waypointLongName_present(true);
  107.         waypoint->waypointName_present(true);
  108.         waypoint->waypointId_present(true);
  109.        
  110.         if (jsonLongName.isEmpty())
  111.             waypoint->waypointLongName().basic_string::operator=(jsonName.toStdString());
  112.         else
  113.             waypoint->waypointLongName().basic_string::operator=(jsonLongName.toStdString());
  114.        
  115.         waypoint->waypointName().basic_string::operator=(jsonName.toStdString());
  116.         waypoint->waypointId().basic_string::operator=(jsonName.toStdString());
  117.        
  118.         // coordinates
  119.        
  120.         if (jsonWaypointGeometry.value("coordinates").toList().size() >= 2)
  121.         {
  122.             double lon = jsonWaypointGeometry.value("coordinates").toList().at(0).toDouble();
  123.             double lat = jsonWaypointGeometry.value("coordinates").toList().at(1).toDouble();
  124.            
  125.             waypoint->Coordinates_present(true);
  126.             waypoint->Coordinates().latitude().base_value(MathUtils::convert(MathUtils::Hour, MathUtils::Second, lat));
  127.             waypoint->Coordinates().longitude().base_value(MathUtils::convert(MathUtils::Hour, MathUtils::Second, lon));
  128.         }
  129.        
  130.         // airway
  131.        
  132.         QString airway = jsonWaypointProperty.value("onRoute").toString();
  133.        
  134.         waypoint->Airway_present(true);
  135.         waypoint->Airway().basic_string::operator=(airway.toStdString());
  136.         waypoint->Airway().type_present(true);
  137.        
  138.         // altitude
  139.        
  140.         double alt = jsonWaypointProperty.value("flightRule").toMap().value("altitude").toDouble();
  141.        
  142.         waypoint->Altitude_present(true);
  143.         waypoint->Altitude().EstimatedAltitude().Value().unit(altitudeUnitType::ft_100);
  144.         waypoint->Altitude().EstimatedAltitude().Value().base_value(alt);
  145.        
  146.         // ground speed
  147.        
  148.         double spd = jsonWaypointProperty.value("flightRule").toMap().value("speed").toString().toDouble();
  149.        
  150.         waypoint->GroundSpeed_present(true);
  151.         waypoint->GroundSpeed().EstimatedSpeed().Value().unit(speedUnitType::kt);
  152.         waypoint->GroundSpeed().EstimatedSpeed().Value().base_value(spd);
  153.        
  154.         // distance
  155.        
  156.         double dist = jsonWaypointProperty.value("distanceFromPreviousPoint").toDouble();
  157.        
  158.         waypoint->GroundDistance_present(true);
  159.         waypoint->GroundDistance().Value().unit(distanceUnitType::NM);
  160.         waypoint->GroundDistance().Value().base_value(dist);
  161.        
  162.         // timeOverWaypoint
  163.        
  164.         qint64 elapsed = jsonWaypointProperty.value("estimatedElapsedTime").toDouble();
  165.         QDateTime jsonTime = jsonEtd.addSecs(elapsed * 60);
  166.        
  167.         waypoint->TimeOverWaypoint_present(true);
  168.         waypoint->TimeOverWaypoint().EstimatedTime().Value().day(    jsonTime.date().day());
  169.         waypoint->TimeOverWaypoint().EstimatedTime().Value().month(  jsonTime.date().month());
  170.         waypoint->TimeOverWaypoint().EstimatedTime().Value().year(   jsonTime.date().year());
  171.         waypoint->TimeOverWaypoint().EstimatedTime().Value().minutes(jsonTime.time().minute());
  172.         waypoint->TimeOverWaypoint().EstimatedTime().Value().hours(  jsonTime.time().hour());
  173.        
  174.         // add waypoint
  175.         fp->Waypoints().Waypoint().push_back(waypoint);
  176.     }
  177.    
  178.     // estimated time of arrival
  179.    
  180.     QString jsonEtaString = jsonObject.value("estimatedArrivalTime").toString();
  181.     QDateTime jsonEta = QDateTime::fromString(jsonEtaString, Qt::ISODate).toUTC();
  182.    
  183.     fp->FlightPlanSummary_present(true);
  184.     fp->FlightPlanSummary().ScheduledTimeOfArrival_present(true);
  185.     fp->FlightPlanSummary().ScheduledTimeOfArrival().year(jsonEta.date().year());
  186.     fp->FlightPlanSummary().ScheduledTimeOfArrival().month(jsonEta.date().month());
  187.     fp->FlightPlanSummary().ScheduledTimeOfArrival().day(jsonEta.date().day());
  188.     fp->FlightPlanSummary().ScheduledTimeOfArrival().hours(jsonEta.time().hour());
  189.     fp->FlightPlanSummary().ScheduledTimeOfArrival().minutes(jsonEta.time().minute());
  190.    
  191.     // test
  192. //    for (size_t i = 0; i < fp->Waypoints().Waypoint().size(); ++i) {
  193. //        WaypointType *wpt = &fp->Waypoints().Waypoint()[i];
  194. //        qDebug() << QString(wpt->waypointName().data()) << wpt->Coordinates().latitude().base_value() << wpt->Coordinates().longitude().base_value();
  195. //    }
  196.    
  197.     return fp;
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement