Beispiel #1
0
        public override Location Parse(MessageInput input)
        {
            Match locationMatch =
                new Regex(
                    "simei:(\\d+)," +      // imei
                    "(.*?)" +              // ignore
                    "(\\d{12})," +         // yy mm dd hh mm ss
                    "(A|V)," +             // gps fix
                    "(\\d+.\\d+),(N|S)," + // latitude
                    "(\\d+.\\d+),(E|W)," + // longitude
                    "(\\d+.\\d+),")        // speed
                .Match(input.DataMessage.String);

            if (locationMatch.Success)
            {
                input.Client.SetDevice(locationMatch.Groups[1].Value);

                Location location = new Location
                {
                    Device         = input.Client.Device,
                    DateTime       = NewDateTimeUtil.Convert(DateFormat.YYMMDDHHMMSS, locationMatch.Groups[3].Value),
                    PositionStatus = locationMatch.Groups[4].Value == "A",
                    Latitude       = GpsUtil.ConvertDmmLatToDecimal(locationMatch.Groups[5].Value,
                                                                    locationMatch.Groups[6].Value),
                    Longitude = GpsUtil.ConvertDmmLongToDecimal(locationMatch.Groups[7].Value,
                                                                locationMatch.Groups[8].Value),
                    Speed = locationMatch.Groups[9].Get <decimal?>()
                };

                return(location);
            }

            return(null);
        }
        public override Location Parse(MessageInput input)
        {
            Match locationMatch =
                new Regex(
                    "(\\d+)," +                                 // device id
                    "(\\d{4}\\d{2}\\d{2}\\d{2}\\d{2}\\d{2})," + // YYYY mm dd hh mm ss
                    "(-?\\d+.\\d+)," +                          // longitude
                    "(-?\\d+.\\d+)," +                          // latitude
                    "(\\d+)," +                                 // speed
                    "(\\d+)," +                                 // heading
                    "(.*?)," +                                  // altitude
                    "(\\d+)")                                   // satellites
                .Match(input.DataMessage.String);

            if (locationMatch.Success)
            {
                input.Client.SetDevice(locationMatch.Groups[1].Value);

                Location location = new Location
                {
                    Device     = input.Client.Device,
                    DateTime   = NewDateTimeUtil.Convert(DateFormat.YYYYMMDDHHMMSS, locationMatch.Groups[2].Value),
                    Longitude  = locationMatch.Groups[3].Get <decimal>(),
                    Latitude   = locationMatch.Groups[4].Get <decimal>(),
                    Speed      = locationMatch.Groups[5].Get <decimal?>(),
                    Heading    = locationMatch.Groups[6].Get <decimal?>(),
                    Altitude   = locationMatch.Groups[7].Get <decimal?>(),
                    Satellites = locationMatch.Groups[8].Get <short?>(),
                };

                return(location);
            }

            return(null);
        }
