const char *simulate;
static SimEventFn se_timestamp, se_timerevent;
-static SimEventFn se_serial, se_command, se_eof;
+static SimEventFn se_serial, se_samedet, se_command, se_eof;
static SimTimeout *simtimeouts;
static char *sevent_buf;
static size_t sevent_buflen;
static int sevent_lno;
+static Byte sevent_lastdet[2];
static SimEventFn *sevent_type;
static char *sevent_data;
static struct timeval sevent_abst;
+#define PICMSG_DETECT_01 (PICMSG_DETECT0^PICMSG_DETECT1)
+
/*---------- writing simulation log ----------*/
+static Byte simlog_lastdet[2];
+
void simlogv(const char *fmt, va_list al) {
if (simoutput==stdout) ovprintf(UPO,fmt,al);
else if (simoutput) vfprintf(simoutput,fmt,al);
+ simlog_lastdet[0]= 0;
}
void simlog(const char *fmt, ...) {
va_list al;
diee("write simulation log");
}
void simlog_serial(const Byte *data, int length) {
- simlog("picioh in suppressed");
+ static Byte db0, db1;
+ int is_det;
+
+ if (!length) return;
+
+ db0= data[0] & ~PICMSG_DETECT_01;
+
+ /* optimise consecutive dithering detects into just 0 and 1 msgs */
+ is_det= PICMSG_DETECT0_P(db0) && length==2 && !((db1=data[1]) & 0x80);
+ if (is_det) {
+ if (db0==simlog_lastdet[0] && data[1]==simlog_lastdet[1]) {
+ simlog("%d\n",!!(data[0] & PICMSG_DETECT_01));
+ goto set_lastdet;
+ }
+ simlog("picioh in suppressed-detect");
+ } else {
+ simlog("picioh in suppressed");
+ }
+
while (length--) simlog(" %02x",*data++);
simlog("\n");
simlog_flush();
+
+ set_lastdet:
+ if (is_det) {
+ simlog_lastdet[0]= db0;
+ simlog_lastdet[1]= db1;
+ }
}
void simlog_open(const char *fn) {
if (!fn) fn= "+realtime.log";
assert(sevent_buf[gr-1]=='\n');
sevent_buf[gr-1]= 0;
+ if ((sevent_buf[0] & ~1)=='0' && !sevent_buf[1]) {
+ sevent_type= se_samedet;
+ sevent_data= &sevent_buf[0];
+ return;
+ }
+
#define IF_ET(pfx, et) \
if (!strncmp(pfx " ", sevent_buf, sizeof(pfx)) \
&& (sevent_type=(et), p=sevent_buf+(sizeof(pfx))))
serial_buf.d[buf_used++]= strtoul(c,&ep,16);
if (*ep) simbad("bad hex");
}
+ if (buf_used>=2) {
+ Byte db0= serial_buf.d[buf_used-2] & ~PICMSG_DETECT_01;
+ if (PICMSG_DETECT0_P(db0)) {
+ sevent_lastdet[0]= db0;
+ sevent_lastdet[1]= serial_buf.d[buf_used-1];
+ }
+ }
+ serial_indata_process(buf_used);
+}
+
+static void se_samedet(void) {
+ int buf_used;
+
+ buf_used= serial_buf.l;
+ if (buf_used >= sizeof(serial_buf.d)-1) simbad("samedet serial_buf overrun");
+ if (!sevent_lastdet[0]) simbad("samedet but no previous det");
+ if (sevent_lastdet[1] & 0x80) simbad("samedet but bad previous det");
+ serial_buf.d[buf_used++]= sevent_lastdet[0] |
+ (sevent_data[0]=='1' ? PICMSG_DETECT_01 : 0);
+ serial_buf.d[buf_used++]= sevent_lastdet[1];
serial_indata_process(buf_used);
}