/* '======================================================================================================================================================== '=> [Start] About clsErrEventInfo '======================================================================================================================================================== '-------------------------------------------------------------------------------------------------------------------------------------------------------- '-> About Error Event Info '-------------------------------------------------------------------------------------------------------------------------------------------------------- ' ' [Build] ' Author: Jaan Doh ' Title: clsErrEventInfo ' Version: V0.3 ' 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 //#ifndef _STRING_H //#include //#endif #ifndef JD_STRING_METHODS_MODULE #include "clsJD_Library.h" #endif //-> 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(char *ptrDestStrAddr); void Ei1SetErrTitle(char *ptrSrcStrAddr); void Ei1GetErrDesc(char *ptrDestStrAddr); void Ei1SetErrDesc(char *ptrSrcStrAddr); void Ei1SetErrorInfo(unsigned short pwSrcObjId, unsigned short pwErrId, char *ptrErrTitleTxt, char *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; } } // The method below has been moved to an external file // //-> Ei1MoveGenericString // void Ei1MoveGenericString(char *plSrcStrAddr, char *plDestStrAddr, char pbMaxLen) // { // 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(char *ptrDestStrAddr) { //memcpy(&_baErrTitle, ptrDestStrAddr, ERRORTITLELEN); MoveGenericString(_baErrTitle, ptrDestStrAddr, ERRORTITLELEN); } //-> Ei1SetErrTitle void Ei1SetErrTitle(char *ptrSrcStrAddr) { //memcpy(ptrSrcStrAddr, &_baErrTitle, ERRORTITLELEN); MoveGenericString(ptrSrcStrAddr, _baErrTitle, ERRORTITLELEN); } //-> Ei1GetErrDesc void Ei1GetErrDesc(char *ptrDestStrAddr) { //memcpy(&_baErrDesc, ptrDestStrAddr, ERRORDESCLEN); MoveGenericString(_baErrDesc, ptrDestStrAddr, ERRORDESCLEN); } //-> Ei1SetErrDesc void Ei1SetErrDesc(char *ptrSrcStrAddr) { //memcpy(ptrSrcStrAddr, &_baErrDesc, ERRORDESCLEN); MoveGenericString(ptrSrcStrAddr, _baErrDesc, ERRORDESCLEN); } //-> Ei1SetErrorInfo void Ei1SetErrorInfo(unsigned short pwSrcObjId, unsigned short pwErrId, char *ptrErrTitleTxt, char *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); MoveGenericString(et_Unforeseen, _baErrTitle, ETUNFORESEENLEN); // // Store user friendly error message in error description //memcpy(&_baErrDesc, &ed_Unforeseen, EDUNFORESEENLEN); MoveGenericString(ed_Unforeseen, _baErrDesc, EDUNFORESEENLEN); } //-> Foreseen error else { // Store user friendly error title in error title //memcpy(&_baErrTitle, ptrErrTitleTxt, ERRORTITLELEN); MoveGenericString(ptrErrTitleTxt, _baErrTitle, ERRORTITLELEN); // // Store user friendly error message in error description //memcpy(&_baErrDesc, ptrErrDescTxt, ERRORDESCLEN); MoveGenericString(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. ' '-------------------------------------------------------------------------------------------------------------------------------------------------------- */