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@3:116c45e2a41e, 2014-09-18 (annotated)
- Committer:
- p3p
- Date:
- Thu Sep 18 17:49:08 2014 +0000
- Revision:
- 3:116c45e2a41e
- Parent:
- 0:a0abf3eff698
- Child:
- 4:dfe9a9434a92
Updated to reflect changes in SimpleSErialProtocol
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 | 3:116c45e2a41e | 12 | //initialise the comm port at 155200 baud and use the default codec |
p3p | 3:116c45e2a41e | 13 | SimpleSerialProtocol::Codec codec; |
p3p | 3:116c45e2a41e | 14 | comms.initialise(115200, &codec); |
p3p | 0:a0abf3eff698 | 15 | //listen for packets of type 1 and relay the data to the onFileStart callback in SFTProtocol |
p3p | 0:a0abf3eff698 | 16 | comms.receiveCallback(1, &fileAcceptor, &SFTProtocol::onFileStart); |
p3p | 0:a0abf3eff698 | 17 | //listen for packets of type 3 and relay |
p3p | 0:a0abf3eff698 | 18 | comms.receiveCallback(3, &fileAcceptor, &SFTProtocol::onFileStream); |
p3p | 0:a0abf3eff698 | 19 | |
p3p | 0:a0abf3eff698 | 20 | debug.baud(115200); |
p3p | 0:a0abf3eff698 | 21 | debug.printf("Debug Terminal:\r\n"); |
p3p | 0:a0abf3eff698 | 22 | |
p3p | 0:a0abf3eff698 | 23 | while(true){ |
p3p | 0:a0abf3eff698 | 24 | //the protocol needs constant updates to process packets and forward the data |
p3p | 0:a0abf3eff698 | 25 | comms.update(); |
p3p | 0:a0abf3eff698 | 26 | |
p3p | 0:a0abf3eff698 | 27 | //the SFTProtocol is updated so it can timeout, and request packet resends, |
p3p | 0:a0abf3eff698 | 28 | fileAcceptor.update(&comms); |
p3p | 0:a0abf3eff698 | 29 | } |
p3p | 0:a0abf3eff698 | 30 | } |