mirror of
https://github.com/cheveguerra/FLP_2.0.git
synced 2026-04-18 03:39:26 +00:00
Cambio de puerto
This commit is contained in:
110
Tracker.bas
110
Tracker.bas
@@ -36,30 +36,40 @@ Sub Process_Globals
|
||||
Private nid As Int = 1
|
||||
Private Tracking As Boolean
|
||||
Private lock As PhoneWakeState
|
||||
'Para FusedLocationProvider (2 lineas)
|
||||
Public flp As FusedLocationProvider
|
||||
Private flpStarted As Boolean
|
||||
Dim minAccuracy As Int = 50
|
||||
Dim killerCalled As Int = 0
|
||||
Dim locReqSmall As LocationRequest
|
||||
End Sub
|
||||
|
||||
Sub Service_Create
|
||||
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
|
||||
'Para FusedLocationProvider (2 lineas)
|
||||
Subs.revisaBD
|
||||
flp.Initialize("flp")
|
||||
flp.Connect
|
||||
lock.PartialLock
|
||||
StartFLP
|
||||
If Starter.logger Then Log("FLP initialized")
|
||||
Subs.bitacora($"Iniciamos Tracker"$)
|
||||
' Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Iniciamos Tracker', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
End Sub
|
||||
|
||||
Sub Service_Start (StartingIntent As Intent)
|
||||
locReqSmall = CreateLocationRequest2(1000, 0) 'ignore
|
||||
Service.StopAutomaticForeground
|
||||
Service.StartForeground(nid, Subs.CreateNotification("..."))
|
||||
Track
|
||||
StartServiceAt(Me, DateTime.Now + 60 * DateTime.TicksPerMinute, True)
|
||||
Subs.bitacora($"Tracker - Service_Start"$)
|
||||
End Sub
|
||||
|
||||
'Apagamos y prendemos sel servicio "Tracker" o reinicamos la aplicacion.
|
||||
'killerCalled = 0 -> Apagamos y prendemos.
|
||||
'killerCalled = 1 -> ExitApplication (se reinican todos los servicios).
|
||||
Sub flpReConnect
|
||||
Try
|
||||
If killerCalled = 0 Then
|
||||
killerCalled = 1
|
||||
Subs.bitacora("Llamamos RESTART-TRACKER")
|
||||
CallSubDelayed(Starter, "restartTracker")
|
||||
Else
|
||||
Subs.bitacora("Llamamos EXIT-APP")
|
||||
@@ -72,25 +82,16 @@ End Sub
|
||||
|
||||
Sub flp_ConnectionSuccess
|
||||
Log("FLP - Connected to location provider")
|
||||
'FLP.GetLastKnownLocation
|
||||
Subs.bitacora("FLP - Connection Success")
|
||||
End Sub
|
||||
|
||||
Sub flp_ConnectionFailed(ConnectionResult1 As Int)
|
||||
Log("Failed to connect to location provider")
|
||||
End Sub
|
||||
|
||||
Sub Service_Start (StartingIntent As Intent)
|
||||
'Para FusedLocationProvider (1 linea)
|
||||
Service.StopAutomaticForeground
|
||||
Service.StartForeground(nid, Subs.CreateNotification("..."))
|
||||
Track
|
||||
StartServiceAt(Me, DateTime.Now + 10 * DateTime.TicksPerMinute, True)
|
||||
Subs.bitacora($"Tracker - Service_Start"$)
|
||||
' Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Tracker - Service_Start', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
Subs.bitacora("FLP - Connection Failed")
|
||||
End Sub
|
||||
|
||||
Public Sub Track
|
||||
'Log("Track")
|
||||
If Starter.logger Then Log("Track")
|
||||
If Tracking Then Return 'Si ya estamos "rastreando" no hacemos nada (return)
|
||||
If Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION) = False Then
|
||||
Log("No permission")
|
||||
@@ -110,21 +111,17 @@ Public Sub StartFLP
|
||||
cont = cont + 1
|
||||
If cont > 70 Then
|
||||
cont = 0
|
||||
Log("Reiniciamos FLP")
|
||||
flpReConnect
|
||||
LogColor("Reiniciamos FLP", Colors.red)
|
||||
killerCalled = 1 : flpReConnect
|
||||
End If
|
||||
Loop
|
||||
' If flpStarted = False Then
|
||||
' Log("RequestLocationUpdates")
|
||||
' Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
flp.RequestLocationUpdates(CreateLocationRequest) 'Buscamos ubicacion
|
||||
flpStarted = True
|
||||
' End If
|
||||
End Sub
|
||||
|
||||
Private Sub CreateLocationRequest As LocationRequest
|
||||
Sub CreateLocationRequest As LocationRequest
|
||||
' Log("CreateLocationRequest")
|
||||
' Starter.FLPStatus = "Searching" : LogColor("FLP Searching", Colors.blue)
|
||||
Dim lr As LocationRequest
|
||||
lr.Initialize
|
||||
lr.SetInterval(30000) 'Intervalo deseado para actualizaciones de ubicacion en milisegundos
|
||||
@@ -134,21 +131,19 @@ Private Sub CreateLocationRequest As LocationRequest
|
||||
Return lr
|
||||
End Sub
|
||||
|
||||
Sub dameUltimaUbicacionConocida(lastLocation As Location) 'ignore
|
||||
If Starter.logger Then LogColor("dameUltimaUbicacionConocida", Colors.Magenta)
|
||||
' Subs.gps_hist.ExecNonQuery("CREATE TABLE IF NOT EXISTS RUTA_GPS(FECHA INTEGER, LAT TEXT, LON TEXT)")
|
||||
If Starter.logger Then Log("This accuracy: " & Starter.UUC.Accuracy)
|
||||
Subs.bitacora($"Enviamos UUC - Acc: ${Starter.UUC.Accuracy}, Time:${Starter.UUC.Time}"$)
|
||||
' Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Enviamos UUC - Acc: ${Starter.UUC.Accuracy}, Time:${Starter.UUC.Time}', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
Subs.mandaLocAServer(Starter.UUC, Starter.devModel)
|
||||
FirebaseMessaging.locRequest = "Activa"
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc", Starter.UUC)
|
||||
If Starter.logger Then Log("Mandamos GetLastKnownLocation : "&DateTime.Time(flp.GetLastKnownLocation.Time))
|
||||
If Starter.logger Then Log($"UUC: ${Starter.UUC.Latitude},${Starter.UUC.Longitude}"$)
|
||||
Sub CreateLocationRequest2(interval0 As Int, displacement0 As Int) As LocationRequest 'ignore
|
||||
' Log("CreateLocationRequestSmall")
|
||||
Dim lr As LocationRequest
|
||||
lr.Initialize
|
||||
lr.SetInterval(interval0) 'Intervalo deseado para actualizaciones de ubicacion en milisegundos
|
||||
lr.SetFastestInterval(lr.GetInterval / 2) 'Intervalo minimo para actualizaciones de ubicacion
|
||||
lr.SetSmallestDisplacement(displacement0) 'Solo registra cambio de ubicacion si es mayor a XX mts
|
||||
lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY)
|
||||
Return lr
|
||||
End Sub
|
||||
|
||||
Public Sub StopFLP
|
||||
'Log("StopFLP")
|
||||
If Starter.logger Then Log("StopFLP")
|
||||
If flpStarted Then
|
||||
flp.RemoveLocationUpdates 'Eliminamos todas las solicitudes de ubicacion
|
||||
flpStarted = False
|
||||
@@ -156,35 +151,39 @@ Public Sub StopFLP
|
||||
End Sub
|
||||
|
||||
Sub flp_LocationChanged (Location1 As Location)
|
||||
' Starter.FLPStatus = "Location changed" : LogColor("Location changed", Colors.blue)
|
||||
LogColor($"Location Changed - Acc: ${Location1.Accuracy}"$, Colors.blue)
|
||||
Dim el_texto As String = ""
|
||||
Starter.UUC = Location1
|
||||
If Not(Starter.Timer1.Enabled) Then
|
||||
Starter.Timer1.Enabled = True
|
||||
Log("FLP - Timer Enabled")
|
||||
End If
|
||||
flp.RequestLocationUpdates(CreateLocationRequest)
|
||||
If Starter.logger Then LogColor("FLP_LocationChanged", Colors.Red)
|
||||
' ToastMessageShow("FLP_LocationChanged", False)
|
||||
Main.laUbicacion = Location1
|
||||
' ToastMessageShow(coords, False)
|
||||
' Log("Mandamos Ubicacion")
|
||||
If Starter.logger Then Log(FirebaseMessaging.locRequest)
|
||||
If Starter.logger Then Log(Location1)
|
||||
If Starter.logger Then Log(Location1.Accuracy&" - "&Location1.AccuracyValid)
|
||||
' solo mandamos la ubicacion si la precision es dentro de XX mts
|
||||
el_texto = $"LocChange - Coords NO enviadas (Acc:${Location1.Accuracy})."$
|
||||
'Solo mandamos la ubicacion si la precision es dentro de XX mts
|
||||
If Location1.Accuracy < minAccuracy Then
|
||||
Subs.mandaLocAServer(Location1, Starter.devModel)
|
||||
FirebaseMessaging.locRequest = "Activa"
|
||||
CallSubDelayed2(FirebaseMessaging,"mandamosLoc", Location1)
|
||||
Subs.mandaLoc2(Location1, Starter.devModel)
|
||||
el_texto = $"LocChange - Coords enviadas (Acc:${Location1.Accuracy})."$
|
||||
End If
|
||||
If Starter.logger Then Log("Loc changed : "&Location1.Latitude&","&Location1.Longitude&"|"&Starter.devModel&"|")
|
||||
Subs.gps_hist.ExecNonQuery("CREATE TABLE IF NOT EXISTS BITACORA(RUTA TEXT, TEXTO TEXT, FECHA TEXT)")
|
||||
' If Starter.logger Then Log("Loc changed : "&Location1.Latitude&","&Location1.Longitude&"|"&Starter.devModel&"|")
|
||||
Subs.bitacora($"${el_texto}"$)
|
||||
ToastMessageShow(el_texto, False)
|
||||
' Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', '${el_texto}', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
CallSubDelayed(Main, "ponCoords")
|
||||
End Sub
|
||||
|
||||
Sub flp_ConnectionSuspended(SuspendedCause1 As Int)
|
||||
Dim Cause As String
|
||||
Log("ConnectionSuspended")
|
||||
Subs.bitacora("ConnectionSuspended")
|
||||
If(SuspendedCause1=flp.SuspendedCause.CAUSE_NETWORK_LOST) Then
|
||||
Cause="Suspended by NetworkLost"
|
||||
Else If(SuspendedCause1=flp.SuspendedCause.CAUSE_SERVICE_DISCONNECTED) Then
|
||||
Cause="Suspended by Disconnected"
|
||||
Else
|
||||
Cause="Suspended: Unknow cause"
|
||||
End If
|
||||
Cause = Cause&": "& Subs.fechaNormal(DateTime.Now)
|
||||
LogColor(Cause, Colors.magenta)
|
||||
Subs.bitacora(Cause)
|
||||
flp.Disconnect
|
||||
Sleep(5000)
|
||||
flp.Connect
|
||||
End Sub
|
||||
|
||||
Sub Service_Destroy
|
||||
@@ -194,5 +193,4 @@ Sub Service_Destroy
|
||||
Tracking = False
|
||||
lock.ReleasePartialLock
|
||||
Subs.bitacora($"Tracker - Service_Destroy"$)
|
||||
' Subs.gps_hist.ExecNonQuery($"insert into BITACORA (RUTA, TEXTO, FECHA) values ('${Starter.devModel}', 'Tracker - Service_Destroy', '${Subs.fechaKMT(DateTime.now)}')"$)
|
||||
End Sub
|
||||
|
||||
Reference in New Issue
Block a user