Exemplo n.º 1
0
        public VehicleGps(GpsRealTimeData rtData, string name, string sym, string source, string url, string desc, bool doTrackLog)
            : base(rtData.location.Clone(), name, sym, source, url, desc)                               // location must be not null
        {
            RealTimeData = rtData;
            m_doTrackLog = doTrackLog;

            if (m_doTrackLog)
            {
                logTrack(rtData);
            }

            if (m_image_nofix == null)
            {
                m_image_nofix = VehiclesCache.getVehicleImage("gps_nofix");
            }

            if (m_image_default == null)
            {
                m_image_default = VehiclesCache.getVehicleImage("gps_car_default");
            }

            setImage(sym);

            Image = m_imageSym;              //m_image_nofix;				// may be null

            imageBoundingRect();
        }
Exemplo n.º 2
0
        // real-time track logging:
        private bool logTrack(GpsRealTimeData rtData)
        {
            bool ret = false;

            // only good fixes with non-null location reach here
            string source = this.Label + " " + DateTime.Now;

            if (trackId == -1)
            {
                trackId = ++Project.trackId;

                string trackName = "VEHICLE-LOG-" + trackId + " " + this.Label;

                CreateInfo createInfo = new CreateInfo();

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

                totalTrkpt = 0;

                WaypointsCache.insertWaypoint(createInfo);                      // actually inserts a track
                WaypointsCache.isDirty = true;
            }

            // garmin sends data every second, even if it is same point. Ignore repetetions to save memory.

            double[] howfars = new Double[] { 0.0d, 1.0d, 10.0d, 20.0d, 50.0d, 100.0d };

            double   howFarMeters = howfars[howfarIndex];
            GeoCoord loc          = new GeoCoord(rtData.location.Lng, rtData.location.Lat, rtData.location.Elev);

            // tolerance 0.0001 degree = 10 meters
            if (howfarIndex == 0 || !loc.almostAs(lastLoc, howFarMeters * 0.00001d))                    // 0 means every incoming reading
            {
                CreateInfo createInfo = new CreateInfo();

                createInfo.init("trkpt");
                createInfo.id       = trackId;                                  // relate waypoint to track
                createInfo.dateTime = rtData.time;
                createInfo.lat      = rtData.location.Lat;
                createInfo.lng      = rtData.location.Lng;
                createInfo.elev     = rtData.location.Elev;
                createInfo.source   = source;
                //createInfo.name = "" + totalTrkpt;		// track point name

                lastLat  = rtData.location.Lat;
                lastLng  = rtData.location.Lng;
                lastElev = rtData.location.Elev;

                totalTrkpt++;
                ret = true;

                WaypointsCache.insertWaypoint(createInfo);
                lastLoc = loc;
            }
            return(ret);
        }
