From 85ca7b11f4ae66e6b0a4839b0e8c70b1a217f733 Mon Sep 17 00:00:00 2001 From: Anthony Berg Date: Thu, 9 May 2024 07:59:25 +0100 Subject: [PATCH] fix(connector): vdm type errors --- .../src/commonMain/resources/checklist.vdmsl | 1 + .../io/anthonyberg/connector/shared/vdmj/VDMJ.kt | 6 +++--- .../connector/shared/vdmj/VDMJTransaction.kt | 13 ++++++++++++- .../connector/shared/vdmj/type/Aircraft.kt | 4 ++-- .../connector/shared/vdmj/type/ProcedureItem.kt | 16 +++++++++++++++- 5 files changed, 33 insertions(+), 7 deletions(-) create mode 120000 connector/composeApp/src/commonMain/resources/checklist.vdmsl diff --git a/connector/composeApp/src/commonMain/resources/checklist.vdmsl b/connector/composeApp/src/commonMain/resources/checklist.vdmsl new file mode 120000 index 0000000..e88e4d5 --- /dev/null +++ b/connector/composeApp/src/commonMain/resources/checklist.vdmsl @@ -0,0 +1 @@ +../../../../../formal/checklist.vdmsl \ No newline at end of file diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJ.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJ.kt index 6f562fe..8575bc2 100644 --- a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJ.kt +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJ.kt @@ -57,7 +57,7 @@ class VDMJ { * Creates VDMJ Lifecycle with interpreter mode */ private fun createLifecycle(): Lifecycle { - val vdmPath = Paths.get("src/main/resources/checklist.vdmsl") + val vdmPath = Paths.get("src/commonMain/resources/checklist.vdmsl") // Creates the arguments for VDMJ - i.e. where the file is located val vdmArgs = arrayOf(vdmPath.pathString, "-vdmsl", "-i", "-q") @@ -94,8 +94,8 @@ class VDMJ { var output = byteArrayOutputStream.toString() - while(!this::exitStatus.isInitialized and output.isEmpty()) { - delay(10) + while(!this::exitStatus.isInitialized and (output.isEmpty() or (output.length <=2))) { + delay(100) // Convert the captured output to a string output = byteArrayOutputStream.toString() diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJTransaction.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJTransaction.kt index 8bdab9f..bce4661 100644 --- a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJTransaction.kt +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/VDMJTransaction.kt @@ -15,6 +15,7 @@ class VDMJTransaction(val actions: List, private val xpc: XPC) { private val drefs: Array = actions.map { it.type }.toTypedArray() private var aircraft: Aircraft + private var step = 1 init { // Check X-Plane is running @@ -37,10 +38,20 @@ class VDMJTransaction(val actions: List, private val xpc: XPC) { aircraft = Aircraft(items = items, procedure = procedures) } - fun nextStep() { + suspend fun expectedEndState(): String { + val command = "p complete_procedure(${aircraft.toVDMString()})" + println(command) + + val result = vdmj.run(command = command) + + return result.output } +// fun nextStep() { +// val command = "do_proc_item(" +// } + /** * Gets the state of all the DREFs in X-Plane for [Aircraft.items] * diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/type/Aircraft.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/type/Aircraft.kt index 33d0b12..b69252a 100644 --- a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/type/Aircraft.kt +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/type/Aircraft.kt @@ -37,7 +37,7 @@ data class Aircraft( } // Removes the last comma in the VDM map as it will error otherwise - output.dropLast(1) + output = output.dropLast(1) output += "}" @@ -58,7 +58,7 @@ data class Aircraft( } // Removes the last comma in the VDM sequence as it will error otherwise - output.dropLast(1) + output = output.dropLast(1) output += "]" diff --git a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/type/ProcedureItem.kt b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/type/ProcedureItem.kt index b960942..5900738 100644 --- a/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/type/ProcedureItem.kt +++ b/connector/shared/src/commonMain/kotlin/io/anthonyberg/connector/shared/vdmj/type/ProcedureItem.kt @@ -12,6 +12,20 @@ data class ProcedureItem( * @return String record for VDM ChecklistItem */ fun toVDMString(): String { - return "mk_ChecklistItem(\"$dref\", ${type.toVDMString()}, $goal, $complete)" + return "mk_ChecklistItem(\"$dref\", ${type.toVDMString()}, ${getSwitchState()}, $complete)" + } + + /** + * Gets the VDM object for the switch state + * + * @return String representation for switch state + */ + private fun getSwitchState(): String { + return when (goal) { + 0 -> "" + 1 -> "" // TODO add middle button + 2 -> "" + else -> throw IllegalArgumentException("Position must be between 0 and 2") + } } }