+/* val is 12 bits. Return the 16 bits value that includes the 4 bits
+ * cksum in MSB. */
+static uint16_t do_cksum(uint16_t val)
+{
+ uint16_t x, cksum;
+
+ x = (val & 0xfff);
+ /* add the three 4-bits blocks of x together */
+ cksum = x & 0xf;
+ x = x >> 4;
+ cksum += x & 0xf;
+ cksum = (cksum & 0xf) + ((cksum & 0xf0) >> 4);
+ x = x >> 4;
+ cksum += x & 0xf;
+ cksum = (cksum & 0xf) + ((cksum & 0xf0) >> 4);
+ cksum = (~cksum) & 0xf;
+ return (cksum << 12) + (val & 0xfff);
+}
+
+/* get the frame from laser time difference, return 0 on error (this
+ * frame cannot be sent). */