Exemplo n.º 3
0
        public void StartRealTime(GpsRealTimeHandler realtimeCallback)
        {
            int  total     = 0;
            int  maxErrors = 5;
            int  errors    = maxErrors;
            bool finished  = false;

            m_stopRealTime = false;

            while (!finished && !m_stopRealTime)
            {
                GpsRealTimeData pvtData = new GpsRealTimeData();                                // will be returned empty if no data

                MPacketReceived received = null;
                try
                {
                    received = m_linkLayer.ReceivePacket();
                    if (!received.isGood)
                    {
                        m_linkLayer.logError("StartRealTime: bad packet received, count=" + total);
                        pvtData.comment = "bad data packet from GPS";
                        realtimeCallback(pvtData);
                        continue;
                    }
                }
                catch (Exception e)
                {
                    m_linkLayer.logError("StartRealTime: " + e.Message + "  count=" + total);
                    //if(received != null)
                    {
                        try
                        {
                            m_linkLayer.ReOpen();
                        }
                        catch (Exception ee)
                        {
                            m_linkLayer.logError("while ReOpen(): " + ee.Message);
                        }
                    }
                    pvtData.comment = e.Message.StartsWith("Timeout") ?
                                      "GPS not responding - check cable" : ("error: " + e.Message);
                    realtimeCallback(pvtData);
                    continue;
                }
                //m_linkLayer.log("" + total + " ===  " + received);
                m_linkLayer.log("StartRealTime: good packet received, count=" + total + "   " + received);
                if (received.header.EndsWith("GGA"))                    // NMEA GGA expected for location
                {
                    m_linkLayer.log("StartRealTime: " + received.header + " packet received, count=" + total + "   content=" + received);
                    try
                    {
                        MPacket pvt = received.fromString();

                        /*
                         *      $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
                         *
                         *      Where:
                         *              GGA          Global Positioning System Fix Data
                         *      0	123519       Fix taken at 12:35:19 UTC
                         *      1	4807.038,N   Latitude 48 deg 07.038' N
                         *      3	01131.000,E  Longitude 11 deg 31.000' E
                         *      5	1            Fix quality: 0 = invalid
                         *                                                              1 = GPS fix
                         *                                                              2 = DGPS fix
                         *                                                              6 = estimated (2.3 feature)
                         *      6	08           Number of satellites being tracked
                         *      7	0.9          Horizontal dilution of position
                         *      8	545.4,M      Altitude, Meters, above mean sea level
                         *      10	46.9,M       Height of geoid (mean sea level) above WGS84
                         *                                              ellipsoid
                         *      12	(empty field) time in seconds since last DGPS update
                         *      13	(empty field) DGPS station ID number
                         * 47          the checksum data, always begins with *
                         */

                        double Lat  = pvt.parseLat(1);
                        double Lng  = pvt.parseLng(1);
                        double Elev = pvt.parseElev(8);                                 // alt above mean sea level
                        pvtData.location = new GeoCoord(Lng, Lat, Elev);
                        //m_linkLayer.log("coord=" + pvtData.location);

                        // time component:
                        pvtData.time = pvt.parseNmeaTime(0, Project.localToZulu(DateTime.Now));                         // UTC

                        // errors and velocity:
                        pvtData.posError  = 0;
                        pvtData.posErrorH = 0;
                        pvtData.posErrorV = 0;
                        pvtData.fix       = 0;                                          // failed integrity check
                        switch ((string)pvt.fields[5])
                        {
                        case "0":                                                       // invalid
                            pvtData.fix = 1;                                            // invalid
                            break;

                        case "1":                                                       // GPS fix
                            pvtData.fix = 2;                                            // two dimensional
                            break;

                        case "2":                                                       // DGPS fix
                            pvtData.fix = 4;                                            // two dimensional differential
                            break;

                        case "6":                                                       // estimated
                            pvtData.fix = 6;                                            // estimated
                            break;
                        }
                        pvtData.velocityEast  = 0;
                        pvtData.velocityNorth = 0;
                        pvtData.velocityUp    = 0;

                        pvtData.comment = "received " + received.header;
                        //realtimeCallback(pvtData);

                        total++;
                        errors = maxErrors;
                    }
                    catch (Exception ee)
                    {
                        m_linkLayer.logError("StartRealTime: " + ee.Message);
                    }
                }
                else if (received.header.EndsWith("RMC"))                       // NMEA RMC may come
                {
                    m_linkLayer.log("StartRealTime: " + received.header + " packet received, count=" + total + "   content=" + received);
                    try
                    {
                        MPacket pvt = received.fromString();

                        // $GPRMC,052458.73,V,3334.6441,N,11739.6622,W,00.0,000.0,290103,13,E*4F

                        /*
                         * see http://www.gpsinformation.org/dale/nmea.htm for NMEA reference
                         *
                         * RMC - NMEA has its own version of essential gps pvt (position, velocity, time) data.
                         * It is called RMC, The Recommended Minimum, which might look like:
                         *
                         * $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
                         * $GPRMC,050821.000,A,3334.5551,N,11739.7705,W,0.00,,251006,,,A*67
                         *
                         * Where:
                         *  RMC          Recommended Minimum sentence C
                         * 0	123519       Fix taken at 12:35:19 UTC
                         * 1	A            Status A=active or V=Void.
                         * 2	4807.038,N   Latitude 48 deg 07.038' N
                         * 4	01131.000,E  Longitude 11 deg 31.000' E
                         * 6	022.4        Speed over the ground in knots
                         * 7	084.4        Track angle in degrees True
                         * 8	230394       Date - 23rd of March 1994
                         * 9	003.1,W      Magnetic Variation
                         * 6A          The checksum data, always begins with *
                         *
                         * Note that, as of the 2.3 release of NMEA, there is a new field in the RMC sentence
                         * at the end just prior to the checksum. The value of the entry is
                         * A=autonomous, D=differential, E=estimated, N=Data not valid.
                         */
                        bool status = "A".Equals(pvt.fields[1]);
                        if (status)
                        {
                            double Lat  = pvt.parseLat(2);
                            double Lng  = pvt.parseLng(2);
                            double Elev = 0.0d;
                            pvtData.location = new GeoCoord(Lng, Lat, Elev);
                            //m_linkLayer.log("coord=" + pvtData.location);

                            // time component (only time part):
                            pvtData.time = pvt.parseNmeaDateTime(0, 8); // UTC

                            if (!"".Equals(pvt.fields[6]))
                            {
                                double knots = Convert.ToDouble(pvt.fields[6]);
                                pvtData.velocity = knots * Distance.METERS_PER_NAUTICAL_MILE / 3600.0d;
                                // calculate velocity vector based on track angle:
                                if (!"".Equals(pvt.fields[7]))
                                {
                                    double trackAngleRad = Convert.ToDouble(pvt.fields[7]) * Math.PI / 180.0d;
                                    pvtData.velocityNorth = pvtData.velocity * Math.Cos(trackAngleRad);
                                    pvtData.velocityEast  = pvtData.velocity * Math.Sin(trackAngleRad);
                                }
                            }

                            pvtData.fix     = 2;                                                // assume two-dimensional
                            pvtData.comment = "received " + received.header;
                            realtimeCallback(pvtData);
                        }
                        total++;
                        errors = maxErrors;
                    }
                    catch (Exception ee)
                    {
                        m_linkLayer.logError("StartRealTime: " + ee.Message);
                    }
                }
                else if (received.header.EndsWith("GLL"))                       // NMEA GLL may come
                {
                    m_linkLayer.log("StartRealTime: GLL packet received, count=" + total + "   content=" + received);
                    try
                    {
                        MPacket pvt = received.fromString();
                        // $GPGLL,3334.6464,N,11739.6583,W,052707.129,A*29

                        /*
                         * see http://www.gpsinformation.org/dale/nmea.htm for NMEA reference
                         *
                         * GLL - Geographic Latitude and Longitude is a holdover from Loran data and some old units
                         *   may not send the time and data valid information if they are emulating Loran data.
                         *   If a gps is emulating Loran data they may use the LC Loran prefix instead of GP.
                         *
                         * $GPGLL,4916.45,N,12311.12,W,225444,A,*31
                         *
                         * Where:
                         *  GLL          Geographic position, Latitude and Longitude
                         * 0	4916.46,N    Latitude 49 deg. 16.45 min. North
                         * 2	12311.12,W   Longitude 123 deg. 11.12 min. West
                         * 4	225444       Fix taken at 22:54:44 UTC
                         * 5	A            Data valid or V (void)
                         * 31          checksum data
                         *
                         */
                        bool status = "A".Equals(pvt.fields[5]);
                        if (status)
                        {
                            double Lat  = pvt.parseLat(0);
                            double Lng  = pvt.parseLng(0);
                            double Elev = 0.0d;
                            pvtData.location = new GeoCoord(Lng, Lat, Elev);
                            //m_linkLayer.log("coord=" + pvtData.location);

                            // time component (only time part):
                            pvtData.time = pvt.parseNmeaTime(4, Project.localToZulu(DateTime.Now)); // UTC

                            pvtData.fix     = 2;                                                    // assume two-dimensional
                            pvtData.comment = "received " + received.header;
                            //realtimeCallback(pvtData);
                        }
                        total++;
                        errors = maxErrors;
                    }
                    catch (Exception ee)
                    {
                        m_linkLayer.logError("StartRealTime: " + ee.Message);
                    }
                }
                else if (received.header.EndsWith("GSV"))                       // NMEA GSV may come for satellite reception status
                {
                    m_linkLayer.log("StartRealTime: GSV packet received, count=" + total + "   content=" + received);

                    /*
                     * see http://www.gpsinformation.org/dale/nmea.htm for NMEA reference
                     *
                     * $GPGSV,3,1,08,14,69,204,,15,57,105,36,18,45,047,36,03,42,263,36*71
                     * $GPGSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75
                     *
                     * Where:
                     *  GSV          Satellites in view
                     * 0	2            Number of sentences for full data
                     * 1	1            sentence 1 of 2
                     * 2	08           Number of satellites in view
                     * for up to 4 satellites per sentence {
                     *      3	01           Satellite PRN number
                     *      4	40           Elevation, degrees
                     *      5	083          Azimuth, degrees
                     *      6	46           Signal strength - higher is better
                     * }
                     * 75          the checksum data, always begins with *
                     */

                    //MPacket pvt  = received.fromString();
                    //pvtData.comment = "received";
                    //realtimeCallback(pvtData);

                    total++;
                    errors = maxErrors;
                }
                else if (received.header.EndsWith("VTG"))                       // NMEA GSA may come
                {
                    m_linkLayer.log("StartRealTime: GPVTG packet received, count=" + total + "   content=" + received);
                    // $GPVTG,309.62,T,,M,0.13,N,0.2,K*6E

                    /*
                     *  VTG - Course Over Ground and Ground Speed
                     *
                     *      Name		Example		Units	Description
                     *      Message ID	$GPVTG				VTG protocol header
                     *      Course		309.62		degrees Measured heading
                     *      Reference	T					True
                     *      Course					degrees	Measured heading
                     *      Reference	M					Magnetic
                     *      Speed		0.13		knots	Measured horizontal speed
                     *      Units		N			Knots
                     *      Speed		0.2			Km/hr	Measured horizontal speed
                     *      Units		K					Kilometers per hour
                     */
                }
                else if (received.header.EndsWith("GSA"))                       // NMEA GSA may come
                {
                    m_linkLayer.log("StartRealTime: GPGSA packet received, count=" + total + "   content=" + received);
                    // $GPGSA,A,2,15,18,14,31,,,,,,,,,05.6,05.6,*17

                    /*
                     * see http://www.gpsinformation.org/dale/nmea.htm for NMEA reference
                     *
                     * GSA - GPS DOP and active satellites. This sentence provides details on the nature of the
                     * fix. It includes the numbers of the satellites being used in the current solution and
                     * the DOP. DOP (dilution of precision) is an indication of the effect of satellite geometry
                     * on the accuracy of the fix. It is a unitless number where smaller is better. For 3D fixes
                     * using 4 satellites a 1.0 would be considered to be a perfect number. For overdetermined
                     * solutions it is possible to see numbers below 1.0. There are differences in the way the
                     * PRN's are presented which can effect the ability of some programs to display this data.
                     * For example, in the example shown below there are 5 satellites in the solution and
                     * the null fields are scattered indicating that the almanac would show satellites in
                     * the null positions that are not being used as part of this solution. Other receivers
                     * might output all of the satellites used at the beginning of the sentence with the
                     * null field all stacked up at the end. This difference accounts for some satellite
                     * display programs not always being able to display the satellites being tracked.
                     *
                     * $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39
                     *
                     * Where:
                     *  GSA      Satellite status
                     *  A        Auto selection of 2D or 3D fix (M = manual)
                     *  3        3D fix - other values include: 1 = no fix
                     *                                          2 = 2D fix
                     *  04,05... PRNs of satellites used for fix (space for 12)
                     *  2.5      PDOP (dilution of precision)
                     *  1.3      Horizontal dilution of precision (HDOP)
                     *  2.1      Vertical dilution of precision (VDOP)
                     * 39      the checksum data, always begins with *
                     *
                     */
                }
                else
                {
                    m_linkLayer.log("StartRealTime: good other (unrecognized) packet received, count=" + total + "   content=" + received);
                }
            }             // end while()

            m_linkLayer.log("StartRealTime: finished receiving fixes count=" + total);
        }
