Skip to content

Commit 4211b5f

Browse files
authored
feat: adds property full_name to message type 21 (#163)
* feat: adds property full_name to message type 21 * chore: drops python 3.8 from CI replacing it with 3.13
1 parent bb69849 commit 4211b5f

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

.github/workflows/main.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
15+
python: ['3.9', '3.10', '3.11', '3.12', '3.13']
1616
os: ['ubuntu-latest']
1717
steps:
1818
- uses: actions/checkout@master
1919

2020
- name: Setup python
21-
uses: actions/setup-python@v1
21+
uses: actions/setup-python@v5
2222
with:
2323
python-version: ${{ matrix.python }}
24-
architecture: x64
2524

2625
- name: Install requirements
2726
run: pip install -r requirements.txt

CHANGELOG.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
====================
22
pyais CHANGELOG
33
====================
4+
-------------------------------------------------------------------------------
5+
Version 2.8.4 26 Jan 2025
6+
-------------------------------------------------------------------------------
7+
* closes #161: https://github.com/M0r13n/pyais/issues/161
8+
* adds property `full_name` to message type 21
49
-------------------------------------------------------------------------------
510
Version 2.8.3 20 Dec 2024
611
-------------------------------------------------------------------------------

pyais/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pyais.tracker import AISTracker, AISTrack
66

77
__license__ = 'MIT'
8-
__version__ = '2.8.3'
8+
__version__ = '2.8.4'
99
__author__ = 'Leon Morten Richter'
1010

1111
__all__ = (

pyais/messages.py

+12
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,18 @@ class MessageType21(Payload):
13291329
spare_1 = bit_field(1, bytes, default=b'')
13301330
name_ext = bit_field(88, str, default='')
13311331

1332+
@functools.cached_property
1333+
def full_name(self) -> str:
1334+
"""The name field is up to 20 characters of 6-bit ASCII. If this field
1335+
is full (has no trailing @ characters) the decoder should interpret
1336+
the Name Extension field later in the message (no more than 14 6-bit
1337+
characters) and concatenate it to this one to obtain the full name."""
1338+
if self.name:
1339+
if self.name_ext:
1340+
return f"{self.name}{self.name_ext}"
1341+
return str(self.name)
1342+
return ""
1343+
13321344

13331345
@attr.s(slots=True)
13341346
class MessageType22Addressed(Payload):

tests/test_decode.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ def test_to_dict_non_enum(self):
961961
"aid_type": 25,
962962
"assigned": None,
963963
"epfd": 7,
964+
'full_name': 'STDB CUT 2',
964965
"lat": -32.004333,
965966
"lon": 115.691833,
966967
"mmsi": 995036013,
@@ -986,7 +987,6 @@ def test_decode_and_merge(self):
986987
decoded = NMEAMessage(msg)
987988

988989
d = decoded.decode_and_merge(enum_as_int=True)
989-
990990
self.assertEqual(
991991
d,
992992
{
@@ -1001,6 +1001,7 @@ def test_decode_and_merge(self):
10011001
"fill_bits": 2,
10021002
"frag_cnt": 1,
10031003
"frag_num": 1,
1004+
'full_name': 'STDB CUT 2',
10041005
"lat": -32.004333,
10051006
"lon": 115.691833,
10061007
"mmsi": 995036013,
@@ -1041,6 +1042,7 @@ def test_decode_and_merge(self):
10411042
"fill_bits": 2,
10421043
"frag_cnt": 1,
10431044
"frag_num": 1,
1045+
'full_name': 'STDB CUT 2',
10441046
"lat": -32.004333,
10451047
"lon": 115.691833,
10461048
"mmsi": 995036013,
@@ -1768,3 +1770,9 @@ def test_decode_with_empty_payload(self):
17681770
)
17691771

17701772
self.assertEqual(str(err.exception), '!AIVDM,1,1,0,A,,0*16')
1773+
1774+
def test_decode_type_21_full_name(self):
1775+
raw = b"!AIVDM,1,1,,B,E>jHDL1W73nWaanah7S39T7a2h;wror=@5nL`A2AISd002CQ1PDS@0,4*39"
1776+
decoded = decode(raw)
1777+
1778+
assert decoded.full_name == "NNG-OSS-S OFFSHORE WINDFARM"

0 commit comments

Comments
 (0)