mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-11 07:14:04 +09:00
testdiskdrive minor fixes, working directory listing
This commit is contained in:
@@ -5,4 +5,20 @@ ba = com.pullMessage(0)
|
|||||||
serial.print(ba);
|
serial.print(ba);
|
||||||
serial.println("# END OF MSG");
|
serial.println("# END OF MSG");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ba = com.sendMessageGetBytes(1, "DEVNAM"+String.fromCharCode(0x17));
|
||||||
|
serial.println(ba);
|
||||||
|
|
||||||
|
ba = com.sendMessageGetBytes(1, "DEVSTU"+String.fromCharCode(0x17));
|
||||||
|
serial.println(ba);
|
||||||
|
|
||||||
|
ba = com.sendMessageGetBytes(1, "LIST");
|
||||||
|
ba = com.pullMessage(1);
|
||||||
|
println(ba);
|
||||||
|
|
||||||
|
ba = com.sendMessageGetBytes(1, "DEVSTU"+String.fromCharCode(0x17));
|
||||||
|
serial.println(ba);
|
||||||
|
|
||||||
|
|
||||||
serial.println("k bye")
|
serial.println("k bye")
|
||||||
@@ -75,6 +75,9 @@ abstract class BlockTransferInterface(val isMaster: Boolean, val isSlave: Boolea
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val BLOCK_SIZE = 4096
|
const val BLOCK_SIZE = 4096
|
||||||
|
|
||||||
|
// these consts are UNUSABLE on writeoutImpl because wtf
|
||||||
|
// still possible to use on stringbuilder tho
|
||||||
const val GOOD_NEWS = 0x06.toByte()
|
const val GOOD_NEWS = 0x06.toByte()
|
||||||
const val BAD_NEWS = 0x15.toByte()
|
const val BAD_NEWS = 0x15.toByte()
|
||||||
const val UNIT_SEP = 0x1F.toByte()
|
const val UNIT_SEP = 0x1F.toByte()
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
val sb = ArrayList<Byte>()
|
val sb = ArrayList<Byte>()
|
||||||
sb.add(GOOD_NEWS)
|
sb.add(GOOD_NEWS)
|
||||||
sb.addAll(msg[0].toByteArray().toTypedArray())
|
sb.addAll(msg[0].toByteArray().toTypedArray())
|
||||||
for (k in 1 until msg.lastIndex) {
|
for (k in 1 until msg.size) {
|
||||||
sb.add(UNIT_SEP)
|
sb.add(UNIT_SEP)
|
||||||
sb.addAll(msg[k].toByteArray().toTypedArray())
|
sb.addAll(msg[k].toByteArray().toTypedArray())
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
val sb = ArrayList<Byte>()
|
val sb = ArrayList<Byte>()
|
||||||
sb.add(BAD_NEWS)
|
sb.add(BAD_NEWS)
|
||||||
sb.addAll(msg[0].toByteArray().toTypedArray())
|
sb.addAll(msg[0].toByteArray().toTypedArray())
|
||||||
for (k in 1 until msg.lastIndex) {
|
for (k in 1 until msg.size) {
|
||||||
sb.add(UNIT_SEP)
|
sb.add(UNIT_SEP)
|
||||||
sb.addAll(msg[k].toByteArray().toTypedArray())
|
sb.addAll(msg[k].toByteArray().toTypedArray())
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,10 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
return sb.toByteArray()
|
return sb.toByteArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val rootPath = File("test_assets/test_drive_$driveNum")
|
||||||
|
|
||||||
private var fileOpen = false
|
private var fileOpen = false
|
||||||
private var file: File? = null
|
private var file = File(rootPath.toURI())
|
||||||
//private var readModeLength = -1 // always 4096
|
//private var readModeLength = -1 // always 4096
|
||||||
private var stateCode = STATE_CODE_STANDBY
|
private var stateCode = STATE_CODE_STANDBY
|
||||||
private var writeMode = false
|
private var writeMode = false
|
||||||
@@ -62,8 +64,6 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
private var blockSendBuffer = ByteArray(1)
|
private var blockSendBuffer = ByteArray(1)
|
||||||
private var blockSendCount = 0
|
private var blockSendCount = 0
|
||||||
|
|
||||||
private val rootPath = File("test_assets/test_drive_$driveNum")
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (!rootPath.exists()) {
|
if (!rootPath.exists()) {
|
||||||
@@ -112,18 +112,18 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
* Disk drive must create desired side effects in accordance with the input message.
|
* Disk drive must create desired side effects in accordance with the input message.
|
||||||
*/
|
*/
|
||||||
override fun writeoutImpl(inputData: ByteArray) {
|
override fun writeoutImpl(inputData: ByteArray) {
|
||||||
val inputString = inputData.toString()
|
val inputString = inputData.toString(VM.CHARSET)
|
||||||
|
|
||||||
if (inputString.startsWith("DEVRST$END_OF_SEND_BLOCK")) {
|
if (inputString.startsWith("DEVRST\u0017")) {
|
||||||
//readModeLength = -1
|
//readModeLength = -1
|
||||||
fileOpen = false
|
fileOpen = false
|
||||||
file = null
|
file = File(rootPath.toURI())
|
||||||
blockSendCount = 0
|
blockSendCount = 0
|
||||||
stateCode = STATE_CODE_STANDBY
|
stateCode = STATE_CODE_STANDBY
|
||||||
writeMode = false
|
writeMode = false
|
||||||
writeModeLength = -1
|
writeModeLength = -1
|
||||||
}
|
}
|
||||||
else if (inputString.startsWith("DEVSTU$END_OF_SEND_BLOCK")) {
|
else if (inputString.startsWith("DEVSTU\u0017")) {
|
||||||
if (stateCode < 128) {
|
if (stateCode < 128) {
|
||||||
recipient?.writeout(composePositiveAns("${stateCode.toChar()}", errorMsgs[stateCode]))
|
recipient?.writeout(composePositiveAns("${stateCode.toChar()}", errorMsgs[stateCode]))
|
||||||
}
|
}
|
||||||
@@ -131,12 +131,12 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
recipient?.writeout(composeNegativeAns("${stateCode.toChar()}", errorMsgs[stateCode]))
|
recipient?.writeout(composeNegativeAns("${stateCode.toChar()}", errorMsgs[stateCode]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (inputString.startsWith("DEVTYP$END_OF_SEND_BLOCK"))
|
else if (inputString.startsWith("DEVTYP\u0017"))
|
||||||
recipient?.writeout(composePositiveAns("STOR"))
|
recipient?.writeout(composePositiveAns("STOR"))
|
||||||
else if (inputString.startsWith("DEVNAM$END_OF_SEND_BLOCK"))
|
else if (inputString.startsWith("DEVNAM\u0017"))
|
||||||
recipient?.writeout(composePositiveAns("Testtec Virtual Disk Drive"))
|
recipient?.writeout(composePositiveAns("Testtec Virtual Disk Drive"))
|
||||||
else if (inputString.startsWith("OPENR\"") || inputString.startsWith("OPENW\"") || inputString.startsWith("OPENA\"")) {
|
else if (inputString.startsWith("OPENR\"") || inputString.startsWith("OPENW\"") || inputString.startsWith("OPENA\"")) {
|
||||||
if (file != null) {
|
if (fileOpen) {
|
||||||
stateCode = STATE_CODE_FILE_ALREADY_OPENED
|
stateCode = STATE_CODE_FILE_ALREADY_OPENED
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
|
|
||||||
file = File(rootPath, filePath)
|
file = File(rootPath, filePath)
|
||||||
|
|
||||||
if (openMode == 'R' && !file!!.exists()) {
|
if (openMode == 'R' && !file.exists()) {
|
||||||
stateCode = STATE_CODE_FILE_NOT_FOUND
|
stateCode = STATE_CODE_FILE_NOT_FOUND
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -167,18 +167,19 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
// temporary behaviour to ignore any arguments
|
// temporary behaviour to ignore any arguments
|
||||||
resetBuf()
|
resetBuf()
|
||||||
messageComposeBuffer.write(getReadableLs().toByteArray(VM.CHARSET))
|
messageComposeBuffer.write(getReadableLs().toByteArray(VM.CHARSET))
|
||||||
|
stateCode = STATE_CODE_STANDBY
|
||||||
}
|
}
|
||||||
else if (inputString.startsWith("CLOSE")) {
|
else if (inputString.startsWith("CLOSE")) {
|
||||||
file = null
|
|
||||||
fileOpen = false
|
fileOpen = false
|
||||||
|
stateCode = STATE_CODE_STANDBY
|
||||||
}
|
}
|
||||||
else if (inputString.startsWith("READ")) {
|
else if (inputString.startsWith("READ")) {
|
||||||
//readModeLength = inputString.substring(4 until inputString.length).toInt()
|
//readModeLength = inputString.substring(4 until inputString.length).toInt()
|
||||||
|
|
||||||
resetBuf()
|
resetBuf()
|
||||||
if (file?.isFile == true) {
|
if (file.isFile) {
|
||||||
try {
|
try {
|
||||||
messageComposeBuffer.write(file!!.readBytes())
|
messageComposeBuffer.write(file.readBytes())
|
||||||
stateCode = STATE_CODE_STANDBY
|
stateCode = STATE_CODE_STANDBY
|
||||||
}
|
}
|
||||||
catch (e: IOException) {
|
catch (e: IOException) {
|
||||||
@@ -191,26 +192,35 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
|||||||
val diskID: UUID = UUID(0, 0)
|
val diskID: UUID = UUID(0, 0)
|
||||||
|
|
||||||
private fun getReadableLs(): String {
|
private fun getReadableLs(): String {
|
||||||
if (file == null) throw IllegalStateException("No file is opened")
|
|
||||||
|
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
|
val isRoot = (file.absolutePath == rootPath.absolutePath)
|
||||||
|
|
||||||
if (file!!.isFile) sb.append(file!!.name)
|
if (file.isFile) sb.append(file.name)
|
||||||
else {
|
else {
|
||||||
|
sb.append("Current directory: ")
|
||||||
|
sb.append(if (isRoot) "(root)" else file.path)
|
||||||
|
sb.append('\n')
|
||||||
|
|
||||||
sb.append(".\n")
|
sb.append(".\n")
|
||||||
if (file!!.absolutePath != rootPath.absolutePath) sb.append("..\n")
|
if (isRoot) sb.append("..\n")
|
||||||
// actual entries
|
// actual entries
|
||||||
file!!.listFiles()!!.forEach {
|
file.listFiles()!!.forEach {
|
||||||
var filenameLen = it.name.length
|
var filenameLen = it.name.length
|
||||||
|
|
||||||
sb.append(it.name)
|
sb.append(it.name)
|
||||||
|
|
||||||
if (it.isDirectory) {
|
if (it.isDirectory) {
|
||||||
sb.append("/")
|
sb.append("/")
|
||||||
filenameLen += 1
|
filenameLen += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(" ".repeat(40 - filenameLen))
|
sb.append(" ".repeat(40 - filenameLen))
|
||||||
|
|
||||||
if (it.isFile) {
|
if (it.isFile) {
|
||||||
sb.append("${it.length()} B")
|
sb.append("${it.length()} B")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.append('\n')
|
||||||
}
|
}
|
||||||
sb.append('\n')
|
sb.append('\n')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
|||||||
else if (inputString.startsWith("DEVTYP\u0017"))
|
else if (inputString.startsWith("DEVTYP\u0017"))
|
||||||
recipient?.writeout(composeSerialAns("STOR"))
|
recipient?.writeout(composeSerialAns("STOR"))
|
||||||
else if (inputString.startsWith("DEVNAM\u0017"))
|
else if (inputString.startsWith("DEVNAM\u0017"))
|
||||||
recipient?.writeout(composeSerialAns("Testtec Virtual Disk Drive"))
|
recipient?.writeout(composeSerialAns("Testtec Signal Generator"))
|
||||||
else if (inputString.startsWith("OPENR\""))
|
else if (inputString.startsWith("OPENR\""))
|
||||||
fileOpen = true
|
fileOpen = true
|
||||||
else if (inputString.startsWith("CLOSE"))
|
else if (inputString.startsWith("CLOSE"))
|
||||||
|
|||||||
Reference in New Issue
Block a user