Test HTTP Server, including RPCFunction

Fork of HTTPServer by Pete Baston

ソフト UP 練習用

Committer:
MasudaToshio
Date:
Thu Apr 18 10:06:20 2013 +0000
Revision:
1:8b75f90ef1da
Parent:
0:dacaf456d264
rev0.1;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pbaston 0:dacaf456d264 1 #include "mbed.h"
MasudaToshio 1:8b75f90ef1da 2 #include "TextLCD.h"
pbaston 0:dacaf456d264 3 #include "EthernetNetIf.h"
pbaston 0:dacaf456d264 4 #include "HTTPServer.h"
MasudaToshio 1:8b75f90ef1da 5 #include "RPCFunction.h" //ADD Here!!
MasudaToshio 1:8b75f90ef1da 6 DigitalOut led1(LED1,"led1");
MasudaToshio 1:8b75f90ef1da 7 DigitalOut led2(LED2,"led2");
MasudaToshio 1:8b75f90ef1da 8 DigitalOut led3(LED3,"led3");
MasudaToshio 1:8b75f90ef1da 9 DigitalOut led4(LED4,"led4");
MasudaToshio 1:8b75f90ef1da 10
MasudaToshio 1:8b75f90ef1da 11 TextLCD lcd(p24, p26, p27, p28, p29, p30);
MasudaToshio 1:8b75f90ef1da 12
MasudaToshio 1:8b75f90ef1da 13 #if 1
MasudaToshio 1:8b75f90ef1da 14 /*
MasudaToshio 1:8b75f90ef1da 15 * Use DHCP
MasudaToshio 1:8b75f90ef1da 16 */
MasudaToshio 1:8b75f90ef1da 17 EthernetNetIf ethif;
MasudaToshio 1:8b75f90ef1da 18 #else
MasudaToshio 1:8b75f90ef1da 19 /*
MasudaToshio 1:8b75f90ef1da 20 * Use "static IP address" (Parameters:IP, Subnet mask, Gateway, DNS)
MasudaToshio 1:8b75f90ef1da 21 */
MasudaToshio 1:8b75f90ef1da 22 EthernetNetIf ethif(IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx));
MasudaToshio 1:8b75f90ef1da 23 #endif
MasudaToshio 1:8b75f90ef1da 24
MasudaToshio 1:8b75f90ef1da 25 HTTPServer server;
MasudaToshio 1:8b75f90ef1da 26 LocalFileSystem local("local");
MasudaToshio 1:8b75f90ef1da 27 void LcdWrite(char *input,char *output); //ADD Here!!
MasudaToshio 1:8b75f90ef1da 28 RPCFunction rpcFunc(&LcdWrite, "LcdWrite"); //ADD Here!!
MasudaToshio 1:8b75f90ef1da 29
MasudaToshio 1:8b75f90ef1da 30 int main(void) {
MasudaToshio 1:8b75f90ef1da 31
pbaston 0:dacaf456d264 32 Base::add_rpc_class<DigitalOut>();
MasudaToshio 1:8b75f90ef1da 33
MasudaToshio 1:8b75f90ef1da 34 lcd.cls();
MasudaToshio 1:8b75f90ef1da 35 lcd.locate(0,0);
MasudaToshio 1:8b75f90ef1da 36 lcd.printf("Program init.. ");
MasudaToshio 1:8b75f90ef1da 37
MasudaToshio 1:8b75f90ef1da 38 if (ethif.setup()) {
MasudaToshio 1:8b75f90ef1da 39 error("Ethernet setup failed.");
MasudaToshio 1:8b75f90ef1da 40 return 1;
pbaston 0:dacaf456d264 41 }
MasudaToshio 1:8b75f90ef1da 42 IpAddr ethIp=ethif.getIp();
MasudaToshio 1:8b75f90ef1da 43
MasudaToshio 1:8b75f90ef1da 44 lcd.locate(0,1);
MasudaToshio 1:8b75f90ef1da 45 lcd.printf("%d.%d.%d.%d", ethIp[0], ethIp[1], ethIp[2], ethIp[3]);
MasudaToshio 1:8b75f90ef1da 46 led1=1;
MasudaToshio 1:8b75f90ef1da 47 wait(1);
MasudaToshio 1:8b75f90ef1da 48 server.addHandler<SimpleHandler>("/hello");
MasudaToshio 1:8b75f90ef1da 49 server.addHandler<RPCHandler>("/rpc");
MasudaToshio 1:8b75f90ef1da 50 FSHandler::mount("/local", "/");
MasudaToshio 1:8b75f90ef1da 51 server.addHandler<FSHandler>("/");
MasudaToshio 1:8b75f90ef1da 52 server.bind(80);
MasudaToshio 1:8b75f90ef1da 53 while (1) {
pbaston 0:dacaf456d264 54 Net::poll();
pbaston 0:dacaf456d264 55 }
pbaston 0:dacaf456d264 56 return 0;
pbaston 0:dacaf456d264 57 }
MasudaToshio 1:8b75f90ef1da 58 void LcdWrite(char *input , char *output) //ADD Here!!
MasudaToshio 1:8b75f90ef1da 59 {
MasudaToshio 1:8b75f90ef1da 60 lcd.locate(0,1);
MasudaToshio 1:8b75f90ef1da 61 lcd.printf("%s",input);
MasudaToshio 1:8b75f90ef1da 62 }