Reference

On this page, there is a reference to the functions, classes and methods of the PyNGHam library, including a description of each one, and the inputs and outputs.

Main Module

class pyngham.pyngham.PyNGHam(mod=0)

PyNGHam main class.

This class is used to encode and/or decode a NGHam packet.

decode(pkt)

Decodes a NGHam packet.

Parameters:

pkt (list[int], bytearray or str) – raw NGHam packet to decode.

Returns:

The decoded data, the number of corrected errors and a list with the bit position of the errors.

Return type:

list[int], int, list[int]

decode_byte(byte)

Decodes a single byte from a NGHam packet.

This function returns the decoded packet when the complete sequence of bytes is received.

Parameters:

byte (int) – byte of a raw NGHam packet to decode.

Returns:

The decoded data, the number of corrected errors and a list with the bit position of the errors (empty data if the decoding process is not done).

Type:

list[int], int, list[int]

encode(pl, flags=0)

Encodes a sequence of bytes as a NGHam packet.

Parameters:
  • pl (list[int], bytearray or str) – Data to encode as a NGHam packet (list of integeres, byte array or string).

  • flags (int, optional) – Packet flags, default 0.

Returns:

An encoded NGHam packet.

Return type:

list[int]

class pyngham.pyngham.State(value)

Decoder states:

  • SIZE_TAG

  • SIZE_TAG_2

  • SIZE_TAG_3

  • SIZE_KNOWN

  • STATUS

  • STATUS_2

SPP Module

class pyngham.spp.PyNGHamSPP

The protocol is used to transfer data and commands between the transceiver and the serial port host.

decode(pkt)

Decodes an SPP packet.

Parameters:

pkt – is the SPP packet to decode.

Returns:

The decoded packet as a dictionary.

Return type:

dict

decode_byte(c)

Decodes a single byte from a SPP packet.

Parameters:

c (int) – is the byte from a SPP packet to decode.

Returns:

An empty dictionary while the decoding is not done yet, and a dictionay with the decoded data when the decoding is ready.

Return type:

dict

encode(pkt_type, pl)

Encodes a generic SPP packet from a given payload data. The SPP packets have the following fields:

Name

Size (Byte)

Notes

Start tag

1

Fixed as ’$’.

CRC Size

2

16-bit CRC CCITT (start=0xffff, polynomial=0x1021 reversed, Xorout=0xffff). Notice the use of little endian, as everything on this layer and up use little endian. CRC is calculated of everything except start tag and CRC itself.

Payload type

1

0x00=RF receive packet, 0x01=RF transmit packet, 0x02=Local packet, 0x03=Command.

Payload length

1

Length of payload field.

Payload

n

This is the actual payload specified by the payload type.

Parameters:
  • pkt_type (int) – The SPP packet type (SPPType.RX.value, SPPType.TX.value, SPPType.LOCAL.value or SPPType.CMD.value).

  • pl (list[int]) – The payload of the desired SPP packet.

Returns:

The encoded SPP packet.

Return type:

list[int]

encode_cmd_pkt(cmd)

Encodes a command packet.

This type of packet is used to enter commands. On the Owl VHF, this command will do the same as typing into the command-line interpreter, except the commands and replies are not terminated by LF/CR/CRLF. The table below describes what is put into the payload of the general packet format.

Name

Size (Byte)

Notes

Command

n B

Non-terminated command, 144800000”.

Parameters:

cmd (int) – A list with command content of the packet.

Returns:

The encoded SPP command packet.

Return type:

list[int]

encode_local_pkt(flags, data)

Encodes a local packet.

Packet generated by the radio (not received over the air). For example a status report. The table below describes what is put into the payload of the general packet format.

Name

Size (Byte)

Notes

Flags

1

Bit 0: NGHam extension enabled flag.

Data

n-1 B

Data to be transmitted.

Parameters:
  • flags (int) – Local packet flags (see table above).

  • data (list[int]) – The data of the local packet.

Returns:

The encoded SPP local packet.

Return type:

list[int]

encode_rx_pkt(noise_floor, rssi, symbol_errors, flags, data)

Encodes an RX packet from the given data.

Data received from RF link. Length from 4 to 223. The table below describes what is put into the payload of the general packet format.

Name

Size

Notes

Time of hour in microseconds

4

Local time of hour timestamp of the incoming packet. Wraps from 3599999999 (one step before 3600 seconds) to 0. N/A-value is 0xffffffff.

Noise floor

1

Subtract 200 to get dBm. Eg. 0x50 = -120 dBm. N/A is 0xff.

RSSI

1

Same as above.

Symbol errors

1

Number of corrected Reed-Solomon symbols.

Flags

1

Bit 0: NGHam extension enabled. If this bit is set, the data field is a valid NGHam extension packet.

Data

n-8

Received data.

Parameters:
  • noise_floor (int) – Noise floor value (see table above).

  • rssi (int) – RSSI value (see table above).

  • symbol_errors (int) – The number of corrected Reed-Solomon symbols.

  • flags (int) – RX packet flags (see table above).

  • data (list[int]) – The data of the packet.

Returns:

The encoded SPP RX packet.

Return type:

list[int]

encode_tx_pkt(flags, data)

Encodes a TX packet from the given data.

Data to be transmitted on RF link. Length from 1 to 220. The table below describes what is put into the payload of the general packet format.

Name

Size (Byte)

Notes

Flags

1

Bit 0: NGHam extension enabled flag.

Data

n-1 B

