public GpsWorkerArguemnts(GpsLog log, DateTime firstPicture, DateTime lastPicture, List <PictureMetaData> pictures)
 {
     this.log          = log;
     this.firstPicture = firstPicture;
     this.lastPicture  = lastPicture;
     this.pictures     = pictures;
 }
 public GpsWorkerArguemnts(GpsLog log)
 {
     this.log          = log;
     this.pictures     = null;
     this.firstPicture = DateTime.Now;
     this.lastPicture  = DateTime.Now;
 }
        public async Task Post(GpsLog data)
        {
            // save to database
            data.SubmitDate = DateTime.Now;
            await repo.SaveGpsLog(data);

            var groupId = data.DeviceId.ToString();
            await hub.Clients.Group(groupId).NewPosition(data.DeviceId, data.Latitude, data.Longitude);
        }
        private void UpdateGpsData(PictureMetaData picture, GpsLog log)
        {
            if (picture.ExifOriginalDateTime.HasValue)
            {
                GpsLogEntry entry = log.GetNearestEntry(picture.ExifOriginalDateTime.Value);
                if (entry != null)
                {
                    picture.GpsLatitude      = new GpsCoordinate(entry.Latitude);
                    picture.GpsLongitude     = new GpsCoordinate(entry.Longitude);
                    picture.GpsLatitudeRef   = entry.Latitude >= 0 ? "N" : "S";
                    picture.GpsLongitudeRef  = entry.Longitude >= 0 ? "E" : "W";
                    picture.GpsDateTimeStamp = entry.Time;

                    picture.SaveChanges();
                }
            }
        }
        void exifGpsView_TagFromGpsLogClick(object sender, EventArgs e)
        {
            // the filename of the gps log
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "Open gps nmea file";
            ofd.Filter = "*.txt|*.txt";
            if (ofd.ShowDialog(mainForm) != DialogResult.OK)
            {
                return;
            }

            this.lastGpsFile = ofd.FileName;

            // read the gps log
            mainForm.WaitCursor(true);
            GpsLog log = GpsLogFactory.FromFile(ofd.FileName);

            mainForm.WaitCursor(false);

            // empty log -> exit
            if (log.Count == 0)
            {
                MessageBox.Show("The gps log file is empty or PhotoTagStudio cannot read it.", mainForm.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // ask for gps time offset
            PictureGpsOffsetDialog d = new PictureGpsOffsetDialog(currentPicture, log.FirstTime.Value, log.LastTime.Value);

            d.Offset = Settings.Default.GPSTimeOffset;
            if (d.ShowDialog(mainForm) != DialogResult.OK)
            {
                return;
            }

            // set offset to gps log
            Settings.Default.GPSTimeOffset = d.Offset;
            log.Offset = d.Offset;

            PauseOtherWorker();
            gpsBackgroundWorker.RunWorkerAsync(new GpsWorkerArguemnts(log));
        }
示例#6
0
        private void WriteCommand(string str)
        {
            if (str == string.Empty)
            {
                return;
            }
            if (SyncSerialPort.IsOpen)
            {
                byte[] c = new byte[str.Length / 2];
                for (int i = 0; i < str.Length / 2; i++)
                {
                    string s = str.Substring(i * 2, 2);

                    int d = Convert.ToByte(s, 16);
                    c[i] = (byte)d;
                    SyncSerialPort.Write(c, i, 1);
                }

                //SyncSerialPort.Write(str.ToCharArray(),0,str.Length);
                GpsLog.AppendText("<<--上位机" + str);
                GpsLog.AppendText("\r\n");
                GpsLog.ScrollToCaret();
            }
        }
示例#7
0
        /// <summary>
        /// gets routes from gpsd log file
        /// </summary>
        /// <param name="gpsdLogFile"></param>
        /// <param name="start">start time(UTC) of route, null to read from very start</param>
        /// <param name="end">end time(UTC) of route, null to read to the very end</param>
        /// <param name="maxPositionDilutionOfPrecision">max value of PositionDilutionOfPrecision, null to get all</param>
        /// <returns></returns>
        public static IEnumerable <List <GpsLog> > GetRoutesFromMobileLog(string gpsdLogFile, DateTime?start, DateTime?end, double?maxPositionDilutionOfPrecision)
        {
#if SQLite
            using (SQLiteConnection cn = new SQLiteConnection())
            {
#if !MONO
                cn.ConnectionString = string.Format("Data Source=\"{0}\";FailIfMissing=True;", gpsdLogFile);
#else
                cn.ConnectionString = string.Format("Version=3,URI=file://{0},FailIfMissing=True", gpsdLogFile);
#endif

                cn.Open();
                {
                    using (DbCommand cmd = cn.CreateCommand())
                    {
                        cmd.CommandText = "SELECT * FROM GPS ";

                        if (start.HasValue)
                        {
                            cmd.CommandText += "WHERE TimeUTC >= @t1 ";
                            SQLiteParameter lookupValue = new SQLiteParameter("@t1", start);
                            cmd.Parameters.Add(lookupValue);
                        }

                        if (end.HasValue)
                        {
                            if (!start.HasValue)
                            {
                                cmd.CommandText += "WHERE ";
                            }
                            else
                            {
                                cmd.CommandText += "AND ";
                            }

                            cmd.CommandText += "TimeUTC <= @t2 ";
                            SQLiteParameter lookupValue = new SQLiteParameter("@t2", end);
                            cmd.Parameters.Add(lookupValue);
                        }

                        if (maxPositionDilutionOfPrecision.HasValue)
                        {
                            if (!start.HasValue && !end.HasValue)
                            {
                                cmd.CommandText += "WHERE ";
                            }
                            else
                            {
                                cmd.CommandText += "AND ";
                            }

                            cmd.CommandText += "(PositionDilutionOfPrecision <= @p3)";
                            SQLiteParameter lookupValue = new SQLiteParameter("@p3", maxPositionDilutionOfPrecision);
                            cmd.Parameters.Add(lookupValue);
                        }

                        using (DbDataReader rd = cmd.ExecuteReader())
                        {
                            List <GpsLog> points = new List <GpsLog>();

                            long lastSessionCounter = -1;

                            while (rd.Read())
                            {
                                GpsLog log = new GpsLog();
                                {
                                    log.TimeUTC                       = (DateTime)rd["TimeUTC"];
                                    log.SessionCounter                = (long)rd["SessionCounter"];
                                    log.Delta                         = rd["Delta"] as double?;
                                    log.Speed                         = rd["Speed"] as double?;
                                    log.SeaLevelAltitude              = rd["SeaLevelAltitude"] as double?;
                                    log.EllipsoidAltitude             = rd["EllipsoidAltitude"] as double?;
                                    log.SatellitesInView              = rd["SatellitesInView"] as System.Byte?;
                                    log.SatelliteCount                = rd["SatelliteCount"] as System.Byte?;
                                    log.Position                      = new PointLatLng((double)rd["Lat"], (double)rd["Lng"]);
                                    log.PositionDilutionOfPrecision   = rd["PositionDilutionOfPrecision"] as double?;
                                    log.HorizontalDilutionOfPrecision = rd["HorizontalDilutionOfPrecision"] as double?;
                                    log.VerticalDilutionOfPrecision   = rd["VerticalDilutionOfPrecision"] as double?;
                                    log.FixQuality                    = (FixQuality)((byte)rd["FixQuality"]);
                                    log.FixType                       = (FixType)((byte)rd["FixType"]);
                                    log.FixSelection                  = (FixSelection)((byte)rd["FixSelection"]);
                                }

                                if (log.SessionCounter - lastSessionCounter != 1 && points.Count > 0)
                                {
                                    List <GpsLog> ret = new List <GpsLog>(points);
                                    points.Clear();
                                    {
                                        yield return(ret);
                                    }
                                }

                                points.Add(log);
                                lastSessionCounter = log.SessionCounter;
                            }

                            if (points.Count > 0)
                            {
                                List <GpsLog> ret = new List <GpsLog>(points);
                                points.Clear();
                                {
                                    yield return(ret);
                                }
                            }

                            points.Clear();
                            points = null;

                            rd.Close();
                        }
                    }
                }
                cn.Close();
            }
#else
            return(null);
#endif
        }
示例#8
0
        /// <summary>
        ///  处理gps信息,刷新控件及发送信息给主窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">gps信息</param>
        void GPSForm_GpsLogEvent(object sender, EventsClass.GpsEventArgs e)
        {
            if (GpsLog.InvokeRequired)
            {
                LogBoxCallback d = new LogBoxCallback(GPSForm_GpsLogEvent);
                this.Invoke(d, new object[] { sender, e });
            }
            else
            {
                string comming = e.gpsdata;
                comming = comming.Substring(comming.LastIndexOf("EB90"));
                string[] str = comming.Split(',');
                if (str[1] == "03")
                {
                    GpsLog.AppendText("430-->>" + e.gpsdata + ",END" + "\r\n");
                    GpsLog.ScrollToCaret();
                    if (str[2] == "Y")
                    {
                        GpsLog.AppendText("430回复ACK正确" + "\r\n");
                        GpsLog.ScrollToCaret();
                    }
                    else
                    {
                        GpsLog.AppendText("430回复ACK错误" + "\r\n");
                        GpsLog.ScrollToCaret();
                    }
                }
                else
                {
                    string oldstr = comming;


                    oldstr = oldstr.Remove(oldstr.Length - 2);
                    try
                    {
                        string crcnew = CRCHelper.CRC16(oldstr);

                        string newstr = CRCHelper.ConvertCharToHex(comming) + CRCHelper.ConvertCharToHex(",END");
                        GpsLog.AppendText("430-->>" + newstr + "\r\n");
                        GpsLog.ScrollToCaret();
                        string crc = newstr.Substring(newstr.Length - 12, 4);

                        if (crc == crcnew)
                        {
                            string ack = "EB90,03,Y,";
                            ack += CRCHelper.CRC16(ack);
                            ack += ",END";
                            ack  = CRCHelper.ConvertCharToHex(ack);
                            WriteCommand(ack);
                            GpsLog.AppendText("上位机回复ACK正确" + "\r\n");
                            GpsLog.ScrollToCaret();
                        }
                        else
                        {
                            string ack = "EB90,03,N,";
                            ack += CRCHelper.CRC16(ack);
                            ack += ",END";
                            ack  = CRCHelper.ConvertCharToHex(ack);
                            WriteCommand(ack);
                            GpsLog.AppendText("上位机回复ACK错误" + "\r\n");
                            GpsLog.ScrollToCaret();
                            wrongnumber++;
                            numberlabel.Text = "上位机校验错误次数:" + wrongnumber.ToString() + " 双击清零";
                        }
                    }
                    catch (Exception MyEx)
                    {
                        MessageBox.Show(MyEx.Message + ":" + MyEx.StackTrace);
                    }
                }
            }
        }
示例#9
0
        public async Task SaveGpsLog(GpsLog data)
        {
            await context.GpsLogs.AddAsync(data);

            await context.SaveChangesAsync();
        }
示例#10
0
        private void buttonGetGpsData_Click(object sender, EventArgs e)
        {
            // a picture is need for the offset dialog
            if (this.currentPicture == null)
            {
                return;
            }

            // the filename of the gps log
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "Open gps nmea file";
            ofd.Filter = "*.txt|*.txt";
            if (ofd.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            this.lastGpsFile = ofd.FileName;

            // read the gps log
            GpsLog log = GpsLogFactory.FromFile(ofd.FileName);

            // empty log -> exit
            if (log.Count == 0)
            {
                return;
            }

            // ask for gps time offset
            PictureGpsOffsetDialog d = new PictureGpsOffsetDialog(currentPicture, log.FirstTime.Value, log.LastTime.Value);

            d.Offset = Settings.Default.GPSTimeOffset;
            if (d.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            // set offset to gps log
            Settings.Default.GPSTimeOffset = d.Offset;
            log.Offset = d.Offset;

            IStatusDisplay statusDisplay = (IStatusDisplay)this.FindForm();

            List <string> filenames = this.GetAllFileList(false);

            statusDisplay.WorkStart(filenames.Count);

            // compute the timespan of all pictures
            DateTime firstPicture           = new DateTime(4000, 1, 1);
            DateTime lastPicture            = new DateTime(1, 1, 1);
            List <PictureMetaData> pictures = new List <PictureMetaData>();

            foreach (string filename in filenames)
            {
                PictureMetaData pmd;
                if (this.currentPicture != null &&
                    this.currentPicture.Filename == filename)
                {
                    pmd = currentPicture;
                }
                else
                {
                    pmd = new PictureMetaData(filename);
                }

                if (pmd.ExifOriginalDateTime.HasValue)
                {
                    DateTime time = pmd.ExifOriginalDateTime.Value;

                    if (time > lastPicture)
                    {
                        lastPicture = time;
                    }
                    if (time < firstPicture)
                    {
                        firstPicture = time;
                    }

                    pictures.Add(pmd);
                }
                statusDisplay.WorkNextPart();
            }
            statusDisplay.WorkFinished();

            // ask the user: do it now?
            string text =
                String.Format(
                    "The GPS time is between {0} and {1}.\nThe picture time is between {2} and {3} ({4} and {5}).\n\nContinue?",
                    log.FirstTime,
                    log.LastTime,
                    firstPicture.Add(log.Offset),
                    lastPicture.Add(log.Offset),
                    firstPicture,
                    lastPicture);

            if (MessageBox.Show(text, "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                statusDisplay.WorkStart(pictures.Count);
                foreach (PictureMetaData pmd in pictures)
                {
                    UpdateGpsData(pmd, log);

                    if (pmd != currentPicture)
                    {
                        pmd.Close();
                    }
                    statusDisplay.WorkNextPart();
                }

                FireDataChanged();
                statusDisplay.WorkFinished();
            }
            else
            {
                foreach (PictureMetaData pmd in pictures)
                {
                    if (pmd != currentPicture)
                    {
                        pmd.Close();
                    }
                }
            }
        }