Dead MOD5282 - UGG!
Posted: Wed Sep 24, 2008 9:32 am
This post is a parallel to my MOD5282 DHCP post. I was attempting to change user flash and configuration record settings via the web page in my project. The settings seemed to take the first time, however, on the second attempt the MOD5282 has seemed to die. I thought that I had possibly put the unit in some strange state (i.e. infinate loop), but it seems that the unit no longer is functional. Specifically, I cannot find the unit on the network and I can no longer get any activity out of the serial port when I reset or power cycle. Thus, I cannot even download a previous "_APP.s19" file. The following code snippet is what was executed by the webpage post. Any hints? What can be done to resurrect the seemingly dead MOD5282?
int MyDoPost(int sock, char *url, char *pData1, char *rxBuffer)
{
bool bUserDataChanged = false;
bool bIpDataChanged = false;
//Used for changing runtime IP settings
InterfaceBlock *ib = GetInterFaceBlock(0);
//Used for changing flash IP settings
//get pointer to Configuration Record
ConfigRecord *cr = RawGetConfig(1);
//create new config record and copy data
ConfigRecord NewCr;
memcpy(&NewCr, cr, sizeof(NewCr));
//Determine which page issued the submit and process accordingly
sprintf(buffer, "%s", url);
if(strncmp(buffer, "/CONFIGURATION.htm", 17)==0)
{
//Load values from user flash
MyDataStoreStruct *pData = (MyDataStoreStruct *)GetUserParameters();
//Check for proper verification key
if ( pData->VerifyKey != VERIFY_KEY ) { return 0; }
int iPortNum = pData->iSoc;
char cSerialNum[5];
strncpy(cSerialNum, pData->cSerNo, 4);
cSerialNum[4] = '\0';
bool bUseDhcp;
if(pData->iDhcp == 1) { bUseDhcp = true; }
else { bUseDhcp = false; }
char cUserProdName[80];
strncpy(cUserProdName, pData->cName, 80);
cUserProdName[79] = '\0';
//Process user name input
if((ExtractPostData("w_cName", pData1, buffer, 16)!=-1))
{
strncpy(cUserProdName, buffer, 80);
bUserDataChanged = true;
}
//Process IP address input
if((ExtractPostData("w_cIpaddress", pData1, buffer, 16)!=-1))
{
char cTempIp[16];
strncpy(cTempIp, buffer, 15);
IPADDR newIpAddr = AsciiToIp(cTempIp);
//Update runtime setting
ib->netIP = newIpAddr;
//Update flash setting
NewCr.ip_Addr = newIpAddr;
bIpDataChanged = true;
}
//Process netmask input
if((ExtractPostData("w_cNetmask", pData1, buffer, 16)!=-1))
{
char cTempNm[16];
strncpy(cTempNm, buffer, 15);
IPADDR newIpMask = AsciiToIp(cTempNm);
//Update runtime setting
ib->netIpMask = newIpMask;
//Update flash setting
NewCr.ip_Mask = newIpMask;
bIpDataChanged = true;
}
//Process gateway input
if((ExtractPostData("w_cGateway", pData1, buffer, 16)!=-1))
{
char cTempGw[16];
strncpy(cTempGw, buffer, 15);
IPADDR newIpGate = AsciiToIp(cTempGw);
//Update runtime setting
ib->netIpGate = newIpGate;
//Update flash setting
NewCr.ip_GateWay = newIpGate;
bIpDataChanged = true;
}
//Process name server input
if((ExtractPostData("w_cNameserver", pData1, buffer, 16)!=-1))
{
char cTempNs[16];
strncpy(cTempNs, buffer, 15);
IPADDR newIpDNS = AsciiToIp(cTempNs);
//Update runtime setting
ib->netDNS = newIpDNS;
//Update flash setting
NewCr.ip_DNS_server = newIpDNS;
bIpDataChanged = true;
}
//Process socket port# input
if((ExtractPostData("w_iPort", pData1, buffer, 6)!=-1))
{
iPortNum = atoi(buffer);
bUserDataChanged = true;
}
//Store new settings to user flash
if (bUserDataChanged)
{
MyDataStore2.VerifyKey = VERIFY_KEY;
MyDataStore2.iSoc = iPortNum;
strncpy(MyDataStore2.cSerNo, cSerialNum, 4);
strncpy(MyDataStore2.cName, cUserProdName, 80);
if(bUseDhcp) { MyDataStore2.iDhcp = 1; }
else { MyDataStore2.iDhcp = 0; }
//Update user flash settings
SaveUserParameters(&MyDataStore2, sizeof(MyDataStore2));
}
//Store new settings to network flash configuration record
if (bIpDataChanged)
{ UpdateConfigRecord(&NewCr); }
RedirectResponse(sock, "CONFIGURATION.htm");
return 0;
}
else if(strncmp(buffer, "/UPDATE.htm", 10)==0)
{
return 0;
}
}
int MyDoPost(int sock, char *url, char *pData1, char *rxBuffer)
{
bool bUserDataChanged = false;
bool bIpDataChanged = false;
//Used for changing runtime IP settings
InterfaceBlock *ib = GetInterFaceBlock(0);
//Used for changing flash IP settings
//get pointer to Configuration Record
ConfigRecord *cr = RawGetConfig(1);
//create new config record and copy data
ConfigRecord NewCr;
memcpy(&NewCr, cr, sizeof(NewCr));
//Determine which page issued the submit and process accordingly
sprintf(buffer, "%s", url);
if(strncmp(buffer, "/CONFIGURATION.htm", 17)==0)
{
//Load values from user flash
MyDataStoreStruct *pData = (MyDataStoreStruct *)GetUserParameters();
//Check for proper verification key
if ( pData->VerifyKey != VERIFY_KEY ) { return 0; }
int iPortNum = pData->iSoc;
char cSerialNum[5];
strncpy(cSerialNum, pData->cSerNo, 4);
cSerialNum[4] = '\0';
bool bUseDhcp;
if(pData->iDhcp == 1) { bUseDhcp = true; }
else { bUseDhcp = false; }
char cUserProdName[80];
strncpy(cUserProdName, pData->cName, 80);
cUserProdName[79] = '\0';
//Process user name input
if((ExtractPostData("w_cName", pData1, buffer, 16)!=-1))
{
strncpy(cUserProdName, buffer, 80);
bUserDataChanged = true;
}
//Process IP address input
if((ExtractPostData("w_cIpaddress", pData1, buffer, 16)!=-1))
{
char cTempIp[16];
strncpy(cTempIp, buffer, 15);
IPADDR newIpAddr = AsciiToIp(cTempIp);
//Update runtime setting
ib->netIP = newIpAddr;
//Update flash setting
NewCr.ip_Addr = newIpAddr;
bIpDataChanged = true;
}
//Process netmask input
if((ExtractPostData("w_cNetmask", pData1, buffer, 16)!=-1))
{
char cTempNm[16];
strncpy(cTempNm, buffer, 15);
IPADDR newIpMask = AsciiToIp(cTempNm);
//Update runtime setting
ib->netIpMask = newIpMask;
//Update flash setting
NewCr.ip_Mask = newIpMask;
bIpDataChanged = true;
}
//Process gateway input
if((ExtractPostData("w_cGateway", pData1, buffer, 16)!=-1))
{
char cTempGw[16];
strncpy(cTempGw, buffer, 15);
IPADDR newIpGate = AsciiToIp(cTempGw);
//Update runtime setting
ib->netIpGate = newIpGate;
//Update flash setting
NewCr.ip_GateWay = newIpGate;
bIpDataChanged = true;
}
//Process name server input
if((ExtractPostData("w_cNameserver", pData1, buffer, 16)!=-1))
{
char cTempNs[16];
strncpy(cTempNs, buffer, 15);
IPADDR newIpDNS = AsciiToIp(cTempNs);
//Update runtime setting
ib->netDNS = newIpDNS;
//Update flash setting
NewCr.ip_DNS_server = newIpDNS;
bIpDataChanged = true;
}
//Process socket port# input
if((ExtractPostData("w_iPort", pData1, buffer, 6)!=-1))
{
iPortNum = atoi(buffer);
bUserDataChanged = true;
}
//Store new settings to user flash
if (bUserDataChanged)
{
MyDataStore2.VerifyKey = VERIFY_KEY;
MyDataStore2.iSoc = iPortNum;
strncpy(MyDataStore2.cSerNo, cSerialNum, 4);
strncpy(MyDataStore2.cName, cUserProdName, 80);
if(bUseDhcp) { MyDataStore2.iDhcp = 1; }
else { MyDataStore2.iDhcp = 0; }
//Update user flash settings
SaveUserParameters(&MyDataStore2, sizeof(MyDataStore2));
}
//Store new settings to network flash configuration record
if (bIpDataChanged)
{ UpdateConfigRecord(&NewCr); }
RedirectResponse(sock, "CONFIGURATION.htm");
return 0;
}
else if(strncmp(buffer, "/UPDATE.htm", 10)==0)
{
return 0;
}
}