Skip to content

Commit c491655

Browse files
committed
More framework.
1 parent 709f229 commit c491655

File tree

5 files changed

+140
-2
lines changed

5 files changed

+140
-2
lines changed

Diff for: src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ list(APPEND direwolf_SOURCES
8585
dwgpsnmea.c
8686
dwgpsd.c
8787
mheard.c
88+
eotd.c
8889
)
8990

9091
if(LINUX)
@@ -317,6 +318,7 @@ list(APPEND atest_SOURCES
317318
symbols.c
318319
tt_text.c
319320
textcolor.c
321+
eotd.c
320322
)
321323

322324
if(WIN32 OR CYGWIN)

Diff for: src/eotd.c

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
// This file is part of Dire Wolf, an amateur radio packet TNC.
3+
//
4+
// Copyright (C) 2022 David Tiller, K4DET
5+
//
6+
// This program is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 2 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// This program is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
//
19+
20+
21+
/********************************************************************************
22+
*
23+
* File: eotd.c
24+
*
25+
* Purpose: Functions for processing received EOTD transmissions and
26+
* converting to NMEA sentence representation.
27+
*
28+
* References: AIVDM/AIVDO protocol decoding by Eric S. Raymond
29+
* https://gpsd.gitlab.io/gpsd/AIVDM.html
30+
*
31+
* Sample recording with about 100 messages. Test with "atest -B AIS xxx.wav"
32+
* https://github.com/freerange/ais-on-sdr/wiki/example-data/long-beach-160-messages.wav
33+
*
34+
* Useful on-line decoder for AIS NMEA sentences.
35+
* https://www.aggsoft.com/ais-decoder.htm
36+
*
37+
* Future? Add an interface to feed AIS data into aprs.fi.
38+
* https://aprs.fi/page/ais_feeding
39+
*
40+
*******************************************************************************/
41+
42+
#include "direwolf.h"
43+
44+
#include <stdio.h>
45+
#include <stdlib.h>
46+
#include <assert.h>
47+
#include <ctype.h>
48+
#include <string.h>
49+
50+
#include "textcolor.h"
51+
#include "eotd.h"
52+
53+
/*-------------------------------------------------------------------
54+
*
55+
* Convert EOTD binary block (from HDLC frame) to NMEA sentence.
56+
*
57+
* In: Pointer to EOTD binary block and number of bytes.
58+
* Out: NMEA sentence. Provide size to avoid string overflow.
59+
*
60+
*--------------------------------------------------------------------*/
61+
62+
void eotd_to_nmea (unsigned char *eotd, int eotd_len, char *nmea, int nmea_size)
63+
{
64+
for (int i = 0; i < eotd_len; i++) {
65+
char temp[32];
66+
snprintf(temp, sizeof(temp), "%d=%02x ", i, eotd[i]);
67+
strlcpy(nmea, temp, nmea_size);
68+
}
69+
}

Diff for: src/eotd.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void eotd_to_nmea (unsigned char *ais, int ais_len, char *nema, int nema_size);

Diff for: src/hdlc_rec.c

+60-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//
2-
// This file is part of Dire Wolf, an amateur radio packet TNC.
1+
////
2+
//// This file is part of Dire Wolf, an amateur radio packet TNC.
33
//
44
// Copyright (C) 2011, 2012, 2013, 2014, 2015 John Langner, WB2OSZ
55
//
@@ -111,6 +111,10 @@ struct hdlc_state_s {
111111
int eas_plus_found; /* "+" seen, indicating end of geographical area list. */
112112

113113
int eas_fields_after_plus; /* Number of "-" characters after the "+". */
114+
115+
uint32_t eotd_acc; /* Accumulate last recent 32 bits for EOTD. */
116+
117+
int eotd_gathering; /* Decoding in progress - valid frame. */
114118
};
115119

116120
static struct hdlc_state_s hdlc_state[MAX_CHANS][MAX_SUBCHANS][MAX_SLICERS];
@@ -423,6 +427,8 @@ a good modem here and providing a result when it is received.
423427
*
424428
***********************************************************************************/
425429

