Skip to content

Commit

Permalink
Location: add SNCF/Ouigo location lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
valerierx committed Nov 26, 2023
1 parent 891503f commit f61f9ee
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,29 @@ class MovingWifiHelper(private val context: Context) {
}
return location
}

private fun parseSncf(location: Location, data: ByteArray): Location {
val json = JSONObject(data.decodeToString())
if(json.getInt("fix") == -1) { // no fix
return location
}
location.accuracy = 100f
location.latitude = json.getDouble("latitude")
location.longitude = json.getDouble("longitude")

json.optDouble("speed").takeIf { !it.isNaN() }?.let {
location.speed = it.toFloat()
LocationCompat.setSpeedAccuracyMetersPerSecond(location, location.speed * 0.1f)
}

location.time = json.getLong("timestamp")
json.optDouble("heading").takeIf { !it.isNaN() }?.let {
location.bearing = it.toFloat()
LocationCompat.setBearingAccuracyDegrees(location, 90f)
}
return location

}

private fun parseInput(ssid: String, data: ByteArray): Location {
val location = Location(ssid)
Expand All @@ -223,6 +246,10 @@ class MovingWifiHelper(private val context: Context) {
"AegeanWiFi" -> parseDisplayUgo(location, data)
"Cathay Pacific", "Telekom_FlyNet" -> parsePanasonic(location, data)
"FlyNet" -> parseBoardConnect(location, data)
"OUIFI" -> parseSncf(location, data)
"_SNCF_WIFI_INOUI" -> parseSncf(location, data)
"_SNCF_WIFI_INTERCITES" -> parseSncf(location, data)
"NormandieTrainConnecte" -> parseSncf(location, data)
else -> throw UnsupportedOperationException()
}
}
Expand All @@ -242,6 +269,10 @@ class MovingWifiHelper(private val context: Context) {
"Cathay Pacific" to "https://services.inflightpanasonic.aero/inflight/services/flightdata/v2/flightdata",
"FlyNet" to "https://ww2.lufthansa-flynet.com/map/api/flightData",
"CDWiFi" to "http://cdwifi.cz/portal/api/vehicle/realtime",
"OUIFI" to "https://ouifi.ouigo.com:8084/api/gps",
"_SNCF_WIFI_INOUI" to "https://wifi.sncf/router/api/train/gps",
"_SNCF_WIFI_INTERCITES" to "https://wifi.intercites.sncf/router/api/train/gps",
"NormandieTrainConnecte" to "https://wifi.normandie.fr/router/api/train/gps",
)
}
}
Expand Down

0 comments on commit f61f9ee

Please sign in to comment.