chiark / gitweb /
diagnoses pic output
authorian <ian>
Mon, 30 May 2005 16:47:22 +0000 (16:47 +0000)
committerian <ian>
Mon, 30 May 2005 16:47:22 +0000 (16:47 +0000)
hostside/Makefile
hostside/README
hostside/client.c
hostside/commands.c
hostside/common.h
hostside/hostside.h
hostside/main.c
hostside/output.c [new file with mode: 0644]
hostside/serialio.c

index f9ea034188f127c3a56a4f1f0ae11b28bb3be57a..45f17d73fdb60706e349bdcc8177de1e1e51a333 100644 (file)
@@ -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
index 5fc572cc885b8ee68c7ad666f1abf89fc945d487..dc4c1470530f4127bba6511e7abe64b33f87abfe 100644 (file)
@@ -33,19 +33,27 @@ To test:
 
 
 Protocol over new hostside stdin:
+                                            Example (always the same msg):
+ P> nmra [*<slot>] [<nmra-command [<nmra-args>...]]    nmra speed28 3 13 1
+ P> nmra [*<slot>] [=<nmra-bytes>]                     nmra =0348
+ P> nmra [*<slot>] [:<nmra-bytes-with-csum>]           nmra :03484b
+ P> nmra [*<slot>] [_<pic-literal-bytes>]              nmra _7f7f00644197
+   in each case *<slot> indicates that the message should be put in
+   the retransmission cycle, and cancels any previous message with the
+   same *<slot>.  <slot> may be empty.
+ P> nmra *<slot>
+   cancels the relevant retransmission.
 
- P> nmra-x <nmra-command> [<nmra-args>...]
- P> nmra-1 <nmra-command> [<nmra-args>...]
- P> xmit-x <nmra-data-hex>...
- P> xmit-1 <nmra-data-hex>...
-       *-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-bytes>                                   pic =a003
+ P> pic <pic-command> [<pic-args...]                   pic point 3
+       the latter for commands with no `...' in README.protocol only
+
+ Keen readers will observe that
+    pic =<pic-bytes>    and
+    nmra _<pic-bytes>
+ do exactly the same.
 
- P> pic <pic-command> [<pic-args>...]
- P> raw <pic-command-data-hex>...
-       eg  pic point 3  ==  raw a003
-       for commands with no `...' in README.protocol only
  P> polarity <bit-string-in-hex>....
        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 <hex-bytes...>
+ Up< pic-in <hex-bytes...>
+
  U< count <type> <number-in-decimal>
       eg  count polarity 14
  U< pic detect 1|0 <S>
index f0ff75837afa7840359f58227a36b809f3d4efa3..81c0b7fb5588703e82d8e6c2ad2cddf8676b48b2 100644 (file)
@@ -5,6 +5,9 @@
 #include <stdlib.h>
 
 #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");
 }
index 13fea12cb6937c787fff59166d37080be86c6132..51d4f49958a0de8fc57daef98fa8fdf6adcdd33b 100644 (file)
@@ -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 }
 };
index 66dd6f35fe53355d85b1594158757c92625eb1e2..5d3a476a294b2f38a5b699579b29f0b1a7d4100f 100644 (file)
@@ -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 ----------*/
index 3066ade77a9b5051174f2b970447947a8c5cf265..ff495fe3a7cfae350955ad21aa3143f0d7f3b477 100644 (file)
@@ -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;
 };
 
index 320cb5841089425fb7df4fa06d55e13734538394..ce2b50e9d5110ec6c1bd14d4926a00603ccc316b 100644 (file)
@@ -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 (file)
index 0000000..16ab81d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * transmissions to clients
+ */
+
+#include <string.h>
+#include <stdarg.h>
+
+#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);
+}
index c481c23343912964cb6470a001386a0882b492e3..8232ebde401d5f0ac1c3c9a5797f91c5d5724b89 100644 (file)
@@ -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);