USB file system over internet
Dependencies: EthernetNetIfamr FatFileSystemCpp HTTPServer mbed
Fork of MSCUsbHost by
Revision 4:1e70ea58f9e3, committed 2014-03-14
- Comitter:
- joinamruta
- Date:
- Fri Mar 14 18:28:22 2014 +0000
- Parent:
- 3:95e55809ecdb
- Commit message:
- Acessing USB file sysytem over internet;
Changed in this revision
diff -r 95e55809ecdb -r 1e70ea58f9e3 EthernetNetIf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Fri Mar 14 18:28:22 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/joinamruta/code/EthernetNetIfamr/#47063e9036c5
diff -r 95e55809ecdb -r 1e70ea58f9e3 HTTPServer.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPServer.lib Fri Mar 14 18:28:22 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
diff -r 95e55809ecdb -r 1e70ea58f9e3 main.cpp --- a/main.cpp Mon Jul 30 13:49:56 2012 +0000 +++ b/main.cpp Fri Mar 14 18:28:22 2014 +0000 @@ -1,69 +1,64 @@ #include "mbed.h" +#include "EthernetNetIf.h" +#include "HTTPServer.h" #include "MSCFileSystem.h" -//#include <stat.h> #define FSNAME "msc" MSCFileSystem msc(FSNAME); -int main() -{ - DIR *d; - struct dirent *p; - //struct stat st; - //char path[PATH_MAX]; +DigitalOut led1(LED1, "led1"); +EthernetNetIf eth; +HTTPServer svr; + +int main() { + + + printf("Setting up...\n"); + EthernetErr ethErr = eth.setup(); + if(ethErr) + { + printf("Error %d in setup.\n", ethErr); + return -1; + } + printf("Setup OK\n"); + + FSHandler::mount("/msc", "/files"); //Mount /webfs path on /files web path +// FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path + FSHandler::mount("/msc", "/"); //Mount /webfs path on web root path + FSHandler::mount("/msc", "/"); //Mount /webfs path on web root path + + svr.addHandler<SimpleHandler>("/hello"); + svr.addHandler<RPCHandler>("/rpc"); + svr.addHandler<FSHandler>("/files"); + svr.addHandler<FSHandler>("/"); //Default handler + //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm + + svr.bind(80); + + printf("Listening...\n"); - printf("\n\n================================\n"); - printf("USB Mass storage demo program for mbed LPC1768\n"); - printf("================================\n\n"); - - d = opendir("/" FSNAME); - - printf("\nList of files on the flash drive:\n"); - if ( d != NULL ) + Timer tm; + tm.start(); + //Listen indefinitely + while(true) + { + Net::poll(); + if(tm.read()>.5) { - while ( (p = readdir(d)) != NULL ) - { - printf(" - %s\n", p->d_name); - /* no <stat.h> on mbed, it seems :/ - sprintf(path, "/"FSNAME"/%s", p->d_name); - if ( stat(path, &st) == 0 ) - { - if ( S_ISDIR(st.st_mode) ) - printf(" <directory>\n"); - else - printf(" %d\n", st.st_size); - } - else - { - printf(" ???\n"); - }*/ - } - } - else - { - error("Could not open directory!"); + led1=!led1; //Show that we are alive + tm.start(); } - printf("\nTesting file write:\n"); - FILE *fp = fopen( "/" FSNAME "/msctest.txt", "w"); - if ( fp == NULL ) - { - error("Could not open file for write\n"); - } - fprintf(fp, "Hello mass storage!"); - fclose(fp); - printf("\n - OK\n"); + } + + return 0; + +} + - printf("\nTesting file read:\n"); - fp = fopen( "/" FSNAME "/msctest.txt", "r"); - if ( fp == NULL ) - { - error("Could not open file for read\n"); - } - char buf[256]; - if ( NULL == fgets(buf, sizeof(buf), fp) ) - { - error("Error reading from file\n"); - } - fclose(fp); - printf("\n - OK, read string: '%s'\n\n", buf); -} + + + + + + +