/**/
#include <assert.h>
+#include <stdio.h>
#include "hostside.h"
working_qty= 15; /* are some data bits to encode, rest are clear. */
/* we start with the 14-bit preamble and the packet start bit */
for (;;) {
+fprintf(stderr,"l=%d w=%08x q=%-2d",length,working,working_qty);
assert(working_qty >= 0);
if (working_qty < 7) {
if (length > 0) {
+fprintf(stderr," nmra=%02x",*nmra_packet);
/* plonk new data bits just to right of old data bits */
length--;
newbits= *nmra_packet++;
newbits |= !length; /* 9 bits, bottom one is `end of packet' */
working |= (newbits << (7-working_qty));
working_qty += 9;
+fprintf(stderr," nmra\n");
+continue;
} else if (!working_qty) {
/* all done */
+fprintf(stderr," alldone\n");
break;
} else {
/* pad with exactly enough 1 bits to make up the encoded byte */
working |= 0xffU << (8-working_qty);
working_qty= 7;
+fprintf(stderr," pad\n");
}
}
assert(encp < encoded + COMMAND_ENCODED_MAX);
*encp++= (working >> 9) & 0x7f; /* top 7 bits, right-justified */
+fprintf(stderr," enc=%02x\n", encp[-1]);
working <<= 7;
working_qty -= 7;
}