From: ian Date: Sat, 8 Jan 2005 23:41:07 +0000 (+0000) Subject: support serial_fudge_delay X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=1076011989b4204d5271e46f142c13c3d6e3412d;p=trains.git support serial_fudge_delay --- diff --git a/hostside/hostside.h b/hostside/hostside.h index 8e5dfe6..db315d9 100644 --- a/hostside/hostside.h +++ b/hostside/hostside.h @@ -15,4 +15,6 @@ void xmit_command(const Byte *command, int length); void sysfatal(const char *m); void serial_open(const char *device); +extern int serial_fudge_delay; + #endif /*HOSTSIDE_H*/ diff --git a/hostside/main.c b/hostside/main.c index dab5244..d0e184a 100644 --- a/hostside/main.c +++ b/hostside/main.c @@ -19,7 +19,7 @@ int main(int argc, const char **argv) { char hbuf[3], *ep; Byte buf[NMRA_PACKET_MAX + COMMAND_ENCODED_MAX]; - assert(argc==4); + assert(argc==4 || argc==5); assert(argv[3]); serial_open(argv[1]); @@ -36,6 +36,9 @@ int main(int argc, const char **argv) { assert(ep==&hbuf[2]); } + if (argc==5) + serial_fudge_delay= atoi(argv[4]); + switch (argv[3][0]) { case 'c': xmit_command(buf,l); break; case 'r': xmit_nmra_raw(buf,l); break; diff --git a/hostside/serialio.c b/hostside/serialio.c index b4bd7fb..3a5a597 100644 --- a/hostside/serialio.c +++ b/hostside/serialio.c @@ -11,6 +11,8 @@ #include "hostside.h" +int serial_fudge_delay= 0; + static int serial_fd= -1; void sysfatal(const char *m) { perror(m); exit(12); } @@ -27,7 +29,8 @@ void xmit_command(const Byte *command, int length) { assert(length <= COMMAND_ENCODED_MAX); while (length > 0) { - r= write(serial_fd, command, length); + r= write(serial_fd, command, + serial_fudge_delay ? 1 : length); if (r==-1) { if (errno == EINTR) continue; sysfatal("command_transmit"); @@ -35,5 +38,7 @@ void xmit_command(const Byte *command, int length) { assert(r<=length); command += r; length -= r; + if (r>0 && serial_fudge_delay) + usleep(serial_fudge_delay); } }