UpdateConfigRecord_Num(...) Destroys Boot Monitor...

Discussion to talk about software related topics only.
Post Reply
BMillikan
Posts: 14
Joined: Thu Dec 23, 2010 7:56 am

UpdateConfigRecord_Num(...) Destroys Boot Monitor...

Post by BMillikan »

I have some code that retrieves IP settings from a web page (through a POST command) and puts the data into a ConfigRecord. This all seems to work fine, however the code destroys the boot monitor despite a 2 second delay after the call before rebooting. This is currently a MOD5234 on a Mod-Dev-70 develpment card. Here is the code...

Code: Select all


bool SetIPHandler(int sock, char *url, char *pData, char *rxBuffer)
{
	char ippart1[20], ippart2[20], ippart3[20], ippart4[20];
	char ip[20];

	ConfigRecord *cr = RawGetConfig(0);
	ConfigRecord NewRec;

	// IP Address
	int res = ExtractPostData("ipaddr1",pData,ippart1,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("ipaddr2",pData,ippart2,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("ipaddr3",pData,ippart3,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("ipaddr4",pData,ippart4,20);
	if( res <= 0 ) return false;

	sprintf(ip,"%s.%s.%s.%s",ippart1,ippart2,ippart3,ippart4);
	NewRec.ip_Addr = AsciiToIp( ip );

	// Netmask
	res = ExtractPostData("netmask1",pData,ippart1,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("netmask2",pData,ippart2,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("netmask3",pData,ippart3,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("netmask4",pData,ippart4,20);
	if( res <= 0 ) return false;

	sprintf(ip,"%s.%s.%s.%s",ippart1,ippart2,ippart3,ippart4);
	NewRec.ip_Mask = AsciiToIp( ip );

	// Gateway
	res = ExtractPostData("ipgate1",pData,ippart1,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("ipgate2",pData,ippart2,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("ipgate3",pData,ippart3,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("ipgate4",pData,ippart4,20);
	if( res <= 0 ) return false;

	sprintf(ip,"%s.%s.%s.%s",ippart1,ippart2,ippart3,ippart4);
	NewRec.ip_GateWay = AsciiToIp( ip );

	// DNS
	res = ExtractPostData("dns1",pData,ippart1,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("dns2",pData,ippart2,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("dns3",pData,ippart3,20);
	if( res <= 0 ) return false;

	res = ExtractPostData("dns4",pData,ippart4,20);
	if( res <= 0 ) return false;

	sprintf(ip,"%s.%s.%s.%s",ippart1,ippart2,ippart3,ippart4);
	NewRec.ip_DNS_server = AsciiToIp( ip );

	dbprintf("Old Settings:\r\n");
	dbprintf("   IP:    %s\r\n", IPtoAscii(cr->ip_Addr));
	dbprintf("   Mask:  %s\r\n", IPtoAscii(cr->ip_Mask));
	dbprintf("   Gate:  %s\r\n", IPtoAscii(cr->ip_GateWay));
	dbprintf("   DNS :  %s\r\n", IPtoAscii(cr->ip_DNS_server));

	// Write new values to Flash system configuration sector
	UpdateConfigRecord_Num(&NewRec, 0);

	dbprintf("New Settings:\r\n");
	dbprintf("   IP:    %s\r\n", IPtoAscii(cr->ip_Addr));
	dbprintf("   Mask:  %s\r\n", IPtoAscii(cr->ip_Mask));
	dbprintf("   Gate:  %s\r\n", IPtoAscii(cr->ip_GateWay));
	dbprintf("   DNS :  %s\r\n", IPtoAscii(cr->ip_DNS_server));

	return true;
}
		if( SetIPHandler(sock,url,pData,rxBuffer) == true )
		{
			OSTimeDly( TICKS_PER_SECOND * 2 );
			//RedirectResponse( sock, "lriipok.htm" );
			ForceReboot();
		}
		else
		{
			//OSTimeDly( TICKS_PER_SECOND * 2 );
			RedirectResponse( sock, "lriipfail.htm" );
		}
User avatar
lgitlitz
Posts: 331
Joined: Wed Apr 23, 2008 11:43 am
Location: San Diego, CA
Contact:

Re: UpdateConfigRecord_Num(...) Destroys Boot Monitor...

Post by lgitlitz »

You create a new config record but only put in the values for IP, Mas, Gateway and DNS. The values for everything else will either be 0 or unknown. Everything else includes serial baud, boot time, MAC address... ext. Look at the following example in the build:
C:\nburn\examples\DHCP\ChangeIP
The key line of code you are missing right after you declare NewRec:
memcpy( &NewRec, cr, sizeof( NewRec ) );

-Larry
Post Reply