![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sfs
Dependencies: EthernetInterface mbed-rtos mbed
main.cpp@1:2bdce5c2162d, 2016-12-08 (annotated)
- Committer:
- grzemich
- Date:
- Thu Dec 08 21:43:12 2016 +0000
- Revision:
- 1:2bdce5c2162d
- Parent:
- 0:8864e30d7121
- Child:
- 3:150e1413e660
sisk_proj_stat
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
grzemich | 0:8864e30d7121 | 1 | #include "mbed.h" |
grzemich | 0:8864e30d7121 | 2 | #include "EthernetInterface.h" |
grzemich | 1:2bdce5c2162d | 3 | #include "rtos.h" |
grzemich | 0:8864e30d7121 | 4 | |
grzemich | 0:8864e30d7121 | 5 | #define MBED_DEV_IP "192.168.0.52" |
grzemich | 0:8864e30d7121 | 6 | #define MBED_DEV_MASK "255.255.255.0" |
grzemich | 0:8864e30d7121 | 7 | #define MBED_DEV_GW "0.0.0.0" |
grzemich | 0:8864e30d7121 | 8 | #define ECHO_SERVER_PORT 5000 |
grzemich | 0:8864e30d7121 | 9 | |
grzemich | 0:8864e30d7121 | 10 | |
grzemich | 0:8864e30d7121 | 11 | |
grzemich | 0:8864e30d7121 | 12 | int main (void) { |
grzemich | 0:8864e30d7121 | 13 | EthernetInterface eth; |
grzemich | 1:2bdce5c2162d | 14 | |
grzemich | 1:2bdce5c2162d | 15 | //to do |
grzemich | 1:2bdce5c2162d | 16 | |
grzemich | 0:8864e30d7121 | 17 | eth.connect(); |
grzemich | 0:8864e30d7121 | 18 | printf("IP Address is %s\n", eth.getIPAddress()); |
grzemich | 0:8864e30d7121 | 19 | |
grzemich | 0:8864e30d7121 | 20 | TCPSocketServer server; |
grzemich | 0:8864e30d7121 | 21 | server.bind(ECHO_SERVER_PORT); |
grzemich | 0:8864e30d7121 | 22 | server.listen(); |
grzemich | 1:2bdce5c2162d | 23 | |
grzemich | 1:2bdce5c2162d | 24 | while(1) { |
grzemich | 1:2bdce5c2162d | 25 | TCPSocketConnection client; |
grzemich | 0:8864e30d7121 | 26 | server.accept(client); |
grzemich | 0:8864e30d7121 | 27 | client.set_blocking(false, 1500); // Timeout after (1.5)s |
grzemich | 1:2bdce5c2162d | 28 | if((int)phy_link_status()){ |
grzemich | 1:2bdce5c2162d | 29 | printf("Cable is connected\n"); |
grzemich | 1:2bdce5c2162d | 30 | if((int)phy_get_duplex()) |
grzemich | 1:2bdce5c2162d | 31 | printf("Full duplex\n"); |
grzemich | 1:2bdce5c2162d | 32 | else |
grzemich | 1:2bdce5c2162d | 33 | printf("Half duplex\n"); |
grzemich | 1:2bdce5c2162d | 34 | if((int)phy_get_speed()) |
grzemich | 1:2bdce5c2162d | 35 | printf("100 Mbit per second\n"); |
grzemich | 1:2bdce5c2162d | 36 | else |
grzemich | 1:2bdce5c2162d | 37 | printf("10 Mbit per second\n"); |
grzemich | 1:2bdce5c2162d | 38 | } |
grzemich | 1:2bdce5c2162d | 39 | else |
grzemich | 1:2bdce5c2162d | 40 | printf("Cable is disconnected\n"); |
grzemich | 1:2bdce5c2162d | 41 | wait(1); |
grzemich | 1:2bdce5c2162d | 42 | |
grzemich | 0:8864e30d7121 | 43 | } |
grzemich | 0:8864e30d7121 | 44 | } |
grzemich | 0:8864e30d7121 | 45 |