Beispiel #3
0
        public override Location Parse(MessageInput input)
        {
            Match locationMatch =
                new Regex(
                    "\\$GM(\\d)(.{2})?" +
                    "(\\d{15})" +                               // imei
                    "T(\\d{2}\\d{2}\\d{2}\\d{2}\\d{2}\\d{2})" + // dd mm yy hh mm ss
                    "(N|S)(\\d{2}\\d{2}\\d{4})" +               // latitude dd mm ssss
                    "(E|W)(\\d{3}\\d{2}\\d{4})" +               // longitude ddd mm ssss
                    "(\\d{3})" +                                // speed
                    "(\\d{3})" +                                // heading
                    "(.)" +                                     // satellites hex
                    "(.{2})(\\d)(\\d)(\\d{3})#")
                .Match(input.DataMessage.String);

            if (locationMatch.Success)
            {
                input.Client.SetDevice(locationMatch.Groups[3].Value);

                Location location = new Location
                {
                    Device     = input.Client.Device,
                    DateTime   = NewDateTimeUtil.Convert(DateFormat.DDMMYYHHMMSS, locationMatch.Groups[4].Value),
                    Latitude   = NewGpsUtil.Convert(GpsFormat.DDDMMmmmm, locationMatch.Groups[6].Value, locationMatch.Groups[5].Value),
                    Longitude  = NewGpsUtil.Convert(GpsFormat.DDDMMmmmm, locationMatch.Groups[8].Value, locationMatch.Groups[7].Value),
                    Speed      = locationMatch.Groups[9].Get <decimal?>(),
                    Heading    = locationMatch.Groups[10].Get <decimal?>(),
                    Satellites = short.Parse(locationMatch.Groups[11].Value, NumberStyles.HexNumber)
                };

                return(location);
            }

            return(null);
        }
        public override Location Parse(MessageInput input)
        {
            Match locationMatch =
                new Regex("\\((\\d+)" +        // imei
                          "(.*?)(\\d{12})" +   // date time yy mm dd hh mm ss
                          "(A|V)" +            // gps fix
                          "(\\d+.\\d+)(N|S)" + // latitude
                          "(\\d+.\\d+)(E|W)" + // longitude
                          "(\\d{3}.\\d)" +     // speed
                          "(\\d+.\\d+)")       // heading
                .Match(input.DataMessage.String);

            if (locationMatch.Success)
            {
                Location location = new Location
                {
                    Device = new Device
                    {
                        DeviceId = locationMatch.Groups[1].Value
                    },
                    DateTime       = NewDateTimeUtil.Convert(DateFormat.YYMMDDHHMMSS, locationMatch.Groups[3].Value),
                    PositionStatus = locationMatch.Groups[4].Value == "A",
                    Latitude       = GpsUtil.ConvertDmmLatToDecimal(locationMatch.Groups[5].Value, locationMatch.Groups[6].Value),
                    Longitude      = GpsUtil.ConvertDmmLongToDecimal(locationMatch.Groups[7].Value, locationMatch.Groups[8].Value),
                    Speed          = locationMatch.Groups[9].Get <decimal?>(),
                    Heading        = locationMatch.Groups[10].Get <decimal?>()
                };

                return(location);
            }

            return(null);
        }
Beispiel #5
0
        // Input example: $GPRMC,102156.000,A,2232.4690,N,11403.6847,E,0.00,,180909,,*15
        public static GPRMC Parse(string input)
        {
            Match match = new Regex("(\\d{2}\\d{2}\\d{2}.\\d+)," + // dd mm yy
                                    "(A|V)," +                     // gps fix
                                    "(\\d+.\\d+),(N|S)," +         // latitude
                                    "(\\d+.\\d+),(E|W)," +         // longitude
                                    "(.*?)," +                     // speed
                                    "(.*?)," +                     // heading
                                    "(\\d{2}\\d{2}\\d{2})")        // hh mm ss . ss
                          .Match(input);

            if (match.Success)
            {
                GPRMC gprmc = new GPRMC
                {
                    DateTime = NewDateTimeUtil.Convert(DateFormat.HHMMSS_SS_DDMMYY, match.Groups[1].Value,
                                                       match.Groups[9].Value),
                    PositionStatus = match.Groups[2].Value == "A",
                    Latitude       = GpsUtil.ConvertDmmLatToDecimal(match.Groups[3].Value, match.Groups[4].Value),
                    Longitude      = GpsUtil.ConvertDmmLongToDecimal(match.Groups[5].Value, match.Groups[6].Value),
                    Speed          = SpeedUtil.KnotsToKph(match.Groups[7].Get <decimal>()),
                    Heading        = match.Groups[8].Get <decimal?>()
                };

                return(gprmc);
            }

            return(null);
        }
        private static Location Location(MessageInput input)
        {
            Match locationMatch =
                new Regex(
                    _pattern)
                .Match(input.DataMessage.String);

            if (locationMatch.Success)
            {
                Location location = new Location
                {
                    Device = new Device
                    {
                        DeviceId = locationMatch.Groups[1].Value
                    },
                    DateTime = NewDateTimeUtil.Convert(DateFormat.DDMMYYHHMMSS,
                                                       $"{locationMatch.Groups[10].Value}{locationMatch.Groups[2].Value}"),
                    Latitude = GpsUtil.ConvertDmmLatToDecimal(locationMatch.Groups[4].Value,
                                                              locationMatch.Groups[5].Value),
                    Longitude = GpsUtil.ConvertDmmLongToDecimal(locationMatch.Groups[6].Value,
                                                                locationMatch.Groups[7].Value),
                    Speed   = SpeedUtil.KnotsToKph(locationMatch.Groups[8].Get <decimal>()),
                    Heading = locationMatch.Groups[9].Get <decimal>()
                };

                SendLocationAcknowledge(locationMatch.Groups[3].Value, locationMatch.Groups[11].Value,
                                        locationMatch.Groups[17].Value, input);

                return(location);
            }

            return(null);
        }
