Skip to content

Commit 2ea1a18

Browse files
committed
Added support for gen_packets.
**** NOTE THAN THE MARK AND SPACE FREQUENCIES ARE BACKWARDS in gen_tone.c. Lines 228-229 correctly set f1_change_per_sample to the MARK frequency and f2_change_per_sample the space frequency. Line 383, however, sends MARK on 0 and SPACE on 1: tone_phase[chan] += dat ? f2_change_per_sample[chan] : f1_change_per_sample[chan]; As such, you have to generate packets like this: gen_packets -e R -m 1800 -s 1200 -o test.wav eotd.data EOTD input to the program consists of lines of 8 byte packets in HCB+ATAD format; i.e. the format that direwolf appends to the decoded packet. Ex: 81 b0 32 fb 31 23 73 8f A new option has been added to atest: -e type. That enables EOTD generation and the 'type' signifies 'R'ear to front or 'F'ront to rear decoding. Using "atest -B EOTD test.wav" the above packet decodes to: DECODED[1] 0:00.123 EOTD audio level = 49(30/31) [0] EOTD>APDW16:{DRREAR>FRONT:ts=2022-04-07T10:02:00.350,chain=ONLY,block=BASIC,devbat=OK,msgid=ONEWAY,unit_addr=18151,brake_status=GO(49 psig),disc_bits=f6,valve=OPERATIONAL,confirm=UPDATE,disc_bit_1=1,motion=STOPPED/NOT_MONITORED,light_batt=OK/NOT_MONITORED,light=ON,hex=81 b0 32 fb 31 23 73 8f
1 parent 971383a commit 2ea1a18

File tree

6 files changed

+149
-7
lines changed

6 files changed

+149
-7
lines changed

Diff for: src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ list(APPEND gen_packets_SOURCES
278278
dtmf.c
279279
textcolor.c
280280
dsp.c
281+
eotd_send.c
281282
)
282283

283284
add_executable(gen_packets

Diff for: src/bchapply.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ printf("data_len=%d, crc_len=%d\n", data_len, crc_len);
6363
//
6464
// THIS IS THE LSB-FIRST VERSION
6565
//
66-
fprintf(stderr, "Enter HCB+ATAD _WITH_ the parity bit intact.\n");
66+
fprintf(stderr, "Enter HCB+ATAD _WITH_ the parity bit intact and XOR already applied.\n");
6767
while (1) {
6868
for (int i = 0; i < 8; i++) {
6969
int temp;

Diff for: src/eotd_send.c

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#include "direwolf.h"
2+
3+
#include <stdio.h>
4+
5+
#include "eotd_send.h"
6+
#include "audio.h"
7+
#include "gen_tone.h"
8+
#include "eotd_defs.h"
9+
10+
#define EOTD_SILENCE_SAMPLES 1000
11+
//#define EOTD_SEND_DEBUG
12+
13+
static int eotd_fs[] = {1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0};
14+
static int hotd_fs[] = {1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1 };
15+
16+
void my_tone_gen_put_bit (int chan, int bit) {
17+
18+
#ifdef EOTD_SEND_DEBUG
19+
printf("mytone bit %d\n", bit);
20+
#endif
21+
tone_gen_put_bit (chan, bit);
22+
}
23+
24+
void my_gen_tone_put_sample (int chan, int a, int sam) {
25+
26+
#ifdef EOTD_SEND_DEBUG
27+
printf("mysilence sample %d\n", sam);
28+
#endif
29+
gen_tone_put_sample (chan, a, sam);
30+
}
31+
32+
void send_preamble(int chan, char type) {
33+
int bit = 0;
34+
int preamble_count;
35+
int fs_count;
36+
int *fs;
37+
38+
if (type == EOTD_TYPE_R2F) {
39+
bit = 0;
40+
preamble_count = 69;
41+
fs_count = sizeof(eotd_fs) / sizeof(int);
42+
fs = eotd_fs;
43+
} else {
44+
preamble_count = 456;
45+
fs_count = sizeof(hotd_fs) / sizeof(int);
46+
fs = hotd_fs;
47+
}
48+
49+
for (int i = 0; i < preamble_count; i++) {
50+
my_tone_gen_put_bit (chan, bit);
51+
bit ^= 1;
52+
}
53+
54+
#ifdef EOTD_SEND_DEBUG
55+
printf("end-of-preamble\n");
56+
#endif
57+
// send FS
58+
for (int i = 0; i < fs_count; i++) {
59+
my_tone_gen_put_bit (chan, fs[i]);
60+
}
61+
62+
#ifdef EOTD_SEND_DEBUG
63+
printf("end-of-fs\n");
64+
#endif
65+
}
66+
67+
void send_silence(int chan) {
68+
int a = ACHAN2ADEV(chan);
69+
70+
for (int i = 0; i < EOTD_SILENCE_SAMPLES; i++) {
71+
my_gen_tone_put_sample (chan, a, 0);
72+
}
73+
}
74+
75+
int eotd_send_block (int chan, char *str, char type) {
76+
77+
unsigned int b[EOTD_LENGTH];
78+
79+
int status = sscanf(str, "%x %x %x %x %x %x %x %x", b, b+1, b+2, b+3, b+4, b+5, b+6, b+7);
80+
if (status != EOTD_LENGTH) {
81+
fprintf(stderr, "Error: expected 8, read %d", status);
82+
return -1;
83+
}
84+
85+
send_preamble(chan, type);
86+
87+
for (int i = 7; i >= 0; i--) {
88+
int byte = b[i]; // Copy this non-destructively so we can repeat it later, per spec.
89+
for (int j = 0; j < 8; j++) {
90+
int bit = byte & 0x01;
91+
byte >>= 1;
92+
my_tone_gen_put_bit (chan, bit);
93+
}
94+
}
95+
96+
#ifdef EOTD_SEND_DEBUG
97+
printf("end-of-data\n");
98+
#endif
99+
send_silence(chan);
100+
101+
return 0;
102+
}

Diff for: src/eotd_send.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef __EOTD_SEND_H
2+
#define __EOTD_SEND_H
3+
4+
int eotd_send_block (int chan, char *str, char type);
5+
6+
#endif

Diff for: src/gen_packets.c

+21-4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
#include "morse.h"
7777
#include "dtmf.h"
7878
#include "fx25.h"
79+
#include "eotd_send.h"
80+
#include "eotd_defs.h"
7981

8082

8183
/* Own random number generator so we can get */
@@ -97,6 +99,10 @@ static int audio_file_close (void);
9799
static int g_add_noise = 0;
98100
static float g_noise_level = 0;
99101
static int g_morse_wpm = 0; /* Send morse code at this speed. */
102+
static int g_eotd_type = 0;
103+
104+
static int byte_count; /* Number of data bytes written to file. */
105+
/* Will be written to header when file is closed. */
100106

101107

102108
static struct audio_s modem;
@@ -115,6 +121,11 @@ static void send_packet (char *str)
115121

116122
morse_send (0, str, g_morse_wpm, 100, 100);
117123
}
124+
else if (g_eotd_type > 0) {
125+
for (c=0; c<modem.adev[0].num_channels; c++) {
126+
eotd_send_block (c, str, g_eotd_type);
127+
}
128+
}
118129
else {
119130
pp = ax25_from_text (str, 1);
120131
if (pp == NULL) {
@@ -227,7 +238,7 @@ int main(int argc, char **argv)
227238

228239
/* ':' following option character means arg is required. */
229240

230-
c = getopt_long(argc, argv, "gjJm:s:a:b:B:r:n:N:o:z:82M:X:",
241+
c = getopt_long(argc, argv, "gjJm:s:a:b:B:r:n:N:o:z:82M:X:e:",
231242
long_options, &option_index);
232243
if (c == -1)
233244
break;
@@ -462,6 +473,15 @@ int main(int argc, char **argv)
462473
usage (argv);
463474
break;
464475

476+
case 'e':
477+
g_eotd_type = optarg[0];
478+
if (g_eotd_type != EOTD_TYPE_F2R && g_eotd_type != EOTD_TYPE_R2F) {
479+
text_color_set(DW_COLOR_ERROR);
480+
dw_printf ("EOTD type must be %c or %c\n", EOTD_TYPE_F2R, EOTD_TYPE_R2F);
481+
exit(EXIT_FAILURE);
482+
}
483+
break;
484+
465485
default:
466486

467487
/* Should not be here. */
@@ -757,9 +777,6 @@ static FILE *out_fp = NULL;
757777

758778
static struct wav_header header;
759779

760-
static int byte_count; /* Number of data bytes written to file. */
761-
/* Will be written to header when file is closed. */
762-
763780

764781
static int audio_file_open (char *fname, struct audio_s *pa)
765782
{

Diff for: src/hdlc_rec.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "bch.h"
5151
#include "eotd_defs.h"
5252

53+
//#define EOTD_DEBUG
5354

5455
//#define TEST 1 /* Define for unit testing. */
5556

@@ -473,11 +474,20 @@ int is_eotd_valid(struct hdlc_state_s *H) {
473474

474475
// Note: bits are changed in-place.
475476
int corrected = apply_bch(temp_bch, bits + 1);
477+
476478
// Put back in HCB+ATAD format
477479
rotate_bits(bits + 1, temp_bits, crc_len);
478480
memcpy(bits + 1, temp_bits, crc_len * sizeof(int));
479481
bits_to_bytes(bits, H->frame_buf, 64);
480482

483+
// Put the XOR-ed bits back.
484+
if (H->eotd_type == EOTD_TYPE_R2F) {
485+
// The HCB needs to be XOR'ed with a special constant.
486+
for (int i = 0; i < sizeof(r2f_mask); i++) {
487+
H->frame_buf[i] ^= r2f_mask[i];
488+
}
489+
}
490+
481491
return corrected;
482492
}
483493

@@ -515,7 +525,8 @@ static void eotd_rec_bit (int chan, int subchan, int slice, int raw, int future_
515525
H = &hdlc_state[chan][subchan][slice];
516526

517527
#ifdef EOTD_DEBUG
518-
dw_printf("chan=%d subchan=%d slice=%d raw=%d\n", chan, subchan, slice, raw);
528+
// dw_printf("chan=%d subchan=%d slice=%d raw=%d\n", chan, subchan, slice, raw);
529+
dw_printf("%d ", raw);
519530
#endif
520531
//dw_printf ("slice %d = %d\n", slice, raw);
521532

@@ -565,7 +576,12 @@ for (int ii=0; ii < EOTD_LENGTH; ii++) {dw_printf("%02x ", H->frame_buf[ii]); }
565576
if (is_eotd_valid(H) >= 0) {
566577
alevel_t alevel = demod_get_audio_level (chan, subchan);
567578
multi_modem_process_rec_frame (chan, subchan, slice, H->frame_buf, H->frame_len, alevel, 0, 0);
568-
}
579+
} else {
580+
#ifdef EOTD_DEBUG
581+
print_bytes("BCH failed for packet (type byte appended) ", H->frame_buf, H->frame_len);
582+
#endif
583+
584+
}
569585

570586
H->eotd_acc = 0;
571587
H->eotd_gathering = 0;

0 commit comments

Comments
 (0)