首页 > 编程语言 >【听如子说】-python模块系列-AIS编解码Pyais

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

时间:2022-10-20 16:11:08浏览次数:68  
标签:编解码 Pyais python pyais dict encode message type

Pyais Module Introduce

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

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

v1 doc 弃用,看2就好

[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

相关文章

  • 零基础python 第六章
    实例1输出每日一贴(共享版)deffunction_tips():'''功能:每天输出一条励志文字'''importdatetimemot=["今天星期一:\n坚持下去不是因为我很坚强,而且因为......
  • 记录python3.7版本中 Django+celery 启动报错
     虚拟环境启动I报错Traceback(mostrecentcalllast):File"/data/.virtualenvs/cmdb/lib/python3.7/site-packages/gunicorn/arbiter.py",line589,inspawn_w......
  • python 绘制直方图代码
    importmatplotlib.pyplotaspltimportnumpyasnpx=np.arange(3)#数据集CQL=[11.17,2368.12,3347.40]PER200=[84.62,2546.82,3470.67]PER1000=[15.61,1811.55,3618.98]......
  • 使用python写docx文档
    需要使用python-docx(1)安装python-mpipinstallpython-docx(2)新建空白文档fromdocximportDocumentdocument=Document()document.save('../data/123.docx')......
  • python中多装饰器执行顺序
    python中会遇到被多个装饰器装饰,那么这几个装饰器的执行顺序是如何的呢?下面通过函数装饰器装饰函数的例子来说明下。1defsay_hi(func):2defwrapper(*args,**k......
  • python 常用的字符串处理函数
    find()  功能:检测字符串是否包含特定字符,如果包含,则返回开始的索引;否则返回-1##find()函数str='helloworld'#'wo'在字符串中print(str.find('wo'))#'wc'......
  • Python第六章
    实例一:输出每日一贴(共享版) 代码如下:deffunction_tips():'''功能:每天输出一条励志文字'''importdatetime#导入日期时间类#定义一......
  • Python第六章实例、实战
    0102  03  04    05    06   实战1     s2    s3    s4   ......
  • Python实验报告——第6章 函数
    实验报告实例01:输出每日一帖(共享版)代码如下:deffunction_tips():'''功能:每天输出一条励志文字'''importdatetime#导入日期时间类#定义......
  • python实验报告(函数)
    1.输出每日一站(共享版)  结果:   2.根据身高,体重计算BMI指数  结果:  3.根据身高,体重计算BMI指数  结果:  4.模拟结账功能———计算实付金......