Ejemplo n.º 1
0
        private void SetGps()
        {
            GpsMessage gps = this.ga.Gps;

            if (gps != null)
            {
                double lat      = gps.latitude.V;
                double lon      = gps.longitude.V;
                double utmx     = gps.pos.getUtmX();
                double utmy     = gps.pos.getUtmY();
                double gndspeed = gps.gndSpeed.V;
                double course   = gps.trackAngle.V;
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(SetAdc));
                    return;
                }
                this.LatText.Text      = lat.ToString("0.0000000");
                this.LonText.Text      = lon.ToString("0.0000000");
                this.UtmXText.Text     = utmx.ToString("0");
                this.UtmYText.Text     = utmy.ToString("0");
                this.GndSpeedText.Text = gndspeed.ToString("0");
                this.CourseText.Text   = course.ToString("0");
            }
        }
Ejemplo n.º 2
0
        public GsvStandardGpsMessage(GpsMessage message)
            : base(StandardGpsMessageKind.Gsv)
        {
            // Example of data fields:
            // "3", "1", "12", "01", "05", "060", "18", "02", "17", "259", "43", "04", "56", "287", "28", "09", "08", "277", "28"
            // "3", "2", "12", "10", "34", "195", "46", "13", "08", "125", "45", "17", "67", "014", "", "20", "32", "048", "24"
            // "3", "3", "12", "23", "13", "094", "48", "24", "04", "292", "24", "28", "49", "178", "46", "32", "06", "037", "22"
            // or
            // "1", "1", "00"

            NumberOfMessages      = GpsValueParser.ParseNullableInt(message.DataFields[0]) ?? 1;
            SequenceNumber        = GpsValueParser.ParseNullableInt(message.DataFields[1]) ?? 1;
            TotalSatellitesInView = GpsValueParser.ParseNullableInt(message.DataFields[2]) ?? 0;

            var satellites = new List <SatelliteInView>();

            int satelliteDataFieldStartIndex = 3;

            while (satelliteDataFieldStartIndex < message.DataFields.Length)
            {
                int satelliteId = GpsValueParser.ParseNullableInt(message.DataFields[satelliteDataFieldStartIndex++]) ?? 0;
                int elevation   = GpsValueParser.ParseNullableInt(message.DataFields[satelliteDataFieldStartIndex++]) ?? 0;
                int azimuth     = GpsValueParser.ParseNullableInt(message.DataFields[satelliteDataFieldStartIndex++]) ?? 0;
                int snr         = GpsValueParser.ParseNullableInt(message.DataFields[satelliteDataFieldStartIndex++]) ?? 0;

                satellites.Add(new SatelliteInView(satelliteId, elevation, azimuth, snr));
            }

            Satellites = satellites.ToArray();
        }
