#include "udptrans.h" typedef struct { int socketSn; u32 localIP; u32 localPort; u32 remoteIP; u16 remotePort; }UdpCtrl; UdpCtrl g_udpCtrl; //------------------------------------------- #if (UDP_NUM > 0) //------------------------------------------- SocketCtrl g_udpSocket[UDP_NUM] = { {UDP_COMM, STA_INIT, UDP_SN_BEG+0, UDP_LOCAL_PORT_BEG+0}, #if (UDP_NUM > 1) {UDP_COMM, STA_INIT, UDP_SN_BEG+1, UDP_LOCAL_PORT_BEG+1}, #endif #if (UDP_NUM > 2) {UDP_COMM, STA_INIT, UDP_SN_BEG+2, UDP_LOCAL_PORT_BEG+2}, #endif #if (UDP_NUM > 3) {UDP_COMM, STA_INIT, UDP_SN_BEG+3, UDP_LOCAL_PORT_BEG+3}, #endif #if (UDP_NUM > 4) {UDP_COMM, STA_INIT, UDP_SN_BEG+4, UDP_LOCAL_PORT_BEG+4}, #endif #if (UDP_NUM > 5) {UDP_COMM, STA_INIT, UDP_SN_BEG+5, UDP_LOCAL_PORT_BEG+5}, #endif #if (UDP_NUM > 6) {UDP_COMM, STA_INIT, UDP_SN_BEG+6, UDP_LOCAL_PORT_BEG+6}, #endif #if (UDP_NUM > 7) {UDP_COMM, STA_INIT, UDP_SN_BEG+7, UDP_LOCAL_PORT_BEG+7}, #endif }; #endif void InitUdpTrans(void) { g_udpCtrl.socketSn = UDP_SN_BEG; g_udpCtrl.localIP = UDP_LOCAL_IP; g_udpCtrl.localPort = UDP_LOCAL_PORT_BEG; g_udpCtrl.remoteIP = UDP_REMOTE_IP; g_udpCtrl.remotePort = UDP_REMOTE_PORT; } int UdpTransData(u8 * pBuff, int len) { int rslt; rslt = sendto(g_udpCtrl.socketSn, pBuff, len, (u8*)(&g_udpCtrl.remoteIP), g_udpCtrl.remotePort); return rslt; } int UdpRecvData(u8 * pBuff, int len) { int rslt; u32 ip; u16 port; rslt = recvfrom(g_udpCtrl.socketSn, pBuff, len, (u8*)(&ip), &port); /* // 更新对方IP 和 PORT g_udpCtrl.remoteIP; g_udpCtrl.remotePort; */ return rslt; } SocketCtrl * GetUdpCtrlFromSocketId(int sIdx) { #if (UDP_NUM > 0) if (sIdx < UDP_NUM) { return &(g_udpSocket[sIdx]); } else #endif { return NULL; } }