mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 11:51:49 +09:00
startSend() wont send extra fill-in bytes
This commit is contained in:
@@ -2,6 +2,7 @@ var ba = com.sendMessageGetBytes(0, "DEVNAM"+String.fromCharCode(0x17));
|
||||
serial.println(ba);
|
||||
|
||||
ba = com.pullMessage(0)
|
||||
serial.println(ba);
|
||||
serial.print(ba);
|
||||
serial.println("# END OF MSG");
|
||||
|
||||
serial.println("\nk bye")
|
||||
serial.println("k bye")
|
||||
@@ -85,18 +85,19 @@ Description: opens the file for writing
|
||||
|
||||
Description: opens the file for appending (a variant of write)
|
||||
|
||||
WRITE<number of bytes to write>
|
||||
WRITE
|
||||
|
||||
Description: puts the device to WRITE mode. Any subsequent bytes will be interpreted as-is for writing
|
||||
Description: puts the device into WRITE mode. Any subsequent bytes will be interpreted as-is for writing
|
||||
|
||||
FLUSH
|
||||
|
||||
Description: flushes any internal output buffer and no longer puts the device to WRITE mode
|
||||
|
||||
READ<number of bytes to read>
|
||||
READ
|
||||
|
||||
Description: reads specified number of bytes. Any subsequent reading operation will return bytes stored into the file
|
||||
until the specified number of bytes reached
|
||||
Description: reads one block of file. Any subsequent read attempts will return next block. If file size is lesser
|
||||
than a single block, rest of the bytes will be filled with zero, and size-of-the-block (see terranmon.txt)
|
||||
will be set accordingly.
|
||||
|
||||
CLOSE
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
private var file: File? = null
|
||||
//private var readModeLength = -1 // always 4096
|
||||
private var stateCode = STATE_CODE_STANDBY
|
||||
private var writeMode = false
|
||||
private var writeModeLength = -1
|
||||
|
||||
private val messageComposeBuffer = ByteArrayOutputStream(BLOCK_SIZE) // always use this and don't alter blockSendBuffer please
|
||||
private var blockSendBuffer = ByteArray(1)
|
||||
@@ -92,14 +94,12 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
blockSendBuffer = messageComposeBuffer.toByteArray()
|
||||
}
|
||||
|
||||
recipient.writeout(ByteArray(BLOCK_SIZE) {
|
||||
val i = blockSendCount * BLOCK_SIZE
|
||||
if (i + it >= blockSendBuffer.size) {
|
||||
0.toByte()
|
||||
}
|
||||
else {
|
||||
blockSendBuffer[i + it]
|
||||
}
|
||||
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
||||
blockSendBuffer.size % BLOCK_SIZE
|
||||
else BLOCK_SIZE
|
||||
|
||||
recipient.writeout(ByteArray(sendSize) {
|
||||
blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
|
||||
})
|
||||
|
||||
blockSendCount += 1
|
||||
@@ -124,21 +124,20 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
|
||||
file = null
|
||||
blockSendCount = 0
|
||||
stateCode = STATE_CODE_STANDBY
|
||||
writeMode = false
|
||||
writeModeLength = -1
|
||||
}
|
||||
else if (inputString.startsWith("DEVSTU$END_OF_SEND_BLOCK")) {
|
||||
if (stateCode < 128) {
|
||||
recipient?.writeout(composePositiveAns("${stateCode.toChar()}", errorMsgs[stateCode]))
|
||||
//startSend { it.writeout(composePositiveAns("${stateCode.toChar()}", errorMsgs[stateCode])) }
|
||||
}
|
||||
else {
|
||||
startSend { it.writeout(composeNegativeAns("${stateCode.toChar()}", errorMsgs[stateCode])) }
|
||||
recipient?.writeout(composeNegativeAns("${stateCode.toChar()}", errorMsgs[stateCode]))
|
||||
}
|
||||
}
|
||||
else if (inputString.startsWith("DEVTYP$END_OF_SEND_BLOCK"))
|
||||
//startSend { it.writeout(composePositiveAns("STOR")) }
|
||||
recipient?.writeout(composePositiveAns("STOR"))
|
||||
else if (inputString.startsWith("DEVNAM$END_OF_SEND_BLOCK"))
|
||||
//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) {
|
||||
|
||||
@@ -80,7 +80,8 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
||||
15360th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
|
||||
15616th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
|
||||
15872nd Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
|
||||
16128th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF#""".toByteArray(Charsets.US_ASCII)
|
||||
16128th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
|
||||
16384th Byte and some trailing bytes too!""".toByteArray(Charsets.US_ASCII)
|
||||
|
||||
private var fileOpen = false
|
||||
|
||||
@@ -106,14 +107,12 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
|
||||
blockSendBuffer = fileContent_multiblocks
|
||||
}
|
||||
|
||||
recipient.writeout(ByteArray(BLOCK_SIZE) {
|
||||
val i = blockSendCount * BLOCK_SIZE
|
||||
if (i + it >= blockSendBuffer.size) {
|
||||
0.toByte()
|
||||
}
|
||||
else {
|
||||
blockSendBuffer[i + it]
|
||||
}
|
||||
val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
|
||||
blockSendBuffer.size % BLOCK_SIZE
|
||||
else BLOCK_SIZE
|
||||
|
||||
recipient.writeout(ByteArray(sendSize) {
|
||||
blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
|
||||
})
|
||||
|
||||
blockSendCount += 1
|
||||
|
||||
Reference in New Issue
Block a user