Ejemplo n.º 1
0
        private void ParsePositionTime()
        {
            //InformationField
            ParseDateTime(InformationField.Substring(0, 7));
            string psr = InformationField.Substring(7);


            //after parsing position and symbol from the information field
            //all that can be left is a comment
            Comment = ParsePositionAndSymbol(psr);

            //ignoring weather data "_" for now
        }
Ejemplo n.º 2
0
 private string getValue(InformationField field)
 {
     fields.TryGetValue(field, out string result);
     return(result);
 }
Ejemplo n.º 3
0
        private void ParseMicE()
        {
            char ConvertDest(char ch)
            {
                int ci = ch - 0x30; //adjust all to be 0 based

                if (ci == 0x1C)
                {
                    ci = 0x0A;     //change L to be a space digit
                }
                if ((ci > 0x10) && (ci <= 0x1B))
                {
                    ci = ci - 1;                      //A-K need to be decremented
                }
                if ((ci & 0x0F) == 0x0A)
                {
                    ci = ci & 0xF0;              //space is converted to 0 - we don't support ambiguity
                }
                return((char)ci);
            }

            string dest = DestCallsign.StationCallsign;

            if (dest.Length < 6 || dest.Length == 7)
            {
                return;
            }

            //validate
            bool custom = (((dest[0] >= 'A') && (dest[0] <= 'K')) || ((dest[1] >= 'A') && (dest[1] <= 'K')) || ((dest[2] >= 'A') && (dest[2] <= 'K')));

            for (int j = 0; j < 3; j++)
            {
                var ch = dest[j];
                if (custom)
                {
                    if ((ch < '0') || (ch > 'L') || ((ch > '9') && (ch < 'A')))
                    {
                        return;
                    }
                }
                else
                {
                    if ((ch < '0') || (ch > 'Z') || ((ch > '9') && (ch < 'L')) || ((ch > 'L') && (ch < 'P')))
                    {
                        return;
                    }
                }
            }
            for (int j = 3; j < 6; j++)
            {
                var ch = dest[j];
                if ((ch < '0') || (ch > 'Z') || ((ch > '9') && (ch < 'L')) || ((ch > 'L') && (ch < 'P')))
                {
                    return;
                }
            }
            if (dest.Length > 6)
            {
                if ((dest[6] != '-') || (dest[7] < '0') || (dest[7] > '9'))
                {
                    return;
                }
                if (dest.Length == 9)
                {
                    if ((dest[8] < '0') || (dest[8] > '9'))
                    {
                        return;
                    }
                }
            }

            //parse the destination field
            int c   = ConvertDest(dest[0]);
            int mes = 0; //message code

            if ((c & 0x10) != 0)
            {
                mes = 0x08;            //set the custom flag
            }
            if (c >= 0x10)
            {
                mes = mes + 0x04;
            }
            int d = (c & 0x0F) * 10; //degrees

            c = ConvertDest(dest[1]);
            if (c >= 0x10)
            {
                mes = mes + 0x02;
            }
            d = d + (c & 0x0F);
            c = ConvertDest(dest[2]);
            if (c >= 0x10)
            {
                mes += 1;
            }
            //save message index
            MessageData.MsgIndex = mes;
            int m = (c & 0x0F) * 10; //minutes

            c = ConvertDest(dest[3]);
            bool north = c >= 0x20;

            m = m + (c & 0x0F);
            c = ConvertDest(dest[4]);
            bool hundred = c >= 0x20;       //flag for adjustment
            int  s       = (c & 0x0F) * 10; //hundredths of minutes

            c = ConvertDest(dest[5]);
            bool west = c >= 0x20;

            s = s + (c & 0x0F);
            double lat = d + (m / 60.0) + (s / 6000.0);

            if (!north)
            {
                lat = -lat;
            }
            Position.CoordinateSet.Latitude = new Coordinate(lat, true);

            //parse the symbol
            if (InformationField.Length > 6)
            {
                SymbolCode = InformationField[6];
            }
            if (InformationField.Length > 7)
            {
                SymbolTableIdentifier = InformationField[7];
            }

            //set D7/D700 flags
            if (InformationField.Length > 8)
            {
                FromD7   = InformationField[8] == '>';
                FromD700 = InformationField[8] == ']';
            }

            //parse the longitude
            d = InformationField[0] - 28;
            m = InformationField[1] - 28;
            s = InformationField[2] - 28;

            //validate
            if ((d < 0) || (d > 99) || (m < 0) || (m > 99) || (s < 0) || (s > 99))
            {
                Position.Clear();
                return;
            }

            //adjust the degrees value
            if (hundred)
            {
                d = d + 100;
            }
            if (d >= 190)
            {
                d = d - 190;
            }
            else if (d >= 180)
            {
                d = d - 80;
            }
            //adjust minutes 0-9 to proper spot
            if (m >= 60)
            {
                m = m - 60;
            }
            double lon = d + (m / 60.0) + (s / 6000.0);

            if (west)
            {
                lon = -lon;
            }
            Position.CoordinateSet.Longitude = new Coordinate(lon, false);

            //record comment
            Comment = InformationField.Length > 8 ? InformationField.Substring(8) : string.Empty;

            if (InformationField.Length > 5)
            {
                //parse the Speed/Course (s/d)
                m = InformationField[4] - 28;
                if ((m < 0) || (m > 97))
                {
                    return;
                }
                s = InformationField[3] - 28;
                if ((s < 0) || (s > 99))
                {
                    return;
                }
                s = (int)Math.Round((double)((s * 10) + (m / 10))); //speed in knots
                d = InformationField[5] - 28;
                if ((d < 0) || (d > 99))
                {
                    return;
                }

                d = ((m % 10) * 100) + d; //course
                if (s >= 800)
                {
                    s = s - 800;
                }
                if (d >= 400)
                {
                    d = d - 400;
                }
                if (d > 0)
                {
                    Position.Course = d;
                    Position.Speed  = s;
                }
            }
        }