Guest User

Untitled

a guest
Nov 27th, 2018
82
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "board.h"
  2.  
  3. #include "net/af.h"
  4. #include "net/protnum.h"
  5. #include "net/ipv6/addr.h"
  6. #include "net/sock/udp.h"
  7.  
  8. #include "shell.h"
  9.  
  10. #define BUFFER_SIZE (128U)
  11. #define UDP_PORT (32323U)
  12.  
  13. uint8_t data[BUFFER_SIZE];
  14.  
  15. extern void handle_udp_command(uint8_t * data);
  16. extern void send_ack(sock_udp_t * sock, sock_udp_ep_t * remote);
  17.  
  18. int main(void)
  19. {
  20. puts("RIOT OS");
  21.  
  22. sock_udp_ep_t local = SOCK_IPV6_EP_ANY;
  23. sock_udp_t sock;
  24.  
  25. local.port = UDP_PORT;
  26.  
  27. if (sock_udp_create(&sock, &local, NULL, 0) < 0)
  28. {
  29. return -1;
  30. }
  31. while (1)
  32. {
  33. sock_udp_ep_t remote;
  34. ssize_t res;
  35.  
  36. remote.port = UDP_PORT;
  37.  
  38. if ((res = sock_udp_recv(&sock, data, sizeof(data), SOCK_NO_TIMEOUT, &remote)) >= 0)
  39. {
  40. if (res > 0)
  41. {
  42. send_ack(&sock, &remote);
  43. handle_udp_command(data);
  44. }
  45. }
  46. }
  47.  
  48. return 0;
  49. }
RAW Paste Data