-----------------------------------------
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Socket1 As Socket
Dim ServerSocket1 As ServerSocket
'Dim InputStream1 As InputStream
Dim AStreams As AsyncStreams
Dim OutputStream1 As OutputStream
'Dim Conv As ByteConverter
Dim Timer1 As Timer
Dim MyIP As String
Dim ServerIp As String
Dim iStr As String 'input string
Dim Tracciato As String
Dim GPS1 As GPS
Dim Luppa As Int
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim lblConnect As Label
Dim btnConnect As Button
Dim lvLog As ListView
Dim lblMsg As Label
Dim lblLon As Label
Dim lblLat As Label
Dim lblSpeed As Label
Dim lblSatellites As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Dim t As String
Activity.LoadLayout("1")
btnConnect.Enabled = False
'Todo: Change typeface of lvLog
lvLog.SingleLineLayout.ItemHeight = 16dip
lvLog.SingleLineLayout.Label.TextSize = 12
MyIP = ServerSocket1.GetMyIP
lblConnect.Text = MyIP
If FirstTime = True Then
btnConnect_Click
End If
If FirstTime Then
GPS1.Initialize("GPS")
End If
Activity.LoadLayout("1")
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 btnConnect_Click
Select Case btnConnect.Text
Case "Connect"
btnConnect.Text = "Disconnect"
Socket1.Initialize("Socket1")
'Set correct ServerIp
Socket1.Connect("192.168.43.150",30175,10000)
Case "Disconnect"
btnConnect.Text = "Connect"
Socket1.Close
'ExitApplication
Case Else
End Select
End Sub
Sub GPS_LocationChanged (Location1 As Location)
Luppa=Luppa+1
If Luppa > 4 Then
lblLat.Text = "Lat = " & Location1.Latitude
lblLon.Text = "Lon = " & Location1.Longitude
lblSpeed.Text = "Speed = " & Location1.Speed
Tracciato = "Maurizio;" & Location1.Longitude & ";" & Location1.Latitude & ";" & Location1.Altitude &";"&DateTime.Date(DateTime.Now)& " " & DateTime.Time(DateTime.Now) & ";" & Location1.Speed & ";" & Location1.Bearing & ";3;15"
SendData (Tracciato)
Luppa=0
End If
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 Socket1_Connected(Connected As Boolean)As Boolean
If Connected = True Then
ToastMessageShow("Connected",True)
lvLog.AddSingleLine("Connected!")
AStreams.Initialize( Socket1.InputStream ,Socket1.OutputStream,"Astreams")
Else
ToastMessageShow("Server not available",True)
lvLog.AddSingleLine("Server not available")
btnConnect.Text = "Connect"
End If
btnConnect.Enabled = True
End Sub
Sub AStreams_NewData (Buffer () As Byte)
' Dim msg As String
' Dim cMsg As String
' Dim t As String
' Dim x As Int
' Dim unsignedi As Int
' Dim signedb As Byte
' msg = BytesToString( Buffer, 0, Buffer.Length, "ASCII")
' lvLog.AddSingleLine (msg)
' Log(msg)
' For i = 0 To msg.Length -1
' signedb = Buffer(i)
' unsignedi = Bit.And(0xff, signedb)
' cMsg = cMsg & Chr(unsignedi)
' Next
' lvLog.AddSingleLine(cMsg)
' Log(cMsg)
' lblMsg.Text = x & " / " & msg.Length & " - " & msg
End Sub
Sub SendData(msg As String)
Dim Buffer() As Byte
Buffer = msg.GetBytes( "UTF8")
AStreams.Write (Buffer)
'AStreams.Write(Array As Byte(254))
'AStreams.flush
End Sub
Sub btnTest_Click
Dim msg As String
msg = "Ciao !!!!!"
SendData(msg)
End Sub