diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 581a5e2..b867457 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -278,6 +278,7 @@ list(APPEND gen_packets_SOURCES dtmf.c textcolor.c dsp.c + eotd_send.c ) add_executable(gen_packets diff --git a/src/bchapply.c b/src/bchapply.c index 80a15f4..2ce1666 100644 --- a/src/bchapply.c +++ b/src/bchapply.c @@ -63,7 +63,7 @@ printf("data_len=%d, crc_len=%d\n", data_len, crc_len); // // THIS IS THE LSB-FIRST VERSION // -fprintf(stderr, "Enter HCB+ATAD _WITH_ the parity bit intact.\n"); +fprintf(stderr, "Enter HCB+ATAD _WITH_ the parity bit intact and XOR already applied.\n"); while (1) { for (int i = 0; i < 8; i++) { int temp; diff --git a/src/eotd_send.c b/src/eotd_send.c new file mode 100644 index 0000000..635bb23 --- /dev/null +++ b/src/eotd_send.c @@ -0,0 +1,102 @@ +#include "direwolf.h" + +#include + +#include "eotd_send.h" +#include "audio.h" +#include "gen_tone.h" +#include "eotd_defs.h" + +#define EOTD_SILENCE_SAMPLES 1000 +//#define EOTD_SEND_DEBUG + +static int eotd_fs[] = {1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0}; +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 }; + +void my_tone_gen_put_bit (int chan, int bit) { + +#ifdef EOTD_SEND_DEBUG + printf("mytone bit %d\n", bit); +#endif + tone_gen_put_bit (chan, bit); +} + +void my_gen_tone_put_sample (int chan, int a, int sam) { + +#ifdef EOTD_SEND_DEBUG + printf("mysilence sample %d\n", sam); +#endif + gen_tone_put_sample (chan, a, sam); +} + +void send_preamble(int chan, char type) { + int bit = 0; + int preamble_count; + int fs_count; + int *fs; + + if (type == EOTD_TYPE_R2F) { + bit = 0; + preamble_count = 69; + fs_count = sizeof(eotd_fs) / sizeof(int); + fs = eotd_fs; + } else { + preamble_count = 456; + fs_count = sizeof(hotd_fs) / sizeof(int); + fs = hotd_fs; + } + + for (int i = 0; i < preamble_count; i++) { + my_tone_gen_put_bit (chan, bit); + bit ^= 1; + } + +#ifdef EOTD_SEND_DEBUG + printf("end-of-preamble\n"); +#endif + // send FS + for (int i = 0; i < fs_count; i++) { + my_tone_gen_put_bit (chan, fs[i]); + } + +#ifdef EOTD_SEND_DEBUG + printf("end-of-fs\n"); +#endif +} + +void send_silence(int chan) { + int a = ACHAN2ADEV(chan); + + for (int i = 0; i < EOTD_SILENCE_SAMPLES; i++) { + my_gen_tone_put_sample (chan, a, 0); + } +} + +int eotd_send_block (int chan, char *str, char type) { + + unsigned int b[EOTD_LENGTH]; + + 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); + if (status != EOTD_LENGTH) { + fprintf(stderr, "Error: expected 8, read %d", status); + return -1; + } + + send_preamble(chan, type); + + for (int i = 7; i >= 0; i--) { + int byte = b[i]; // Copy this non-destructively so we can repeat it later, per spec. + for (int j = 0; j < 8; j++) { + int bit = byte & 0x01; + byte >>= 1; + my_tone_gen_put_bit (chan, bit); + } + } + +#ifdef EOTD_SEND_DEBUG + printf("end-of-data\n"); +#endif + send_silence(chan); + + return 0; +} diff --git a/src/eotd_send.h b/src/eotd_send.h new file mode 100644 index 0000000..c331265 --- /dev/null +++ b/src/eotd_send.h @@ -0,0 +1,6 @@ +#ifndef __EOTD_SEND_H +#define __EOTD_SEND_H + +int eotd_send_block (int chan, char *str, char type); + +#endif diff --git a/src/gen_packets.c b/src/gen_packets.c index b097790..b822df4 100644 --- a/src/gen_packets.c +++ b/src/gen_packets.c @@ -76,6 +76,8 @@ #include "morse.h" #include "dtmf.h" #include "fx25.h" +#include "eotd_send.h" +#include "eotd_defs.h" /* Own random number generator so we can get */ @@ -97,6 +99,10 @@ static int audio_file_close (void); static int g_add_noise = 0; static float g_noise_level = 0; static int g_morse_wpm = 0; /* Send morse code at this speed. */ +static int g_eotd_type = 0; + +static int byte_count; /* Number of data bytes written to file. */ + /* Will be written to header when file is closed. */ static struct audio_s modem; @@ -115,6 +121,11 @@ static void send_packet (char *str) morse_send (0, str, g_morse_wpm, 100, 100); } + else if (g_eotd_type > 0) { + for (c=0; cframe_buf, 64); + // Put the XOR-ed bits back. + if (H->eotd_type == EOTD_TYPE_R2F) { + // The HCB needs to be XOR'ed with a special constant. + for (int i = 0; i < sizeof(r2f_mask); i++) { + H->frame_buf[i] ^= r2f_mask[i]; + } + } + return corrected; } @@ -515,7 +525,8 @@ 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("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); +dw_printf("%d ", raw); #endif //dw_printf ("slice %d = %d\n", slice, raw); @@ -565,7 +576,12 @@ for (int ii=0; ii < EOTD_LENGTH; ii++) {dw_printf("%02x ", H->frame_buf[ii]); } if (is_eotd_valid(H) >= 0) { alevel_t alevel = demod_get_audio_level (chan, subchan); multi_modem_process_rec_frame (chan, subchan, slice, H->frame_buf, H->frame_len, alevel, 0, 0); - } + } else { +#ifdef EOTD_DEBUG +print_bytes("BCH failed for packet (type byte appended) ", H->frame_buf, H->frame_len); +#endif + +} H->eotd_acc = 0; H->eotd_gathering = 0;