Skip to content

JaskRendix/pyarinc429

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyARINC429

PyARINC429 is a maintained fork of the original work by Jason Hodge:
https://github.com/aeroneous/PyARINC429

The library provides Python types for encoding and decoding ARINC 429 words:

  • BCD
  • BNR
  • Discrete fields
  • Mixed BCD/discrete and BNR/discrete fields
  • Bit‑field extraction and validation
  • Parity computation
  • Label bit‑reversal
  • Optional label metadata
  • A builder for constructing words

The library targets Python 3.12 and uses type annotations.

Installation

git clone https://github.com/yourusername/PyARINC429
cd PyARINC429
pip install .

Install test dependencies:

pip install .[test]

Run tests:

pytest

Package structure

arinc429/
    word.py
    bitfields.py
    errors.py
    builder.py
    definitions.py
    datatypes/
        base.py
        bcd.py
        bnr.py
        discrete.py

API Reference

Word

Represents a 32‑bit ARINC 429 word.
Parity is recomputed when any bit‑field is written.

Properties:

  • label — octal label (0o000–0o377), bit‑reversed on write
  • sdi — Source/Destination Identifier (2 bits)
  • data — bits 11–29 (19 bits)
  • ssm — Sign/Status Matrix (2 bits)
  • parity — computed from bits 1–31
  • parity_type — ODD_PARITY or EVEN_PARITY
  • parity_ok — parity check result
  • raw — underlying integer value

Methods:

  • get_bit_field(lsb, msb)
  • set_bit_field(lsb, msb, value)
  • from_int(value, parity_type)
  • to_int()
  • copy()
  • with_fields(label=..., sdi=..., data=..., ssm=...)
  • as_dict()

Parity notes:

  • parity_type controls whether the word uses odd or even parity. The library
  • parity_type controls whether the word uses odd or even parity. The library computes and updates the parity bit automatically whenever a bit field is written (via set_bit_field). Use parity_ok to validate the stored parity against the computed value. Word.validate() performs a parity check and will raise if the parity bit does not match the configured parity_type.

WordBuilder parity:

  • Use WordBuilder.parity_type(Word.EVEN_PARITY) to fluently set parity when constructing words.

Data field integer semantics:

  • Conversions using int(...) on data-field objects now return the encoded integer payload (the on-wire integer), while float(...)/str(...) and the decoded property continue to expose the semantic decoded value. This makes int(BNR|BCD|Discrete) safe to pass into set_bit_field and aligns the types across data-field classes.

Label metadata:

  • definitions.py exposes LabelDefinition and sample equipment dictionaries (EQUIP_ADC, EQUIP_IRS). These provide optional metadata (name, type, resolution, unit) that can be used by higher-level decoding helpers. The package does not automatically apply LabelDefinition when decoding words — use the metadata as guidance for which DataFieldType (BNR, BCD, Discrete) to use when interpreting the data and ssm fields.

WordBuilder

Fluent builder for constructing words:

from arinc429.builder import WordBuilder

w = (
    WordBuilder()
    .label(0o123)
    .sdi(1)
    .data(0x55AA)
    .ssm(2)
    .build()
)

BCD

Constructor:

BCD(value, resolution)

Attributes:

  • decoded
  • encoded
  • resolution
  • sign

Methods:

  • decode(bcd_value, bcd_sign, resolution)
  • copy()
  • with_resolution(new_resolution)
  • as_dict()

BNR

Constructor:

BNR(value, resolution)

Attributes:

  • decoded
  • encoded
  • resolution

Methods:

  • decode(bnr_value, bit_length, resolution)
  • copy()
  • with_resolution(new_resolution)
  • as_dict()

Discrete

Constructor:

Discrete(value)

Attributes:

  • decoded
  • encoded

Methods:

  • decode(value)
  • copy()
  • as_dict()

definitions

Optional label metadata:

LabelDefinition(name, type, resolution, unit=None)
EQUIP_ADC
EQUIP_IRS

loader.Arinc615Packetizer

Splits a byte stream into ARINC 429 words using control labels.

williamsburg.WilliamsburgTransmitter

Encodes a byte stream into Williamsburg block‑transfer words.

williamsburg.WilliamsburgReceiver

Reassembles Williamsburg frames into a byte stream.

Examples

BCD

word = arinc429.Word()
word.label = 0o1
encoded = arinc429.BCD(121.5, resolution=0.1)
word.set_bit_field(11, 29, encoded)
decoded = arinc429.BCD.decode(word.data, word.ssm, 0.1)

BNR

word = arinc429.Word()
word.label = 0o2
encoded = arinc429.BNR(90, 0.043945313)
word.set_bit_field(13, 29, encoded)
word.set_bit_field(11, 12, arinc429.Discrete(1))
decoded = arinc429.BNR.decode(
    word.get_bit_field(bnr_field.lsb, bnr_field.msb),
    17,
    0.043945313
)

Discrete

word = arinc429.Word()
word.label = 0o3
encoded = arinc429.Discrete(6)
word.set_bit_field(11, 13, encoded)
decoded = arinc429.Discrete.decode(word.data)

Williamsburg (SOF/DATA/EOF block transfer)

The package exports both WilliamsburgTransmitter and WilliamsburgReceiver at the package root for convenience. These helpers implement a simple SOF/DATA/EOF block transfer framing for packing small byte streams into ARINC 429 words.

Example (transmit + receive):

from arinc429 import WilliamsburgTransmitter, WilliamsburgReceiver

tx = WilliamsburgTransmitter()
words = tx.encode(b"HELLO")

rx = WilliamsburgReceiver()
result = None
for w in words:
    out = rx.process_word(w)
    if out is not None:
        result = out

assert result == b"HELLO"

Decoding with label metadata:

from arinc429 import Word
from arinc429.definitions import EQUIP_ADC, decode_word

w = Word()
w.label = 0o203  # Pressure Altitude in EQUIP_ADC
# assume `w.data` contains encoded BNR for 100 feet
decoded = decode_word(w, EQUIP_ADC)
if decoded is not None:
    data_field, definition = decoded
    print(definition.name, float(data_field))
else:
    # handle missing metadata gracefully
    print("No label metadata; decode manually using BNR/BCD/Discrete")

Or using the Word helper:

from arinc429 import Word
from arinc429.definitions import EQUIP_ADC

w = Word()
try:
    decoded = w.decode_by_label(EQUIP_ADC)
except KeyError:
    # Missing label metadata
    decoded = None

if decoded:
    print(float(decoded))

Using Word.validate() without raising exceptions:

w = Word()
errors = w.validate(raise_on_error=False)
if errors:
    print("Validation issues:", errors)

About

ARINC 429 word handling in Python with BNR, BCD, discrete fields, Williamsburg framing, and ARINC 615 packetization.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages