Skip to content

Commit

Permalink
Add support for GlobalTop MTK
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Jun 10, 2020
1 parent 4527cf4 commit f61a182
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pynmea2/types/proprietary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from . import tnl
from . import ubx
from . import vtx
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', '_'),
('Data', 'data', 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
)
15 changes: 15 additions & 0 deletions test/test_mtk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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_mtk220():
sentence = pynmea2.ProprietarySentence('MTK', ('220', '200', ))
assert str(sentence) == '$PMTK220,200*2C'

0 comments on commit f61a182

Please sign in to comment.