/*------------------------------------------------------------*/ /* Sample task of http */ /*------------------------------------------------------------*/ #include #include #include #include #include "lwip/sys.h" #include "lwip/api.h" #include "app_server.h" #include "TypeDef.h" #include "net.h" #include "http.h" #include "app.h" #include "includes.h" #include "web.h" #include "Matrix.h" #include "flash.h" #include "protocol.h" //by ming 2005-01 add counter & runtimer //static u32_t counter=0; void app_server_init(void); static INT32U tcpCtrlService(UCHAR *inbuf,UINT len,struct tcp_pcb* pcb,struct app_server_state *hs); static void send_bc_cmd(INT8 WebPageBuf[],INT32U nLen,INT32U nCladdr,INT32U nPort); static void EchoData(INT32U BodyLen,INT8 WebPageBuf[],struct tcp_pcb* pcb,struct app_server_state *hs); //*****************************************************************// extern INT8 html_message[30]; //ÍøÒ³ÇëÇó×Ö³¤×î¶à30¸ö×Ö½Ú extern INT32U G_PostPageLen; //POSTÒ³µÄ³¤¶È extern INT8 *G_PostPageWr; //POSTÒ³µÄдÈëÖ¸Õë extern INT16U G_session_time; //»á»°Ê±¼ä extern INT16U G_udpDeviceSaveSign; //UDPÉ豸ÉèÖñ£´æ±ê¼Ç extern SESSION G_Session[MAX_SESSION]; //WEB»á»°½á¹¹ extern INT16U G_MacId; //´«µÝÎïÀíµØÖ·£¬WEBµÄsetÒ³×Ô¶¯°´ÐÐÊý·­Ò³ extern INT8U G_SetPage; //ÉϴηÃÎʵÄSETÒ³£¬ÓÃÓÚË¢ÐÂ×Ô¶¯×ªÌøÕýÈ·ÐÐ extern INT8U G_SetPageNow; //Ä¿Ç°·ÃÎʵÄSETÒ³ extern INT8U G_HttpSendDelay; //HTTP´«ËÍÐèÒªÑÓʱ£¬µ¼³öÅäÖúͺêµÄʱºò£¬Ç°Ê®ÃëÂýËÙ£¬Öð½¥ÌáËÙ extern INT32U G_UpdateSys; //=0½ûֹдµ×¶ËµØÖ·µÄFLASH£¬=1ϵͳ¸üв»ÏÞÖÆ //******************************************************************// extern CONNECTION conxn[]; extern INT16U G_TcpDataLen; //TCPÊý¾Ý°ü²é³¤¶È extern UCHAR debug; extern MY my; //WEBÉèÖÃÍøÂçÊý¾Ý //extern UCHAR outbuf_static[]; //¾²Ì¬·ÖÅäÄÚ´æ extern UCHAR app_outbuf_static[]; //¾²Ì¬·ÖÅäÄÚ´æ extern void chk_udp_link(void); extern void BrodcastMy(void); extern OS_EVENT *Flash_SEM; //±£´æÊý¾Ýµ½FLASHµÄÈÎÎñ extern UINT G_TcpWindow; //TCP¶Ô¶ËµÄ½ÓÊÕ´°¿Ú¡£ extern INT8U G_IE_Refresh; //=1ÌύˢÐÂÖ÷Ò³ //--ÒÔÏ·®º£´º¶¨ÒåµÄº¯Êý--// extern void SyncOsdDisp(void); //Ë¢ÐÂËùÓмàµÄ×Ö·ûÑ¡Ïî extern void KeyBoardReLog(void); //·¢ÃüÁîÖØÆô¼üÅÌ£¬Í¬²½Êý¾Ý¡£ÐèҪͬ²½µÄÉèÖ㺠//1¡¢ÉèÖÃÉãÏñ»ú2¡¢ÉèÖüàÊÓÆ÷3¡¢ÉèÖñ¨¾¯µã //4¡¢ÉèÖÃOSD 5¡¢¸ü¸ÄÓû§Ãû³Æ6¡¢¸ü¸ÄÉ豸·ÖÇø£» extern INT32U chip_id; extern INT8U SendInf[]; extern INT8U nSendLen; extern sys_mbox_t keymbox; /*-----------------------------------------------------------------------------------*/ static void conn_err(void *arg, err_t err) { struct app_server_state *hs; #if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; cpu_sr = 0; #endif hs = arg; OS_ENTER_CRITICAL(); if(hs){ if(err == ERR_CONN||err==ERR_RST) udpDevice[hs->dev_num].st_now = UDP_BREAK; if(hs->pfile){ mem_free(hs->pfile); hs->pfile=NULL; } if(hs->rcvData){ mem_free(hs->rcvData); hs->rcvData=NULL; } mem_free(hs); } OS_EXIT_CRITICAL(); // Uart_Printf("%s\n",lwip_strerr(err)); } /*-----------------------------------------------------------------------------------*/ static err_t close_conn(struct tcp_pcb *pcb, struct app_server_state *hs) { err_t err; #if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; cpu_sr = 0; #endif // Uart_Printf("app_server¹Ø±ÕtcpÁ¬½ÓCLIENT=%d\n",hs->nClient); tcp_arg(pcb, NULL); tcp_sent(pcb, NULL); tcp_recv(pcb, NULL); if(hs){ if(hs->pfile){ mem_free(hs->pfile); hs->pfile=NULL; } if(hs->rcvData){ mem_free(hs->rcvData); hs->rcvData=NULL; } mem_free(hs); } OS_ENTER_CRITICAL(); err=tcp_close(pcb); OS_EXIT_CRITICAL(); return err; } /*-----------------------------------------------------------------------------------*/ static err_t app_send_data(struct tcp_pcb *pcb, struct app_server_state *hs) { err_t err; u16_t len; INT8U *outbuf; u16_t maxLen; /* We cannot send more data than space available in the send buffer. */ maxLen=tcp_sndbuf(pcb); if(maxLen < hs->left) { len = maxLen;//tcp_sndbuf(pcb); } else { len = hs->left; } if(!hs->file){ if(!hs->sentlen&&hs->HeadLen){ outbuf=app_outbuf_static; memcpy(outbuf,hs->Heade,hs->HeadLen); memcpy(outbuf+hs->HeadLen,hs->WebPageBuf+hs->sentlen,len-hs->HeadLen); }else { outbuf=hs->WebPageBuf+hs->sentlen-hs->HeadLen; // memcpy(outbuf,hs->WebPageBuf+hs->sentlen-hs->HeadLen,len); } // outbuf[len]=0; // Append NULL hs->file = outbuf; } do { err = tcp_write(pcb, hs->file, len, 1); if(err == ERR_MEM) { len /= 2; Uart_Printf("app_send_data err!\n"); } } while(err == ERR_MEM && len > 1); if(err == ERR_OK) { hs->file = NULL; hs->left -= len; hs->sentlen += len; } return err; } /*-----------------------------------------------------------------------------------*/ static err_t app_serv_poll(void *arg, struct tcp_pcb *pcb) { struct app_server_state *hs; err_t err=ERR_OK; #if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; cpu_sr = 0; #endif hs = arg; OS_ENTER_CRITICAL(); /* printf("Polll\n");*/ if(hs == NULL) { /* printf("Null, close\n");*/ tcp_abort(pcb); return ERR_ABRT; } else { ++hs->retries; if(hs->retries == 4) { tcp_abort(pcb); return ERR_ABRT; } err=app_send_data(pcb, hs); } OS_EXIT_CRITICAL(); return err; } /*-----------------------------------------------------------------------------------*/ static err_t app_serv_sent(void *arg, struct tcp_pcb *pcb, u16_t len) { struct app_server_state *hs; err_t err=ERR_OK; hs = arg; hs->retries = 0; if(hs->left > 0) { err=app_send_data(pcb, hs); } else if(udpDevice[hs->dev_num].SeriesSend==0) { err=close_conn(pcb, hs); } return err; } /*-----------------------------------------------------------------------------------*/ static err_t app_serv_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) { int i,nSaveDev=0; char *data,*pRcvData=NULL; struct app_server_state *hs; //by ming 2005.01 u8_t hour,min,sec; u16_t day; struct pbuf *q=NULL; int len=0; char szRcvBuf[1514]; hs = arg; if(err == ERR_OK && p != NULL) { /* Inform TCP that we have taken the data. */ tcp_recved(pcb, p->tot_len); if(hs->file == NULL) { data = p->payload; len = p->tot_len; //ÕûºÏpbufÖеÄÊý¾Ý q=p; if(q->tot_len>PBUF_POOL_BUFSIZE||!hs->rcvFinish) { data = pRcvData=szRcvBuf;//hs->rcvData; while(q) { if(q->payload) { memcpy(pRcvData,q->payload,q->len); pRcvData += q->len; } q=q->next; } pRcvData[0]=0; } //////////////////////// if(1) {//*data =='G'||*data =='P'||!hs->rcvFinish //TODO ÔÚÕâÀïÌí¼Óecho´¦Àí·þÎñ if(*data==ECHO_HEAD1 && *(data+1)==LINK_HEAD2 && *(data+5)==LINK_END1 && *(data+6)==LINK_END2) //Ìṩ»ØÀ¡·þÎñ { for(i=1;iremote_ip.addr==udpDevice[i].ipaddr.addr32) { hs->dev_num=i; udpDevice[i].hs = hs; hs->pcb=pcb; goto NEXT; //´æÔÚµÄÉ豸²»Ìí¼Ó }else if(udpDevice[i].ipaddr.addr32==0&&nSaveDev==0) { nSaveDev=i;//»ñÈ¡¿ÕÓàÉ豸´æ·ÅλÖà } } if(*data==ECHO_HEAD1 && *(data+1)==LINK_HEAD2 && *(data+5)==LINK_END1 && *(data+6)==LINK_END2) { if(*(data+2)>T_NO_DEV && *(data+2)remote_ip.addr; //ÊÕµ½Á¬½ÓÊý¾Ý£¬ÔÚÉ豸ÁбíÖÐÌí¼ÓÉ豸 udpDevice[i].type=*(data+2); //É豸ÀàÐÍ´ÓÁ¬½Ó°üÈ¡³ö udpDevice[i].model=*(data+3); udpDevice[i].timer=0; if(pcb->remote_port!=my.DevPort[udpDevice[i].type]) {//¶Ë¿Ú²»·ûÉèÖà sprintf((char *)udpDevice[i].discription,"%u¿Ú´íÓ¦%u",pcb->remote_port,my.DevPort[udpDevice[i].type]); } break; } } } } NEXT: EchoData(len,data,pcb,hs); } else for(i=1;iremote_ip.addr==udpDevice[i].ipaddr.addr32) { hs->dev_num=i; udpDevice[i].hs = hs; hs->pcb=pcb; udpDevice[i].st_now = UDP_LINK; tcpCtrlService(data,p->tot_len,pcb,hs); break; } } pbuf_free(p); tcp_sent(pcb, app_serv_sent); } //if(*data =='G') else { pbuf_free(p); err=close_conn(pcb, hs); } //else if(*data =='G') } //if(hs->file == NULL) else { pbuf_free(p); } } if(err == ERR_OK && p == NULL) { err=close_conn(pcb, hs); } return ERR_OK; } /*-----------------------------------------------------------------------------------*/ static err_t app_serv_accept(void *arg, struct tcp_pcb *pcb, err_t err) { struct app_server_state *hs; tcp_setprio(pcb, TCP_PRIO_MIN); /* Allocate memory for the structure that holds the state of the connection. */ hs = mem_malloc(sizeof(struct app_server_state)); if(hs == NULL) { return ERR_MEM; } /* Initialize the structure. */ #if 0 hs->file = NULL; hs->left = 0; hs->retries = 0; #else memset(hs,0,sizeof(struct app_server_state)); #endif /* Tell TCP that this is the structure we wish to be passed for our callbacks. */ tcp_arg(pcb, hs); /* Tell TCP that we wish to be informed of incoming data by a call to the app_serv_recv() function. */ tcp_recv(pcb, app_serv_recv); tcp_err(pcb, conn_err); tcp_poll(pcb, app_serv_poll, 4); return ERR_OK; } /*-----------------------------------------------------------------------------------*/ void app_server_init(void) { struct tcp_pcb *pcb; //by ming 2005.1 OSTimeSet((u32_t) 0x00000000); // counter = (u32_t) 0x00000000; pcb = tcp_new(); tcp_bind(pcb, IP_ADDR_ANY, my.DevPort[T_MATRIX]); pcb = tcp_listen(pcb); tcp_accept(pcb, app_serv_accept); Uart_Printf("=================APP SERV initialized =================\r\n"); } /*-----------------------------------------------------------------------------------*/ static err_t app_client_connected( void *arg, struct tcp_pcb *pcb, err_t err) { u16_t len; err_t error; struct app_server_state *rcvs; rcvs = arg; /* rcvs = mem_malloc(sizeof(struct app_server_state)); if( rcvs == NULL) { printf("\nMalloc error"); return ERR_MEM; } memset(rcvs,0,sizeof(struct app_server_state)); */ udpDevice[rcvs->dev_num].st_now = UDP_LINK; if( err == ERR_OK) { // tcp_arg( pcb, rcvs); err=app_send_data(pcb, rcvs); err=close_conn(pcb, rcvs); return err; } else { return err; } } /*-----------------------------------------------------------------------------------*/ void app_client_init(INT8U *sp,INT8U Len,INT8U DeviceNum) { err_t err; struct tcp_pcb *pcb; struct ip_addr remote_addr; struct app_server_state *rcvs; INT8U* pBuff; pcb = tcp_new(); if( pcb == NULL) { printf("\nNot enough memory to create new connection"); return; } printf("\nCreat pcb successfully"); rcvs = mem_malloc(sizeof(struct app_server_state)); memset(rcvs,0,sizeof(struct app_server_state)); rcvs->dev_num = DeviceNum; pBuff = mem_malloc(Len); memcpy(pBuff,sp,Len); rcvs->WebPageBuf = pBuff; rcvs->pfile= pBuff; rcvs->BodyLen=Len; rcvs->left = Len; rcvs->nClient = 1; tcp_arg(pcb, rcvs); tcp_sent( pcb, app_serv_sent); tcp_recv( pcb, app_serv_recv); tcp_err( pcb, conn_err); tcp_poll( pcb, app_serv_poll, 4); err = tcp_connect( pcb, &udpDevice[DeviceNum].ipaddr, my.DevPort[T_KEYBOARD], app_client_connected); if( err == ERR_OK) { // printf("\ntcp_connect has been called successfully"); return; } else if ( err == ERR_MEM) { printf("\nNot enough memory ro enqueue the SYN"); return; } else { printf("\ntcp_connect has been failed"); return; } return; } static void EchoData(INT32U BodyLen,INT8 WebPageBuf[],struct tcp_pcb* pcb,struct app_server_state *hs) //nr-TCP connection number { hs->left=BodyLen; hs->WebPageBuf=WebPageBuf; hs->BodyLen = BodyLen; app_send_data(pcb, hs); } //¹¦ÄÜ£º½«ÏàÓ¦µÄWebʵÌå·¢ËͳöÈ¥ //²ÎÊý£ºWebµÄÍ·³¤¶È£¬WebµÄʵÌ峤¶È£¬WebµÄÍ·Êý¾Ý£¬WebµÄʵÌåÊý¾Ý£¬ static void SendData(INT32U BodyLen,INT8 WebPageBuf[],struct tcp_pcb* pcb,struct app_server_state *hs,INT32U nBCflag) //nr-TCP connection number { UINT i,len=0; u8_t err; i=nBCflag?nBCflag:hs->dev_num; if(udpDevice[i].type!=T_NO_DEV) { if(udpDevice[i].SendReady==1 && udpDevice[i].len==0) //len==0±íʾÖØ·¢Êý¾ÝÍê±Ï { len = FifoLen(udpSendBuf[i].rdp,udpSendBuf[i].wrp); if(len > 0) { if(nBCflag) { send_bc_cmd(&udpSendBuf[i].buf[udpSendBuf[i].rdp],len,udpDevice[i].ipaddr.addr32,my.DevPort[T_TERMINAL]); } else { hs->left=len; hs->WebPageBuf=&udpSendBuf[i].buf[udpSendBuf[i].rdp]; hs->BodyLen = len; hs->sentlen=0; app_send_data(pcb, hs); //udp_send1(&udpSendBuf[i].buf[udpSendBuf[i].rdp],i,len,0); } udpSendBuf[i].rdp = 0; udpSendBuf[i].wrp = 0; } udpDevice[i].SendReady = 0; } } else { udpSendBuf[i].rdp = 0; udpSendBuf[i].wrp = 0; // Çå¿ÕUDP»º³åÇø } } //TCP ·½Ê½·¢Ë͹㲥°ü // static void send_bc_cmd(INT8 WebPageBuf[],INT32U nLen,INT32U nCladdr,INT32U nPort) { struct netconn *conn,*newconn; struct netbuf *buf; struct ip_addr addr; char *data; err_t err=0; int i; /* ´´½¨Ò»¸öеÄÁ¬½Ó*/ conn = netconn_new(NETCONN_TCP); /* ÉèÖÃÔ¶³ÌÖ÷»úµÄIPµØÖ·*/ addr.addr = nCladdr; /* Á¬½ÓÔ¶³ÌÖ÷»ú*/ err=netconn_connect(conn, &addr, nPort); if(err == ERR_OK) { /* ·¢ËÍ*/ err = netconn_write(conn, WebPageBuf, nLen, NETCONN_NOCOPY); } netconn_close(conn); netconn_delete(conn); } #if 0 static void parse_client_data(UCHAR *inbuf,UINT len,struct tcp_pcb *pcb,struct app_server_state *hs) { UCHAR i,j; // Capture sender's port number and ip_addr // to send return message to UINT nSaveDev=1; if(pcb->local_port==ECHO_PORT) //Ìṩ»ØÀ¡·þÎñ { for(i=1;iremote_ip.addr==udpDevice[i].ipaddr.addr32 && pcb->remote_port==my.DevPort[udpDevice[i].type]) { udpDevice[i].timer=0; //Á¬½Ó³¬Ê±¼ÆʱÆ÷ÇåÁã // udp_echo_service(inbuf,udp->length-8,i); SendData(0,len,NULL,inbuf,pcb,hs);//¾ßÌåÉ豸¶Ë¿Ú return; } else if(pcb->remote_ip.addr==udpDevice[i].ipaddr.addr32) { goto NEXT; //´æÔÚµÄÉ豸²»Ìí¼Ó }else if(udpDevice[i].ipaddr.addr32==0&&nSaveDev==1) { nSaveDev=i;//»ñÈ¡¿ÕÓàÉ豸´æ·ÅλÖà } } // inbuf+=42; //È¥µô°üÍ· if(*inbuf==LINK_HEAD1 && *(inbuf+1)==LINK_HEAD2 && *(inbuf+5)==LINK_END1 && *(inbuf+6)==LINK_END2) { if(*(inbuf+2)>T_NO_DEV && *(inbuf+2)remote_ip.addr; //ÊÕµ½Á¬½ÓÊý¾Ý£¬ÔÚÉ豸ÁбíÖÐÌí¼ÓÉ豸 udpDevice[i].type=*(inbuf+2); //É豸ÀàÐÍ´ÓÁ¬½Ó°üÈ¡³ö udpDevice[i].model=*(inbuf+3); udpDevice[i].timer=0; if(pcb->remote_port!=my.DevPort[udpDevice[i].type]) {//¶Ë¿Ú²»·ûÉèÖà sprintf((char *)udpDevice[i].discription,"%u¿Ú´íÓ¦%u",pcb->remote_port,my.DevPort[udpDevice[i].type]); } break; } } } } // inbuf-=42; NEXT: udpDevice[MAX_DEV+1].ipaddr.addr32=pcb->remote_ip.addr; //±¸·ÝIP£¬ÓÃÓÚ·´À¡ my.DevPort[T_ECHO]=pcb->remote_port; //±£´æ¶Ë¿Ú£¬ÓÃÓÚ·´À¡ // udp_echo_service(inbuf,udp->length-8,MAX_DEV+1); //ECHOÐéÉ豸¶Ë¿Ú SendData(0,len,NULL,inbuf,pcb,hs); } else if(pcb->local_port==my.DevPort[T_MATRIX]) //Ìṩ¾ØÕó·þÎñ { for(i=1;iremote_ip.addr==udpDevice[i].ipaddr.addr32) && (udpDevice[i].set_st==UDP_LINK)) // fanhaichun20060522 { udpDevice[i].st_now=UDP_LINK; //˵Ã÷ÍøÂçͨ if(pcb->remote_port==my.DevPort[udpDevice[i].type]) { udpDevice[i].timer=0; //Á¬½Ó³¬Ê±¼ÆʱÆ÷ÇåÁã if(*(inbuf+42-42)==SEQ_HEAD && *(inbuf+44-42)==SEQ_END && *(inbuf+45-42)==SEQ_END) { //Ðè·´À¡µÄÊý¾Ý°ü if((FifoLen(udpRecBuf[i].rdp,udpRecBuf[i].wrp)+4)remote_port==ECHO_PORT) //ECHO·´À¡±¨ { udpDevice[i].timer=0; //Á¬½Ó³¬Ê±¼ÆʱÆ÷ÇåÁã } } } } } #endif static INT32U tcpCtrlService(UCHAR *inbuf,UINT len,struct tcp_pcb* pcb,struct app_server_state *hs) { // inbuf+=42; //È¥µô°üÍ· //³¤¶È±ØÐëСÓÚ»º³åÇøµÄ³¤¶È UCHAR dev_num=hs->dev_num; if((FifoLen(udpRecBuf[dev_num].rdp,udpRecBuf[dev_num].wrp)+len)<(UDPMAXREC-1)) { while(len--) { udpRecBuf[dev_num].buf[udpRecBuf[dev_num].wrp++]=*inbuf++; //ÕâÀォЭÒé½ÓÊÕµ½»·Ðлº³å¶ÓÁÐÖÐ if(udpRecBuf[dev_num].wrp>=UDPMAXREC) udpRecBuf[dev_num].wrp=0; } // sys_mbox_post(keymbox, hs); // OSSemPost(Keycode_parse_SEM); //·¢ËÍÐźÅÁ¿Í¨Öª½øÐÐÍøÂçЭÒé½âÎöÈÎÎñ Udp_Code_ProtocolExtend(dev_num); return 1; } else { // OSSemPost(Keycode_parse_SEM); //·¢ËÍÐźÅÁ¿Í¨Öª½øÐÐÍøÂçЭÒé½âÎöÈÎÎñ return 0; } } #define __UDPINTERFACE_C__ /*----------------------------------------------------------------------------- º¯ÊýÔ­ÐÍ: INT8U WriteNetFIFO(INT8U *sp,INT8U Len,INT8U DeviceNum) ¹¦ÄÜÃèÊö: -----------------------------------------------------------------------------*/ INT8U WriteNetFIFO(INT8U *sp,INT8U Len,INT8U DeviceNum) { #if 1 INT16U LeaveLen; INT32U counter; INT32U nBCflag=0; #if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr; cpu_sr = 0; #endif if(DeviceNum >= MAX_DEV){ DeviceNum %= MAX_DEV; nBCflag=DeviceNum; } if (Len > UDPMAXREC) return(FAILURE); // ÆôÓÿɿ¿Á¬½ÓÐèÒªÅжÏÊÇ·ñ¿ÉÒÔ·¢ËÍ if (G_matrix.UDP_FeedBack == 1) { counter = 0; while(udpDevice[DeviceNum].sendmode == FEED_BACK) { counter++; OSTimeDly(10); if (counter>500) udpDevice[DeviceNum].sendmode = NOR_SEND; } } LeaveLen = FifoLen(udpSendBuf[DeviceNum].wrp,udpSendBuf[DeviceNum].rdp); if (LeaveLen == 0) { LeaveLen = UDPMAXREC; } else if (LeaveLen <= 24) { LeaveLen = 1; } if (LeaveLen <= Len) { // ÊÇ·ñÆôÓÃÁ÷Á¿¿ØÖÆ if (G_matrix.UDP_FeedBack == 1) { if((udpDevice[DeviceNum].type == T_KEYBOARD)&&(DeviceNum != MAX_DEV)) { udpDevice[DeviceNum].sendmode = FEED_BACK; } } // ÊÇ·ñÆôÓÃÍøÂçµ÷ÊÔ #if NET_DEBUG ==1 if (DeviceNum==DeviceId_DEBUG) { udpDevice[DeviceNum].sendmode = NOR_SEND; } #endif udpDevice[DeviceNum].SendReady = 1; ////OSSemPost(TCPIP_SEM);// Æô¶¯·¢ËÍ if(nBCflag) { SendData(0,NULL,NULL,NULL,nBCflag); }else SendData(0,NULL,udpDevice[DeviceNum].hs->pcb,udpDevice[DeviceNum].hs,nBCflag); } // ½øÈëÁÙ½ç¶Î´úÂë OS_ENTER_CRITICAL(); if(udpSendBuf[DeviceNum].wrp >= UDPMAXREC) { udpSendBuf[DeviceNum].wrp = 0; } for(;Len!=0;Len--) { udpSendBuf[DeviceNum].buf[udpSendBuf[DeviceNum].wrp++] = *sp++; if(udpSendBuf[DeviceNum].wrp >= UDPMAXREC) { udpSendBuf[DeviceNum].wrp = 0; } } OS_EXIT_CRITICAL(); // ÊÇ·ñÊÇÁ¬Ðø·¢ËÍ if (udpDevice[DeviceNum].SeriesSend == 0&&!nBCflag)//nBCflag´ú±í¹ã²¥ÐèÒªÁ¬Ðø·¢£¬ { // ÊÇ·ñÆôÓÃÁ÷Á¿¿ØÖÆ if (G_matrix.UDP_FeedBack == 1) { if((udpDevice[DeviceNum].type == T_KEYBOARD)&&(DeviceNum != MAX_DEV)) { udpDevice[DeviceNum].sendmode = FEED_BACK; } } // ÊÇ·ñÆôÓÃÍøÂçµ÷ÊÔ #if NET_DEBUG ==1 if (DeviceNum==DeviceId_DEBUG) { udpDevice[DeviceNum].sendmode = NOR_SEND; } #endif udpDevice[DeviceNum].SendReady = 1; ////OSSemPost(TCPIP_SEM); if(nBCflag) { SendData(0,NULL,NULL,NULL,nBCflag); } else SendData(0,NULL,udpDevice[DeviceNum].hs->pcb,udpDevice[DeviceNum].hs,nBCflag); } #endif return(SUCCESS); } void SendBCData(INT8U *frame,INT8U len) { memcpy(SendInf,frame,len); nSendLen = len; OSSemPost(Broadcast_SEM); } //·¢Ë͹㲥Êý¾Ý #if 0 void udp_bcsend(INT8U *frame,INT8U len) { struct netconn *conn2; struct ip_addr addr; struct netbuf *buf; err_t err=0; char text[120]; /* create a new connection */ conn2 = netconn_new(NETCONN_UDP); /* reference the text into the netbuf */ //buf = netbuf_new(); //netbuf_ref(buf, text, sizeof(text)); //addr.addr = htonl(0x0a0a0a6a); //netconn_connect(conn1, buf->fromaddr, buf->fromport); //netconn_connect(conn1, &addr, 1234); addr.addr = my.ipaddr.addr32; netconn_bind(conn2, &addr, 6000); addr.addr = my.broadcast_ip.addr32;//0x0A0A0BA3 buf = netbuf_new(); if(frame&&buf) { // netbuf_ref(buf, frame, len); memcpy(text,frame,len); netbuf_ref(buf, text, len); if(!(err=netconn_connect(conn2, &addr, 6001))) { netconn_send(conn2, buf); } netbuf_delete(buf); buf=NULL; } /* deallocate connection and netbuf */ netconn_delete(conn2); //netbuf_delete(buf); } #else void udp_bcsend(INT8U *frame,INT8U len) { struct udp_pcb *udpstructreceive; struct ip_addr addr; struct netbuf *buf; err_t err=0; char text[120]; udpstructreceive = udp_new(); if(!udpstructreceive)return; addr.addr = my.ipaddr.addr32; udp_bind(udpstructreceive,&addr,6000); addr.addr = my.broadcast_ip.addr32;//0x0A0A0BA3 buf = netbuf_new(); if(frame&&buf) { // netbuf_ref(buf, frame, len); memcpy(text,frame,len); netbuf_ref(buf, text, len); if(!(err=udp_connect(udpstructreceive,&addr, 6001))) { udp_send(udpstructreceive,buf->p); } netbuf_delete(buf); buf=NULL; } udp_disconnect(udpstructreceive); udp_remove(udpstructreceive); } #endif