Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #define BUF_SIZE 1024 00003 00004 // attributes - peripherals 00005 Serial pc(SERIAL_TX, SERIAL_RX); 00006 DigitalOut myled(LED1); 00007 Timer timeout; 00008 Ticker blinker; 00009 00010 // attributes - program variables 00011 char fileOverSerialBuffer[BUF_SIZE]; // buffer to store received string over pc 00012 00013 // local methods 00014 void ledBlink ( void ) { 00015 myled != myled; 00016 } 00017 00018 // main 00019 int main() { 00020 00021 int i; 00022 int bytesReceived = 0; 00023 00024 pc.baud ( 600 ); // slow communication! 00025 //pc.attach(&serialDataCallback); // attach pc ISR 00026 00027 while ( true ) { 00028 00029 // ready for a new file to be received 00030 bytesReceived = 0; 00031 timeout.stop(); 00032 timeout.reset(); 00033 blinker.attach( &ledBlink, 1.0 ); 00034 00035 // wait for input 00036 while ( pc.readable() && timeout.read() < 1 ) { 00037 if ( bytesReceived == 0 ) { 00038 timeout.start(); // watchdog 00039 timeout.reset(); 00040 } 00041 if ( bytesReceived < BUF_SIZE-1 ) { // avoid buffer overflow 00042 fileOverSerialBuffer[bytesReceived++] = pc.getc(); 00043 myled = fileOverSerialBuffer[bytesReceived] & 0x01; // show activity 00044 timeout.reset(); // got byte: reset watchdog 00045 } else 00046 break; // buffer full - stop receiving 00047 } 00048 00049 // file completed - process 00050 fileOverSerialBuffer[bytesReceived+1] = '\x00'; // terminate a string 00051 blinker.detach(); // stop flashing 00052 myled = 1; // processing 00053 pc.printf("Got %d bytes\n\r", bytesReceived); 00054 for ( i=0; i < bytesReceived; i++) { 00055 pc.printf("%.2x ", fileOverSerialBuffer[i]); 00056 if ( !(i%16) && i!=0 ) pc.printf("\n\r"); 00057 } 00058 pc.printf("\n\r"); 00059 myled = 0; // done 00060 00061 00062 } 00063 }
Generated on Wed Jul 27 2022 10:19:50 by
1.7.2