Exemple #1
0
 public ThreadGpsControl(GpsBase gps, GpsInsertWaypoint insertWaypoint, ArrayList waypoints, ArrayList routes)
 {
     m_gps            = gps;
     m_insertWaypoint = insertWaypoint;
     m_waypoints      = waypoints;               // may be empty, but never null
     m_routes         = routes;                  // may be empty, but never null
 }
Exemple #2
0
 public override void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback)
 {
     m_appLayer.GetWaypoints(insertWaypoint, progressCallback);
 }
Exemple #3
0
 public override void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback)
 {
     progressCallback("Upload Waypoints operation not supported", -1, -1);
 }
        public DlgGpsManager(GpsInsertWaypoint insertWaypoint, CameraManager cameraManager,
			PictureManager pictureManager, ArrayList waypoints, ArrayList routes, string command)
        {
            //LibSys.StatusBar.Trace("DlgGpsManager()");
            if(isUp)
            {
                // duplicate for this instance stays true, so that all functions are disabled
                // and the form will be closed on load.
                this.duplicate = true;
                this.Load += new System.EventHandler(this.DlgGpsManager_Load);	// we will close this instance on load
            }
            else
            {
                This = this;
                duplicate = false;

                m_insertWaypoint = insertWaypoint;
                m_cameraManager = cameraManager;
                m_pictureManager = pictureManager;
                m_waypoints = waypoints == null ? WaypointsCache.WaypointsAll : waypoints;
                m_routes = routes == null ? WaypointsCache.RoutesAll : routes;
                m_command = command;

                //
                // Required for Windows Form Designer support
                //
                InitializeComponent();

                this.SuspendLayout();
                populateGpsPanel();

                //#if DEBUG
                //			Project.gpsLogProtocol = true;
                //			Project.gpsLogPackets = true;
                //			Project.gpsLogErrors = true;
                //#else
                Project.gpsLogProtocol = false;
                Project.gpsLogPackets = false;
                Project.gpsLogErrors = false;
                //#endif

                Project.setDlgIcon(this);
                //LibSys.StatusBar.Trace("DlgGpsManager() done");

                m_initialColor = gpsBasicsGroupBox.BackColor;
                gpsBasicsGroupBox.BackColor = Color.Yellow;
                gpsBasicsGroupBox.Text = "stopped";

                progressDetailDelta = progressGroupBox.Height;
                maxShrinkDelta = progressDetailDelta + Math.Abs(this.PointToScreen(progressDetailButton.Bounds.Location).Y - this.PointToScreen(shrinkMaxButton.Bounds.Location).Y) - slopeLabel.Height;
                this.ResumeLayout(true);
            }
        }
Exemple #5
0
 public abstract void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback);
Exemple #6
0
 public override void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback)
 {
     m_appLayer.GetWaypoints(insertWaypoint, progressCallback);
 }
