mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-05-18 14:34:12 +02:00
feat(connector): add basic XPC connection
This commit is contained in:
parent
2411413d0c
commit
601a869200
@ -85,8 +85,8 @@ class SimulatorStatus {
|
||||
/**
|
||||
* Purely for testing
|
||||
*/
|
||||
private suspend fun loadSimulator(viewModel: InterfaceState) {
|
||||
delay(1000)
|
||||
viewModel.simConnection = !viewModel.simConnection
|
||||
private fun loadSimulator(viewModel: InterfaceState) {
|
||||
val xpc = XPC()
|
||||
viewModel.simConnection = xpc.connected()
|
||||
}
|
||||
}
|
||||
|
27
connector/shared/src/commonMain/kotlin/XPC.kt
Normal file
27
connector/shared/src/commonMain/kotlin/XPC.kt
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user