MiMic WebServer port to LPC1768-Mini-DK2 (Alpha ver.) *On uVision4(MDK-STD), -O2 option is required to run.
Dependencies: NySDFileSystem libMiMic mbed-rtos mbed
Fork of MbedFileServer by
main.cpp@11:5c1608e46104, 2013-05-12 (annotated)
- Committer:
- mio
- Date:
- Sun May 12 03:24:59 2013 +0000
- Revision:
- 11:5c1608e46104
- Parent:
- 10:80c05810f911
- Child:
- 12:e642e14ecb21
Alpha ver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nyatla | 4:0a280ed0a848 | 1 | /** |
mio | 11:5c1608e46104 | 2 | * MbedFilrServer , LPC1768-MiniDK2 Port |
mio | 11:5c1608e46104 | 3 | * |
mio | 11:5c1608e46104 | 4 | * https://mbed.org/users/nyatla/code/libMiMic/ |
nyatla | 4:0a280ed0a848 | 5 | * |
mio | 11:5c1608e46104 | 6 | * *On CodeRed(LPCXpresso) to build, |
mio | 11:5c1608e46104 | 7 | * Must Add -DTOOLCHAIN_CR_ARM project setting of C++ Compiler for "WORDS_STACK_SIZE" in cmsis_os.h |
mio | 11:5c1608e46104 | 8 | * Must create your own mbed-rtos/rtx/LPC1768/HAL_CM3.c routine on RTX |
nyatla | 4:0a280ed0a848 | 9 | */ |
mio | 11:5c1608e46104 | 10 | |
nyatla | 5:6a2a1644ea2c | 11 | #include "mbed.h" |
nyatla | 5:6a2a1644ea2c | 12 | #include "SDFileSystem.h" |
nyatla | 0:ec1e45489427 | 13 | #include "mimic.h" |
nyatla | 10:80c05810f911 | 14 | #include "utils/PlatformInfo.h" |
mio | 11:5c1608e46104 | 15 | |
mio | 11:5c1608e46104 | 16 | #define URL_HANDLE 1 /* if you use TEST URL HANDLER */ |
mio | 11:5c1608e46104 | 17 | |
mio | 11:5c1608e46104 | 18 | DigitalOut LED_1(P3_25),LED_2(P3_26); |
mio | 11:5c1608e46104 | 19 | Serial pc(P0_2,P0_3) ; |
nyatla | 0:ec1e45489427 | 20 | |
nyatla | 3:77431c2bd9cb | 21 | /** |
mio | 11:5c1608e46104 | 22 | * sd filesystem support. |
nyatla | 3:77431c2bd9cb | 23 | */ |
mio | 11:5c1608e46104 | 24 | SDFileSystem sd(P1_24, P1_23, P1_20, P1_21,"sd"); |
mio | 11:5c1608e46104 | 25 | unsigned int p = 0; // LED TOGGLE COUNTER |
mio | 11:5c1608e46104 | 26 | |
nyatla | 0:ec1e45489427 | 27 | /** |
nyatla | 0:ec1e45489427 | 28 | * MiMic RemoteMCU httpd.<br/> |
nyatla | 5:6a2a1644ea2c | 29 | * Number of simultaneous connections:4 |
nyatla | 0:ec1e45489427 | 30 | * <p>Service list</p> |
nyatla | 0:ec1e45489427 | 31 | * <pre> |
mio | 11:5c1608e46104 | 32 | * /sd/ - mbed LocalFileSystem |
mio | 11:5c1608e46104 | 33 | * /**** - URL Handler for test |
nyatla | 0:ec1e45489427 | 34 | * </pre> |
nyatla | 0:ec1e45489427 | 35 | */ |
nyatla | 5:6a2a1644ea2c | 36 | class FsHttpd:public MiMic::Httpd |
nyatla | 0:ec1e45489427 | 37 | { |
nyatla | 0:ec1e45489427 | 38 | private: |
mio | 11:5c1608e46104 | 39 | ModUrl modurl; //basic URL parser |
nyatla | 5:6a2a1644ea2c | 40 | ModLocalFileSystem modsd; |
nyatla | 0:ec1e45489427 | 41 | public: |
nyatla | 5:6a2a1644ea2c | 42 | FsHttpd():Httpd(80) |
nyatla | 0:ec1e45489427 | 43 | { |
nyatla | 3:77431c2bd9cb | 44 | //bind local file system path to /local/* |
nyatla | 5:6a2a1644ea2c | 45 | modsd.setParam("sd"); |
nyatla | 0:ec1e45489427 | 46 | } |
nyatla | 0:ec1e45489427 | 47 | virtual void onRequest(HttpdConnection& i_connection) |
nyatla | 0:ec1e45489427 | 48 | { |
nyatla | 6:20dcb08e1b43 | 49 | p++; |
mio | 11:5c1608e46104 | 50 | LED_1 = p%2; |
mio | 11:5c1608e46104 | 51 | |
nyatla | 5:6a2a1644ea2c | 52 | //try to ModLocalFileSystem(SD) |
nyatla | 5:6a2a1644ea2c | 53 | if(this->modsd.execute(i_connection)){ |
nyatla | 0:ec1e45489427 | 54 | return; |
nyatla | 0:ec1e45489427 | 55 | } |
mio | 11:5c1608e46104 | 56 | |
mio | 11:5c1608e46104 | 57 | #ifdef URL_HANDLE |
mio | 11:5c1608e46104 | 58 | // URL |
mio | 11:5c1608e46104 | 59 | char url[32]; |
mio | 11:5c1608e46104 | 60 | int method; |
mio | 11:5c1608e46104 | 61 | if(this->modurl.execute(i_connection,url,32,&method)){ |
mio | 11:5c1608e46104 | 62 | //send 200 OK and requested URL |
mio | 11:5c1608e46104 | 63 | i_connection.sendHeader(200,"text/html",NULL); |
mio | 11:5c1608e46104 | 64 | i_connection.sendBodyF("Your Request No is [%d] , path is %s.",p,url); |
mio | 11:5c1608e46104 | 65 | pc.printf("%s\r\n",url) ; |
mio | 11:5c1608e46104 | 66 | return; |
mio | 11:5c1608e46104 | 67 | } |
mio | 11:5c1608e46104 | 68 | #endif |
mio | 11:5c1608e46104 | 69 | |
nyatla | 5:6a2a1644ea2c | 70 | //Otherwise, Send simple top index page. |
nyatla | 5:6a2a1644ea2c | 71 | i_connection.sendHeader(200,"text/html",NULL); |
nyatla | 5:6a2a1644ea2c | 72 | if(i_connection.isMethodType(Http::MT_GET)){ |
nyatla | 5:6a2a1644ea2c | 73 | i_connection.sendBodyF( |
nyatla | 5:6a2a1644ea2c | 74 | "<!DOCTYPE html>" |
nyatla | 5:6a2a1644ea2c | 75 | "<html lang=\"ja\">" |
nyatla | 5:6a2a1644ea2c | 76 | "<head></head>" |
nyatla | 5:6a2a1644ea2c | 77 | "<body>" |
mio | 11:5c1608e46104 | 78 | "<h1>This is MiMic Server : Mini1768DK2 Port.</h1>" |
nyatla | 5:6a2a1644ea2c | 79 | "<hr/>" |
nyatla | 5:6a2a1644ea2c | 80 | "<ul>" |
nyatla | 5:6a2a1644ea2c | 81 | "<li><a href=\"/sd/\">SDCard</a></li>" |
nyatla | 5:6a2a1644ea2c | 82 | "</ul></body>"); |
nyatla | 5:6a2a1644ea2c | 83 | } |
nyatla | 0:ec1e45489427 | 84 | } |
nyatla | 0:ec1e45489427 | 85 | }; |
nyatla | 0:ec1e45489427 | 86 | |
nyatla | 0:ec1e45489427 | 87 | int main() |
nyatla | 0:ec1e45489427 | 88 | { |
nyatla | 0:ec1e45489427 | 89 | NetConfig cfg; //create network configulation |
nyatla | 0:ec1e45489427 | 90 | Net net(cfg); //create a net instance. |
mio | 11:5c1608e46104 | 91 | pc.baud(9600) ; // serial port for debug |
mio | 11:5c1608e46104 | 92 | |
mio | 11:5c1608e46104 | 93 | //try to override setting by SD file. |
mio | 11:5c1608e46104 | 94 | if (cfg.loadFromFile("/sd/mimic.cfg")) { |
mio | 11:5c1608e46104 | 95 | pc.printf("Setting is Overridden by /sd/mimic.cfg\r\n") ; |
mio | 11:5c1608e46104 | 96 | } else { |
mio | 11:5c1608e46104 | 97 | pc.printf("MY ADDR is 192.168.1.240\r\n") ; |
mio | 11:5c1608e46104 | 98 | cfg.setIpAddr(192,168,1,240) ; |
mio | 11:5c1608e46104 | 99 | cfg.setGateway(192,168,1,255) ; |
mio | 11:5c1608e46104 | 100 | cfg.setNetMask(255,255,255,0) ; |
mio | 11:5c1608e46104 | 101 | } |
mio | 11:5c1608e46104 | 102 | |
nyatla | 5:6a2a1644ea2c | 103 | FsHttpd httpd; //create a httpd instance. |
nyatla | 0:ec1e45489427 | 104 | httpd.loop(); //start httpd loop. |
nyatla | 0:ec1e45489427 | 105 | return 0; |
nyatla | 0:ec1e45489427 | 106 | } |