Sub Astream_NewData (Buffer() As Byte)
'Log("Command: ", bc.HexFromBytes(Buffer))
If receivingMode Then
WriteIncomingData(Buffer)
Return
Else
Select Buffer(0)
Case TASK_LISTFILES
ListFiles1
Case TASK_SENDFILE
SendFile(Buffer)
Case TASK_RECEIVEFILE
set("SD")
ReceiveFileName(Buffer)
set("EN")
Return
End Select
End If
Delay(100)
socket.Close
set("RFID")
End Sub
Sub Astream_Error
Log("Closed")
If receivingMode Then
receivingMode = False
set("SD")
Log("Stored file size: ", sd.CurrentFile.Size)
sd.Close
set("RFID")
End If
ethServer.Listen
End Sub
Sub ReceiveFileName (Buffer() As Byte)
Dim fileNameLength As Byte = Buffer(1)
Dim fileName() As Byte = bc.SubString2(Buffer, 2, 2 + fileNameLength)
Log("Receiving: ", fileName)
receivingMode = True
sd.OpenReadWrite(bc.StringFromBytes(fileName))
WriteIncomingData(bc.SubString(Buffer, 2 + fileNameLength))
End Sub
Sub WriteIncomingData(Buffer() As Byte)
sd.Stream.WriteBytes(Buffer, 0, Buffer.Length)
End Sub