Implement 'sicslog' command for driver logging
This commit is contained in:
@ -57,6 +57,10 @@ typedef enum {
|
||||
eLogError /* error message to log: is always written to client */
|
||||
} OutCode;
|
||||
|
||||
const char* OutCodeToTxt(OutCode outcode);
|
||||
const char* OutCodeToText(OutCode outcode);
|
||||
int OutCodeFromText(const char *text, OutCode *outcode);
|
||||
|
||||
#include "interrupt.h"
|
||||
|
||||
/* define some user rights codes */
|
||||
|
57
conman.c
57
conman.c
@ -87,6 +87,9 @@ int KillCapture(SConnection * pCon);
|
||||
int LogCapture(SConnection * pCon, SicsInterp * pInter, void *pData,
|
||||
int argc, char *argv[]);
|
||||
|
||||
int LogOutput(SConnection * pCon, SicsInterp * pInter, void *pData,
|
||||
int argc, char *argv[]);
|
||||
|
||||
/*------ Max Size of Command Stack */
|
||||
#define MAXSTACK 1024
|
||||
/*---------- Magic ID Header */
|
||||
@ -2194,6 +2197,60 @@ int LogCapture(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------------------------------------------------
|
||||
the command function:
|
||||
Syntax:
|
||||
LogOutput [OutCode] <text>
|
||||
Logs <text> with outcode OutCode default eLog
|
||||
-------------------------------------------------------------------------- */
|
||||
|
||||
int LogOutput(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char pBueffel[512];
|
||||
char *pBuff;
|
||||
int i, len, result, start;
|
||||
OutCode outcode;
|
||||
|
||||
/* check no af args */
|
||||
if (argc < 2) {
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Insufficient number of arguments to %s", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* assume default eLog unless told otherwise */
|
||||
start = 1;
|
||||
outcode = eLog;
|
||||
if (argv[1][0] == '@') {
|
||||
result = OutCodeFromText(&argv[1][1], &outcode);
|
||||
if (result >= 0) {
|
||||
start = 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* make it a string */
|
||||
for (i = start, len = 0; i < argc; ++i)
|
||||
len += strlen(argv[i]) + 1;
|
||||
if (len > sizeof(pBueffel))
|
||||
pBuff = malloc(len+10);
|
||||
else
|
||||
pBuff = pBueffel;
|
||||
if (pBuff == NULL) {
|
||||
SCWrite(pCon, "Out of memory in LogOutput\n", eError);
|
||||
return 1;
|
||||
}
|
||||
for (i = start, len = 0; i < argc; ++i) {
|
||||
if (i > start)
|
||||
pBuff[len++] = ' ';
|
||||
strcpy(&pBuff[len], argv[i]);
|
||||
len += strlen(argv[i]);
|
||||
}
|
||||
SICSLogWrite(pBuff, outcode);
|
||||
if (pBuff != pBueffel)
|
||||
free(pBuff);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int SCTaskFunction(void *pData)
|
||||
{
|
||||
|
1
ofac.c
1
ofac.c
@ -102,6 +102,7 @@ static void InitIniCommands(SicsInterp * pInter)
|
||||
PCMD("sicscron", MakeCron);
|
||||
PCMD("sicsdatafactory", SICSDataFactory);
|
||||
PCMD("sicsdescriptor", SICSDescriptor);
|
||||
PCMD("SICSLog", LogOutput);
|
||||
PCMD("sicsprompt", SicsPrompt);
|
||||
PCMD("SICSStatus", SICSStatus);
|
||||
PCMD("sicstime", SICSTime);
|
||||
|
39
servlog.c
39
servlog.c
@ -82,7 +82,7 @@ static pCaptureEntry pCapture = NULL;
|
||||
/*------------------------------------------------------------------------*/
|
||||
#include "outcode.c" /* for pCode */
|
||||
|
||||
static char* OutCodeToTxt(OutCode eOut)
|
||||
const char* OutCodeToTxt(OutCode eOut)
|
||||
{
|
||||
switch (eOut) {
|
||||
case eInternal: return "Int"; /* internal */
|
||||
@ -104,10 +104,45 @@ static char* OutCodeToTxt(OutCode eOut)
|
||||
return "???";
|
||||
}
|
||||
|
||||
const char* OutCodeToText(OutCode eOut)
|
||||
{
|
||||
switch (eOut) {
|
||||
case eInternal: return "Internal";
|
||||
case eCommand: return "Command";
|
||||
case eHWError: return "HWError";
|
||||
case eInError: return "InError";
|
||||
case eStatus: return "Status";
|
||||
case eValue: return "Value";
|
||||
case eStart: return "Start";
|
||||
case eFinish: return "Finish";
|
||||
case eEvent: return "Event";
|
||||
case eWarning: return "Warning";
|
||||
case eError: return "Error";
|
||||
case eHdbValue: return "HdbValue";
|
||||
case eHdbEvent: return "HdbEvent";
|
||||
case eLog: return "Log";
|
||||
case eLogError: return "LogError";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
int OutCodeFromText(const char *text, OutCode *outcode)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < iNoCodes; ++i) {
|
||||
if (strcasecmp(text, pCode[i]) == 0) {
|
||||
if (outcode)
|
||||
*outcode = i;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static unsigned int find_code_bits(const char *p1, const char *p2) {
|
||||
/* must be outcode, try find it */
|
||||
int i;
|
||||
int len = p2 - p1;
|
||||
size_t len = p2 - p1;
|
||||
if (len == 3 && strncasecmp(p1, "all", 3))
|
||||
return ~0;
|
||||
for (i = 0; i < iNoCodes; ++i) {
|
||||
|
Reference in New Issue
Block a user