Exemplo n.º 4
0
        private void simulateStartRealTime(GpsRealTimeHandler realtimeCallback)
        {
            int      toWait   = 3;
            int      toCount  = 10;
            double   degIncr  = 360.0d / (toCount * 4);
            double   degree   = 0.0d;
            int      count    = toCount;
            GeoCoord location = new GeoCoord(CameraManager.This.Location.Lng, CameraManager.This.Location.Lat);

            while (count-- > 0)
            {
                GpsRealTimeData rtData = new GpsRealTimeData();
                rtData.location = location;
                rtData.fix      = 2;
                rtData.time     = DateTime.Now;

                rtData.velocity      = 10.0d;
                rtData.velocityEast  = 5.0d * Math.Sin(degree * Math.PI / 180.0d);
                rtData.velocityNorth = 5.0d * Math.Cos(degree * Math.PI / 180.0d);
                degree += degIncr;

                realtimeCallback(rtData);

                location.Lat += 0.0005d;
                location.Lng += 0.0005d;

                Thread.Sleep(toWait);
            }
            count = toCount;
            while (count-- > 0)
            {
                GpsRealTimeData rtData = new GpsRealTimeData();
                rtData.location = location;
                rtData.fix      = 2;
                rtData.time     = DateTime.Now;

                rtData.velocity      = 10.0d;
                rtData.velocityEast  = 5.0d * Math.Sin(degree * Math.PI / 180.0d);
                rtData.velocityNorth = 5.0d * Math.Cos(degree * Math.PI / 180.0d);
                degree += degIncr;

                realtimeCallback(rtData);

                location.Lat -= 0.0005d;
                location.Lng += 0.0005d;

                Thread.Sleep(toWait);
            }
            count = toCount;
            while (count-- > 0)
            {
                GpsRealTimeData rtData = new GpsRealTimeData();
                rtData.location = location;
                rtData.fix      = 2;
                rtData.time     = DateTime.Now;

                rtData.velocity      = 10.0d;
                rtData.velocityEast  = 5.0d * Math.Sin(degree * Math.PI / 180.0d);
                rtData.velocityNorth = 5.0d * Math.Cos(degree * Math.PI / 180.0d);
                degree += degIncr;

                realtimeCallback(rtData);

                location.Lat -= 0.0005d;
                location.Lng -= 0.0005d;

                Thread.Sleep(toWait);
            }
            count = toCount;
            while (count-- > 0)
            {
                GpsRealTimeData rtData = new GpsRealTimeData();
                rtData.location = location;
                rtData.fix      = 2;
                rtData.time     = DateTime.Now;

                rtData.velocity      = 10.0d;
                rtData.velocityEast  = 5.0d * Math.Sin(degree * Math.PI / 180.0d);
                rtData.velocityNorth = 5.0d * Math.Cos(degree * Math.PI / 180.0d);
                degree += degIncr;

                realtimeCallback(rtData);

                location.Lat += 0.0005d;
                location.Lng -= 0.0005d;

                Thread.Sleep(toWait);
            }
        }
