An example program for SerialFileTransfer, receives files from a java application and stores them on the LocalFileSystem
Dependencies: MODSERIAL SerialFileTransfer SimpleSerialProtocol mbed
SerialFileReceiver allow the mbed to receive a file using binary packets over the serial connection,
you can test the library with this java application /media/uploads/p3p/mbedserialfiletransfer.zip
the arguments to the command are, Comport Baudrate file to see the console output use java, not javaw
Example command: java -jar SerialTransfer.jar com3 115200 test.bin
main.cpp@0:a0abf3eff698, 2014-08-27 (annotated)
- Committer:
- p3p
- Date:
- Wed Aug 27 17:51:48 2014 +0000
- Revision:
- 0:a0abf3eff698
- Child:
- 3:116c45e2a41e
Initial Commit, Using the SimpleSerialProtocol library to send files to the mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
p3p | 0:a0abf3eff698 | 1 | #include "mbed.h" |
p3p | 0:a0abf3eff698 | 2 | #include "SerialFileTransfer.h" |
p3p | 0:a0abf3eff698 | 3 | |
p3p | 0:a0abf3eff698 | 4 | //Create an instance of the SimpleSerialProtocol on a Serial port, optionaly choose a status led |
p3p | 0:a0abf3eff698 | 5 | SimpleSerialProtocol::Protocol comms(USBTX, USBRX, LED1); |
p3p | 0:a0abf3eff698 | 6 | |
p3p | 0:a0abf3eff698 | 7 | Serial debug(p13,p14); |
p3p | 0:a0abf3eff698 | 8 | |
p3p | 0:a0abf3eff698 | 9 | SFTProtocol fileAcceptor; |
p3p | 0:a0abf3eff698 | 10 | |
p3p | 0:a0abf3eff698 | 11 | int main() { |
p3p | 0:a0abf3eff698 | 12 | //initialise the comm port at 155200 baud |
p3p | 0:a0abf3eff698 | 13 | comms.initialise(115200); |
p3p | 0:a0abf3eff698 | 14 | //listen for packets of type 1 and relay the data to the onFileStart callback in SFTProtocol |
p3p | 0:a0abf3eff698 | 15 | comms.receiveCallback(1, &fileAcceptor, &SFTProtocol::onFileStart); |
p3p | 0:a0abf3eff698 | 16 | //listen for packets of type 3 and relay |
p3p | 0:a0abf3eff698 | 17 | comms.receiveCallback(3, &fileAcceptor, &SFTProtocol::onFileStream); |
p3p | 0:a0abf3eff698 | 18 | |
p3p | 0:a0abf3eff698 | 19 | debug.baud(115200); |
p3p | 0:a0abf3eff698 | 20 | debug.printf("Debug Terminal:\r\n"); |
p3p | 0:a0abf3eff698 | 21 | |
p3p | 0:a0abf3eff698 | 22 | while(true){ |
p3p | 0:a0abf3eff698 | 23 | //the protocol needs constant updates to process packets and forward the data |
p3p | 0:a0abf3eff698 | 24 | comms.update(); |
p3p | 0:a0abf3eff698 | 25 | |
p3p | 0:a0abf3eff698 | 26 | //the SFTProtocol is updated so it can timeout, and request packet resends, |
p3p | 0:a0abf3eff698 | 27 | fileAcceptor.update(&comms); |
p3p | 0:a0abf3eff698 | 28 | } |
p3p | 0:a0abf3eff698 | 29 | } |