chiark / gitweb /
working on making initial startup version of realtime compile
authorian <ian>
Thu, 4 May 2006 00:18:01 +0000 (00:18 +0000)
committerian <ian>
Thu, 4 May 2006 00:18:01 +0000 (00:18 +0000)
17 files changed:
cebpic/README.protocol
hostside/Makefile
hostside/client.c
hostside/commands.c
hostside/common.h
hostside/daemons.h
hostside/gui-plan.c
hostside/hostside.h
hostside/main.c
hostside/multiplex.h
hostside/obc.c
hostside/parseutils.c
hostside/realtime.c
hostside/realtime.h
hostside/skelproto-pic.c
hostside/startup.c
hostside/utils.c

index 3ceace68dd67cd02079f791542fae72d72a8bf28..7e0861ac596e6a3bb454ff04a473d09527ffca27 100644 (file)
@@ -58,7 +58,7 @@ From PIC to host:
  < 1 0001 XXX  0 XXXXXXX  (88+)        PONG      Pong `X' (reply to Ping `X')
  < 0 000 1001             (HT)  HELLO    I am booted
  < 0 000 1011             (VT)  AAARGH   Followed by debug chars (only)
- < 0 000 1101             (CR)  WATCHDOG  Timeout happened
+ < 0 000 1101             (CR)  WTIMEOUT  Watchdog timeout happened
  < 0 000 0111             (BEL) FAULT    Fault exists
  < 0 000 0110             (ACK) FIXED    Fault now fixed
  < 0 0100 PPP             (20+)        POINTED   Point change done using capacitor P
index 9e31d709f68d5c5713d240e4610bf17b9975504d..add235520b34f16936d8fa4d12d98e67b4df5a40 100644 (file)
@@ -1,12 +1,11 @@
 #
 
-AUTOINCS=      selectors.h
+AUTOINCS=      auproto-pic.h layoutinfo.h selectors.h
+TARGETS=       hostside-old gui-plan-bot realtime
 
 include ../common.make
 include ../cprogs.make
 
-TARGETS=       hostside hostside-old gui-plan-bot realtime
-
 default:       all
 recurse:       all
 for-pic:
@@ -15,10 +14,9 @@ all:         $(TARGETS)
 hostside-old:  serialio.o nmra.o main.o encode.o utils.o
                $(LINK)
 
-hostside:      hostside.o serialio.o client.o obc.o commands.o utils.o \
-                nmra.o encode.o retransmit.o output.o auproto-pic.o \
-                parseutils.o \
-                -loop
+realtime:      realtime.o startup.o cdumgr.o           \
+                cmdinput.o                             \
+                utils.o serialio.o auproto-pic.o
                $(LINK)
 
 proto-expanded:        ../cebpic/README.protocol
@@ -29,7 +27,8 @@ gui-plan-bot: gui-plan-%: gui-plan.o utils.o parseutils.o \
                 __oop-read-copy.o -loop
                $(LINK) -L/usr/X11R6/lib -lXpm -lX11
 
-auproto-%:     parse-proto-spec proto-expanded skelproto-%
+auproto-pic.c auproto-pic.h: auproto-%: \
+                       parse-proto-spec proto-expanded skelproto-%
                ./$+ $o
 
 layoutinfo.h:  ../layout/ours.layout-data.c Makefile
@@ -38,15 +37,13 @@ layoutinfo.h:       ../layout/ours.layout-data.c Makefile
 selectors.h:   selectors.h.gen
                ./$< $o
 
-%.o:           auproto-pic.h
-safety.o trackloc.o: layoutinfo.h
-
-realtime:      realtime.o startup.o cdumgr.o
-               cmdinput.o
-               utils.o serialio.o auproto-pic.o
+safety:                safety.o utils.o trackloc.o ../layout/ours.layout-data.o
                $(LINK)
 
