#pragma once #ifdef __cplusplus extern "C" { #endif #include #include #include "lwip/api.h" #include "lwip/opt.h" #include "lwip/sys.h" #include "project_configs.h" typedef struct udp_s udp_t; typedef void (*udp_on_packet_t)(udp_t *udp_handler, struct sockaddr_in *client, uint8_t *data, uint16_t len); struct udp_s { struct sockaddr_in server; int sock_fd; osThreadId rx_thread; char *rxbuf; int rxbuf_len; udp_on_packet_t on_packet; void *data; const char *name; }; typedef struct { struct sockaddr_in server; int sock_fd; } udp_broadcast_handler_t; 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); int xs_udp_send_message(udp_t *udp_handler, const char *remoteip, int remoteport, const char *data, int len); int xs_udp_send_message2(udp_t *udp_handler, struct sockaddr_in *add, const char *data, int len); bool xs_udp_broadcast_init(udp_broadcast_handler_t *handler, uint16_t localport); bool xs_udp_broadcast(udp_broadcast_handler_t *handler, uint32_t remoteport, uint8_t *data, size_t datalen); #ifdef __cplusplus } #endif