void nmra_transmit(const Byte *nmra_packet, int length) {
Byte encoded[COMMAND_ENCODED_MAX], *encp;
unsigned working;
- int working_bits;
+ int working_qty;
assert(length <= NMRA_PACKET_MAX);
encp= encoded;
- working= 0xfffc; /* 16-bit temp register. Top working_bits bits */
- working_bits= 14; /* are some data bits to encode, rest are clear. */
+ working= 0xfffc; /* 16-bit temp register. Top working_qty bits */
+ working_qty= 14; /* are some data bits to encode, rest are clear. */
for (;;) {
- assert(working_bits >= 0);
- if (working_bits < 7) {
+ assert(working_qty >= 0);
+ if (working_qty < 7) {
if (length > 0) {
/* plonk new data bits just to right of old data bits */
- working |= (*nmra_packet++ << (8-working_bits));
+ working |= (*nmra_packet++ << (8-working_qty));
length--;
- working_bits += 8;
- } else if (!working_bits) {
+ working_qty += 8;
+ } else if (!working_qty) {
/* all done */
break;
} else {
/* pad with exactly enough 1 bits to make up the encoded byte */
- working |= 0xffU << (8-working_bits);
- working_bits= 7;
+ working |= 0xffU << (8-working_qty);
+ working_qty= 7;
}
}
assert(encp < encoded + COMMAND_ENCODED_MAX);
- *encp++= (working_bits >> 8) & 0xfe; /* top 7 bits, shifted left one */
- working_bits -= 7;
+ *encp++= (working >> 8) & 0xfe; /* top 7 bits, shifted left one */
+ working <<= 7;
+ working_qty -= 7;
}
assert(encp > encoded);
encp[-1] |= 0x01; /* `end of command' bit */