Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 47 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
JT65/JT9/JT4/FT8/WSPR/FSQ Encoder Library for Arduino
=====================================================

This library very simply generates a set of channel symbols for JT65, JT9, JT4, FT8, or WSPR based on the user providing a properly formatted Type 6 message for JT65, JT9, or JT4 (which is 13 valid characters), Type 0.0 or 0.5 message for FT8 (v2.0.0 protocol) or a Type 1, Type 2, or Type 3 message for WSPR. It will also generate an arbitrary FSQ message of up to 130 characters (non-directed) or 100 characters (directed). When paired with a synthesizer that can output frequencies in fine, phase-continuous tuning steps (such as the Si5351), then a beacon or telemetry transmitter can be created which can change the transmitted characters as needed from the Arduino.
This library very simply generates a set of channel symbols for JT65, JT9, JT4, FT8, or WSPR based on the user providing a properly formatted Type 6 message for JT65, JT9, or JT4 (which is 13 valid characters), Type 0.0 or 0.5 message for FT8 (v2.0.0 protocol) or a Type 1, Type 2, or Type 3 message for WSPR. With the full packmsg path enabled (`JTENCODE_FULL_PACKMSG`, see [Message Encoding Path](#message-encoding-path-compact-vs-full-packmsg)), JT65/JT9/JT4 also accept standard messages — callsign, grid, and report in the usual WSJT-X formats (including `CQ`/`QRZ`/`DE` prefixes and `/P`-style suffixes) — which are then encoded as the corresponding standard message types instead of as free text. It will also generate an arbitrary FSQ message of up to 130 characters (non-directed) or 100 characters (directed). When paired with a synthesizer that can output frequencies in fine, phase-continuous tuning steps (such as the Si5351), then a beacon or telemetry transmitter can be created which can change the transmitted characters as needed from the Arduino.

Please feel free to use the issues feature of GitHub if you run into problems or have suggestions for important features to implement.

Expand All @@ -23,6 +23,26 @@ RAM Usage
---------
Most of the encoding functions need to manipulate multiple arrays of symbols in RAM at the same time, and therefore are quite RAM intensive. Care has been taken to put as much data into program memory as is possible, but the encoding functions still can cause problems with the low RAM microcontrollers such as the ATmegaxx8 series. If you are using these, then please be sure to call them only once when a transmit buffer needs to be created or changed, and call them separately of other subroutine calls. When using other microcontrollers that have more RAM, such as most of the ARM ICs, this won't be as much of a problem. If you see unusual freezes, that almost certainly indicates a RAM shortage.

Message Encoding Path (compact vs full packmsg)
------------------------------------------------
The library encodes JT65/JT9/JT4 messages using one of two paths, selected at compile time.

**Compact path (default)** — a simple free-text encoder: the message is uppercased and padded to 13 characters, then encoded as base-42 with the freeform flag set. This is what the library has done historically, and it is small enough to leave plenty of flash on a 32 KB Arduino Uno (~18 KB total for the JT9/JT4 path). It does **not** implement the standard message types (standard callsign/grid, CQ/QRZ/DE prefixes and suffixes, grid/report packing) — everything is transmitted as free text, so decoding tools see the message as free-form.

**Full path** — a faithful C++ port of WSJT-X `packjt.f90` (`packmsg` and helpers): type detection, callsign packing (`CQ`/`QRZ`/`DE` and Swaziland/Guinea workarounds), 339-entry prefix and 12-entry suffix tables, Maidenhead grid and report packing (including the extended `KA`/`LA` report range), free-text fallback, and `entail`. It costs ~7.7 KB of extra flash (~25.8 KB total for JT9/JT4 on a Uno) and ~120 B of extra RAM. Verified bit-exact against the WSJT-X Fortran reference (28/28 messages, itype/dat/entail). Enable it by defining `JTENCODE_FULL_PACKMSG` in the sketch's build flags (see below for the exact options per toolchain).

Note: enabling the full path changes the encoded symbols for standard messages relative to the compact path — the compact path sets the freeform flag unconditionally, so its symbols are not what WSJT-X would transmit. Decoded messages are unaffected by the encoder choice. JT65 uses the same `packmsg` port with the 12-byte `dat` block fed directly to the Reed-Solomon encoder (no `entail`); JT9/JT4 feed it through `entail`.

The macro must be defined at compile time for the library itself — a `#define` in the sketch does **not** propagate to the library's translation units. The cleanest options are:

- **PlatformIO** — `build_flags = -DJTENCODE_FULL_PACKMSG` in `platformio.ini`
- **arduino-cli** — `--build-property "build.extra_flags=-DJTENCODE_FULL_PACKMSG"`
- **Arduino IDE** — no built-in build-flag UI; use PlatformIO/arduino-cli, or copy the library into your sketch folder and uncomment the `#define` in `src/JTEncode.cpp`

Note on the bundled example sketch: it uses a free-text message (`N0CALL AA00`), which encodes identically in both paths (the full path only changes standard messages). On an Arduino Uno the example still builds only with the compact path — at 28.4 KB it would overflow the 32 KB limit with the full path (~36.3 KB). On the Uno R4 WiFi the example builds with both paths (~72 KB basic / ~77 KB full, both comfortable). Use the compact path on an Uno; enable the full path on devices with more flash.

If the build fails because of the full path, the default compact path is still in use — simply remove the flag.

WSPR Messages
-------------
JTEncode includes support for all three WSPR message types. A brief listing of the three types is given below:
Expand Down Expand Up @@ -171,7 +191,10 @@ Public Methods
* Takes an arbitrary message of up to 13 allowable characters and returns
* a channel symbol table.
*
* message - Plaintext Type 6 message.
* message - Plaintext Type 6 message (compact path, the default). With
* JTENCODE_FULL_PACKMSG enabled, standard WSJT-X messages are also accepted
* (callsign, grid, and report in the usual formats) and are encoded as the
* corresponding standard message type instead of as free text.
* symbols - Array of channel symbols to transmit returned by the method.
* Ensure that you pass a uint8_t array of at least size JT65_SYMBOL_COUNT to the method.
*
Expand All @@ -185,7 +208,10 @@ Public Methods
* Takes an arbitrary message of up to 13 allowable characters and returns
* a channel symbol table.
*
* message - Plaintext Type 6 message.
* message - Plaintext Type 6 message (compact path, the default). With
* JTENCODE_FULL_PACKMSG enabled, standard WSJT-X messages are also accepted
* (callsign, grid, and report in the usual formats) and are encoded as the
* corresponding standard message type instead of as free text.
* symbols - Array of channel symbols to transmit returned by the method.
* Ensure that you pass a uint8_t array of at least size JT9_SYMBOL_COUNT to the method.
*
Expand All @@ -200,7 +226,10 @@ Public Methods
* Takes an arbitrary message of up to 13 allowable characters and returns
* a channel symbol table.
*
* message - Plaintext Type 6 message.
* message - Plaintext Type 6 message (compact path, the default). With
* JTENCODE_FULL_PACKMSG enabled, standard WSJT-X messages are also accepted
* (callsign, grid, and report in the usual formats) and are encoded as the
* corresponding standard message type instead of as free text.
* symbols - Array of channel symbols to transmit returned by the method.
* Ensure that you pass a uint8_t array of at least size JT4_SYMBOL_COUNT to the method.
*
Expand Down Expand Up @@ -324,6 +353,20 @@ Changelog
---------
* v1.4.3

* Full packmsg port verified bit-exact against the WSJT-X Fortran
reference (28/28 messages: `itype`, `dat`, and `entail` all match).
Fixes applied: (1) `grid2deg` now copies all 6 grid characters (was
truncating to 5, dropping the 6th and corrupting extended reports);
(2) the `c3` fill loop maps NUL bytes to blanks (was leaving NUL in
the 4th field of blank grids, forcing free-text fallback);
(3) `getpfx1` falls through to the generic prefix/suffix path when
the pfx/sfx tables miss (was returning early with a stale callsign),
and keeps a copy of the original callsign for the generic path;
(4) the full path now honors the Fortran early exits
(`nv2a >= 4`, `text1`, `text2` -> free text) and the add-on-grid
`k1 < 0 || k2 < 0 || k1*k2 != 0` check. The bundled example builds
on the Uno (compact, 28.4 KB) and Uno R4 WiFi (compact ~72.2 KB /
full ~77.3 KB); the Uno full-path build overflows by design.
* Fix the JT4 encoder to produce frames that match WSJT-X. The previous
implementation was wrong in several ways: it used a 207-symbol
`JT4_SYMBOL_COUNT` (the JT4 frame is 206 symbols), it filled a
Expand Down
4 changes: 4 additions & 0 deletions examples/Si5351JTDemo/Si5351JTDemo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
// (a Type 6 message) in JT65, JT9, JT4, a type 0.0 or type 0.5 FT8 message,
// a FSQ message, or a standard Type 1 message in WSPR.
//
// With the full packmsg path enabled (JTENCODE_FULL_PACKMSG), the JT
// modes also accept standard WSJT-X messages (callsign/grid/report),
// encoded as the corresponding standard message type instead of free text.
//
// Connect a momentary push button to pin 12 to use as the
// transmit trigger. Get fancy by adding your own code to trigger
// off of the time from a GPS or your PC via virtual serial.
Expand Down
20 changes: 20 additions & 0 deletions src/JTEncode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <crc14.h>
#include <generator.h>
#include <nhash.h>
#include "upstream_packmsg.h"

#include <string.h>
#include <ctype.h>
Expand Down Expand Up @@ -796,6 +797,14 @@ void JTEncode::wspr_message_prep(char * call, char * loc, int8_t dbm)

void JTEncode::jt65_bit_packing(char * message, uint8_t * c)
{
#ifdef JTENCODE_FULL_PACKMSG
// Full path — faithful port of WSJT-X packmsg. JT65 uses the 12 6-bit
// data bytes directly (no entail — RS encodes dat[0..11]).
uint8_t dat[12];
int itype = 6;
UpstreamPackmsg::upstream_packmsg(message, dat, itype);
memcpy(c, dat, 12);
#else
uint32_t n1, n2, n3;

// Find the N values
Expand Down Expand Up @@ -836,10 +845,20 @@ void JTEncode::jt65_bit_packing(char * message, uint8_t * c)
c[9] = ((n2 & 0x0003) << 4) + ((n3 >> 12) & 0x000f);
c[10] = (n3 >> 6) & 0x003f;
c[11] = n3 & 0x003f;
#endif
}

void JTEncode::jt9_bit_packing(char * message, uint8_t * c)
{
#ifdef JTENCODE_FULL_PACKMSG
// Full path — faithful port of WSJT-X packmsg (type detection, callsign
// packing, prefix/suffix handling, grid/report packing, freeform fallback).
// Costs ~11 KB extra flash — only enable on devices with plenty of flash.
uint8_t dat[12];
int itype = 6;
UpstreamPackmsg::upstream_packmsg(message, dat, itype);
UpstreamPackmsg::upstream_entail(dat, c);
#else
uint32_t n1, n2, n3;

// Find the N values
Expand Down Expand Up @@ -896,6 +915,7 @@ void JTEncode::jt9_bit_packing(char * message, uint8_t * c)
c[10] = 0;
c[11] = 0;
c[12] = 0;
#endif
}

void JTEncode::wspr_bit_packing(uint8_t * c)
Expand Down
21 changes: 21 additions & 0 deletions src/JTEncode.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@
#define WSPR_SYMBOL_COUNT 162
#define FT8_SYMBOL_COUNT 79

// ---------------------------------------------------------------------------
// Message encoding path
// ---------------------------------------------------------------------------
// By default the library uses the compact free-text message encoder
// (base-42 with the freeform flag). This is small enough to leave plenty of
// flash on a 32 KB Arduino Uno.
//
// Defining JTENCODE_FULL_PACKMSG (e.g. in platformio.ini or in the sketch's
// build flags) selects a faithful C++ port of WSJT-X packjt.f90 — type
// detection, callsign packing, prefix/suffix handling, Maidenhead grid and
// report packing, and free-text fallback. It costs ~7.7 KB of extra flash
// (~25.8 KB total for JT9/JT4 on a Uno) and ~120 B of extra RAM, so leave
// it off on tight devices and enable it on devices with plenty of flash
// (e.g. Uno R4 WiFi, Mega, ESP32).
//
// Note: the full path changes the encoded symbols for standard messages
// (JT9/JT4/JT65) relative to the compact path. JT65/JT9 decoding is
// unaffected by the encoder choice, but exact symbol comparisons against
// the compact encoder will not match.
// ---------------------------------------------------------------------------

#define JT65_ENCODE_COUNT 63
#define JT9_ENCODE_COUNT 69
#define FT8_ENCODE_COUNT 77
Expand Down
Loading
Loading