mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-11-30 01:39:38 +01:00
feat(connector): add basic XPC connection
This commit is contained in:
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user