From 5fe6e1a6993712ecb138c0ce671eeb597a358d81 Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 4 Jun 2005 10:14:37 +0000 Subject: [PATCH] serial_transmit takes a PicInsn --- hostside/commands.c | 10 +++++----- hostside/common.h | 3 +-- hostside/hostside.h | 5 ++--- hostside/main.c | 7 +++---- hostside/nmra.c | 10 +++++----- hostside/output.c | 6 +++--- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/hostside/commands.c b/hostside/commands.c index c80c845..c2e5d24 100644 --- a/hostside/commands.c +++ b/hostside/commands.c @@ -53,7 +53,7 @@ static int cmd_nmra_command(ParseState *ps, RetransmitNode *rn) { assert(ps->remain); switch (ps->remain[0]) { - case '_': ps->remain++; return ps_needhextoend(ps, rn->d, &rn->l); + case '_': ps->remain++; return ps_needhextoend(ps, rn->pi.d, &rn->pi.l); case '=': hex=1; checksum=1; break; case ':': hex=1; checksum=0; break; default: hex=0; checksum=1; break; @@ -89,7 +89,7 @@ static int cmd_nmra_command(ParseState *ps, RetransmitNode *rn) { if (checksum) nmra_addchecksum(&nmra); - nmra_encodeforpic(&nmra, rn->d, &rn->l); + nmra_encodeforpic(&nmra, &rn->pi); return 1; } @@ -134,7 +134,7 @@ static void cmd_nmra(ParseState *ps, const CmdInfo *ci) { } rn= mrn ? &mrn->rn : &rn_buf; - rn->l= sizeof(rn->d); + rn->pi.l= sizeof(rn->pi.d); if (!cmd_nmra_command(ps, rn)) { if (mrn) { free(mrn->name); free(mrn); } @@ -144,7 +144,7 @@ static void cmd_nmra(ParseState *ps, const CmdInfo *ci) { if (mrn) retransmit_queue(&mrn->rn); else - serial_transmit(rn->d, rn->l); + serial_transmit(&rn->pi); } static void cmd_noop(ParseState *ps, const CmdInfo *ci) { @@ -176,7 +176,7 @@ static void cmd_pic(ParseState *ps, const CmdInfo *ci) { if (!ps_neednoargs(ps)) return; enco_pic_anyinsn(&pi, pii, arg); - serial_transmit(pi.d, pi.l); + serial_transmit(&pi); } const CmdInfo toplevel_cmds[]= { diff --git a/hostside/common.h b/hostside/common.h index 1a008c9..a1b163d 100644 --- a/hostside/common.h +++ b/hostside/common.h @@ -51,8 +51,7 @@ void nmra_parse_encode(Nmra *out, const char *arg, int argl, void nmra_problem(NmraParseEncodeCaller *pec, const char *problem); void nmra_addchecksum(Nmra *packet); -void nmra_encodeforpic(const Nmra *packet, Byte *picdata, int *lpicdata_r); - /* picdata should point to COMMAND_ENCODED_MAX bytes */ +void nmra_encodeforpic(const Nmra *packet, PicInsn *pi_out); #endif /*COMMON_H*/ diff --git a/hostside/hostside.h b/hostside/hostside.h index 6bb5755..3216edc 100644 --- a/hostside/hostside.h +++ b/hostside/hostside.h @@ -49,7 +49,7 @@ void ooprintf(Selector sel, const char *fmt, ...) __attribute__((format(printf,2,3))); void oowrite(Selector sel, const char *data, int l); -void serial_transmit(const Byte *command, int length); +void serial_transmit(const PicInsn *pi); void output_hex(Selector sel, const char *work, const Byte *command, int length); @@ -115,8 +115,7 @@ extern const CmdInfo toplevel_cmds[]; /* defined in commands.c*/ struct RetransmitNode { /* set by caller: */ - Byte d[COMMAND_ENCODED_MAX]; - int l; + PicInsn pi; /* internal: */ }; diff --git a/hostside/main.c b/hostside/main.c index ce2b50e..7b6a283 100644 --- a/hostside/main.c +++ b/hostside/main.c @@ -90,12 +90,11 @@ static void xmit_command(void) { } static void xmit_nmra_raw(void) { - Byte encoded[COMMAND_ENCODED_MAX]; - int lencoded; + PicInsn pi; dump("xmit_nmra_raw", buf.d, buf.l); - nmra_encodeforpic(&buf, encoded, &lencoded); - serial_transmit_now(encoded, lencoded); + nmra_encodeforpic(&buf, &pi); + serial_transmit_now(pi.d, pi.l); } static void xmit_nmra_bytes(void) { diff --git a/hostside/nmra.c b/hostside/nmra.c index 0032870..be0d38a 100644 --- a/hostside/nmra.c +++ b/hostside/nmra.c @@ -7,7 +7,7 @@ #include "common.h" #include "nmra.h" -void nmra_encodeforpic(const Nmra *packet, Byte *encoded, int *lencoded_r) { +void nmra_encodeforpic(const Nmra *packet, PicInsn *pi) { const Byte *bp; int length; Byte *encp; @@ -19,7 +19,7 @@ void nmra_encodeforpic(const Nmra *packet, Byte *encoded, int *lencoded_r) { assert(length > 0); assert(length <= NMRA_PACKET_MAX); - encp= encoded; + encp= pi->d; working= 0xfffc; /* 16-bit temp register. Top working_qty bits */ working_qty= 15; /* are some data bits to encode, rest are clear. */ /* we start with the 14-bit preamble and the packet start bit */ @@ -43,14 +43,14 @@ void nmra_encodeforpic(const Nmra *packet, Byte *encoded, int *lencoded_r) { working_qty= 7; } } - assert(encp < encoded + COMMAND_ENCODED_MAX); + assert(encp < pi->d + COMMAND_ENCODED_MAX); *encp++= (working >> 9) & 0x7f; /* top 7 bits, right-justified */ working <<= 7; working_qty -= 7; } - assert(encp > encoded); + assert(encp > pi->d); encp[-1] |= 0x80; /* `end of command' bit */ - *lencoded_r= encp - encoded; + pi->l= encp - pi->d; } void nmra_addchecksum(Nmra *packet) { diff --git a/hostside/output.c b/hostside/output.c index fe0c8b4..3081c0c 100644 --- a/hostside/output.c +++ b/hostside/output.c @@ -40,7 +40,7 @@ void output_hex(Selector sel, const char *word, ooprintf(sel, "\n"); } -void serial_transmit(const Byte *command, int length) { - output_hex('p', "pic-out", command,length); - serial_transmit_now(command, length); +void serial_transmit(const PicInsn *pi) { + output_hex('p', "pic-out", pi->d, pi->l); + serial_transmit_now(pi->d, pi->l); } -- 2.30.2