Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GlobalTop MTK (Work in progress) #111

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pynmea2/types/proprietary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
from . import ubx
from . import vtx
from . import nor

from . import mtk
107 changes: 107 additions & 0 deletions pynmea2/types/proprietary/mtk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# -- TRIMBLE -- #

# pylint: disable=wildcard-import,unused-wildcard-import
from ... import nmea
from ...nmea_utils import *
""" Support for proprietary messages from MediaTek recievers.
Documentation: https://cdn-shop.adafruit.com/datasheets/PMTK_A11.pdf
"""


class MTK(nmea.ProprietarySentence):
sentence_types = {}
"""
Generic MTK Message
"""
def __new__(_cls, manufacturer, data):
'''
Return the correct sentence type based on the first field
'''
sentence_type = data[0] or data[1]
name = manufacturer + sentence_type
cls = _cls.sentence_types.get(name, _cls)
return super(MTK, cls).__new__(cls)

def __init__(self, manufacturer, data):
self.sentence_type = data[0] or data[1]
super(MTK, self).__init__(manufacturer, data)


class MTK001(MTK):
"""
001 MTK_ACK
"""
fields = (
('Blank', '_'),
('Cmd', 'cmd', int),
('Flag', 'flag', int),
)


class MTK010(MTK):
"""
010 MTK_SYS_MSG
"""
fields = (
('Blank', '_'),
('Msg', 'msg', int), # 0 = UNKNOWN
# 1 = STARTUP
# 2 = Notification for host aiding EPO
# 3 = Notification for transition to Normal mode success
)


class MTK011(MTK):
"""
011 MTK_TXT_MSG
"""
fields = (
('Blank', '_'),
('Text', 'text'),
)


class MTK101(MTK):
"""
101 MTK_CMD_HOT_START
"""
fields = (
('Blank', '_'),
)


class MTK102(MTK):
"""
102 MTK_CMD_WARM_START
"""
fields = (
('Blank', '_'),
)


class MTK103(MTK):
"""
103 MTK_CMD_COLD_START
"""
fields = (
('Blank', '_'),
)


class MTK104(MTK):
"""
104 MTK_CMD_FULL_COLD_START
"""
fields = (
('Blank', '_'),
)


class MTK220(MTK):
"""
220 MTK_SET_NMEA_UPDATERATE
"""
fields = (
('Blank', '_'),
("FixInterval", "fix_interval", int), # Fix interval in milliseconds from 100 to 10,000
)
22 changes: 22 additions & 0 deletions test/test_mtk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pynmea2


def test_mtk001():
data = '$PMTK001,604,3*32'
msg = pynmea2.parse(data)
assert isinstance(msg, pynmea2.types.mtk.MTK001)
assert msg.sentence_type == '001'
assert msg.cmd == 604
assert msg.flag == 3


def test_mtk010():
data = '$PMTK010,002*2D'
msg = pynmea2.parse(data)
assert isinstance(msg, pynmea2.types.mtk.MTK010)
assert msg.msg == 2


def test_mtk220():
sentence = pynmea2.ProprietarySentence('MTK', ('220', '200', ))
assert str(sentence) == '$PMTK220,200*2C'