fix(connector): vdm type errors

This commit is contained in:
Anthony Berg 2024-05-09 07:59:25 +01:00
parent 3e31294b27
commit 85ca7b11f4
5 changed files with 33 additions and 7 deletions

View File

@ -0,0 +1 @@
../../../../../formal/checklist.vdmsl

View File

@ -57,7 +57,7 @@ class VDMJ {
* Creates VDMJ Lifecycle with interpreter mode * Creates VDMJ Lifecycle with interpreter mode
*/ */
private fun createLifecycle(): Lifecycle { 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 // Creates the arguments for VDMJ - i.e. where the file is located
val vdmArgs = arrayOf(vdmPath.pathString, "-vdmsl", "-i", "-q") val vdmArgs = arrayOf(vdmPath.pathString, "-vdmsl", "-i", "-q")
@ -94,8 +94,8 @@ class VDMJ {
var output = byteArrayOutputStream.toString() var output = byteArrayOutputStream.toString()
while(!this::exitStatus.isInitialized and output.isEmpty()) { while(!this::exitStatus.isInitialized and (output.isEmpty() or (output.length <=2))) {
delay(10) delay(100)
// Convert the captured output to a string // Convert the captured output to a string
output = byteArrayOutputStream.toString() output = byteArrayOutputStream.toString()

View File

@ -15,6 +15,7 @@ class VDMJTransaction(val actions: List<Action>, private val xpc: XPC) {
private val drefs: Array<String> = actions.map { it.type }.toTypedArray() private val drefs: Array<String> = actions.map { it.type }.toTypedArray()
private var aircraft: Aircraft private var aircraft: Aircraft
private var step = 1
init { init {
// Check X-Plane is running // Check X-Plane is running
@ -37,10 +38,20 @@ class VDMJTransaction(val actions: List<Action>, private val xpc: XPC) {
aircraft = Aircraft(items = items, procedure = procedures) 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] * Gets the state of all the DREFs in X-Plane for [Aircraft.items]
* *

View File

@ -37,7 +37,7 @@ data class Aircraft(
} }
// Removes the last comma in the VDM map as it will error otherwise // Removes the last comma in the VDM map as it will error otherwise
output.dropLast(1) output = output.dropLast(1)
output += "}" output += "}"
@ -58,7 +58,7 @@ data class Aircraft(
} }
// Removes the last comma in the VDM sequence as it will error otherwise // Removes the last comma in the VDM sequence as it will error otherwise
output.dropLast(1) output = output.dropLast(1)
output += "]" output += "]"

View File

@ -12,6 +12,20 @@ data class ProcedureItem(
* @return String record for VDM ChecklistItem * @return String record for VDM ChecklistItem
*/ */
fun toVDMString(): String { 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 -> "<OFF>"
1 -> "<ON>" // TODO add middle button
2 -> "<ON>"
else -> throw IllegalArgumentException("Position must be between 0 and 2")
}
} }
} }