Ejemplo n.º 3
0
        private void ProcessGpsMessage(GpsMessage gpsMsg)
        {
            if (gpsMsg == null)
            {
                return;
            }

            try
            {
                SmartDevice device = _gpsDevices.Find(x => x.DeviceId == gpsMsg.DeviceId);
                if (device != null)
                {
                    device.Latitude  = gpsMsg.Latitude;
                    device.Longitude = gpsMsg.Longitude;
                    BlobTable <SmartDevice> .Update(device);
                }

#if DEBUG
                Console.WriteLine(Scf.Net.IotHub.MessageHelper.ToString(gpsMsg));
#endif

                _gpsQueue.SendMessage(Scf.Net.IotHub.MessageHelper.ToString(gpsMsg));
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 4
0
        public static void handleGps(GpsMessage msg)
        {
            Console.WriteLine("==============================================================================");
            Console.WriteLine("imei:           {0}", msg.device.imei);
            Console.WriteLine("message_type:   {0}", msg.message_type);
            Console.WriteLine("gateway:        {0}", msg.gateway);
            Console.WriteLine("port:           {0}", msg.port);
            Console.WriteLine("transmission:   {0}", msg.transmission);

            Console.WriteLine("gsm.signal_str: {0}", msg.gsm[0].signal_str);
            Console.WriteLine("gsm.status:     {0}", String.Join(", ", msg.gsm[0].status));

            Console.WriteLine("sims.msisdn:    {0}", msg.sims[0].msisdn);
            Console.WriteLine("sims.iccid:     {0}", msg.sims[0].iccid);

            Console.WriteLine("gps.timestamp:  {0}", msg.gps.timestamp.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss"));
            Console.WriteLine("gps.latitude:   {0}", msg.gps.latitude);
            Console.WriteLine("gps.longitude:  {0}", msg.gps.longitude);
            Console.WriteLine("gps.altitude:   {0}", msg.gps.altitude);
            Console.WriteLine("gps.speed:      {0}", msg.gps.speed);
            Console.WriteLine("gps.heading:    {0}", msg.gps.heading);
            Console.WriteLine("gps.satellites: {0}", msg.gps.satellites);
            Console.WriteLine("gps.activity:   {0}", msg.gps.activity);
            Console.WriteLine("gps.odometer:   {0}", msg.gps.odometer);
            Console.WriteLine("gps.trip_odo:   {0}", msg.gps.trip_odo);
            Console.WriteLine("gps.fix:        {0}", String.Join(", ", msg.gps.fix));
            Console.WriteLine("gps.dop:        hdop: {0} vdop: {1} pdop: {2} tdop: {3}", msg.gps.hdop, msg.gps.vdop, msg.gps.pdop, msg.gps.tdop);

            foreach (var msg_event in msg.events)
            {
                // The first element in the list is always the event code
                Console.WriteLine("event:          {0}", msg_event[0]);
                foreach (var event_field in msg_event)
                {
                    // Any additional elements contains event data and are defined as IList's with a
                    // count of 2 where the first element is the field name and the second element is
                    // the value, e.g.:
                    // [ "HARSH_EVENT:ACCIDENT", [ "x", 15.3 ], ["y", 20.8 ], [ "z", 17.4 ] ]
                    if (event_field is IList && event_field.Count == 2)
                    {
                        Console.WriteLine("         field: {0}={1}", event_field[0], event_field[1]);
                    }
                }
            }

            foreach (var sensor in msg.sensors)
            {
                Console.WriteLine("sensor:         {0} = {1}", sensor[0], sensor[1]);
            }

            foreach (var pid in msg.obd_ii.mode_01)
            {
                Console.WriteLine("OBD PID:        {0} = {1}", pid[0], pid[1]);
            }

            Console.WriteLine("==============================================================================");
        }
Ejemplo n.º 5
0
        public bool OnMessage(object sender, ReceivedMessageEventArgs args)
        {
            GpsMessage msg = args.Message as GpsMessage;

            if (msg != null)
            {
                UpdateLocation(msg.DeviceId, msg.Latitude, msg.Longitude);
            }

            return(true);
        }
        public VtgStandardGpsMessage(GpsMessage message)
            : base(StandardGpsMessageKind.Vtg)
        {
            // Example of data fields:
            // "0.0", "T", "", "M", "0.0", "N", "0.1", "K", "A"

            CourseOverGround = GpsValueParser.ParseNullableDouble(message.DataFields[0]);
            SpeedInKnots     = GpsValueParser.ParseNullableDouble(message.DataFields[4]);
            SpeedInKmPerH    = GpsValueParser.ParseNullableDouble(message.DataFields[6]);
            PositioningMode  = GpsValueParser.ParsePositioningMode(message.DataFields[8]);
        }
Ejemplo n.º 7
0
        public TxtStandardGpsMessage(GpsMessage message)
            : base(StandardGpsMessageKind.Txt)
        {
            // Example of data fields:
            // "01", "01", "02", "ANTSTATUS=OK"

            NumberOfMessages = GpsValueParser.ParseNullableInt(message.DataFields[0]) ?? 1;
            SequenceNumber   = GpsValueParser.ParseNullableInt(message.DataFields[1]) ?? 1;
            Severity         = GpsValueParser.ParseTextMessageSeverity(message.DataFields[2]);
            TextMessage      = message.DataFields[3];
        }
Ejemplo n.º 8
0
        public bool OnMessage(object sender, ReceivedMessageEventArgs args)
        {
            GpsMessage msg = args.Message as GpsMessage;

            if (msg != null)
            {
                _mapData.UpdateLocation(msg.DeviceId, msg.Latitude, msg.Longitude);
            }

            //RedirectToAction("Index", "GpsTracking");
            return(true);
        }
Ejemplo n.º 9
0
        public GllStandardGpsMessage(GpsMessage message)
            : base(StandardGpsMessageKind.Gll)
        {
            // Example of data fields:
            // "3110.2908", "N", "12123.2348", "E", "041139.000", "A", "A"

            Latitude        = GpsValueParser.ParseLatitude(message.DataFields[0], message.DataFields[1]);
            Longitude       = GpsValueParser.ParseLongitude(message.DataFields[2], message.DataFields[3]);
            UtcTimeOfDay    = GpsValueParser.ParseUtcTime(message.DataFields[4]);
            DataValid       = message.DataFields[5] == "A";
            PositioningMode = GpsValueParser.ParsePositioningMode(message.DataFields[6]);
        }
        public RmcStandardGpsMessage(GpsMessage message)
            : base(StandardGpsMessageKind.Rmc)
        {
            // Example of data fields:
            // "013732.000", "A", "3150.7238", "N", "11711.7278", "E", "0.00", "0.00", "220413", "", "", "A"

            UtcDateTime      = GpsValueParser.ParseUtcDateTime(message.DataFields[8] + message.DataFields[0]);
            DataValid        = message.DataFields[1] == "A";
            Latitude         = GpsValueParser.ParseLatitude(message.DataFields[2], message.DataFields[3]);
            Longitude        = GpsValueParser.ParseLongitude(message.DataFields[4], message.DataFields[5]);
            Speed            = GpsValueParser.ParseNullableDouble(message.DataFields[6]);
            CourseOverGround = GpsValueParser.ParseNullableDouble(message.DataFields[7]);
            PositioningMode  = GpsValueParser.ParsePositioningMode(message.DataFields[11]);
        }
Ejemplo n.º 11
0
        public static bool TryDeserialize(string packetText, out GpsMessage message)
        {
            if (packetText == null)
            {
                message = null;
                return(false);
            }

            packetText = packetText.Trim();
            int preambleIndex = packetText.LastIndexOf('$');

            if (preambleIndex > 0)
            {
                packetText = packetText.Substring(preambleIndex);
            }

            if (string.IsNullOrEmpty(packetText) ||
                (packetText.Length < 4) ||
                (packetText[0] != '$') ||
                (packetText[packetText.Length - 3] != '*'))
            {
                message = null;
                return(false);
            }

            string checkSumText = packetText.Substring(packetText.Length - 2, 2);
            byte   checkSum;

            if (!byte.TryParse(checkSumText, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out checkSum))
            {
                message = null;
                return(false);
            }

            string messageText        = packetText.Substring(1, packetText.Length - 4);
            byte   actualCheckSumByte = messageText.Aggregate <char, byte>(0, (current, t) => (byte)(current ^ (byte)t));

            if (actualCheckSumByte != checkSum)
            {
                message = null;
                return(false);
            }

            string[] fields = messageText.Split(',');
            message = new GpsMessage(fields[0], fields.Skip(1).ToArray());
            return(true);
        }
        public GgaStandardGpsMessage(GpsMessage message)
            : base(StandardGpsMessageKind.Gga)
        {
            // Example of data fields:
            // "015540.000", "3150.68378", "N", "11711.93139", "E", "1", "17", "0.6", "0051.6", "M", "0.0", "M", "", ""

            UtcTimeOfDay                 = GpsValueParser.ParseUtcTime(message.DataFields[0]);
            Latitude                     = GpsValueParser.ParseLatitude(message.DataFields[1], message.DataFields[2]);
            Longitude                    = GpsValueParser.ParseLongitude(message.DataFields[3], message.DataFields[4]);
            FixStatus                    = GpsValueParser.ParseGgaFixStatus(message.DataFields[5]);
            NumberOfSatellites           = GpsValueParser.ParseNullableInt(message.DataFields[6]);
            HorizontalDilutioOfPrecision = GpsValueParser.ParseNullableDouble(message.DataFields[7]);
            Altitude                     = GpsValueParser.ParseNullableDouble(message.DataFields[8]);
            GeoIdSeparation              = GpsValueParser.ParseNullableDouble(message.DataFields[10]);
            DgpsAge     = GpsValueParser.ParseNullableDouble(message.DataFields[12]);
            DgpsStateId = GpsValueParser.ParseNullableDouble(message.DataFields[13]);
        }
        public GsaStandardGpsMessage(GpsMessage message)
            : base(StandardGpsMessageKind.Gsa)
        {
            // Example of data fields:
            // "A", "3", "14", "06", "16", "31", "23", "", "", "", "", "", "", "", "1.66", "1.42", "0.84"

            Mode      = GpsValueParser.ParseGsaMode(message.DataFields[0]);
            FixStatus = GpsValueParser.ParseGsaFixStatus(message.DataFields[1]);

            SatelliteUsedPerChannelArray = new int?[12];
            for (int i = 0; i < SatelliteUsedPerChannelArray.Length; i++)
            {
                SatelliteUsedPerChannelArray[i] = GpsValueParser.ParseNullableInt(message.DataFields[2 + i]);
            }

            PositionDilutionOfPrecision   = GpsValueParser.ParseNullableDouble(message.DataFields[14]);
            HorizontalDilutionOfPrecision = GpsValueParser.ParseNullableDouble(message.DataFields[15]);
            VerticalDilutionOfPrecision   = GpsValueParser.ParseNullableDouble(message.DataFields[16]);
        }
Ejemplo n.º 14
0
        public static byte[] Serialize(GpsMessage message)
        {
            string messageText = message.MessageId + "," + string.Join(",", message.DataFields);

            byte[] messageBytes = Encoding.ASCII.GetBytes(messageText);
            byte   checksumByte = messageBytes.Aggregate <byte, byte>(0, (current, messageByte) => (byte)(current ^ messageByte));
            string checkSum     = checksumByte.ToString("X2");

            var packetBytes = new byte[messageBytes.Length + 6];

            packetBytes[0] = (byte)'$';
            Array.Copy(messageBytes, 0, packetBytes, 1, messageBytes.Length);
            packetBytes[messageBytes.Length + 1] = (byte)'*';
            packetBytes[messageBytes.Length + 2] = (byte)checkSum[0];
            packetBytes[messageBytes.Length + 3] = (byte)checkSum[1];
            packetBytes[messageBytes.Length + 4] = (byte)'\r';
            packetBytes[messageBytes.Length + 5] = (byte)'\n';

            return(packetBytes);
        }
Ejemplo n.º 15
0
        public void StartGpsSimulation(GpsSimulationInfo info)
        {
            if (info == null)
            {
                return;
            }

            GpsInfo         = info;
            GpsInfo.Running = true;

            Task.Run(async() =>
            {
                int counter = 0;
                while (GpsInfo.Running)
                {
                    GpsMessage msg = new GpsMessage();
                    msg.Id         = msgcounter.ToString();
                    msg.DeviceId   = deviceId;
                    if (counter < GpsInfo.Country.Count)
                    {
                        msg.Latitude  = GpsInfo.Country[counter].Latitude;
                        msg.Longitude = GpsInfo.Country[counter].Longitude;
                        msgSendQueue.Enqueue(msg);
                        counter++;
                    }
                    else
                    {
                        counter = 0;
                    }

                    await Task.Delay(GpsInfo.Interval);

                    msgcounter++;
                }
            });
        }
        public static bool TryConvertToStandardGpsMessage(GpsMessage message, out StandardGpsMessage standardGpsMessage)
        {
            switch (message.MessageId)
            {
            case "GPRMC":
                standardGpsMessage = new RmcStandardGpsMessage(message);
                return(true);

            case "GPVTG":
                standardGpsMessage = new VtgStandardGpsMessage(message);
                return(true);

            case "GPGGA":
                standardGpsMessage = new GgaStandardGpsMessage(message);
                return(true);

            case "GPGSA":
                standardGpsMessage = new GsaStandardGpsMessage(message);
                return(true);

            case "GPGSV":
                standardGpsMessage = new GsvStandardGpsMessage(message);
                return(true);

            case "GPGLL":
                standardGpsMessage = new GllStandardGpsMessage(message);
                return(true);

            case "GPTXT":
                standardGpsMessage = new TxtStandardGpsMessage(message);
                return(true);
            }

            standardGpsMessage = null;
            return(false);
        }
Ejemplo n.º 17
0
 public async Task SendMessage(GpsMessage message)
 {
     IBuffer txBuffer = GpsMessageSerializer.Serialize(message).AsBuffer();
     await _serialDevice.OutputStream.WriteAsync(txBuffer);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Send a message to the GPS chip.
 /// </summary>
 /// <param name="message">The message to be sent.</param>
 /// <returns></returns>
 public Task SendMessage(GpsMessage message)
 {
     return(_gpsMessageHandler.SendMessage(message));
 }
 internal GpsMessageEventArgs(GpsMessage message, DateTime systemReceivedUtcDateTime)
 {
     Message = message;
     SystemReceivedUtcDateTime = systemReceivedUtcDateTime;
 }