eth
Dependencies: EthernetInterface mbed-rtos mbed
Fork of FRDM_K64F-Ethernet by
main.cpp@4:edeb4d3d1968, 2015-04-23 (annotated)
- Committer:
- dariusz777
- Date:
- Thu Apr 23 18:38:21 2015 +0000
- Revision:
- 4:edeb4d3d1968
- Parent:
- 3:5bb986247f20
- Child:
- 5:f689b3fc93b2
na zajecia OK
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
issaiass | 0:bbc9cfdee3bc | 1 | #include "mbed.h" |
issaiass | 0:bbc9cfdee3bc | 2 | #include "EthernetInterface.h" |
dariusz777 | 2:ff5c01165824 | 3 | |
dariusz777 | 3:5bb986247f20 | 4 | #define IP "***" |
dariusz777 | 3:5bb986247f20 | 5 | #define MASK "***" |
dariusz777 | 3:5bb986247f20 | 6 | #define GW "***" |
dariusz777 | 3:5bb986247f20 | 7 | #define PORT ** |
dariusz777 | 1:52ba06578336 | 8 | |
dariusz777 | 2:ff5c01165824 | 9 | void getsth(char a, EthernetInterface e, TCPSocketConnection cli); |
issaiass | 0:bbc9cfdee3bc | 10 | |
dariusz777 | 2:ff5c01165824 | 11 | int main (void){ |
issaiass | 0:bbc9cfdee3bc | 12 | EthernetInterface eth; |
dariusz777 | 2:ff5c01165824 | 13 | eth.init(IP, MASK, GW); //Assign a device ip, mask and gateway |
dariusz777 | 2:ff5c01165824 | 14 | // eth.init(); |
issaiass | 0:bbc9cfdee3bc | 15 | eth.connect(); |
dariusz777 | 4:edeb4d3d1968 | 16 | printf("IP Address is %s\n", eth.getIPAddress()); |
dariusz777 | 2:ff5c01165824 | 17 | |
issaiass | 0:bbc9cfdee3bc | 18 | TCPSocketServer server; |
dariusz777 | 2:ff5c01165824 | 19 | server.bind(PORT); |
issaiass | 0:bbc9cfdee3bc | 20 | server.listen(); |
dariusz777 | 1:52ba06578336 | 21 | |
issaiass | 0:bbc9cfdee3bc | 22 | while (true) { |
issaiass | 0:bbc9cfdee3bc | 23 | printf("\nWait for new connection...\n"); |
issaiass | 0:bbc9cfdee3bc | 24 | TCPSocketConnection client; |
issaiass | 0:bbc9cfdee3bc | 25 | server.accept(client); |
issaiass | 0:bbc9cfdee3bc | 26 | client.set_blocking(false, 1500); // Timeout after (1.5)s |
dariusz777 | 2:ff5c01165824 | 27 | |
issaiass | 0:bbc9cfdee3bc | 28 | printf("Connection from: %s\n", client.get_address()); |
issaiass | 0:bbc9cfdee3bc | 29 | char buffer[256]; |
issaiass | 0:bbc9cfdee3bc | 30 | while (true) { |
issaiass | 0:bbc9cfdee3bc | 31 | int n = client.receive(buffer, sizeof(buffer)); |
dariusz777 | 2:ff5c01165824 | 32 | if(n>0) { |
dariusz777 | 2:ff5c01165824 | 33 | char a = buffer[0]; |
dariusz777 | 2:ff5c01165824 | 34 | if(a == '1') { |
dariusz777 | 2:ff5c01165824 | 35 | client.send_all(eth.getIPAddress(),16); |
dariusz777 | 2:ff5c01165824 | 36 | } else if(a == '2') { |
dariusz777 | 2:ff5c01165824 | 37 | client.send_all(eth.getGateway(),16); |
dariusz777 | 2:ff5c01165824 | 38 | } else if(a == '3') { |
dariusz777 | 2:ff5c01165824 | 39 | client.send_all(eth.getMACAddress(),17); |
dariusz777 | 2:ff5c01165824 | 40 | } else if(a == '4') { |
dariusz777 | 2:ff5c01165824 | 41 | client.send_all(eth.getNetworkMask(),16); |
dariusz777 | 2:ff5c01165824 | 42 | }else if(a == 'c'){ |
dariusz777 | 2:ff5c01165824 | 43 | client.close(); |
dariusz777 | 2:ff5c01165824 | 44 | } |
dariusz777 | 2:ff5c01165824 | 45 | client.send_all("\n",2); |
dariusz777 | 2:ff5c01165824 | 46 | n=0; |
dariusz777 | 2:ff5c01165824 | 47 | a='0'; |
dariusz777 | 2:ff5c01165824 | 48 | |
dariusz777 | 2:ff5c01165824 | 49 | } |
dariusz777 | 2:ff5c01165824 | 50 | |
dariusz777 | 2:ff5c01165824 | 51 | } |
issaiass | 0:bbc9cfdee3bc | 52 | } |
dariusz777 | 2:ff5c01165824 | 53 | |
dariusz777 | 1:52ba06578336 | 54 | } |