Exemplo n.º 5
0
        public static void processApiCall(string strArgs)
        {
            ArrayList files  = new ArrayList();                 // of string
            bool      doMove = false;

            char[]   splitter = { '|' };
            string[] args     = strArgs.Split(splitter);
            GeoCoord pos      = PictureManager.This.CameraManager.Location.Clone();

            switch (args[0])
            {
            case "api":                                 // something like "api|cmd|data...."
                switch (args[1])
                {
                case "refresh":
                    PictureManager.This.CameraManager.ProcessCameraMove();
                    break;

                case "resetzoom":
                    WaypointsCache.resetBoundaries();
                    break;

                case "dozoom":
                    PictureManager.This.CameraManager.zoomToCorners();
                    break;

                case "newwpt":
                {
                    double   lat       = Convert.ToDouble(args[2]);
                    double   lng       = Convert.ToDouble(args[3]);
                    double   elev      = Convert.ToDouble(args[4]);
                    DateTime dateTime  = Convert.ToDateTime(args[5]);
                    string   name      = args[6];                                       // like "GC12345"
                    string   urlName   = args[7];                                       // like "Mike's cache"
                    string   type      = args[8];                                       // like "geocache"
                    string   typeExtra = args[9];                                       // like "Geocache Found"
                    string   sym       = args[10];                                      // like "Geocache"
                    long     trackid   = Convert.ToInt64(args[11]);                     // -1 is none, -2 - last track created
                    if (trackid == -2)
                    {
                        trackid = Project.trackId;
                    }
                    string url        = args[12];                                       // can be empty
                    string descr      = args[13];                                       // can be empty
                    string source     = args[14];                                       // can be empty
                    bool   keepInView = "true".Equals(args[15].ToLower());

                    CreateInfo ci = new CreateInfo();

                    ci.init(type);

                    ci.comment  = "";
                    ci.dateTime = dateTime;
                    ci.desc     = descr;
                    ci.elev     = elev;
                    ci.id       = trackid;
                    ci.lat      = lat;
                    ci.lng      = lng;
                    //ci.magn = 0.0d;
                    ci.name      = name;
                    ci.source    = source;
                    ci.sym       = sym;
                    ci.typeExtra = typeExtra;
                    ci.url       = url;
                    ci.urlName   = urlName;

                    WaypointsCache.insertWaypoint(ci);
                    if (keepInView)
                    {
                        GeoCoord loc = new GeoCoord(lng, lat);
                        PictureManager.This.CameraManager.keepInView(loc);
                    }
                }
                break;

                case "delwpt":
                {
                    string name    = args[2];                                           // like "GC12345"
                    string urlName = args[3];                                           // like "Mike's cache"
                    string source  = args[4];

                    if (name.Length > 0)
                    {
                        WaypointsCache.RemoveWaypointByName(name);
                    }
                    else if (urlName.Length > 0)
                    {
                        WaypointsCache.RemoveWaypointByUrlname(urlName);
                    }
                    else if (source.Length > 0)
                    {
                        WaypointsCache.RemoveWaypointsBySource(source);
                    }

                    //PictureManager.This.CameraManager.ProcessCameraMove();
                }
                break;

                case "newtrk":
                {
                    string trackName = args[2];                                                 // like "trip home"
                    string type      = args[3];                                                 // like "trk" or "rte"
                    string source    = args[4];                                                 // can be empty

                    CreateInfo ci = new CreateInfo();

                    Project.trackId++;

                    ci.init(type);
                    ci.name   = trackName;
                    ci.id     = Project.trackId;
                    ci.source = source;

                    WaypointsCache.insertWaypoint(ci);
                }
                break;

                case "deltrk":                                  // or route
                {
                    string name   = args[2];                    // like "track45"			- if empty, use source
                    string source = args[3];                    // can delete by source		- if empty, delete the last one

                    if (name.Length > 0)
                    {
                        WaypointsCache.RemoveTracksByName(name);
                    }
                    else if (source.Length > 0)
                    {
                        WaypointsCache.RemoveTracksBySource(source);
                    }
                    else
                    {
                        // move ID pointer to the highest yet existing track/route:
                        while (Project.trackId > 0 && WaypointsCache.getTrackById(Project.trackId) == null)
                        {
                            Project.trackId--;
                        }

                        if (Project.trackId >= 0)
                        {
                            WaypointsCache.RemoveTrackById(Project.trackId);

                            // move ID pointer to the highest yet existing track/route:
                            while (Project.trackId > 0 && WaypointsCache.getTrackById(Project.trackId) == null)
                            {
                                Project.trackId--;
                            }
                        }
                    }

                    PictureManager.This.CameraManager.ProcessCameraMove();
                }
                break;

                case "newvehicle":
                {
                    double   lat        = Convert.ToDouble(args[2]);
                    double   lng        = Convert.ToDouble(args[3]);
                    double   elev       = Convert.ToDouble(args[4]);
                    DateTime dateTime   = args[5].Length > 0 ? Convert.ToDateTime(args[5]) : Project.localToZulu(DateTime.Now);
                    string   name       = args[6];                                                              // like "My Chevy"
                    string   sym        = args[7];                                                              // like "1" "2"...  or empty
                    string   url        = args[8];                                                              // can be empty
                    string   source     = args[9];                                                              // can be empty
                    string   desc       = args[10];                                                             // can be empty
                    bool     keepInView = "true".Equals(args[11].ToLower());
                    bool     doTrackLog = "true".Equals(args[12].ToLower());

                    GeoCoord loc = new GeoCoord(lng, lat, elev);

                    GpsRealTimeData rtData = new GpsRealTimeData();
                    rtData.location = loc;
                    rtData.fix      = 2;
                    rtData.time     = dateTime;

                    VehicleGps vehicle = new VehicleGps(rtData, name, sym, source, url, desc, doTrackLog);                              // also adds to VehicleCache
                    vehicle.KeepInView = keepInView;
                    VehiclesCache.addVehicle(vehicle);
                }
                break;

                case "movevehicle":
                {
                    double   lat        = Convert.ToDouble(args[2]);
                    double   lng        = Convert.ToDouble(args[3]);
                    double   elev       = Convert.ToDouble(args[4]);
                    DateTime dateTime   = args[5].Length > 0 ? Convert.ToDateTime(args[5]) : Project.localToZulu(DateTime.Now);
                    string   name       = args[6];                                                              // like "My Chevy"
                    string   sym        = args[7];                                                              // like "1" "2"...  or empty
                    string   url        = args[8];                                                              // can be empty
                    string   source     = args[9];                                                              // can be empty
                    string   desc       = args[10];                                                             // can be empty
                    bool     keepInView = "true".Equals(args[11].ToLower());
                    bool     doTrackLog = "true".Equals(args[12].ToLower());

                    GeoCoord loc = new GeoCoord(lng, lat, elev);

                    GpsRealTimeData rtData = new GpsRealTimeData();
                    rtData.location = loc;
                    rtData.fix      = 2;
                    rtData.time     = dateTime;

                    VehicleGps vehicle = (VehicleGps)VehiclesCache.getVehicleByName(name);
                    if (vehicle != null)
                    {
                        if (url.Length > 0)
                        {
                            vehicle.Url = url;
                        }
                        if (sym.Length > 0)
                        {
                            vehicle.Sym = sym;
                            vehicle.setImage(sym);
                        }
                        if (desc.Length > 0)
                        {
                            vehicle.Desc = desc;
                        }
                        vehicle.KeepInView = keepInView;
                        vehicle.doTrackLog = doTrackLog;
                        vehicle.ProcessMove(rtData);
                    }
                }
                break;

                case "delvehicle":
                {
                    string name   = args[2];                                                                    // like "My Chevy" or empty
                    string source = args[3];                                                                    // can be empty

                    VehicleGps vehicle = (VehicleGps)VehiclesCache.getVehicleByName(name);
                    if (vehicle != null)
                    {
                        bool wasTracking = vehicle.doTrackLog;
                        VehiclesCache.deleteVehicle(vehicle);                                   // takes care of removing it from LayerVehicle
                        if (wasTracking)
                        {
                            PictureManager.This.CameraManager.ProcessCameraMove();                                      // refresh to have track endpoints
                        }
                    }
                }
                break;

                case "exporttofile":
                {
                    string fileName = args[2];

                    int waypointCount = 0;
                    int trkpointCount = 0;
                    int tracksCount   = 0;

                    FileAndZipIO.saveGpx(fileName, WaypointsCache.TracksAll, true,
                                         WaypointsCache.WaypointsAll, true, out waypointCount, out trkpointCount, out tracksCount);

                    if (waypointCount > 0 || trkpointCount > 0)
                    {
                        LibSys.StatusBar.Trace("OK: " + waypointCount + " waypoints and " + trkpointCount + " legs saved to file " + fileName);
                    }
                    else
                    {
                        LibSys.StatusBar.Error("failed to save to file (0 waypoints, 0 legs): " + fileName);
                    }
                }
                break;
                }
                break;

            default:                            // regular command-line style messages - lon, lat, elev, map, file

                foreach (string arg in args)
                {
                    if (arg.StartsWith("/"))
                    {
#if DEBUG
                        LibSys.StatusBar.Trace("option: '" + arg + "'");
#endif
                        try
                        {
                            if (arg.ToLower().StartsWith("/lat="))
                            {
                                double lat = Convert.ToDouble(arg.Substring(5));
                                if (lat < 90.0d && lat > -90.0d)
                                {
                                    pos.Lat = lat;
                                    doMove  = true;
                                }
                            }
                            else if (arg.ToLower().StartsWith("/lon="))
                            {
                                double lon = Convert.ToDouble(arg.Substring(5));
                                if (lon < 180.0d && lon > -180.0d)
                                {
                                    pos.Lng = lon;
                                    doMove  = true;
                                }
                            }
                            else if (arg.ToLower().StartsWith("/elev="))
                            {
                                double elev = Convert.ToDouble(arg.Substring(6));
                                if (elev < Project.CAMERA_HEIGHT_MAX * 1000.0d && elev > Project.CAMERA_HEIGHT_MIN_DEFAULT * 1000.0d)
                                {
                                    pos.Elev = elev;
                                    doMove   = true;
                                }
                            }
                            else if (arg.ToLower().StartsWith("/map="))
                            {
                                string mode = arg.Substring(5);
                                Project.mainCommand.setMapMode(mode);
                                doMove = true;
                            }
                        }
                        catch (Exception ee)
                        {
                            string message = "argument '" + arg + "' - wrong format (" + ee.Message + ")";
                            LibSys.StatusBar.Error(message);
                            Project.ErrorBox(null, message);
                        }
                    }
                    else
                    {
#if DEBUG
                        LibSys.StatusBar.Trace("file: '" + arg + "'");
#endif
                        files.Add(arg);
                    }
                }

                if (files.Count > 0)
                {
                    // similar to drag&drop:
                    Cursor.Current = Cursors.WaitCursor;
                    Project.mainForm.Focus();
                    Project.mainForm.BringToFront();

                    try
                    {
                        string[] fileNames = new string[files.Count];

                        int ii = 0;
                        foreach (string fileName in files)
                        {
                            fileNames[ii] = fileName;
                            ii++;
                        }

                        bool anySuccess = FileAndZipIO.readFiles(fileNames);

                        if (anySuccess)                                 // we need to zoom into whole set of dropped files, or refresh in case of JPG
                        {
                            Project.mainCommand.wptEnabled(true);
                            if (!PictureManager.This.CameraManager.zoomToCorners())
                            {
                                PictureManager.This.CameraManager.ProcessCameraMove();                                          // nowhere to zoom in - just refresh
                            }
                        }
                    }
                    catch
                    {
                        LibSys.StatusBar.Trace("* API: cannot accept arguments '" + strArgs + "'");
                    }
                    Cursor.Current = Cursors.Default;
                }
                break;
            }                   // end switch

            if (doMove)
            {
                PictureManager.This.CameraManager.Location = pos;                               // calls ProcesCameraMove()
            }
        }
