|
|
View previous topic :: View next topic |
Author |
Message |
noname3020
Joined: 16 Jun 2013 Posts: 2
|
Problem with tcp/ip stack |
Posted: Fri Jun 21, 2013 8:52 pm |
|
|
Hi,
I'm using the tcp/ip stack with example 13b.c
I'm using pic18f4520 to send data from rs232 to to the TCP_client.exe. But i don't know why my board only send data for about 30s then it did not continue sending. i could still ping to my board but the TCP_client.exe didn't receive anything.
When I pressed disconnect and then pressed connect again in the application TCP_client.exe, or when I reset my board, the data was started sending. But after about 30s, my problem happen again.
Code: | void MyTCPTask() {
static TICKTYPE lastTick[NUM_LISTEN_SOCKETS];
static TCP_SOCKET socket[NUM_LISTEN_SOCKETS]={INVALID_SOCKET};
static enum {
MYTCP_STATE_NEW=0, MYTCP_STATE_LISTENING=1,
MYTCP_STATE_CONNECTED=2, MYTCP_STATE_DISCONNECT=3,
MYTCP_STATE_FORCE_DISCONNECT=4
} state[NUM_LISTEN_SOCKETS]={0};
static NODE_INFO remote[NUM_LISTEN_SOCKETS];
TICKTYPE currTick;
char c;
int8 i;
currTick=TickGet();
for (i=0;i<NUM_LISTEN_SOCKETS;i++) {
switch (state[i]) {
case MYTCP_STATE_NEW:
socket[i]=TCPListen(EXAMPLE_TCP_PORT);
if (socket[i]!=INVALID_SOCKET) {
state[i]=MYTCP_STATE_LISTENING;
//sprintf(&lcd_str[i][0],"LISTENING");
}
else {
//sprintf(&lcd_str[i][0],"SOCKET ERROR");
}
break;
case MYTCP_STATE_LISTENING:
if (TCPIsConnected(socket[i])) {
state[i]=MYTCP_STATE_CONNECTED;
//sprintf(&lcd_str[i][0],"CONNECTED!");
lastTick[i]=currTick;
}
break;
case MYTCP_STATE_CONNECTED:
if (TCPIsConnected(socket[i])) {
if (TickGetDiff(currTick,lastTick[i]) > ((int16)TICKS_PER_SECOND * 300)) {
state[i]=MYTCP_STATE_DISCONNECT;
//sprintf(&lcd_str[i][0],"TIMEOUT");
lastTick[i]=currTick;
}
else {
if (TCPIsGetReady(socket)) {
while (TCPGet(socket, &c)){
//lcd_str[which][i++]=c;
//if (i>=20) {i=19;}
//lcd_str[which][i]=0;
}
}
for (j=0;j<40;j++) if (TCPIsPutReady(socket[i])) TCPPut(socket[i],data_u[j]);
TCPFlush(socket[i]);
}
}
else {
//sprintf(&lcd_str[i][0],"DISCONNECTED");
state[i]=MYTCP_STATE_FORCE_DISCONNECT;
}
break;
case MYTCP_STATE_DISCONNECT:
if (TCPIsPutReady(socket[i])) {
state[i]=MYTCP_STATE_FORCE_DISCONNECT;
}
else if (TickGetDiff(currTick, lastTick[i]) > (TICKS_PER_SECOND * 10)) {
state[i]=MYTCP_STATE_FORCE_DISCONNECT;
}
break;
case MYTCP_STATE_FORCE_DISCONNECT:
TCPDisconnect(socket[i]);
state[i]=MYTCP_STATE_LISTENING;
break;
}
}
} |
Code: | void main(void) {
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
enable_interrupts(INT_EXT);
enable_interrupts(INT_EXT1);
enable_interrupts(INT_EXT2);
MACAddrInit();
IPAddrInit();
StackInit();
while(TRUE) {
StackTask();
MyTCPTask();
}
} |
Please help me,
Thanks, |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
Posted: Sat Jun 22, 2013 2:48 am |
|
|
Looks like your DHCP lease is expiring.
You need to call DHCPTask() regularly. |
|
|
noname3020
Joined: 16 Jun 2013 Posts: 2
|
|
Posted: Sun Jun 23, 2013 3:45 am |
|
|
The original example has defined not to use DHCP. It only used ICMP, ARP and TCP. And it set the default IP address.
Code: | #define STACK_USE_ICMP 1
#define STACK_USE_ARP 1
#define STACK_USE_TCP 1
//------------------------------------------------
void IPAddrInit(void) {
//IP address of this unit
MY_IP_BYTE1=192;
MY_IP_BYTE2=168;
MY_IP_BYTE3=1;
MY_IP_BYTE4=50;
//network gateway
MY_GATE_BYTE1=192;
MY_GATE_BYTE2=168;
MY_GATE_BYTE3=1;
MY_GATE_BYTE4=1;
//subnet mask
MY_MASK_BYTE1=255;
MY_MASK_BYTE2=255;
MY_MASK_BYTE3=255;
MY_MASK_BYTE4=0;
} |
I saw at the function "TCPPut" in the "tcp.c" that the "RemoteWindow" decrease to 0 over time. When it reach 0, the function "TCPPut" won't put anything to transmit. But i didn't see anywhere increase or update the "RemoteWindow". Did i omit somewhere and is that the ploblem?
Code: | BOOL TCPPut(TCP_SOCKET s, BYTE byte)
{
SOCKET_INFO* ps;
WORD tempCount;
ps = &TCB[s];
// Make sure that the remote node is able to accept our data
if(ps->RemoteWindow == 0)
return FALSE;
if(ps->TxBuffer == INVALID_BUFFER)
{
ps->TxBuffer = MACGetTxBuffer(FALSE);
// Check to make sure that we received a TX Buffer
if(ps->TxBuffer == INVALID_BUFFER)
return FALSE;
ps->TxCount = 0;
IPSetTxBuffer(ps->TxBuffer, sizeof(TCP_HEADER));
}
ps->Flags.bIsTxInProgress = TRUE;
MACPut(byte);
ps->RemoteWindow--;
tempCount = ps->TxCount;
tempCount++;
ps->TxCount = tempCount;
if(tempCount >= MAX_TCP_DATA_LEN)
TCPFlush(s);
return TRUE;
} |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|