#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: GPS
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#End Region
Sub Process_Globals
Dim GPS1 As GPS
End Sub
Sub Globals
Dim lblLon As Label
Dim lblLat As Label
Dim lblTime As Label
Dim lblSatellites As Label
Dim bSetDateTime As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
GPS1.Initialize("GPS")
End If
Activity.LoadLayout("layout_gps")
bSetDateTime = False
End Sub
Sub Activity_Resume
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
Else
GPS1.Start(0, 0) 'Listen to GPS with no filters.
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
GPS1.Stop
End Sub
Sub Compute_date_time (UnixTime As Long)
Dim targetDate As Long = DateUtils.UnixTimeToTicks(UnixTime)
DateTime.DateFormat = "yyyyMMdd"
DateTime.TimeFormat = "HHmmss"
DateTime.SetTimeZone(1)
If bSetDateTime = False Then
bSetDateTime = True
SetDateTime (DateTime.Date(targetDate), DateTime.Time(targetDate))
ToastMessageShow ("Date réglée.",True)
End If
DateTime.DateFormat = "dd.MM.yyyy"
DateTime.TimeFormat = "HH:mm:ss"
lblTime.Text = DateTime.Date(targetDate) & " / " & DateTime.Time(targetDate)
End Sub
Sub GPS_LocationChanged (Location1 As Location)
lblLat.Text = "Lat = " & Location1.ConvertToMinutes(Location1.Latitude)
lblLon.Text = "Lon = " & Location1.ConvertToMinutes(Location1.Longitude)
Compute_date_time(Location1.Time / 1000)
End Sub
Sub GPS_UserEnabled (Enabled As Boolean)
ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub
Sub GPS_GpsStatus (Satellites As List)
lblSatellites.Text = "Satellites:" & CRLF
For i = 0 To Satellites.Size - 1
Dim Satellite As GPSSatellite
Satellite = Satellites.Get(i)
lblSatellites.Text = lblSatellites.Text & CRLF & Satellite.Prn & _
" " & Satellite.Snr & " " & Satellite.UsedInFix & " " & Satellite.Azimuth _
& " " & Satellite.Elevation
Next
End Sub
Sub SetDateTime(ToDate As String, ToTime As String)
'date needs to be in yyyymmdd format
'time needs to be in hhmmss 24-hour
'date -s 20120419.024012; \n
Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
Dim Ph As Phone
StdOut.Initialize
StdErr.Initialize
Runner = File.Combine(File.DirInternalCache, "runner")
Command = File.Combine(File.DirInternalCache, "command")
File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
File.WriteString(File.DirInternalCache, "command", "date -s " & ToDate & "." & ToTime & "; \n" & CRLF & "exit")
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
End Sub
Sub GPS_NMEA (timestamp As Long, Sentence As String)
End Sub