-safety:                safety.o utils.o trackloc.o ../layout/ours.layout-data.o
+hostside:      hostside.o serialio.o client.o obc.o commands.o utils.o \
+                nmra.o encode.o retransmit.o output.o auproto-pic.o \
+                parseutils.o \
+                -loop
                $(LINK)
 
 clean:
index 05197959ece4b391c2c959316cc6f71bb264418a..8b3a24ade01a448fa2006ad281a67c92c4b90331 100644 (file)
@@ -5,7 +5,7 @@
 #include <stdlib.h>
 #include <errno.h>
 
-#include "hostside.h"
+#include "multiplex.h"
 #include "../layout/dlist.h"
 
 struct ClientList clients;
index 4683877b2aceb3c3a90a5f68cb27b5364152049f..26ee20dd6ec51c69cac27bf89878f738a306ce2c 100644 (file)
@@ -6,7 +6,7 @@
 #include <assert.h>
 #include <string.h>
 
-#include "hostside.h"
+#include "realtime.h"
 #include "auproto-pic.h"
 
 #define NMRA_MAX_NARGS 10
index 1d11bb54b865dfe0ef5a0b21022c0491108fc228..7354b09be8fa8b9e25943c8e227e9da96972f506 100644 (file)
 #include <sys/types.h>
 #include <sys/time.h>
 
+typedef struct ParseState ParseState;
+typedef struct CmdInfo CmdInfo;
+typedef struct Client Client;
+
+extern const char *progname;
+
 /*---------- types ----------*/
 
 typedef unsigned char Byte;
@@ -29,6 +35,55 @@ typedef struct PicInsn {
   int l;
 } PicInsn;
 
+/*---------- from parseutils.c ----------*/
+
+struct ParseState {
+  Client *cl; /* used only by multiplexer */
+  const char *remain;
+  const char *thisword;
+  int lthisword;
+};
+
+void vbadcmd(ParseState *ps, const char *fmt, va_list al)
+  __attribute__((format(printf,2,0)));
+void badcmd(ParseState *ps, const char *fmt, ...)
+  __attribute__((format(printf,2,3)));
+
+int lstrstrcmp(const char *a, int la, const char *b);
+int thiswordstrcmp(ParseState *ps, const char *b);
+
+int ps_word(ParseState *ps);
+int ps_needword(ParseState *ps);
+int ps_needhextoend(ParseState *ps, Byte *dbuf, int *len_io);
+int ps_neednumber(ParseState *ps, long *r, long min, long max, const char *wh);
+int ps_neednoargs(ParseState *ps);
+
+/*---------- macro for table lookups, with help from parseutils.c ----------*/
+
+#define some_lookup(ps, infos)                 \
+  ((const typeof(infos[0])*)                   \
+   any_lookup((ps),(infos),sizeof((infos)[0])))
+
+#define some_needword_lookup(ps, infos, what)                  \
+  ((const typeof(infos[0])*)                                   \
+   any_needword_lookup((ps),(infos),sizeof((infos)[0]),(what)))
+
+const void *any_lookup(ParseState *ps, const void *infos, size_t infosz);
+const void *any_needword_lookup(ParseState *ps, const void *infos,
+                               size_t sz, const char *what);
+
+/*---------- from client.c ----------*/
+
+struct CmdInfo {
+  const char *name;
+  void (*fn)(ParseState *ps, const CmdInfo *ci);
+  int xarg;
+};
+
+void stdin_client(void);
+
+extern const CmdInfo toplevel_cmds[]; /* defined in commands.c*/
+
 /*---------- from utils.c ----------*/
 
 void vdie(const char *fmt, int ev, va_list al)
@@ -42,6 +97,8 @@ char *mstrdupl(const char *s, int l);
 char *mstrdup(const char *s);
 void mgettimeofday(struct timeval *tv);
 
+#define massert(x) ((x) ? (void)0 : diem())
+
 /*---------- from serialio.c ----------*/
 
 void serial_open(const char *device);
