Пример #1
0
def test_encode_payload_error_radio():
    with unittest.TestCase().assertRaises(ValueError) as err:
        encode_payload({'mmsi': 123456}, radio_channel="C")

    assert str(err.exception) == "radio_channel must be any of ['A', 'B']"

    with unittest.TestCase().assertRaises(ValueError) as err:
        encode_payload({'mmsi': 123456}, radio_channel=None)

    assert str(err.exception) == "radio_channel must be any of ['A', 'B']"
Пример #2
0
def test_encode_payload_invalid_talker_id():
    with unittest.TestCase().assertRaises(ValueError) as err:
        encode_payload({'mmsi': 123456}, talker_id="AIDDD")

    assert str(err.exception) == "talker_id must be any of ['AIVDM', 'AIVDO']"

    with unittest.TestCase().assertRaises(ValueError) as err:
        encode_payload({'mmsi': 123456}, talker_id=None)

    assert str(err.exception) == "talker_id must be any of ['AIVDM', 'AIVDO']"
Пример #3
0
def test_ship_name_too_lon():
    msg = MessageType5.create(mmsi="123", shipname="Titanic Titanic Titanic")
    encoded = encode_payload(msg)
    assert encoded[
        0] == "!AIVDO,2,1,,A,50000Nh000000000001@U@4pT>1@U@4pT>1@U@40000000000000000000000,2*56"
    assert encoded[1] == "!AIVDO,2,2,,A,0000000000,2*26"
Пример #4
0
def test_lon_too_large():
    msg = MessageType1.create(mmsi="123", lon=1 << 30)
    encoded = encode_payload(msg)
    assert encoded[0] == "!AIVDO,1,1,,A,10000Nh000Owwwv0000000000000,0*7D"
Пример #5
0
def test_mmsi_too_long():
    msg = MessageType1.create(mmsi=1 << 35)
    encoded = encode_payload(msg)
    assert encoded[0] == "!AIVDO,1,1,,A,1?wwwwh000000000000000000000,0*72"
Пример #6
0
from pyais.encode import MessageType5, encode_payload

from pyais.encode import encode_dict

data = {
    'course': 219.3,
    'lat': 37.802,
    'lon': -122.341,
    'mmsi': '366053209',
    'type': 1
}
encoded = encode_dict(data, radio_channel="B", talker_id="AIVDM")[0]

# It is also possible to create messages directly and pass them to `encode_payload`
payload = MessageType5.create(mmsi="123",
                              shipname="Titanic",
                              callsign="TITANIC",
                              destination="New York")
encoded = encode_payload(payload)
print(encoded)