private string GetJSON()
        {
            string fp = "";

            try
            {
                string res = "";
                string sep = "";
                for (int i = 0; i < 1; i++)
                {
                    foreach (Waypoint wp in this.WaypointList)
                    {
                        res = "";
                        res = JSon.ToString(res, "id", wp.ID);
                        res = JSon.ToString(res, "icao", wp.ICAO);
                        res = JSon.ToString(res, "desc", wp.WaypointDesc);
                        res = JSon.ToString(res, "wptype", wp.WaypointType);
                        res = JSon.ToString(res, "lat", wp.Coord.Lat.Degree);
                        res = JSon.ToString(res, "lng", wp.Coord.Lng.Degree);
                        res = JSon.ToString(res, "alt", wp.Altitude);
                        //res = JSon.ToString(res, "dest", 0);
                        //res = JSon.ToString(res, "brg", 0);
                        fp += sep + "{" + res + "}";
                        sep = ",";
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return("{\"type\":\"flightplan\", \"timestamp\": " + this.LoadDt.Ticks.ToString() + ", \"data\": [" + fp + "]}");
        }
Example #2
0
        public string GetVariablesJSON()
        {
            string   res = "";
            DateTime dt  = DateTime.Now;

            res = JSon.ToString(res, "PacketID", (Int32)this.Counter);
            this.Counter++;
            foreach (var item in this.VarList)
            {
                if (item.Value != null)
                {
                    if (item.Value is string)
                    {
                        res = JSon.ToString(res, item.ID, item.Value.ToString());
                    }
                    else if (item.Value is Int32)
                    {
                        res = JSon.ToString(res, item.ID, (Int32)item.Value);
                    }
                    else
                    {
                        res = JSon.ToString(res, item.ID, (Double)item.Value);
                    }
                }
                else
                {
                    if (item.Unit.ToLower() == "string")
                    {
                        res = JSon.ToString(res, item.ID, "0");
                    }
                    else
                    {
                        res = JSon.ToString(res, item.ID, 0.0);
                    }
                }
            }
            return("{\"type\":\"variables\", \"data\": {" + res + "}}");
        }
Example #3
0
        protected override void OnMessage(MessageEventArgs e)
        {
            string res = "";

            if (this.MainWindow != null && this.MainWindow.SimConnectViewModel != null && this.MainWindow.FlightPlanViewModel != null)
            {
                //if (Globals.MainWindow.FlightPlanViewModel.LoadDt != this.LastFlightPlanDt)
                //{
                //    this.Send(Globals.MainWindow.FlightPlanViewModel.FlightPlanJSON);
                //    LastFlightPlanDt = Globals.MainWindow.FlightPlanViewModel.LoadDt;
                //}

                if (e.Data == "getposition")
                {
                    var lat = this.MainWindow.SimConnectViewModel.VarList.Where(k => k.VarName == "PLANE LATITUDE").FirstOrDefault();
                    var lng = this.MainWindow.SimConnectViewModel.VarList.Where(k => k.VarName == "PLANE LONGITUDE").FirstOrDefault();
                    var hdg = this.MainWindow.SimConnectViewModel.VarList.Where(k => k.VarName == "PLANE HEADING DEGREES TRUE").FirstOrDefault();
                    if (lat != null && lng != null && hdg != null)
                    {
                        res = JSon.ToString(res, "PLANE_LATITUDE", lat.Value != null ? (double)lat.Value : 47.434387018741525);
                        res = JSon.ToString(res, "PLANE_LONGITUDE", lng.Value != null ? (double)lng.Value : 19.264183044433597);
                        res = JSon.ToString(res, "PLANE_HEADING_DEGREES_TRUE", hdg.Value != null ? (double)hdg.Value : 0);
                        this.Send("{\"type\":\"position\", \"data\": {" + res + "}}");
                    }
                    else
                    {
                        this.Send("{\"type\":\"status\", \"data\": \"No valid position!\"}");
                    }
                    return;
                }
                else if (this.DealWithDataBase)
                {
                    if (e.Data.StartsWith("{\"cmd\":"))
                    {
                        QueryModel q = JsonConvert.DeserializeObject <QueryModel>(e.Data);
                        if (q.cmd == "getairports")
                        {
                            MapDetailsModel d = JsonConvert.DeserializeObject <MapDetailsModel>(q.data.ToString());


                            AirPortsInfo ai = new AirPortsInfo();
                            ai.AirPorts = Globals.DatabaseViewModel.SelectAirPorts(d);
                            res         = JsonConvert.SerializeObject(ai);
                            this.Send(res);
                            return;
                        }
                        else if (q.cmd == "getparkings")
                        {
                            MapDetailsModel d = JsonConvert.DeserializeObject <MapDetailsModel>(q.data.ToString());

                            ResponseParkings rap = new ResponseParkings();
                            rap.type     = "parkings";
                            rap.parkings = Globals.DatabaseViewModel.SelectParkings(d);
                            res          = JsonConvert.SerializeObject(rap);
                            this.Send(res);
                            return;
                        }
                        else if (q.cmd == "getvors")
                        {
                            MapDetailsModel d = JsonConvert.DeserializeObject <MapDetailsModel>(q.data.ToString());

                            ResponseVORs vrs = new ResponseVORs();
                            vrs.vors = Globals.DatabaseViewModel.SelectVORs(d);
                            res      = JsonConvert.SerializeObject(vrs);
                            this.Send(res);
                            return;
                        }
                        else if (q.cmd == "getairportbyname")
                        {
                            AirPortInfo ai = new AirPortInfo();
                            ai.AirPort = Globals.DatabaseViewModel.SelectAirPorts(q.data.ToString());
                            res        = JsonConvert.SerializeObject(ai);
                            this.Send(res);
                            return;
                        }
                        else if (q.cmd == "getvorbyid")
                        {
                            VORInfo v = new VORInfo();
                            v.VOR = Globals.DatabaseViewModel.SelectVOR((Int64)q.data);
                            res   = JsonConvert.SerializeObject(v);
                            this.Send(res);
                            return;
                        }
                        this.Send("{\"type\":\"status\", \"data\": \"Unknown cmd\"}");
                    }
                    else
                    {
                        this.Send("{\"type\":\"status\", \"data\": \"Unknown query\"}");
                    }
                }
                else
                {
                    this.Send("{\"type\":\"status\", \"data\": \"No database\"}");
                }
            }
            else
            {
                this.Send("{\"type\":\"status\", \"data\": \"Not Connected\"}");
            }
        }