From f61a182d30b43af9240752eb643c853fa31504ec Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Wed, 10 Jun 2020 11:50:48 +0100 Subject: [PATCH] Add support for GlobalTop MTK --- pynmea2/types/proprietary/__init__.py | 2 +- pynmea2/types/proprietary/mtk.py | 107 ++++++++++++++++++++++++++ test/test_mtk.py | 15 ++++ 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 pynmea2/types/proprietary/mtk.py create mode 100644 test/test_mtk.py diff --git a/pynmea2/types/proprietary/__init__.py b/pynmea2/types/proprietary/__init__.py index 3aae55a..c187d89 100644 --- a/pynmea2/types/proprietary/__init__.py +++ b/pynmea2/types/proprietary/__init__.py @@ -8,4 +8,4 @@ from . import tnl from . import ubx from . import vtx - +from . import mtk diff --git a/pynmea2/types/proprietary/mtk.py b/pynmea2/types/proprietary/mtk.py new file mode 100644 index 0000000..055e2b1 --- /dev/null +++ b/pynmea2/types/proprietary/mtk.py @@ -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 + ) diff --git a/test/test_mtk.py b/test/test_mtk.py new file mode 100644 index 0000000..e50ec5c --- /dev/null +++ b/test/test_mtk.py @@ -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'