From 9b6a071cee6bd9bf2263c1f5cf97f0be5d0cd231 Mon Sep 17 00:00:00 2001 From: Cort Buffington Date: Mon, 10 Oct 2016 20:49:51 -0500 Subject: [PATCH] Moving towards complete DMR rebuild for re-write --- dmr_decon.py | 57 ++++++++++++++++++++++++---------------------------- hb_router.py | 28 +++++++++++++++++++++----- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/dmr_decon.py b/dmr_decon.py index e14fb4b..be3c86d 100755 --- a/dmr_decon.py +++ b/dmr_decon.py @@ -39,38 +39,33 @@ def voice_head_term(_string): info = burst[0:98] + burst[166:264] de_int_info = bptc19696.deinterleave(info) slot_type = burst[98:108] + burst[156:166] - sync = burst[108:156] - if sync == const.BS_DATA_SYNC: - sync = True - else: - sync = False lc = to_bytes(lc_data_9(de_int_info)) cc = to_bytes(slot_type[0:4]) dtype = to_bytes(slot_type[4:8]) - return (lc, cc, dtype, sync) + return (lc, cc, dtype) -def voice_burst(_string): +def voice_sync(_string): burst = to_bits(_string) ambe = [0,0,0] ambe[0] = burst[0:72] ambe[1] = burst[72:108] + burst[156:192] ambe[2] = burst[192:264] - sync = burst [108:156] - if sync == const.BS_VOICE_SYNC: - cc = bitarray('00') - lcss = bitarray('00') - sync = True - else: - emb = burst[108:116] + burst[148:156] - embeded = burst[116:148] - cc = (emb[0:4]) - # pi = (emb[4:5]) - lcss = (emb[5:7]) - sync = False - if not sync and lcss == const.LCSS_FIRST_FRAG or lcss == const.LCSS_CONT_FRAG or lcss == const.LCSS_LAST_FRAG: - pass - return (ambe, cc, lcss, sync) + return (ambe) + + +def voice(_string): + burst = to_bits(_string) + ambe = [0,0,0] + ambe[0] = burst[0:72] + ambe[1] = burst[72:108] + burst[156:192] + ambe[2] = burst[192:264] + emb = burst[108:116] + burst[148:156] + embeded = burst[116:148] + cc = (emb[0:4]) + # pi = (emb[4:5]) + lcss = (emb[5:7]) + return (ambe, cc, lcss, embeded) def to_bytes(_bits): @@ -107,47 +102,47 @@ if __name__ == '__main__': t0 = time() lc = voice_head_term(data_head) t1 = time() - print(h(lc[0]), h(lc[1]), h(lc[2]), lc[3]) + print(h(lc[0]), h(lc[1]), h(lc[2])) print(t1-t0, '\n') print('Voice Burst A Validation:') t0 = time() - lc = voice_burst(voice_a) + lc = voice_sync(voice_a) t1 = time() - print(lc[0], h(lc[1]), h(lc[2]), lc[3]) + print(lc[0]) print(t1-t0, '\n') print('Voice Burst B Validation:') t0 = time() - lc = voice_burst(voice_b) + lc = voice(voice_b) t1 = time() print(lc[0], h(lc[1]), h(lc[2]), lc[3]) print(t1-t0, '\n') print('Voice Burst C Validation:') t0 = time() - lc = voice_burst(voice_c) + lc = voice(voice_c) t1 = time() print(lc[0], h(lc[1]), h(lc[2]), lc[3]) print(t1-t0, '\n') print('Voice Burst D Validation:') t0 = time() - lc = voice_burst(voice_d) + lc = voice(voice_d) t1 = time() print(lc[0], h(lc[1]), h(lc[2]), lc[3]) print(t1-t0, '\n') print('Voice Burst E Validation:') t0 = time() - lc = voice_burst(voice_e) + lc = voice(voice_e) t1 = time() print(lc[0], h(lc[1]), h(lc[2]), lc[3]) print(t1-t0, '\n') print('Voice Burst F Validation:') t0 = time() - lc = voice_burst(voice_f) + lc = voice(voice_f) t1 = time() print(lc[0], h(lc[1]), h(lc[2]), lc[3]) print(t1-t0, '\n') @@ -156,5 +151,5 @@ if __name__ == '__main__': t0 = time() lc = voice_head_term(voice_term) t1 = time() - print(h(lc[0]), h(lc[1]), h(lc[2]), lc[3]) + print(h(lc[0]), h(lc[1]), h(lc[2])) print(t1-t0) \ No newline at end of file diff --git a/hb_router.py b/hb_router.py index d879e1b..cd92bf0 100755 --- a/hb_router.py +++ b/hb_router.py @@ -11,6 +11,7 @@ from __future__ import print_function # Python modules we need import sys from binascii import b2a_hex as h +from bitarray import bitarray # Debugging functions from pprint import pprint @@ -22,7 +23,7 @@ from twisted.internet import task # Things we import from the main hblink module from hblink import CONFIG, HBMASTER, HBCLIENT, logger, systems, hex_str_3, int_id -import dmr_decon +import dmr_decon, crc # Import Bridging rules # Note: A stanza *must* exist for any MASTER or CLIENT configured in the main @@ -68,15 +69,28 @@ __status__ = 'pre-alpha' class routerMASTER(HBMASTER): + + def __init__(self, *args, **kwargs): + HBMASTER.__init__(self, *args, **kwargs) + self.lc_fragments = {'B': '', 'C': '', 'D': '', 'E': '', 'F': ''} def dmrd_received(self, _radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): _bits = int_id(_data[15]) if _call_type == 'group': - if _frame_type == 'data_sync' and (_dtype_vseq == 1 or _dtype_vseq == 2): - print(dmr_decon.voice_head_term(_data[20:53])) - elif _frame_type == 'voice' or _frame_type == 'voice_sync': - print(dmr_decon.voice_burst(_data[20:53])) + if _frame_type == 'data_sync': + lc = dmr_decon.voice_head_term(_data[20:53])[0] + print(h(lc)) + if _dtype_vseq == 1: + lc_bits = bitarray() + lc_bits.frombytes(lc) + embedded_lc = lc_bits + crc.csum5(lc) + print('SHIT IS TEH SHIT:', lc_bits) + print('THIS IS THE SHIT:', embedded_lc) + elif _frame_type == 'voice_sync': + print(dmr_decon.voice_sync(_data[20:53])) + elif _frame_type == 'voice': + print(dmr_decon.voice(_data[20:53])) _routed = False for rule in RULES[self._master]['GROUP_VOICE']: @@ -98,6 +112,10 @@ class routerMASTER(HBMASTER): class routerCLIENT(HBCLIENT): + def __init__(self, *args, **kwargs): + HBCLIENT.__init__(self, *args, **kwargs) + self.lc_fragments = {'B': '', 'C': '', 'D': '', 'E': '', 'F': ''} + def dmrd_received(self, _radio_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data): _bits = int_id(_data[15]) if _call_type == 'group':