Data sendback over ethernet from mbed

Dependencies:   EthernetInterface FastAnalogIn mbed-rtos mbed

Fork of Ananlog_in_test by Michael Coe

Files at this revision

API Documentation at this revision

Comitter:
michaelcoe
Date:
Tue Oct 21 19:53:05 2014 +0000
Child:
1:27168b548705
Commit message:
Commit code for testing

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
FastAnalogIn.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
main.txt Show annotated file Show diff for this revision Revisions of this file
main2.txt 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Tue Oct 21 19:53:05 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#5887ae6c0c2c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FastAnalogIn.lib	Tue Oct 21 19:53:05 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/FastAnalogIn/#31184aa1449c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 21 19:53:05 2014 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+#include "FastAnalogIn.h"
+#include "EthernetInterface.h"
+ 
+AnalogIn input1(p15);
+AnalogIn input2(p16);
+AnalogIn input3(p17);
+AnalogIn input4(p18);
+DigitalOut led1(LED1);
+Timer t;
+
+const int BROADCAST_PORT = 58083;
+
+struct packet{
+   int times[512];
+   uint16_t samples1[512];
+   uint16_t samples2[512];
+   uint16_t samples3[512];
+   uint16_t samples4[512];
+};
+
+int main() {
+    //Setting up the Ethernet
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    
+    UDPSocket sock;
+    sock.init();
+    sock.set_broadcasting();
+    
+    Endpoint broadcast;
+    broadcast.set_address("255.255.255.255", BROADCAST_PORT);
+    
+//    uint16_t sample_buffer[2560];
+    t.start();
+    t.reset();
+    t.start();
+    while(1){
+        packet sample_data;   
+        printf("Executing Read Loop");
+        for(int i=0; i<512; i++) {
+            sample_data.times[i] = 6;
+            //t.read_us();
+            sample_data.samples1[i] = 1;
+            //input1.read_u16();
+            sample_data.samples2[i] = 2;
+            //input2.read_u16();
+            sample_data.samples3[i] = 3;
+            //input3.read_u16();
+            sample_data.samples4[i] = 4;
+            //input4.read_u16();
+            //wait_ms(1);
+        }
+        
+        printf("Size of struct: %i \n", sizeof(sample_data));
+        printf("Copying to char array \n");
+        char* data = static_cast<char*>(static_cast<void*>(&sample_data));
+        //unsigned char *out_buffer = (char*) &sample_data;
+        
+        char out_buffer[6144];
+        memcpy(&out_buffer,&data,sizeof(packet));
+        //out_buffer[6144] = '\0';
+        
+        printf("Sending to Ethernet \n");
+        sock.sendTo(broadcast, out_buffer, sizeof(out_buffer));
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.txt	Tue Oct 21 19:53:05 2014 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+#include "FastAnalogIn.h"
+#include "EthernetInterface.h"
+ 
+AnalogIn input1(p15);
+AnalogIn input2(p16);
+AnalogIn input3(p17);
+AnalogIn input4(p18);
+DigitalOut led1(LED1);
+Timer t, t2;
+
+const int BROADCAST_PORT = 58083;
+ 
+int main() {
+    //Setting up the Ethernet
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    
+    UDPSocket sock;
+    sock.init();
+    sock.set_broadcasting();
+    
+    Endpoint broadcast;
+    broadcast.set_address("255.255.255.255", BROADCAST_PORT);
+    
+    uint16_t sample_buffer[2561];
+    sample_buffer[2560] = 0;
+
+    while(1){   
+        printf("Executing Read Loop");
+        t.start();
+        for(int i=0; i<512; i++) {
+            sample_buffer[i] = (uint16_t)t.read_us();
+            sample_buffer[i+512] = input1.read_u16();
+            sample_buffer[i+1024] = input2.read_u16();
+            sample_buffer[i+1536] = input3.read_u16();
+            sample_buffer[i+2048] = input4.read_u16();
+            //wait_ms(1);
+        }
+        t.stop();
+        t.reset();
+        t2.start();
+        
+        sample_buffer[2560] = (uint16_t)t2.read_us();
+        
+        printf("Copying to char array \n");
+        char out_buffer[5122];
+        memcpy(&out_buffer,&sample_buffer,sizeof(sample_buffer));
+        
+        printf("Sending to Ethernet \n");
+        sock.sendTo(broadcast, out_buffer, sizeof(out_buffer));
+        
+        t2.stop();
+        t2.reset();
+    }
+}   
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main2.txt	Tue Oct 21 19:53:05 2014 +0000
@@ -0,0 +1,66 @@
+#include "mbed.h"
+#include "FastAnalogIn.h"
+#include "EthernetInterface.h"
+ 
+AnalogIn input1(p15);
+AnalogIn input2(p16);
+AnalogIn input3(p17);
+AnalogIn input4(p18);
+DigitalOut led1(LED1);
+Timer t, t2;
+
+const int BROADCAST_PORT = 58083;
+ 
+struct data{
+   int times[512];
+   uint16_t sample_buffer[2048];
+   int send_time;
+}sample_data;
+
+int main() {
+    //Setting up the Ethernet
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    
+    UDPSocket sock;
+    sock.init();
+    sock.set_broadcasting();
+    
+    Endpoint broadcast;
+    broadcast.set_address("255.255.255.255", BROADCAST_PORT);
+    
+//    uint16_t sample_buffer[2560];
+    sample_data.send_time = 0;
+    
+    while(1){   
+        printf("Executing Read Loop");
+        t.start();
+        for(int i=0; i<512; i++) {
+            sample_data.times[i] = t.read_us();
+            sample_data.sample_buffer[i+512] = input1.read_u16();
+            sample_data.sample_buffer[i+1024] = input2.read_u16();
+            sample_data.sample_buffer[i+1536] = input3.read_u16();
+            sample_data.sample_buffer[i+2048] = input4.read_u16();
+            //wait_ms(1);
+        }
+        t.stop();
+        t.reset();
+        t2.start();
+        
+        printf("Copying to char array \n");
+        int len = sizeof(struct data);
+        char out_buffer[len];
+        memcpy(&out_buffer, &sample_data, len);
+        
+ //       char out_buffer[5120];
+//        memcpy(&out_buffer,&sample_buffer,sizeof(sample_buffer));
+        
+        printf("Sending to Ethernet \n");
+        sock.sendTo(broadcast, out_buffer, sizeof(out_buffer));
+        sample_data.send_time = t2.read_us();
+        
+        t2.stop();
+        t2.reset();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Oct 21 19:53:05 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#bd07334df5b1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 21 19:53:05 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013
\ No newline at end of file