Page 1 of 1

MOD54415 UDP packet formation issue

Posted: Thu Apr 25, 2013 6:38 am
by jediengineer
Hey all, having a little trouble with a UDP packet. This is my main while loop and it works correctly, but it's messy and it doesn't seem like it should:

while(1)
{
UDPPacket pkt;
pkt.SetSourcePort(portnum);
pkt.SetDestinationPort(portnum);

if (enabled == true)
{
siprintf (buffer, "System Running - main while loop \r\n");
pkt.AddData(buffer);

// send out the data:
{
UDPPacket pkt;
pkt.SetSourcePort(portnum);
pkt.SetDestinationPort(portnum);
pkt.AddData(buffer);
pkt.AddDataByte(0);
pkt.Send(ipaddr);
iprintf ("System enabled mode. \r\n");
}
OSTimeDly(TICKS_PER_SECOND / 10); // five second delay to give time to examine incoming UDP packet...

for (int i = 0; i < 32; i++)
{
buffer = 0; //zero the buffer
}

} //end if


else
{

siprintf (buffer, "system idle - main while loop \r\n");

{ // send out the data:
UDPPacket pkt;
pkt.SetSourcePort(portnum);
pkt.SetDestinationPort(portnum);
pkt.AddData(buffer);
pkt.AddDataByte(0);
pkt.Send(ipaddr);
iprintf("System idle mode. \r\n");
}

OSTimeDly(2*TICKS_PER_SECOND); // two second delay to give time to examine incoming UDP packet...
}//end else

}//end while(1)


I tried cleaning it up a bit, but it only crashes when I do:


while(1)
{
UDPPacket pkt;
pkt.SetSourcePort(portnum);
pkt.SetDestinationPort(portnum);

if (enabled == true)
{
siprintf (buffer, "System Running - main while loop \r\n");
pkt.AddData(buffer);
pkt.AddDataByte(0);
pkt.Send(ipaddr);
iprintf ("System enabled mode. \r\n");

OSTimeDly(TICKS_PER_SECOND / 10); // five second delay to give time to examine incoming UDP packet...

for (int i = 0; i < 32; i++)
{
buffer = 0; //zero the buffer
}
} //end if


else
{

siprintf (buffer, "system idle - main while loop \r\n");
pkt.AddData(buffer);
pkt.AddDataByte(0);
pkt.Send(ipaddr);
iprintf("System idle mode. \r\n");


OSTimeDly(2*TICKS_PER_SECOND); // two second delay to give time to examine incoming UDP packet...
}//end else

}//end while(1)


Anyone have any idea? Sorry, can't post any more code than this - sensitive nature. But I'll do what I can if anyone needs any more...

Re: MOD54415 UDP packet formation issue

Posted: Thu Apr 25, 2013 12:45 pm
by ecasey
A couple of things:

1. How big is buffer? I see you limit it to 32 characters in the for loop, but you siprintf more than 32 characters to it. If buffer isn't big enough, you will get a crash at some point. "System Running - main while loop \r\n" is 35 characters, I think.

2. (TICKS_PER_SECOND / 10) doesn't give you five seconds, if you need that much time.

Ed

Re: MOD54415 UDP packet formation issue

Posted: Fri Apr 26, 2013 6:45 am
by jediengineer
Hi Ed,

Sonofagun, I could swear I put both buffers (Another section of code has a UDP output) at 512. Apparently I missed it during the troubleshooting. the 5 second comment- I just forgot to update my comments. I know it's 1/10 second... But it works now, thanks!!

Tony