- introduced <controller> actions function for listing actions
- introduced <controller> reconnect function - list seconds of minute in debugging mode - "sct utime" may be used from scripts to get the milliseconds time
This commit is contained in:
@ -162,7 +162,6 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object,
|
||||
Hdb *node = NULL;
|
||||
Hdb *cNode = NULL;
|
||||
hdbValue v;
|
||||
double dtime;
|
||||
|
||||
assert(sct == object);
|
||||
if (sct->nodes != NULL) {
|
||||
@ -222,13 +221,12 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object,
|
||||
* time stamping
|
||||
*/
|
||||
if (strcmp(argv[1], "utime") == 0) {
|
||||
if (argc < 3) {
|
||||
SCWrite(con, "ERROR: need property to write time stamp too", eError);
|
||||
return 0;
|
||||
snprintf(value, 1024, "%.3f", DoubleTime());
|
||||
if (argc > 2) { /* if no property is given, use only return value */
|
||||
SetHdbProperty(node, argv[2], value);
|
||||
}
|
||||
dtime = DoubleTime();
|
||||
snprintf(value, 1024, "%.3f", dtime);
|
||||
SetHdbProperty(node, argv[2], value);
|
||||
/* write time as return value */
|
||||
SCWrite(con, value, eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -268,6 +266,11 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object,
|
||||
return 1;
|
||||
}
|
||||
|
||||
double secondsOfMinute() {
|
||||
double now=DoubleTime();
|
||||
return (now/60-floor(now/60))*60;
|
||||
}
|
||||
|
||||
int SctCallInContext(SConnection * con, char *script, Hdb * node,
|
||||
SctController * controller, char **resPtr)
|
||||
{
|
||||
@ -279,7 +282,7 @@ int SctCallInContext(SConnection * con, char *script, Hdb * node,
|
||||
|
||||
PushContext(node, controller->node);
|
||||
if (verbose) {
|
||||
SCPrintf(con, eLog, "script: %s", script);
|
||||
SCPrintf(con, eLog, "%6.3f script: %s", secondsOfMinute(), script);
|
||||
}
|
||||
|
||||
MacroPush(con);
|
||||
@ -295,7 +298,7 @@ int SctCallInContext(SConnection * con, char *script, Hdb * node,
|
||||
}
|
||||
}
|
||||
if (verbose) {
|
||||
SCPrintf(con, eLog, "error: %s", result);
|
||||
SCPrintf(con, eLog, "%6.3f error: %s", secondsOfMinute(), result);
|
||||
}
|
||||
iRet = 0;
|
||||
}
|
||||
@ -362,7 +365,7 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
||||
script = NULL;
|
||||
if (!commError && controller->verbose && lastReply != NULL
|
||||
&& *lastReply != '\0') {
|
||||
SCPrintf(con, eLog, "reply : %s\n", lastReply);
|
||||
SCPrintf(con, eLog, "%6.3f reply : %s\n", secondsOfMinute(), lastReply);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -499,7 +502,7 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
||||
if (send == NULL)
|
||||
send = "";
|
||||
if (controller->verbose) {
|
||||
SCPrintf(con, eLog, "send : %s", send);
|
||||
SCPrintf(con, eLog, "%6.3f send : %s", secondsOfMinute(), send);
|
||||
}
|
||||
return send;
|
||||
}
|
||||
@ -545,6 +548,18 @@ static int SctMatchNode(void *vNode, void *vData)
|
||||
return node == d->node;
|
||||
}
|
||||
|
||||
static char * SctDataInfo(void *d)
|
||||
{
|
||||
SctData *data = d;
|
||||
char text[256];
|
||||
int l;
|
||||
|
||||
snprintf(text, sizeof text, "%s ", data->name);
|
||||
l = strlen(text);
|
||||
GetHdbPath(data->node, text + l, sizeof text - l);
|
||||
return strdup(text);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the callback for all nodes participating in the
|
||||
* scriptcontext system
|
||||
@ -708,7 +723,7 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData,
|
||||
data->answered = 0;
|
||||
data->inMacro = SCinMacro(con);
|
||||
DevQueue(data->controller->devser, data, prio,
|
||||
SctWriteHandler, SctMatch, NULL);
|
||||
SctWriteHandler, SctMatch, NULL, SctDataInfo);
|
||||
/* no kill function in DevQueue: data is owned by the node (callback list) */
|
||||
return hdbContinue;
|
||||
}
|
||||
@ -815,7 +830,7 @@ int SctAddPollNode(SctController * controller, Hdb * node, double interval,
|
||||
data->name = strdup(action);
|
||||
|
||||
return DevSchedule(controller->devser, data, prio, interval,
|
||||
SctActionHandler, SctMatch, SctKillData);
|
||||
SctActionHandler, SctMatch, SctKillData, SctDataInfo);
|
||||
|
||||
}
|
||||
|
||||
@ -852,13 +867,13 @@ static int SctPollCmd(pSICSOBJ ccmd, SConnection * con,
|
||||
}
|
||||
action = ParText(cmdNode, "action", nPar, "read");
|
||||
|
||||
if (SctAddPollNode(controller, node, interval, prio, action) > 0) {
|
||||
if (SctAddPollNode(controller, node, interval, prio, action)) {
|
||||
SCPrintf(con, eValue,
|
||||
"%s poll on %s changed to %g sec, %s prio",
|
||||
"%s poll registered on %s (%g sec, %s prio)",
|
||||
action, path, interval, prioText);
|
||||
} else {
|
||||
SCPrintf(con, eValue,
|
||||
"%s poll registered on %s (%g sec, %s prio)",
|
||||
"%s poll on %s changed to %g sec, %s prio",
|
||||
action, path, interval, prioText);
|
||||
}
|
||||
return 1;
|
||||
@ -1009,7 +1024,7 @@ void SctQueueNode(SctController * controller, Hdb * node,
|
||||
data->answered = 1;
|
||||
|
||||
if (DevQueue(data->controller->devser, data, prio,
|
||||
SctWriteHandler, SctMatch, SctKillData)) {
|
||||
SctWriteHandler, SctMatch, SctKillData, SctDataInfo)) {
|
||||
if (con != NULL) {
|
||||
data->conCtx = SCCopyConnection(con);
|
||||
}
|
||||
@ -1084,13 +1099,13 @@ static char *TransactionHandler(void *actionData, char *lastReply,
|
||||
if (st->sent == 0) {
|
||||
st->sent = 1;
|
||||
if (st->controller->verbose) {
|
||||
SCPrintf(st->con, eLog, "send : %s", st->command);
|
||||
SCPrintf(st->con, eLog, "%6.3f send : %s", secondsOfMinute(), st->command);
|
||||
}
|
||||
return st->command;
|
||||
} else {
|
||||
st->sent = 2;
|
||||
if (st->controller->verbose) {
|
||||
SCPrintf(st->con, eLog, "reply : %s", lastReply);
|
||||
SCPrintf(st->con, eLog, "%6.3f reply : %s", secondsOfMinute(), lastReply);
|
||||
}
|
||||
SCWrite(st->con, lastReply, eValue);
|
||||
return NULL;
|
||||
@ -1119,7 +1134,7 @@ static int SctTransactCmd(pSICSOBJ ccmd, SConnection * con,
|
||||
st->controller = c;
|
||||
|
||||
DevQueue(c->devser, st, WritePRIO,
|
||||
TransactionHandler, SctTransactMatch, NULL);
|
||||
TransactionHandler, SctTransactMatch, NULL, NULL);
|
||||
while (st->sent != 2) {
|
||||
TaskYield(pServ->pTasker);
|
||||
if (SCGetInterrupt(con) != eContinue) {
|
||||
@ -1156,7 +1171,7 @@ static int SctSendCmd(pSICSOBJ ccmd, SConnection * con,
|
||||
}
|
||||
|
||||
DevQueue(c->devser, st, prio,
|
||||
TransactionHandler, SctTransactMatch, KillSctTransact);
|
||||
TransactionHandler, SctTransactMatch, KillSctTransact, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1170,6 +1185,28 @@ static int SctDisconnect(pSICSOBJ ccmd, SConnection * con,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int SctReconnect(pSICSOBJ ccmd, SConnection * con,
|
||||
Hdb * cmdNode, Hdb * par[], int nPar)
|
||||
{
|
||||
SctController *c;
|
||||
|
||||
c = (SctController *) ccmd->pPrivate;
|
||||
DevReconnect(c->devser, ParText(cmdNode, "hostport", nPar, ""));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int SctListActions(pSICSOBJ ccmd, SConnection * con,
|
||||
Hdb * cmdNode, Hdb * par[], int nPar)
|
||||
{
|
||||
SctController *c;
|
||||
char *result;
|
||||
|
||||
c = (SctController *) ccmd->pPrivate;
|
||||
result = DevList(c->devser);
|
||||
SCWrite(con, result, eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static hdbCallbackReturn SctDebugCallback(Hdb * node, void *userData,
|
||||
hdbMessage * msg)
|
||||
{
|
||||
@ -1323,8 +1360,15 @@ static int SctMakeController(SConnection * con, SicsInterp * sics,
|
||||
cmd = AddSICSHdbPar(controller->node,
|
||||
"disconnect", usMugger, MakeSICSFunc(SctDisconnect));
|
||||
|
||||
cmd = AddSICSHdbPar(controller->node,
|
||||
"reconnect", usMugger, MakeSICSFunc(SctReconnect));
|
||||
AddSICSHdbPar(cmd, "hostport", usMugger, MakeHdbText(""));
|
||||
|
||||
par = AddSICSHdbPar(controller->node, "debug", usUser, MakeHdbInt(-1));
|
||||
|
||||
cmd = AddSICSHdbPar(controller->node,
|
||||
"actions", usUser, MakeSICSFunc(SctListActions));
|
||||
|
||||
cb = MakeHipadabaCallback(SctDebugCallback, controller, NULL);
|
||||
if (cb)
|
||||
AppendHipadabaCallback(par, cb);
|
||||
|
Reference in New Issue
Block a user