David Wilson
/
DGWWebServer
Web Server with access to local and SD card filesystem
main.cpp@1:2b224ec81465, 2010-04-19 (annotated)
- Committer:
- dgwilson
- Date:
- Mon Apr 19 07:38:13 2010 +0000
- Revision:
- 1:2b224ec81465
- Parent:
- 0:fd1cf5929992
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dgwilson | 1:2b224ec81465 | 1 | #include "SDFileSystem.h" |
dgwilson | 1:2b224ec81465 | 2 | |
dgwilson | 0:fd1cf5929992 | 3 | #include "mbed.h" |
dgwilson | 0:fd1cf5929992 | 4 | |
dgwilson | 0:fd1cf5929992 | 5 | #include "HTTPServer.h" |
dgwilson | 1:2b224ec81465 | 6 | |
dgwilson | 0:fd1cf5929992 | 7 | #include "HTTPRPC.h" |
dgwilson | 0:fd1cf5929992 | 8 | #include "HTTPFS.h" |
dgwilson | 0:fd1cf5929992 | 9 | #include "HTTPStaticPage.h" |
dgwilson | 0:fd1cf5929992 | 10 | |
dgwilson | 0:fd1cf5929992 | 11 | #include "SDFileSystem.h" |
dgwilson | 0:fd1cf5929992 | 12 | |
dgwilson | 0:fd1cf5929992 | 13 | //#include <string.h> |
dgwilson | 0:fd1cf5929992 | 14 | |
dgwilson | 0:fd1cf5929992 | 15 | const char content[] = "<HTML><BODY><H1>Hello World</H1></BODY></HTML>"; |
dgwilson | 0:fd1cf5929992 | 16 | |
dgwilson | 0:fd1cf5929992 | 17 | HTTPServer http; |
dgwilson | 0:fd1cf5929992 | 18 | DigitalOut myled1(LED1), myled2(LED2), myled3(LED3), myled4(LED4); |
dgwilson | 0:fd1cf5929992 | 19 | LocalFileSystem local("local"); |
dgwilson | 0:fd1cf5929992 | 20 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
dgwilson | 0:fd1cf5929992 | 21 | |
dgwilson | 0:fd1cf5929992 | 22 | void SetConsole38400(void) |
dgwilson | 0:fd1cf5929992 | 23 | { |
dgwilson | 0:fd1cf5929992 | 24 | uint8_t lcrSave = LPC_UART0->LCR; |
dgwilson | 0:fd1cf5929992 | 25 | LPC_UART0->LCR |= 0x80; |
dgwilson | 0:fd1cf5929992 | 26 | uint16_t oldDLValue = LPC_UART0->DLM * 256 + LPC_UART0->DLL; |
dgwilson | 0:fd1cf5929992 | 27 | uint8_t oldFDRValue = LPC_UART0->FDR; |
dgwilson | 0:fd1cf5929992 | 28 | LPC_UART0->DLM = 125 / 256; |
dgwilson | 0:fd1cf5929992 | 29 | LPC_UART0->DLL = 125; |
dgwilson | 0:fd1cf5929992 | 30 | LPC_UART0->LCR = lcrSave; |
dgwilson | 0:fd1cf5929992 | 31 | LPC_UART0->FDR = 0x41; |
dgwilson | 0:fd1cf5929992 | 32 | printf("UART0 old DL %d FDR %d %d\r\n", oldDLValue, oldFDRValue >> 4, oldDLValue & 0x0F); |
dgwilson | 0:fd1cf5929992 | 33 | } |
dgwilson | 0:fd1cf5929992 | 34 | |
dgwilson | 0:fd1cf5929992 | 35 | int main(void) { |
dgwilson | 0:fd1cf5929992 | 36 | myled1 = 1; |
dgwilson | 1:2b224ec81465 | 37 | printf("\r\n----------------------------------------------------\n\r"); |
dgwilson | 1:2b224ec81465 | 38 | printf("\r\nWe have ignition - make sure Ethernet is connected!\n\r"); |
dgwilson | 0:fd1cf5929992 | 39 | http.addHandler(new HTTPStaticPage("/test.htm", content, strlen(content))); |
dgwilson | 0:fd1cf5929992 | 40 | printf("HTTPStaticPage added\n\r"); |
dgwilson | 0:fd1cf5929992 | 41 | http.addHandler(new HTTPRPC()); |
dgwilson | 0:fd1cf5929992 | 42 | printf("HTTPRPC added\n\r"); |
dgwilson | 0:fd1cf5929992 | 43 | http.addHandler(new HTTPFileSystemHandler("/", "/local/")); |
dgwilson | 0:fd1cf5929992 | 44 | printf("HTTPFileSystemHandler added for /local/ \n\r"); |
dgwilson | 1:2b224ec81465 | 45 | http.addHandler(new HTTPFileSystemHandler("/sdcard/", "/sd/")); |
dgwilson | 0:fd1cf5929992 | 46 | printf("HTTPFileSystemHandler added for /sd/ \n\r"); |
dgwilson | 0:fd1cf5929992 | 47 | http.bind(); |
dgwilson | 1:2b224ec81465 | 48 | printf("bind\n\r"); |
dgwilson | 0:fd1cf5929992 | 49 | NetServer *net = NetServer::get(); |
dgwilson | 0:fd1cf5929992 | 50 | printf("%hhu.%hhu.%hhu.%hhu\n\r", (net->getIPAddr().addr)&0xFF, (net->getIPAddr().addr>>8)&0xFF, (net->getIPAddr().addr>>16)&0xFF, (net->getIPAddr().addr>>24)&0xFF); |
dgwilson | 0:fd1cf5929992 | 51 | while (1) { |
dgwilson | 0:fd1cf5929992 | 52 | //wait_ms(1); |
dgwilson | 0:fd1cf5929992 | 53 | wait_us(100); |
dgwilson | 0:fd1cf5929992 | 54 | http.poll(); |
dgwilson | 0:fd1cf5929992 | 55 | myled2 = !myled2; |
dgwilson | 0:fd1cf5929992 | 56 | // wait(0.1); |
dgwilson | 0:fd1cf5929992 | 57 | } |
dgwilson | 0:fd1cf5929992 | 58 | } |