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
More framework.
  • Loading branch information
dtiller committed Mar 19, 2022
commit c491655edb68615ca49ec87b2ed06abec7ba9a7b
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ list(APPEND direwolf_SOURCES
dwgpsnmea.c
dwgpsd.c
mheard.c
eotd.c
)

if(LINUX)
Expand Down Expand Up @@ -317,6 +318,7 @@ list(APPEND atest_SOURCES
symbols.c
tt_text.c
textcolor.c
eotd.c
)

if(WIN32 OR CYGWIN)
Expand Down
69 changes: 69 additions & 0 deletions src/eotd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2022 David Tiller, K4DET
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//


/********************************************************************************
*
* File: eotd.c
*
* Purpose: Functions for processing received EOTD transmissions and
* converting to NMEA sentence representation.
*
* References: AIVDM/AIVDO protocol decoding by Eric S. Raymond
* https://gpsd.gitlab.io/gpsd/AIVDM.html
*
* Sample recording with about 100 messages. Test with "atest -B AIS xxx.wav"
* https://github.com/freerange/ais-on-sdr/wiki/example-data/long-beach-160-messages.wav
*
* Useful on-line decoder for AIS NMEA sentences.
* https://www.aggsoft.com/ais-decoder.htm
*
* Future? Add an interface to feed AIS data into aprs.fi.
* https://aprs.fi/page/ais_feeding
*
*******************************************************************************/

#include "direwolf.h"

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#include <string.h>

#include "textcolor.h"
#include "eotd.h"

/*-------------------------------------------------------------------
*
* Convert EOTD binary block (from HDLC frame) to NMEA sentence.
*
* In: Pointer to EOTD binary block and number of bytes.
* Out: NMEA sentence. Provide size to avoid string overflow.
*
*--------------------------------------------------------------------*/

void eotd_to_nmea (unsigned char *eotd, int eotd_len, char *nmea, int nmea_size)
{
for (int i = 0; i < eotd_len; i++) {
char temp[32];
snprintf(temp, sizeof(temp), "%d=%02x ", i, eotd[i]);
strlcpy(nmea, temp, nmea_size);
}
}
1 change: 1 addition & 0 deletions src/eotd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void eotd_to_nmea (unsigned char *ais, int ais_len, char *nema, int nema_size);
62 changes: 60 additions & 2 deletions src/hdlc_rec.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// This file is part of Dire Wolf, an amateur radio packet TNC.
////
//// This file is part of Dire Wolf, an amateur radio packet TNC.
//
// Copyright (C) 2011, 2012, 2013, 2014, 2015 John Langner, WB2OSZ
//
Expand Down Expand Up @@ -111,6 +111,10 @@ struct hdlc_state_s {
int eas_plus_found; /* "+" seen, indicating end of geographical area list. */

int eas_fields_after_plus; /* Number of "-" characters after the "+". */

uint32_t eotd_acc; /* Accumulate last recent 32 bits for EOTD. */

int eotd_gathering; /* Decoding in progress - valid frame. */
};

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

#define PREAMBLE_AND_BARKER_CODE 0x55555712
#define EOTD_MAX_LEN 8

static void eotd_rec_bit (int chan, int subchan, int slice, int raw, int future_use)
{
Expand All @@ -432,7 +438,59 @@ static void eotd_rec_bit (int chan, int subchan, int slice, int raw, int future_
* Different state information for each channel / subchannel / slice.
*/
H = &hdlc_state[chan][subchan][slice];

fprintf(stderr, "chan=%d subchan=%d slice=%d raw=%d\n", chan, subchan, slice, raw);
//dw_printf ("slice %d = %d\n", slice, raw);

// Accumulate most recent 32 bits in MSB-first order.

H->eotd_acc <<= 1;
H->eotd_acc |= raw;

int done = 0;

if (!H->eotd_gathering && H->eotd_acc == PREAMBLE_AND_BARKER_CODE) {
dw_printf ("Barker Code Found\n");
H->olen = 0;
H->eotd_gathering = 1;
H->frame_len = 0;
}
else if (H->eotd_gathering) {
H->olen++;

/* Hack to skip 'dummy' 64th bit */
if (H->olen == 7 && H->frame_len == 7) {
fprintf(stderr, "Special case!\n");
H->eotd_acc <<= 1;
H->olen++;
}

if (H->olen == 8) {
H->olen = 0;
char ch = H->eotd_acc & 0xff;
H->frame_buf[H->frame_len++] = ch;
H->frame_buf[H->frame_len] = '\0';
//dw_printf ("frame_buf = %s\n", H->frame_buf);

if (H->frame_len == EOTD_MAX_LEN) { // FIXME: look for other places with max length
done = 1;
for (int ii=0; ii < EOTD_MAX_LEN; ii++) {fprintf(stderr, "%02x ", H->frame_buf[ii]); } fprintf(stderr, "\n");
}
}
}

if (done) {
#ifdef DEBUG_E
dw_printf ("frame_buf %d = %s\n", slice, H->frame_buf);
#endif
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);

H->eotd_acc = 0;
H->eotd_gathering = 0;
H->olen = 0;
H->frame_len = 0;
}
return;
} // end eotd_rec_bit

Expand Down
8 changes: 8 additions & 0 deletions src/multi_modem.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
#include "fx25.h"
#include "version.h"
#include "ais.h"
#include "eotd.h"



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

// alevel gets in there somehow making me question why it is passed thru here.
}
else if (save_audio_config_p->achan[chan].modem_type == MODEM_EOTD) {
char nmea[300];
eotd_to_nmea (fbuf, flen, nmea, sizeof(nmea));
char monfmt[276];
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);
pp = ax25_from_text (monfmt, 1);
}
else {
pp = ax25_from_frame (fbuf, flen, alevel);
}
Expand Down