diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-03-06 12:09:02 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-03-06 12:09:02 +0200 |
| commit | fb2d080fbbcea3a91e598b4ea8837a230de6a319 (patch) | |
| tree | 6b3ce09a252d2ebab8189a92b3326ffbba6dbe4b /Software/Embedded_SW/Embedded/Common/report | |
| parent | d734bb5cf08ba2433b74fc86a8858d2437d1a237 (diff) | |
| download | Tango-fb2d080fbbcea3a91e598b4ea8837a230de6a319.tar.gz Tango-fb2d080fbbcea3a91e598b4ea8837a230de6a319.zip | |
A new forlder for embedded software in our common structure
Diffstat (limited to 'Software/Embedded_SW/Embedded/Common/report')
6 files changed, 2299 insertions, 0 deletions
diff --git a/Software/Embedded_SW/Embedded/Common/report/distributor.c b/Software/Embedded_SW/Embedded/Common/report/distributor.c new file mode 100644 index 000000000..38b9ccff8 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Common/report/distributor.c @@ -0,0 +1,851 @@ +/****************************************************************************** + * File name : distributor.c + * Title : REPORT PACKAGE - Message Distributor + * Date created : 01 SEP, 1996 + * Revision : 1.0 + * Author : Zvika Zilberman + * + * Description : Report distributor provides the duplicating of + * messages to the several destinations. + * + ****************************************************************************** + * + * Procedures: + * + * ReportFd - Add or remove file descriptor to/from the + * list of destinations + * ReportFunc - Add or remove funtion to/from the list of + * destnations + * ReportEnableAll - Resume the work of distributor + * + * Functions, internal for Report: + * + * distibutorInit - Initialize message distributor + * reportDistribute - Send message to destibutor + * + * Local functions: + * + * messageDistribute - Forward message to all destinations. + * reportService - Distibutor Task main function + * + ****************************************************************************** + * + * History: + * 01.09.96 Ilia Maller - start of coding + * 21.02.97 Ilia Maller - minor improvements + * 17.09.97 Zvika Zilberman - porting to DCME SWINFRA + * + ******************************************************************************/ + +/*------------- Includes --------------------------------*/ +#include "include.h" + +#include "report.h" +#include "filter.h" +#include "distributor.h" + +/*------------- Local Definitions -----------------------*/ + +#define SEVERITY_MASK(severity) ((severity) & 0x10) +#define REPORT_ROOT_NAME "system" +#define REPORT_TASK_STACK_SIZE 1024 + +typedef struct +{ + FormatType format; + char message[REPORT_MAX_MSG_LEN]; + char FileName[REPORT_MAX_MSG_LEN]; + int LineNumber; + int errorCode; + ErrorSeverity severity; + int parameter1; + int parameter2; +}INPUT_MESSAGE; + +#define INPUT_MESSAGE_LEN sizeof(INPUT_MESSAGE) + +typedef struct +{ + int fd; + ReportFunction function; +}DESTINATION; + +#define DESTINATION_SIZE sizeof(DESTINATION) + +#define NUM_OF_DESTINATIONS 4 +typedef struct +{ + char name[11]; + bool IsActive; /* false - discard its messages. true - send them. */ + bool IsAlive; /* false - if not in action, can not be used or seen */ + DESTINATION dest[NUM_OF_DESTINATIONS]; +} DistributorElement; + + +static void messageDistribute(char *msg, + int DistTableEntry, + char *FileName, + int LineNumber, + int errorCode, + int parameter1, + int parameter2); +/*static STATUS reportFormat(char *buffer, + int *maxlen, + const char *message, + int errorCode, + ErrorSeverity severity, + int parameter1, + int parameter2);*/ +static int FindFreeDestinationElement(int DistTableEntry); + +/*------------- Local Data ------------------------------*/ + +static Mailbox_Handle inputQueue; + +/* Table where output of distributor (destinations) stored + Every element of the table may be or file descriptor + or function address. + The destinations stored unsorted */ +static DistributorElement *Dist_Table; +static int DistCounter; /* number of current elements in the table */ +static int NumOfDistributions; + +/*************************************************************************** + * + * Name : distibutorInit + * + * Function : Initialize message distributor + * + * Notes : Function uses malloc for memory allocation + * + * Parameters: priority - distributor task priority + * maxMsgs - maximum number of messages stored in + * destributor task queue + * maxDstr - maximum number of distributors + * + * Return value: STATUS - OK or ERROR + **************************************************************************/ +STATUS distibutorInit( int priority, int maxMsgs, int maxDstr ) +{ + + static int initialized = false; + int i, j; + + if (initialized) + return OK; + + NumOfDistributions = maxDstr; + /* create mailbox to recive messages */ + inputQueue = Mailbox_create(INPUT_MESSAGE_LEN,maxMsgs, 0,0); + if (inputQueue == NULL) + return ERROR; + + /* create table for destionations. malloc takes care about allignment */ + Dist_Table = (DistributorElement *)malloc(sizeof(DistributorElement)*(maxDstr+1)); + if (Dist_Table == NULL) + return ERROR; + /* initialize table */ + for (i=0; i<=maxDstr; i++) + { + for (j=0; j<NUM_OF_DESTINATIONS; j++) + { + Dist_Table[i].dest[j].fd = -1; + Dist_Table[i].dest[j].function = NULL; + } + Dist_Table[i].IsActive = false; + Dist_Table[i].IsAlive = false; + } + /* Reset the internal (basic) distributor */ + strcpy(Dist_Table[0].name,REPORT_ROOT_NAME); + Dist_Table[0].IsActive = true; + Dist_Table[0].IsAlive = true; + + /* initialize local data */ + DistCounter = 1; + + initialized = true; + return OK; +} + + +/*************************************************************************** + * + * Name : reportDistribute + * + * Function : Send message to destibutor + * + * Notes : Function trancates message if it length grater + * than INPUT_MESSAGE_LEN + * + * Parameters: message - user message + * extErrorType - error type and severity + * errorCode - error code + * parameter1 - user parameter 1 + * parameter2 - user parameter 2 + * + * Return value: STATUS - OK or ERROR + **************************************************************************/ +STATUS reportDistribute(FormatType format, + const char *message, + char *FileName, + int LineNumber, + int errorCode, + ErrorSeverity severity, + int parameter1, + int parameter2) +{ + INPUT_MESSAGE msg; + int Distributor = GET_PRIVATE_SEVERITY(severity); + + if (Distributor > 0) + { + if (Dist_Table[Distributor].IsAlive == false) + return OK; + if (Dist_Table[Distributor].IsActive == false) + return OK; + } + else if (Dist_Table[0].IsActive == false) + return OK; + /* truncate if message length greater than defined */ + msg.format = format; + strncpy(msg.message, message, REPORT_MAX_MSG_LEN); + msg.errorCode = errorCode; + msg.severity = severity; + msg.parameter1 = parameter1; + msg.parameter2 = parameter2; + + if (inputQueue != NULL) + Mailbox_post(inputQueue , &msg, BIOS_NO_WAIT); + return OK; +} + + +/*************************************************************************** + * + * Name : reportService + * + * Function : Distibutor Task main function + * + * Notes : + * + * Return value: void + **************************************************************************/ +Void reportService(UArg arg0, UArg arg1) +{ + INPUT_MESSAGE msg; + //static char buf[REPORT_MAX_MSG_LEN + REPORT_MSG_FORMAT_LEN]; + int DistTableEntry;//,msgLen, errCode, par1, par2; + + while(1) + { + Mailbox_pend(inputQueue , &msg, BIOS_WAIT_FOREVER); + + DistTableEntry = (SEVERITY_MASK(msg.severity) == RpPrivate) ? (msg.severity >> 5) : 0; +// /* format received string */ +// /*if (msg.format == REPORT_FORMAT) +// { +// msgLen = REPORT_MAX_MSG_LEN + REPORT_MSG_FORMAT_LEN; +// reportFormat(buf, &msgLen, msg.message, msg.errorCode, +// msg.severity, msg.parameter1, msg.parameter2); +// errCode = msg.errorCode; +// par1 = msg.parameter1; +// par2 = msg.parameter2; +// } +// else /* MESSAGE_FORMAT - regular message */ +// { +// msgLen = strlen(msg.message); +// if (msgLen > REPORT_MAX_MSG_LEN-1) +// msgLen = REPORT_MAX_MSG_LEN-1; +// strcpy(buf,msg.message); +// errCode = 0; +// par1 = 0; +// par2 = 0; +// }*/ + /* send message to subscribers */ + messageDistribute( msg.message, DistTableEntry,msg.FileName, msg.LineNumber,msg.errorCode,msg.severity,msg.parameter2); + } +} + +/*----------------------------------------------------------------------------*/ +/*----------------------------- Private Severity -----------------------------*/ +/*----------------------------------------------------------------------------*/ + +/*************************************************************************** + * + * Name : ReportDistributor + * + * Function : Add static distributor + * + * Notes : The name is given in order to note the severity name + * during the report exception. + * + * Parameters: distributorName - The severity's name must be up to 10 + * letters long. + * SwitchAddRemove - REPORT_ADD to add the new static severity, + * REPORT_REMOVE to remove it. + * + * Return value: the new distributor handle, or -1 and thus: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_NAME_ALREADY_DISABLE if the distributor + * was already removed, + * errno = REPORT_ERROR_NAME_NOT_EXISTS if the distributorName + * not exists, + * errno = REPORT_ERROR_TABLE_FULL if there are already too + * many distributors, + * errno = REPORT_ERROR_NAME_EXISTS if the distributorName + * already exists. + **************************************************************************/ +DistributorHandle ReportDistributor(const char *distributorName, uint32_t SwitchAddRemove) +{ + int index; + + if ((DistCounter > NumOfDistributions) && (SwitchAddRemove == REPORT_ADD)) + { + errno = REPORT_ERROR_TABLE_FULL; + return -1; + } + if (strlen(distributorName) > 10) + { + errno = REPORT_ERROR_NAME_TOO_LONG; + return -1; + } + else if ((strcmp(distributorName,"system")==0) || ((strcmp(distributorName,"SYSTEM")==0))) + { + errno = REPORT_ERROR_NAME; + return -1; + } + if (IsNameExistsInFiltersTable(distributorName)) + { + errno = REPORT_ERROR_NAME_EXISTS; + return -1; + } + for (index=1; index<DistCounter; index++) + if (strcmp(Dist_Table[index].name,distributorName)==0) + { + if (SwitchAddRemove == REPORT_ADD) + { + if (Dist_Table[index].IsAlive) + { + errno = REPORT_ERROR_NAME_EXISTS; + return -1; + } + else + { + Dist_Table[index].IsAlive = true; + return index; + } + } + else /* Private severity disable */ + { + if (Dist_Table[index].IsAlive) + { + Dist_Table[index].IsAlive = false; + return index; + } + else + { + errno = REPORT_ERROR_NAME_ALREADY_DISABLE; + return -1; + } + } + } + if (SwitchAddRemove == REPORT_REMOVE) + { + errno = REPORT_ERROR_NAME_NOT_EXISTS; + return -1; /* nothing to remove */ + } + strcpy(Dist_Table[DistCounter].name,distributorName); + Dist_Table[DistCounter].IsAlive = true; + DistCounter++; + return (DistCounter-1); +} + + +/*************************************************************************** + * + * Name : ReportAddDistributor + * + * Function : Add static distributor + * + * Notes : + * + * Parameters: distributorName - The name must be up to 10 letters long + * + * Return value: the new distributor handle, or -1 and thus: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_TABLE_FULL if there are already too + * many distributors, + * errno = REPORT_ERROR_NAME_EXISTS if the distributorName + * already exists. + **************************************************************************/ +DistributorHandle ReportAddDistributor(const char *distributorName) +{ + return ReportDistributor(distributorName,REPORT_ADD); +} + + +/*************************************************************************** + * + * Name : ReportRemoveDistributor + * + * Function : Remove static distributor + * + * Notes : The distributor's messages will be discarded. + * Its name will be no longer seen in the distributor's list + * when the REP_CONTROL is typed in the Monitor. + * + * Parameters: distributorName - The severity's name must be up to 10 + * letters long. + * + * Return value: OK; or ERROR and thus errno is set to one of the following: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_NAME_ALREADY_DISABLE if the distributor + * was already removed, + * errno = REPORT_ERROR_NAME_NOT_EXISTS if the distributorName + * not exists. + **************************************************************************/ +STATUS ReportRemoveDistributor(const char *distributorName) +{ + return ReportDistributor(distributorName,REPORT_REMOVE); +} + + +/*************************************************************************** + * + * Name : ReportDistributorControl + * + * Function : Disable / enable the flow of reports given its static + * severity + * + * Notes : Disable reports using the constant REPORT_OFF + * Enable the reports using the constant REPORT_ON + * + * Return value: OK or ERROR if illegal Distributor + **************************************************************************/ +STATUS ReportDistributorControl(DistributorHandle Distributor, uint32_t SwitchOnOff) +{ + if ((Distributor > DistCounter) || (Distributor < 0)) + return ERROR; + Dist_Table[Distributor].IsActive = (SwitchOnOff == REPORT_ON) ? true : false; + return OK; +} + + +/*************************************************************************** + * + * Name : ReportGetDistributorHandleByName + * + * Function : Get the severity handle given the severity's name + * + * Notes : + * + * Return value: the handle; or -1 if no such name + **************************************************************************/ +DistributorHandle ReportGetDistributorHandleByName(const char *distributorName) +{ + int index; + + for (index = 0; index <= DistCounter; index++) + if (ReportStrCmp(distributorName,Dist_Table[index].name)) + { + if (Dist_Table[index].IsAlive) + return index; + else + return -1; /* disable used */ + } + return -1; +} + + +/*************************************************************************** + * + * Name : GetDistributorParamsByHandle + * + * Function : Get the static severity details according to its handle + * + * Parameters : DistributorHandle - table entry + * name - buffer to contain the static severity's name + * IsActive - a reference to a boolean flag + * + * Notes : The name field must exceeds 10 bytes long + * + * Return value: OK or ERROR and then: + * errno = REPORT_ERROR_ILLEGAL_PARAMETER if no such entry + * errno = REPORT_ERROR_FILTER_NOT_ALIVE if the static + * severity has already removed. + **************************************************************************/ +STATUS GetDistributorParamsByHandle(uint32_t DistributorHandle, char *name, bool *IsActive) +{ + if (DistributorHandle >= DistCounter) + { + errno = REPORT_ERROR_ILLEGAL_PARAMETER; + return ERROR; + } + if ((Dist_Table[DistributorHandle].IsAlive) == false) + { + errno = REPORT_ERROR_FILTER_NOT_ALIVE; + return ERROR; + } + strcpy(name,Dist_Table[DistributorHandle].name); + *IsActive = Dist_Table[DistributorHandle].IsActive; + return OK; +} + + +/*************************************************************************** + * + * Name : ReportFd + * + * Function : Add or remove a file descriptor to/from the output distributor + * + * Notes : + * + * Parameters: fd - file descriptor. Supplied by the user + * SwitchAddRemove - REPORT_ADD to add the fd + * REPORT_REMOVE to remove it. + * Distributor - 0 if not concerned with any static + * severity, or the static severity's handle + * to set with the given fd + * + * Return value: OK or ERROR with: + * errno = REPORT_ERROR_NOT_ENOUGH_MEMORY if destination list + * is full + * errno = REPORT_ERROR_ILLEGAL_PARAMETER if (fd == -1) or + * not found if asked to remove + **************************************************************************/ +STATUS ReportFd(int fd, uint32_t SwitchAddRemove, DistributorHandle Distributor) +{ + int index = 0, i; + + if (SwitchAddRemove == REPORT_ADD) + { + index = FindFreeDestinationElement(Distributor); + /* check for the table overflow */ + if (index == -1) + { + errno = REPORT_ERROR_NOT_ENOUGH_MEMORY; + return ERROR; + } + } + /* consistency check: don't add illegal fd */ + if (fd == -1) + { + errno = REPORT_ERROR_ILLEGAL_PARAMETER; + return ERROR; + } + + /* search for fd */ + for( i = 0; i < NUM_OF_DESTINATIONS; i++ ) + if ( Dist_Table[Distributor].dest[i].fd == fd ) + break; + + if (i == NUM_OF_DESTINATIONS) + { + if (SwitchAddRemove == REPORT_REMOVE) + { + errno = REPORT_ERROR_CODE_NOT_FOUND; + return ERROR; + } + /* Add fd */ + /* add new destination to the end of the table */ + Dist_Table[Distributor].dest[index].fd = fd; + /* set the function to NULL to ensure that destination is nothing but fd */ + Dist_Table[Distributor].dest[index].function = NULL; + } + else if (SwitchAddRemove == REPORT_ADD) + return OK; /* this fd is already exists in the table */ + else /* Remove fd */ + Dist_Table[Distributor].dest[i].fd = -1; + return OK; +} + + +/*************************************************************************** + * + * Name : ReportFunc + * + * Function : Add or remove an output routine to/from the distributor + * + * Notes : + * + * Parameters: func - hook to the routine. Supplied by the user . + * SwitchAddRemove - REPORT_ADD to add the hook + * REPORT_REMOVE to remove it. + * Distributor - Set 0 if not concerned with any static + * severity, or give the static severity's + * handle to set with the given fd. + * + * Return value: OK or ERROR with: + * errno = REPORT_ERROR_NOT_ENOUGH_MEMORY if destination list + * is full + * errno = REPORT_ERROR_ILLEGAL_PARAMETER if (func == NULL) + **************************************************************************/ +STATUS ReportFunc(ReportFunction func, uint32_t SwitchAddRemove, DistributorHandle Distributor) +{ + int index = 0, i; + + if (SwitchAddRemove == REPORT_ADD) + { + index = FindFreeDestinationElement(Distributor); + /* check for the table overflow */ + if (index == -1) + { + errno = REPORT_ERROR_NOT_ENOUGH_MEMORY; + return ERROR; + } + } + /* consistency check: don't add illegal pointer */ + if( func == NULL ) + { + errno = REPORT_ERROR_ILLEGAL_PARAMETER; + return ERROR; + } + + /* search for func - if already exists */ + for( i = 0; i < NUM_OF_DESTINATIONS; i++ ) + if (Dist_Table[Distributor].dest[i].function == func) + break; + + if (i == NUM_OF_DESTINATIONS) + { + if (SwitchAddRemove == REPORT_REMOVE) /* nothing to remove */ + { + errno = REPORT_ERROR_CODE_NOT_FOUND; + return ERROR; + } + /* Add routine */ + /* add new destination to the end of the table */ + Dist_Table[Distributor].dest[index].function = func; + /* set the fd to illegal value to ensure that destination is nothing but function */ + Dist_Table[Distributor].dest[index].fd = -1; + } + else if (SwitchAddRemove == REPORT_ADD) + return OK; /* this routine is already exists in the table */ + else /* Remove routine */ + Dist_Table[Distributor].dest[i].function = NULL; + return OK; +} + + +/*************************************************************************** + * + * Name : ReportMessage2Dist + * + * Function : Report a message to the appropriate distributor + * + * Notes : The distributor handle should be passed using the macro + * SET_PRIVATE_DISTRIBUTOR + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +STATUS ReportMessage2Dist(DistributorHandle distributor, const char *message) +{ + return reportDistribute(MESSAGE_FORMAT, message,NULL, 0, 0, distributor, 0, 0); +} + + +/*************************************************************************** + * + * Name : ReportMonitorFunc + * + * Function : Add/remove an output routine that prints to the monitor + * + * Notes : Hiding Report messages from appearing on the monitor is + * enable when the HALT> prompt is shown (by pressing <ENTER>). + * The filtering is done using an internal routine. + * This routine can be added/removed using this call. + * It can be added either to the regular distributor or to the + * distributor of each of the static severities. + * + * Parameters: SwitchAddRemove - REPORT_ADD to add the routine + * REPORT_REMOVE to remove it. + * Distributor - Set 0 if not concerned with any static + * severity, or give the static severity's + * handle to set with it . + * + * Return value: void + **************************************************************************/ +/*void ReportMonitorFunc(uint32_t SwitchAddRemove, uint32_t Distributor) +{ + switch (SwitchAddRemove) + { + case REPORT_ADD: + ReportFunc(MonitorFuncRoutine, REPORT_ADD, Distributor); + break; + case REPORT_REMOVE: + ReportFunc(MonitorFuncRoutine, REPORT_REMOVE, Distributor); + break; + } +} +*/ + +/*------------- messageDistribute ------------------------*/ +/* + * Forward message to all destinations. + * + * Parameters: + * void* msg - address of the message + * int len - message length + * + * Returns: + * None + * + */ + +static void messageDistribute(char *msg, + int DistTableEntry, + char *FileName, + int LineNumber, + int errorCode, + int parameter1, + int parameter2) +{ + int index; + + /* pass through the table and send message to destination. + Assume for consistency: when the destination is fd, + it should not be -1 and function must be NULL. + If the destination is function, it's address must not be NULL + and fd should be -1 */ + for (index = 0; index < NUM_OF_DESTINATIONS; index++ ) + { + if (Dist_Table[DistTableEntry].dest[index].function != NULL) + Dist_Table[DistTableEntry].dest[index].function(msg,FileName,LineNumber,errorCode,parameter1,parameter2); + } +} + + +/*------------- reportFormat --------------------------*/ +/* + * The function converts mesage with error type, code, etc. into string + * with length using the following format (example): + * "H/W Error #12,05,01: Bus error (0xffde,0x1234)" + * + * Parameters: + * char* buffer - buffer to store the formatted message + * int* maxlen - length of the buffer. If the estimated length + * of the formatted message exceeds maxlen, + * function returns ERROR, set errno to + * REPORT_ERROR_NOT_ENOUGH_MEMORY and buffer left unchanged. + * char* message - user message + * UNIT16 extErrorType - error type and severity + * ERRORCODE errorCode - error code + * uint32_t32 parameter1 - user parameter 1 + * uint32_t32 parameter2 - user parameter 2 + * + */ + +//STATUS reportFormat(char *buffer, +// int *maxlen, +// const char *message, +// int errorCode, +// ErrorSeverity severity, +// int parameter1, +// int parameter2) +//{ +// int DstrTableEntry; +// char *name; +// static char* severities[8] = {"Message","Warning","","Error","","","","Fatal error"}; +// +// /* Total message length w/o text is REPORT_MSG_FORMAT_LEN bytes */ +// int msgLen = strlen(message) + REPORT_MSG_FORMAT_LEN; +// +// /* check if message fit the supplied buffer */ +// if (*maxlen < msgLen) +// { +// errno = REPORT_ERROR_NOT_ENOUGH_MEMORY; +// return ERROR; +// } +// /* Format message. +// ATTENTION: DON'T forget to change REPORT_MSG_FORMAT_LEN +// when changing the format string */ +// if (SEVERITY_MASK(severity) == RpPrivate) +// { +// DstrTableEntry = (severity >> 5); +// if (Dist_Table[DstrTableEntry].IsAlive == false) +// { +// errno = REPORT_ERROR_ILLEGAL_PARAMETER; +// return ERROR; +// } +// name = Dist_Table[DstrTableEntry].name; +// } +// else +// name = severities[severity-1]; +// +// *maxlen = sprintf(buffer,"%s: #%d: %s (0x%x,0x%x)\r\n",name,errorCode,message,parameter1,parameter2); +// return OK; +//} + + +/*************************************************************************** + * + * Name : FindFreeDestinationElement + * + * Function : Find Free Destination Element. + * + * Notes : + * + * Return value: index if found , ERROR - otherwise + **************************************************************************/ +int FindFreeDestinationElement(int DistTableEntry) +{ + int index; + + for (index=0; index<NUM_OF_DESTINATIONS; index++) + if ((Dist_Table[DistTableEntry].dest[index].fd == -1) && + (Dist_Table[DistTableEntry].dest[index].function == NULL)) + return index; + + return ERROR; +} + + +/*************************************************************************** + * + * Name : ReportStrCmp + * + * Function : compare between two string with case-insensitive. + * + * Notes : + * + * Return value: true - strings are identical; false - otherwise + **************************************************************************/ +bool ReportStrCmp(const char *str1, const char *str2) +{ + int i=0; + + while ((str1[i] != '\0') || (str2[i] != '\0')) + { + if (tolower(str1[i]) != tolower(str2[i])) + return false; + i++; + } + if ((str1[i] == '\0') && (str2[i] == '\0')) + return true; + return false; +} + + +/*************************************************************************** + * + * Name : IsNameExistsInDistributorTable + * + * Function : Check if a given name is already found in the table + * of the static severities + * + * Notes : + * + * Return value: true if found; false otherwise + **************************************************************************/ +bool IsNameExistsInDistributorTable(const char *name) +{ + int index; + + for (index=0; index<=DistCounter; index++) + if (ReportStrCmp(name,Dist_Table[index].name) == true) + return true; + return false; + +} + + diff --git a/Software/Embedded_SW/Embedded/Common/report/distributor.h b/Software/Embedded_SW/Embedded/Common/report/distributor.h new file mode 100644 index 000000000..4b7f9185a --- /dev/null +++ b/Software/Embedded_SW/Embedded/Common/report/distributor.h @@ -0,0 +1,94 @@ + +#ifndef __RDISTRIBUTOR_H__ +#define __RDISTRIBUTOR_H__ + +/* The following enum is to inform about the kind of message format. For example: + * MESSAGE_FORMAT: this is a message + * REPORT_FORMAT: distributor.h.7, Error: this is a message. 0, (0x0,0x1) */ +typedef enum { MESSAGE_FORMAT, REPORT_FORMAT } FormatType; + +/* Use the following macro in order to get the private severity as the */ +/* severity parameter from one of the Report routines */ +#define GET_PRIVATE_SEVERITY(handle) (DistributorHandle)((handle)>>5) + +/* The mask of currently enabled severity. */ +extern bool filterTest(ErrorSeverity severity); + +extern STATUS distibutorInit( int priority, int maxMsgs, int maxDestinations ); + +extern STATUS reportDistribute(FormatType format, + const char *message, + char *FileName, + int LineNumber, + int errorCode, + ErrorSeverity severity, + int parameter1, + int parameter2); + + +/*************************************************************************** + * + * Name : ReportStrCmp + * + * Function : compare between two string with case-insensitive. + * + * Notes : + * + * Return value: TRUE - strings are identical; FALSE - otherwise + **************************************************************************/ +extern bool ReportStrCmp(const char *str1, const char *str2); + + +/*************************************************************************** + * + * Name : IsNameExistsInDistributorTable + * + * Function : Check if a given name is already found in the table + * of the private severities + * + * Notes : + * + * Return value: TRUE if found; FALSE otherwise + **************************************************************************/ +extern bool IsNameExistsInDistributorTable(const char *name); + +/*************************************************************************** + * + * Name : ReportGetDistributorHandleByName + * + * Function : Get the severity handle given the severity's name + * + * Notes : + * + * Return value: the handle; or -1 if no such name + **************************************************************************/ +extern DistributorHandle ReportGetDistributorHandleByName(const char *distributorName); + + +/*************************************************************************** + * + * Name : GetDistributorParamsByHandle + * + * Function : Get the private severity details according to its handle + * + * Parameters : DistributorHandle - table entry + * name - buffer to contain the private severity's name + * IsActive - FALSE if the private severity + * + * Notes : The name field must exceeds 10 bytes long + * + * Return value: OK or ERROR and then: + * errno = REPORT_ERROR_ILLEGAL_PARAMETER if no such entry + * errno = REPORT_ERROR_FILTER_NOT_ALIVE if the private + * severity has already removed (and thus it is no + * no longer exists until re-added). + **************************************************************************/ +extern STATUS GetDistributorParamsByHandle(uint32_t DistributorHandle, + char *name, + bool *IsActive); +/* Total message length w/o message text in bytes + (for reportMsgFormat function ) */ +#define REPORT_MSG_FORMAT_LEN 61 + +#endif /* __RDISTRIBUTOR_H__ */ + diff --git a/Software/Embedded_SW/Embedded/Common/report/filter.c b/Software/Embedded_SW/Embedded/Common/report/filter.c new file mode 100644 index 000000000..7efc56d36 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Common/report/filter.c @@ -0,0 +1,526 @@ + /*+************************************************************************* + * File name : FILTER.C + * Title : TERMINAL DRIVER INTERFACE + * Project : NEVADA + * Subsystem : SYSTEM + * Date created: 18 SEP, 1997 + * Revision : Rev 1.0 + * Author : Zvika Zilberman + * History : 18.09.97 Zvika Zilberman - porting to DCME SWINFRA + * + * Description : This file includes the FILTER part of the report package + * + * + * Procedures: + * + * Report - Report message using filters and message multiplexing. + * ReportSeveritySet - Set message severity + * + ******************************************************************************/ + +#include "report.h" +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <errno.h> +#include "stdint.h" /* RETCODE */ +#include "filter.h" +#include "distributor.h" /* reportDistribute */ + +#define MAX_STRING_LEN 255 + +/*------------- Local Data ------------------------------*/ + +/* the filter's table */ + +packageFilter *packageFilterTable; +uint8_t filterTableSize; +uint8_t filterNumOfCurrentEntries; + +/* The mask of currently enabled severity. */ +static ErrorSeverity SeverityLevel; + +/* flag allows or dennies filter usage */ +static bool filterDontUse; + + +/*************************************************************************** + * + * Name : filterTableInit + * + * Function : Init the filtering mechanism + * + * Notes : + * + * Return value: OK; ERROR if malloc is failed + **************************************************************************/ +STATUS filterTableInit(uint32_t TableSize) +{ + int index; + + filterTableSize = TableSize; + packageFilterTable = (packageFilter*)malloc(sizeof(packageFilter)*TableSize); + if (packageFilterTable == NULL) + return ERROR; + for (index=0; index<TableSize; index++) + packageFilterTable[index].IsActive = true; + filterNumOfCurrentEntries = 0; + return OK; +} + + +/*************************************************************************** + * + * Name : ReportFilterPackage + * + * Function : Add or remove a filter to/from the filter's data base + * + * Notes : + * + * Parameters : filterName - The filter's name must be up to 10 letters + * long + * SwitchAddRemove - REPORT_ADD to add the new filter, + * REPORT_REMOVE to remove it. + * + * Return value: the new filter handle; or -1 in case of an ERROR, thus: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_TABLE_FULL if there are already too + * many filters, + * errno = REPORT_ERROR_NAME_EXISTS if the filterName already exists. + **************************************************************************/ +int ReportFilterPackage(const char *filterName, uint8_t SwitchAddRemove) +{ + int index; + + if ((filterNumOfCurrentEntries == filterTableSize) && (SwitchAddRemove == REPORT_ADD)) + { + errno = REPORT_ERROR_TABLE_FULL; + return -1; + } + else if (strlen(filterName) > 10) + { + errno = REPORT_ERROR_NAME_TOO_LONG; + return -1; + } + else if ((IsNameExistsInDistributorTable(filterName)) && (SwitchAddRemove == REPORT_ADD)) + { + errno = REPORT_ERROR_NAME_EXISTS; + return -1; + } + for (index=0; index<filterNumOfCurrentEntries; index++) + if (ReportStrCmp(packageFilterTable[index].filterName,filterName)) + { + if (SwitchAddRemove == REPORT_ADD) + { + if (packageFilterTable[index].IsActive) + { + errno = REPORT_ERROR_NAME_EXISTS; + return -1; + } + else + { + packageFilterTable[index].IsActive = true; + return index; + } + } + else /* Filter disable */ + { + if (packageFilterTable[index].IsActive) + { + packageFilterTable[index].IsActive = false; + return index; + } + else + { + errno = REPORT_ERROR_NAME_ALREADY_DISABLE; + return -1; + } + } + } + if (SwitchAddRemove == REPORT_REMOVE) + { + errno = REPORT_ERROR_NAME_NOT_EXISTS; + return -1; /* nothing to remove */ + } + strcpy(packageFilterTable[filterNumOfCurrentEntries].filterName,filterName); + packageFilterTable[filterNumOfCurrentEntries].filterDontUse = true; + filterNumOfCurrentEntries++; + return (filterNumOfCurrentEntries-1); +} + + +/*************************************************************************** + * + * Name : ReportAddFilterPackage + * + * Function : Add a package filter to the package filter's data base + * + * Notes : + * + * Parameters : filterName - The filter's name must be up to 10 letters + * long + * + * Return value: the new filter handle; or -1 in case of an ERROR, thus: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_TABLE_FULL if there are already too + * many filters, + * errno = REPORT_ERROR_NAME_EXISTS if the filterName already exists. + **************************************************************************/ +PackageHandle ReportAddFilterPackage(const char *filterName) +{ + return ReportFilterPackage(filterName, REPORT_ADD); +} + + +/*************************************************************************** + * + * Name : ReportRemoveFilterPackage + * + * Function : Remove a package filter from the package filter's data base + * + * Notes : + * + * Parameters : filterName - The filter's name must be up to 10 letters + * long + * + * Return value: OK; or ERROR and thus errno is set to one of the following: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_NAME_ALREADY_DISABLE if the filter was + * already removed, + * errno = REPORT_ERROR_NAME_NOT_EXISTS if the filterName not exists. + **************************************************************************/ +STATUS ReportRemoveFilterPackage(const char *filterName) +{ + return ReportFilterPackage(filterName, REPORT_REMOVE); +} + + +/*************************************************************************** + * + * Name : ReportSwitchPackageFilter + * + * Function : Switch the filter of the given handle + * + * Notes : REPORT_ON - filter is active. messages do not discarded. + * REPORT_OFF - filter is not active. Its messages are discarded. + * + * Return value: OK; or ERROR if wrong handle + **************************************************************************/ +STATUS ReportSwitchPackageFilter(PackageHandle ReportPackageHandle, uint32_t SwitchOnOff) +{ + if (ReportPackageHandle >= filterNumOfCurrentEntries) + return ERROR; + packageFilterTable[ReportPackageHandle].filterDontUse = (SwitchOnOff == REPORT_OFF); + return OK; +} + + +/*************************************************************************** + * + * Name : GetFilterParamsByHandle + * + * Function : Get the filter details according to its handle + * + * Notes : filterNameBuf must exceeds 10 bytes long + * + * Return value: OK; or ERROR if wrong handle + **************************************************************************/ +STATUS GetFilterParamsByHandle(uint32_t filterHandle, + packageFilter *pPackage) +{ + if (filterHandle >= filterNumOfCurrentEntries) + return ERROR; + strcpy(pPackage->filterName,packageFilterTable[filterHandle].filterName); + pPackage->filterDontUse = packageFilterTable[filterHandle].filterDontUse; + pPackage->IsActive = packageFilterTable[filterHandle].IsActive; + return OK; +} + + +/*************************************************************************** + * + * Name : GetFilterHandleByName + * + * Function : Get the filter handle given the filter's name + * + * Notes : + * + * Return value: the handle; or -1 if no such name + **************************************************************************/ +int ReportGetFilterHandleByName(const char *filterName) +{ + int index; + + for (index = 0; index < filterNumOfCurrentEntries; index++) + if (ReportStrCmp(filterName,packageFilterTable[index].filterName) == true) + { + if (packageFilterTable[index].IsActive) + return index; + else + return -1; /* disable used */ + } + return -1; +} + + +/*************************************************************************** + * + * Name : IsNameExistsInFiltersTable + * + * Function : Check if a given name is already found in the filter's + * table. + * + * Notes : + * + * Return value: true if found; false otherwise + **************************************************************************/ +bool IsNameExistsInFiltersTable(const char *name) +{ + int index; + + for (index = 0; index < filterNumOfCurrentEntries; index++) + if (ReportStrCmp(name,packageFilterTable[index].filterName) == true) + return true; + return false; +} + + +/*************************************************************************** + * + * Name : ReportFilterTest + * + * Function : Test the filter's handle to check if to report or not + * + * Notes : + * + * Return value: true - discard the report; false - report. + **************************************************************************/ +bool ReportFilterTest(uint8_t filterHandle) +{ + if (filterHandle >= filterNumOfCurrentEntries) + return false; + return (packageFilterTable[filterHandle].filterDontUse); +} + + +bool filterTest(ErrorSeverity severity) +{ + if (filterDontUse) + return true; /* The filter machnism is disabled - */ + /* all errors are enabled */ + if( SeverityLevel <= severity ) /* check for severity */ + return true; + + return false; +} + + +/*************************************************************************** + * + * Name : ReportSeveritySet + * + * Function : Determine the filter level of the message's severity + * + * Notes : Messages with severity below this level wont be sent to + * their output + * + * Return value: void + **************************************************************************/ +void ReportSeveritySet(ErrorSeverity level) +{ + SeverityLevel = level; +} + + +/*************************************************************************** + * + * Name : Report + * + * Function : PEPORT main routine + * + * Notes : + * + * Parameters: message - user's message + * errorCode - should be the return code of the routine that + * failed and made this report + * severity - the error level + * parameter1 - user params no.1 (for additional information) + * parameter2 - another user params. + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +STATUS Report(const char *message, + char *FileName, + int LineNumber, + int errorCode, + ErrorSeverity severity, + int parameter1, + int parameter2) +{ + + /* if message passes the filter send it to distributor */ + if (filterTest(severity) || (GET_PRIVATE_SEVERITY(severity) > 0)) + return reportDistribute(REPORT_FORMAT, + message, + FileName, + LineNumber, + errorCode, + severity, + parameter1, + parameter2); + return OK; +} + + +/*************************************************************************** + * + * Name : ReportMessage2SysDist + * + * Function : Report a message to the System Distributor + * + * Notes : The severity of this report is always <Message> + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +/*STATUS ReportMessage2SysDist(const char *message) +{ + if (filterTest(RpMessage) == false) + return OK; + return reportDistribute(MESSAGE_FORMAT, message,NULL,0, 0, RpMessage, 0, 0); +} + +STATUS ReportMessage(const char *message) +{ + if (filterTest(RpMessage) == false) + return OK; + return reportDistribute(MESSAGE_FORMAT, message, NULL, 0,0, RpMessage, 0, 0); +} + +*/ +/*************************************************************************** + * + * Name : ReportPackageMessage2SysDist + * + * Function : Report a message to the System distributor if the handle + * is not filtered + * + * Notes : The severity of this report is always <Message> + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +/*STATUS ReportPackageMessage2SysDist(PackageHandle ReportPackageHandle, const char *message) +{ + if (filterTest(RpMessage) == false) + return OK; + if (ReportFilterTest(ReportPackageHandle)) + return OK; + return ReportMessage2SysDist(message); +} +*/ + +/*************************************************************************** + * + * Name : ReportFormatMessage2SysDist + * + * Function : Report a formatted message (like printf) to the System + * distributor + * + * Notes : The severity of this report is always <Message> + * IMPORTANT: the formatting is done in the context of the + * calling application!! + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +/*STATUS ReportFormatMessage2SysDist(const char *format, ...) +{ + static char text[MAX_STRING_LEN]; + va_list ap; + + if (filterTest(RpMessage) == false) + return OK; + + va_start (ap , format ); + vsprintf ( text , format , ap ); + va_end ( ap ); + return reportDistribute(MESSAGE_FORMAT, text, NULL,0,0, RpMessage, 0, 0); +} + +STATUS Reportf(const char *format, ...) +{ + static char text[MAX_STRING_LEN]; + va_list ap; + + if (filterTest(RpMessage) == false) + return OK; + + va_start (ap , format ); + vsprintf ( text , format , ap ); + va_end ( ap ); + return reportDistribute(MESSAGE_FORMAT, text, NULL,0,0, RpMessage, 0, 0); +} + +*/ +/*************************************************************************** + * + * Name : ReportWithFilter + * + * Function : PEPORT with filter - main routine + * + * Notes : It is recommended to use one of the macros below instead + * of using this routine directly. This is because the macros + * support other benefits such: file name, line number etc. + * + * Parameters: handle - filter's handle + * message - user's message + * errorCode - should be the return code of the routine that + * failed and made this report + * severity - the error level + * parameter1 - user params no.1 (for additional information) + * parameter2 - another user param. + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +STATUS ReportWithPackageFilter(PackageHandle ReportPackageHandle, + const char *message, + char *FileName, + int LineNumber, + int errorCode, + ErrorSeverity severity, + int parameter1, + int parameter2) +{ + if (ReportFilterTest(ReportPackageHandle)) + return OK; /* discard message */ + return Report(message,FileName,LineNumber,errorCode,severity,parameter1,parameter2); +} + + +/*************************************************************************** + * + * Name : ReportFormatPackageMessage2SysDist + * + * Function : Report a formatted message (like printf) to the output + * if handle is not filtered + * + * Notes : The severity of this report is always <Message> + * IMPORTANT: the formatting is done in the context of the + * calling task!! + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +/*STATUS ReportFormatPackageMessage2SysDist(PackageHandle ReportPackageHandle, + const char *format, ...) +{ + static char text[MAX_STRING_LEN]; + va_list ap; + + if (ReportFilterTest(ReportPackageHandle)) + return OK; + if (filterTest(RpMessage) == false) + return OK; + va_start (ap , format ); + vsprintf ( text , format , ap ); + va_end ( ap ); + return reportDistribute(MESSAGE_FORMAT, text, NULL,0,0, RpMessage, 0, 0); +}*/ + diff --git a/Software/Embedded_SW/Embedded/Common/report/filter.h b/Software/Embedded_SW/Embedded/Common/report/filter.h new file mode 100644 index 000000000..481f6cb66 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Common/report/filter.h @@ -0,0 +1,74 @@ + +#ifndef __RFILTER_H__ +#define __RFILTER_H__ + +/* the type definition of the filter per package */ +#ifdef __cplusplus +extern "C"{ +#endif + +typedef struct packageFilter { + char filterName[11]; /* up to 10 letter of filter's name */ + bool filterDontUse; /* TRUE - dont use. FALSE - send to report */ + bool IsActive; /* TRUE - can be used. FALSE - disable it */ +} packageFilter; + +/*************************************************************************** + * + * Name : filterTableInit + * + * Function : Init the filtering mechanism + * + * Notes : + * + * Return value: OK; ERROR if malloc is failed + **************************************************************************/ +extern STATUS filterTableInit(uint32_t TableSize); + + +/*************************************************************************** + * + * Name : GetFilterParamsByHandle + * + * Function : Get the filter details according to its handle + * + * Notes : filterNameBuf must exceeds 10 bytes long + * + * Return value: OK; or ERROR if wrong handle + **************************************************************************/ +extern STATUS GetFilterParamsByHandle(uint32_t filterHandle, + packageFilter *pPackage); + + +/*************************************************************************** + * + * Name : IsNameExistsInFiltersTable + * + * Function : Check if a given name is already found in the filter's + * table. + * + * Notes : + * + * Return value: TRUE if found; FALSE otherwise + **************************************************************************/ +extern bool IsNameExistsInFiltersTable(const char *name); + + +/*************************************************************************** + * + * Name : GetFilterHandleByName + * + * Function : Get the filter handle given the filter's name + * + * Notes : + * + * Return value: the handle; or -1 if no such name (or filter was removed). + **************************************************************************/ +extern int ReportGetFilterHandleByName(const char *filterName); + +#ifdef __cplusplus +} +#endif + +#endif /* __RFILTER_H__ */ + diff --git a/Software/Embedded_SW/Embedded/Common/report/report.h b/Software/Embedded_SW/Embedded/Common/report/report.h new file mode 100644 index 000000000..d98844d71 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Common/report/report.h @@ -0,0 +1,593 @@ +/****************************************************************************** + * File name : REPORT.H + * Title : INFRA REPORT PACKAGE - Application Interface + * Date created : 16 SEP, 1997 + * Revision : 2.0 + * Author : Zvika Zilberman + * + * Description : This package provides services for reporting and + * debug tracing. The package includes: + * - Error coding convention definitions + * - Message report interface + * - Message filtering interface + * - Message distributor interface + * - Compatibility with UT_EXCEPTION package + * + ****************************************************************************** + * + * History: + * 01.05.96 Roie Geron - first cut + * 01.09.96 Ilia Maller - start of coding + * 21.02.97 Ilia Maller - minor improvements + * 16.09.97 Zvika Zilberman - porting to DCME SWINFRA (0200 - 0240) + * 29.07.98 Zvika Zilberman - approach to new generation (0300 - 0320) + * 10.11.98 Zvika Zilberman - update the new generation (0330) + * + ****************************************************************************** + * Dependencies of SWINFRA packages: + * Terminal + * Monitor + ******************************************************************************/ + +#ifndef __REPORT_H__ +#define __REPORT_H__ + + +/*---------------------------- Includes ---------------------------------------*/ + +#include "include.h" +#include <assert.h> /* _ASSET_STR */ +#include "PMR/common/MessageContainer.pb-c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*#define OK 0 +#define ERROR -1 +//#define FALSE false +//#define TRUE true +#define OFF 0 +#define ON 1 +*/ +#define RET_NOTOK -1 +#define RET_OK 0 +typedef int STATUS; +/*--------------------------- Type definitions -------------------------------*/ + +/* This following redefinition is the filter level. Reports with lower severity than */ +/* the filter's one, won't be sent to the output. */ +typedef int ErrorSeverity; + +#define RpMessage 0x1 +#define RpWarning 0x2 +#define RpError 0x4 +#define RpFatalError 0x8 +#define RpPrivate 0x10 +typedef int DistributorHandle; +typedef int PackageHandle; + +#define REPORT_MAX_MSG_LEN 128 + +/* Use the following macro in order to pass the private severity as the */ +/* severity parameter to one of the Report routines */ +#define SET_PRIVATE_DISTRIBUTOR(handle) (ErrorSeverity)(Private | ((handle)<<5)) + +/* The following are some constant for control and manipulation throughout the */ +/* Report's control routines */ +#define REPORT_OFF 0 +#define REPORT_ON 1 +#define REPORT_REMOVE 0 +#define REPORT_ADD 1 + +/* This is a prototype of the output hook. When adding a function to the distributor, */ +/* the routine's prototype should be the same as here */ +typedef int (* ReportFunction)(char *message, /* The formatted message */ + char *FileName, + int LineNumber, + int errorCode, /* error code that caused the report */ + int parameter1, /* user parameter no. 1 */ + int parameter2); /* user parameter no. 2 */ + +/* Initialization struct. Default values are below */ +typedef struct{ + int DistributorTaskPriority; /* The report task's priority */ + int DistributorQueueMaxMsgs; /* Maximum number of messages in the queue */ + int MaxNumberOfPrivateDistributors; /* Maximum number of private distributor */ + int MaxNumOfFilterNames; /* Maximum number of filters to enable the applica */ +}ReportInitParams; +/* these values can be used as default in the above package configuration */ +#define REPORT_TASK_PRIORITY 150 +#define REPORT_MAX_FILTER_PACKAGES 20 +#define REPORT_QUEUE_MAX_MSGS 100 + + +/*----------------------------------------------------------------------------*/ +/*---------------------- Report Tracing and Exceptions -----------------------*/ +/*---------------------------- without filtering -----------------------------*/ +/*----------------------------------------------------------------------------*/ +//void SendStatusResponse (uint32_t Code, char *Token); +/*************************************************************************** + * + * Name : ReportInit + * + * Function : PEPORT library init + * + * Notes : Should be called before any other function from the Report + * package. + * + * Return value: OK or ERROR if malloc has failed or task creation has + * failed + **************************************************************************/ +extern STATUS ReportInit(ReportInitParams InitParams); +extern uint32_t ReportInitMessage(MessageContainer* requestContainer); + +/*************************************************************************** + * + * Name : Report + * + * Function : PEPORT main routine + * + * Notes : It is recommended to use one of the macros below (Debug + * Tracing ) instead of using this routine directly. This + * is because the macros support other benefits such: file + * name, line number etc. + * + * Parameters: message - user's message + * errorCode - should be the return code of the routine that + * failed and made this report + * severity - the error level + * parameter1 - user params no.1 (for additional information) + * parameter2 - another user param. + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +extern STATUS Report(const char *message, + char *FileName, + int LineNumber, + int errorCode, + ErrorSeverity severity, + int parameter1, + int parameter2); + + +/*************************************************************************** + * + * Name : ReportMessage2SysDist + * + * Function : Report a message to the System distributor + * + * Notes : The severity of this report is always <Message> + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +extern STATUS ReportMessage2SysDist(const char *message); + + +/*************************************************************************** + * + * Name : ReportFormatMessage2SysDist + * + * Function : Report a formatted message (like printf) to the System + * distributor + * + * Notes : The severity of this report is always <Message> + * IMPORTANT: the formatting is done in the context of the + * calling task!! + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +extern STATUS ReportFormatMessage2SysDist(const char *format, ...); + + +/*************************************************************************** + * + * Name : ReportMessage2Dist + * + * Function : Report a message to the appropriate distributor + * + * Notes : The distributor handle should be passed using the macro + * SET_PRIVATE_DISTRIBUTOR + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +extern STATUS ReportMessage2Dist(DistributorHandle distributor, const char *message); + + +/*************************************************************************** + * + * Name : REPORT_ERR + * + * Function : Report an error + * + * Notes : Attention: this is a macro. Will add the file name & the + * line number where the error is reported + * + * Parameters : See above, Report. + * + * Return value: OK; or Report's return code + **************************************************************************/ +#define REPORT_ERR(msg, error, severity, par1, par2) \ + Report(REPORT_LINE(msg), error, severity, par1, par2) + + +/*************************************************************************** + * + * Name : REPORT_IF_ERROR + * + * Function : if <condition> is TRUE then report an error + * + * Notes : Attention: this is a macro. Will add the file name & the + * line number where the error is reported + * + * Parameters : See above, Report. + * + * Return value: OK; or Report's return code + **************************************************************************/ +#define REPORT_IF_ERROR(condition, msg, error, severity, par1, par2) \ + ((condition) ? Report(REPORT_LINE(msg), error, severity, par1, par2) : OK) + +/*----------------------------------------------------------------------------*/ +/*---------------------- Report Tracing and Exceptions -----------------------*/ +/*----------------------------- with filtering -------------------------------*/ +/*----------------------------------------------------------------------------*/ + +/*************************************************************************** + * + * Name : ReportWithPackageFilter + * + * Function : PEPORT with package filter - main routine + * + * Notes : It is recommended to use one of the macros below instead + * of using this routine directly. This is because the macros + * support other benefits such: file name, line number etc. + * + * Parameters: ReportPackageHandle - filter's handle + * message - user's message + * errorCode - should be the return code of the routine + * that failed and made this report + * severity - the error level + * parameter1 - user params no.1 (for additional + * information) + * parameter2 - another user param. + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +extern STATUS ReportWithPackageFilter(PackageHandle ReportPackageHandle, + const char *message, + char *FileName, + int LineNumber, + int errorCode, + ErrorSeverity severity, + int parameter1, + int parameter2); + + +/*************************************************************************** + * + * Name : ReportPackageMessage2SysDist + * + * Function : Report a message to the System distributor if the handle + * is not filtered + * + * Notes : The severity of this report is always <Message> + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +/*extern STATUS ReportPackageMessage2SysDist(PackageHandle ReportPackageHandle, + const char *message); +*/ + +/*************************************************************************** + * + * Name : ReportFormatPackageMessage2SysDist + * + * Function : Report a formatted message (like printf) to the output + * if handle is not filtered + * + * Notes : The severity of this report is always <Message> + * IMPORTANT: the formatting is done in the context of the + * calling task!! + * + * Return value: OK or ERROR if failed to send to distributor + **************************************************************************/ +/*extern STATUS ReportFormatPackageMessage2SysDist(PackageHandle ReportPackageHandle, + const char *format, ...); +*/ + +/*************************************************************************** + * + * Name : REPORT_ERR_FILTER + * + * Function : Report an error if handle is not filtered + * + * Notes : Attention: this is a macro. Will add the file name & the + * line number where the error is reported + * + * Parameters : See above, Report. + * + * Return value: OK; or Report's return code + **************************************************************************/ +#define REPORT_ERR_FILTER(handle, msg, FileName, LineNumber,error, severity, par1, par2) \ + ReportWithPackageFilter(handle, REPORT_LINE(msg), FileName, LineNumber,error, severity, par1, par2) + + +/*************************************************************************** + * + * Name : REPORT_IF_ERROR_FILTER + * + * Function : if <condition> is TRUE and handle is not filtered + * then report an error + * + * Notes : Attention: this is a macro. Will add the file name & the + * line number where the error is reported + * + * Parameters : See above, Report. + * + * Return value: OK; or Report's return code + **************************************************************************/ +#define REPORT_IF_ERROR_FILTER(condition, handle, msg, FileName, LineNumber,error, severity, par1, par2) \ + ((condition) ? REPORT_ERR_FILTER(handle,msg,FileName, LineNumber,error,severity,par1,par2) : OK) + + +/*************************************************************************** + * + * Name : ReportAddFilterPackage + * + * Function : Add a package filter to the package filter's data base + * + * Notes : + * + * Parameters : filterName - The filter's name must be up to 10 letters + * long + * + * Return value: The new filter handle; or -1 in case of an ERROR, thus: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_TABLE_FULL if there are already too + * many filters, + * errno = REPORT_ERROR_NAME_EXISTS if the filterName already exists. + **************************************************************************/ +extern PackageHandle ReportAddFilterPackage(const char *filterName); + + +/*************************************************************************** + * + * Name : ReportRemoveFilterPackage + * + * Function : Remove a package filter from the package filter's data base + * + * Notes : + * + * Parameters : filterName - The filter's name must be up to 10 letters + * long + * + * Return value: OK; or ERROR and thus errno is set to one of the following: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_NAME_ALREADY_DISABLE if the filter was + * already removed, + * errno = REPORT_ERROR_NAME_NOT_EXISTS if the filterName not exists. + **************************************************************************/ +extern STATUS ReportRemoveFilterPackage(const char *filterName); + + +/*************************************************************************** + * + * Name : ReportSwitchPackageFilter + * + * Function : Switch the filter of the given handle + * + * Notes : REPORT_ON - filter is active. messages do not discarded. + * REPORT_OFF - filter is not active. Its messages are discarded. + * + * Return value: OK; or ERROR if wrong handle + **************************************************************************/ +extern STATUS ReportSwitchPackageFilter(PackageHandle ReportPackageHandle, uint32_t SwitchOnOff); + +/*----------------------------------------------------------------------------*/ +/*---------------------------- Distributor -----------------------------------*/ +/*----------------------------------------------------------------------------*/ + +/*************************************************************************** + * + * Name : ReportAddDistributor + * + * Function : Add private distributor + * + * Notes : + * + * Parameters: distributorName - The name must be up to 10 letters long + * + * Return value: The new distributor handle, or -1 and thus: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_TABLE_FULL if there are already too + * many distributors, + * errno = REPORT_ERROR_NAME_EXISTS if the distributorName + * already exists. + **************************************************************************/ +extern DistributorHandle ReportAddDistributor(const char *distributorName); + + +/*************************************************************************** + * + * Name : ReportRemoveDistributor + * + * Function : Remove private distributor + * + * Notes : The distributor's messages will be discarded. + * Its name will be no longer seen in the distributor's list + * when the REP_CONTROL is typed in the Monitor. + * + * Parameters: distributorName - The severity's name must be up to 10 + * letters long. + * + * Return value: OK; or ERROR and thus errno is set to one of the following: + * errno = REPORT_ERROR_NAME_TOO_LONG in case of long name, + * errno = REPORT_ERROR_NAME_ALREADY_DISABLE if the distributor + * was already removed, + * errno = REPORT_ERROR_NAME_NOT_EXISTS if the distributorName + * not exists. + **************************************************************************/ +extern DistributorHandle ReportRemoveDistributor(const char *distributorName); + + +/*************************************************************************** + * + * Name : ReportDistributorControl + * + * Function : Disable / enable the flow of reports given its private + * severity + * + * Notes : Disable reports using the constant REPORT_OFF + * Enable the reports using the constant REPORT_ON + * + * Return value: OK or ERROR if illegal Distributor + **************************************************************************/ +extern STATUS ReportDistributorControl(DistributorHandle Distributor, uint32_t SwitchOnOff); + +/*----------------------------------------------------------------------------*/ +/*------------------------ Message Distributor -------------------------------*/ +/*----------------------------------------------------------------------------*/ + +/*************************************************************************** + * + * Name : ReportFd + * + * Function : Add or remove a file descriptor to/from the output distributor + * + * Notes : + * + * Parameters: fd - file descriptor. Supplied by the user + * SwitchAddRemove - REPORT_ADD to add the fd + * REPORT_REMOVE to remove it. + * Distributor - 0 if not concerned with any private + * severity, or the private severity's handle + * to set with the given fd + * + * Return value: OK or ERROR with: + * errno = REPORT_ERROR_NOT_ENOUGH_MEMORY if destination list + * is full + * errno = REPORT_ERROR_ILLEGAL_PARAMETER if (fd == -1) or + * not found if asked to remove + **************************************************************************/ +extern STATUS ReportFd(int fd, uint32_t SwitchAddRemove, DistributorHandle Distributor); + + +/*************************************************************************** + * + * Name : ReportFunc + * + * Function : Add or remove an output routine to/from the distributor + * + * Notes : + * + * Parameters: func - hook to the routine. Supplied by the user . + * SwitchAddRemove - REPORT_ADD to add the hook + * REPORT_REMOVE to remove it. + * Distributor - Set 0 if not concerned with any private + * severity, or give the private severity's + * handle to set with the given fd. + * + * Return value: OK or ERROR with: + * errno = REPORT_ERROR_NOT_ENOUGH_MEMORY if destination list + * is full + * errno = REPORT_ERROR_ILLEGAL_PARAMETER if (func == NULL) + **************************************************************************/ +extern STATUS ReportFunc(ReportFunction func, + uint32_t SwitchAddRemove, + DistributorHandle Distributor); + + +/*************************************************************************** + * + * Name : ReportMonitorFunc + * + * Function : Add/remove an output routine that prints to the monitor + * + * Notes : Hiding Report messages from appearing on the monitor is + * enable when the HALT> prompt is shown (by pressing <ENTER>). + * The filtering is done using an internal routine. + * This routine can be added/removed using this call. + * It can be added either to the regular distributor or to each + * of the private distributors + * + * Parameters: SwitchAddRemove - REPORT_ADD to add the routine + * REPORT_REMOVE to remove it. + * Distributor - Set 0 if not concerned with any private + * severity, or give the private severity's + * handle to set with it . + * + * Return value: void + **************************************************************************/ +extern void ReportMonitorFunc(uint32_t SwitchAddRemove, uint32_t Distributor); + +/*----------------------------------------------------------------------------*/ +/*------------------------------ Severity ------------------------------------*/ +/*----------------------------------------------------------------------------*/ + +/*************************************************************************** + * + * Name : ReportSeveritySet + * + * Function : Determine the filter level of the message's severity + * + * Notes : Messages with severity below this level wont be sent to + * their output + * It does not affect the private severities + * + * Return value: void + **************************************************************************/ +extern void ReportSeveritySet(ErrorSeverity level); + +/*----------------------------------------------------------------------------*/ + +#define S1(x) #x +#define S2(x) S1(x) +//#define LOCATION __FILE__ " : " S2(__LINE__) +#define REPORT_LINE(message) __FILE__ "." S2(__LINE__) ":t"S2(UsersysTickGet())" : " S2(message) +//#define REPORT_LINE(message) __FILE__ "." _ASSERT_STR(__LINE__) ": " message + +/*----------------------------------------------------------------------------*/ +/*---------------------- Backward Support to UT_Except -----------------------*/ +/*----------------------------------------------------------------------------*/ + +#define ON_ERROR_REPORT_ERROR(msg) if ( rc != 0 ) \ + Report("\n\r*** ERROR :" REPORT_LINE(msg),__FILE__,__LINE__,rc,RpFatalError,0,0) + +#define REPORT_ERROR(rc,msg) \ + Report("\n\r*** ERROR :" REPORT_LINE(msg),__FILE__,__LINE__,rc,RpFatalError,0,0) + +#define ON_ERROR_LOG_ERROR(msg) if ( rc != 0 ) \ + Report("\n\r*** ERROR :" REPORT_LINE(msg),__FILE__,__LINE__,rc,RpError,0,0) + +#define LOG_ERROR(rc,msg) \ + Report("\n\r*** ERROR :" REPORT_LINE(msg),__FILE__,__LINE__,rc,RpError,0,0) + +/*----------------------------------------------------------------------------*/ +/*----------------------- Backward Compatible --------------------------------*/ +/*----------------------------------------------------------------------------*/ +extern STATUS ReportMessage(const char *message); +extern STATUS Reportf(const char *format, ...); +#define ReportFilterMessage ReportPackageMessage2SysDist + +/*----------------------------------------------------------------------------*/ +/*---------------------------- Error Codes -----------------------------------*/ +/*----------------------------------------------------------------------------*/ + +/* Error, returned by errno in Report's routines */ +#define REPORT_ERROR_ILLEGAL_PARAMETER 1 +#define REPORT_ERROR_CODE_NOT_FOUND 2 +#define REPORT_ERROR_FILTER_NOT_ALIVE 3 +#define REPORT_ERROR_NAME 10 +#define REPORT_ERROR_NAME_EXISTS 11 +#define REPORT_ERROR_NAME_NOT_EXISTS 12 +#define REPORT_ERROR_NAME_TOO_LONG 13 +#define REPORT_ERROR_NAME_ALREADY_DISABLE 14 +#define REPORT_ERROR_NOT_ENOUGH_MEMORY 20 +#define REPORT_ERROR_TABLE_FULL 21 + +#ifdef __cplusplus +} +#endif + +#endif /* __REPORT_H__ */ + diff --git a/Software/Embedded_SW/Embedded/Common/report/reportInit.c b/Software/Embedded_SW/Embedded/Common/report/reportInit.c new file mode 100644 index 000000000..c7ea0c194 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Common/report/reportInit.c @@ -0,0 +1,161 @@ +/****************************************************************************** + * File name : reportInit.c + * Title : REPORT PACKAGE - Application Interface + * Date created : 01 SEP, 1996 + * Revision : 1.0 + * Author : Ilia Maller, Zvika Zilberman + * + * Description : + * + ****************************************************************************** + * + * Procedures: + * + * ReportInit - Initialise report package + * + ****************************************************************************** + * + * History: + * 01.09.96 Ilia Maller - start of coding + * 21.02.97 Ilia Maller - minor improvements + * 17.09.97 Zvika Zilberman - porting to DCME SWINFRA + * + ******************************************************************************/ + +/*------------- Includes --------------------------------*/ + +#include <stdio.h> /* puts(), etc. */ +#include "report.h" +#include "distributor.h" /* distibutorInit */ +#include "filter.h" +#include "include.h" + +#include <Modules/Stubs_Handler/DataDef.h> +#include "PMR/common/MessageContainer.pb-c.h" +#include "PMR/debugging/DebugLogRequest.pb-c.h" +#include "PMR/debugging/DebugLogResponse.pb-c.h" +#include "drivers/twine_usblib/usb_serial_adapter.h" +//#include "graphics_adapter.h" +#include "Modules/Stubs_Handler/Container.h" + +#include "Modules/thread/thread.h" + +MotorConfigStruc MotorsCfg[MAX_THREAD_MOTORS_NUM]; +InternalWinderConfigStruc InternalWinderCfg; +char protobufToken[36]; +/*void SendStatusResponse (uint32_t Code, char *Token) +{ + MessageContainer responseContainer; + StatusResponse response = STATUS_RESPONSE__INIT; + + + response.has_status = true; + response.status = (ErrorCode)Code; + + responseContainer = createContainer(MESSAGE_TYPE__StatusResponse, Token, true, &response, &status_response__pack, &status_response__get_packed_size); + uint8_t* container_buffer = malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + SendChars((char*)container_buffer, container_size); + free(container_buffer); + + +}*/ + +int ReportResponseFunc(char *message, /* The formatted message */ + char *FileName, + int LineNumber, + int errorCode, /* error code that caused the report */ + int parameter1, /* user parameter no. 1 */ + int parameter2) /* user parameter no. 2 */ +{ + MessageContainer responseContainer; + + DebugLogResponse response = DEBUG_LOG_RESPONSE__INIT; + response.filename = FileName; + response.has_linenumber = true; + response.linenumber = LineNumber; + /*response.has_errorcode = true; + response.errorcode = (ErrorCode)errorCode; + response.has_severity = true; + response.severity = (Severity)parameter1;*/ + response.has_filter = true; + response.has_category = true; + response.category = (DebugLogCategory)parameter1; + response.filter = parameter2; + strcpy (response.message,message); + responseContainer = createContainer(MESSAGE_TYPE__DebugLogResponse, protobufToken, false, &response, &debug_log_response__pack, &debug_log_response__get_packed_size); + uint8_t* container_buffer = malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + SendChars((char*)container_buffer, container_size); + + return OK; + +} + + +uint32_t ReportInitMessage(MessageContainer* requestContainer) +{ + uint32_t status = NOT_SUPPORTED; + //MessageContainer responseContainer; + + ReportInitParams InitParams; + + DebugLogRequest* request = debug_log_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); + strcpy (protobufToken, requestContainer->token); + InitParams.DistributorQueueMaxMsgs = 20; + InitParams.DistributorTaskPriority = 6; + InitParams.MaxNumOfFilterNames = 1; + InitParams.MaxNumberOfPrivateDistributors = 2; + status |= ReportInit (InitParams); + DistributorHandle ReportHandle = ReportAddDistributor("ProtoBuf"); + if (ReportHandle == NULL) status |= 0x8; + status |= ReportFunc(ReportResponseFunc , REPORT_ADD, ReportHandle); + + return status; +} + +#define REPORT_RESERVED_NUM_OF_FILTER_PACKAGES 30 /* This reserved for swinfra packages */ + +/*************************************************************************** + * + * Name : ReportInit + * + * Function : PEPORT library init + * + * Notes : Should be called before any other function from the Report + * package. + * + * Return value: OK or ERROR if malloc has failed or task creation has + * failed + **************************************************************************/ +STATUS ReportInit(ReportInitParams InitParams) +{ + static int initialized = false; + STATUS status; + int MaxNumOfFilterNames; + + if (initialized) + return OK; + + /* Set the filter to receive all kind */ + ReportSeveritySet(RpMessage); + + /* Configure distributor */ + if( distibutorInit(InitParams.DistributorTaskPriority, + InitParams.DistributorQueueMaxMsgs, + InitParams.MaxNumberOfPrivateDistributors) == -1) + return ERROR; + + /* Add the support of the monitor commands */ + //ReportMonitorInit(); + /* Add the Monitor Output routine, by default */ + //ReportMonitorFunc(REPORT_ADD, 0); + + MaxNumOfFilterNames = InitParams.MaxNumOfFilterNames; + MaxNumOfFilterNames += REPORT_RESERVED_NUM_OF_FILTER_PACKAGES; + status = filterTableInit(MaxNumOfFilterNames); + if (status == OK) + initialized = true; + + return status; +} |
