From 91b9df034959d78fe37dd60682ecab35c52454c1 Mon Sep 17 00:00:00 2001 From: zolliker Date: Tue, 21 Aug 2012 06:46:25 +0000 Subject: [PATCH] - added seaclientprot (communication with other sics/sea servers) --- make_gen | 2 +- psi.c | 1 + seaclientprot.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 seaclientprot.c diff --git a/make_gen b/make_gen index 974edb0..397ed1e 100644 --- a/make_gen +++ b/make_gen @@ -31,7 +31,7 @@ OBJ=psi.o buffer.o ruli.o sps.o pimotor.o charbychar.o\ MZOBJ=fsm.o sugar.o pardef.o ease.o strobj.o oxinst.o \ ipsdriv.o ilmdriv.o itcdriv.o ighdriv.o euro2kdriv.o modbus.o arrobj.o \ lscsupport.o lsc370driv.o linadriv.o haakedriv.o amilevel.o binprot.o \ - cnvrt.o dumprot.o + cnvrt.o seaclientprot.o dumprot.o libpsi.a: $(OBJ) rm -f libpsi.a diff --git a/psi.c b/psi.c index 741ff8c..a36a320 100644 --- a/psi.c +++ b/psi.c @@ -73,6 +73,7 @@ void SiteInit(void) INIT(AddSLSEchoProtocoll); INIT(AddCharByCharProtocoll); INIT(AddBinProtocol); + INIT(AddSeaClientProtocol); INIT(AddDumProtocol); INIT(AddJVLProtocoll); diff --git a/seaclientprot.c b/seaclientprot.c new file mode 100644 index 0000000..b31aa19 --- /dev/null +++ b/seaclientprot.c @@ -0,0 +1,93 @@ +#include +#include +#include +#include "ascon.h" +#include "ascon.i" +#include "dynstring.h" +#include "cnvrt.h" + +/* + * this is a driver for connection to an other sea (or sics) server + * + * Markus Zolliker June 2012 + * + */ + +/*----------------------------------------------------------------------------*/ +int SeaClientHandler(Ascon *a) { + int ret; + char chr; + int tmo; + char *line; + int result; + + switch (a->state) { + case AsconWriteStart: + line = GetCharArray(a->wrBuffer); + if (strncasecmp(line, "fulltransact", 12) == 0) { + a->readState = 0; + } else if (strncasecmp(line, "transact", 8) == 0) { + a->readState = 1; + } else if (strstr(line, "\ntransAct ") != 0) { + a->readState = 1; + } else { + a->readState = 2; + } + a->lineCount = 0; /* used as position to beginning of line */ + break; + case AsconReading: + result = AsconBaseHandler(a); + if (result == 0) + return 0; + chr = a->lastChar; + if (chr == '\n') { + line = GetCharArray(a->rdBuffer) + a->lineCount; + switch (a->readState) { + case 0: + if (strncmp(line, "TRANSACTIONSTART", 16) == 0) { + a->readState = 1; + DynStringClear(a->rdBuffer); + } + break; + case 1: + if (strncmp(line, "TRANSACTIONFINISHED", 19) == 0) { + a->state = AsconReadDone; + if (a->lineCount > 0) { + a->lineCount--; + } + DynStringShorten(a->rdBuffer, a->lineCount); + } + break; + case 2: + a->state = AsconReadDone; + DynStringBackspace(a->rdBuffer); + break; + } + a->lineCount = GetDynStringLength(a->rdBuffer); /* set position of new line */ + } + return 1; + } + return AsconBaseHandler(a); +} +/*----------------------------------------------------------------------------*/ +static int SeaClientInit(Ascon * a, SConnection * con, int argc, char *argv[]) +{ + a->hostport = strdup(argv[1]); + if (argc > 2) { + a->timeout = atof(argv[2]); + } else { + a->timeout = 5.0; + } + a->sendTerminator = strdup("\n"); + return 1; +} + +/*----------------------------------------------------------------------------*/ +void AddSeaClientProtocol() +{ + static AsconProtocol seaclientprot; + seaclientprot.name = "seaclient"; + seaclientprot.handler = SeaClientHandler; + seaclientprot.init = SeaClientInit; + AsconInsertProtocol(&seaclientprot); +}