Data sendback over ethernet from mbed
Dependencies: EthernetInterface FastAnalogIn mbed-rtos mbed
Fork of Ananlog_in_test by
main.cpp@1:27168b548705, 2014-10-24 (annotated)
- Committer:
- apullin
- Date:
- Fri Oct 24 23:05:27 2014 +0000
- Revision:
- 1:27168b548705
- Parent:
- 0:e066babe3c39
Fixes to memory copy and pointers.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
michaelcoe | 0:e066babe3c39 | 1 | #include "mbed.h" |
michaelcoe | 0:e066babe3c39 | 2 | #include "FastAnalogIn.h" |
michaelcoe | 0:e066babe3c39 | 3 | #include "EthernetInterface.h" |
michaelcoe | 0:e066babe3c39 | 4 | |
michaelcoe | 0:e066babe3c39 | 5 | AnalogIn input1(p15); |
michaelcoe | 0:e066babe3c39 | 6 | AnalogIn input2(p16); |
michaelcoe | 0:e066babe3c39 | 7 | AnalogIn input3(p17); |
michaelcoe | 0:e066babe3c39 | 8 | AnalogIn input4(p18); |
michaelcoe | 0:e066babe3c39 | 9 | DigitalOut led1(LED1); |
michaelcoe | 0:e066babe3c39 | 10 | Timer t; |
michaelcoe | 0:e066babe3c39 | 11 | |
michaelcoe | 0:e066babe3c39 | 12 | const int BROADCAST_PORT = 58083; |
michaelcoe | 0:e066babe3c39 | 13 | |
apullin | 1:27168b548705 | 14 | typedef struct{ |
michaelcoe | 0:e066babe3c39 | 15 | int times[512]; |
michaelcoe | 0:e066babe3c39 | 16 | uint16_t samples1[512]; |
michaelcoe | 0:e066babe3c39 | 17 | uint16_t samples2[512]; |
michaelcoe | 0:e066babe3c39 | 18 | uint16_t samples3[512]; |
michaelcoe | 0:e066babe3c39 | 19 | uint16_t samples4[512]; |
apullin | 1:27168b548705 | 20 | } packet_t; |
michaelcoe | 0:e066babe3c39 | 21 | |
michaelcoe | 0:e066babe3c39 | 22 | int main() { |
apullin | 1:27168b548705 | 23 | |
apullin | 1:27168b548705 | 24 | packet_t sample_data; |
apullin | 1:27168b548705 | 25 | |
michaelcoe | 0:e066babe3c39 | 26 | //Setting up the Ethernet |
michaelcoe | 0:e066babe3c39 | 27 | EthernetInterface eth; |
michaelcoe | 0:e066babe3c39 | 28 | eth.init(); //Use DHCP |
michaelcoe | 0:e066babe3c39 | 29 | eth.connect(); |
michaelcoe | 0:e066babe3c39 | 30 | |
michaelcoe | 0:e066babe3c39 | 31 | UDPSocket sock; |
michaelcoe | 0:e066babe3c39 | 32 | sock.init(); |
michaelcoe | 0:e066babe3c39 | 33 | sock.set_broadcasting(); |
michaelcoe | 0:e066babe3c39 | 34 | |
michaelcoe | 0:e066babe3c39 | 35 | Endpoint broadcast; |
michaelcoe | 0:e066babe3c39 | 36 | broadcast.set_address("255.255.255.255", BROADCAST_PORT); |
michaelcoe | 0:e066babe3c39 | 37 | |
michaelcoe | 0:e066babe3c39 | 38 | // uint16_t sample_buffer[2560]; |
michaelcoe | 0:e066babe3c39 | 39 | t.start(); |
michaelcoe | 0:e066babe3c39 | 40 | t.reset(); |
michaelcoe | 0:e066babe3c39 | 41 | t.start(); |
michaelcoe | 0:e066babe3c39 | 42 | while(1){ |
michaelcoe | 0:e066babe3c39 | 43 | printf("Executing Read Loop"); |
michaelcoe | 0:e066babe3c39 | 44 | for(int i=0; i<512; i++) { |
michaelcoe | 0:e066babe3c39 | 45 | sample_data.times[i] = 6; |
michaelcoe | 0:e066babe3c39 | 46 | //t.read_us(); |
michaelcoe | 0:e066babe3c39 | 47 | sample_data.samples1[i] = 1; |
michaelcoe | 0:e066babe3c39 | 48 | //input1.read_u16(); |
michaelcoe | 0:e066babe3c39 | 49 | sample_data.samples2[i] = 2; |
michaelcoe | 0:e066babe3c39 | 50 | //input2.read_u16(); |
michaelcoe | 0:e066babe3c39 | 51 | sample_data.samples3[i] = 3; |
michaelcoe | 0:e066babe3c39 | 52 | //input3.read_u16(); |
michaelcoe | 0:e066babe3c39 | 53 | sample_data.samples4[i] = 4; |
michaelcoe | 0:e066babe3c39 | 54 | //input4.read_u16(); |
michaelcoe | 0:e066babe3c39 | 55 | //wait_ms(1); |
michaelcoe | 0:e066babe3c39 | 56 | } |
michaelcoe | 0:e066babe3c39 | 57 | |
michaelcoe | 0:e066babe3c39 | 58 | printf("Size of struct: %i \n", sizeof(sample_data)); |
michaelcoe | 0:e066babe3c39 | 59 | printf("Copying to char array \n"); |
apullin | 1:27168b548705 | 60 | //char* data = static_cast<char*>(static_cast<void*>(&sample_data)); |
apullin | 1:27168b548705 | 61 | char *out_buffer = (char*)(&sample_data); |
michaelcoe | 0:e066babe3c39 | 62 | |
apullin | 1:27168b548705 | 63 | //char out_buffer[6144]; |
apullin | 1:27168b548705 | 64 | //memcpy(out_buffer, data, sizeof(sample_data)); |
michaelcoe | 0:e066babe3c39 | 65 | //out_buffer[6144] = '\0'; |
michaelcoe | 0:e066babe3c39 | 66 | |
michaelcoe | 0:e066babe3c39 | 67 | printf("Sending to Ethernet \n"); |
apullin | 1:27168b548705 | 68 | //sock.sendTo(broadcast, out_buffer, sizeof(out_buffer)); |
apullin | 1:27168b548705 | 69 | sock.sendTo(broadcast, out_buffer, 6144); |
michaelcoe | 0:e066babe3c39 | 70 | } |
michaelcoe | 0:e066babe3c39 | 71 | } |