feat(connector): add basic XPC connection

This commit is contained in:
Anthony Berg 2024-04-20 11:00:32 +01:00
parent 2411413d0c
commit 601a869200
2 changed files with 30 additions and 3 deletions

View File

@ -85,8 +85,8 @@ class SimulatorStatus {
/** /**
* Purely for testing * Purely for testing
*/ */
private suspend fun loadSimulator(viewModel: InterfaceState) { private fun loadSimulator(viewModel: InterfaceState) {
delay(1000) val xpc = XPC()
viewModel.simConnection = !viewModel.simConnection viewModel.simConnection = xpc.connected()
} }
} }

View File

@ -0,0 +1,27 @@
import gov.nasa.xpc.XPlaneConnect
import io.ktor.utils.io.errors.*
import java.net.SocketException
class XPC {
private lateinit var xpc: XPlaneConnect
/**
* Connects to the X-Plane and tests the connection
*
* @return `true` if connection successfully established, `false` otherwise
*/
fun connected(): Boolean {
try {
xpc = XPlaneConnect()
// Ensure connection is established
xpc.getDREF("sim/test/test_float")
return true
} catch (ex: SocketException) {
return false
} catch (ex: IOException) {
return false
}
}
}