chiark / gitweb /
optimise away identical flickering detections
authorian <ian>
Sat, 24 May 2008 11:28:16 +0000 (11:28 +0000)
committerian <ian>
Sat, 24 May 2008 11:28:16 +0000 (11:28 +0000)
hostside/README.commands
hostside/simulate.c

index 4ca65b7a184e04a94545161cee007bf634f4ceb0..9ffb95a8ee503955286fb50109e7bf5ba2bff10b 100644 (file)
@@ -71,9 +71,11 @@ POSSIBLY-ASYNCHRONOUS REPORTING OF MESSAGES TO/FROM (MASTER) PIC
 MESSAGES TO SIMULATION LOG
 
  L  picioh in suppressed <byte> [<byte>...]
+ L  picioh in suppressed-detect <byte> [<byte>...]
  L  command-in <command> <args>....
  L  timestamp <seconds>.<microseconds>
  L  timer-event <class>.<instance>
+ L  0|1                   detection, same segment as last suppressed-detect
 
 ======================================================================
 
index 2f42e32db9d315c9243df11d8b6a210ddb82437d..0f5f9b582dc5a9a3bd517228be075a1a2490e7c7 100644 (file)
@@ -16,7 +16,7 @@ int simlog_full;
 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;
 
@@ -25,16 +25,22 @@ static FILE *siminput;
 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;
@@ -49,10 +55,34 @@ void simlog_flush(void) {
       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";
@@ -89,6 +119,12 @@ static void sevent(void) {
     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))))
@@ -190,6 +226,26 @@ static void se_serial(void) {
     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);
 }