You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #include <lwip/sockets.h>
  6. #include <stdbool.h>
  7. #include "lwip/api.h"
  8. #include "lwip/opt.h"
  9. #include "lwip/sys.h"
  10. #include "project_configs.h"
  11. typedef struct udp_s udp_t;
  12. typedef void (*udp_on_packet_t)(udp_t *udp_handler, struct sockaddr_in *client, uint8_t *data, uint16_t len);
  13. struct udp_s {
  14. struct sockaddr_in server;
  15. int sock_fd;
  16. osThreadId rx_thread;
  17. char *rxbuf;
  18. int rxbuf_len;
  19. udp_on_packet_t on_packet;
  20. void *data;
  21. const char *name;
  22. };
  23. typedef struct {
  24. struct sockaddr_in server;
  25. int sock_fd;
  26. } udp_broadcast_handler_t;
  27. bool xs_udp_init(udp_t *udp_handler, const char *name, uint16_t port, udp_on_packet_t on_packet, int32_t rxbuf_size, void *data);
  28. int xs_udp_send_message(udp_t *udp_handler, const char *remoteip, int remoteport, const char *data, int len);
  29. int xs_udp_send_message2(udp_t *udp_handler, struct sockaddr_in *add, const char *data, int len);
  30. bool xs_udp_broadcast_init(udp_broadcast_handler_t *handler, uint16_t localport);
  31. bool xs_udp_broadcast(udp_broadcast_handler_t *handler, uint32_t remoteport, uint8_t *data, size_t datalen);
  32. #ifdef __cplusplus
  33. }
  34. #endif