Beispiel #7
0
        private static Location HandleLocation(MessageInput input)
        {
            if (input.Client.Device != null)
            {
                string locationRegex = "(\\d+\\/\\d+\\/\\d+)," + // date dd/mm/yy
                                       "(\\d+:\\d+:\\d+)," +     // time hh:mm:ss
                                       "(.*?)," +                // latitude
                                       "(.*?)," +                // longitude
                                       "(.*?)," +                // speed
                                       "(.*?)," +                // heading
                                       "((.*?)," +               // flags
                                       "(.*?)," +                //altitude
                                       "(\\d+)," +               // battery
                                       "(\\d+)," +               // satellites in use
                                       "(\\d+),)?";              // satellites in view

                Match locationMatch =
                    new Regex(locationRegex)
                    .Match(input.DataMessage.String);

                if (locationMatch.Success)
                {
                    Location location = new Location
                    {
                        Device   = input.Client.Device,
                        DateTime = NewDateTimeUtil.Convert(DateFormat.DDMMYY_HHMMSS, locationMatch.Groups[1].Value,
                                                           locationMatch.Groups[2].Value),
                        Latitude   = locationMatch.Groups[3].Get <decimal>(),
                        Longitude  = locationMatch.Groups[4].Get <decimal>(),
                        Speed      = locationMatch.Groups[5].Get <decimal?>(),
                        Heading    = locationMatch.Groups[6].Get <decimal?>(),
                        Altitude   = locationMatch.Groups[9].Get <decimal?>(),
                        Satellites = locationMatch.Groups[11].Get <short?>()
                    };

                    return(location);
                }
            }

            return(null);
        }
        private void SetData(string dataString, Location location)
        {
            string[] data    = dataString.Split(",");
            string[] dataKey = DefaultDataFormat.Split(",");

            for (int i = 0; i < Math.Min(data.Length, dataKey.Length); i++)
            {
                if (dataKey[i] == "#LAT#")
                {
                    location.Latitude = GetCoordinate(data[i]);
                }

                if (dataKey[i] == "#LONG#")
                {
                    location.Longitude = GetCoordinate(data[i]);
                }

                if (dataKey[i] == "#SPD#")
                {
                    location.Speed = SpeedUtil.KnotsToKph(Convert.ToDecimal(data[i]));
                }

                if (dataKey[i] == "#HEAD#")
                {
                    location.Heading = Convert.ToDecimal(data[i]);
                }

                if (dataKey[i] == "#ODO#")
                {
                    location.Odometer = Convert.ToDouble(data[i]) * 1000;
                }

                if (dataKey[i] == "#EDT#")
                {
                    location.DateTime = NewDateTimeUtil.Convert(DateFormat.YYMMDDHHMMSS, data[i]);
                }
            }
        }