testing code for analog_in

Dependencies:   EthernetInterface FastAnalogIn mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "FastAnalogIn.h"
00003 #include "EthernetInterface.h"
00004  
00005 AnalogIn input1(p15);
00006 AnalogIn input2(p16);
00007 AnalogIn input3(p17);
00008 AnalogIn input4(p18);
00009 DigitalOut led1(LED1);
00010 Timer t;
00011 
00012 const int BROADCAST_PORT = 58083;
00013 
00014 struct packet{
00015    int times[512];
00016    uint16_t samples1[512];
00017    uint16_t samples2[512];
00018    uint16_t samples3[512];
00019    uint16_t samples4[512];
00020 };
00021 
00022 int main() {
00023     //Setting up the Ethernet
00024     EthernetInterface eth;
00025     eth.init(); //Use DHCP
00026     eth.connect();
00027     
00028     UDPSocket sock;
00029     sock.init();
00030     sock.set_broadcasting();
00031     
00032     Endpoint broadcast;
00033     broadcast.set_address("255.255.255.255", BROADCAST_PORT);
00034     
00035 //    uint16_t sample_buffer[2560];
00036     t.start();
00037     t.reset();
00038     t.start();
00039     while(1){
00040         packet sample_data;   
00041         printf("Executing Read Loop");
00042         for(int i=0; i<512; i++) {
00043             sample_data.times[i] = 6;
00044             //t.read_us();
00045             sample_data.samples1[i] = 1;
00046             //input1.read_u16();
00047             sample_data.samples2[i] = 2;
00048             //input2.read_u16();
00049             sample_data.samples3[i] = 3;
00050             //input3.read_u16();
00051             sample_data.samples4[i] = 4;
00052             //input4.read_u16();
00053             //wait_ms(1);
00054         }
00055         
00056         printf("Size of struct: %i \n", sizeof(sample_data));
00057         printf("Copying to char array \n");
00058         char* data = static_cast<char*>(static_cast<void*>(&sample_data));
00059         //unsigned char *out_buffer = (char*) &sample_data;
00060         
00061         char out_buffer[6144];
00062         memcpy(&out_buffer,&data,sizeof(packet));
00063         //out_buffer[6144] = '\0';
00064         
00065         printf("Sending to Ethernet \n");
00066         sock.sendTo(broadcast, out_buffer, sizeof(out_buffer));
00067     }
00068 }