From 92c0e928a789ae842e8b0151239c2b3464dcf838 Mon Sep 17 00:00:00 2001 From: zolliker Date: Mon, 29 Aug 2011 11:56:06 +0000 Subject: [PATCH] added dummy protocol without real controller --- dumprot.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 dumprot.c diff --git a/dumprot.c b/dumprot.c new file mode 100644 index 0000000..470001d --- /dev/null +++ b/dumprot.c @@ -0,0 +1,60 @@ +#include "ascon.h" +#include "ascon.i" + +/* + * this is a scriptcontext driver connecting to its own sics server + * after a send command the configured polling script is called repeatedly + * with the sent command as argument until it returns something else than 0 + * + * Markus Zolliker Aug 2011 + */ + +/*----------------------------------------------------------------------------*/ +int DumProtHandler(Ascon *a) +{ + Tcl_Interp *pTcl = InterpGetTcl(pServ->pSics); + int ret, l; + char *result = NULL; + int iRet = 1; + + switch (a->state) { + case AsconConnectStart: + case AsconConnecting: + a->state = AsconConnectDone; + break; + case AsconWriteStart: + DynStringInsert(a->wrBuffer, " ", 0); + DynStringInsert(a->wrBuffer, a->hostport, 0); + case AsconWriting: + a->state = AsconWriteDone; + break; + case AsconReadStart: + case AsconReading: + ret = Tcl_EvalEx(pTcl, GetCharArray(a->wrBuffer), l, 0); + result = (char *) Tcl_GetStringResult(pTcl); + DynStringCopy(a->rdBuffer, result); + if (ret != TCL_OK || strcmp(result, "0") != 0) { + a->state = AsconReadDone; + } + break; + } + return 0; +} + +/*----------------------------------------------------------------------------*/ +static int DumProtInit(Ascon * a, SConnection * con, int argc, char *argv[]) +{ + /* argv[1] is the polling script. stored in hostport */ + a->hostport = strdup(argv[1]); + return 1; +} + +/*----------------------------------------------------------------------------*/ +void AddDumProtocol() +{ + static AsconProtocol dumprot; + dumprot.name = "dumprot"; + dumprot.handler = DumProtHandler; + dumprot.init = DumProtInit; + AsconInsertProtocol(&dumprot); +}