From 586b4e1b78e560baa0c8b264ca35e5fe3e1f268f Mon Sep 17 00:00:00 2001 From: koennecke Date: Tue, 13 Apr 2010 15:12:18 +0000 Subject: [PATCH] - Added missing file charbychar.c which contains a protocol handler which writes char by char, thereby waiting for the echo character to be received in between. --- charbychar.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 charbychar.c diff --git a/charbychar.c b/charbychar.c new file mode 100644 index 0000000..a4ea145 --- /dev/null +++ b/charbychar.c @@ -0,0 +1,73 @@ +/* + * charbychar.c + * + * This is a variation of the standard AsonHandler which implements + * a char by char mode while sending. This means, that the protocol + * handler waits for the echoed character from the device before sending + * the next character. + * + * Created on: Apr 1, 2010 + * Author: koennecke + */ +#include +#include +#include + +/*----------------------------------------------------------- + * I am abusing the echo field as a flag if we are reading + * an echo char or not +-----------------------------------------------------------*/ +static int CharByCharHandler(Ascon *a) +{ + int ret; + char chr; + + switch(a->state){ + case AsconWriting: + if(a->wrPos < GetDynStringLength(a->wrBuffer)){ + ret = AsconWriteChars(a->fd,GetCharArray(a->wrBuffer)+a->wrPos,1); + if (ret < 0) { + AsconError(a, "ASC4", errno); /* sets state to AsconFailed */ + return 0; + } else { + a->wrPos++; + a->private = (void *)1; + a->state = AsconReading; + a->start = DoubleTime(); + } + break; + } else { + a->private = NULL; + a->state = AsconWriteDone; + } + break; + case AsconReading: + /** + * Here I rely on the fact that the base + * handler, in AsconReadStart, clears the + * rdBuffer of amassed echo characters. + */ + ret = AsconStdHandler(a); + if(ret == 1){ + if(a->private != NULL){ + a->state = AsconWriting; + } + } + return ret; + break; + default: + return AsconStdHandler(a); + } + return 1; +} +/*------------------------------------------------------------------------*/ +void AddCharByCharProtocoll() +{ + AsconProtocol *prot = NULL; + + prot = calloc(sizeof(AsconProtocol), 1); + prot->name = strdup("charbychar"); + prot->init = AsconStdInit; + prot->handler = CharByCharHandler; + AsconInsertProtocol(prot); +}