Pyais Module Introduce
pyais一个简单实用的ais编解码模块
工作中需要和ais打交道,在摸鱼的过程中发现了一个牛逼的模块,对ais编解码感兴趣的可以拿项目学习一下,或者运用到你的项目中!
[v2] 仓库(folked)(https://github%20url%20:https://github.com/Iamruzi/pyais)
现在github拉取的代码是v2,所以例子参考直接查看github的readme就好了,贴的第一个链接是v1与v2仓库的文档
模块特点:
AIS消息的编解码。
100% 纯Python。
支持AIVDM / AIVDO消息。
支持单消息,文件和TCP/UDP套接字。
首先直接pip安装模块
!pip install pyais
编码例子
from pyais import encode_dict
# Every message needs at least a MMSI and a message-type (1-27)
data = {'mmsi': 12345, 'type': 1}
# Because larger payloads may need to split over several fragment sentences
# `encode_dict` always returns a list of parts (even if the message has a single part)
encoded = encode_dict(data)
看看编码效果:
encoded
['!AIVDO,1,1,,A,E000h>@00000000000000000000000000000000000000000000000000000,4*73']
from pyais.encode import encode_dict
data = {
'course': 219.3,
'lat': 37.802,
'lon': -122.341,
'mmsi': '366053209',
'type': 1,
}
# This will create a type 1 message for the MMSI 366053209 with lat, lon and course values specified above
encoded = encode_dict(data, radio_channel="B", talker_id="AIVDM")[0]
解码例子
from pyais import decode
decoded = decode(b"!AIVDM,1,1,,B,15NG6V0P01G?cFhE`R2IU?wn28R>,0*05")
print(decoded)
MessageType1(msg_type=1, repeat=0, mmsi=367380120, status=<NavigationStatus.UnderWayUsingEngine: 0>, turn=None, speed=0.1, accuracy=False, lon=-122.404333, lat=37.806948, course=245.2, heading=511, second=59, maneuver=0, spare_1=b'\x00', raim=True, radio=34958)
from pyais import decode
parts = [
b"!AIVDM,2,1,4,A,55O0W7`00001L@gCWGA2uItLth@DqtL5@F22220j1h742t0Ht0000000,0*08",
b"!AIVDM,2,2,4,A,000000000000000,2*20",
]
# Decode a multipart message using decode
decoded = decode(*parts)
print(decoded)
MessageType5(msg_type=5, repeat=0, mmsi=368060190, ais_version=2, imo=0, callsign='WDK4954', shipname='P/V_GOLDEN_GATE', ship_type=50, to_bow=14, to_stern=7, to_port=4, to_starboard=2, epfd=0, month=0, day=0, hour=24, minute=60, draught=0.0, destination='', dte=False, spare_1=b'\x00')
其他例子
参看仓库的readme,本博客就是一个介绍,很强大,可认真学习源码,使用时候请注意开源协议,注意引用来源,尊重作者。
gui使用 (todo,有时间在二次开发)
基于gooey快速开发GUI application
首先,咱们安装一下gooey,这是一个快速生成GUI程序的一个库,好用简单。
!pip install Gooey
未完,待续...
可执行程序打包
未完,待续...
标签:编解码,Pyais,python,pyais,dict,encode,message,type From: https://www.cnblogs.com/iamruzi/p/16810211.html