Skip to content

Commit

Permalink
Merge pull request #214 from luarvique/pocsag_fix
Browse files Browse the repository at this point in the history
Fixing POCSAG decoders not working when fed small data over pipes, etc.
  • Loading branch information
EliasOenal authored May 16, 2024
2 parents 6547c94 + 69255ec commit be6c092
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion demod_afsk12.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* demod_afsk12.c -- 1200 baud AFSK demodulator
*
* Copyright (C) 1996
* Copyright (C) 1996
* Thomas Sailer ([email protected], [email protected])
*
* This program is free software; you can redistribute it and/or modify
Expand Down
17 changes: 9 additions & 8 deletions demod_poc12.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
* demod_poc12.c -- 1200 baud POCSAG demodulator
*
* Copyright (C) 1996
* Copyright (C) 1996
* Thomas Sailer ([email protected], [email protected])
* Copyright (C) 2024
* Marat Fayzullin ([email protected])
*
* POCSAG (Post Office Code Standard Advisory Group)
* Radio Paging Decoder
Expand Down Expand Up @@ -54,16 +56,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));
Expand All @@ -82,7 +83,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)
Expand Down
17 changes: 9 additions & 8 deletions demod_poc5.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
* demod_poc5.c -- 512 baud POCSAG demodulator
*
* Copyright (C) 1996
* Copyright (C) 1996
* Thomas Sailer ([email protected], [email protected])
* Copyright (C) 2024
* Marat Fayzullin ([email protected])
*
* POCSAG (Post Office Code Standard Advisory Group)
* Radio Paging Decoder
Expand Down Expand Up @@ -52,16 +54,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));
Expand All @@ -80,7 +81,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)
Expand Down

0 comments on commit be6c092

Please sign in to comment.