index 836680eda221f44e880ab9ee04218f79e04ad9b4..205b66a672b8b39858616745e10ea7a95037951c 100644 (file)
 #include <oop.h>
 #include <oop-read.h>
 
-#include <sys/types.h>
-#include <sys/time.h>
+#include "common.h"
+
+typedef struct CommandInput CommandInput;
 
 /*---------- from obc.c ----------*/
 
 typedef struct OutBuffer OutBuffer;
 typedef struct OutBufferChain OutBufferChain;
 typedef void OutBufferError(OutBufferChain*, const char *e1, const char *e2
-                           /* both e1 and e2 always non-0.  say `$e1: $e2');
+                           /* both e1 and e2 always non-0. say `$e1: $e2' */);
 
 struct OutBufferChain {
   /* set by user: */
@@ -48,13 +49,6 @@ struct CommandInput {
   oop_read *rd;
 };
 
-struct ParseState {
-  Client *cl; /* used only by multiplexer */
-  const char *remain;
-  const char *thisword;
-  int lthisword;
-};
-
 void cmdin_new(CommandInput *cmdi, int readfd);
   /* fill in cmdi->out's `set by user' fields before calling cmdin_new,
    * as cmdin_new will call obc_init and will use cmdi->out->fd. */
@@ -82,34 +76,4 @@ void toev_start(TimeoutEvent*);   /* IR -> R; reads duration */
   /* if duration is -1 then is same as toev_stop */
 void toev_stop(TimeoutEvent*);    /* IR -> I */
 
-/*---------- from parseutils.c ----------*/
-
-void vbadcmd(ParseState *ps, const char *fmt, va_list al)
-  __attribute__((format(printf,2,0)));
-void badcmd(ParseState *ps, const char *fmt, ...)
-  __attribute__((format(printf,2,3)));
-
-int lstrstrcmp(const char *a, int la, const char *b);
-int thiswordstrcmp(ParseState *ps, const char *b);
-
-int ps_word(ParseState *ps);
-int ps_needword(ParseState *ps);
-int ps_needhextoend(ParseState *ps, Byte *dbuf, int *len_io);
-int ps_neednumber(ParseState *ps, long *r, long min, long max, const char *wh);
-int ps_neednoargs(ParseState *ps);
-
-/*---------- macro for table lookups, with help from parseutils.c ----------*/
-
-#define some_lookup(ps, infos)                 \
-  ((const typeof(infos[0])*)                   \
-   any_lookup((ps),(infos),sizeof((infos)[0])))
-
-#define some_needword_lookup(ps, infos, what)                  \
-  ((const typeof(infos[0])*)                                   \
-   any_needword_lookup((ps),(infos),sizeof((infos)[0]),(what)))
-
-const void *any_lookup(ParseState *ps, const void *infos, size_t infosz);
-const void *any_needword_lookup(ParseState *ps, const void *infos,
-                               size_t sz, const char *what);
-
 #endif /*DAEMONS_H*/
index 73bdbeef5cbb79a7f0572adecc4f875499bdd694..1eb719630948bd55561221edc12a4fe2c512e351 100644 (file)
@@ -15,7 +15,7 @@
 #include <X11/Xlib.h>
 #include <X11/xpm.h>
 
-#include "hostside.h"
+#include "common.h"
 #include "../layout/plan-data-format.h"
 
 #include <oop.h>
@@ -44,6 +44,7 @@ struct SegmovfeatState {
 };
 
 oop_source *events;
+const char *progname= "gui-plan";
 
 static SegmovfeatState **state, *states_head;
 static Display *d;
index 8d1ed6d37698a7574793e20395d94e153ac5377b..b6fbdc6fc5d956e6878ff8be400ecb76dde9b2c8 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ * OBSOLETE FILE
  * declarations for hostside controller daemon
  */
 
@@ -7,9 +8,6 @@
 
 #include "common.h"
 
-typedef struct ParseState ParseState;
-typedef struct CmdInfo CmdInfo;
-
 /*---------- from protocol.c ----------*/
 
 typedef struct OrdinaryPicMessage OrdinaryPicMessage;
@@ -19,22 +17,6 @@ struct OrdinaryPicMessage {
   int operand_bits; /* 0: no operand.  >=7, insn is a 2-byte message */
 };
      
-/*---------- from hostside.c ----------*/
-
-extern oop_source *events;
-
-/*---------- from client.c ----------*/
-
-struct CmdInfo {
-  const char *name;
-  void (*fn)(ParseState *ps, const CmdInfo *ci);
-  int xarg;
-};
-
-void stdin_client(void);
-
-extern const CmdInfo toplevel_cmds[]; /* defined in commands.c*/
-
 /*---------- from retransmit.c ----------*/
 
 struct RetransmitNode {
@@ -45,3 +27,5 @@ struct RetransmitNode {
 
 void retransmit_queue(RetransmitNode *rn);
 void retransmit_cancel(RetransmitNode *rn);
+
+#endif
index 7f2cc6d14edc71e51f9140b95d678da53572a427..378c173292159ec4439c210d7dac61a6db92769d 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "common.h"
 
+const char *progname= "hostside-old";
 static FILE *dump_stream= 0;
 
 static int repeat_delay= -1, iterations= -1;
index 81d3b13c89218d7c89fa826062b07bf96bbb9687..0c66f2c3dc310834307463970e7469ca54cc637c 100644 (file)
@@ -8,8 +8,6 @@
 
 #include "daemons.h"
 
-typedef struct Client Client;
-
 /*---------- from output.c ----------*/
 
 typedef unsigned long Selector;
index ef294fcdf01bf1ab4c481df94cb249ca0ccb1371..63547a065d968d21b3c76c788f3d195f7c58fac7 100644 (file)
@@ -6,7 +6,7 @@
 #include <stdarg.h>
 #include <string.h>
 
-#include "hostside.h"
+#include "daemons.h"
 #include "../layout/dlist.h"
 
 struct OutBuffer {
@@ -15,6 +15,12 @@ struct OutBuffer {
   int l;
 };
 
+void vbadcmd(ParseState *ps, const char *fmt, va_list al) {
+  oprintf(&ps->ci->out,"error ");
+  ovprintf(&ps->ci->out,fmt,al);
+  owrite(&ps->ci->out,"\n",1);
+}
+
 static void *writeable(oop_source *evts, int fd,
                       oop_event evt, void *ch_v) {
   OutBufferChain *ch= ch_v;
index 89ab4ba6be8d06ec3d6b3191905961ee87f96270..7cb962a42aff5844fe92cf4fff406a4d6ce61fa9 100644 (file)
@@ -1,17 +1,14 @@
-/**/
+/*
+ * common
+ * utilities for helping parsing
+ */
 
 #include <stdarg.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "hostside.h"
-
-void vbadcmd(ParseState *ps, const char *fmt, va_list al) {
-  oprintf(&ps->ci->out,"error ");
-  ovprintf(&ps->ci->out,fmt,al);
-  owrite(&ps->ci->out,"\n",1);
-}
+#include "common.h"
 
 void badcmd(ParseState *ps, const char *fmt, ...) {
   va_list al;
index 59285eb2876cd73df807a097b42f11e4ba1656bc..7d2b7cd27e0b9a3f9a48bcf43a15e68fdae22965 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "realtime.h"
 
+const char *progname= "realtime";
+
 /*---------- global variables ----------*/
 
 CommandInput cmdi;
@@ -19,11 +21,11 @@ static void comms_error(const char *ch, const char *e1,
 
 static void *read_exception(oop_source *evts, int fd,
                            oop_event evt, void *cl_v) {
-  OutBufferChain *ch;
+  const char *ch;
   char bufc;
   int r;
 
-  ch= (fd==up_ochain.fd ? up_ochain.desc :
+  ch= (fd==UPO->fd ? UPO->desc :
        fd==serial_fd ? "serial port" :
        0);
   
@@ -31,6 +33,8 @@ static void *read_exception(oop_source *evts, int fd,
   if (r==-1) comms_error(ch, "read error", strerror(errno));
   else if (r==0) comms_error(ch, "reports exception, reads EOF", 0);
   else comms_error(ch, "reports exception, but readable", 0);
+
+  return OOP_CONTINUE;
 }
 
 /*---------- command channel handling (oop_read, obc) ----------*/
@@ -67,7 +71,6 @@ static PicInsn serial_buf;
 
 static void *serial_readable(oop_source *evts, int fd,
                             oop_event evt, void *u0) {
-  const Byte *ep;
   int r, buf_used;
 
   r= read(serial_fd, &serial_buf.d, sizeof(serial_buf.d) - serial_buf.l);
@@ -139,6 +142,7 @@ int main(int argc, const char **argv) {
   events->on_fd(events, serial_fd, OOP_READ, serial_readable, 0);
   events->on_fd(events, serial_fd, OOP_EXCEPTION, read_exception, 0);
 
+  sta_startup();
   oop_sys_run(sys_events);
   abort();
 }
index b98c547769cf12eedeb54f644d90192fef1dbb5e..473f415e78982d63bcf9319a00cccc07c4566196 100644 (file)
@@ -5,6 +5,18 @@
 #ifndef REALTIME_H
 #define REALTIME_H
 
+#include "daemons.h"
+#include "auproto-pic.h"
+
+#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+#include <stdlib.h>
+
+#include <sys/types.h>
+#include <sys/time.h>
+
 typedef struct RetransmitNode RetransmitNode;
 
 extern CommandInput cmdi;
@@ -19,6 +31,17 @@ typedef enum {   /* sta_toev   ping_toev    */
   Sta_Run        /*  I ?        R set       */
 } StartupState;
 
-#define UPO (&(cmdi->out));
+#define UPO (&(cmdi.out))
+
+void oupicio(const char *dirn, const PicInsnInfo *pii, int objnum);
+void ouhex(const char *word, const Byte *command, int length);
+
+void serial_moredata(PicInsn *buf);
+void serial_transmit(const PicInsn *pi);
+
+void sta_startup(void);
+extern StartupState sta_state;
+
+void abandon_run(void);
 
 #endif /*REALTIME_H*/
index d4403e4835b5da7e1ed525bea3194403d843177b..ec565e21f55df3d72aa8f759b049f5e8ab896a47 100644 (file)
@@ -7,7 +7,7 @@
  * and related functions
  */
 
-#include "hostside.h"
+#include "common.h"
 #include "auproto-pic.h"
 
 extern void enco_pic_anyinsn(PicInsn *out, const PicInsnInfo *pii,
index a72a0b0ed23603eb365145882498da58be8c395b..f9fd986ba9299e41168cca9d22c95388a614acb6 100644 (file)
@@ -5,11 +5,13 @@
 
 #include "realtime.h"
 
-static StartupState sta_state;
+StartupState sta_state;
+
 static TimeoutEvent sta_toev;
+static TimeoutEvent ping_toev;
 
 static int ping_seq;
-static PicInsn *piob;
+static PicInsn piob;
 static void sta_goto(StartupState new_state);
 
 static void timedout_onward(TimeoutEvent *toev) {
@@ -23,31 +25,28 @@ static void timedout_ping(TimeoutEvent *toev) {
 }
 
 static void timefor_ping(TimeoutEvent *toev) {
-  serial_transit(&ping_pi);
+  enco_pic_ping(&piob, ping_seq);
+  serial_transmit(&piob);
+  ping_toev.callback= timedout_ping;
   toev_start(&ping_toev);
 }
 
 static void initial_ping(void) {
   struct timeval now;
   
-  ping_toev.callback= timedout_ping;
-  ping_toev.duration=  300;
   mgettimeofday(&now);
   ping_seq= (now.tv_sec & 0x1fU) << 5; /* bottom 5bi of secs: period 32s */
   ping_seq |= (now.tv_usec >> 15);      /* top 5bi of 20bi us: res.~2^15us */
-  enco_pic_ping(&piob, ping_seq);
-  serial_transmit(&piob);
+  ping_toev.duration=  300;
   timefor_ping(0);
 }
 
+void sta_startup(void) { sta_goto(Sta_Flush); }
+
 static void sta_goto(StartupState new_state) {
   toev_stop(&sta_toev);
   sta_toev.callback= timedout_onward;
-  sta_toev.callback= -1;
-
-  toev_stop(&ping_toev);
-  ping_toev.callback= timedout_ping;
-  ping_toev.duration= -1;
+  sta_toev.duration= -1;
 
   if (new_state < Sta_Ping) {
     toev_stop(&ping_toev);
@@ -81,13 +80,16 @@ static void sta_goto(StartupState new_state) {
 
   toev_start(&sta_toev);
   sta_state= new_state;
-  notify_startup(new_state);
+
+  /* notify various people: */
+  oprintf(UPO, "stastate %d\n", sta_state);
+  /* ... add others here. */
 }   
 
 void serial_moredata(PicInsn *buf) {
   const PicInsnInfo *pii;
   int objnum;
-  char *&ep
+  Byte *ep;
 
   /* Called when more data is received from PICs.
    * On entry, buf->l is amount of data available.
@@ -132,16 +134,17 @@ void serial_moredata(PicInsn *buf) {
     ouhex("picioh in toolong", buf->d, buf->l);
     die("PIC sent packet too long");
   }
-  return 0;
+  buf->l= 0; /* message not yet finished, so consume nothing */
+  return;
 
  found_end:
   /* Aha! */
   buf->l= ep - buf->d;
   ouhex("picioh in msg", buf->d, buf->l);
-  picinsn_decode(&buf, pic_reply_infos, &pii, &objnum);
+  picinsn_decode(buf, pic_reply_infos, &pii, &objnum);
   if (!pii) { oprintf(UPO, "picio in unknown\n"); return; }
   oupicio("in",pii,objnum);
-  pii->input_fn(pii,pi,objnum);
+  pii->input_fn(pii,buf,objnum);
 }
 
 void on_pic_pong(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
@@ -151,7 +154,8 @@ void on_pic_pong(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
   if (sta_state == Sta_Ping) {
     sta_goto(Sta_Settling);
   } else {
-    ping_toev.callback= timedfor_ping;
+    ping_toev.duration= 1000;
+    ping_toev.callback= timefor_ping;
     toev_start(&ping_toev);
   }
 }
@@ -167,9 +171,9 @@ void on_pic_fault(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
   sta_goto(Sta_Fault);
 }
 
-void on_pic_watchdog(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
+void on_pic_wtimeout(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
   if (sta_state <= Sta_Settling) return;
-  if (sta_state == Sta_Resolving) die("PIC sent WATCHDOG in Resolving");
+  if (sta_state == Sta_Resolving) die("PIC sent WTIMEOUT in Resolving");
   oprintf(UPO, "warning watchdog \"PIC watchdog timer triggered\"\n");
 }
 
@@ -187,3 +191,7 @@ void on_pic_detect0(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
 void on_pic_detect1(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
   /* fixme do something here */
 }
+
+void abandon_run(void) {
+  /* fixme do something here */
+}
index db2318471bd78543cff85416481424f9af7de5a6..3a1cb42227bcc48caa36a19055bb12728129169b 100644 (file)
@@ -45,6 +45,7 @@ char *mstrdupl(const char *s, int l) {
 char *mstrdup(const char *s) { return mstrdupl(s,strlen(s)); }
 
 void mgettimeofday(struct timeval *tv) {
+  int r;
   r= gettimeofday(tv,0);
   if (r) diee("gettimeofday failed");
 }