Test Server
Dependencies: EthernetInterface mbed-rtos mbed
Revision 0:762cc0d8a4fa, committed 2015-03-04
- Comitter:
- timmey9
- Date:
- Wed Mar 04 20:21:43 2015 +0000
- Commit message:
- Initial commit.
Changed in this revision
diff -r 000000000000 -r 762cc0d8a4fa EthernetInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Wed Mar 04 20:21:43 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#65b0d840274c
diff -r 000000000000 -r 762cc0d8a4fa main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 04 20:21:43 2015 +0000 @@ -0,0 +1,63 @@ +#include "mbed.h" +#include "EthernetInterface.h" + +#define ECHO_SERVER_PORT 54321 + +#define IP "169.254.225.206" +#define GATEWAY "169.254.225.1" +#define MASK "255.255.0.0" + +#define LEN 18980 +uint16_t sample_array0[LEN]; + +DigitalOut led_red(LED_RED); +DigitalOut led_green(LED_GREEN); +DigitalOut led_blue(LED_BLUE); + +Serial pc(USBTX,USBRX); + +int main (void) { + for(int i = 0; i < LEN; i++) sample_array0[i] = ((0x0031<<8) | 0x0032); + sample_array0[0] = ('S'<<8)|'S'; + sample_array0[LEN-1] = ('F'<<8) | 'F'; + pc.baud(230400); + pc.printf("Starting test server\r\n"); + + EthernetInterface eth; + eth.init(IP, MASK, GATEWAY); + eth.connect(); + pc.printf("IP Address is %s\r\n", eth.getIPAddress()); + + TCPSocketServer server; + server.bind(ECHO_SERVER_PORT); + server.listen(); + + led_blue = 1; + led_green = 1; + led_red = 1; + + while (true) { + //pc.printf("\r\nWait for new connection...\r\n"); + + + TCPSocketConnection client; + server.accept(client); + client.set_blocking(true, 5000); + + //pc.printf("Connection from: %s\r\n", client.get_address()); + char buffer[1460]; // size of IP payload + while (true) { + int n = client.receive(buffer, sizeof(buffer)); + if (n <= 0) break; + pc.printf("Rec: %i: ",n); + + n = client.send_all((char *)sample_array0, LEN*2); + + if (n <= 0) {led_blue = 0; break;} + pc.printf("Sent %i: ",n); + } + + client.close(); + pc.printf("\r\n"); + } +} \ No newline at end of file
diff -r 000000000000 -r 762cc0d8a4fa mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Wed Mar 04 20:21:43 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#63988a2238f7
diff -r 000000000000 -r 762cc0d8a4fa mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 04 20:21:43 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf \ No newline at end of file