Пример #1
0
        public GPSPosition GetPosition()
        {
            GPSPosition ret         = null;
            bool        posAcquired = false;

            lock (this) {
                if (IsOpen())
                {
                    int    cb  = Marshal.SizeOf(typeof(GPSPosition));
                    IntPtr ptr = LocalAlloc(LPTR, cb);

                    ret           = new GPSPosition();
                    ret.dwVersion = 1;
                    ret.dwSize    = Marshal.SizeOf(typeof(GPSPosition));

                    // Marshal our data to the native pointer we allocated.
                    Marshal.StructureToPtr(ret, ptr, false);

                    Int32 i = GPSGetPosition(hGPSDevice, ptr, mMaximunAge, 0);

                    if (i == 0)
                    {
                        Marshal.PtrToStructure(ptr, ret);
                        posAcquired = true;

                        // COMENTADO.
                        // Ahora la fecha la sacamos del SQL Server.
                        //' '' Seteo la hora actual en el sistema con la que tienen los satélites
                        // ''If ret.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_UTC_TIME) Then
                        // ''    If ret.stUTCTime.wYear >= 2007 Then
                        // ''        'Si la diferencia de tiempo es de más de 2 minutos, actualiza la hora
                        // ''        If Math.Abs(ret.Time.Subtract(DateTime.UtcNow).Minutes) > 2 Then
                        // ''            Dim rc As UInteger
                        // ''            rc = SetSystemTime(ret.stUTCTime)
                        // ''        End If
                        // ''    End If
                        // ''End If
                    }
                    else
                    {
                        MessageBox.Show("Error# " + i.ToString());
                    }
                    LocalFree(ptr);
                }
            }

            if (posAcquired == false)
            {
                if (PositionReceived != null)
                {
                    PositionReceived(ret);
                }
            }

            return(ret);
        }
Пример #2
0
        public static bool IsPositionValid(GPSPosition position, bool ValidateFix, float MAXDOP)
        {
            bool posOk = false;

            if ((position != null))
            {
                if (position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_UTC_TIME) & position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_HORIZONTAL_DILUTION_OF_PRECISION) & position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_LATITUDE) & position.isValidField(GPSPosition.GPS_VALID_FIELDS.GPS_VALID_LONGITUDE) & (position.fixType >= GPSFixType.XyD | ValidateFix == false))
                {
                    if ((MAXDOP >= position.flHorizontalDilutionOfPrecision) | MAXDOP == -1)
                    {
                        posOk = true;
                    }
                }
            }
            return(posOk);
        }