From c8441065cd3e354674b5533814a761c7fd87b855 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 9 Feb 2011 11:20:18 +0100 Subject: [PATCH] hdlcsync: disable debug output, only print decoded hdlc data --- hdlc/hdlcsync.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/hdlc/hdlcsync.c b/hdlc/hdlcsync.c index e5b4624..ff236ea 100644 --- a/hdlc/hdlcsync.c +++ b/hdlc/hdlcsync.c @@ -10,6 +10,12 @@ #include #include +#if 0 +#define DEBUGP(x, args ...) fprintf(stderr, x, ## args) +#else +#define DEBUGP(x, args ...) do {} while (0) +#endif + enum hdlc_proc_state { STATE_INIT, STATE_FLAG_WAIT_ZERO, @@ -50,14 +56,15 @@ static int append_bit(struct hdlc_proc *hdlc, uint8_t bit, int ignore) static int process_hdlc_bit(struct hdlc_proc *hdlc, uint8_t bit) { int ignore = 0; - int out; + int out, flag = 0; - printf("bit=%u, history_in = %s, ", bit, ubit_dump(hdlc->history, sizeof(hdlc->history))); + DEBUGP("bit=%u, history_in = %s, ", bit, ubit_dump(hdlc->history, sizeof(hdlc->history))); switch (hdlc->state) { case STATE_FLAG_WAIT_ZERO: if (bit == 0) { - printf("F "); + DEBUGP("F "); + flag = 1; hdlc->state = STATE_PAYLOAD; } else { hdlc->state = STATE_INIT; @@ -68,7 +75,7 @@ static int process_hdlc_bit(struct hdlc_proc *hdlc, uint8_t bit) default: if (!memcmp(five_ones, hdlc->history, sizeof(five_ones))) { if (bit == 1) { - //printf("F "); + //DEBUGP("F "); hdlc->state = STATE_FLAG_WAIT_ZERO; ignore = 1; } else { @@ -79,13 +86,16 @@ static int process_hdlc_bit(struct hdlc_proc *hdlc, uint8_t bit) break; } out = append_bit(hdlc, bit, ignore); - printf("history_out = %s", ubit_dump(hdlc->history, sizeof(hdlc->history))); + DEBUGP("history_out = %s", ubit_dump(hdlc->history, sizeof(hdlc->history))); if (out > 0) - printf(", out 0x%02x\n", out); + DEBUGP(", out 0x%02x\n", out); else - printf("\n"); + DEBUGP("\n"); - return out; + if (flag) + return -123; + else + return out; } static int process_raw_hdlc(struct hdlc_proc *hdlc, uint8_t *data, unsigned int len) @@ -95,6 +105,10 @@ static int process_raw_hdlc(struct hdlc_proc *hdlc, uint8_t *data, unsigned int for (i = 0; i < len; i ++) { out = process_hdlc_bit(hdlc, data[i]); + if (out == -123) + printf("F "); + else if (out >= 0) + printf("%02x ", out); } } @@ -126,7 +140,7 @@ int main(int argc, char **argv) exit(1); bitlen = osmo_pbit2ubit_ext(bitbuf, 0, buf, 0, rc*8, 0); - printf("%s\n", ubit_dump(bitbuf, bitlen)); + DEBUGP("%s\n", ubit_dump(bitbuf, bitlen)); process_raw_hdlc(&hdlc, bitbuf, bitlen); }