From: ian Date: Mon, 30 May 2005 16:47:22 +0000 (+0000) Subject: diagnoses pic output X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=615303e94fe9e80090f4930158c8f543b052d163;p=trains.git diagnoses pic output --- diff --git a/hostside/Makefile b/hostside/Makefile index f9ea034..45f17d7 100644 --- a/hostside/Makefile +++ b/hostside/Makefile @@ -11,7 +11,7 @@ hostside-old: serialio.o nmra.o main.o encode.o $(LINK) hostside: hostside.o serialio.o client.o obc.o commands.o \ - nmra.o encode.o retransmit.o -loop + nmra.o encode.o retransmit.o output.o -loop $(LINK) layoutinfo.h: ../layout/ours.layout-data.c Makefile diff --git a/hostside/README b/hostside/README index 5fc572c..dc4c147 100644 --- a/hostside/README +++ b/hostside/README @@ -33,19 +33,27 @@ To test: Protocol over new hostside stdin: + Example (always the same msg): + P> nmra [*] [...]] nmra speed28 3 13 1 + P> nmra [*] [=] nmra =0348 + P> nmra [*] [:] nmra :03484b + P> nmra [*] [_] nmra _7f7f00644197 + in each case * indicates that the message should be put in + the retransmission cycle, and cancels any previous message with the + same *. may be empty. + P> nmra * + cancels the relevant retransmission. - P> nmra-x [...] - P> nmra-1 [...] - P> xmit-x ... - P> xmit-1 ... - *-1 means transmit it once - *-x means put it in the transmission cycle; to cancel, - ask for nmra-x idle + Example (always the same msg): + P> pic = pic =a003 + P> pic [ and + nmra _ + do exactly the same. - P> pic [...] - P> raw ... - eg pic point 3 == raw a003 - for commands with no `...' in README.protocol only P> polarity .... where, eg, with 14 segments, [ 1] [111 1111] reversible @@ -62,6 +70,9 @@ Protocol over new hostside stdin: 0x02 0x3c hex values 023c hex data string + Up< pic-out + Up< pic-in + U< count eg count polarity 14 U< pic detect 1|0 diff --git a/hostside/client.c b/hostside/client.c index f0ff758..81c0b7f 100644 --- a/hostside/client.c +++ b/hostside/client.c @@ -5,6 +5,9 @@ #include #include "hostside.h" +#include "../layout/dlist.h" + +struct ClientList clients; void vbadcmd(ParseState *ps, const char *fmt, va_list al) { oprintf(&ps->cl->ch,"error "); @@ -128,12 +131,14 @@ static void *client_exception(oop_source *evts, int fd, return OOP_CONTINUE; } -static void new_client(int fd, OutBufferError error, char *desc) { +static void new_client(int fd, OutBufferError error, + char *desc, const char *default_selectors) { Client *cl; int r; cl= mmalloc(sizeof(*cl)); + cl->selectors= mstrdup(default_selectors); cl->ch.desc= desc; cl->ch.fd= fd; cl->ch.error= error; @@ -147,6 +152,8 @@ static void new_client(int fd, OutBufferError error, char *desc) { client_ifok, cl, client_iferr, cl); if (r) diee("oop_rd_read"); + + LIST_LINK_TAIL(clients, cl); } static void stdin_error(OutBufferChain *ch, const char *e1, const char *e2) { @@ -157,5 +164,5 @@ static void stdin_error(OutBufferChain *ch, const char *e1, const char *e2) { } void stdin_client(void) { - new_client(0, stdin_error, (char*)"stdin"); + new_client(0, stdin_error, (char*)"stdin", "p"); } diff --git a/hostside/commands.c b/hostside/commands.c index 13fea12..51d4f49 100644 --- a/hostside/commands.c +++ b/hostside/commands.c @@ -150,16 +150,10 @@ static void cmd_noop(ParseState *ps, const CmdInfo *ci) { } const CmdInfo toplevel_cmds[]= { - { "nmra", cmd_nmra, }, - /* eg nmra [*[slot]] speed28 3 13 1 */ - /* eg nmra [*[slot]] =0348 */ - /* eg nmra [*[slot]] :03484b */ - /* eg nmra [*[slot]] _7f7f00644197 */ - /* eg nmra [*[slot]] */ #if 0 - { "pic-raw" , cmd_pic_raw, 1, }, - { "pic", cmd_pic }, /* eg pic point 3 */ + { "pic", cmd_pic }, /* eg pic point 3 */ #endif - { "noop", cmd_noop }, + { "nmra", cmd_nmra, }, + { "noop", cmd_noop }, { 0 } }; diff --git a/hostside/common.h b/hostside/common.h index 66dd6f3..5d3a476 100644 --- a/hostside/common.h +++ b/hostside/common.h @@ -28,10 +28,12 @@ void diee(const char *fmt, ...) __attribute__((noreturn,format(printf,1,2))); void diem(void) __attribute__((noreturn)); void serial_open(const char *device); -void serial_transmit(const Byte *command, int length); +void serial_transmit_now(const Byte *command, int length); void *mmalloc(size_t sz); - +char *mstrdupl(const char *s, int l); +char *mstrdup(const char *s); + extern int serial_fd, serial_fudge_delay; /*---------- nmra parsing, nmra.c et al ----------*/ diff --git a/hostside/hostside.h b/hostside/hostside.h index 3066ade..ff495fe 100644 --- a/hostside/hostside.h +++ b/hostside/hostside.h @@ -32,20 +32,41 @@ struct OutBufferChain { }; void obc_init(OutBufferChain *ch); + void ovprintf(OutBufferChain *ch, const char *fmt, va_list al) __attribute__((format(printf,2,0))); void oprintf(OutBufferChain *ch, const char *msg, ...) __attribute__((format(printf,2,3))); void owrite(OutBufferChain *ch, const char *data, int l); +/*---------- from output.c ----------*/ + +typedef char Selector; + +void oovprintf(Selector sel, const char *fmt, va_list al) + __attribute__((format(printf,2,0))); +void ooprintf(Selector sel, const char *fmt, ...) + __attribute__((format(printf,2,3))); +void oowrite(Selector sel, const char *data, int l); + +void serial_transmit(const Byte *command, int length); + +void output_hex(Selector sel, const char *work, + const Byte *command, int length); + /*---------- from hostside.c ----------*/ extern oop_source *events; /*---------- from client.c ----------*/ +struct ClientList { Client *head, *tail; }; +extern struct ClientList clients; + struct Client { OutBufferChain ch; + Client *back, *next; + char *selectors; oop_read *rd; }; diff --git a/hostside/main.c b/hostside/main.c index 320cb58..ce2b50e 100644 --- a/hostside/main.c +++ b/hostside/main.c @@ -86,7 +86,7 @@ static void dump(const char *what, const Byte *data, int length) { static void xmit_command(void) { dump("xmit_command", buf.d, buf.l); - serial_transmit(buf.d, buf.l); + serial_transmit_now(buf.d, buf.l); } static void xmit_nmra_raw(void) { @@ -95,7 +95,7 @@ static void xmit_nmra_raw(void) { dump("xmit_nmra_raw", buf.d, buf.l); nmra_encodeforpic(&buf, encoded, &lencoded); - serial_transmit(encoded, lencoded); + serial_transmit_now(encoded, lencoded); } static void xmit_nmra_bytes(void) { diff --git a/hostside/output.c b/hostside/output.c new file mode 100644 index 0000000..16ab81d --- /dev/null +++ b/hostside/output.c @@ -0,0 +1,46 @@ +/* + * transmissions to clients + */ + +#include +#include + +#include "hostside.h" + +#define FOR_OOS(s) do{ \ + Client *cl, *next_cl; \ + for (cl= clients.head; \ + cl; \ + cl= next_cl) { \ + OutBufferChain *ch= &cl->ch; \ + next_cl= cl->next; \ + if (!strchr(cl->selectors, sel)) continue; \ + s; \ + } \ + }while(0) + +void oovprintf(Selector sel, const char *fmt, va_list al) { + FOR_OOS( ovprintf(ch, fmt, al) ); +} + +void ooprintf(Selector sel, const char *fmt, ...) + { va_list al; va_start(al,fmt); oovprintf(sel,fmt,al); va_end(al); } + +void oowrite(Selector sel, const char *data, int l) { + FOR_OOS( owrite(ch, data, l) ); +} + +void output_hex(Selector sel, const char *word, + const Byte *command, int length) { + ooprintf(sel, "%s", word); + while (length) { + ooprintf(sel, " %02x", *command++); + length--; + } + ooprintf(sel, "\n"); +} + +void serial_transmit(const Byte *command, int length) { + output_hex('p', "trace-pic-out", command,length); + serial_transmit_now(command, length); +} diff --git a/hostside/serialio.c b/hostside/serialio.c index c481c23..8232ebd 100644 --- a/hostside/serialio.c +++ b/hostside/serialio.c @@ -40,6 +40,16 @@ void *mmalloc(size_t sz) { return p; } +char *mstrdupl(const char *s, int l) { + char *p; + p= mmalloc(l+1); + memcpy(p,s,l); + p[l]= 0; + return p; +} + +char *mstrdup(const char *s) { return mstrdupl(s,strlen(s)); } + void serial_open(const char *device) { assert(serial_fd==-1); @@ -47,7 +57,7 @@ void serial_open(const char *device) { if (serial_fd<0) diee(device); } -void serial_transmit(const Byte *command, int length) { +void serial_transmit_now(const Byte *command, int length) { int r; assert(length <= COMMAND_ENCODED_MAX);