430+
#define PREAMBLE_AND_BARKER_CODE 0x55555712
431+
#define EOTD_MAX_LEN 8
426432

427433
static void eotd_rec_bit (int chan, int subchan, int slice, int raw, int future_use)
428434
{
@@ -432,7 +438,59 @@ static void eotd_rec_bit (int chan, int subchan, int slice, int raw, int future_
432438
* Different state information for each channel / subchannel / slice.
433439
*/
434440
H = &hdlc_state[chan][subchan][slice];
441+
435442
fprintf(stderr, "chan=%d subchan=%d slice=%d raw=%d\n", chan, subchan, slice, raw);
443+
//dw_printf ("slice %d = %d\n", slice, raw);
444+
445+
// Accumulate most recent 32 bits in MSB-first order.
446+
447+
H->eotd_acc <<= 1;
448+
H->eotd_acc |= raw;
449+
450+
int done = 0;
451+
452+
if (!H->eotd_gathering && H->eotd_acc == PREAMBLE_AND_BARKER_CODE) {
453+
dw_printf ("Barker Code Found\n");
454+
H->olen = 0;
455+
H->eotd_gathering = 1;
456+
H->frame_len = 0;
457+
}
458+
else if (H->eotd_gathering) {
459+
H->olen++;
460+
461+
/* Hack to skip 'dummy' 64th bit */
462+
if (H->olen == 7 && H->frame_len == 7) {
463+
fprintf(stderr, "Special case!\n");
464+
H->eotd_acc <<= 1;
465+
H->olen++;
466+
}
467+
468+
if (H->olen == 8) {
469+
H->olen = 0;
470+
char ch = H->eotd_acc & 0xff;
471+
H->frame_buf[H->frame_len++] = ch;
472+
H->frame_buf[H->frame_len] = '\0';
473+
//dw_printf ("frame_buf = %s\n", H->frame_buf);
474+
475+
if (H->frame_len == EOTD_MAX_LEN) { // FIXME: look for other places with max length
476+
done = 1;
477+
for (int ii=0; ii < EOTD_MAX_LEN; ii++) {fprintf(stderr, "%02x ", H->frame_buf[ii]); } fprintf(stderr, "\n");
478+
}
479+
}
480+
}
481+
482+
if (done) {
483+
#ifdef DEBUG_E
484+
dw_printf ("frame_buf %d = %s\n", slice, H->frame_buf);
485+
#endif
486+
alevel_t alevel = demod_get_audio_level (chan, subchan);
487+
multi_modem_process_rec_frame (chan, subchan, slice, H->frame_buf, H->frame_len, alevel, 0, 0);
488+
489+
H->eotd_acc = 0;
490+
H->eotd_gathering = 0;
491+
H->olen = 0;
492+
H->frame_len = 0;
493+
}
436494
return;
437495
} // end eotd_rec_bit
438496

Diff for: src/multi_modem.c

+8
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#include "fx25.h"
104104
#include "version.h"
105105
#include "ais.h"
106+
#include "eotd.h"
106107

107108

108109

@@ -342,6 +343,13 @@ void multi_modem_process_rec_frame (int chan, int subchan, int slice, unsigned c
342343

343344
// alevel gets in there somehow making me question why it is passed thru here.
344345
}
346+
else if (save_audio_config_p->achan[chan].modem_type == MODEM_EOTD) {
347+
char nmea[300];
348+
eotd_to_nmea (fbuf, flen, nmea, sizeof(nmea));
349+
char monfmt[276];
350+
snprintf (monfmt, sizeof(monfmt), "EOTD>%s%1d%1d:{%c%c%s", APP_TOCALL, MAJOR_VERSION, MINOR_VERSION, USER_DEF_USER_ID, USER_DEF_TYPE_AIS, nmea);
351+
pp = ax25_from_text (monfmt, 1);
352+
}
345353
else {
346354
pp = ax25_from_frame (fbuf, flen, alevel);
347355
}

0 commit comments

Comments
 (0)