Test HTTP Server, including RPCFunction

Fork of HTTPServer by Pete Baston

ソフト UP 練習用

Files at this revision

API Documentation at this revision

Comitter:
MasudaToshio
Date:
Thu Apr 18 10:06:20 2013 +0000
Parent:
0:dacaf456d264
Commit message:
rev0.1;

Changed in this revision

HTTPServer.cpp Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
diff -r dacaf456d264 -r 8b75f90ef1da HTTPServer.cpp
--- a/HTTPServer.cpp	Thu Feb 03 20:23:51 2011 +0000
+++ b/HTTPServer.cpp	Thu Apr 18 10:06:20 2013 +0000
@@ -1,68 +1,62 @@
 #include "mbed.h"
+#include "TextLCD.h"
 #include "EthernetNetIf.h"
 #include "HTTPServer.h"
-#include "RPCFunction.h"
-
-EthernetNetIf eth;
-
-HTTPServer svr;
-
-LocalFileSystem fs("webfs");
-
-//Create a function of the required format
-void testFunc(char * input, char * output);
-//Attach it to an RPC object
-RPCFunction rpcTestFunc(&testFunc, "testFunc");
-
-int main() {
-
+#include "RPCFunction.h"  //ADD Here!!
+DigitalOut led1(LED1,"led1");
+DigitalOut led2(LED2,"led2");
+DigitalOut led3(LED3,"led3");
+DigitalOut led4(LED4,"led4");
+ 
+TextLCD lcd(p24, p26, p27, p28, p29, p30);
+ 
+#if 1
+/*
+ * Use DHCP
+ */
+        EthernetNetIf ethif;
+#else
+/*
+ * Use "static IP address" (Parameters:IP, Subnet mask, Gateway, DNS)
+ */
+        EthernetNetIf ethif(IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx));
+#endif
+    
+    HTTPServer server;
+    LocalFileSystem local("local");
+    void LcdWrite(char *input,char *output);    //ADD Here!!
+    RPCFunction rpcFunc(&LcdWrite, "LcdWrite"); //ADD Here!!
+ 
+int main(void) {
+ 
     Base::add_rpc_class<DigitalOut>();
-    Base::add_rpc_class<PwmOut>();
-    Base::add_rpc_class<AnalogIn>();
-
-
-    printf("Setting up...\r\n");
-    EthernetErr ethErr = eth.setup();
-    if (ethErr) {
-        printf("Error %d in setup.\r\n", ethErr);
-        return -1;
+ 
+    lcd.cls();
+    lcd.locate(0,0);
+    lcd.printf("Program init..  ");
+ 
+    if (ethif.setup()) {
+        error("Ethernet setup failed.");
+        return 1;
     }
-    printf("Setup OK\r\n");
-
-    FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
-
-    svr.addHandler<SimpleHandler>("/hello"); //Default handler
-    svr.addHandler<RPCHandler>("/rpc");
-    svr.addHandler<FSHandler>("/"); //Default handler
-
-    svr.bind(80);
-
-    printf("Listening...\r\n");
-
-    Timer tm;
-    tm.start();
-    //Listen indefinitely
-    while (true) {
+    IpAddr ethIp=ethif.getIp();
+    
+    lcd.locate(0,1);
+    lcd.printf("%d.%d.%d.%d", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
+    led1=1;
+    wait(1);
+    server.addHandler<SimpleHandler>("/hello");
+    server.addHandler<RPCHandler>("/rpc");
+    FSHandler::mount("/local", "/");
+    server.addHandler<FSHandler>("/");
+    server.bind(80);
+    while (1) {
         Net::poll();
-        if (tm.read()>.5) {
-            tm.start();
-            printf("alive!\r\n");
-        }
     }
-
     return 0;
 }
-
-void testFunc(char * input, char * output) {
-
-    static int toggle=0;
-
-    if (toggle != 0) {
-        sprintf(output, "Hello");
-        toggle = 0;
-    } else {
-        sprintf(output, "Bye !");
-        toggle = 1;
-    }
-}
-
+void LcdWrite(char *input , char *output)  //ADD Here!!
+{
+    lcd.locate(0,1);
+    lcd.printf("%s",input);
+}
\ No newline at end of file
diff -r dacaf456d264 -r 8b75f90ef1da TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Thu Apr 18 10:06:20 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37