incorporate syringe pump protocol
r3226 | dcl | 2011-06-24 13:05:51 +1000 (Fri, 24 Jun 2011) | 1 line
This commit is contained in:
@@ -18,6 +18,12 @@
|
|||||||
#include <ascon.i>
|
#include <ascon.i>
|
||||||
#include <dynstring.h>
|
#include <dynstring.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ProtocolOxford = 0,
|
||||||
|
ProtocolHamilton = 1,
|
||||||
|
ProtocolSyringe = 2
|
||||||
|
};
|
||||||
|
|
||||||
struct OxfordProtocol_t {
|
struct OxfordProtocol_t {
|
||||||
unsigned int magic;
|
unsigned int magic;
|
||||||
Ascon* parent;
|
Ascon* parent;
|
||||||
@@ -25,7 +31,7 @@ struct OxfordProtocol_t {
|
|||||||
double last_char_time;
|
double last_char_time;
|
||||||
double inter_line_time;
|
double inter_line_time;
|
||||||
double inter_char_time;
|
double inter_char_time;
|
||||||
int do_echo;
|
int protocol_subtype;
|
||||||
};
|
};
|
||||||
typedef struct OxfordProtocol_t OxfordProtocol;
|
typedef struct OxfordProtocol_t OxfordProtocol;
|
||||||
|
|
||||||
@@ -108,19 +114,32 @@ int OxfordReading(Ascon *a) {
|
|||||||
int ret;
|
int ret;
|
||||||
char chr, ch[2];
|
char chr, ch[2];
|
||||||
char* cp = NULL;
|
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);
|
ret = AsconReadChar(a->fd, &chr);
|
||||||
while (ret > 0) {
|
while (ret > 0) {
|
||||||
a->start = DoubleTime();
|
a->start = DoubleTime();
|
||||||
|
|
||||||
if (chr != '\r') {
|
/* Accept ASCII CR or ETX as terminator */
|
||||||
|
if (chr != term) {
|
||||||
DynStringConcatChar(a->rdBuffer, chr);
|
DynStringConcatChar(a->rdBuffer, chr);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
ilen = GetDynStringLength(a->rdBuffer);
|
||||||
olen = GetDynStringLength(a->wrBuffer) - 1; /* omit CR */
|
olen = GetDynStringLength(a->wrBuffer) - 1; /* omit CR */
|
||||||
if (olen == ilen) {
|
if (olen == ilen) {
|
||||||
@@ -133,6 +152,7 @@ int OxfordReading(Ascon *a) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
a->state = AsconReadDone;
|
a->state = AsconReadDone;
|
||||||
break;
|
break;
|
||||||
@@ -223,16 +243,8 @@ void OxfordKillPrivate(void *arg) {
|
|||||||
free(arg);
|
free(arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OxfordQKillPrivate(void *arg) {
|
static int GenericInit(Ascon *a, SConnection *con,
|
||||||
OxfordQProtocol *private = (OxfordQProtocol *) arg;
|
int argc, char *argv[], int subtype) {
|
||||||
assert(private->magic == 0xcafef00d);
|
|
||||||
assert(private->parent->private == private);
|
|
||||||
private->magic = 0;
|
|
||||||
free(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int OxfordInit(Ascon *a, SConnection *con,
|
|
||||||
int argc, char *argv[]) {
|
|
||||||
OxfordProtocol *private;
|
OxfordProtocol *private;
|
||||||
int ret;
|
int ret;
|
||||||
ret = AsconStdInit(a, con, argc, argv);
|
ret = AsconStdInit(a, con, argc, argv);
|
||||||
@@ -242,40 +254,21 @@ int OxfordInit(Ascon *a, SConnection *con,
|
|||||||
private->parent = a;
|
private->parent = a;
|
||||||
private->inter_line_time = 0.100;
|
private->inter_line_time = 0.100;
|
||||||
private->inter_char_time = 0.010;
|
private->inter_char_time = 0.010;
|
||||||
private->do_echo = 0;
|
private->protocol_subtype = subtype;
|
||||||
a->killPrivate = OxfordKillPrivate;
|
a->killPrivate = OxfordKillPrivate;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HamiltonInit(Ascon *a, SConnection *con,
|
static int OxfordInit(Ascon *a, SConnection *con, int argc, char *argv[]) {
|
||||||
int argc, char *argv[]) {
|
return GenericInit(a, con, argc, argv, ProtocolOxford);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int OxfordQInit(Ascon *a, SConnection *con,
|
static int HamiltonInit(Ascon *a, SConnection *con, int argc, char *argv[]) {
|
||||||
int argc, char *argv[]) {
|
return GenericInit(a, con, argc, argv, ProtocolHamilton);
|
||||||
OxfordQProtocol *private;
|
}
|
||||||
int ret;
|
|
||||||
ret = AsconStdInit(a, con, argc, argv);
|
static int SyringeInit(Ascon *a, SConnection *con, int argc, char *argv[]) {
|
||||||
private = calloc(sizeof(OxfordQProtocol), 1);
|
return GenericInit(a, con, argc, argv, ProtocolSyringe);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddOxfordProtocoll(){
|
void AddOxfordProtocoll(){
|
||||||
@@ -294,8 +287,8 @@ void AddOxfordProtocoll(){
|
|||||||
AsconInsertProtocol(prot);
|
AsconInsertProtocol(prot);
|
||||||
|
|
||||||
prot = calloc(sizeof(AsconProtocol), 1);
|
prot = calloc(sizeof(AsconProtocol), 1);
|
||||||
prot->name = strdup("oxfordq");
|
prot->name = strdup("syringe");
|
||||||
prot->init = OxfordQInit;
|
prot->init = SyringeInit;
|
||||||
prot->handler = OxfordQProtHandler;
|
prot->handler = OxfordQProtHandler;
|
||||||
AsconInsertProtocol(prot);
|
AsconInsertProtocol(prot);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user