- introduced logsetup and savehdb
- moved logger.c and logreader.c for sics/psi/ to sics/ - make comments in status file
This commit is contained in:
86
logsetup.c
Normal file
86
logsetup.c
Normal file
@ -0,0 +1,86 @@
|
||||
#include "logger.h"
|
||||
#include "sics.h"
|
||||
#include "sicshipadaba.h"
|
||||
|
||||
static int LoggerUpdateCallback(void *user, void *conn, pHdb node, hdbValue value) {
|
||||
Logger *logger = user;
|
||||
pDynString str;
|
||||
|
||||
str = formatValue(value, node);
|
||||
LoggerWrite(logger, time(NULL), LoggerPeriod(logger), GetCharArray(str));
|
||||
DeleteDynString(str);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int LogSetup(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]) {
|
||||
pHdb node;
|
||||
pHdbCallback cb;
|
||||
static char basepath[1024]="/";
|
||||
char buf[1024];
|
||||
char *p, *name;
|
||||
static char *loggerDir=NULL;
|
||||
int numeric, period;
|
||||
Logger *logger;
|
||||
|
||||
if (argc < 2) {
|
||||
SCPrintf(pCon, eError, "ERROR: should be: logsetup <node> [<period> [<filename>]]");
|
||||
return 0;
|
||||
}
|
||||
if (strcasecmp(argv[1], "basepath") == 0) {
|
||||
if (argc > 2) {
|
||||
snprintf(basepath, sizeof basepath, "%s", argv[2]);
|
||||
}
|
||||
SCPrintf(pCon, eValue, "%s", basepath);
|
||||
return 1;
|
||||
}
|
||||
if (loggerDir == NULL) {
|
||||
loggerDir = IFindOption(pSICSOptions, "LoggerDir");
|
||||
if (loggerDir == NULL) loggerDir="./";
|
||||
LoggerSetDir(loggerDir);
|
||||
}
|
||||
if (strcasecmp(argv[1], "directory") == 0) {
|
||||
if (argc > 2) {
|
||||
loggerDir = strdup(argv[2]);
|
||||
}
|
||||
SCPrintf(pCon, eValue, "%s", loggerDir);
|
||||
return 1;
|
||||
}
|
||||
node = FindHdbNode(basepath, argv[1], pCon);
|
||||
if (node == NULL) {
|
||||
SCPrintf(pCon, eError, "ERROR: %s not found", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
period = 0;
|
||||
if (argc > 2) {
|
||||
period = atoi(argv[2]);
|
||||
}
|
||||
if (argc > 3) {
|
||||
snprintf(buf, sizeof buf, "%s", argv[3]);
|
||||
} else {
|
||||
snprintf(buf, sizeof buf, "%s", argv[1]);
|
||||
}
|
||||
for (p = buf; *p != '\0'; p++) {
|
||||
if (*p =='/') *p = '.';
|
||||
}
|
||||
if (buf[0] == '.') {
|
||||
name = buf+1;
|
||||
} else {
|
||||
name = buf;
|
||||
}
|
||||
if (node->value.dataType == HIPFLOAT) {
|
||||
numeric = 1;
|
||||
} else {
|
||||
numeric = 0;
|
||||
}
|
||||
logger = LoggerMake(name, period, !numeric);
|
||||
LoggerSetNumeric(logger, numeric);
|
||||
cb = MakeHipadabaCallback(LoggerUpdateCallback, logger, (void (*)(void *))LoggerKill, -1, NULL);
|
||||
assert(cb);
|
||||
AppendHipadabaCallback(node, HCBUPDATE, cb);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void LogSetupInit(void) {
|
||||
AddCmd("LogSetup",LogSetup);
|
||||
}
|
Reference in New Issue
Block a user