Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fa49b6a

Browse files
committedApr 4, 2022
Starting to look like a real project.
1 parent 07209b5 commit fa49b6a

File tree

9 files changed

+258
-678
lines changed

9 files changed

+258
-678
lines changed
 

‎src/atest.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ int main (int argc, char *argv[])
280280
else if (strcasecmp(optarg, "EAS") == 0) {
281281
B_opt = 23456; // See special case below.
282282
}
283+
else if (strcasecmp(optarg, "EOTD") == 0) {
284+
B_opt = 34567;
285+
}
283286
else {
284287
B_opt = atoi(optarg);
285288
}
@@ -475,6 +478,12 @@ int main (int argc, char *argv[])
475478
my_audio_config.achan[0].space_freq = 1563; // Actually 1562.5 - logic 0.
476479
strlcpy (my_audio_config.achan[0].profiles, "D", sizeof(my_audio_config.achan[0].profiles));
477480
}
481+
else if (my_audio_config.achan[0].baud == 34567) {
482+
my_audio_config.achan[0].modem_type = MODEM_EOTD;
483+
my_audio_config.achan[0].baud = 1200;
484+
my_audio_config.achan[0].mark_freq = 1200;
485+
my_audio_config.achan[0].space_freq = 1800;
486+
}
478487
else {
479488
my_audio_config.achan[0].modem_type = MODEM_SCRAMBLE;
480489
my_audio_config.achan[0].mark_freq = 0;

‎src/bch.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* BCH processing, library-style. Copyright (2022) David E. Tiller, K4DET
2+
This file was adapted from a program written by Robert Morelos-Zaragoza
3+
(robert@spectra.eng.hawaii.edu) whose original Copyright appears below.
4+
*/
15
/*
26
* File: bch3.c
37
* Title: Encoder/decoder for binary BCH codes in C (Version 3.1)
@@ -147,7 +151,7 @@ int init_bch(bch_t *bch, int m, int length, int t) {
147151
*
148152
* alpha=2 is the primitive element of GF(2**m)
149153
*/
150-
register int i, mask;
154+
register int mask;
151155

152156
bch->alpha_to = malloc(n * sizeof(int));
153157
bch->index_of = malloc(n * sizeof(int));
@@ -339,7 +343,7 @@ int apply_bch(const bch_t *bch, int *recd)
339343
{
340344
register int i, j, u, q, t2, count = 0, syn_error = 0;
341345
int elp[1026][1024], d[1026], l[1026], u_lu[1026], s[1025];
342-
int root[200], loc[200], err[1024], reg[201];
346+
int root[200], loc[200], reg[201];
343347

344348
t2 = 2 * bch->t;
345349

‎src/bch3a.c

Lines changed: 0 additions & 620 deletions
This file was deleted.

‎src/bchapply.c

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
#include "bch.h"
4+
5+
#define SHOW_BYTES
6+
7+
int test(bch_t *bch, char *msg, int *bits, int length) {
8+
int corrected = 0;
9+
int temp_bits[length];
10+
uint8_t bytes[8];
11+
12+
memcpy(temp_bits, bits, length * sizeof(int));
13+
#ifdef SHOW_BYTES
14+
bits_to_bytes(temp_bits, bytes, length);
15+
print_bytes(msg, bytes, 8);
16+
#else
17+
print_bits(msg, temp_bits, length);
18+
#endif
19+
corrected = apply_bch(bch, temp_bits);
20+
21+
if (corrected >= 0) {
22+
printf("corrected %d ", corrected);
23+
#ifdef SHOW_BYTES
24+
bits_to_bytes(temp_bits, bytes, length);
25+
printf("CORR ");
26+
print_bytes(msg, bytes, 8);
27+
#else
28+
print_bits(msg, temp_bits, length);
29+
#endif
30+
printf("\n");
31+
} else {
32+
printf("invalid.\n");
33+
}
34+
35+
return corrected >= 0;
36+
}
37+
38+
int main(int argc, char **argv) {
39+
bch_t bch;
40+
uint8_t bytes[8];
41+
int m, length, t;
42+
int data_len, crc_len;
43+
44+
45+
if (argc != 4) {
46+
fprintf(stderr, "Expecting 3 arguments.\n");
47+
return -1;
48+
}
49+
50+
sscanf(argv[1], "%d", &m);
51+
sscanf(argv[2], "%d", &length);
52+
sscanf(argv[3], "%d", &t);
53+
54+
int orig_bits[length+1];
55+
56+
init_bch(&bch, m, length, t);
57+
data_len = bch.k;
58+
crc_len = bch.length - bch.k;
59+
60+
printf("m=%d, length=%d, n=%d, k=%d, t=%d\n", bch.m, bch.length, bch.n, bch.k, bch.t);
61+
printf("data_len=%d, crc_len=%d\n", data_len, crc_len);
62+
63+
//
64+
// THIS IS THE LSB-FIRST VERSION
65+
//
66+
fprintf(stderr, "Enter HCB+ATAD _WITH_ the parity bit intact.\n");
67+
while (1) {
68+
for (int i = 0; i < 8; i++) {
69+
int temp;
70+
int status = scanf("%x ", &temp);
71+
bytes[i] = temp;
72+
if (status == EOF) {
73+
return 0;
74+
}
75+
76+
if (status != 1) {
77+
fprintf(stderr, "Error: %d", status);
78+
}
79+
printf("%0x ", bytes[i]);
80+
}
81+
printf("\n");
82+
83+
int temp[length];
84+
85+
// HCB + ATAD
86+
bytes_to_bits(bytes, orig_bits, length+1);
87+
memcpy(temp, orig_bits+1, length * sizeof(int));
88+
print_bits("atad: ", temp + crc_len, data_len);
89+
printf("\n");
90+
print_bits("hcb: ", temp, crc_len);
91+
printf("\n");
92+
93+
test(&bch, "HCB+ATAD: ", temp, length);
94+
95+
// ATAD+HCB
96+
bytes_to_bits(bytes, orig_bits, length+1);
97+
swap_format(orig_bits+1, temp, crc_len, length);
98+
print_bits("atad: ", temp, data_len);
99+
printf("\n");
100+
print_bits("hcb: ", temp+data_len, crc_len);
101+
printf("\n");
102+
test(&bch, "ATAD+HCB: ", temp, length);
103+
104+
// DATA + BCH
105+
bytes_to_bits(bytes, orig_bits, length+1);
106+
rotate_bits(orig_bits+1, temp, length);
107+
print_bits("data: ", temp, data_len);
108+
printf("\n");
109+
print_bits("bch: ", temp+data_len, crc_len);
110+
printf("\n");
111+
test(&bch, "DATA+BCH: ", temp, length);
112+
113+
// BCH+DATA
114+
int swap[length];
115+
bytes_to_bits(bytes, orig_bits, length+1);
116+
rotate_bits(orig_bits+1, temp, length);
117+
// now DATA+BCH
118+
swap_format(temp, swap, data_len, length);
119+
// now BCH + DATA
120+
print_bits("data: ", swap + crc_len, data_len);
121+
printf("\n");
122+
print_bits("bch: ", swap, crc_len);
123+
printf("\n");
124+
test(&bch, "BCH+DATA: ", swap, length);
125+
126+
int rot[length];
127+
// DATA + HCB
128+
bytes_to_bits(bytes, orig_bits, length+1);
129+
memcpy(rot+data_len, orig_bits + 1, crc_len * sizeof(int));
130+
rotate_bits(orig_bits+1+crc_len, temp, data_len);
131+
memcpy(rot, temp, data_len * sizeof(int));
132+
print_bits("data: ", rot, data_len);
133+
printf("\n");
134+
print_bits("hcb: ", rot+data_len, crc_len);
135+
printf("\n");
136+
// Now DATA+HCB
137+
test(&bch, "DATA+HCB: ", rot, length);
138+
139+
// ATAD+BCH
140+
bytes_to_bits(bytes, orig_bits, length+1);
141+
// h+a
142+
memcpy(rot, orig_bits+1+crc_len, data_len * sizeof(int));
143+
rotate_bits(orig_bits+1, temp, crc_len);
144+
memcpy(rot+data_len, temp, crc_len * sizeof(int));
145+
// Now ATAD+BCH
146+
print_bits("atad: ", rot, data_len);
147+
printf("\n");
148+
print_bits("bch: ", rot+data_len, crc_len);
149+
printf("\n");
150+
test(&bch, "ATAD+BCH: ", rot, length);
151+
152+
// HCB+DATA
153+
bytes_to_bits(bytes, orig_bits, length+1);
154+
memcpy(rot, orig_bits+1, crc_len * sizeof(int));
155+
rotate_bits(orig_bits+1+crc_len, temp, data_len);
156+
memcpy(rot+crc_len, temp, data_len * sizeof(int));
157+
print_bits("data: ", rot+crc_len, data_len);
158+
printf("\n");
159+
print_bits("hcb: ", rot, crc_len);
160+
printf("\n");
161+
// Now HCB+DATA
162+
test(&bch, "HCB+DATA: ", rot, length);
163+
164+
// BCH+ATAD
165+
bytes_to_bits(bytes, orig_bits, length+1);
166+
memcpy(rot+crc_len, orig_bits+1+crc_len, data_len * sizeof(int));
167+
rotate_bits(orig_bits+1, temp, crc_len);
168+
memcpy(rot, temp, crc_len * sizeof(int));
169+
print_bits("atad: ", rot + crc_len, data_len);
170+
printf("\n");
171+
print_bits("bch: ", rot, crc_len);
172+
printf("\n");
173+
// Now BCH+ATAD
174+
test(&bch, "BCH+ATAD: ", rot, length);
175+
}
176+
}

‎src/direwolf.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,6 @@ int main (int argc, char *argv[])
768768
audio_config.achan[0].baud = 1200;
769769
audio_config.achan[0].mark_freq = 1200;
770770
audio_config.achan[0].space_freq = 1800;
771-
// strlcpy (audio_config.achan[0].profiles, "D", sizeof(audio_config.achan[0].profiles));
772771
}
773772
else {
774773
audio_config.achan[0].modem_type = MODEM_SCRAMBLE;

‎src/eotd_defs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef __EOTD_DEFS
2+
#define __EOTD_DEFS
3+
#define EOTD_LENGTH 8
4+
5+
#define EOTD_PREAMBLE_AND_BARKER_CODE 0x48eaaaaa00000000ULL
6+
#define EOTD_PREAMBLE_MASK 0xffffffff00000000ULL
7+
8+
#define HOTD_PREAMBLE_AND_BARKER_CODE 0x9488f1aa00000000ULL
9+
#define HOTD_PREAMBLE_MASK 0xffffffff00000000ULL
10+
11+
#define EOTD_TYPE_F2R 'F'
12+
#define EOTD_TYPE_R2F 'R'
13+
14+
#endif

‎src/hdlc_rec.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@
5555

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

58-
#undef EOTD_DEBUG
59-
60-
61-
6258
/*
6359
* Minimum & maximum sizes of an AX.25 frame including the 2 octet FCS.
6460
*/
@@ -418,6 +414,9 @@ int is_eotd_valid(struct hdlc_state_s *H) {
418414
419415
The apply_bch funtion requires the packet in int[63] format, with the bits arranged
420416
in either BCH+ATAD or ATAD+BCH format. Very odd. We'll use the first one.
417+
418+
The HCB for R2F packets must be XOR-ed with 0EED4 - since we have a leading dummy bit,
419+
we XOR with 0EED4 >> 1.
421420
*/
422421
static uint8_t r2f_mask[] = {0x07, 0x76, 0xa0 };
423422
static bch_t *bch_r2f = NULL;
@@ -459,11 +458,9 @@ int is_eotd_valid(struct hdlc_state_s *H) {
459458
} else {
460459
temp_bch = bch_r2f;
461460
// The HCB needs to be XOR'ed with a special constant.
462-
print_bytes("IN BYTES: ", H->frame_buf, H->frame_len);printf("\n");
463461
for (int i = 0; i < sizeof(r2f_mask); i++) {
464462
H->frame_buf[i] ^= r2f_mask[i];
465463
}
466-
print_bytes("XOR BYTES: ", H->frame_buf, H->frame_len);printf("\n");
467464
}
468465

469466
int crc_len = temp_bch->n - temp_bch->k;
@@ -473,17 +470,13 @@ print_bytes("XOR BYTES: ", H->frame_buf, H->frame_len);printf("\n");
473470
// +1 is to skip the dummy/parity bit.
474471
rotate_bits(bits + 1 , temp_bits, crc_len);
475472
memcpy(bits + 1, temp_bits, crc_len * sizeof(int));
476-
print_bits("BCH+ATAD : ", bits, 64);printf("\n");
477473

478474
// Note: bits are changed in-place.
479475
int corrected = apply_bch(temp_bch, bits + 1);
480-
printf("Corrected %d\n", corrected);
481476
// Put back in HCB+ATAD format
482477
rotate_bits(bits + 1, temp_bits, crc_len);
483478
memcpy(bits + 1, temp_bits, crc_len * sizeof(int));
484-
print_bits("COR BITS: ", bits, 64);printf("\n");
485479
bits_to_bytes(bits, H->frame_buf, 64);
486-
print_bytes("COR BYTES: ", H->frame_buf, H->frame_len);printf("\n");
487480

488481
return corrected;
489482
}

‎src/mkpkts.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎src/pkttest.c

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,60 @@
11
#include <stdio.h>
2+
#include <strings.h>
23
#include "bch.h"
4+
#include "eotd.h"
5+
#include "eotd_defs.h"
6+
7+
void dump(uint8_t *bytes, char type) {
8+
unsigned char eotd[9];
9+
for (int i = 0; i < 8; i++) {
10+
eotd[i] = bytes[i] & 0xff;
11+
}
12+
eotd[8] = type;
13+
// Slice packet
14+
char buffer[512];
15+
eotd_to_text(eotd, 9, buffer, sizeof(buffer));
16+
printf("%s\n", buffer);
17+
};
18+
19+
void rotate_bytes(uint8_t *src, uint8_t *dest, int count) {
20+
for (int i = 0; i < count; i++) {
21+
dest[count - i - 1] = rotate_byte(src[i]);
22+
}
23+
}
324

425
int main(int argc, char **argv) {
526
bch_t bch;
6-
int bytes[8];
27+
uint8_t bytes[8];
728
int bits[63];
29+
int m, length, t;
30+
int count = 0;
31+
int rev = 0;
32+
char type = EOTD_TYPE_R2F;
33+
834

9-
init_bch(&bch, 6, 63, 3);
10-
#ifdef ARGS
11-
if (argc != 9) {
12-
fprintf(stderr, "Expecting 8 arguments.\n");
35+
if (argc < 5) {
36+
fprintf(stderr, "Expecting 4+ arguments - m, length, t, type (F or R) and optionally rev to reverse the input bytes.\n");
1337
return -1;
1438
}
1539

16-
for (int i = 0; i < 8; i++) {
17-
sscanf(argv[i + 1], "%x", bytes + i);
40+
sscanf(argv[1], "%d", &m);
41+
sscanf(argv[2], "%d", &length);
42+
sscanf(argv[3], "%d", &t);
43+
sscanf(argv[4], "%c", &type);
44+
45+
if (argc > 5) {
46+
if (strcasecmp(argv[5], "rev") == 0) {
47+
rev = 1;
48+
}
1849
}
19-
#else
50+
51+
init_bch(&bch, m, length, t);
52+
2053
while (1) {
2154
for (int i = 0; i < 8; i++) {
22-
int status = scanf("%x ", bytes + i);
55+
int t;
56+
int status = scanf("%x ", &t);
57+
bytes[i] = t;
2358
if (status == EOF) {
2459
return 0;
2560
}
@@ -28,41 +63,15 @@ int main(int argc, char **argv) {
2863
fprintf(stderr, "Error: %d", status);
2964
}
3065
}
31-
#endif
32-
// UNEEDED
33-
// swap_format(bits, 45, 63);
34-
bytes_to_bits(bytes, bits, 63);
35-
int corrected = apply_bch(&bch, bits);
36-
if (corrected >= 0) {
37-
#ifdef DEBUG
38-
printf("%d corrected\n", corrected);
39-
for (int i = 0; i < 8; i++) {
40-
printf("%02x ", bytes[i]);
66+
if (rev) {
67+
uint8_t temp[8];
68+
rotate_bytes(bytes, temp, 8);
69+
memcpy(bytes, temp, 8);
4170
}
42-
printf("\n");
43-
#endif
44-
bits_to_bytes(bits, bytes, 63);
45-
for (int i = 0; i < 8; i++) {
46-
printf("%02x ", bytes[i]);
47-
}
48-
// Slice packet
4971

50-
printf("chain=%1x,",(bytes[0] >> 6) & 0x03);
51-
printf("devst=%1x,",(bytes[0] >> 4) & 0x03);
52-
printf("msgid=%1x,",(bytes[0] >> 1) & 0x07);
53-
printf("uaddr=%03x,",((bytes[0] & 0x01) << 16) | (bytes[1] << 8) | (bytes[2]));
54-
printf("bpres=%d,",(bytes[3] >> 1) & 0x07f);
55-
printf("dbit1=%02x,",((bytes[3] & 0x01) << 7) | ((bytes[4] >> 1) & 0x7f));
56-
printf("confm=%x,",(bytes[5] >> 7) & 0x01);
57-
printf("dbit2=%x,",(bytes[5] >> 6) & 0x01);
58-
printf("motdt=%x,",(bytes[5] >> 5) & 0x01);
59-
printf("ltbat=%x,",(bytes[5] >> 4) & 0x01);
60-
printf("ltsta=%x",(bytes[5] >> 3) & 0x01);
61-
printf("\n");
62-
}
63-
#ifndef ARGS
72+
printf("%04d,", count++);
73+
dump(bytes, type);
6474
}
65-
#endif
6675

6776
return 0;
6877
}

0 commit comments

Comments
 (0)
Please sign in to comment.