mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
serialhelper get device status
This commit is contained in:
@@ -57,7 +57,7 @@ Description: reads status of the device, if applicable
|
||||
Returns:
|
||||
0x06 <status code> <0x1F> <message string> 0x17
|
||||
0x15 <status code> <0x1F> <message string> 0x17
|
||||
(see section 1.0)
|
||||
Status Code is single byte number. Also see section 1.0
|
||||
|
||||
2. Device-specific commands
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class VmFilesystemDelegate(val vm: VM, val portNo: Int) {
|
||||
|
||||
}
|
||||
|
||||
class DiskDriveFileInputStream(vm: VM, portNo: Int, path: String) : InputStream() {
|
||||
class DiskDriveFileInputStream(val vm: VM, val portNo: Int, val path: String) : InputStream() {
|
||||
|
||||
private val contents: ByteArray
|
||||
private var readCursor = 0
|
||||
@@ -60,7 +60,7 @@ class DiskDriveFileInputStream(vm: VM, portNo: Int, path: String) : InputStream(
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
TODO()
|
||||
SerialHelper.sendMessage(vm, portNo, "CLOSE".toByteArray(VM.CHARSET))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.torvald.tsvm
|
||||
import net.torvald.UnsafeHelper
|
||||
import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.toUint
|
||||
import net.torvald.tsvm.peripheral.BlockTransferInterface.Companion.BLOCK_SIZE
|
||||
import net.torvald.tsvm.peripheral.BlockTransferInterface.Companion.END_OF_SEND_BLOCK
|
||||
import java.io.ByteArrayOutputStream
|
||||
import kotlin.experimental.and
|
||||
import kotlin.experimental.or
|
||||
@@ -52,6 +53,15 @@ object SerialHelper {
|
||||
return msgBuffer.toByteArray()
|
||||
}
|
||||
|
||||
fun getDeviceStatus(vm: VM, portNo: Int): DeviceStatus {
|
||||
val msgStr = sendMessageGetBytes(vm, portNo, "DEVSTU$END_OF_SEND_BLOCK".toByteArray(VM.CHARSET))
|
||||
return DeviceStatus(
|
||||
msgStr[0] == 0x06.toByte(),
|
||||
msgStr[1].toUint(),
|
||||
msgStr.sliceArray(3 until msgStr.size - 1).toString(VM.CHARSET)
|
||||
)
|
||||
}
|
||||
|
||||
fun waitUntilReady(vm: VM, portNo: Int) {
|
||||
while (!checkIfDeviceIsReady(vm, portNo)) { Thread.sleep(SLEEP_TIME) }
|
||||
}
|
||||
@@ -87,4 +97,6 @@ object SerialHelper {
|
||||
|
||||
|
||||
private fun Boolean.toInt() = if (this) 1 else 0
|
||||
|
||||
data class DeviceStatus(val isError: Boolean, val code: Int, val message: String)
|
||||
}
|
||||
@@ -12,6 +12,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
const val STATE_CODE_STANDBY = 0
|
||||
const val STATE_CODE_ILLEGAL_COMMAND = 128
|
||||
const val STATE_CODE_FILE_NOT_FOUND = 129
|
||||
const val STATE_CODE_FILE_ALREADY_OPENED = 130
|
||||
const val STATE_CODE_SYSTEM_IO_ERROR = 192
|
||||
|
||||
|
||||
@@ -21,6 +22,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
errorMsgs[STATE_CODE_STANDBY] = "READY"
|
||||
errorMsgs[STATE_CODE_ILLEGAL_COMMAND] = "SYNTAX ERROR"
|
||||
errorMsgs[STATE_CODE_FILE_NOT_FOUND] = "FILE NOT FOUND"
|
||||
errorMsgs[STATE_CODE_FILE_ALREADY_OPENED] = "FILE ALREADY OPENED"
|
||||
errorMsgs[STATE_CODE_SYSTEM_IO_ERROR] = "IO ERROR ON SIMULATED DRIVE"
|
||||
}
|
||||
}
|
||||
@@ -139,6 +141,10 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
//startSend { it.writeout(composePositiveAns("Testtec Virtual Disk Drive")) }
|
||||
recipient?.writeout(composePositiveAns("Testtec Virtual Disk Drive"))
|
||||
else if (inputString.startsWith("OPENR\"") || inputString.startsWith("OPENW\"") || inputString.startsWith("OPENA\"")) {
|
||||
if (file != null) {
|
||||
stateCode = STATE_CODE_FILE_ALREADY_OPENED
|
||||
return
|
||||
}
|
||||
|
||||
val openMode = inputString[4]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user