CE OS 5.2를 실행하는 Motorola MC65 장치가 있습니다. 나는 장치를위한 유효한 시간을 얻고 싶다; 나는이 데이터를 위성으로부터 수신했기 때문에 위치에 대한 정확한 시간을 알 수 있었다고 느꼈다. ...GPS가 Windows Mobile CE 5.2에서 잘못된 타임 스탬프를 반환합니다.
나는 정확한 날짜를 받고 있지만 시간은 3 시간 씩 떨어져있다. 나는 동부 표준시 시간대이며, 장치의 시간대가 올바로 설정되어 있고 장치의 시간이 오전 11시 56 분 (알 수 없음)이며 GPS는 오후 4:15을 반환합니다 ...
여기 내 현재입니다 코드, 나는 Microsoft에서 제공하는 GPS 중급 드라이버 (https://msdn.microsoft.com/en-us/library/bb202128.aspx)를 사용하게 GPS를 통해 시간을 얻을 : 또한
public DateTime GetGPSTime()
{
Boolean satsInView = false;
Gps g = new Gps();
g.DeviceStateChanged += new DeviceStateChangedEventHandler(g_DeviceStateChanged);
g.Open();
Thread.Sleep(4000);
if (g.Opened)
{
if (deviceState.ServiceState == GpsServiceState.On)
{
GpsPosition pos = g.GetPosition(TimeSpan.Zero); //No Delay in time
if (pos != null)
{
//First check that we have sats visible for good GPS signal.
if (pos.SatellitesInViewCountValid)
{
if (pos.SatellitesInViewCount >= 1)
satsInView = true;
else
satsInView = false;
}
if (pos.TimeValid && satsInView)
{
g.Close();
g.DeviceStateChanged -= g_DeviceStateChanged;
return pos.Time; //Returned time obtained from GPS Obj
}
}
g.Close();
g.DeviceStateChanged -= g_DeviceStateChanged;
return Helper.GetSystemTimeToNow(); //If GPS obj is null, return current system time.
}
}
g.Close();
g.DeviceStateChanged -= g_DeviceStateChanged;
return Helper.GetSystemTimeToNow(); //If GPS obj is null, return current system time.
}
을, 여기에 마이크로 소프트의 공식 Interme의 방법입니다 diate GPS 코드 샘플. GPSposition.validField은 시간이 유효 함을 말한다면이 방법은, GpsPosition pos = g.GetPosition(TimeSpan.Zero);
/// <summary>
/// Get the position reported by the GPS receiver that is no older than
/// the maxAge passed in
/// </summary>
/// <param name="maxAge">Max age of the gps position data that you want back.
/// If there is no data within the required age, null is returned.
/// if maxAge == TimeSpan.Zero, then the age of the data is ignored</param>
/// <returns>GpsPosition class with all the position details</returns>
public GpsPosition GetPosition(TimeSpan maxAge)
{
GpsPosition gpsPosition = null;
if (Opened)
{
// allocate the necessary memory on the native side. We have a class (GpsPosition) that
// has the same memory layout as its native counterpart
IntPtr ptr = Utils.LocalAlloc(Marshal.SizeOf(typeof(GpsPosition)));
// fill in the required fields
gpsPosition = new GpsPosition();
gpsPosition.dwVersion = 1;
gpsPosition.dwSize = Marshal.SizeOf(typeof(GpsPosition));
// Marshal our data to the native pointer we allocated.
Marshal.StructureToPtr(gpsPosition, ptr, false);
// call native method passing in our native buffer
int result = GPSGetPosition(gpsHandle, ptr, 500000, 0);
if (result == 0)
{
// native call succeeded, marshal native data to our managed data
gpsPosition = (GpsPosition)Marshal.PtrToStructure(ptr, typeof(GpsPosition));
if (maxAge != TimeSpan.Zero)
{
// check to see if the data is recent enough.
if (!gpsPosition.TimeValid || DateTime.Now - maxAge > gpsPosition.Time)
{
gpsPosition = null;
}
}
}
else if (result == 87) // ERROR_INVALID_PARAMETER)
{
//
// TEMPORARY HACK
//
// http://blogs.msdn.com/cenet/archive/2007/12/06/gpsid-problem-workaround-on-recent-wm6-release.aspx
//
Utils.LocalFree(ptr);
// allocate the necessary memory on the native side. We have a class (GpsPosition) that
// has the same memory layout as its native counterpart
ptr = Utils.LocalAlloc(376);
// fill in the required fields
gpsPosition = new GpsPosition();
gpsPosition.dwVersion = 1;
gpsPosition.dwSize = 376;
// Marshal our data to the native pointer we allocated.
Marshal.StructureToPtr(gpsPosition, ptr, false);
// call native method passing in our native buffer
result = GPSGetPosition(gpsHandle, ptr, 500000, 0);
if (result == 0)
{
// native call succeeded, marshal native data to our managed data
gpsPosition = (GpsPosition)Marshal.PtrToStructure(ptr, typeof(GpsPosition));
if (maxAge != TimeSpan.Zero)
{
// check to see if the data is recent enough.
if (!gpsPosition.TimeValid || DateTime.Now - maxAge > gpsPosition.Time)
{
gpsPosition = null;
}
}
}
}
// free our native memory
Utils.LocalFree(ptr);
}
return gpsPosition;
}
대단히 감사합니다. – Dayan