< 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
#
-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:
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
__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
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:
#include <stdlib.h>
#include <errno.h>
-#include "hostside.h"
+#include "multiplex.h"
#include "../layout/dlist.h"
struct ClientList clients;
#include <assert.h>
#include <string.h>
-#include "hostside.h"
+#include "realtime.h"
#include "auproto-pic.h"
#define NMRA_MAX_NARGS 10
#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;
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)
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);
#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: */
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. */
/* 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*/
#include <X11/Xlib.h>
#include <X11/xpm.h>
-#include "hostside.h"
+#include "common.h"
#include "../layout/plan-data-format.h"
#include <oop.h>
};
oop_source *events;
+const char *progname= "gui-plan";
static SegmovfeatState **state, *states_head;
static Display *d;
/*
+ * OBSOLETE FILE
* declarations for hostside controller daemon
*/
#include "common.h"
-typedef struct ParseState ParseState;
-typedef struct CmdInfo CmdInfo;
-
/*---------- from protocol.c ----------*/
typedef struct OrdinaryPicMessage 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 {
void retransmit_queue(RetransmitNode *rn);
void retransmit_cancel(RetransmitNode *rn);
+
+#endif
#include "common.h"
+const char *progname= "hostside-old";
static FILE *dump_stream= 0;
static int repeat_delay= -1, iterations= -1;
#include "daemons.h"
-typedef struct Client Client;
-
/*---------- from output.c ----------*/
typedef unsigned long Selector;
#include <stdarg.h>
#include <string.h>
-#include "hostside.h"
+#include "daemons.h"
#include "../layout/dlist.h"
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;
-/**/
+/*
+ * 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;
#include "realtime.h"
+const char *progname= "realtime";
+
/*---------- global variables ----------*/
CommandInput cmdi;
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);
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) ----------*/
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);
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();
}
#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;
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*/
* and related functions
*/
-#include "hostside.h"
+#include "common.h"
#include "auproto-pic.h"
extern void enco_pic_anyinsn(PicInsn *out, const PicInsnInfo *pii,
#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) {
}
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);
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.
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) {
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);
}
}
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");
}
void on_pic_detect1(const PicInsnInfo *pii, const PicInsn *pi, int objnum) {
/* fixme do something here */
}
+
+void abandon_run(void) {
+ /* fixme do something here */
+}
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");
}