hdlcsync: disable debug output, only print decoded hdlc data

This commit is contained in:
Harald Welte 2011-02-09 11:20:18 +01:00
parent 02ddcf9d90
commit c8441065cd
1 changed files with 23 additions and 9 deletions

View File

@ -10,6 +10,12 @@
#include <osmocore/utils.h>
#include <osmocore/bits.h>
#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);
}