Data to be transmitted.

Parameters:
  • flags (int) – TX paket flags (see table above).

  • data (list[int]) – The data of the packet.

Returns:

The encoded SPP TX packet.

Return type:

list[int]

class pyngham.spp.SPPState(value)

States:

  • START: Decoder in start flag field

  • HEADER: Decoder in header field

  • PAYLOAD: Decoder in payload field

class pyngham.spp.SPPType(value)

Serial Port Protocol packets types:

  • RX: RF RX packet

  • TX: RF TX packet

  • LOCAL: Local packet

  • CMD: Command packet

Extension Module

class pyngham.extension.ExtPktType(value)

Extension packets types.

  • DATA: Generic data packet

  • ID: ID packet

  • STAT: Status packet

  • SIMPLEDIGI: Simple digi packet

  • POS: Position data packet

  • TOH: Time info packet

  • DEST: Destination/receiver callsign

  • CMD_REQ: Command request packet

  • CMD_REPLY: Command reply packet

  • REQUEST: Request packet

class pyngham.extension.PyNGHamExtension

Class to handle NGHam extension packets.

append_dest_pkt(pl, call_ssid)

Adds a destination extension packet to a NGHam payload.

Parameters:
  • pl (list[int]) – is the packet payload to append a destination packet.

  • call_ssid (list[int]) – 7 x 6 bit (SIXBIT DEC, which is ASCII-32 and limited to 0-64) empty characters padded with 0, 6 bit SSID.

Returns:

The given payload with the new destination extension packet.

Return type:

list[int]

append_id_pkt(pl, call_ssid, sequence)

Adds a ID extension packet to a NGHam payload.

Note:

Always first in a packet, except when resent by another station.

Parameters:
  • pl (list[int]) – is the packet payload to append an ID packet.

  • call_ssid (list[int]) – 7 x 6 bit (SIXBIT DEC, which is ASCII-32 and limited to 0-64) empty characters padded with 0, 6 bit SSID.

  • sequence (int) – is the packet sequence number, wraps around from 255 to 0.

Returns:

The given payload with the new ID extension packet.

Return type:

list[int]

append_pkt(pl, typ, data)

Appends a new extension packet to a NGHam payload.

Parameters:
  • pl (list[int]) – is the packet payload to append an extension packet.

  • typ (int) – is the type of extension packet.

  • data (list[int]) – is the content of the extension packet.

Returns:

The given payload with the extension packet.

append_pos_pkt(pl, latitude, longitude, altitude, sog, cog, hdop)

Adds a position extension packet to a NGHam payload.

Parameters:
  • pl (list[int]) – is the packet payload to append a position packet.

  • latitude (int) – Latitude in degrees * 10^7

  • longitude (int) – Longitude in degrees * 10^7

  • altitude (int) – Altitude in centimeters

  • sog (int) – Hundreds of meters per second

  • cog (int) – Tenths of degrees

  • hdop (int) – In tenths

Returns:

The given payload with the new position extension packet.

Return type:

list[int]

append_stat_pkt(pl, hw_ver, serial, sw_ver, uptime_s, voltage, temp, signal, noise, cntr_rx_ok, cntr_rx_fix, cntr_rx_err, cntr_tx)

Adds an statistic extension packet to a NGHam payload.

Parameters:
  • pl (list[int]) – is the packet payload to append an statistic packet.

  • hw_ver (int) – hardware version ID (10b for company, 6b for product).

  • serial (int) – Serial number.

  • sw_ver (int) – software version ID (4b major, 4b minor, 8b build).

  • uptime_s (int) – time in whole seconds since startup.

  • voltage (int) – input voltage in decivolts (0-25.5)

  • temp (int) – system temperature in degrees Celsius (-128 to 127).

  • signal (int) – received signal strength in dBm - 200, -200 to 54 (0xFF=N/A).

  • noise (int) – noise floor, same as above.

  • cntr_rx_ok (int) – packets successfully received.

  • cntr_rx_fix (int) – packets with corrected errors.

  • cntr_rx_err (int) – packets with uncorrectable errors.

  • cntr_tx (int) – packets sent.

Returns:

The given payload with the new statistic extension packet.

Return type:

list[int]

append_toh_pkt(pl, toh_us, toh_val)

Adds a TOH extension packet to a NGHam payload.

Parameters:
  • packet (pl is the packet payload to append a TOH) –

  • toh_us (int) – time of hour in microseconds.

  • toh_val (int) – validity.

Returns:

The given payload with the new TOH extension packet.

Return type:

list[int]

decode(pl)

Decodes all extension packets in a given NGHam payload.

Parameters:

pl (list[int]) – is the NGHam payload to decode.

Returns:

All found extension packets as a list of dictionaries.

Return type:

dict

decode_callsign(enc_callsign)

Decodes a given encoded callsign.

Parameters:

enc_callsign (list[int]) – the encoded callsign to decode.

Returns:

The decoded callsign as an string.

Return type:

str

encode_callsign(callsign, ssid)

Encodes a given callsign.

Parameters:
  • callsign (str) – is the callsign to encode (ASCII string).

  • ssid (int) – is the SSID to encode with the callsign (integer).

Returns:

The encoded callsign as a list of integers (bytes).

Return type:

list[int]

get_numpkts(d)

Gets the number of extension packets in a NGHam packet.

Parameters:

d (list[int]) – is the packet payload with extension packet(s).

Returns:

The detected number of extension packets.

Return type:

int