采用CH579M芯片的設(shè)備,多播UDP模式下。100M域網(wǎng)內(nèi),掛載200+臺其它設(shè)備和本設(shè)備。經(jīng)調(diào)試,當(dāng)設(shè)備收到多播請求,設(shè)備應(yīng)答時調(diào)用?CH57xNET_SocketUdpSendTo(...)? 得到?CH57xNET_ERR_UNKNOW(未知錯誤)。之后設(shè)備的 多播UDP-SOCKET端將永久接收不到請求數(shù)據(jù)。斷電重啟本設(shè)備,重復(fù)上述問題。本設(shè)備獨立組網(wǎng)是不會出現(xiàn) CH57xNET_ERR_UNKNOW?錯誤 。?兩種組網(wǎng)下ping包正常。
代碼如下:
/*?CH579相關(guān)定義?*/ UINT8?MACAddr[6]?=?{0x84,0xc2,0xe4,0x02,0x03,0x04};?????????????????????????????/*?CH579MAC地址?*/ UINT8?IPAddr[4]??=?{192,168,100,243};?????????????????????????????????????????????/*?CH579IP地址?*/ UINT8?GWIPAddr[4]=?{192,168,20,1};???????????????????????????????????????????????/*?CH579網(wǎng)關(guān)?*/ UINT8?IPMask[4]??=?{255,255,255,0};?????????????????????????????????????????????/*?CH579子網(wǎng)掩碼?*/ const?UINT8?DESIP[4]???=?{255,255,255,255}; UINT8?ackbuf[120]; UINT32?ablen;? void?CH57xNET_UdpServerRecv(struct?_SCOK_INF?*socinf,UINT32?ipaddr,UINT16?port,UINT8?*buf,UINT32?len) { ????UINT8?ip_addr[4],i; ????UINT8??ERR;??? ????PRINT("ipaddr=%-8x?port=%-8d?len=%-8d?socketid=%-4d\r\n",ipaddr,port,len,socinf->SockIndex); ????for(i=0;i>8;???? ????} ???? ????//?請求數(shù)據(jù)處理省略 ???? ????ERR?=?CH57xNET_SocketUdpSendTo(?socinf->SockIndex,ackbuf,&ablen,ip_addr,port); ????if?(CH57xNET_ERR_SUCCESS?==?ERR) ????????return; ????else?if?(CH57xNET_ERR_UNKNOW?!=?ERR)?{?//?此處報?-?CH57xNET_ERR_UNKNOW?未知錯誤 ????????PRINT("ERROR:?0x%X?\r\n",ERR); ????????//... ????} ????else?{?//?其它錯誤 ????????PRINT("ERROR:?0x%X?\r\n",ERR); ????} ???? ????//?錯誤處理todo } static?UINT8?s_muludpsock; static?UINT8?SocketRecvBuf[RECE_BUF_LEN]; void?CH57xNET_CreatUdpSocket(void) { ???UINT8?i;????????????????????????????????????????????????????????????? ???SOCK_INF?TmpSocketInf;???????????????????????????????????????????????????????/*?創(chuàng)建臨時socket變量?*/ ???memset((void?*)&TmpSocketInf,0,sizeof(SOCK_INF));????????????????????????????/*?庫內(nèi)部會將此變量復(fù)制,所以最好將臨時變量先全部清零?*/ ???memcpy((void?*)TmpSocketInf.IPAddr,DESIP,4);?????????????????????????????????/*?設(shè)置目的IP地址?*/ ???TmpSocketInf.DesPort?=?2000;?????????????????????????????????????????????????/*?設(shè)置目的端口?*/ ???TmpSocketInf.SourPort?=?2000;????????????????????????????????????????????????/*?設(shè)置源端口?*/ ???TmpSocketInf.ProtoType?=?PROTO_TYPE_UDP;?????????????????????????????????????/*?設(shè)置socekt類型?*/ ???TmpSocketInf.AppCallBack?=?CH57xNET_UdpServerRecv;???????????????????????????/*?接收回調(diào)函數(shù)?*/ ???TmpSocketInf.RecvStartPoint?=?(UINT32)SocketRecvBuf;?????????????????????????/*?設(shè)置接收緩沖區(qū)的接收緩沖區(qū)?*/ ???TmpSocketInf.RecvBufLen?=?RECE_BUF_LEN?;?????????????????????????????????????/*?設(shè)置接收緩沖區(qū)的接收長度?*/ ???i?=?CH57xNET_SocketCreat(&SocketId,&TmpSocketInf);???????????????????????????/*?創(chuàng)建socket,將返回的socket索引保存在SocketId中?*/ ???mStopIfError(i);?????????????????????????????????????????????????????????????/*?檢查錯誤?*/ ???s_muludpsock?=?i; } int?main(void)? { ????UINT8?i?=?0; GetMacAddr(MACAddr); ????i?=?CH57xNET_LibInit(IPAddr,GWIPAddr,IPMask,MACAddr);???????????????????????/*?庫初始化?*/ ????mStopIfError(i);????????????????????????????????????????????????????????????/*?檢查錯誤?*/ ????PRINT("CH57xNETLibInit?Success\r\n");???? Timer0Init(?10000?); ????????????????????????????????????????????????/*初始化定時器:10ms*/ NVIC_EnableIRQ(ETH_IRQn); while?(?CH57xInf.PHYStat?<?2?)?{ DelayMs(50); } ????CH57xNET_CreatUdpSocket();??????????????????????????????????????????????????/*?創(chuàng)建TCP?Socket?*/ ????PRINT("CH579?UDP?socket?create!\r\n");??? ????while(1) ????{ ????????CH57xNET_MainTask();????????????????????????????????????????????????????/*?CH57xNET庫主任務(wù)函數(shù),需要在主循環(huán)中不斷調(diào)用?*/ ????????if(CH57xNET_QueryGlobalInt())CH57xNET_HandleGlobalInt();????????????????/*?查詢中斷,如果有中斷,則調(diào)用全局中斷處理函數(shù)?*/ ????} }
?
CH57xNET_SocketUdpSendTo()?目標IP=192.168.100.112 ,PROT=6500
100網(wǎng)段PC一臺,本設(shè)備一臺,其它分20網(wǎng)段,10網(wǎng)段,30網(wǎng)段。