Here is the code from my web.cpp file as it is currently. Since the active task at the time of the crash was the HTTP task, I think the issue is/was in this file. The web page with the AJAX call was running the
Code: Select all
#include <startnet.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <math.h>
#include <autoupdate.h>
using namespace std;
//Define External Variables
extern const char* AppName;
extern unsigned long g_UptimeSeconds;
extern bool g_USUnits;
extern int g_DirectionTTL;
extern bool g_DirectionForward;
extern string g_IOCardVersion;
extern bool g_MaxOfflineDistanceOverrideActive;
extern int g_ReceiverTTL[];
extern double g_ReceiverDistance[2][2];
extern double g_ReceiverHeading[];
extern string g_ReceiverFields[2][12];
extern double g_Distances[2][2];
extern double g_WayPointHeading[];
extern double g_WayPointDistance[];
extern bool g_WayPointStraight[];
extern int g_WayPointCount;
extern int g_ActiveWayPointSegment;
extern double g_ActiveWayPointHeading;
char output[2000];
char fnum[20];
// Functions called from a web page must be declared extern C
extern "C" {
void DisplayFirmwareVersion(int sock, PCSTR url);
void DisplayIOCardVersion(int sock, PCSTR url);
void getAJAXSystemStatus(int sock, PCSTR url);
void getAJAXPathList(int sock, PCSTR url);
void RebootSystem();
void ReadUserSettings();
void WriteUserSettings();
void DisplayUnitsDropDown(int sock, PCSTR url);
}
// Structure for storing and retieving from user Flash
#define VERIFY_VALUE (0x48666050) //A random value picked from the phone book....
struct MyOwnDataStore {
DWORD verify_key;
bool USUnits;
};
void ReadUserSettings() { //Read the stored data
MyOwnDataStore *pData = (MyOwnDataStore*) GetUserParameters();
//Verify it has the right key value. In a "Real" application, a checksum would be more robust.
if (pData->verify_key == VERIFY_VALUE) { //Data is ok
if (pData->USUnits) {
g_USUnits = true;
iprintf("Loading System Settings: Using US units (feet).\r\n");
} else {
g_USUnits = false;
iprintf("Loading System Settings: Using metric units (meters).\r\n");
}
} else {
iprintf("System settings could not be read from NVRAM.\r\n");
}
}
void WriteUserSettings() {
MyOwnDataStore mds;
mds.USUnits = g_USUnits;
mds.verify_key = VERIFY_VALUE;
if (SaveUserParameters( &mds, sizeof(mds)) != 0) {
iprintf("Parameters saved in User Parameter area.\r\n");
} else {
iprintf("Programming failed \r\n");
}
}
int MyDoPost(int sock, char *url, char *pData, char *rxBuffer) {
iprintf("----- Processing Post -----\r\n");
iprintf("Post URL: %s\r\n", url);
iprintf("Post Data: %s\r\n", pData);
if (httpstricmp(url+1, "REBOOTSYSTEM")) {
//ExtractPostData("textForm1", pData, textForm1, MAX_BUF_LEN);
//iprintf("textForm1 set to: \"%s\"\r\n", textForm1 );
RebootSystem();
// Tell the web browser to issue a GET request for the next page
RedirectResponse(sock, "advanced.htm");
} else if (httpstricmp(url+1, "SETUNITS")) {
char newunits[20];
if (ExtractPostData("units", pData, newunits, 20) != -1) {
if (!strcmp(newunits, "metric")) {
g_USUnits = false;
iprintf("Setting units to Metric.\r\n");
} else if (!strcmp(newunits, "us")) {
g_USUnits = true;
iprintf("Setting units to Feet.\r\n");
} else {
iprintf("Specified units were not recognized.\r\n");
}
WriteUserSettings();
}
RedirectResponse(sock, "advanced.htm");
} else {
NotFoundResponse(sock, url);
iprintf("HTTP Post Form Processor: We did not match any page\r\n");
}
return 1;
}
void RegisterPost() {
SetNewPostHandler(MyDoPost);
}
void DisplayFirmwareVersion(int sock, PCSTR url) {
writestring(sock, AppName);
}
void DisplayIOCardVersion(int sock, PCSTR url) {
char output[100];
//siprintf(output, "%s", std::string(g_IOCardVersion).c_str());
siprintf(output, "%s", g_IOCardVersion.c_str());
writestring(sock, output);
}
void DisplayUnitsDropDown(int sock, PCSTR url) {
siprintf(output, "<select name=\"units\">");
if (g_USUnits) {
siprintf(output+strlen(output), "<option value=\"metric\">Metric (Meters)</option>");
siprintf(output+strlen(output), "<option value=\"us\" SELECTED>US (Feet)</option>");
} else {
siprintf(output+strlen(output), "<option value=\"metric\" SELECTED>Metric (Meters)</option>");
siprintf(output+strlen(output), "<option value=\"us\">US (Feet)</option>");
}
siprintf(output+strlen(output), "</select>");
writestring(sock, output);
}
void getAJAXSystemStatus(int sock, PCSTR url) {
unsigned long secs = g_UptimeSeconds;
unsigned int days = secs/86400; secs -= days*86400;
unsigned int hours = secs/3600; secs -= hours*3600;
unsigned int mins = secs/60; secs -= mins*60;
siprintf(output, "<table border=1 cellspacing=0 cellpadding=5>");
siprintf(output+strlen(output), "<tr><td colspan=3>System Uptime: %d Day", days);
if (days != 1) siprintf(output+strlen(output), "s");
siprintf(output+strlen(output), ", %d Hour", hours);
if (hours != 1) siprintf(output+strlen(output), "s");
siprintf(output+strlen(output), ", %d Minute", mins);
if (mins != 1) siprintf(output+strlen(output), "s");
siprintf(output+strlen(output), ", %d Second", secs);
if (secs != 1) siprintf(output+strlen(output), "s");
siprintf(output+strlen(output), "<br><br></td></tr>");
siprintf(output+strlen(output), "<tr><td>Travel Direction:</td><td colspan=2");
if (g_DirectionTTL == 0) {
siprintf(output+strlen(output), " bgcolor=#FF6666>I/O Card Not Available");
} else {
if (g_DirectionForward) {
siprintf(output+strlen(output), ">Forward");
} else {
siprintf(output+strlen(output), ">Reverse");
}
}
siprintf(output+strlen(output), "</td></tr>");
siprintf(output+strlen(output), "<tr><td>-</td><td><b>Receiver 1</b></td><td><b>Receiver 2</b></td></tr>");
siprintf(output+strlen(output), "<tr><td><b>Receiving Data</b></td>");
if (g_ReceiverTTL[0] == 0) {
siprintf(output+strlen(output), "<td bgcolor=#FF6666>No</td>");
} else {
siprintf(output+strlen(output), "<td bgcolor=#00FF00>Yes</td>");
}
if (g_ReceiverTTL[1] == 0) {
siprintf(output+strlen(output), "<td bgcolor=#FF6666>No</td>");
} else {
siprintf(output+strlen(output), "<td bgcolor=#00FF00>Yes</td>");
}
siprintf(output+strlen(output), "</tr>");
writestring(sock, output);output[0] = '\0'; //Clear output buffer
//siprintf(output+strlen(output), "<tr><td><b>GPS Solution Status</b></td><td>%s</td><td>%s</td></tr>", std::string(g_ReceiverFields[0][0]).c_str(), std::string(g_ReceiverFields[1][0]).c_str());
//siprintf(output+strlen(output), "<tr><td><b>GPS Position Type</b></td><td>%s</td><td>%s</td></tr>", std::string(g_ReceiverFields[0][1]).c_str(), std::string(g_ReceiverFields[1][1]).c_str());
//siprintf(output+strlen(output), "<tr><td><b>Satellites Tracked</b></td><td>%s</td><td>%s</td></tr>", std::string(g_ReceiverFields[0][9]).c_str(), std::string(g_ReceiverFields[1][9]).c_str());
//siprintf(output+strlen(output), "<tr><td><b>Satellites Used</b></td><td>%s</td><td>%s</td></tr>", std::string(g_ReceiverFields[0][10]).c_str(), std::string(g_ReceiverFields[1][10]).c_str());
siprintf(output+strlen(output), "<tr><td><b>GPS Solution Status</b></td><td>%s</td><td>%s</td></tr>", g_ReceiverFields[0][0].c_str(), g_ReceiverFields[1][0].c_str());
siprintf(output+strlen(output), "<tr><td><b>GPS Position Type</b></td><td>%s</td><td>%s</td></tr>", g_ReceiverFields[0][1].c_str(), g_ReceiverFields[1][1].c_str());
siprintf(output+strlen(output), "<tr><td><b>Satellites Tracked</b></td><td>%s</td><td>%s</td></tr>", g_ReceiverFields[0][9].c_str(), g_ReceiverFields[1][9].c_str());
siprintf(output+strlen(output), "<tr><td><b>Satellites Used</b></td><td>%s</td><td>%s</td></tr>", g_ReceiverFields[0][10].c_str(), g_ReceiverFields[1][10].c_str());
siprintf(output+strlen(output), "<tr><td><b>Vector Length</b></td><td>");
if (g_USUnits) { //*3.28084
double rf02 = atof(g_ReceiverFields[0][2].c_str());
double rf12 = atof(g_ReceiverFields[0][2].c_str());
sprintf(fnum, "%3.2f", rf02 * 3.28084);
siprintf(output+strlen(output), "%s ft", fnum);
sprintf(fnum, "%3.2f", rf12 * 3.28084);
siprintf(output+strlen(output), "</td><td>%s ft", fnum);
} else {
//siprintf(output+strlen(output), "%s m</td><td>%s m", std::string(g_ReceiverFields[0][2]).c_str(), std::string(g_ReceiverFields[1][2]).c_str());
siprintf(output+strlen(output), "%s m</td><td>%s m", g_ReceiverFields[0][2].c_str(), g_ReceiverFields[1][2].c_str());
}
siprintf(output+strlen(output), "</td></tr>");
//siprintf(output+strlen(output), "<tr><td><b>Vector Heading</b></td><td>%s°</td><td>%s°</td></tr>", std::string(g_ReceiverFields[0][3]).c_str(), std::string(g_ReceiverFields[1][3]).c_str());
//siprintf(output+strlen(output), "<tr><td><b>Vector Pitch</b></td><td>%s°</td><td>%s°</td></tr>", std::string(g_ReceiverFields[0][4]).c_str(), std::string(g_ReceiverFields[1][4]).c_str());
//siprintf(output+strlen(output), "<tr><td><b>Heading Accuracy</b></td><td>+/- %s°</td><td>+/- %s°</td></tr>", std::string(g_ReceiverFields[0][6]).c_str(), std::string(g_ReceiverFields[1][6]).c_str());
//siprintf(output+strlen(output), "<tr><td><b>Pitch Accuracy</b></td><td>+/- %s°</td><td>+/- %s°</td></tr>", std::string(g_ReceiverFields[0][7]).c_str(), std::string(g_ReceiverFields[1][7]).c_str());
siprintf(output+strlen(output), "<tr><td><b>Vector Heading</b></td><td>%s°</td><td>%s°</td></tr>", g_ReceiverFields[0][3].c_str(), g_ReceiverFields[1][3].c_str());
siprintf(output+strlen(output), "<tr><td><b>Vector Pitch</b></td><td>%s°</td><td>%s°</td></tr>", g_ReceiverFields[0][4].c_str(), g_ReceiverFields[1][4].c_str());
siprintf(output+strlen(output), "<tr><td><b>Heading Accuracy</b></td><td>+/- %s°</td><td>+/- %s°</td></tr>", g_ReceiverFields[0][6].c_str(), g_ReceiverFields[1][6].c_str());
siprintf(output+strlen(output), "<tr><td><b>Pitch Accuracy</b></td><td>+/- %s°</td><td>+/- %s°</td></tr>", g_ReceiverFields[0][7].c_str(), g_ReceiverFields[1][7].c_str());
writestring(sock, output);output[0] = '\0'; //Clear output buffer
siprintf(output+strlen(output), "<tr><td><BR><BR><b>Current Distance</b></td><td><BR><BR>");
if (g_USUnits) {
sprintf(fnum, "%3.2f", g_ReceiverDistance[0][0] * 3.28084);
siprintf(output+strlen(output), "%s ft", fnum);
} else {
sprintf(fnum, "%3.2f", g_ReceiverDistance[0][0]);
siprintf(output+strlen(output), "%s m", fnum);
}
siprintf(output+strlen(output), "</td><td><BR><BR>");
if (g_USUnits) {
sprintf(fnum, "%3.2f", g_ReceiverDistance[1][0] * 3.28084);
siprintf(output+strlen(output), "%s ft", fnum);
} else {
sprintf(fnum, "%3.2f", g_ReceiverDistance[1][0]);
siprintf(output+strlen(output), "%s m", fnum);
}
siprintf(output+strlen(output), "</td></tr>");
siprintf(output+strlen(output), "<tr><td><b>Offline Distance</b></td><td");
double dbl_od = fabs(g_ReceiverDistance[0][1]);
if (dbl_od > 0.5) {
if (dbl_od > 1) { //Red
siprintf(output+strlen(output), " bgcolor=#FF6666");
} else { //Yellow
siprintf(output+strlen(output), " bgcolor=#FFFF00");
}
}
if (g_USUnits) {
dbl_od *= 3.28084 * 12; //to feet, to inches
sprintf(fnum, "%3.1f", dbl_od);
siprintf(output+strlen(output), ">%s in", fnum);
} else {
sprintf(fnum, "%3.2f", dbl_od);
siprintf(output+strlen(output), ">%s m", fnum);
}
siprintf(output+strlen(output), "</td><td");
dbl_od = fabs(g_ReceiverDistance[1][1]);
if (dbl_od > 0.5) {
if (dbl_od > 1) { //Red
siprintf(output+strlen(output), " bgcolor=#FF6666");
} else { //Yellow
siprintf(output+strlen(output), " bgcolor=#FFFF00");
}
}
if (g_USUnits) {
dbl_od *= 3.28084 * 12; //to feet, to inches
sprintf(fnum, "%3.1f", dbl_od);
siprintf(output+strlen(output), ">%s in", fnum);
} else {
sprintf(fnum, "%3.2f", dbl_od);
siprintf(output+strlen(output), ">%s m", fnum);
}
siprintf(output+strlen(output), "</td></tr>");
if (g_MaxOfflineDistanceOverrideActive) {
siprintf(output+strlen(output), "<tr><td colspan=3 bgcolor=#FFFF00><b>Override of Maximum Offline Distance is Enabled</b></td><tr>");
}
siprintf(output+strlen(output), "</table>");
writestring(sock, output);
}
void getAJAXPathList(int sock, PCSTR url) {
if (g_WayPointCount == 0) {
siprintf(output, "There are no waypoints defined.<BR><BR>");
} else {
siprintf(output, "<table border=1 cellspacing=0 cellpadding=5>");
siprintf(output+strlen(output), "<tr><td>Heading<BR>(in Degrees)</td><td>Distance<BR>(in ");
if (g_USUnits) {
siprintf(output+strlen(output), "Feet");
} else {
siprintf(output+strlen(output), "Meters");
}
siprintf(output+strlen(output), ")</td><td>Path</td></tr>");
if (g_WayPointCount > 0) {
for (int i = 0; i < g_WayPointCount; i++) { //-1
if (i > 0 && i == g_ActiveWayPointSegment) { //Add the row showing current location
siprintf(output+strlen(output), "<tr><td bgcolor=#CCCCCC><b>");
sprintf(fnum, "%3.4f", g_ActiveWayPointHeading);
siprintf(output+strlen(output), "%s", fnum);
siprintf(output+strlen(output), "</b></td><td bgcolor=#CCCCCC><b>");
if (g_USUnits) {
sprintf(fnum, "%3.2f", g_ReceiverDistance[1][0] * 3.28084);
} else {
sprintf(fnum, "%3.2f", g_ReceiverDistance[1][0]);
}
siprintf(output+strlen(output), "%s", fnum);
siprintf(output+strlen(output), "</b></td><td bgcolor=#CCCCCC><b>Current Location");
siprintf(output+strlen(output), "</b></td></tr>");
}
siprintf(output+strlen(output), "<tr><td>");
sprintf(fnum, "%3.4f", g_WayPointHeading[i]);
siprintf(output+strlen(output), "%s", fnum);
siprintf(output+strlen(output), "</td><td>");
if (g_USUnits) {
sprintf(fnum, "%3.2f", g_WayPointDistance[i] * 3.28084);
} else {
sprintf(fnum, "%3.2f", g_WayPointDistance[i]);
}
siprintf(output+strlen(output), "%s", fnum);
siprintf(output+strlen(output), "</td><td>");
if (g_WayPointStraight[i]) {
siprintf(output+strlen(output), "Straight");
} else {
siprintf(output+strlen(output), "Arc");
}
siprintf(output+strlen(output), "</td></tr>");
writestring(sock, output);output[0] = '\0'; //Clear output buffer
}
}
siprintf(output+strlen(output), "</table>");
}
writestring(sock, output);
}
That call creates a table that looks like the image below. As you can see, current up time is 38 hours, no traps since I removed the std::string() stuff.