I am logging to the eeprom exceptions that may be generated by functions e.g: failure to send an email or failure to to get time from ntp etc. I organized the eeprom into 512 8 byte records, each stores
'unix time stamp' of the exception (4 bytes)
'who' is generating the error (1 byte) generally this is a function or a piece of code in a function
'expected' value (1 byte)
'actual' actual value (1 byte)
'extra' unused byte (1 byte)
It works perfectly well and upon start-up I have the ability to dump the eeprom.
My concern is to find a systematic and quasi automatic way for the assignment of the 'who' numbers in such a way that they be unique and, of course that I keep trace of who's who when i make a post mortem analysis
Use #define's to allocate numbers to function names (#define 10 GET_NTP_TIME) and in the function getNtpTime() you call the error logger with GET_NTP_TIME as the who value.
Keeping all the defines together at top of code makes tracking additions & changes easier than going through several separate functions.
enum ErrorWho_t
{
WHO_UNDEFINED,
WHO_SETUP, // Error occurred in Setup()
WHO_LOOP, // Error occurred in Loop()
WHO_FUNC1, // Error occurred in Func1()
// etc..
};
ErrorWho_t who = WHO_UNDEFINED;
int Func1(int somearg)
{
// Do whatever...
if (BlowChunks)
LogException(WHO_FUNC1, expected, got, extra);
}
This will create symbols for , WHO_UNDEFINED (== 0), WHO_SETUP (== 1), WHO_LOOP (== 2), WHO_FUNC1 (== 3), etc. that you can use just like #defines, and each value will be unique.