Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - add end-of-train and head-of-train message decoding #387

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
709f229
Initial checkin for EOTD support.
dtiller Mar 18, 2022
c491655
More framework.
dtiller Mar 19, 2022
7bde86f
#ifdef'ed debugging.
dtiller Mar 19, 2022
507f04e
Added date tag for debugging.
dtiller Mar 20, 2022
3b17d45
#ifdef'ed a lot of stuff.
dtiller Mar 20, 2022
26ac27b
Added beginnings of BCH processing.
dtiller Mar 20, 2022
d898d1b
Added derived code to calc/apply BCH codes.
dtiller Mar 21, 2022
be0f9c4
debug and comment changes.
dtiller Mar 21, 2022
475f951
Put original program back for reference. Added fixed codes.
dtiller Mar 21, 2022
53d5b2b
checked return status and found that we _can_ use 'forward' packets (…
dtiller Mar 22, 2022
a707fc8
Cleaned up output.
dtiller Mar 22, 2022
5be9e44
Closer. Lots of ACCA data to chew on.
dtiller Mar 22, 2022
742dfb4
Last checkin before trying dev branch.
dtiller Mar 29, 2022
98b8949
Slight fixes before switching to uint64_t and MSB processing.
dtiller Mar 30, 2022
7d58e40
New branch for 64 bit processing. Probably not needed.
dtiller Mar 30, 2022
2cf23db
Default buffer was _way_ too small.
dtiller Apr 2, 2022
1fb18ed
changes for 64 bit uint. Not sure I like them.
dtiller Apr 2, 2022
07209b5
First fully-working BCH code.
dtiller Apr 4, 2022
fa49b6a
Starting to look like a real project.
dtiller Apr 4, 2022
7646fc5
Shortened timestamp.
dtiller Apr 4, 2022
9871ba8
Added f2r decoder.
dtiller Apr 5, 2022
72708ec
Added mS to time.
dtiller Apr 5, 2022
09d2d5f
Added ARM logic.
dtiller Apr 5, 2022
a12f9e0
Added option block processing.
dtiller Apr 5, 2022
b17d987
Merge branch 'wb2osz:master' into feat-EOTD-master
dtiller Apr 5, 2022
27c97e3
Debian needs stdint.h in more places.
dtiller Apr 6, 2022
16d102e
Cleanup and changes to fix DTMF message.
dtiller Apr 6, 2022
f20fcd0
Debian is _picky_. Fixed a few warnings.
dtiller Apr 6, 2022
971383a
Deleted unneeded file.
dtiller Apr 6, 2022
2ea1a18
Added support for gen_packets.
dtiller Apr 7, 2022
89bc82b
Moved unit_addr closer to the beginning so it's always in the same pl…
dtiller Apr 8, 2022
1d7a4b9
Changed FRONT>REAR to dir=f2r, etc for consistency.
dtiller Apr 8, 2022
c4ccbdc
Added msg re: BCH code and added protective #ifndefs.
dtiller Apr 9, 2022
52298c1
Made -e flag imply the right (wrong\!) mark and space freqs and baud …
dtiller Apr 9, 2022
67d5900
Removed unused variable.
dtiller Apr 9, 2022
2048747
Added XOR for t=3 packets, added more verbiage, removed variable-leng…
dtiller Apr 9, 2022
6c8cf2a
Added pkttest and bchapply to the CMake system.
dtiller Apr 9, 2022
52d3d84
Deleted spurious executable.
dtiller Apr 9, 2022
b17f6f0
Fixed CMake issue and missing inttypes.h
dtiller Apr 29, 2022
c8d8977
Fixed typo.
dtiller May 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Last checkin before trying dev branch.
  • Loading branch information
dtiller committed Mar 29, 2022
commit 742dfb486b710c61be5b1cbae25de46dd5de33f3
86 changes: 60 additions & 26 deletions src/bch.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@
#include <string.h>
#include "bch.h"

#undef DEBUG

int init_bch(bch_t *bch, int m, int length, int t) {

int p[21], n;
Expand Down Expand Up @@ -119,16 +117,16 @@ int init_bch(bch_t *bch, int m, int length, int t) {
else if (m == 20) p[3] = 1;

n = 1;
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("p(x) = ");
#endif
for (int i = 0; i <= m; i++) {
n *= 2;
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("%1d", p[i]);
#endif
}
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("\n");
#endif
n = n / 2 - 1;
Expand Down Expand Up @@ -192,7 +190,7 @@ int init_bch(bch_t *bch, int m, int length, int t) {
cycle[1][0] = 1;
size[1] = 1;
jj = 1; /* cycle set index */
#ifdef DEBUG
#ifdef BCH_DEBUG
if (bch->m > 9) {
printf("Computing cycle sets modulo %d\n", bch->n);
printf("(This may take some time)...\n");
Expand Down Expand Up @@ -260,7 +258,7 @@ int init_bch(bch_t *bch, int m, int length, int t) {
return -4;
}

#ifdef DEBUG
#ifdef BCH_DEBUG
printf("This is a (%d, %d, %d) binary BCH code\n", bch->length, bch->k, d);
#endif

Expand All @@ -277,7 +275,7 @@ int init_bch(bch_t *bch, int m, int length, int t) {
bch->g[jj] = bch->g[jj - 1];
bch->g[0] = bch->alpha_to[(bch->index_of[bch->g[0]] + zeros[ii]) % bch->n];
}
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("Generator polynomial:\ng(x) = ");
for (ii = 0; ii <= rdncy; ii++) {
printf("%d", bch->g[ii]);
Expand All @@ -287,7 +285,7 @@ int init_bch(bch_t *bch, int m, int length, int t) {
return 0;
}

void generate_bch(bch_t *bch, int *data, int *bb) {
void generate_bch(bch_t *bch, const int *data, int *bb) {
/*
* Compute redundacy bb[], the coefficients of b(x). The redundancy
* polynomial b(x) is the remainder after dividing x^(length-k)*data(x)
Expand Down Expand Up @@ -315,7 +313,7 @@ void generate_bch(bch_t *bch, int *data, int *bb) {
}


int apply_bch(bch_t *bch, int *recd)
int apply_bch(const bch_t *bch, int *recd)
/*
* Simon Rockliff's implementation of Berlekamp's algorithm.
*
Expand Down Expand Up @@ -346,7 +344,7 @@ int apply_bch(bch_t *bch, int *recd)
t2 = 2 * bch->t;

/* first form the syndromes */
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("S(x) = ");
#endif
for (i = 1; i <= t2; i++) {
Expand All @@ -362,11 +360,11 @@ int apply_bch(bch_t *bch, int *recd)
*/
/* convert syndrome from polynomial form to index form */
s[i] = bch->index_of[s[i]];
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("%3d ", s[i]);
#endif
}
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("\n");
#endif

Expand Down Expand Up @@ -468,7 +466,7 @@ int apply_bch(bch_t *bch, int *recd)
for (i = 0; i <= l[u]; i++)
elp[u][i] = bch->index_of[elp[u][i]];

#ifdef DEBUG
#ifdef BCH_DEBUG
printf("sigma(x) = ");
for (i = 0; i <= l[u]; i++)
printf("%3d ", elp[u][i]);
Expand All @@ -491,12 +489,12 @@ int apply_bch(bch_t *bch, int *recd)
root[count] = i;
loc[count] = bch->n - i;
count++;
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("%3d ", bch->n - i);
#endif
}
}
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("\n");
#endif
if (count == l[u]) {
Expand All @@ -506,7 +504,7 @@ int apply_bch(bch_t *bch, int *recd)
return l[u];
}
else { /* elp has degree >t hence cannot solve */
#ifdef DEBUG
#ifdef BCH_DEBUG
printf("Incomplete decoding: errors detected\n");
#endif
return -1;
Expand All @@ -520,7 +518,7 @@ int apply_bch(bch_t *bch, int *recd)
}

/* LEFT justified in hex */
void bytes_to_bits(int *bytes, int *bit_dest, int num_bits) {
void bytes_to_bits(const int *bytes, int *bit_dest, int num_bits) {
for (int i = 0; i < num_bits; i++) {
int index = i / 8;
int bit_pos = 7 - (i % 8);
Expand All @@ -529,7 +527,7 @@ void bytes_to_bits(int *bytes, int *bit_dest, int num_bits) {
}
}

void bits_to_bytes(int *bits, int *byte_dest, int num_bits) {
void bits_to_bytes(const int *bits, int *byte_dest, int num_bits) {

int index;

Expand All @@ -540,30 +538,66 @@ void bits_to_bytes(int *bits, int *byte_dest, int num_bits) {
}

byte_dest[index] <<= 1;
byte_dest[index] |= bits[i] & 0x01;
byte_dest[index] |= (bits[i] & 0x01);
}

byte_dest[index] <<= 8 - (num_bits % 8);
}

void swap_format(int *bits, int cutoff, int num_bits) {
void swap_format(const int *bits, int *dest, int cutoff, int num_bits) {
// Do it the easy way
int *temp = malloc(num_bits * sizeof(int));
for (int i = 0; i < num_bits; i++) {
if (i < cutoff) {
temp[num_bits - cutoff + i] = bits[i];
dest[num_bits - cutoff + i] = bits[i];
} else {
temp[i - cutoff] = bits[i];
dest[i - cutoff] = bits[i];
}
}
}

int rotate_byte(int x) {
int y = 0;

for (int i = 0; i < 8; i++) {
y <<= 1;
y |= (x & 0x01);
x >>= 1;
}

memcpy(bits, temp, num_bits * sizeof(int));
return y;
}

void dump_bch(bch_t *bch) {
void rotate_bits(const int *in, int *out, int num_bits) {
for (int i = 0; i < num_bits; i++) {
out[i] = in[num_bits - i - 1];
}
}

void invert_bits(const int *bits, int *dest, int num_bits) {
for (int i = 0; i < num_bits; i++) {
dest[i] = (bits[i] == 0);
}
}

void dump_bch(const bch_t *bch) {
printf("m: %d length: %d t: %d n: %d k: %d\n", bch->m, bch->length, bch->t, bch->n, bch->k);
}

void print_array(const char *msg, const char *format, const int *bytes, int num_bytes) {
printf("%s", msg);
for (int i = 0; i < num_bytes; i++) {
printf(format, bytes[i]);
}
}

void print_bytes(const char *msg, const int *bytes, int num_bytes) {
print_array(msg, "%02x ", bytes, num_bytes);
}

void print_bits(const char *msg, const int *bits, int num_bits) {
print_array(msg, "%d ", bits, num_bits);
}

#undef MAIN
#undef TEST_BYTES_TO_BITS
#define TEST_SWAP
Expand Down
20 changes: 15 additions & 5 deletions src/bch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ typedef struct bch bch_t;

int init_bch(bch_t *bch, int m, int length, int t);

void generate_bch(bch_t *bch, int *data, int *bb);
void generate_bch(bch_t *bch, const int *data, int *bb);

int apply_bch(bch_t *bch, int *recd);
int apply_bch(const bch_t *bch, int *recd);

void bytes_to_bits(int *bytes, int *bit_dest, int num_bits);
void bytes_to_bits(const int *bytes, int *bit_dest, int num_bits);

void bits_to_bytes(int *bits, int *byte_dest, int num_bits);
void bits_to_bytes(const int *bits, int *byte_dest, int num_bits);

void swap_format(int *bits, int cutoff, int num_bits);
void swap_format(const int *bits, int *dest, int cutoff, int num_bits);

int rotate_byte(int x);

void rotate_bits(const int *in, int *out, int num_bits);

void print_bytes(const char *msg, const int *bytes, int num_bytes);

void print_bits(const char *msg, const int *bits, int num_bits);

void invert_bits(const int *bits, int *dest, int num_bits);

#endif
2 changes: 1 addition & 1 deletion src/eotd.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void eotd_to_nmea (unsigned char *eotd, int eotd_len, char *nmea, int nmea_size)
strcat(nmea, ctime(&now));
for (int i = 0; i < eotd_len; i++) {
char temp[32];
snprintf(temp, sizeof(temp), "%d=%02x ", i, eotd[i]);
snprintf(temp, sizeof(temp), " %02x", eotd[i]);
strlcat(nmea, temp, nmea_size);
}
}
15 changes: 10 additions & 5 deletions src/hdlc_rec.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

//#define DEBUG3 1 /* monitor the data detect signal. */

#undef EOTD_DEBUG



/*
Expand Down Expand Up @@ -427,9 +429,10 @@ a good modem here and providing a result when it is received.
*
***********************************************************************************/

#define PREAMBLE_AND_BARKER_CODE 0x55555712
#define EOTD_PREAMBLE_AND_BARKER_CODE 0x55555712
#define HOTD_PREAMBLE_AND_BARKER_CODE 0x558f1129
#define EOTD_MAX_LEN 8
#define DUMMY_BIT_HACK
#undef DUMMY_BIT_HACK

static void eotd_rec_bit (int chan, int subchan, int slice, int raw, int future_use)
{
Expand All @@ -441,7 +444,7 @@ static void eotd_rec_bit (int chan, int subchan, int slice, int raw, int future_
H = &hdlc_state[chan][subchan][slice];

#ifdef EOTD_DEBUG
dw_printf(stderr, "chan=%d subchan=%d slice=%d raw=%d\n", chan, subchan, slice, raw);
dw_printf("chan=%d subchan=%d slice=%d raw=%d\n", chan, subchan, slice, raw);
#endif
//dw_printf ("slice %d = %d\n", slice, raw);

Expand All @@ -452,9 +455,11 @@ dw_printf(stderr, "chan=%d subchan=%d slice=%d raw=%d\n", chan, subchan, slice,

int done = 0;

if (!H->eotd_gathering && H->eotd_acc == PREAMBLE_AND_BARKER_CODE) {
if (!H->eotd_gathering &&
(H->eotd_acc == EOTD_PREAMBLE_AND_BARKER_CODE ||
H->eotd_acc == HOTD_PREAMBLE_AND_BARKER_CODE)) {
#ifdef EOTD_DEBUG
dw_printf ("Barker Code Found\n");
dw_printf ("Barker Code Found %x\n", H->eotd_acc);
#endif
H->olen = 0;
H->eotd_gathering = 1;
Expand Down