frap
frap is a pure Rust port of the Finnish/Fabulous APRS Parser
(Ham::APRS::FAP). It parses APRS
packets in TNC2/APRS-IS text format without C bindings or runtime
dependencies.
The parser accepts either UTF-8 text or raw bytes. Packet::original_bytes
always contains the exact input. Valid UTF-8 is restored in unambiguous
free-text fields after structural parsing; invalid or ambiguous non-ASCII
payload bytes are represented by ?.
use ;
let packet = parse?;
assert_eq!;
let Location = &packet.body else ;
assert_eq!;
# Ok::
let raw = b"N0CALL>APRS:>binary \x81 status";
let packet = parse?;
assert_eq!;
# Ok::
For hot paths, parse_ref borrows the input buffer for the original packet,
header, body, callsigns, and path components whenever normalization is not
needed. Convert to the original owned representation only when required:
let raw = b"2W0FWJ>APRS:!5120.00N/00300.00W>Testing";
let borrowed = parse_ref?;
assert_eq!;
let owned = borrowed.into_owned;
assert_eq!;
# Ok::
Both packet representations store decoded payload data directly in a
PacketBody variant. Position, object, item, message, weather, telemetry,
status, capability, and beacon fields therefore cannot be confused with one
another or appear in an impossible combination.
Status
The parser supports:
- TNC2/APRS-IS headers and digipeater paths
- optional strict AX.25 callsign/path validation
- uncompressed and compressed positions
- Mic-E positions, altitude, telemetry, and opt-in damaged-packet recovery
- NMEA GPRMC, GPGGA, and GPGLL positions with checksum validation
- timestamped positions, objects, and status reports with decoded timestamps
- objects and items
- messages, acknowledgements, rejects, and reply-acks
- status and station capabilities
- classic and Mic-E telemetry
- positionless, positioned, compressed, and ULTW weather reports
- DAO, PHG/PHGRA, radio range, altitude, course, and speed extensions
- generic beacon recognition
- stable, machine-readable parse errors
- message, object, timestamp, and compressed/uncompressed-position encoding
- KISS/TNC2 conversion and duplicate-detection helpers
- distance, direction, digihop, callsign, and APRS-IS passcode utilities
- an optional asynchronous APRS-IS client
The public functionality exported by FAP has a Rust equivalent. Idiomatic
names such as parse, encode_position, and mice_message are primary;
make_position, make_object, make_timestamp, and
mice_mbits_to_message are also available as compatibility names.
Encoding and frame conversion
EncodePositionOptions::compressed selects APRS base-91 position encoding;
compressed positions cannot also use ambiguity or DAO. EncodeObjectOptions
uses the same position options and creates the required UTC object timestamp.
An empty symbol selects FAP's default // symbol.
tnc2_to_kiss returns a complete, byte-stuffed KISS frame including its FEND
bytes. kiss_to_tnc2 follows FAP and accepts the content between those FEND
bytes. Both APIs use byte vectors so binary APRS information fields round-trip
without UTF-8 conversion.
Async APRS-IS client
The parser has no runtime dependencies. Enable the separate Tokio-based client only when it is needed:
[]
= { = "0.1", = ["aprs-is"] }
use Duration;
use AprsIsConnection;
# async
Development
Run the complete black-box parser suite with:
cargo test
cargo test --all-features
cargo clippy --all-targets --all-features -- -D warnings
RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps
cargo test --doc --all-features
cargo bench --bench parser
The tests live in tests/parser.rs, so cargo test --lib is not the test
command for this crate. To run only the parser integration test target, use:
cargo test --test parser
Publishing
CI runs the complete test, lint, documentation, and package checks on every
pull request and push to main. A tag whose name begins with v starts the
crates.io publishing workflow. The tag must exactly match the version in
Cargo.toml, for example v0.1.0.
Publishing uses crates.io trusted publishing, so GitHub receives a short-lived token for each run rather than storing a crates.io API token as a repository secret. After the crate's first release, configure its trusted publisher on crates.io with:
- GitHub owner:
sladeview - repository:
frap - workflow:
publish.yml - environment:
crates-io
Also create a GitHub environment named crates-io; requiring approval for that
environment is recommended. Crates.io currently requires the first version of
a new crate to be published manually before a trusted publisher can be added.
For that one-time bootstrap, authenticate locally and run:
cargo publish --dry-run --locked
cargo publish --locked
For later versions, update Cargo.toml and Cargo.lock, commit the release,
then create and push its matching tag:
git tag -s v0.2.0
git push origin v0.2.0
Real-world dataset
Large or frequently changing packet datasets belong in the git-ignored
test-data directory because committing them would permanently enlarge the
repository and its history. Callsigns and positions are expected parts of
amateur-radio transmissions and are not, by themselves, a reason to anonymize
a dataset. Before redistributing a capture, however, check its source terms and
review free-form message text, which can contain information about third
parties. Small, deliberately selected regression fixtures can be committed with
the tests.
The dataset audit test defaults to
test-data/real-world-1m.tnc2, or accepts another path through
FRAP_DATASET:
cargo test --test dataset -- --ignored --nocapture
FRAP_DATASET=/path/to/dataset.tnc2 cargo test --test dataset -- --ignored --nocapture
The audit reports parser errors by stable error code and fails if any packet causes a panic. Parse errors do not currently fail the audit, so the dataset can drive incremental compatibility work.
Capturing a dataset
The dataset-capture example uses FRAP's asynchronous APRS-IS client and writes
one TNC2 packet per line. Supply your APRS-IS callsign and passcode, the desired
packet count, and a suitably narrow APRS-IS server-side filter:
APRS_CALLSIGN=2W0FWJ APRS_PASSCODE=-1 cargo run --features aprs-is \
--example dataset-capture -- test-data/capture.tnc2 100000 'r/51.5/-3.0/100'
-1 requests an unverified, receive-only login; use the credentials and server
permitted by your APRS-IS provider. APRS_SERVER can override the default
rotate.aprs2.net:14580 server.
The recorder intentionally saves packets before parsing them, so failures remain available for compatibility work. It removes APRS-IS server comments and line terminators. The current APRS-IS API returns UTF-8 text, so a byte-exact capture that must retain invalid UTF-8 needs a raw TCP recorder instead. When retaining or sharing a dataset, record its capture period, server and filter, packet count, byte size, and checksum in a sibling manifest.
Comparing with Perl FAP
Bootstrap the pinned original Ham::APRS::FAP 1.21 module into target/, then
run the line-for-line differential comparison:
scripts/bootstrap-perl-fap
cargo run --release --example fap-diff -- test-data/real-world-1m.tnc2
For a parser-only throughput comparison, load the same dataset into memory in both runtimes and run repeated timed passes:
cargo run --release --example dataset-bench -- test-data/real-world-1m.tnc2 3
perl -Itarget/perl-fap tools/perl-fap-bench.pl test-data/real-world-1m.tnc2 3
These benchmarks exclude database export, differential-report I/O, and dataset loading. The Rust runner reports both borrowed and owned FRAP parsing; both runners report every pass and the median packet rate.
The comparator reports pass/fail agreement, error distributions, packet-type,
position, message, telemetry, and weather differences among mutual successes.
Weather comments are compared when both parsers attach a weather record.
Perl byte-string fields are normalized to FRAP's documented ASCII parser view;
exact input bytes remain available through Packet::original_bytes.
FRAP-only water-level, radiation, and battery-voltage extensions are also
inventoried even though FAP 1.21 has no corresponding output fields.
Exact packets with differing outcomes are written as hex to
target/fap-diff/outcome-mismatches.tsv. Field-presence differences are reported
directionally, and every run atomically refreshes target/fap-diff/summary.txt.
Known differences caused by FRAP's documented extensions, UTF-8 free text,
positioned-weather inline telemetry, and APRS 1.1 reply-acks are written separately to
target/fap-diff/intentional-differences.tsv.
Normalized weather-comment edit fragments are grouped by frequency in
target/fap-diff/comment-deltas.tsv so common scanner effects can be audited
without inspecting every packet individually.
Comparing with libfap
The same comparator can run against the released C port, libfap 1.5. The
bootstrap script downloads the source from the
official libfap site, verifies its
published SHA-256, and builds it locally under target/; it does not install a
system library.
scripts/bootstrap-libfap
cargo run --release --example fap-diff -- --libfap test-data/real-world-1m.tnc2
Its reports are written separately under target/libfap-diff/. Libfap is not
treated as a newer specification: version 1.5 predates FAP 1.21 and contains
known port-specific differences, so the report preserves raw mismatch totals
for diagnosis instead of making FRAP emulate them.
FRAP deliberately preserves valid partial weather readings. For example, a
direction paired with an unavailable speed (247/...) remains available as a
direction-only reading. FAP 1.21 omits both fields unless the initial wind pair
is complete, so these appear as FRAP-only field-presence differences. The same
policy preserves valid four- or five-digit pressure fields in otherwise partial
weather reports. Shorter b fragments are left in the comment rather than being
misidentified as pressure. Explicit gust fields are likewise retained in
partial reports, while field-like fragments inside words, callsigns, hostnames,
and dates (such as mtg3.eu, g8wvw, and Dec2025) remain comment text.
The s in an embedded cDDDsSSS pair is treated as wind speed rather than
snowfall. Standalone snow and luminosity markers are kept when they form weather
fields, but fragments in otherwise free-form names such as WX3in1Plus2.0,
ks5s, PL100, and DL6MM remain comments.
Temperature and humidity fields receive the same partial-report treatment.
FRAP keeps explicit t and h measurements even when malformed or unavailable
fields prevent FAP 1.21 from attaching a weather record. A one-digit h embedded
inside a word or hostname (such as dh5dy) is left as comment text rather than
being mistaken for humidity.
FRAP additionally recognizes the APRS weather extensions F (water level), X
(radiation), and V (battery voltage) at the start of weather data or directly
after another parsed weather field. This keeps explicit forms such as X111,
V135, and F....V041 while preventing values in METARs, software names, and
free-form sensor text from being reinterpreted as extensions.
Like FAP, FRAP recognizes the variable-width rain markers r, p, and P
wherever they occur in the remaining weather text. A marker followed by digits
in free-form text is therefore inherently ambiguous. FRAP retains this behavior
for compatibility; applications can consult the preserved comment and original
packet bytes when provenance matters.
FAP derives weather software identifiers after a sequence of destructive regular expression substitutions. On malformed or unusually ordered reports this can turn a delimiter fragment, numeric residue, or unconsumed weather field into a three-to-five-character software string. FRAP reports software only when its decoded remainder is itself a clean identifier, leaving ambiguous residue in the comment instead.
Inline base-91 telemetry is decoded on every positioned packet type, including
positioned weather. APRS identifies it only by a pipe-delimited 4–14 character
base-91 payload, so ordinary text such as |Digi| is syntactically
indistinguishable from a two-pair telemetry report. FRAP follows the wire
format and decodes it; applications that use free-form pipe-delimited comments
should account for that ambiguity.
Classic T# reports are decoded permissively when truncated or when a later
analog field is malformed. Valid leading channels remain available and a
tlm_inv entry is added to Packet::warnings. FAP 1.21 rejects these reports
entirely, so they account for most FRAP-only telemetry successes.
Analog values at or beyond FAP's numeric limit of ±999999 are also preserved,
with a tlm_large warning. This retains real-world frequency-like readings used
by RXTLM, TetraLogic, and RepeaterLogic packets while making the FAP compatibility
difference explicit.
Message response keywords are recognized only when followed by a valid one-to-five
character response ID; ordinary text such as ack, ack 3, or ack?= remains a
message. FRAP also implements APRS 1.1 reply-ack ({message-id}ack-id) parsing,
which FAP 1.21 lists as a TODO. The differential report therefore shows intentional
message-ID and acknowledgement differences for reply-ack packets. Other message-text
value differences are the public ASCII parser view's ? substitutions for
non-ASCII bytes; exact input remains available through Packet::original_bytes.
Licence
FRAP is distributed under the same terms as Perl 5: either the Artistic License 1.0 (Perl) or the GNU General Public License version 1 or later, at your option. See COPYRIGHT for FRAP and Ham::APRS::FAP attribution.