diff --git a/site_ansto/hardsup/sct_oxfordprot.c b/site_ansto/hardsup/sct_oxfordprot.c index 7c5d4de4..c23b7cc4 100644 --- a/site_ansto/hardsup/sct_oxfordprot.c +++ b/site_ansto/hardsup/sct_oxfordprot.c @@ -18,6 +18,12 @@ #include #include +enum { + ProtocolOxford = 0, + ProtocolHamilton = 1, + ProtocolSyringe = 2 +}; + struct OxfordProtocol_t { unsigned int magic; Ascon* parent; @@ -25,7 +31,7 @@ struct OxfordProtocol_t { double last_char_time; double inter_line_time; double inter_char_time; - int do_echo; + int protocol_subtype; }; typedef struct OxfordProtocol_t OxfordProtocol; @@ -108,19 +114,32 @@ int OxfordReading(Ascon *a) { int ret; char chr, ch[2]; char* cp = NULL; + char term; + OxfordProtocol* private; + + private = (OxfordProtocol*) a->private; + switch (private->protocol_subtype) { + case ProtocolOxford: + case ProtocolHamilton: + term = '\r'; + break; + case ProtocolSyringe: + term = '\003'; + break; + } ret = AsconReadChar(a->fd, &chr); while (ret > 0) { a->start = DoubleTime(); - if (chr != '\r') { + /* Accept ASCII CR or ETX as terminator */ + if (chr != term) { DynStringConcatChar(a->rdBuffer, chr); } else { - OxfordProtocol* private; - private = (OxfordProtocol*) a->private; - if (private->do_echo) { - int ilen, olen; + int ilen, olen; + switch (private->protocol_subtype) { + case ProtocolHamilton: ilen = GetDynStringLength(a->rdBuffer); olen = GetDynStringLength(a->wrBuffer) - 1; /* omit CR */ if (olen == ilen) { @@ -133,6 +152,7 @@ int OxfordReading(Ascon *a) { continue; } } + break; } a->state = AsconReadDone; break; @@ -223,16 +243,8 @@ void OxfordKillPrivate(void *arg) { free(arg); } -void OxfordQKillPrivate(void *arg) { - OxfordQProtocol *private = (OxfordQProtocol *) arg; - assert(private->magic == 0xcafef00d); - assert(private->parent->private == private); - private->magic = 0; - free(arg); -} - -int OxfordInit(Ascon *a, SConnection *con, - int argc, char *argv[]) { +static int GenericInit(Ascon *a, SConnection *con, + int argc, char *argv[], int subtype) { OxfordProtocol *private; int ret; ret = AsconStdInit(a, con, argc, argv); @@ -242,40 +254,21 @@ int OxfordInit(Ascon *a, SConnection *con, private->parent = a; private->inter_line_time = 0.100; private->inter_char_time = 0.010; - private->do_echo = 0; + private->protocol_subtype = subtype; a->killPrivate = OxfordKillPrivate; return ret; } -int HamiltonInit(Ascon *a, SConnection *con, - int argc, char *argv[]) { - OxfordProtocol *private; - int ret; - ret = AsconStdInit(a, con, argc, argv); - private = calloc(sizeof(OxfordProtocol), 1); - a->private = (void *) private; - private->magic = 0xcafef00d; - private->parent = a; - private->inter_line_time = 0.100; - private->inter_char_time = 0.010; - private->do_echo = 1; - a->killPrivate = OxfordKillPrivate; - return ret; +static int OxfordInit(Ascon *a, SConnection *con, int argc, char *argv[]) { + return GenericInit(a, con, argc, argv, ProtocolOxford); } -int OxfordQInit(Ascon *a, SConnection *con, - int argc, char *argv[]) { - OxfordQProtocol *private; - int ret; - ret = AsconStdInit(a, con, argc, argv); - private = calloc(sizeof(OxfordQProtocol), 1); - a->private = (void *) private; - private->magic = 0xcafef00d; - private->parent = a; - private->inter_line_time = 0.100; - private->inter_char_time = 0.010; - a->killPrivate = OxfordQKillPrivate; - return ret; +static int HamiltonInit(Ascon *a, SConnection *con, int argc, char *argv[]) { + return GenericInit(a, con, argc, argv, ProtocolHamilton); +} + +static int SyringeInit(Ascon *a, SConnection *con, int argc, char *argv[]) { + return GenericInit(a, con, argc, argv, ProtocolSyringe); } void AddOxfordProtocoll(){ @@ -294,8 +287,8 @@ void AddOxfordProtocoll(){ AsconInsertProtocol(prot); prot = calloc(sizeof(AsconProtocol), 1); - prot->name = strdup("oxfordq"); - prot->init = OxfordQInit; + prot->name = strdup("syringe"); + prot->init = SyringeInit; prot->handler = OxfordQProtHandler; AsconInsertProtocol(prot); }