chiark / gitweb /
pic commands compile, untested
authorian <ian>
Sat, 4 Jun 2005 00:16:35 +0000 (00:16 +0000)
committerian <ian>
Sat, 4 Jun 2005 00:16:35 +0000 (00:16 +0000)
hostside/Makefile
hostside/client.c
hostside/commands.c
hostside/common.h
hostside/hostside.h
hostside/parse-proto-spec
hostside/skelproto-pic.c
hostside/skelproto-pic.h

index 90470e3a677972fcfd3678c8165394637f909649..d988188613b7338055ed939da6d4b3105c683166 100644 (file)
@@ -11,12 +11,15 @@ 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 output.o -loop
+                nmra.o encode.o retransmit.o output.o auproto-pic.o \
+                -loop
                $(LINK)
 
 proto-expanded:        ../cebpic/README.protocol
                expand <$< $o
 
+commands.o auproto-pic.o: auproto-pic.h
+
 auproto-%:     parse-proto-spec proto-expanded skelproto-%
                ./$+ $o
 
index a3f409a23f67f1f89eb98246519ee5dc84cc280b..66d162f1840437e218b9e1580b8da41e2247adae 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdarg.h>
 #include <string.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #include "hostside.h"
 #include "../layout/dlist.h"
@@ -42,6 +43,32 @@ int ps_needword(ParseState *ps) {
   return 1;
 }
 
