We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi I use TCP library and my project work fine but when i receive a command from my client on PC and process data in my Embedded System it not work fine and tcp_check_send() return false!!!! This condition repeat in both Server and Client mode. I feel when i receive an command i must send any act before response it???
void send_data (U8 socket,U8 protocol, U8 p2val, U8 command) { U8 *sendbuf; /* UDP */ if (protocol == UDP) { /* Start Connection */ sendbuf = udp_get_buf (SENDLEN); sendbuf[0] = DIVICE_ADDREES_H; sendbuf[1] = DIVICE_ADDREES_L; sendbuf[2] = command; sendbuf[3] = p2val; udp_send (socket, rem_add.IP, 1001, sendbuf, SENDLEN); } /* TCP */ else if (protocol == TCP) { /* Start Connection */ switch (tcp_get_state(socket)) { case TCP_STATE_FREE: case TCP_STATE_CLOSED: tcp_connect (socket, rem_add.IP, rem_add.PORT, 0); break; case TCP_STATE_CONNECT: if (tcp_check_send (socket) != __FALSE) { sendbuf = tcp_get_buf(SENDLEN); sendbuf[0] = DIVICE_ADDREES_H; sendbuf[1] = DIVICE_ADDREES_L; sendbuf[2] = command; sendbuf[3] = p2val; tcp_send (socket, sendbuf, SENDLEN); } break; } } }
U16 tcp_callback (U8 soc, U8 evt, U8 *ptr, U16 par) { /* This function is called by the TCP module on TCP event */ /* Check the Net_Config.h for possible events. */ /* Make a reference to suppress compiler warnings. */ soc = soc; par = par; evt = evt; ptr = ptr; if (soc != socket_tcp_client && soc != socket_tcp_server) { return (0); } switch (evt) { case TCP_EVT_DATA: /* TCP data frame has arrived, data is located at *par1, */ /* data length is par2. Allocate buffer to send reply. */ procrec(soc,ptr); break; case TCP_EVT_CONREQ: /* Remote peer requested connect, accept it */ return (1); case TCP_EVT_CONNECT: /* The TCP socket is connected */ return (1); } return (0); } void procrec (U8 socket, U8 *buf) { U8 val=0; if(buf[0]!=DIVICE_ADDREES_H && buf[1]!=DIVICE_ADDREES_L){ return; } switch (buf[2]) { case SET_OUT_AND: setOutVal (buf[3],1); break; case SET_OUT_OR: setOutVal (buf[3],0); break; case CLR_OUT: clrOutVal (buf[3]); break; case QUERY_OUT: val=getOutVal(); send_data(socket,protocol,80,QUERY_OUT); break; case QUERY_IN: val=getInVal(); send_data(socket,protocol,80,QUERY_IN); break; } }
You can not send data from tcp_callback().