/* '======================================================================================================================================================== '=> [Start] About clsErrEventInfo '======================================================================================================================================================== '-------------------------------------------------------------------------------------------------------------------------------------------------------- '-> About Error Event Info '-------------------------------------------------------------------------------------------------------------------------------------------------------- ' ' [Build] ' Author: Jaan Doh ' Title: clsErrEventInfo ' Version: V0.2 ' Date: 12 Dec 2020 ' Category: System ' Notes: Shared generic error event info for use by framework objects ' '-------------------------------------------------------------------------------------------------------------------------------------------------------- '======================================================================================================================================================== '=> [Finish] About clsErrEventInfo '======================================================================================================================================================== */ #ifndef JD_ERROR_INFO2_MODULE #define JD_ERROR_INFO2_MODULE #include //-> Constants #define HUBDATA __attribute__((section(".hub"))) // const char ERRORTITLELEN = 32; const char ERRORDESCLEN = 64; // const char ETUNFORESEENLEN = 16; const char EDUNFORESEENLEN = 60; // const unsigned short eGBL_UNFORSEENERROR = 65535; // // //-> Variables (stored in shared hub ram) unsigned short HUBDATA _wSrcObjId; unsigned short HUBDATA _wErrId; char HUBDATA _baErrTitle[33]; // title=32chars + 1 for zero separator char HUBDATA _baErrDesc[65]; // desc=64chars + 1 for zero separator // //-> Unforeseen error text (stored in shared hub ram) char HUBDATA et_Unforeseen[] = {"Unforseen Error!"}; // len16+1 char HUBDATA ed_Unforeseen[] = {"An unforeseen error has occurred, please restart your device"}; //len=60+1 // // //-> Prototypes void Ei1Init(void); void Ei1ClearErrors(void); unsigned int Ei1ErrTitleAddr(void); //as int because it returns an address pointer unsigned int Ei1ErrDescAddr(void); //as int because it returns an address pointer unsigned short Ei1GetSrcObjId(void); void Ei1SetSrcObjId(unsigned short pwNewErrSrcObjId); unsigned short Ei1GetErrId(void); void Ei1SetErrId(unsigned short pwNewErrId); void Ei1GetErrTitle(unsigned int *ptrDestStrAddr); void Ei1SetErrTitle(unsigned int *ptrSrcStrAddr); void Ei1GetErrDesc(unsigned int *ptrDestStrAddr); void Ei1SetErrDesc(unsigned int *ptrSrcStrAddr); void Ei1SetErrorInfo(unsigned short pwSrcObjId, unsigned short pwErrId, unsigned int *ptrErrTitleTxt, unsigned int *ptrErrDescTxt); // // //-> Ei1Init void Ei1Init(void) { Ei1ClearErrors(); } //-> Ei1ClearErrors void Ei1ClearErrors(void) { char tmpPos; // tmpPos = 0; _wSrcObjId = 0; _wErrId = 0; while (tmpPos < ERRORDESCLEN+1) { if (tmpPos < ERRORTITLELEN+1) { _baErrTitle[tmpPos] = 0; } _baErrDesc[tmpPos] = 0; } } //-> Ei1MoveGenericString void Ei1MoveGenericString(unsigned int *plSrcStrAddr, unsigned int *plDestStrAddr, char pbMaxLen) { const char *tmpLen; // Get length of src-string tmpLen = strlen(plSrcStrAddr); // Limit length if over maxlen if (tmpLen > pbMaxLen) { tmpLen = pbMaxLen; } memcpy(plDestStrAddr, plSrcStrAddr, tmpLen); } //-> Ei1ErrTitleAddr unsigned int Ei1ErrTitleAddr(void) { return (int)(&_baErrTitle); } //-> Ei1ErrDescAddr unsigned int Ei1ErrDescAddr(void) { return (int)(&_baErrDesc); } //-> Ei1GetSrcObjId unsigned short Ei1GetSrcObjId(void) { return _wSrcObjId; } //-> Ei1SetSrcObjId void Ei1SetSrcObjId(unsigned short pwNewErrSrcObjId) { _wSrcObjId = pwNewErrSrcObjId; } //-> Ei1GetErrId unsigned short Ei1GetErrId(void) { return _wErrId; } //-> Ei1SetErrId void Ei1SetErrId(unsigned short pwNewErrId) { _wErrId = pwNewErrId; } //-> Ei1GetErrTitle void Ei1GetErrTitle(unsigned int *ptrDestStrAddr) { //memcpy(&_baErrTitle, ptrDestStrAddr, ERRORTITLELEN); Ei1MoveGenericString(&_baErrTitle, ptrDestStrAddr, ERRORTITLELEN); } //-> Ei1SetErrTitle void Ei1SetErrTitle(unsigned int *ptrSrcStrAddr) { //memcpy(ptrSrcStrAddr, &_baErrTitle, ERRORTITLELEN); Ei1MoveGenericString(ptrSrcStrAddr, &_baErrTitle, ERRORTITLELEN); } //-> Ei1GetErrDesc void Ei1GetErrDesc(unsigned int *ptrDestStrAddr) { //memcpy(&_baErrDesc, ptrDestStrAddr, ERRORDESCLEN); Ei1MoveGenericString(&_baErrDesc, ptrDestStrAddr, ERRORDESCLEN); } //-> Ei1SetErrDesc void Ei1SetErrDesc(unsigned int *ptrSrcStrAddr) { //memcpy(ptrSrcStrAddr, &_baErrDesc, ERRORDESCLEN); Ei1MoveGenericString(ptrSrcStrAddr, &_baErrDesc, ERRORDESCLEN); } //-> Ei1SetErrorInfo void Ei1SetErrorInfo(unsigned short pwSrcObjId, unsigned short pwErrId, unsigned int *ptrErrTitleTxt, unsigned int *ptrErrDescTxt) { //-> Info // This method raises an error by populatng the error object fields with valid data and thus officiating the error // The user must call the PRintERROR method directly after calling this method to PRint the ERROR to the SCREEN //-> Process request if (pwErrId > 0) { // Clear old error info Ei1ClearErrors; // Set error source object id _wSrcObjId = pwSrcObjId; // Set error id _wErrId = pwErrId; //-> Unforseen error if (pwErrId == eGBL_UNFORSEENERROR) { // Store user friendly error title in error title //memcpy(&_baErrTitle, &et_Unforeseen, ETUNFORESEENLEN); Ei1MoveGenericString(&et_Unforeseen, &_baErrTitle, ETUNFORESEENLEN); // // Store user friendly error message in error description //memcpy(&_baErrDesc, &ed_Unforeseen, EDUNFORESEENLEN); Ei1MoveGenericString(&ed_Unforeseen, &_baErrDesc, EDUNFORESEENLEN); } //-> Foreseen error else { // Store user friendly error title in error title //memcpy(&_baErrTitle, ptrErrTitleTxt, ERRORTITLELEN); Ei1MoveGenericString(ptrErrTitleTxt, &_baErrTitle, ERRORTITLELEN); // // Store user friendly error message in error description //memcpy(&_baErrDesc, ptrErrDescTxt, ERRORDESCLEN); Ei1MoveGenericString(ptrErrDescTxt, &_baErrDesc, ERRORDESCLEN); } } } #endif /* '-------------------------------------------------------------------------------------------------------------------------------------------------------- '-> Terms Of Use : MIT Licence '-------------------------------------------------------------------------------------------------------------------------------------------------------- 'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 'to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 'and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, ' 'Subject to the following conditions: ' The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. ' ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, ' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ' IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, ' TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ' '-------------------------------------------------------------------------------------------------------------------------------------------------------- */