+int ps_neednumber(ParseState *ps, long *r, long mi, long mx, const char *wh) {
+  char *ep;
+  long v;
+  
+  if (!ps_needword(ps)) return 0;
+  errno= 0; v= strtol(ps->thisword,&ep,0);
+  if (errno || ep != ps->thisword + ps->lthisword) {
+    badcmd(ps,"invalid number for %s",wh);
+    return 0;
+  }
+  if (v < mi || v > mx) {
+    badcmd(ps,"%s %ld out of range %ld..%ld",wh,v,mi,mx);
+    return 0;
+  }
+  *r= v;
+  return 1;
+}
+
+int ps_neednoargs(ParseState *ps) {
+  if (ps->remain) {
+    badcmd(ps,"too many arguments");
+    return 0;
+  }
+  return 1;
+}
 int ps_needhextoend(ParseState *ps, Byte *d, int *remain_io) {
   Byte *d_end;
   char buf[3], *ep;
index 904e53bd323aede7d4d74c56f5c0d559708ebd09..02d5b28a783b9e5818a662aec8580b101dd1666e 100644 (file)
@@ -7,6 +7,7 @@
 #include <string.h>
 
 #include "hostside.h"
+#include "auproto-pic.h"
 
 #define NMRA_MAX_NARGS 10
 
@@ -158,8 +159,22 @@ struct PicCmdInfo {
 };
 
 static void cmd_pic(ParseState *ps, const CmdInfo *ci) {
-  if (!ps_needword(ps)) return;
+  const PicInsnInfo *pii;
+  PicInsn pi;
+  long arg;
   
+  pii= some_needword_lookup(ps,pic_command_infos);
+  if (pii->argbits) {
+    if (!ps_neednumber(ps, &arg, 0, (1L << pii->argbits) - 1,
+                      "pic object number"))
+      return;
+  } else {
+    arg= 0;
+  }
+  if (!ps_neednoargs(ps))
+    return;
+  enco_pic_anyinsn(&pi, pii, arg);
+  serial_transmit(pi.d, pi.l);
 }
 
 const CmdInfo toplevel_cmds[]= {
index 3b2305700b0edcc3f98ccb15d775082c36ade564..1a008c968d167367a1427e73f97070a5a77df1e4 100644 (file)
@@ -38,7 +38,7 @@ 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 dc6efa393b01ea08f0212d62a5951a5c71c60d35..b387eda16db71a4afd9c098a51c77a2501f34365 100644 (file)
@@ -99,6 +99,8 @@ int ps_word(ParseState *ps);
 int ps_needword(ParseState *ps);
 int ps_needhextoend(ParseState *ps, Byte *dbuf, int *len_io);
 void ps_callword(ParseState *ps, const CmdInfo *infs, const char *what);
+int ps_neednumber(ParseState *ps, long *r, long min, long max, const char *wh);
+int ps_neednoargs(ParseState *ps);
 
 void vbadcmd(ParseState *ps, const char *fmt, va_list al)
      __attribute__((format(printf,2,0)));
index b4847324b05ee7619d2775e6e9b481b93f6cf22e..0ed738128b4c113d798a675540d55c9fce8dfe05 100755 (executable)
@@ -10,6 +10,16 @@ sub begin ($) {
 
 ($spec,$templ)=@ARGV;
 
+$linexpect= -1;
+
+sub pln ($) {
+    if ($dolinno && $linexpect != $templlinno) {
+       print "# $templlinno \"$templ\"\n" or die $!;
+    }
+    print $_[0] or die $!;
+    $linexpect= $templlinno+1;
+}
+
 sub expand_and_write () {
     $templl= $templlin;
     $templl =~ s/\@([a-z]+)\=(\w*)\@/
@@ -22,7 +32,7 @@ sub expand_and_write () {
        die $1 unless exists $v{$1};
         $v{$1}
     /ge;
-    print $templl or die $!;
+    pln($templl);
 }
 
 sub process_line () {
@@ -86,8 +96,12 @@ sub process_line () {
 open T, "$templ" or die "$templ $!";
 for (;;) {
     $templlin= <T>;  last unless length $templlin;
+    $templlinno= $.;
+    if ($templlin =~ s/\@L\@//) {
+       $dolinno= 1;
+    }
     if ($templlin !~ m/\@\w+\@/) {
-       print $templlin or die $!;
+       pln($templlin);
     } elsif ($templlin =~ s/\@1\@//) {
        undef %v;
        $v{skeleton}= 'autogenerated - do not edit';
index 9619a3a674fd597db4fd732118a5da20bb45f005..e828302587cdcb57e14fba46a108ee95cc533ebf 100644 (file)
@@ -1,3 +1,4 @@
+/* @skeleton@ @1@ @L@ */
 /*
  * arranges for the declarations of
  *  enco_pic_WHATEVER
@@ -5,15 +6,29 @@
  * and the tables
  */
 
-#ifndef PROTOCOL_H
-#define PROTOCOL_H
+#include "hostside.h"
+#include "auproto-pic.h"
+
+extern void enco_pic_anyinsn(PicInsn *out, const PicInsnInfo *pii,
+                            int objnum) {
+  unsigned long as= objnum;
+  int i;
+
+  out->l= 1 + pii->argbits/7;
+  for (i= out->l - 1;
+       i > 0;
+       i--, as >>= 7)
+    out->d[i]= (as & 0x07fUL) | 0x080UL;
+  out->d[out->l - 1] &= ~0x080UL;
+  out->d[0] |= pii->opcode;
+}
 
 const PicInsnInfo pic_command_infos[]= {
   { "@cnameyn@", @opcodeyn@, @arglen@ }, @h2p@
-  0
+  { 0 }
 };
 
 const PicInsnInfo pic_reply_infos[]= {
   { "@cnameyn@", @opcodeyn@, @arglen@ }, @p2h@
-  0
+  { 0 }
 };
index dc1ca89bbed307fcbd496dfe0c59d9c0530151df..d5b2d46784224525c505b2cdff14707c02366e4a 100644 (file)
@@ -1,4 +1,4 @@
-/* @skeleton@ @1@ */
+/* @skeleton@ @1@ @L@ */
 /*
  * arranges for the declarations of
  *  enco_pic_WHATEVER
@@ -9,6 +9,8 @@
 #ifndef AUPROTO_PIC_H
 #define AUPROTO_PIC_H
 
+typedef struct PicInsnInfo PicInsnInfo;
+
 void enco_pic_@cname@(PicInsn *out);            @h2p@ @arglentf=0@
 void enco_pic_@cname@(PicInsn *out, int objum); @h2p@ @arglentf=1@
 
@@ -19,7 +21,8 @@ extern void enco_pic_polarity_begin(PicInsn *out);
 extern void enco_pic_polarity_setbit(PicInsn *out, int objnum);
 extern void on_pic_debug(int ch);
 
-typedef struct PicInsnInfo PicInsnInfo;
+extern void enco_pic_anyinsn(PicInsn *out, const PicInsnInfo *pii, int objnum);
+
 struct PicInsnInfo {
   const char *name;
   Byte opcode;