I'm designing a embedded system and we have to oftenly report system fault in different code module. So I decided to create a source file to keep the error log and I'm building a struct for that. So that, every module reporting the error log and store in a data structure directly instead of keep return a false from function. I would like to get some recommendation for the necessary members.
I have some idea on the member and would like to get some suggestion to add / optimize the data structure :
struct ErrLog
{
unsigned long ulDate; //Store the date of error occurs : [MSB YYMMDD LSB, decimal]
unsigned long ulTime; //Store the time of error occurs : [MSB HHMMSS LSB, decimal]
unsigned long ulCategory; //Store which category of error occurs : will define a list of number to indicate which category is in
char* cErrMsg; //Store the error msg : is a string actually but I'm working on embedded system so try not to include huge header file
unsigned long* ulErrData; //Store the error value package : in unsigned long array format
};
Although I have the idea but I not sure how the pointer going to work. If I assign a reference cErrMsg pointer to a local char array. Does the cErrMsg pointer value remain if the it leave the function block and the local char array is deleted.
For example:
unsigned long ConvertDecimalArrayToDecimal (unsigned char* ucArray, unsigned char ucLen)
{
unsigned long ulDecimal = 0;
unsigned char ucItr = 0;
//Error Log items
char cErrMsg[] = "Length missmatch while converting from decimal array to decimal";
unsigned long ulErrData[1];
ulErrData[0] = (unsigned long) ucLen;
if(ucSize>=4)
{
// error occur here, let say i have extern the data structure here call "SysErrLog". And ignore the error log storage size, I will use link list or fixed size array later on.
SysErrLog.ulDate = .... //will get date time from a function
SysErrLog.ulTime = .... //will get date time from a function
SysErrLog.ulCategory = ERR_TYPE_CONVERSION; //the value is define in header file, and let say value ONE
SysErrLog.cErrMsg = cErrMsg; //reference the msg from local array here.
SysErrLog.ulErrData = ulErrData; //reference the msg from local array here.
// *The last 2 assigns are for the pointer refrencing. I worry the value it pointing to will be wipe off after the code exit this function.
return 0xFFFFFFFF;
}
//conversion
for(ucItr=0; ucItr<ucLen; ucItr++)
{
if(ucItr!=0)
ulDecimal *= 0x100;
ulDecimal += ucArray[ucItr];
}
return ulDecimal;
}