【听如子说】-python模块系列-AIS编解码Pyais

Pyais Module Introduce

pyais一个简单实用的ais编解码模块

工作中需要和ais打交道,在摸鱼的过程中发现了一个牛逼的模块,对ais编解码感兴趣的可以拿项目学习一下,或者运用到你的项目中!

v1 doc 弃用,看2就好

这是我folk的 v2

现在github拉取的代码是v2,所以例子参考直接查看github的readme就好了,贴的第一个链接是v1与v2仓库的文档

模块特点

AIS消息的编解码。

100% 纯Python。

支持AIVDM / AIVDO消息。

支持单消息,文件和TCP/UDP套接字。

1. 首先直接pip安装模块

!pip install pyais

2. 编码例子

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]

3. 解码例子

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')

4. 其他例子

参看仓库的readme,本博客就是一个介绍,很强大,可认真学习源码,使用时候请注意开源协议,注意引用来源,尊重作者。

5.gui使用 (todo,有时间在二次开发)

5.1 基于gooey快速开发GUI application

首先,咱们安装一下gooey,这是一个快速生成GUI程序的一个库,好用简单。

!pip install Gooey

未完,待续…

5.2 可执行程序打包

未完,待续…

  • 4
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值