Ejemplo n.º 1
0
            public override string ToString()
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendLine("Global Positioning System Fix Data");
                sb.AppendLine("Fix taken at:\t" + Time.ToLongTimeString());
                sb.AppendLine("Latitude:\t" + Latitude + LatHeading);
                sb.AppendLine("Longitude:\t" + Longitude + LongHeading);
                sb.AppendLine("Fix quality:\t" + NMEA_Parser.QualityName(Quality));
                sb.AppendLine("Satellites:\t" + Satelites);
                sb.AppendLine("Dilution:\t" + Dilution);
                sb.AppendLine("Altitude:\t" + Altitude + AltMeasure);
                sb.AppendLine("Mean Sea Level:\t" + WGS84 + WGS84Measure);
                return(sb.ToString());
            }
Ejemplo n.º 2
0
            public GPS_Data(string[] sa)
            {
                Time = NMEA_Parser.parseUTC(sa[1]);

                Latitude     = rawToDeg(sa[2]);
                LatHeading   = sa[3];
                Longitude    = rawToDeg(sa[4]);
                LongHeading  = sa[5];
                Quality      = int.Parse(sa[6]);
                Satelites    = int.Parse(sa[7]);
                Dilution     = float.Parse(sa[8], System.Globalization.NumberStyles.Any);
                Altitude     = float.Parse(sa[9], System.Globalization.NumberStyles.Any);
                AltMeasure   = sa[10];
                WGS84        = float.Parse(sa[11], System.Globalization.NumberStyles.Any);
                WGS84Measure = sa[12];
            }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (!File.Exists("/dev/ttyUSB0"))
                {
                    return;
                }
                bool parse   = ParseArgs(args, "p", "parse");
                bool settime = ParseArgs(args, "s", "set", "settime");
                bool once    = ParseArgs(args, "o", "once");
                bool raw     = ParseArgs(args, "r", "raw");
                if (settime)
                {
                    parse = true;
                    raw   = false;
                    once  = true;
                }
                if (once)
                {
                    parse = true;
                    raw   = false;
                }

                SerialPort sp = new SerialPort("/dev/ttyUSB0", 9600, Parity.None, 8, StopBits.One);
                sp.Open();

                Console.Clear();

                NMEA_Parser parser = new NMEA_Parser();
                bool        hasFix = true;
                while (true)
                {
                    if (parse)
                    {
                        string s = sp.ReadLine();

                        GPS_Data data = parser.GPGGA(s);
                        DateTime dt   = parser.GPZDA(s);
                        if (data != null)
                        {
                            Console.WriteLine(data.ToString());
                            Console.WriteLine();
                            hasFix = true;
                        }
                        else if (dt.Ticks > 0)
                        {
                            if (dt.Ticks > 0)
                            {
                                //"HH:MM:SS MM/DD/YYYY"
                                if (settime)
                                {
                                    Console.WriteLine("Set Time to:");
                                    Process p = Process.Start("date", "-s \"" + dt.ToString().Replace(".", "/") + "\"");
                                    while (!p.HasExited)
                                    {
                                        ;
                                    }
                                }
                                else
                                {
                                    Console.WriteLine(dt.ToString());
                                    Console.WriteLine();
                                }
                                if (once)
                                {
                                    break;
                                }
                                hasFix = true;
                                Console.SetCursorPosition(0, 0);
                            }
                        }
                        else
                        {
                            if (hasFix)
                            {
                                Console.WriteLine("No Fix available!");
                            }
                            hasFix = false;
                        }
                    }
                    if (raw)
                    {
                        Console.Write(sp.ReadExisting());
                    }
                }
                sp.Close();
            }
            else
            {
                Console.WriteLine("Usage:");
                foreach (string s in arguments)
                {
                    Console.Write("gps.exe "); Console.WriteLine(s);
                }
                Console.WriteLine("Set Time requires root permissions!");
                Console.WriteLine();
            }
        }