sample program for Wi-Fi TANK.

Dependencies:   EthernetNetIf mbed HTTPServer

Committer:
halfpitch
Date:
Thu Jul 28 10:42:37 2011 +0000
Revision:
0:0b46e539de3c
Rev.A

Who changed what in which revision?

UserRevisionLine numberNew contents of line
halfpitch 0:0b46e539de3c 1 #include "mbed.h"
halfpitch 0:0b46e539de3c 2 #include "EthernetNetIf.h"
halfpitch 0:0b46e539de3c 3 #include "HTTPServer.h"
halfpitch 0:0b46e539de3c 4 #include "RPCFunction.h"
halfpitch 0:0b46e539de3c 5
halfpitch 0:0b46e539de3c 6 DigitalOut led1(LED1);
halfpitch 0:0b46e539de3c 7 DigitalOut led2(LED2);
halfpitch 0:0b46e539de3c 8 DigitalOut led3(LED3);
halfpitch 0:0b46e539de3c 9 DigitalOut led4(LED4);
halfpitch 0:0b46e539de3c 10
halfpitch 0:0b46e539de3c 11 DigitalOut motor1(p21);
halfpitch 0:0b46e539de3c 12 DigitalOut motor2(p22);
halfpitch 0:0b46e539de3c 13 DigitalOut motor3(p23);
halfpitch 0:0b46e539de3c 14 DigitalOut motor4(p24);
halfpitch 0:0b46e539de3c 15
halfpitch 0:0b46e539de3c 16 #if 1
halfpitch 0:0b46e539de3c 17 /*
halfpitch 0:0b46e539de3c 18 * Use DHCP
halfpitch 0:0b46e539de3c 19 */
halfpitch 0:0b46e539de3c 20 EthernetNetIf ethif;
halfpitch 0:0b46e539de3c 21 #else
halfpitch 0:0b46e539de3c 22 /*
halfpitch 0:0b46e539de3c 23 * Use "static IP address" (Parameters:IP, Subnet mask, Gateway, DNS)
halfpitch 0:0b46e539de3c 24 */
halfpitch 0:0b46e539de3c 25 EthernetNetIf ethif(IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx), IpAddr(xxx,xxx,xxx,xxx));
halfpitch 0:0b46e539de3c 26 #endif
halfpitch 0:0b46e539de3c 27
halfpitch 0:0b46e539de3c 28 HTTPServer server;
halfpitch 0:0b46e539de3c 29 LocalFileSystem local("local");
halfpitch 0:0b46e539de3c 30 void MotorSig(char *input,char *output);
halfpitch 0:0b46e539de3c 31 RPCFunction rpcFunc(&MotorSig, "MotorSig");
halfpitch 0:0b46e539de3c 32
halfpitch 0:0b46e539de3c 33 int main(void) {
halfpitch 0:0b46e539de3c 34
halfpitch 0:0b46e539de3c 35 Base::add_rpc_class<DigitalOut>();
halfpitch 0:0b46e539de3c 36
halfpitch 0:0b46e539de3c 37
halfpitch 0:0b46e539de3c 38 if (ethif.setup()) {
halfpitch 0:0b46e539de3c 39 error("Ethernet setup failed.");
halfpitch 0:0b46e539de3c 40 return 1;
halfpitch 0:0b46e539de3c 41 }
halfpitch 0:0b46e539de3c 42 IpAddr ethIp=ethif.getIp();
halfpitch 0:0b46e539de3c 43
halfpitch 0:0b46e539de3c 44 led1=1;
halfpitch 0:0b46e539de3c 45 wait(1);
halfpitch 0:0b46e539de3c 46 server.addHandler<SimpleHandler>("/hello");
halfpitch 0:0b46e539de3c 47 server.addHandler<RPCHandler>("/rpc");
halfpitch 0:0b46e539de3c 48 FSHandler::mount("/local", "/");
halfpitch 0:0b46e539de3c 49 server.addHandler<FSHandler>("/");
halfpitch 0:0b46e539de3c 50 server.bind(80);
halfpitch 0:0b46e539de3c 51 while (1) {
halfpitch 0:0b46e539de3c 52 Net::poll();
halfpitch 0:0b46e539de3c 53 }
halfpitch 0:0b46e539de3c 54 return 0;
halfpitch 0:0b46e539de3c 55 }
halfpitch 0:0b46e539de3c 56
halfpitch 0:0b46e539de3c 57
halfpitch 0:0b46e539de3c 58 void MotorSig(char *input , char *output)
halfpitch 0:0b46e539de3c 59 {
halfpitch 0:0b46e539de3c 60
halfpitch 0:0b46e539de3c 61 //text---------------------------
halfpitch 0:0b46e539de3c 62 int length = 0;
halfpitch 0:0b46e539de3c 63 char str[] = "abcd";
halfpitch 0:0b46e539de3c 64
halfpitch 0:0b46e539de3c 65 //get input data length
halfpitch 0:0b46e539de3c 66 for (length = 0; input[length] != '\0'; length++);
halfpitch 0:0b46e539de3c 67
halfpitch 0:0b46e539de3c 68 //check data
halfpitch 0:0b46e539de3c 69 printf("length = %d : input = %s\n", length, input);
halfpitch 0:0b46e539de3c 70
halfpitch 0:0b46e539de3c 71 if (strcmp(input,str) == 0){
halfpitch 0:0b46e539de3c 72 printf("input OK!\n");
halfpitch 0:0b46e539de3c 73 }
halfpitch 0:0b46e539de3c 74 //-------------------------------
halfpitch 0:0b46e539de3c 75
halfpitch 0:0b46e539de3c 76 led1=!led1;
halfpitch 0:0b46e539de3c 77 if(*input == 'a'){
halfpitch 0:0b46e539de3c 78 led2 =! led2;
halfpitch 0:0b46e539de3c 79 }
halfpitch 0:0b46e539de3c 80 if(*input == 'F'){
halfpitch 0:0b46e539de3c 81 led3 =! led3;
halfpitch 0:0b46e539de3c 82 }
halfpitch 0:0b46e539de3c 83
halfpitch 0:0b46e539de3c 84
halfpitch 0:0b46e539de3c 85 switch(*input){
halfpitch 0:0b46e539de3c 86 case 'F':
halfpitch 0:0b46e539de3c 87 motor1 = 0;
halfpitch 0:0b46e539de3c 88 motor2 = 1;
halfpitch 0:0b46e539de3c 89 motor3 = 1;
halfpitch 0:0b46e539de3c 90 motor4 = 0;
halfpitch 0:0b46e539de3c 91
halfpitch 0:0b46e539de3c 92 led1 = 0;
halfpitch 0:0b46e539de3c 93 led2 = 1;
halfpitch 0:0b46e539de3c 94 led3 = 1;
halfpitch 0:0b46e539de3c 95 led4 = 0;
halfpitch 0:0b46e539de3c 96 break;
halfpitch 0:0b46e539de3c 97
halfpitch 0:0b46e539de3c 98 case 'L':
halfpitch 0:0b46e539de3c 99 motor1 = 1;
halfpitch 0:0b46e539de3c 100 motor2 = 0;
halfpitch 0:0b46e539de3c 101 motor3 = 1;
halfpitch 0:0b46e539de3c 102 motor4 = 0;
halfpitch 0:0b46e539de3c 103
halfpitch 0:0b46e539de3c 104 led1 = 1;
halfpitch 0:0b46e539de3c 105 led2 = 0;
halfpitch 0:0b46e539de3c 106 led3 = 1;
halfpitch 0:0b46e539de3c 107 led4 = 0;
halfpitch 0:0b46e539de3c 108 break;
halfpitch 0:0b46e539de3c 109
halfpitch 0:0b46e539de3c 110 case 'R':
halfpitch 0:0b46e539de3c 111 motor1 = 0;
halfpitch 0:0b46e539de3c 112 motor2 = 1;
halfpitch 0:0b46e539de3c 113 motor3 = 0;
halfpitch 0:0b46e539de3c 114 motor4 = 1;
halfpitch 0:0b46e539de3c 115
halfpitch 0:0b46e539de3c 116 led1 = 0;
halfpitch 0:0b46e539de3c 117 led2 = 1;
halfpitch 0:0b46e539de3c 118 led3 = 0;
halfpitch 0:0b46e539de3c 119 led4 = 1;
halfpitch 0:0b46e539de3c 120 break;
halfpitch 0:0b46e539de3c 121
halfpitch 0:0b46e539de3c 122 case 'B':
halfpitch 0:0b46e539de3c 123 motor1 = 1;
halfpitch 0:0b46e539de3c 124 motor2 = 0;
halfpitch 0:0b46e539de3c 125 motor3 = 0;
halfpitch 0:0b46e539de3c 126 motor4 = 1;
halfpitch 0:0b46e539de3c 127
halfpitch 0:0b46e539de3c 128 led1 = 1;
halfpitch 0:0b46e539de3c 129 led2 = 0;
halfpitch 0:0b46e539de3c 130 led3 = 0;
halfpitch 0:0b46e539de3c 131 led4 = 1;
halfpitch 0:0b46e539de3c 132 break;
halfpitch 0:0b46e539de3c 133
halfpitch 0:0b46e539de3c 134 case 'S':
halfpitch 0:0b46e539de3c 135 motor1 = 0;
halfpitch 0:0b46e539de3c 136 motor2 = 0;
halfpitch 0:0b46e539de3c 137 motor3 = 0;
halfpitch 0:0b46e539de3c 138 motor4 = 0;
halfpitch 0:0b46e539de3c 139
halfpitch 0:0b46e539de3c 140 led1 = 0;
halfpitch 0:0b46e539de3c 141 led2 = 0;
halfpitch 0:0b46e539de3c 142 led3 = 0;
halfpitch 0:0b46e539de3c 143 led4 = 0;
halfpitch 0:0b46e539de3c 144 break;
halfpitch 0:0b46e539de3c 145
halfpitch 0:0b46e539de3c 146
halfpitch 0:0b46e539de3c 147 }
halfpitch 0:0b46e539de3c 148 }
halfpitch 0:0b46e539de3c 149