testing code for analog_in
Dependencies: EthernetInterface FastAnalogIn mbed-rtos mbed
Diff: main2.txt
- Revision:
- 0:e066babe3c39
diff -r 000000000000 -r e066babe3c39 main2.txt --- /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