Test program with networking part in RTOS-thread
Dependencies: mbed mbed-rtos EthernetInterface
Revision 0:7a6d4b87941e, committed 2012-07-22
- Comitter:
- tuxic
- Date:
- Sun Jul 22 09:29:28 2012 +0000
- Commit message:
- first test with network routines in a rtos-thread
Changed in this revision
diff -r 000000000000 -r 7a6d4b87941e EthernetInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Sun Jul 22 09:29:28 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#0063a5bac04f
diff -r 000000000000 -r 7a6d4b87941e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Jul 22 09:29:28 2012 +0000 @@ -0,0 +1,61 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "cmsis_os.h" + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); + +void led2_thread(void const *argument) { + while (true) { + led2 = !led2; + osDelay(1000); + } +} +void net_thread(void const *argument) { + EthernetInterface eth; + eth.init(); //Use DHCP + eth.connect(); + printf("IP Address is %s\n", eth.getIPAddress()); + TCPSocket sock; + while (true) { + led3 = !led3; + sock.connect("mbed.org", 80); + + char http_cmd[] = "GET /media/uploads/donatien/hello.txt HTTP/1.1\r\nHost: %s\r\n\r\n"; + sock.send(http_cmd, sizeof(http_cmd) - 1, 3000); + + char in_buf[256]; + bool firstIteration = true; + int ret; + do { + ret = sock.receive(in_buf, 255, firstIteration?3000:0); + in_buf[ret] = '\0'; + + printf("Received %d chars from server: %s\n", ret, in_buf); + firstIteration = false; + } while ( ret > 0 ); + + sock.close(); + + //eth.disconnect(); + + led3 = !led3; + osDelay(500); + } +} + +osThreadDef(led2_thread, osPriorityNormal, DEFAULT_STACK_SIZE); +osThreadDef(net_thread, osPriorityNormal, DEFAULT_STACK_SIZE); + +int main() { + osThreadCreate(osThread(led2_thread), NULL); + + osThreadCreate(osThread(net_thread), NULL); + + while (true) { + led1 = !led1; + osDelay(500); + } +} +
diff -r 000000000000 -r 7a6d4b87941e mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sun Jul 22 09:29:28 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#01158bb7600c
diff -r 000000000000 -r 7a6d4b87941e mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jul 22 09:29:28 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6 \ No newline at end of file