#pragma once #ifdef _WIN32 #include #define socklen_t int typedef unsigned int uint32_t; #else #include #include # define closesocket close #endif #include #include /** * @brief UDP Handler */ class UDPHandler { public: UDPHandler(unsigned short port = 9000); virtual ~UDPHandler(); int CreateSocket(); void Close(); bool Bind(); int Send(const char *buf, int size, char *ip, unsigned short port); int Recv(char *buf, int bufsize, sockaddr_in *from); int SetRecvTimeout(int sec); int SetSendTimeout(int sec); private: int usock = 0; unsigned short uport = 0; }; /** * @brief Transform a Data Struct to UDP buffer * * @tparam DataStruct an IMUUnitree or ScanUnitree * @param data * @param buffer * @param msgType * @return uint32_t the total bytes sent through udp */ template uint32_t dataStructToUDPBuffer(const DataStruct &data, uint32_t msgType, char *buffer);