M0r13n / pyais

AIS message decoding and encoding in Python (AIVDM/AIVDO)
MIT License
176 stars 61 forks source link

Encoded NRZI data #138

Closed Mas313 closed 3 months ago

Mas313 commented 3 months ago

Hi, Can i get NRZI data using pyais. I want to send NRZI data to SDR and verify using tools like rtl_Ais that pyais can be used for testing AIS messages. To best of my understanding it can only generate payload and concatenate 'AVIDM' but cannot generate binary or bipolar values. The encoder outputs as shown below. Any suggestions on how to get NRZI data. Thanks

from pyais.messages import MessageType5
from pyais.encode import encode_msg
payload = MessageType5.create(mmsi="123", shipname="Titanic", callsign="TITANIC", destination="New York")
encoded = encode_msg(payload)
print(encoded)
'!AIVDO,2,1,0,A,50000Nh00001@U@4pT=@U@4pT<0000000000000000000000003QEp6ClRh0,0*70', 
'!AIVDO,2,2,0,A,00000000000,2*26'
M0r13n commented 3 months ago

@Mas313 Hey there.

To best of my understanding it can only generate payload and concatenate 'AVIDM' but cannot generate binary or bipolar values

Every message has a method to_bitarray() which returns the binary representation of the message as an array of bits. Using this array you can perform whatever transformation you like:

from pyais.messages import MessageType5
from pyais.encode import encode_msg

payload = MessageType5.create(mmsi="123", shipname="Titanic", callsign="TITANIC", destination="New York")

bits = payload.to_bitarray()
print(bits)

# NRZI
state = 0
nrzi_encoded = []
for bit in bits:
    if bit == 0:
        state = 1 - state
    nrzi_encoded.append(state)

print(nrzi_encoded)

Does this help?