mirror of
https://github.com/cheveguerra/FLP_2.0.git
synced 2026-04-17 19:36:42 +00:00
Commit inicial
This commit is contained in:
188
Subs.bas
Normal file
188
Subs.bas
Normal file
@@ -0,0 +1,188 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=StaticCode
|
||||
Version=11
|
||||
@EndOfDesignText@
|
||||
'Code module
|
||||
'Subs in this code module will be accessible from all modules.
|
||||
Sub Process_Globals
|
||||
'These global variables will be declared once when the application starts.
|
||||
'These variables can be accessed from all modules.
|
||||
Public GZip As GZipStrings
|
||||
Private su As StringUtils
|
||||
Dim phn As Phone
|
||||
Dim devModel As String
|
||||
Dim gps_hist As SQL
|
||||
Dim wifi As MLwifi
|
||||
Dim ssid As String
|
||||
End Sub
|
||||
|
||||
Sub getPhnId 'Pone el valor de phn.Model en la variable global "devModel"
|
||||
Private elId As String
|
||||
If File.Exists(File.DirInternal, "phnId.txt") Then
|
||||
elId = File.ReadString(File.DirInternal, "phnId.txt")
|
||||
Else
|
||||
File.WriteString(File.DirInternal, "phnId.txt", "") 'Creamos el archivo
|
||||
End If
|
||||
If elId.Length < 3 Then 'Si el modelo del archivo es menos de 2, lo sustituimos con devmodel
|
||||
devModel = phn.Model
|
||||
If devModel.Length > 1 Then elId = devModel
|
||||
End If
|
||||
If elId.Length < 3 Then 'Si el modelo del archivo es menos de 2, lo sustituimos con android_id
|
||||
elId = phn.GetSettings("android_id") 'Intentamos con "android_id"
|
||||
End If
|
||||
If elId.Length < 3 Then elId = $"dev${DateTime.GetHour(DateTime.Now)}"$
|
||||
File.WriteString(File.DirInternal, "phnId.txt", elId) 'Sobreescribimos archivo phnId.txt with elId
|
||||
If Starter.logger Then Log("Escribimos phnId: "&elId&" a "&File.DirInternal&"/phnId.txt")
|
||||
Starter.devModel = elId
|
||||
If Starter.logger Then Log(Starter.devModel)
|
||||
End Sub
|
||||
|
||||
Sub compress(str As String) As String ' Compresion
|
||||
Dim compressed() As Byte = GZip.compress(str)
|
||||
Log($"CompressedBytesLength: ${compressed.Length}"$)
|
||||
Dim base64 As String = su.EncodeBase64(compressed)
|
||||
Log($"CompressedBytes converted to base64 Length: ${base64.Length}"$)
|
||||
Log($"CompressedBytes converted to base64: ${base64}"$)
|
||||
Return base64
|
||||
End Sub
|
||||
|
||||
Sub decompress(base64 As String) As String ' Descompresion 'ignore
|
||||
Dim decompressedbytes() As Byte = su.DecodeBase64(base64)
|
||||
Log($"decompressedbytesLength: ${decompressedbytes.Length}"$)
|
||||
Dim bc As ByteConverter
|
||||
Dim uncompressed As String = bc.StringFromBytes(decompressedbytes,"UTF8")
|
||||
Log($"uncompressedLength: ${uncompressed.Length}"$)
|
||||
Log($"Decompressed String = ${uncompressed}"$)
|
||||
Return uncompressed
|
||||
End Sub
|
||||
|
||||
Sub formatoFecha(fecha As String) As String 'Convierte una fecha al formato yyMMddHHmmss
|
||||
' Log(fecha)
|
||||
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
|
||||
DateTime.DateFormat="yyMMddHHmmss"
|
||||
Dim lastUpdate As String=DateTime.Date(fecha)
|
||||
DateTime.DateFormat=OrigFormat 'return to orig date format
|
||||
' Log(lastUpdate)
|
||||
Return lastUpdate
|
||||
End Sub
|
||||
|
||||
Sub CreateNotification (Body As String) As Notification
|
||||
Dim notification As Notification
|
||||
notification.Initialize2(notification.IMPORTANCE_LOW)
|
||||
notification.Icon = "icon"
|
||||
notification.SetInfo("FLP", Body, Main)
|
||||
Return notification
|
||||
End Sub
|
||||
|
||||
Sub guardaInfoEnArchivo(coords As String) 'Escribimos coordenadas y fecha a un archivo de texto 'ignore
|
||||
' Cambiamos el formato de la hora
|
||||
Dim OrigFormat As String=DateTime.DateFormat 'save orig date format
|
||||
DateTime.DateFormat="MMM-dd HH:mm:ss"
|
||||
Dim lastUpdate As String=DateTime.Date(DateTime.Now)
|
||||
DateTime.DateFormat=OrigFormat 'return to orig date format
|
||||
|
||||
Dim ubic As String = coords&","&lastUpdate
|
||||
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "gps.txt", True)
|
||||
Dim s As String = ubic & CRLF
|
||||
Dim t() As Byte = s.GetBytes("UTF-8")
|
||||
out.WriteBytes(t, 0, t.Length)
|
||||
out.Close
|
||||
End Sub
|
||||
|
||||
Sub guardaInfoEnBD(coords As String) 'Escribimos coordenadas y fecha a una BD
|
||||
If Starter.logger Then Log("Guardamos ubicacion en db (" & coords & ")")
|
||||
Dim latlon() As String = Regex.Split(",", coords)
|
||||
If gps_hist.IsInitialized = False Then gps_hist.Initialize(Starter.ruta, "gps_hist.db", True)
|
||||
gps_hist.ExecNonQuery2("INSERT INTO RUTA_GPS(fecha, lat, lon) VALUES (?,?,?)", Array As Object (latlon(2),latlon(0),latlon(1)))
|
||||
End Sub
|
||||
|
||||
Sub dameRuta As String
|
||||
Dim c As Cursor
|
||||
If gps_hist.IsInitialized = False Then gps_hist.Initialize(Starter.ruta, "gps_hist.db", True)
|
||||
c = gps_hist.ExecQuery("select FECHA, LAT, LON from RUTA_GPS order by FECHA desc limit 380")
|
||||
c.Position = 0
|
||||
Dim ruta2 As String = ""
|
||||
If c.RowCount>0 Then
|
||||
For i=0 To c.RowCount -1
|
||||
c.Position=i
|
||||
ruta2=ruta2&CRLF&c.GetString("LAT")&","&c.GetString("LON")
|
||||
Main.fechaRuta = c.GetString("FECHA")
|
||||
Next
|
||||
End If
|
||||
c.Close
|
||||
Return compress(ruta2)
|
||||
End Sub
|
||||
|
||||
Sub deleteGPS_DB
|
||||
' gps_hist.ExecQuery
|
||||
gps_hist.ExecNonQuery("delete from RUTA_GPS")
|
||||
gps_hist.ExecNonQuery("vacuum;")
|
||||
Log("RUTA_GPS borrada")
|
||||
End Sub
|
||||
|
||||
Sub borramosArchivoGPS
|
||||
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "gps.txt", False)
|
||||
Dim s As String = ""
|
||||
Dim t() As Byte = s.GetBytes("UTF-8")
|
||||
out.WriteBytes(t, 0, t.Length)
|
||||
out.Close
|
||||
End Sub
|
||||
|
||||
Sub revisaBD
|
||||
' Starter.ruta = File.DirInternal
|
||||
If File.Exists(Starter.ruta, "gps_hist.db") = False Then
|
||||
File.Copy(File.DirAssets, "gps_hist.db", Starter.ruta, "gps_hist.db")
|
||||
Log("No existe gps_hist, copiamos gps_hist.db")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub getSSID
|
||||
If wifi.isWifiConnected Then
|
||||
ssid = wifi.WifiSSID
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Convierte una fecha al formato yyMMddHHmmss
|
||||
Sub fechaKMT(fecha As String) As String 'ignore
|
||||
' Log(fecha)
|
||||
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
|
||||
DateTime.DateFormat="yyMMddHHmmss"
|
||||
Dim nuevaFecha As String=DateTime.Date(fecha)
|
||||
DateTime.DateFormat=OrigFormat 'return to orig date format
|
||||
' Log(nuevaFecha)
|
||||
Return nuevaFecha
|
||||
End Sub
|
||||
|
||||
'Sub dameUltimaUbicacionConocida(lastLocation As Location)
|
||||
' Log(0)
|
||||
' If Tracker.FLP.GetLastKnownLocation.IsInitialized Then 'Mandamos ultima ubicacion guardada
|
||||
' Log("dameUltimaUbicacionConocida")
|
||||
' If Tracker.FLP.GetLastKnownLocation.Accuracy < 30 And Tracker.FLP.GetLastKnownLocation.DistanceTo(lastLocation) > 50 Then
|
||||
' Starter.UUC = Tracker.FLP.GetLastKnownLocation
|
||||
' mandaLocAServer(Tracker.FLP.GetLastKnownLocation, Starter.devModel)
|
||||
' Log($"UUC: ${Starter.UUC.Latitude},${Starter.UUC.Longitude}"$)
|
||||
' End If
|
||||
' End If
|
||||
'End Sub
|
||||
|
||||
Sub mandaLocAServer(loc As Location, id As String)
|
||||
Starter.lastLocUpdate = DateTime.Now
|
||||
CallSubDelayed(Main, "actualizaLabelUU")
|
||||
Starter.cmd.Initialize
|
||||
Starter.cmd.Name = "guardaDatos"
|
||||
Starter.cmd.Parameters = Array As Object(fechaKMT(DateTime.Now), id, fechaKMT(DateTime.Now), $"${loc.Latitude},${loc.Longitude},${loc.Accuracy},${loc.AccuracyValid},${loc.Speed},${loc.SpeedValid}"$, "Coords")
|
||||
' If Starter.logger Then
|
||||
Log($"Mandamos loc a server: ${fechaKMT(DateTime.Now)}|${id}|${fechaKMT(DateTime.Now)}|${loc.Latitude},${loc.Longitude}|Coords"$)
|
||||
' End If
|
||||
Starter.reqManager.ExecuteCommand(Starter.cmd,"guardaDatos")
|
||||
End Sub
|
||||
|
||||
Sub ConvertMillisecondsToString(t As Long) As String
|
||||
Dim hours, minutes, seconds As Int
|
||||
hours = t / DateTime.TicksPerHour
|
||||
minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
|
||||
seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
|
||||
Return $"$1.0{hours}:$2.0{minutes}:$2.0{seconds}"$
|
||||
End Sub
|
||||
Reference in New Issue
Block a user