Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ Replace ```lat``` and ```lon``` with your location, and it will display all ADSB

### Advanced usage
```
java -jar MavADSB.jar lat lon radius interval
java -jar MavADSB.jar [-q] lat lon radius interval
```

Replace ```radius``` with the polling radius around ```lat,lon``` (up to 250) in nautical miles. Optional

Replace ```interval``` with the polling interval in milliseconds (minimum 1000) in milliseconds. Optional

Include ```-q``` (dash lower case letter Q) anywhere on the command line to suppress most messages. Optional

### Mission Planner integration
After running the Jar file, please open Mission Planner and go to config tab -> Planner and look for the "Adsb" checkbox. Enable this and restart Mission Planner

Expand Down
15 changes: 9 additions & 6 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ private const val BASE_URL = "https://api.adsb.one/v2/"
private val server: SBSServer = SBSServer()
private var radius = 250
private var polling_delay = 1000L
private var quiet = false

fun main(args: Array<String>) {
val lat = args[0]
val lon = args[1]
if (args.size > 2) radius = 250.coerceAtMost((args[2].toIntOrNull() ?: radius))
if (args.size > 3) polling_delay = 1000L.coerceAtLeast(args[3].toLongOrNull() ?: polling_delay)
val positional_args = args.dropWhile { it == "-q" }.toTypedArray()
(positional_args.size < args.size).also { quiet = it }
val lat = positional_args[0]
val lon = positional_args[1]
if (positional_args.size > 2) radius = 250.coerceAtMost((positional_args[2].toIntOrNull() ?: radius))
if (positional_args.size > 3) polling_delay = 1000L.coerceAtLeast(positional_args[3].toLongOrNull() ?: polling_delay)
println("Querying ADSB ${radius}nm around ($lat, $lon) every ${polling_delay}ms")
server.start()
val client = OkHttpClient()
val request = Request.Builder().url("${BASE_URL}point/$lat/$lon/$radius").build()
Timer().schedule(object : TimerTask() {
override fun run() {
try {
if (server.clients.isNotEmpty()) client.newCall(request).execute().body?.let { server.sendData(Gson().fromJson(it.string(), ADSBData::class.java)) }
if (server.clients.isNotEmpty()) client.newCall(request).execute().body?.let { server.sendData(Gson().fromJson(it.string(), ADSBData::class.java), quiet) }
} catch (e: Exception) {
println("Failed to query ADSB data: ${e.message}")
if (!quiet) println("Failed to query ADSB data: ${e.message}")
}
}
}, 0, polling_delay)
Expand Down
13 changes: 8 additions & 5 deletions src/main/kotlin/SBSServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SBSServer {
}.start()
}

fun sendData(data: ADSBData) {
fun sendData(data: ADSBData, quiet: Boolean) {
Thread {
val iterator = clients.iterator()
while (iterator.hasNext()) {
Expand All @@ -34,7 +34,8 @@ class SBSServer {
altitude = ac.getAltitude(),
lat = ac.lat,
lon = ac.lon,
squawk = ac.squawk
squawk = ac.squawk,
quiet = quiet
)
)
writer.println(
Expand All @@ -44,7 +45,8 @@ class SBSServer {
flightId = ac.getFlight(),
groundSpeed = ac.gs,
track = ac.track,
squawk = ac.squawk
squawk = ac.squawk,
quiet = quiet
)
)
writer.flush()
Expand Down Expand Up @@ -74,7 +76,8 @@ class SBSServer {
track: Double = 0.0,
lat: Double = 0.0,
lon: Double = 0.0,
squawk: String = ""
squawk: String = "",
quiet: Boolean = false
): String {
val builder = StringBuilder()
// The below basic data fields are standard for all messages (Field 2 used only for MSG)
Expand Down Expand Up @@ -103,7 +106,7 @@ class SBSServer {
builder.append("0") // isOnGround

val message = builder.toString()
println(message)
if (!quiet) println(message)
return message
}

Expand Down