Exemplo n.º 6
0
        public void ProcessMove(GpsRealTimeData rtData)
        {
            if (rtData == null)
            {
                resetTrackLog();
                return;
            }

            if (rtData.location != null)
            {
                RealTimeData = rtData;

                bool locationChanged = false;
                bool imageChanged    = false;
                bool haveFix         = false;

                Rectangle prev    = this.BoundingRect;                  // on previous image/location
                Rectangle prevImg = this.m_imageBoundingRect;           // on previous image

                switch (rtData.fix)
                {
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                    if (Image != m_imageSym)
                    {
                        imageChanged = true;
                        Image        = m_imageSym;
                    }
                    haveFix   = true;
                    m_lastFix = DateTime.Now;
                    //if(rtData.location.Lng != this.Location.Lng || rtData.location.Lat != this.Location.Lat)
                    double moveTreshold = 0.000005d;
                    if (Math.Abs(rtData.location.Lng - this.Location.Lng) > moveTreshold ||
                        Math.Abs(rtData.location.Lat - this.Location.Lat) > moveTreshold)
                    {
                        locationChanged   = true;
                        this.Location.Lng = rtData.location.Lng;
                        this.Location.Lat = rtData.location.Lat;
                    }
                    imageBoundingRect();
                    if (!prevImg.Equals(this.m_imageBoundingRect))
                    {
                        imageChanged = true;
                    }
                    break;

                default:
                    if (Image != m_image_nofix)
                    {
                        imageChanged = true;
                        Image        = m_image_nofix;
                    }
                    break;
                }

                if (imageChanged)
                {
                    m_pixelRadius = (Image == null) ? MIN_VEH_PIXEL_RADIUS : (Image.Width + Image.Height) * 3 / 16;
                }

                this.tick();

                if (haveFix && m_doTrackLog)
                {
                    logTrack(rtData);
                }

                if (locationChanged || imageChanged)
                {
                    VehiclesCache.vehicleMoved(this, prev);                     // will put on map and recalculate image bounding rect
                }
            }
            else if (Image != m_image_nofix && m_lastFix.AddSeconds(10).CompareTo(DateTime.Now) < 0)
            {
                RealTimeData = rtData;
                Rectangle prev = this.BoundingRect;                     // on previous image/location
                Image = m_image_nofix;
                this.tick();
                VehiclesCache.vehicleMoved(this, prev);                 // will put on map and recalculate image bounding rect
            }
        }