pierre masala
/
MeARM
Mearm colorsorting with web application
main.cpp@5:36f1e4e1a427, 2017-12-14 (annotated)
- Committer:
- pierre11
- Date:
- Thu Dec 14 12:48:11 2017 +0000
- Revision:
- 5:36f1e4e1a427
- Parent:
- 4:62b6eaf030ab
- Child:
- 6:60ab0d214512
oui
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pierre11 | 5:36f1e4e1a427 | 1 | //#if !FEATURE_LWIP |
pierre11 | 5:36f1e4e1a427 | 2 | // #error [NOT_SUPPORTED] LWIP not supported for this target |
pierre11 | 5:36f1e4e1a427 | 3 | //#endif |
group-ST | 0:6e8275981824 | 4 | |
group-ST | 0:6e8275981824 | 5 | #include "mbed.h" |
group-ST | 0:6e8275981824 | 6 | #include "EthernetInterface.h" |
group-ST | 0:6e8275981824 | 7 | #include "TCPServer.h" |
group-ST | 0:6e8275981824 | 8 | #include "TCPSocket.h" |
pierre11 | 5:36f1e4e1a427 | 9 | #include "Servo.h" |
pierre11 | 3:f5e5af908b55 | 10 | uint8_t http[1024]; |
pierre11 | 5:36f1e4e1a427 | 11 | uint8_t httpr[1024]={200,200}; |
pierre11 | 5:36f1e4e1a427 | 12 | uint8_t httpr1[300]={2,2,2,2}; |
pierre11 | 5:36f1e4e1a427 | 13 | //static void SendWebPage( float ,float ,float , float ); |
group-ST | 0:6e8275981824 | 14 | |
pierre11 | 5:36f1e4e1a427 | 15 | |
pierre11 | 3:f5e5af908b55 | 16 | |
group-ST | 0:6e8275981824 | 17 | |
group-ST | 0:6e8275981824 | 18 | int main() |
group-ST | 0:6e8275981824 | 19 | { |
pierre11 | 5:36f1e4e1a427 | 20 | Servo Servo1(PD_13); |
pierre11 | 5:36f1e4e1a427 | 21 | Servo Servo2(PD_12); |
pierre11 | 5:36f1e4e1a427 | 22 | Servo Servo3(PD_14); |
pierre11 | 5:36f1e4e1a427 | 23 | Servo Servo4(PD_15); |
pierre11 | 5:36f1e4e1a427 | 24 | |
pierre11 | 5:36f1e4e1a427 | 25 | Servo1.Enable(1500,20000); |
pierre11 | 5:36f1e4e1a427 | 26 | Servo2.Enable(1500,20000); |
pierre11 | 5:36f1e4e1a427 | 27 | Servo3.Enable(1500,20000); |
pierre11 | 5:36f1e4e1a427 | 28 | |
pierre11 | 5:36f1e4e1a427 | 29 | int pos,i=0,a=0,a1=0; |
group-ST | 0:6e8275981824 | 30 | printf("Basic HTTP server example\n"); |
group-ST | 0:6e8275981824 | 31 | |
pierre11 | 3:f5e5af908b55 | 32 | |
group-ST | 0:6e8275981824 | 33 | EthernetInterface eth; |
group-ST | 0:6e8275981824 | 34 | eth.connect(); |
group-ST | 0:6e8275981824 | 35 | |
group-ST | 0:6e8275981824 | 36 | printf("The target IP address is '%s'\n", eth.get_ip_address()); |
group-ST | 0:6e8275981824 | 37 | |
group-ST | 0:6e8275981824 | 38 | TCPServer srv; |
pierre11 | 5:36f1e4e1a427 | 39 | |
group-ST | 0:6e8275981824 | 40 | TCPSocket clt_sock; |
pierre11 | 5:36f1e4e1a427 | 41 | |
adustm | 1:ec61ea9f67de | 42 | SocketAddress clt_addr; |
pierre11 | 5:36f1e4e1a427 | 43 | |
group-ST | 0:6e8275981824 | 44 | |
group-ST | 0:6e8275981824 | 45 | /* Open the server on ethernet stack */ |
group-ST | 0:6e8275981824 | 46 | srv.open(ð); |
group-ST | 0:6e8275981824 | 47 | |
pierre11 | 5:36f1e4e1a427 | 48 | |
group-ST | 0:6e8275981824 | 49 | /* Bind the HTTP port (TCP 80) to the server */ |
pierre11 | 5:36f1e4e1a427 | 50 | //srv.bind(eth.get_ip_address(), 80); |
pierre11 | 5:36f1e4e1a427 | 51 | srv.bind(eth.get_ip_address(), 5001); |
pierre11 | 5:36f1e4e1a427 | 52 | // srv1.bind("10.101.1.130",5001); |
group-ST | 0:6e8275981824 | 53 | |
group-ST | 0:6e8275981824 | 54 | /* Can handle 5 simultaneous connections */ |
group-ST | 0:6e8275981824 | 55 | srv.listen(5); |
pierre11 | 5:36f1e4e1a427 | 56 | |
pierre11 | 3:f5e5af908b55 | 57 | |
group-ST | 0:6e8275981824 | 58 | while (true) { |
pierre11 | 3:f5e5af908b55 | 59 | |
pierre11 | 5:36f1e4e1a427 | 60 | //========================== |
pierre11 | 5:36f1e4e1a427 | 61 | for ( pos = 500; pos < 2000; pos += 25) |
pierre11 | 5:36f1e4e1a427 | 62 | { |
pierre11 | 5:36f1e4e1a427 | 63 | Servo1.SetPosition(pos); |
pierre11 | 5:36f1e4e1a427 | 64 | httpr[i]=8; |
pierre11 | 5:36f1e4e1a427 | 65 | wait_ms(20); |
pierre11 | 5:36f1e4e1a427 | 66 | i++; |
pierre11 | 5:36f1e4e1a427 | 67 | } |
pierre11 | 3:f5e5af908b55 | 68 | |
pierre11 | 5:36f1e4e1a427 | 69 | //i=0; |
pierre11 | 5:36f1e4e1a427 | 70 | // SendWebPage(pos,v2,v3,v4); |
pierre11 | 5:36f1e4e1a427 | 71 | srv.accept(&clt_sock, &clt_addr); |
pierre11 | 5:36f1e4e1a427 | 72 | printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); |
pierre11 | 5:36f1e4e1a427 | 73 | a = clt_sock.send(httpr, strlen((char *)httpr)); |
pierre11 | 5:36f1e4e1a427 | 74 | while(true) |
pierre11 | 5:36f1e4e1a427 | 75 | { |
pierre11 | 5:36f1e4e1a427 | 76 | a1 = clt_sock.recv(httpr1, strlen((char *)httpr1)); |
pierre11 | 5:36f1e4e1a427 | 77 | //printf("accept Xbyte %d\n",a1); |
pierre11 | 5:36f1e4e1a427 | 78 | if (a1 <= 0) |
pierre11 | 5:36f1e4e1a427 | 79 | break; |
pierre11 | 5:36f1e4e1a427 | 80 | //httpr1[a1] = '\0'; |
pierre11 | 5:36f1e4e1a427 | 81 | printf("Received %d chars from server:\n%s\n", a1,httpr1); |
pierre11 | 5:36f1e4e1a427 | 82 | } |
pierre11 | 5:36f1e4e1a427 | 83 | clt_sock.close(); |
pierre11 | 5:36f1e4e1a427 | 84 | printf("accept voir %d\n",httpr1[0]); |
pierre11 | 5:36f1e4e1a427 | 85 | } |
pierre11 | 5:36f1e4e1a427 | 86 |