program to test the sending of small packets of data from memory over EthernetInterface using mbed rtos
Dependencies: EthernetInterface mbed-rtos mbed
Fork of testEthIntfTCPSocket by
Revision 2:a625f2ff0174, committed 2013-09-27
- Comitter:
- uci1
- Date:
- Fri Sep 27 23:16:09 2013 +0000
- Parent:
- 1:6b90cbfe0c9e
- Commit message:
- program for testing the sending of small packets of data over EthernetInterface with mbed rtos
Changed in this revision
--- a/EthernetInterface.lib Sat Sep 22 04:25:21 2012 +0000 +++ b/EthernetInterface.lib Fri Sep 27 23:16:09 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#a0ee3ae75cfa +https://mbed.org/users/AdamGreen/code/EthernetInterface/#3b00827bb0b7
--- a/FatFileSystemCpp.lib Sat Sep 22 04:25:21 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/igorsk/code/FatFileSystemCpp/#88f22c32a456
--- a/SDFileSystem.lib Sat Sep 22 04:25:21 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/SomeRandomBloke/code/SDFileSystem/#9c5f0c655284
--- a/main.cpp Sat Sep 22 04:25:21 2012 +0000 +++ b/main.cpp Fri Sep 27 23:16:09 2013 +0000 @@ -1,6 +1,5 @@ #include "mbed.h" -#include "SDFileSystem.h" #include "TCPSocketConnection.h" #include "EthernetInterface.h" #include "string" @@ -9,10 +8,6 @@ //#define DEBUG // turn on debug output if defined (note this slows down processing due to serial baud rate!) //#define PRINT_DOIO_RESULT // print the number of bytes DoIO returns -// if this is defined, read files starting with "S" from the SD card -// otherwise use the fake data in fakeData.h (from memory) -//#define USE_DATA_FROM_SD - DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); @@ -34,11 +29,7 @@ static const int kTotFakeDat = 2097152; // if sending fake data, send 2 MB total static const int kTimeout = 300; // seconds -static const char* kSDsubDir = "/sd"; -static const char* kFileTag = "S"; // send files starting with this tag - static char gBuff[kBuffSize]; -static SDFileSystem sd(p5, p6, p7, p8, kSDsubDir+1); static LocalFileSystem local("local"); static EthernetInterface* gEth(0); static TCPSocketConnection* gSock(0); @@ -69,11 +60,7 @@ set_time(kBSTime); if (Connect(time(0)+kTimeout)) { led2=1; -#ifdef USE_DATA_FROM_SD - SendAllFiles(time(0)+kTimeout); -#else SendAllFakeData(kTotFakeDat, time(0)+kTimeout); -#endif } else { led4=1; } @@ -84,7 +71,7 @@ gEth->disconnect(); } while (true) { - led1=0; wait(0.5); led1=1; wait(0.5); + led1=0; Thread::wait(500); led1=1; Thread::wait(500); } } @@ -97,12 +84,20 @@ gEth = new EthernetInterface; gSock = new TCPSocketConnection; +#ifdef DEBUG + printf("made eth and sock\r\n"); +#endif + gEth->init(kMyIp, kMyMask, kMyGate); +#ifdef DEBUG + printf("called init\r\n"); +#endif + bool isConn = false; while ( (isConn==false) && (IsTimedOut(timeout)==false) ) { - wait_ms(250); + Thread::wait(250); // TODO : change wait!! isConn = (gEth->connect()==0); } #ifdef DEBUG @@ -111,7 +106,7 @@ isConn=false; while ( (isConn==false) && (IsTimedOut(timeout)==false) ) { - wait_ms(250); + Thread::wait(250); isConn = (gSock->connect(kRserv, kRport)==0); } #ifdef DEBUG @@ -145,80 +140,6 @@ } } -void SendData(FILE* inf, const int timeout) { - // send the SD card data in chunks - - // store position in file so we can go back to it afterwards - const int fpos = ftell(inf); - if (fpos>0) { - fseek(inf, 0, SEEK_SET); - } - // how many bytes? - fseek(inf, 0, SEEK_END); // go to end - const int fend = ftell(inf); - fseek(inf, 0, SEEK_SET); // go to start -#ifdef DEBUG - printf("fend=%d\r\n",fend); - printf("fpos=%d\r\n",fpos); -#endif - - const int* const csend = gChunkSize + kNCsizes; - const int* cs = gChunkSize; - - int br=0; // bytes read/sent so far - int tcs=0; // this chunk size - while ( br<fend ) { - - // read a chunk or the remainder of the file - tcs = ((br+(*cs))<fend) ? (*cs) : (fend-br); - fread(gBuff, tcs, 1, inf); - - // send this chunk - br += SendAll(gBuff, tcs, timeout); - - // change chunk size - ++cs; - if (cs==csend) { - cs = gChunkSize; - } - } - -} - -FILE* OpenSDFile(const char* name, const char* mode) { - // TODO: check if we have memory? - std::string fn(name); - if (strncmp(name, kSDsubDir, strlen(kSDsubDir))!=0) { - // filename lacks directory - fn = kSDsubDir; - fn += "/"; - fn += name; - } -#ifdef DEBUG - printf("OpenSDFile: %s, mode %s\r\n",fn.c_str(),mode); -#endif - return fopen(fn.c_str(), mode); -} - -void SendAllFiles(const int timeout) { - - DIR* d; - struct dirent* dent; - - if ( (d = opendir( kSDsubDir ))!=NULL ) { - FILE* f; - while ( (dent = readdir(d))!=NULL ) { - if (strncmp(dent->d_name, kFileTag, strlen(kFileTag))==0) { - f = OpenSDFile(dent->d_name, "rb"); - SendAll(dent->d_name, strlen(dent->d_name), timeout); - SendData(f, timeout); - fclose(f); - } - } - closedir(d); - } -} - bool IsTimedOut(const int timeout_clock) { if (timeout_clock==0) { // for not obeying timeout option
--- a/mbed-rtos.lib Sat Sep 22 04:25:21 2012 +0000 +++ b/mbed-rtos.lib Fri Sep 27 23:16:09 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90 +http://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
--- a/mbed.bld Sat Sep 22 04:25:21 2012 +0000 +++ b/mbed.bld Fri Sep 27 23:16:09 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file