Exemple #7
0
 public override void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback)
 {
     progressCallback("Upload Waypoints operation not supported", -1, -1);
 }
 public void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback)
 {
     m_linkLayer.getWaypointTransferProtocol().GetWaypoints(insertWaypoint, progressCallback);
 }
        public void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback)
        {
            string source = "MGN-GPS-" + DateTime.Now;

            int total = 0;
            int toReceive = -1;		// we don't know how many waypoints are there in GPS
            int maxErrors = 5;
            int errors = maxErrors;
            bool finished = false;

            if(!gettingRoute)
            {
                m_linkLayer.SetHandshake(Project.gpsMagellanHandshake);
                if(Project.gpsMagellanHandshake)
                {
                    m_linkLayer.SetTransferMode(true);
                }
            }
            m_linkLayer.SendPacket(new MPacketCmd("WAYPOINT"));
            while(!finished)
            {
                MPacketReceived received;
                try
                {
                    received = m_linkLayer.ReceivePacket();
                }
                catch(CommPortException e)
                {
                    m_linkLayer.logError("exception waiting for GPS response: " + e.Message);
                    break;
                }
                //m_linkLayer.log("" + total + " ===  " + received);
                if(!received.isGood)
                {
                    m_linkLayer.logError("GetWaypoints: bad packet received, count=" + total + " content=" + received.m_string);
                    continue;
                }
                //m_linkLayer.log("GetWaypoints: good packet received, count=" + total + "   " + received);
                if(received.header.Equals("PMGNWPL") || received.header.Equals("WPL"))	// NMEA WPL may come from some devices
                {
                    try
                    {
                        MPacket wpt  = received.fromString();
                        string type = gettingRoute ? "rtept" : "wpt";

                        // $PMGNWPL,3328.069,N,11738.812,W,0000000,M,Road to,GCF320 = Road to Wat,a*68
                        double Lat = wpt.parseLat(0);
                        double Lng = wpt.parseLng(0);
                        double Elev = wpt.parseElev(4);
                        string sym = null;
                        string name = (string)wpt.fields[6];		// short name
                        if(name != null && name.StartsWith("GC"))
                        {
                            type = "geocache";
                            sym = "Geocache";
                        }

                        string descr = null;						// description
                        if(wpt.fields.Count > 7)
                        {
                            descr = (string)wpt.fields[7];
                            if(descr != null && descr.StartsWith("GC"))
                            {
                                type = "geocache";
                                sym = "Geocache";
                                string _name;
                                string _descr;
                                if(Project.splitGcDescr(descr, out _name, out _descr))
                                {
                                    name = _name;
                                    descr = _descr;
                                }
                            }
                        }
                        if(wpt.fields.Count > 8)
                        {
                            string icon = "" + (string)wpt.fields[8];	// icon - a (not found), b (found)
                            if(icon.Equals("b") && "geocache".Equals(type))
                            {
                                type += " found";
                                sym = "Geocache Found";
                            }
                        }
                        // we need to allocate every createInfo here, as they will be buffered in the reader thread:
                        CreateInfo createInfo = new CreateInfo();

                        createInfo.init("wpt");
                        createInfo.lat = Lat;
                        createInfo.lng = Lng;
                        createInfo.elev = Elev;
                        createInfo.typeExtra = type;
                        createInfo.source = source;
                        createInfo.name = name.Trim();
                        if(!createInfo.name.Equals(descr))
                        {
                            createInfo.desc = descr;		// can be null
                            createInfo.urlName = descr;		// can be null
                        }
                        //if(!"a".Equals(icon) && !"b".Equals(icon))
                        {
                            createInfo.sym = sym;
                        }

                        insertWaypoint(createInfo);

                        total++;
                        if((total % 3) == 0)
                        {
                            progressCallback("IP: uploading waypoints to PC:", total, toReceive);
                        }
                        errors = maxErrors;
                    }
                    catch(Exception ee)
                    {
                        m_linkLayer.logError("GetWaypoints: " + ee.Message);
                    }
                }
                else if(received.header.Equals("PMGNCMD"))
                {
                    m_linkLayer.log("GetWaypoints: end of waypoints received, count=" + total + "   " + received);
                    finished = true;
                    break;
                }
                else
                {
                    m_linkLayer.log("GetWaypoints: good other packet received, count=" + total + "   content=" + received);
                }
            } // end while()

            if(Project.gpsMagellanHandshake)
            {
                m_linkLayer.SetTransferMode(false);
            }
            progressCallback("loaded OK", total, total);
            m_linkLayer.log("GetWaypoints: loaded OK count=" + total + "  waypoints");
        }
        public void GetTracks(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback)
        {
            string source = "MGN-GPS-" + DateTime.Now;

            string trackName = "";
            bool trackCreated = false;
            int total = 0;
            int toReceive = -1;		// we don't know how many trackpoints are there in GPS
            int maxErrors = 5;
            int errors = maxErrors;
            bool finished = false;
            DateTime dtPrev = DateTime.MinValue;

            m_linkLayer.SetHandshake(Project.gpsMagellanHandshake);
            if(Project.gpsMagellanHandshake)
            {
                m_linkLayer.SetTransferMode(true);
            }
            MPacketCmd trackCmd = new MPacketCmd("TRACK");
            trackCmd.fields.Add("2");			// undocumented, causes date to be included in PMGNTRK responses
            m_linkLayer.SendPacket(trackCmd);
            while(!finished)
            {
                MPacketReceived received;
                try
                {
                    received = m_linkLayer.ReceivePacket();
                }
                catch(CommPortException e)
                {
                    m_linkLayer.logError("exception waiting for GPS response: " + e.Message);
                    break;
                }
                //m_linkLayer.log("" + total + " ===  " + received);
                if(!received.isGood)
                {
                    m_linkLayer.logError("GetTracks: bad packet received, count=" + total + " content=" + received.m_string);
                    continue;
                }
                //m_linkLayer.log("GetTracks: good packet received, count=" + total + "   " + received);
                if(received.header.Equals("PMGNTRK"))
                {
                    // $PMGNTRK,3334.100,N,11742.518,W,00147,M,033531.02,A,,280403*63	// 03:35:31.02 28 Apr 2003  UTM
                    try
                    {
                        MPacket trkpt  = received.fromString();

                        if(!trackCreated)
                        {
                            Project.trackId++;

                            trackName = "MGN-TRACK-LOG" + Project.trackId;

                            // we need to allocate every infos here, as they will be buffered in the reader thread:
                            CreateInfo createInfo = new CreateInfo();

                            createInfo.init("trk");
                            createInfo.id = Project.trackId;	// track id
                            createInfo.source = source;
                            createInfo.name = trackName;

                            insertWaypoint(createInfo);			// actually inserts a track

                            trackCreated = true;
                        }

                        // $PMGNTRK,3334.100,N,11742.518,W,00147,M,033531.02,A,,280403*63	// 03:35:31.02 28 Apr 2003  UTM
                        double Lat = trkpt.parseLat(0);
                        double Lng = trkpt.parseLng(0);
                        double Elev = trkpt.parseElev(4);

                        int h, m, s, ms;
                        trkpt.parseTime(6, out h, out m, out s, out ms);
                        int y, mm, d;
                        trkpt.parseDate(9, out y, out mm, out d);

                        DateTime dt = new DateTime(y, mm, d, h, m, s, ms);		// UTM

                        /*  this is from the days when I didn't know how to get date from Magellan:
                        // make sure that as points come, DateTime only grows:
                        DateTime dt = new DateTime(m_year, m_month, m_day, h, m, s, ms);
                        while(dt.CompareTo(dtPrev) < 0)
                        {
                            m_day++;
                            if(m_day > 28) { m_month++; m_day = 1; }
                            dt = new DateTime(m_year, m_month, m_day, h, m, s, ms);
                        }
                        dtPrev = dt;
                        */

                        //m_linkLayer.log("time=" + dt);

                    {
                        // we need to allocate every createInfo here, as they will be buffered in the reader thread:
                        CreateInfo createInfo = new CreateInfo();

                        createInfo.init("trkpt");
                        createInfo.id = Project.trackId;			// relate waypoint to track
                        createInfo.dateTime = dt;
                        createInfo.lat = Lat;
                        createInfo.lng = Lng;
                        createInfo.elev = Elev;
                        createInfo.source = source;

                        insertWaypoint(createInfo);
                    }
                        total++;
                        if((total % 3) == 0)
                        {
                            progressCallback("IP: uploading track: " + trackName + " to PC\n\nleg ", total, toReceive);
                        }
                        errors = maxErrors;
                    }
                    catch(Exception ee)
                    {
                        m_linkLayer.logError("GetTracks: " + ee.Message);
                    }
                }
                else if(received.header.Equals("PMGNCMD"))
                {
                    m_linkLayer.log("GetTracks: end of tracks received, count=" + total + "   " + received);
                    finished = true;
                    break;
                }
                else
                {
                    m_linkLayer.log("GetTracks: good other packet received, count=" + total + "   content=" + received);
                }
            } // end while()

            if(Project.gpsMagellanHandshake)
            {
                m_linkLayer.SetTransferMode(false);
            }
            progressCallback("loaded OK", total, total);
            m_linkLayer.log("GetTracks: loaded OK count=" + total + "  trackpoints");
        }
        public void GetRoutes(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback)
        {
            ArrayList namesBuffer = new ArrayList();
            ArrayList nameRoutesBuffer = new ArrayList();

            // now get the route information, which is actually list of names:
            string source = "MGN-GPS-" + DateTime.Now;

            int total = 0;
            int toReceive = -1;		// we don't know how many routepoints are there in GPS
            int maxErrors = 5;
            int errors = maxErrors;
            bool finished = false;
            DateTime dtPrev = DateTime.MinValue;
            char[] digits = "0123456789".ToCharArray();

            m_linkLayer.SetHandshake(Project.gpsMagellanHandshake);
            if(Project.gpsMagellanHandshake)
            {
                m_linkLayer.SetTransferMode(true);
            }
            MPacketCmd trackCmd = new MPacketCmd("ROUTE");
            m_linkLayer.SendPacket(trackCmd);
            while(!finished)
            {
                MPacketReceived received;
                try
                {
                    received = m_linkLayer.ReceivePacket();
                }
                catch(CommPortException e)
                {
                    m_linkLayer.logError("exception waiting for GPS response: " + e.Message);
                    break;
                }
                //m_linkLayer.log("" + total + " ===  " + received);
                if(!received.isGood)
                {
                    m_linkLayer.logError("GetRoutes: bad packet received, count=" + total + " content=" + received.m_string);
                    continue;
                }
                m_linkLayer.log("GetRoutes: good packet received, count=" + total + "   " + received);
                if(received.header.Equals("PMGNRTE"))
                {
                    try
                    {
                        MPacket trkpt  = received.fromString();

                        // $PMGNRTE,14,2,c,1,T01P03,a,T01P04,a*35   - message 2 of 14, "c" means this is route, route name "1", "m" means it is route message
                        //                          a        a   - means default icon

                        string routeName = "";
                        try
                        {
                            string sCount	= (string)trkpt.fields[0];
                            string sPtr		= (string)trkpt.fields[1];
                            string type		= (string)trkpt.fields[2];
                            routeName		= (string)trkpt.fields[3];

                            if("c".Equals(type))
                            {
                                for(int j=4; j < trkpt.fields.Count ;j++)
                                {
                                    string name	 = (string)trkpt.fields[j];
                                    if(name != null && name.Length > 0)
                                    {
                                        //m_linkLayer.log("GetRoutes: name=" + name);
                                        namesBuffer.Add(name);
                                        nameRoutesBuffer.Add(routeName);
                                        total++;
                                    }
                                }
                            }
                        }
                        catch(Exception e)
                        {
                            m_linkLayer.logError("exception parsing PMGNRTE: " + e.Message);
                        }

                        if((total % 3) == 0)
                        {
                            progressCallback("IP: uploading route: " + routeName + " to PC\n\nleg ", total, toReceive);
                        }
                        errors = maxErrors;
                    }
                    catch(Exception ee)
                    {
                        m_linkLayer.logError("GetRoutes: " + ee.Message);
                    }
                }
                else if(received.header.Equals("PMGNCMD"))
                {
                    m_linkLayer.log("GetRoutes: end of routes received, count=" + total + "   " + received + "  names: " + namesBuffer.Count);
                    finished = true;
                    break;
                }
                else
                {
                    m_linkLayer.log("GetRoutes: good other packet received, count=" + total + "   content=" + received);
                }
            } // end while()

            if(namesBuffer.Count == 0)
            {
                if(Project.gpsMagellanHandshake)
                {
                    m_linkLayer.SetTransferMode(false);
                }
                progressCallback("Error: no routes in GPS", -1, -1);
                return;
            }

            //Thread.Sleep(3000);	// let magellan messages die down

            // now get all waypoints into a separate array, so that we can relate incoming route points to waypoints:
            wptBuffer.Clear();
            gettingRoute = true;
            GetWaypoints(new GpsInsertWaypoint(bufferWaypoint), progressCallback);
            gettingRoute = false;

            m_linkLayer.log("GetRoutes: waypoints received, count=" + wptBuffer.Count);

            if(wptBuffer.Count == 0)
            {
                progressCallback("Error: no waypoints in GPS to define a valid route", -1, -1);
                return;
            }

            // now relate list of names that came with routes to list of waypoints.
            // we need to insert waypoints within the route in the same order as the names came from GPS, with time growing:
            string nameRoutePrev = "";
            for(int i=0; i < namesBuffer.Count; i++)
            {
                string name = (string)namesBuffer[i];
                string nameRoute = (string)nameRoutesBuffer[i];
                if(!nameRoute.Equals(nameRoutePrev))
                {
                    Project.trackId++;

                    string routeName = "MGN-ROUTE-" + nameRoute; // + "-" + Project.trackId;

                    CreateInfo createInfo = new CreateInfo();

                    createInfo.init("rte");
                    createInfo.id = Project.trackId;	// track id
                    createInfo.source = source;
                    createInfo.name = routeName;

                    insertWaypoint(createInfo);			// actually inserts a Track (route)

                    nameRoutePrev = nameRoute;
                }
                // find corresponding waypoint in the big buffer:
                bool wptFound = false;
                string nameL = name.ToLower();

                for(int j=0; j < wptBuffer.Count; j++)
                {
                    CreateInfo createInfo = (CreateInfo)wptBuffer[j];
                    string infosName = ("" + createInfo.name).Trim();
                    string infosDetail = createInfo.desc;
                    string infosNameL = infosName.ToLower();
                    if(infosNameL.Equals(nameL) || infosNameL.StartsWith(nameL + " "))
                    {
                        wptFound = true;
                        m_dt = m_dt.AddSeconds(1);		// grow time
                        createInfo.dateTime = m_dt;
                        if(infosDetail != null && infosDetail.Length > 0 && infosDetail.Equals(infosName))
                        {
                            createInfo.name = infosName;
                        }
                        if(createInfo.name.StartsWith("T") && createInfo.name.Substring(1,1).IndexOfAny(digits) == 0)
                        {
                            int ppos = createInfo.name.IndexOf("P");
                            if(ppos == 2 || ppos == 3 && createInfo.name.Substring(2,1).IndexOfAny(digits) == 0)
                            {
                                string toReplace = createInfo.name.Substring(0, ppos + 1);
                                createInfo.name = createInfo.name.Replace(toReplace,"");
                            }
                        }
                        createInfo.id = Project.trackId;
                        insertWaypoint(new CreateInfo(createInfo));
                        //wptBuffer.RemoveAt(j);
                        break;
                    }
                }
                if(!wptFound)
                {
                    m_linkLayer.logError("name='" + name + "' route='" + nameRoute + "' could not be related");
                }
            #if DEBUG
                else
                {
                    m_linkLayer.log("name='" + name + "' route='" + nameRoute + "' related ok");
                }
            #endif
            }
            wptBuffer.Clear();
            namesBuffer.Clear();
            nameRoutesBuffer.Clear();

            progressCallback("loaded OK", total, total);
            m_linkLayer.log("GetRoutes: loaded OK count=" + total + "  trackpoints");
        }
Exemple #12
0
 public abstract void GetRoutes(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback);
 public void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback)
 {
     m_linkLayer.getWaypointTransferProtocol().GetWaypoints(insertWaypoint, progressCallback);
 }