Exemple #1
0
        public override List <GoalDeclaration> GetGoalDeclarations()
        {
            var declarations = new List <GoalDeclaration>();

            foreach (var line in TrackLogLines.Where(l => l.StartsWith("E") && l.Substring(7, 3) == "XX1"))
            {
                var wp = ParseDeclaration(line);
                declarations.Add(wp);
            }
            return(declarations);
        }
Exemple #2
0
        public override GeoPoint[] GetTrackLog()
        {
            var lines  = TrackLogLines.Where(l => l.StartsWith("B")).ToArray();
            var points = new GeoPoint[lines.Length];

            Parallel.For(0, lines.Length, i =>
            {
                points[i] = ParseTrackPoint(lines[i]);
            });

            return(points.Where(p => p != null).ToArray());
        }
Exemple #3
0
        public TRKFile(string filePath, TimeSpan utcOffset)
            : base(filePath, utcOffset)
        {
            LogFileExtension = ".trk";
            SignatureStatus  = SignatureStatus.NotSigned;

            //get logger info
            LoggerModel = TrackLogLines.FirstOrDefault(l => l[0] == 'P');
            if (!string.IsNullOrEmpty(LoggerModel))
            {
                LoggerModel = LoggerModel.Substring(2).Trim();
            }
        }
Exemple #4
0
        public override List <GeoWaypoint> GetMarkers()
        {
            var markers = new List <GeoWaypoint>();

            foreach (var line in TrackLogLines.Where(l => l.StartsWith("E") && l.Substring(7, 3) == "XX0"))
            {
                var wp = ParseMarker(line);
                if (wp != null)
                {
                    markers.Add(wp);
                }
            }
            return(markers);
        }
Exemple #5
0
        private int vSpOffset  = int.MinValue; //offset of the variometer vertical speed relative to position data origin

        public IGCFile(string logFilePath, TimeSpan utcOffset, string altitudeCorrectionsFilePath = null)
            : base(logFilePath, utcOffset)
        {
            IsAltitudeBarometric = true;
            LogFileExtension     = ".igc";

            //get signature info
            var v = new Verifier()
            {
                AcceptOldKey = true
            };

            if (v.Verify(logFilePath))
            {
                SignatureStatus = SignatureStatus.Genuine;
            }
            else
            {
                SignatureStatus = SignatureStatus.Counterfeit;
            }

            //get logger info
            try
            {
                var loggerInfo = TrackLogLines.First(l => l.StartsWith("AXXX"));
                LoggerModel        = loggerInfo.Substring(7);
                LoggerSerialNumber = loggerInfo.Substring(4, 3);
            }
            catch (InvalidOperationException) { }

            //get pilot info
            try
            {
                var pilotInfo = TrackLogLines.First(l => l.StartsWith("HFPID"));
                PilotId = int.Parse(pilotInfo.Substring(5));
            }
            catch (InvalidOperationException) { }


            //get date
            try
            {
                var dateInfo = TrackLogLines.First(l => l.StartsWith("HFDTE"));
                loggerDate = ParseDateAt(dateInfo, 9);
            }
            catch (InvalidOperationException) { }
            try
            {
                var dateInfo = TrackLogLines.Last(l => l.StartsWith("K"));
                loggerDate = ParseDateAt(dateInfo, 11);
            }
            catch (InvalidOperationException) { }

            //get IGC B record format
            try
            {
                var format         = TrackLogLines.Last(l => l.StartsWith("I"));
                var BRecordVersion = int.Parse(format.Substring(1, 2));
                if (BRecordVersion >= 5)
                {
                    var latInfoPos = format.IndexOf("LAD");
                    dLatOffset = int.Parse(format.Substring(latInfoPos - 4, 2)) - 1 - 7; //7 is the offset to position data origin

                    var lonInfoPos = format.IndexOf("LOD");
                    dLonOffset = int.Parse(format.Substring(lonInfoPos - 4, 2)) - 1 - 7;

                    var vspInfoPos = format.IndexOf("VAR");
                    vSpOffset = int.Parse(format.Substring(vspInfoPos - 4, 2)) - 1 - 7;
                }
            }
            catch (InvalidOperationException) { }


            //check datum
            try
            {
                var datumInfo = TrackLogLines.Last(l => l.StartsWith("HFDTM"));
                loggerDatum = Datum.GetInstance(datumInfo.Substring(8));
                if (loggerDatum.Name != "WGS84")
                {
                    throw new InvalidOperationException("IGC file datum must be WGS84");
                }
            }
            catch (InvalidOperationException) { }

            //load altitude correction
            altitudeCorrection = 0;
            try
            {
                var strCorrection = File.ReadAllLines(altitudeCorrectionsFilePath).First(l => l.Trim().StartsWith(LoggerSerialNumber)).Split(new char[] { '=' })[1];
                altitudeCorrection = double.Parse(strCorrection) / 10; //altitude correction in file is in dm, convert to m
            }
            catch { }
            Debug.WriteLine(string.Format("Logger altitude correction={0}", altitudeCorrection));
        }
Exemple #6
0
        public override GeoPoint[] GetTrackLog()
        {
            var utm   = false;
            var track = new List <GeoPoint>();

            foreach (var line in TrackLogLines.Where(l => l.Length > 0))
            {
                switch (line[0])
                {
                case 'G':
                {
                    //Datum
                    var strFileDatum = line.Substring(2).Trim();
                    if (strFileDatum == "WGS 84")         //Dirty hack!!!
                    {
                        strFileDatum = "WGS84";
                    }
                    loggerDatum = Datum.GetInstance(strFileDatum);
                }
                break;

                //case 'L':
                //    //Timezone
                //    var tz = TimeZoneInfo.CreateCustomTimeZone("x", -TimeSpan.Parse(fields[1]), "", "");
                //    break;
                case 'T':
                {
                    //Track point
                    var fields = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    DateTime time = DateTime.MinValue;
                    if (DateTime.TryParse(fields[4] + " " + fields[5], out time)) // if datetime is invalid, time is 0000/00/00 00:00:00
                    {
                        time += utcOffset;                                        // utc to local
                    }
                    var      altitude = double.Parse(fields[7], NumberFormatInfo.InvariantInfo);
                    GeoPoint p;

                    if (utm)
                    {
                        //file with utm coordinates
                        p = new GeoPoint(
                            time: time,
                            datum: loggerDatum,
                            zone: fields[1],
                            easting: double.Parse(fields[2], NumberFormatInfo.InvariantInfo),
                            northing: double.Parse(fields[3], NumberFormatInfo.InvariantInfo),
                            altitude: altitude);
                    }
                    else
                    {
                        //file with latlon coordinates
                        // WARNING: 'º' is out of ASCII table: don't use split
                        var strLatitude  = fields[2].Substring(0, fields[2].Length - 2);
                        var ns           = fields[2][fields[2].Length - 1];
                        var strLongitude = fields[3].Substring(0, fields[3].Length - 2);
                        var ew           = fields[3][fields[3].Length - 1];

                        var lat = double.Parse(strLatitude, NumberFormatInfo.InvariantInfo) * (ns == 'S' ? -1 : 1);
                        var lon = double.Parse(strLongitude, NumberFormatInfo.InvariantInfo) * (ew == 'W' ? -1 : 1);

                        p = new GeoPoint(
                            time: time,
                            datum: loggerDatum,
                            latitude: lat,
                            longitude: lon,
                            altitude: altitude
                            );
                    }

                    track.Add(p);
                }
                break;

                case 'U':
                {
                    //file coordinate units
                    var fields = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    utm = (fields[1] == "0");
                }
                break;
                }
            }

            return(track.ToArray());
        }