UART TCP client for LPC1786

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of TCPSocket_HelloWorld by mbed official

Files at this revision

API Documentation at this revision

Comitter:
rodolforbcoutinho
Date:
Thu Oct 26 16:52:09 2017 +0000
Parent:
14:72be2b8b7f24
Commit message:
UART TCP client for LPC1786

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 72be2b8b7f24 -r e6c1c6be2f44 EthernetInterface.lib
--- a/EthernetInterface.lib	Wed May 14 15:07:26 2014 +0000
+++ b/EthernetInterface.lib	Thu Oct 26 16:52:09 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#097a9996f8d5
+https://os.mbed.com/users/rodolforbcoutinho/code/EthernetInterface/#e48d6850ce0c
diff -r 72be2b8b7f24 -r e6c1c6be2f44 main.cpp
--- a/main.cpp	Wed May 14 15:07:26 2014 +0000
+++ b/main.cpp	Thu Oct 26 16:52:09 2017 +0000
@@ -1,27 +1,84 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 
-int main() {
-    EthernetInterface eth;
+InterruptIn BTN_send(p14);
+DigitalOut led(LED1);
+DigitalOut led_rx(LED2);
+
+RawSerial device(p9, p10);  // tx, rx
+
+volatile int flagB = 0;
+volatile int flagS = 0;
+
+// Circular buffers for serial TX and RX data - used by interrupt routines
+const int buffer_size = 16;
+// might need to increase buffer size for high baud rates
+char rx_buffer[buffer_size+1];
+// Circular buffer pointers
+// volatile makes read-modify-write atomic 
+volatile int rx_in=0;
+
+EthernetInterface eth;
+TCPSocketConnection sock;
+
+void BTN_send_TCP()
+{
+    led = !led;
+    flagB = 200;
+}
+
+void UART_send_TCP()
+{
+    int byte_counter = 0;
+    
+    led_rx = 1;
+    while (device.readable() and (byte_counter != 5))
+    {
+        rx_buffer[rx_in] = device.getc();
+        rx_in = (rx_in + 1) % buffer_size;
+        
+        byte_counter++;
+    }
+    flagS = 200;
+    led_rx = 0;
+}
+
+int main() 
+{
+    BTN_send.rise(&BTN_send_TCP);
+    device.baud(9600);
+    device.attach(&UART_send_TCP, Serial::RxIrq); 
+    
+    //device.printf("teste UART 2\n\r");  
+    
+    //EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
-    printf("IP Address is %s\n", eth.getIPAddress());
+    printf("IP Address is %s\n\r", eth.getIPAddress());
     
-    TCPSocketConnection sock;
-    sock.connect("mbed.org", 80);
+    //TCPSocketConnection sock;
+    sock.connect("10.0.126.202", 8888);
+    //sock.connect("192.168.1.7", 8888);
     
-    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
-    sock.send_all(http_cmd, sizeof(http_cmd)-1);
+    char cmd[] = "teste ethernet MBED e C#! Visual Studio Rules!!!\n\r";
+    char cmd2[] = "another test by button fuction flag\n\r";
+    sock.send_all(cmd, sizeof(cmd)-1);
     
-    char buffer[300];
-    int ret;
-    while (true) {
-        ret = sock.receive(buffer, sizeof(buffer)-1);
-        if (ret <= 0)
-            break;
-        buffer[ret] = '\0';
-        printf("Received %d chars from server:\n%s\n", ret, buffer);
-    }
+    while (true)
+    {
+        if(flagB == 200)
+        {
+            flagB = 0;
+            sock.send_all(cmd2, sizeof(cmd2)-1);
+        }  
+        if(flagS == 200)
+        {
+            flagS = 0;
+            sock.send_all(rx_buffer, 5);
+            //sock.send_all(rx_buffer, sizeof(rx_buffer)-1);
+            rx_in = 0;
+        }  
+    }   
       
     sock.close();
     
diff -r 72be2b8b7f24 -r e6c1c6be2f44 mbed-rtos.lib
--- a/mbed-rtos.lib	Wed May 14 15:07:26 2014 +0000
+++ b/mbed-rtos.lib	Thu Oct 26 16:52:09 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#5dfe422a963d
+http://mbed.org/users/mbed_official/code/mbed-rtos/#5713cbbdb706
diff -r 72be2b8b7f24 -r e6c1c6be2f44 mbed.bld
--- a/mbed.bld	Wed May 14 15:07:26 2014 +0000
+++ b/mbed.bld	Thu Oct 26 16:52:09 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/675da3299148
\ No newline at end of file