Yuliya Smirnova
/
h7adc
stm32h7 udp server with adc
main.cpp@0:837bd71aa81c, 2020-10-21 (annotated)
- Committer:
- yuliyasm
- Date:
- Wed Oct 21 21:02:41 2020 +0000
- Revision:
- 0:837bd71aa81c
- Child:
- 1:125ced0f8dd5
- Child:
- 2:fcb521c36965
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yuliyasm | 0:837bd71aa81c | 1 | #include "mbed.h" |
yuliyasm | 0:837bd71aa81c | 2 | #include "EthernetInterface.h" |
yuliyasm | 0:837bd71aa81c | 3 | #include "LWIPStack.h" |
yuliyasm | 0:837bd71aa81c | 4 | #include "ADE7912.h" |
yuliyasm | 0:837bd71aa81c | 5 | |
yuliyasm | 0:837bd71aa81c | 6 | EthernetInterface net; |
yuliyasm | 0:837bd71aa81c | 7 | |
yuliyasm | 0:837bd71aa81c | 8 | DigitalOut led1(LED1); |
yuliyasm | 0:837bd71aa81c | 9 | Thread thread; |
yuliyasm | 0:837bd71aa81c | 10 | |
yuliyasm | 0:837bd71aa81c | 11 | void UDP_thread() |
yuliyasm | 0:837bd71aa81c | 12 | { |
yuliyasm | 0:837bd71aa81c | 13 | printf("UDP Socket example\n"); |
yuliyasm | 0:837bd71aa81c | 14 | net.set_network(SocketAddress("192.168.0.10"), SocketAddress("255.255.255.0"), SocketAddress("192.168.0.1")); |
yuliyasm | 0:837bd71aa81c | 15 | if (0 != net.connect()) { |
yuliyasm | 0:837bd71aa81c | 16 | printf("Error connecting\n"); |
yuliyasm | 0:837bd71aa81c | 17 | } |
yuliyasm | 0:837bd71aa81c | 18 | |
yuliyasm | 0:837bd71aa81c | 19 | UDPSocket sock; |
yuliyasm | 0:837bd71aa81c | 20 | sock.open(&net); |
yuliyasm | 0:837bd71aa81c | 21 | sock.bind(55151); |
yuliyasm | 0:837bd71aa81c | 22 | SocketAddress receive("192.168.0.1", 55151); |
yuliyasm | 0:837bd71aa81c | 23 | |
yuliyasm | 0:837bd71aa81c | 24 | for(;;) { |
yuliyasm | 0:837bd71aa81c | 25 | char out_buffer[10] = "I am LED!"; |
yuliyasm | 0:837bd71aa81c | 26 | // sock.recvfrom(&receive, &out_buffer, sizeof(out_buffer)); |
yuliyasm | 0:837bd71aa81c | 27 | // printf(out_buffer); |
yuliyasm | 0:837bd71aa81c | 28 | if (0 > sock.sendto(receive, out_buffer, sizeof(out_buffer))) { |
yuliyasm | 0:837bd71aa81c | 29 | printf("Error sending data\n"); |
yuliyasm | 0:837bd71aa81c | 30 | } |
yuliyasm | 0:837bd71aa81c | 31 | printf(out_buffer); |
yuliyasm | 0:837bd71aa81c | 32 | ThisThread::sleep_for(2000); |
yuliyasm | 0:837bd71aa81c | 33 | } |
yuliyasm | 0:837bd71aa81c | 34 | } |
yuliyasm | 0:837bd71aa81c | 35 | |
yuliyasm | 0:837bd71aa81c | 36 | int main() |
yuliyasm | 0:837bd71aa81c | 37 | { |
yuliyasm | 0:837bd71aa81c | 38 | struct ADE7912_Phase_Settings a_phase; |
yuliyasm | 0:837bd71aa81c | 39 | thread.start(UDP_thread); |
yuliyasm | 0:837bd71aa81c | 40 | |
yuliyasm | 0:837bd71aa81c | 41 | while (true) { |
yuliyasm | 0:837bd71aa81c | 42 | led1 = !led1; |
yuliyasm | 0:837bd71aa81c | 43 | ThisThread::sleep_for(500); |
yuliyasm | 0:837bd71aa81c | 44 | } |
yuliyasm | 0:837bd71aa81c | 45 | } |