- Reworked the connection object and the IO system
- Reworked the support for TRICS - Added a second generation motor
This commit is contained in:
102
scriptcontext.c
102
scriptcontext.c
@@ -33,7 +33,7 @@ typedef struct ScriptContext {
|
||||
struct SctController {
|
||||
DevSer *devser;
|
||||
Hdb *node; /* the controller node */
|
||||
SCStore *conn;
|
||||
SConnection*conn;
|
||||
int verbose;
|
||||
};
|
||||
|
||||
@@ -41,13 +41,13 @@ struct SctController {
|
||||
typedef struct SctData {
|
||||
char *name;
|
||||
SctController *controller;
|
||||
SCStore *conCtx;
|
||||
SConnection*conCtx;
|
||||
int answered;
|
||||
Hdb *node;
|
||||
} SctData;
|
||||
|
||||
static ScriptContext *sct = NULL;
|
||||
static SCStore *currentCon = NULL;
|
||||
static SConnection *currentCon = NULL;
|
||||
|
||||
static struct {
|
||||
char *name;
|
||||
@@ -184,6 +184,14 @@ int SctCommand(SConnection *con, SicsInterp *sics, void *object,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* controller
|
||||
*/
|
||||
if(strcmp(argv[1],"controller") == 0){
|
||||
SCWrite(con,cNode->name, eValue);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* time stamping
|
||||
*/
|
||||
@@ -271,9 +279,9 @@ static char *SctActionHandler(void *actionData, char *lastReply) {
|
||||
char timeKey[50], timeVal[50];
|
||||
|
||||
if (currentCon) {
|
||||
con = SCStorePush(currentCon);
|
||||
con = currentCon;
|
||||
} else {
|
||||
con = SCStorePush(controller->conn);
|
||||
con = controller->conn;
|
||||
}
|
||||
SetProp(node, controller->node, "result", lastReply);
|
||||
if (controller->verbose && lastReply != NULL && *lastReply != '\0') {
|
||||
@@ -310,26 +318,16 @@ static char *SctActionHandler(void *actionData, char *lastReply) {
|
||||
send = GetProp(node, controller->node, "send");
|
||||
if (send != NULL && send[0] != '\0') {
|
||||
if (controller->verbose) {
|
||||
SCPrintf(con, eWarning, "send : %s", send);
|
||||
}
|
||||
if (currentCon) {
|
||||
SCStorePop(currentCon);
|
||||
} else {
|
||||
SCStorePop(controller->conn);
|
||||
SCPrintf(con, eLog, "send : %s", send);
|
||||
}
|
||||
return send;
|
||||
}
|
||||
}
|
||||
SCPrintf(con, eError, "ERROR: too many quick scripts chained");
|
||||
SCPrintf(con, eLogError, "ERROR: too many quick scripts chained");
|
||||
finish:
|
||||
SetProp(node, controller->node, "state", "idle");
|
||||
if (currentCon) {
|
||||
SCStorePop(currentCon);
|
||||
} else {
|
||||
SCStorePop(controller->conn);
|
||||
}
|
||||
if (data->conCtx != NULL) {
|
||||
SCStoreFree(data->conCtx);
|
||||
SCDeleteConnection(data->conCtx);
|
||||
data->conCtx = NULL;
|
||||
}
|
||||
return send;
|
||||
@@ -337,7 +335,7 @@ finish:
|
||||
|
||||
static char *SctWriteHandler(void *actionData, char *lastReply) {
|
||||
SctData *data = actionData;
|
||||
SCStore *old;
|
||||
SConnection*old;
|
||||
char *result;
|
||||
|
||||
old = currentCon;
|
||||
@@ -470,14 +468,12 @@ static hdbCallbackReturn SctActionCallback(Hdb *node, void *userData,
|
||||
}
|
||||
|
||||
if (data->conCtx != NULL) {
|
||||
con2 = SCStorePush(data->conCtx);
|
||||
GetHdbPath(node, path, sizeof path);
|
||||
SCPrintf(con2, eValue, "%s target changed to %s before completion",
|
||||
SCPrintf(data->conCtx, eLog, "%s target changed to %s before completion",
|
||||
path, GetCharArray(text));
|
||||
SCStorePop(data->conCtx);
|
||||
}
|
||||
DeleteDynString(text);
|
||||
data->conCtx = SCSave(con, data->conCtx);
|
||||
data->conCtx = SCCopyConnection(con);
|
||||
data->answered = 0;
|
||||
DevQueue(data->controller->devser, data, prio,
|
||||
SctWriteHandler, SctMatch, NULL);
|
||||
@@ -490,12 +486,12 @@ static hdbCallbackReturn SctActionCallback(Hdb *node, void *userData,
|
||||
if (currentCon) { /* update called from a write action */
|
||||
data->answered = 1;
|
||||
GetHdbPath(node, path, sizeof path);
|
||||
con = SCStorePush(currentCon);
|
||||
con = currentCon;
|
||||
text = formatValue(*(mm->v), node);
|
||||
SCPrintf(con, eStatus, "%s = %s", path,
|
||||
/* Markus: who is receiving this message? */
|
||||
SCPrintf(con, eLog, "%s = %s", path,
|
||||
GetCharArray(text));
|
||||
DeleteDynString(text);
|
||||
SCStorePop(currentCon);
|
||||
}
|
||||
return hdbContinue;
|
||||
}
|
||||
@@ -537,7 +533,7 @@ static void SctKillData(void *d) {
|
||||
SctData *data = d;
|
||||
|
||||
if (data->name) free(data->name);
|
||||
if (data->conCtx) SCStoreFree(data->conCtx);
|
||||
if (data->conCtx) SCDeleteConnection(data->conCtx);
|
||||
free(data);
|
||||
}
|
||||
|
||||
@@ -564,7 +560,7 @@ int SctAddPollNode(SctController *controller, Hdb *node, double interval,
|
||||
assert(data);
|
||||
data->controller = controller;
|
||||
data->node = node;
|
||||
data->conCtx = NULL;
|
||||
data->conCtx = NULL; /* we might need a dummy connection here */
|
||||
data->name = strdup(action);
|
||||
|
||||
return DevSchedule(controller->devser, data, prio, interval,
|
||||
@@ -755,10 +751,16 @@ void SctQueueNode(SctController *controller, Hdb *node,
|
||||
data->name = strdup(action);
|
||||
data->conCtx = NULL;
|
||||
|
||||
DevQueue(data->controller->devser, data, prio,
|
||||
SctWriteHandler, SctMatch, SctKillData);
|
||||
if (con != NULL) {
|
||||
data->conCtx = SCSave(con, NULL);
|
||||
if(!DevQueue(data->controller->devser, data, prio,
|
||||
SctWriteHandler, SctMatch, SctKillData)){
|
||||
if(data->name != NULL){
|
||||
free(data->name);
|
||||
}
|
||||
free(data);
|
||||
} else {
|
||||
if (con != NULL) {
|
||||
data->conCtx = SCCopyConnection(con);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -813,6 +815,9 @@ static void KillSctTransact(void *data){
|
||||
if(self->command){
|
||||
free(self->command);
|
||||
}
|
||||
if(self->con){
|
||||
SCDeleteConnection(self->con);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
|
||||
@@ -844,7 +849,7 @@ static int SctTransactCmd(pSICSOBJ ccmd, SConnection *con,
|
||||
SCWrite(con,"ERROR: out of memory in SctTransactCommand", eError);
|
||||
return 0;
|
||||
}
|
||||
st->con = con;
|
||||
st->con = SCCopyConnection(con);
|
||||
st->command = strdup(par[0]->value.v.text);
|
||||
|
||||
DevQueue(c->devser, st, WritePRIO,
|
||||
@@ -863,6 +868,8 @@ static int SctSendCmd(pSICSOBJ ccmd, SConnection *con,
|
||||
Hdb *cmdNode, Hdb *par[], int nPar) {
|
||||
pSctTransact st = NULL;
|
||||
SctController *c;
|
||||
char *prioText = NULL;
|
||||
int prio;
|
||||
|
||||
c = (SctController *)ccmd->pPrivate;
|
||||
|
||||
@@ -871,14 +878,28 @@ static int SctSendCmd(pSICSOBJ ccmd, SConnection *con,
|
||||
SCWrite(con,"ERROR: out of memory in SctSendCmd", eError);
|
||||
return 0;
|
||||
}
|
||||
st->con = con;
|
||||
st->con = SCCopyConnection(con);
|
||||
st->command = strdup(par[0]->value.v.text);
|
||||
|
||||
DevQueue(c->devser, st, WritePRIO,
|
||||
prioText = ParText(cmdNode, "prio", nPar, "write");
|
||||
prio = DevText2Prio(prioText);
|
||||
if(prio == NullPRIO){
|
||||
prio = WritePRIO;
|
||||
}
|
||||
|
||||
DevQueue(c->devser, st, prio,
|
||||
TransactionHandler, SctTransactMatch, KillSctTransact);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int SctDisconnect(pSICSOBJ ccmd, SConnection *con,
|
||||
Hdb *cmdNode, Hdb *par[], int nPar) {
|
||||
SctController *c;
|
||||
|
||||
c = (SctController *)ccmd->pPrivate;
|
||||
DevDisconnect(c->devser);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static hdbCallbackReturn SctDebugCallback(Hdb *node, void *userData,
|
||||
hdbMessage *msg) {
|
||||
@@ -911,9 +932,7 @@ static void SctKillController(void *c) {
|
||||
CleanStack(controller->node);
|
||||
RemoveSICSInternalCallback(controller);
|
||||
if (controller->conn) {
|
||||
con = SCLoad(controller->conn);
|
||||
SCDeleteConnection(con);
|
||||
SCStoreFree(controller->conn);
|
||||
SCDeleteConnection(controller->conn);
|
||||
}
|
||||
DevKill(controller->devser);
|
||||
free(controller);
|
||||
@@ -943,7 +962,7 @@ static int SctMakeController(SConnection *con, SicsInterp *sics,
|
||||
|
||||
ccmd = MakeSICSOBJv(nodeName, "SctController", HIPNONE, usSpy);
|
||||
controller->node = ccmd->objectNode;
|
||||
controller->conn = SCSave(SCCreateDummyConnection(pServ->pSics), NULL);
|
||||
controller->conn = SCCreateDummyConnection(pServ->pSics);
|
||||
|
||||
assert(ccmd);
|
||||
assert(controller->node->mama == NULL);
|
||||
@@ -992,8 +1011,11 @@ static int SctMakeController(SConnection *con, SicsInterp *sics,
|
||||
cmd = AddSICSHdbPar(controller->node,
|
||||
"send", usMugger, MakeSICSFunc(SctSendCmd));
|
||||
AddSICSHdbPar(cmd, "data", usMugger, MakeHdbText(""));
|
||||
AddSICSHdbPar(cmd, "prio", usMugger, MakeHdbText(""));
|
||||
|
||||
|
||||
cmd = AddSICSHdbPar(controller->node,
|
||||
"disconnect", usMugger, MakeSICSFunc(SctDisconnect));
|
||||
|
||||
par = AddSICSHdbPar(controller->node, "debug", usUser, MakeHdbInt(-1));
|
||||
|
||||
cb = MakeHipadabaCallback(SctDebugCallback, controller, NULL);
|
||||
|
||||
Reference in New Issue
Block a user