project_client_original

Dependencies:   C12832 EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
jw574
Date:
Thu Sep 07 14:03:23 2017 +0000
Commit message:
project_client_original

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
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 000000000000 -r c7b709c6ec3c C12832.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Thu Sep 07 14:03:23 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/chris/code/C12832/#7de323fa46fe
diff -r 000000000000 -r c7b709c6ec3c EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Thu Sep 07 14:03:23 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#4d7bff17a592
diff -r 000000000000 -r c7b709c6ec3c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 07 14:03:23 2017 +0000
@@ -0,0 +1,85 @@
+//project_client_original
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "C12832.h"
+
+C12832 lcd(D11, D13, D12, D7, D10);
+DigitalOut red(LED_RED);
+DigitalOut green(LED_GREEN);
+DigitalOut blue(LED_BLUE);
+
+static const char* SERVER_IP = "192.168.1.1";
+static const char* CLIENT_IP = "192.168.1.2";
+static const char* MASK = "255.255.255.0";
+static const char* GATEWAY = "192.168.1.1";
+EthernetInterface eth;
+//init 3 thread
+Thread *transmitter;
+Thread *receiver;
+Thread *init;
+void transmit(void const *args);
+void receive(void const *args);
+void init_eth(void const *args);
+int n;
+char counter[4]= {3,2,1,4};
+char counter1[4]= {0};
+//init eth point
+void init_eth(void const *args)
+{
+    eth.init(CLIENT_IP, MASK, GATEWAY);
+    int num=eth.connect();
+    if(num!=-1) {
+        transmitter= new Thread(transmit);
+        receiver=new Thread(receive);
+    }
+}
+//transmit function send information 
+void transmit(void const *args)
+{
+    Endpoint server;
+    UDPSocket sock;
+    sock.init();
+    server.set_address(SERVER_IP, 6503);
+    while(1) {
+        sock.sendTo(server, counter, sizeof(counter));
+        lcd.locate(0,3);
+        lcd.printf("send %d,%d,%d,%d",counter[0],counter[1],counter[2],counter[3]);
+        wait(3);
+    }
+}
+//receive function receive to array "counter1"
+void receive(void const *args)
+{
+    UDPSocket server;
+    Endpoint client;
+    server.bind(6500);
+    while(1) {
+        client.set_address(CLIENT_IP,6500);
+        n = server.receiveFrom(client, counter1, sizeof(counter1));
+        lcd.locate(0,15);
+        lcd.printf("receive %d,%d,%d,%d",counter1[0],counter1[1],counter1[2],counter1[3]);
+        if(counter1[3]==0) {
+            if (counter1[0]==0&&counter1[1]==0&&counter1[2]==1) {
+                red =0;
+                green=1;
+                blue=1;
+            } else if (counter1[0]==0&&counter1[1]==1&&counter1[2]==0) {
+                green =0;
+                red =1;
+                blue =1;
+            } else if(counter1[0]==1&&counter1[1]==0&&counter1[2]==0) {
+                blue = 0;
+                red =1;
+                green =1;
+            }
+        }
+    }
+}
+    int main() {
+        blue =1;
+        red =1;
+        green =1;
+        init=new Thread(init_eth);
+        while (true) {
+        }
+    }
\ No newline at end of file
diff -r 000000000000 -r c7b709c6ec3c mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Thu Sep 07 14:03:23 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#dfc27975e193
diff -r 000000000000 -r c7b709c6ec3c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Sep 07 14:03:23 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file