From 46b7632ad8e4e2d9b3330f0da8f1d88701e072d1 Mon Sep 17 00:00:00 2001 From: Cort Buffington Date: Mon, 24 Oct 2016 06:33:55 -0500 Subject: [PATCH] Progress --- constants.py | 84 +++++++++++++++++++++++++++++++++++---- hb_router.py | 2 +- qr.py | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 8 deletions(-) mode change 100644 => 100755 constants.py create mode 100755 qr.py diff --git a/constants.py b/constants.py old mode 100644 new mode 100755 index db34de4..c7bf42f --- a/constants.py +++ b/constants.py @@ -1,20 +1,90 @@ +#!/usr/bin/env python +# +# This work is licensed under the Creative Attribution-NonCommercial-ShareAlike +# 3.0 Unported License.To view a copy of this license, visit +# http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to +# Creative Commons, 444 Castro Street, Suite 900, Mountain View, +# California, 94041, USA. + +from __future__ import print_function + from bitarray import bitarray +# Does anybody read this stuff? There's a PEP somewhere that says I should do this. +__author__ = 'Cortney T. Buffington, N0MJS' +__copyright__ = 'Copyright (c) 2016 Cortney T. Buffington, N0MJS and the K0USY Group' +__credits__ = '' +__license__ = 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported' +__maintainer__ = 'Cort Buffington, N0MJS' +__email__ = 'n0mjs@me.com' + +# Sync patterns used for LC and Voice Burst A packets BS_VOICE_SYNC = bitarray() BS_DATA_SYNC = bitarray() - BS_VOICE_SYNC.frombytes(b'\x75\x5F\xD7\xDF\x75\xF7') BS_DATA_SYNC.frombytes(b'\xDF\xF5\x7D\x75\xDF\x5D') +SYNC = { + 'BS_VOICE': BS_VOICE_SYNC, + 'BS_DATA': BS_DATA_SYNC +} + # Precomputed EMB values, where CC always = 1, and PI always = 0 -BURST_B_EMB = bitarray('0001001110010001') -BURST_C_EMB = bitarray('0001011101110100') -BURST_D_EMB = bitarray('0001011101110100') -BURST_E_EMB = bitarray('0001010100000111') -BURST_F_EMB = bitarray('0001000111100010') +EMB = { + 'BURST_B': bitarray('0001001110010001'), + 'BURST_C': bitarray('0001011101110100'), + 'BURST_D': bitarray('0001011101110100'), + 'BURST_E': bitarray('0001010100000111'), + 'BURST_F': bitarray('0001000111100010') +} + +# Precomputed Slot Type values where CC always = 1 +SLOT_TYPE = { + 'PI_HEAD': bitarray('00010000001101100111'), + 'VOICE_LC_HEAD': bitarray('00010001101110001100'), + 'VOICE_LC_TERM': bitarray('00010010101001011001'), + 'CSBK': bitarray('00010011001010110010'), + 'MBC_HEAD': bitarray('00010100100111110000'), + 'MBC_CONT': bitarray('00010101000100011011'), + 'DATA_HEAD': bitarray('00010110000011001110'), + '1/2_DATA': bitarray('00010111100000100101'), + '3/4_DATA': bitarray('00011000111010100001'), + 'IDLE': bitarray('00011001011001001010'), + '1/1_DATA': bitarray('00011010011110011111'), + 'RES_1': bitarray('00011011111101110100'), + 'RES_2': bitarray('00011100010000110110'), + 'RES_3': bitarray('00011101110011011101'), + 'RES_4': bitarray('00011110110100001000'), + 'RES_5': bitarray('00011111010111100011') +} + +# LC infor for first 3 Bytes: +# Byte 1: PF (1),Res(1),FLCO(6) -- Byte 2: FID(8) -- Byte 3: Service Options(8) +LC_VOICE = { + 'FLCO-GRP': bitarray('00000000'), + 'FLCO-USR': bitarray('00000011'), + 'FID-GENC': bitarray('00000000'), + 'FID-MOTO': bitarray('00010000'), + 'SVC-OVCM': bitarray('00100000'), + 'SVC-NONE': bitarray('00000000') +} ''' EMB: CC(4b), PI(1b), LCSS(2b), EMB Parity(9b - QR 16,7,5) Slot Type: CC(4b), DataType(4), Slot Type Parity(12b - ) -''' \ No newline at end of file +''' + +#------------------------------------------------------------------------------ +# Used to execute the module directly to run built-in tests +#------------------------------------------------------------------------------ + +if __name__ == '__main__': + + from binascii import b2a_hex as h + from time import time + from pprint import pprint + + pprint(SYNC) + pprint(EMB) + pprint(SLOT_TYPE) \ No newline at end of file diff --git a/hb_router.py b/hb_router.py index ce75af4..2486fbe 100755 --- a/hb_router.py +++ b/hb_router.py @@ -72,7 +72,7 @@ class routerMASTER(HBMASTER): def __init__(self, *args, **kwargs): HBMASTER.__init__(self, *args, **kwargs) - self._last_stream_id + self._last_stream_id = '' self.embedded_lc_rx = [0,0,0,0] self.embedded_lc_tx = [0,0,0,0] self.embedded_lc = '' diff --git a/qr.py b/qr.py new file mode 100755 index 0000000..e6ba72f --- /dev/null +++ b/qr.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python +# +# This work is licensed under the Creative Attribution-NonCommercial-ShareAlike +# 3.0 Unported License.To view a copy of this license, visit +# http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to +# Creative Commons, 444 Castro Street, Suite 900, Mountain View, +# California, 94041, USA. + +from __future__ import print_function +from bitarray import bitarray + +# Does anybody read this stuff? There's a PEP somewhere that says I should do this. +__author__ = 'Cortney T. Buffington, N0MJS' +__copyright__ = 'Copyright (c) 2016 Cortney T. Buffington, N0MJS and the K0USY Group' +__credits__ = 'Jonathan Naylor, G4KLX who many parts of this were thankfully borrowed from' +__license__ = 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported' +__maintainer__ = 'Cort Buffington, N0MJS' +__email__ = 'n0mjs@me.com' + + +ENCODE_1676 = ( + 0x0000, 0x0273, 0x04E5, 0x0696, 0x09C9, 0x0BBA, 0x0D2C, 0x0F5F, 0x11E2, 0x1391, 0x1507, 0x1774, + 0x182B, 0x1A58, 0x1CCE, 0x1EBD, 0x21B7, 0x23C4, 0x2552, 0x2721, 0x287E, 0x2A0D, 0x2C9B, 0x2EE8, + 0x3055, 0x3226, 0x34B0, 0x36C3, 0x399C, 0x3BEF, 0x3D79, 0x3F0A, 0x411E, 0x436D, 0x45FB, 0x4788, + 0x48D7, 0x4AA4, 0x4C32, 0x4E41, 0x50FC, 0x528F, 0x5419, 0x566A, 0x5935, 0x5B46, 0x5DD0, 0x5FA3, + 0x60A9, 0x62DA, 0x644C, 0x663F, 0x6960, 0x6B13, 0x6D85, 0x6FF6, 0x714B, 0x7338, 0x75AE, 0x77DD, + 0x7882, 0x7AF1, 0x7C67, 0x7E14, 0x804F, 0x823C, 0x84AA, 0x86D9, 0x8986, 0x8BF5, 0x8D63, 0x8F10, + 0x91AD, 0x93DE, 0x9548, 0x973B, 0x9864, 0x9A17, 0x9C81, 0x9EF2, 0xA1F8, 0xA38B, 0xA51D, 0xA76E, + 0xA831, 0xAA42, 0xACD4, 0xAEA7, 0xB01A, 0xB269, 0xB4FF, 0xB68C, 0xB9D3, 0xBBA0, 0xBD36, 0xBF45, + 0xC151, 0xC322, 0xC5B4, 0xC7C7, 0xC898, 0xCAEB, 0xCC7D, 0xCE0E, 0xD0B3, 0xD2C0, 0xD456, 0xD625, + 0xD97A, 0xDB09, 0xDD9F, 0xDFEC, 0xE0E6, 0xE295, 0xE403, 0xE670, 0xE92F, 0xEB5C, 0xEDCA, 0xEFB9, + 0xF104, 0xF377, 0xF5E1, 0xF792, 0xF8CD, 0xFABE, 0xFC28, 0xFE5B) + +DECODE_1576 = ( + 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x4020, 0x0008, 0x0009, 0x000A, 0x000B, + 0x000C, 0x000D, 0x2081, 0x2080, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0C00, 0x0016, 0x0C02, + 0x0018, 0x0120, 0x001A, 0x0122, 0x4102, 0x0124, 0x4100, 0x4101, 0x0020, 0x0021, 0x0022, 0x4004, + 0x0024, 0x4002, 0x4001, 0x4000, 0x0028, 0x0110, 0x1800, 0x1801, 0x002C, 0x400A, 0x4009, 0x4008, + 0x0030, 0x0108, 0x0240, 0x0241, 0x0034, 0x4012, 0x4011, 0x4010, 0x0101, 0x0100, 0x0103, 0x0102, + 0x0105, 0x0104, 0x1401, 0x1400, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x4060, + 0x0048, 0x0049, 0x0301, 0x0300, 0x004C, 0x1600, 0x0305, 0x0304, 0x0050, 0x0051, 0x0220, 0x0221, + 0x3000, 0x4200, 0x3002, 0x4202, 0x0058, 0x1082, 0x1081, 0x1080, 0x3008, 0x4208, 0x2820, 0x1084, + 0x0060, 0x0061, 0x0210, 0x0211, 0x0480, 0x0481, 0x4041, 0x4040, 0x0068, 0x2402, 0x2401, 0x2400, + 0x0488, 0x3100, 0x2810, 0x2404, 0x0202, 0x0880, 0x0200, 0x0201, 0x0206, 0x0884, 0x0204, 0x0205, + 0x0141, 0x0140, 0x0208, 0x0209, 0x2802, 0x0144, 0x2800, 0x2801, 0x0080, 0x0081, 0x0082, 0x0A00, + 0x0084, 0x0085, 0x2009, 0x2008, 0x0088, 0x0089, 0x2005, 0x2004, 0x2003, 0x2002, 0x2001, 0x2000, + 0x0090, 0x0091, 0x0092, 0x1048, 0x0602, 0x0C80, 0x0600, 0x0601, 0x0098, 0x1042, 0x1041, 0x1040, + 0x2013, 0x2012, 0x2011, 0x2010, 0x00A0, 0x00A1, 0x00A2, 0x4084, 0x0440, 0x0441, 0x4081, 0x4080, + 0x6000, 0x1200, 0x6002, 0x1202, 0x6004, 0x2022, 0x2021, 0x2020, 0x0841, 0x0840, 0x2104, 0x0842, + 0x2102, 0x0844, 0x2100, 0x2101, 0x0181, 0x0180, 0x0B00, 0x0182, 0x5040, 0x0184, 0x2108, 0x2030, + 0x00C0, 0x00C1, 0x4401, 0x4400, 0x0420, 0x0421, 0x0422, 0x4404, 0x0900, 0x0901, 0x1011, 0x1010, + 0x0904, 0x2042, 0x2041, 0x2040, 0x0821, 0x0820, 0x1009, 0x1008, 0x4802, 0x0824, 0x4800, 0x4801, + 0x1003, 0x1002, 0x1001, 0x1000, 0x0501, 0x0500, 0x1005, 0x1004, 0x0404, 0x0810, 0x1100, 0x1101, + 0x0400, 0x0401, 0x0402, 0x0403, 0x040C, 0x0818, 0x1108, 0x1030, 0x0408, 0x0409, 0x040A, 0x2060, + 0x0801, 0x0800, 0x0280, 0x0802, 0x0410, 0x0804, 0x0412, 0x0806, 0x0809, 0x0808, 0x1021, 0x1020, + 0x5000, 0x2200, 0x5002, 0x2202) + +X14 = 0x00004000 # vector representation of X^14 +X8 = 0x00000100 # vector representation of X^8 +MASK7 = 0xffffff00 # auxiliary vector for testing +GENPOL = 0x00000139 # generator polinomial, g(x) + +def get_synd_1576(_pattern): + aux = X14; + if _pattern >= X8: + while _pattern & MASK7: + while not (aux & _pattern): + aux = aux >> 1 + _pattern ^= (aux / X8) * GENPOL + return _pattern + +def encode(_data): + value = (_data[0] >> 1) & 0x7F + cksum = ENCODE_1676[value] + _data[0] = cksum >> 8 + _data[1] = cksum & 0xFF + return _data + +def decode(_data): + code = (_data[0] << 7) + (_data[1] >> 1) + syndrome = get_synd_1576(code) + error_pattern = DECODE_1576[syndrome] + code ^= error_pattern + return code >> 7 + + +#------------------------------------------------------------------------------ +# Used to execute the module directly to run built-in tests +#------------------------------------------------------------------------------ + +if __name__ == '__main__': + + from binascii import b2a_hex as h + from time import time + + EMB_bits = [0,0,0,0] + EMB_bits[0] = bitarray('0001000') # 111100010 + EMB_bits[1] = bitarray('0001001') # 110010001 + EMB_bits[2] = bitarray('0001010') # 100000111 + EMB_bits[3] = bitarray('0001011') # 101110100 + print(EMB_bits) + + + for seq in xrange(4): + out = 0 + for bit in EMB_bits[seq]: + out = (out << 1) | bit + print(out) + emb = ENCODE_1676[out] + print(bin(emb)) \ No newline at end of file