From 7611ab7e400f64b6c656d7e0870eb0f07eda5707 Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Mon, 6 May 2024 21:12:23 -0400 Subject: [PATCH 1/2] Fixing POCSAG decoders not working when fed small data over pipes, etc. --- demod_poc12.c | 13 ++++++------- demod_poc5.c | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/demod_poc12.c b/demod_poc12.c index 5266290..c020c9b 100644 --- a/demod_poc12.c +++ b/demod_poc12.c @@ -54,16 +54,15 @@ static void poc12_init(struct demod_state *s) static void poc12_demod(struct demod_state *s, buffer_t buffer, int length) { if (s->l1.poc12.subsamp) { - int numfill = SUBSAMP - s->l1.poc12.subsamp; - if (length < numfill) { - s->l1.poc12.subsamp += length; + if (length <= (int)s->l1.poc12.subsamp) { + s->l1.poc12.subsamp -= length; return; } - buffer.fbuffer += numfill; - length -= numfill; + buffer.fbuffer += s->l1.poc12.subsamp; + length -= s->l1.poc12.subsamp; s->l1.poc12.subsamp = 0; } - for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { + for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { s->l1.poc12.dcd_shreg <<= 1; s->l1.poc12.dcd_shreg |= ((*buffer.fbuffer) > 0); verbprintf(10, "%c", '0'+(s->l1.poc12.dcd_shreg & 1)); @@ -82,7 +81,7 @@ static void poc12_demod(struct demod_state *s, buffer_t buffer, int length) pocsag_rxbit(s, s->l1.poc12.dcd_shreg & 1); } } - s->l1.poc12.subsamp = length; + s->l1.poc12.subsamp = -length; } static void poc12_deinit(struct demod_state *s) diff --git a/demod_poc5.c b/demod_poc5.c index 16c4f1e..063d56a 100644 --- a/demod_poc5.c +++ b/demod_poc5.c @@ -52,16 +52,15 @@ static void poc5_init(struct demod_state *s) static void poc5_demod(struct demod_state *s, buffer_t buffer, int length) { if (s->l1.poc5.subsamp) { - int numfill = SUBSAMP - s->l1.poc5.subsamp; - if (length < numfill) { - s->l1.poc5.subsamp += length; + if (length <= (int)s->l1.poc5.subsamp) { + s->l1.poc5.subsamp -= length; return; } - buffer.fbuffer += numfill; - length -= numfill; + buffer.fbuffer += s->l1.poc5.subsamp; + length -= s->l1.poc5.subsamp; s->l1.poc5.subsamp = 0; } - for (; length >= SUBSAMP; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { + for (; length > 0; length -= SUBSAMP, buffer.fbuffer += SUBSAMP) { s->l1.poc5.dcd_shreg <<= 1; s->l1.poc5.dcd_shreg |= ((*buffer.fbuffer) > 0); verbprintf(10, "%c", '0'+(s->l1.poc5.dcd_shreg & 1)); @@ -80,7 +79,7 @@ static void poc5_demod(struct demod_state *s, buffer_t buffer, int length) pocsag_rxbit(s, s->l1.poc5.dcd_shreg & 1); } } - s->l1.poc5.subsamp = length; + s->l1.poc5.subsamp = -length; } static void poc5_deinit(struct demod_state *s) From 69255ec5851ef57f8910fa3ccd307024a93e39bd Mon Sep 17 00:00:00 2001 From: Marat Fayzullin Date: Tue, 14 May 2024 23:05:51 -0400 Subject: [PATCH 2/2] Added copyrights. --- demod_afsk12.c | 2 +- demod_poc12.c | 4 +++- demod_poc5.c | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/demod_afsk12.c b/demod_afsk12.c index 67501e9..fd4763e 100644 --- a/demod_afsk12.c +++ b/demod_afsk12.c @@ -1,7 +1,7 @@ /* * demod_afsk12.c -- 1200 baud AFSK demodulator * - * Copyright (C) 1996 + * Copyright (C) 1996 * Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu) * * This program is free software; you can redistribute it and/or modify diff --git a/demod_poc12.c b/demod_poc12.c index c020c9b..61d7947 100644 --- a/demod_poc12.c +++ b/demod_poc12.c @@ -1,8 +1,10 @@ /* * demod_poc12.c -- 1200 baud POCSAG demodulator * - * Copyright (C) 1996 + * Copyright (C) 1996 * Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu) + * Copyright (C) 2024 + * Marat Fayzullin (luarvique@gmail.com) * * POCSAG (Post Office Code Standard Advisory Group) * Radio Paging Decoder diff --git a/demod_poc5.c b/demod_poc5.c index 063d56a..8de854c 100644 --- a/demod_poc5.c +++ b/demod_poc5.c @@ -1,8 +1,10 @@ /* * demod_poc5.c -- 512 baud POCSAG demodulator * - * Copyright (C) 1996 + * Copyright (C) 1996 * Thomas Sailer (sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu) + * Copyright (C) 2024 + * Marat Fayzullin (luarvique@gmail.com) * * POCSAG (Post Office Code Standard Advisory Group) * Radio Paging Decoder