public override void PutWaypoints(ArrayList waypoints, GpsProgressHandler progressCallback) { m_appLayer.PutWaypoints(waypoints, progressCallback); }
public void PutWaypoints(ArrayList waypoints, GpsProgressHandler progressCallback) { m_linkLayer.getWaypointTransferProtocol().PutWaypoints(waypoints, progressCallback); }
public override void PutRoutes(ArrayList routes, GpsProgressHandler progressCallback, int startRouteNumber) { progressCallback("Upload Routes operation not supported", -1, -1); }
public override void PutWaypoints(ArrayList waypoints, GpsProgressHandler progressCallback) { progressCallback("Download Waypoints operation not supported", -1, -1); }
public abstract void PutWaypoints(ArrayList waypoints, GpsProgressHandler progressCallback);
public override void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback) { m_appLayer.GetWaypoints(insertWaypoint, progressCallback); }
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 abstract void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback);
public abstract void PutRoutes(ArrayList routes, GpsProgressHandler progressCallback, int startRouteNumber);
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"); }
public abstract void GetRoutes(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback);
public void PutRoutes(ArrayList routes, GpsProgressHandler progressCallback, int startRouteNumber) { m_linkLayer.getRouteTransferProtocol().PutRoutes(routes, progressCallback, startRouteNumber); }
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 PutRoutes(ArrayList routes, GpsProgressHandler progressCallback, int startRouteNumber) { // here is a problem: the SporTrack will reject routes which have same waypoint repeating twice on one leg. // the waypoint can repeat in the route many times, if separated by other waypoints. // rejection happens in the form of "UNABLE" response on the physical layer, m_linkLayer.ErrorCount() shows that. // the condition should not happen, as it is cleared during creation of the routes in LayerWaypoints.cs // we need to send all waypoints for all routes first, and then send linking info. m_linkLayer.resetErrorCount(); // make list of relevant waypoints and count them ArrayList trkptsToSend = new ArrayList(); int toSendWpt = 0; // for ProgressCallback int toSendPkt = 0; int routeNumber = startRouteNumber; // 1 to 20 foreach(Track route in routes) { if(route.isRoute) { int cnt = 0; Waypoint prevWpt = null; for(int i=0; i < route.Trackpoints.Count ;i++) { Waypoint trkpt = (Waypoint)route.Trackpoints.GetByIndex(i); if(prevWpt == null || !prevWpt.Location.almostAs(trkpt.Location, 0.0002)) // 0.0001 degree = 10 meters { Waypoint cloneTrkpt = new Waypoint(trkpt); string trkptName = toTptName(routeNumber, trkpt.Name); // use .Name here, as WptName is empty for rtept's cloneTrkpt.WptName = truncateName(trkptName); cloneTrkpt.Desc = trkptName; trkptsToSend.Add(cloneTrkpt); prevWpt = trkpt; cnt++; } } toSendPkt += (cnt + 1) / 2; toSendWpt += cnt; routeNumber++; } } if(toSendWpt == 0) { progressCallback("Error: no routes to upload ", 0, 0); return; } puttingRoute = true; PutWaypoints(trkptsToSend, progressCallback); // will leave TransferMode puttingRoute = false; int count = 0; int maxErrors = 5; int errors = maxErrors; int maxRoutepointCount = 0; string maxRoutepointName = ""; routeNumber = startRouteNumber; foreach(Track route in routes) { if(route.isRoute) { // make a temp list of trackpoints - specifically for this route, and count them: ArrayList trackpoints = new ArrayList(); foreach(Waypoint wpt in trkptsToSend) { if(wpt.TrackId == route.Id) { trackpoints.Add(wpt); } } int toSendThisRoute = (trackpoints.Count + 1) / 2; if(trackpoints.Count > maxRoutepointCount) { maxRoutepointCount = trackpoints.Count; maxRoutepointName = route.Name; } int countThisRoute = 1; for(int i=0; i < trackpoints.Count ;i+=2) { int numPoints = (trackpoints.Count - i > 1) ? 2 : 1; Waypoint trkpt1 = (Waypoint)trackpoints[i]; string trkptName1 = trkpt1.WptName.Trim(); Waypoint trkpt2 = numPoints > 1 ? (Waypoint)trackpoints[i + 1] : null; string trkptName2 = numPoints > 1 ? trkpt2.WptName.Trim() : ""; // send MPackets, followed by PMGNCMD try { MPacket packetToSend = new MPacket("PMGNRTE"); // $PMGNRTE,15,5,c,2,T02P09,a,T02P10,a*3F packetToSend.fields.Add("" + toSendThisRoute); packetToSend.fields.Add("" + countThisRoute); packetToSend.fields.Add("c"); packetToSend.fields.Add("" + routeNumber); packetToSend.fields.Add(trkptName1); packetToSend.fields.Add("a"); if(numPoints > 1) { packetToSend.fields.Add(trkptName2); packetToSend.fields.Add("a"); } m_linkLayer.SendPacket(packetToSend); countThisRoute++; count++; if(count % 10 == 0) { progressCallback("IP: downloading to GPS - route packet ", count, toSendPkt); } } catch (Exception e) { m_linkLayer.logError("PutRoutes: " + e.Message + " count=" + count); if(errors-- > 0) { // on timeout, try continue sending and bail out after too many failures continue; } else { m_linkLayer.logError("PutRoutes: too many errors, stopping transfer"); throw(e); } } } routeNumber++; } } m_linkLayer.SendPacket(new MPacketCmd("END")); m_linkLayer.SetTransferMode(false); if(m_linkLayer.ErrorCount() > 0) { // caught some packets with "UNABLE" response. progressCallback("Errors: " + m_linkLayer.ErrorCount() + " out of route packets: ", count, toSendPkt); Project.ErrorBox(Project.mainCommand.gpsManagerForm(), "Route '" + maxRoutepointName + "' (" + maxRoutepointCount + " route points after combing) failed to load, possibly due to 30 legs-per-route limitation of the Magellan devices." + "\n\nYou can break the route into smaller ones, or remove some mid-route points." + "\nAlternatively you can try clearing waypoints/routes memory in the device."); } else { progressCallback("OK: downloaded to GPS - route packets", count, toSendPkt); } m_linkLayer.log("OK: downloaded to GPS - route packets: " + count + " errors: " + m_linkLayer.ErrorCount()); }
public void PutWaypoints(ArrayList waypoints, GpsProgressHandler progressCallback) { int count = 0; int toSend = waypoints.Count; int maxErrors = 5; int errors = maxErrors; int toTrim = 40; //m_linkLayer.SetHandshake(Project.gpsMagellanHandshake); m_linkLayer.SetHandshake(true); // safer with handshake on m_linkLayer.SetTransferMode(true); foreach(Waypoint wpt in waypoints) { // send toSend MPacket's, followed by PMGNCMD try { MPacket packetToSend = new MPacket("PMGNWPL"); // $PMGNWPL,3339.889,N,11736.283,W,0000155,M,WPT001,this is comment,a*7E packetToSend.packCoord(wpt.Location); // adds 6 fields to array //string name = wpt.WptName; string name = puttingRoute ? (wpt.WptName.Length > 0 ? wpt.WptName : wpt.Name) : wpt.WptName; string desc = wpt.Desc.Length > 0 ? wpt.Desc : wpt.UrlName; if(!puttingRoute) { // keep it in sync with GarminProtoLinkProtocols:sendWaypoint() if(Project.gpsWptDescrAsName) { string _desc = desc; if(wpt.LiveObjectType == LiveObjectTypes.LiveObjectTypeGeocache && name.StartsWith("GC")) { desc = name + " = " + desc; } if(_desc.Length > 0) { name = _desc; } } // end sync name = name.Length > 12 ? name.Substring(0, 12) : name; } desc = desc.Length > toTrim ? desc.Substring(0, toTrim) : desc; packetToSend.fields.Add(name); // name - truncated in GPS packetToSend.fields.Add(desc); // comment has more characters in GPS string icon = wpt.Found ? "b" : "a"; packetToSend.fields.Add(icon); // icon - "crossed box"=a or "box in the box"=b // link layer will make sure all fields are clean of wrong symbols like "," m_linkLayer.SendPacket(packetToSend); count++; if(count % 10 == 0) { progressCallback("IP: downloading to GPS - waypoint ", count, toSend); } } catch (Exception e) { m_linkLayer.logError("PutWaypoints: " + e.Message + " count=" + count); if(errors-- > 0) { // on timeout, try continue sending and bail out after too many failures continue; } else { m_linkLayer.logError("PutWaypoints: too many errors, stopping transfer"); throw(e); } } } m_linkLayer.SendPacket(new MPacketCmd("END")); if(!puttingRoute) { m_linkLayer.SetTransferMode(false); } progressCallback("OK: downloaded to GPS - waypoints", count, toSend); m_linkLayer.log("OK: downloaded to GPS - waypoints: " + count); }
public override void PutRoutes(ArrayList routes, GpsProgressHandler progressCallback, int startRouteNumber) { m_appLayer.PutRoutes(routes, progressCallback, startRouteNumber); }
public override void GetWaypoints(GpsInsertWaypoint insertWaypoint, GpsProgressHandler progressCallback) { progressCallback("Upload Waypoints operation not supported", -1, -1); }