startSend() wont send extra fill-in bytes

This commit is contained in:
minjaesong
2020-10-23 16:50:36 +09:00
parent d579099d9c
commit acbd4ddc7d
4 changed files with 28 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ var ba = com.sendMessageGetBytes(0, "DEVNAM"+String.fromCharCode(0x17));
serial.println(ba); serial.println(ba);
ba = com.pullMessage(0) ba = com.pullMessage(0)
serial.println(ba); serial.print(ba);
serial.println("# END OF MSG");
serial.println("\nk bye") serial.println("k bye")

View File

@@ -85,18 +85,19 @@ Description: opens the file for writing
Description: opens the file for appending (a variant of write) 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 FLUSH
Description: flushes any internal output buffer and no longer puts the device to WRITE mode 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 Description: reads one block of file. Any subsequent read attempts will return next block. If file size is lesser
until the specified number of bytes reached 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 CLOSE

View File

@@ -55,6 +55,8 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
private var file: File? = null private var file: File? = null
//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 writeModeLength = -1
private val messageComposeBuffer = ByteArrayOutputStream(BLOCK_SIZE) // always use this and don't alter blockSendBuffer please private val messageComposeBuffer = ByteArrayOutputStream(BLOCK_SIZE) // always use this and don't alter blockSendBuffer please
private var blockSendBuffer = ByteArray(1) private var blockSendBuffer = ByteArray(1)
@@ -92,14 +94,12 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
blockSendBuffer = messageComposeBuffer.toByteArray() blockSendBuffer = messageComposeBuffer.toByteArray()
} }
recipient.writeout(ByteArray(BLOCK_SIZE) { val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
val i = blockSendCount * BLOCK_SIZE blockSendBuffer.size % BLOCK_SIZE
if (i + it >= blockSendBuffer.size) { else BLOCK_SIZE
0.toByte()
} recipient.writeout(ByteArray(sendSize) {
else { blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
blockSendBuffer[i + it]
}
}) })
blockSendCount += 1 blockSendCount += 1
@@ -124,21 +124,20 @@ class TestDiskDrive(private val driveNum: Int) : BlockTransferInterface(false, t
file = null file = null
blockSendCount = 0 blockSendCount = 0
stateCode = STATE_CODE_STANDBY stateCode = STATE_CODE_STANDBY
writeMode = false
writeModeLength = -1
} }
else if (inputString.startsWith("DEVSTU$END_OF_SEND_BLOCK")) { else if (inputString.startsWith("DEVSTU$END_OF_SEND_BLOCK")) {
if (stateCode < 128) { if (stateCode < 128) {
recipient?.writeout(composePositiveAns("${stateCode.toChar()}", errorMsgs[stateCode])) recipient?.writeout(composePositiveAns("${stateCode.toChar()}", errorMsgs[stateCode]))
//startSend { it.writeout(composePositiveAns("${stateCode.toChar()}", errorMsgs[stateCode])) }
} }
else { 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")) else if (inputString.startsWith("DEVTYP$END_OF_SEND_BLOCK"))
//startSend { it.writeout(composePositiveAns("STOR")) }
recipient?.writeout(composePositiveAns("STOR")) recipient?.writeout(composePositiveAns("STOR"))
else if (inputString.startsWith("DEVNAM$END_OF_SEND_BLOCK")) else if (inputString.startsWith("DEVNAM$END_OF_SEND_BLOCK"))
//startSend { it.writeout(composePositiveAns("Testtec Virtual Disk Drive")) }
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 (file != null) {

View File

@@ -80,7 +80,8 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
15360th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF 15360th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
15616th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF 15616th Byte 000111111111111111122222222222222223333333333333333444444444444444455555555555555556666666666666666777777777777777788888888888888889999999999999999AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFF
15872nd 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 private var fileOpen = false
@@ -106,14 +107,12 @@ Nunc mollis nibh vitae sapien consequat, ut vestibulum sem pharetra. Aliquam iac
blockSendBuffer = fileContent_multiblocks blockSendBuffer = fileContent_multiblocks
} }
recipient.writeout(ByteArray(BLOCK_SIZE) { val sendSize = if (blockSendBuffer.size - (blockSendCount * BLOCK_SIZE) < BLOCK_SIZE)
val i = blockSendCount * BLOCK_SIZE blockSendBuffer.size % BLOCK_SIZE
if (i + it >= blockSendBuffer.size) { else BLOCK_SIZE
0.toByte()
} recipient.writeout(ByteArray(sendSize) {
else { blockSendBuffer[blockSendCount * BLOCK_SIZE + it]
blockSendBuffer[i + it]
}
}) })
blockSendCount += 1 blockSendCount += 1