eth
Dependencies: EthernetInterface mbed-rtos mbed
Fork of FRDM_K64F-Ethernet by
main.cpp@1:52ba06578336, 2015-04-19 (annotated)
- Committer:
- dariusz777
- Date:
- Sun Apr 19 17:00:55 2015 +0000
- Revision:
- 1:52ba06578336
- Parent:
- 0:bbc9cfdee3bc
- Child:
- 2:ff5c01165824
done
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 | 1:52ba06578336 | 3 | #include "gets.h" |
dariusz777 | 1:52ba06578336 | 4 | |
issaiass | 0:bbc9cfdee3bc | 5 | |
issaiass | 0:bbc9cfdee3bc | 6 | #define MBED_DEV_IP "192.168.0.52" |
dariusz777 | 1:52ba06578336 | 7 | #define MBED_DEV_MASK "255.255.255.0" |
dariusz777 | 1:52ba06578336 | 8 | #define MBED_DEV_GW "0.0.0.0" |
dariusz777 | 1:52ba06578336 | 9 | #define ECHO_SERVER_PORT 80 |
dariusz777 | 1:52ba06578336 | 10 | // 5000 |
issaiass | 0:bbc9cfdee3bc | 11 | |
issaiass | 0:bbc9cfdee3bc | 12 | int main (void) { |
dariusz777 | 1:52ba06578336 | 13 | |
dariusz777 | 1:52ba06578336 | 14 | |
issaiass | 0:bbc9cfdee3bc | 15 | EthernetInterface eth; |
issaiass | 0:bbc9cfdee3bc | 16 | eth.init(MBED_DEV_IP, MBED_DEV_MASK, MBED_DEV_GW); //Assign a device ip, mask and gateway |
dariusz777 | 1:52ba06578336 | 17 | // eth.init(); |
issaiass | 0:bbc9cfdee3bc | 18 | eth.connect(); |
dariusz777 | 1:52ba06578336 | 19 | printf("IP Address is %s\n", eth.getIPAddress()); //"192.168.0.52" |
issaiass | 0:bbc9cfdee3bc | 20 | |
issaiass | 0:bbc9cfdee3bc | 21 | TCPSocketServer server; |
issaiass | 0:bbc9cfdee3bc | 22 | server.bind(ECHO_SERVER_PORT); |
issaiass | 0:bbc9cfdee3bc | 23 | server.listen(); |
dariusz777 | 1:52ba06578336 | 24 | |
issaiass | 0:bbc9cfdee3bc | 25 | while (true) { |
issaiass | 0:bbc9cfdee3bc | 26 | printf("\nWait for new connection...\n"); |
issaiass | 0:bbc9cfdee3bc | 27 | TCPSocketConnection client; |
issaiass | 0:bbc9cfdee3bc | 28 | server.accept(client); |
issaiass | 0:bbc9cfdee3bc | 29 | client.set_blocking(false, 1500); // Timeout after (1.5)s |
issaiass | 0:bbc9cfdee3bc | 30 | |
issaiass | 0:bbc9cfdee3bc | 31 | printf("Connection from: %s\n", client.get_address()); |
issaiass | 0:bbc9cfdee3bc | 32 | char buffer[256]; |
issaiass | 0:bbc9cfdee3bc | 33 | while (true) { |
issaiass | 0:bbc9cfdee3bc | 34 | int n = client.receive(buffer, sizeof(buffer)); |
dariusz777 | 1:52ba06578336 | 35 | if(n>0){ |
dariusz777 | 1:52ba06578336 | 36 | getsth(buffer[0], eth, client); |
dariusz777 | 1:52ba06578336 | 37 | n=0; |
issaiass | 0:bbc9cfdee3bc | 38 | } |
dariusz777 | 1:52ba06578336 | 39 | } |
issaiass | 0:bbc9cfdee3bc | 40 | } |
dariusz777 | 1:52ba06578336 | 41 | } |