This commit is contained in:
Cort Buffington 2016-10-24 16:25:14 -05:00
parent 46b7632ad8
commit 5b21e8d612
3 changed files with 60 additions and 62 deletions

View File

@ -7,9 +7,9 @@
# 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'
@ -18,6 +18,11 @@ __license__ = 'Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unpo
__maintainer__ = 'Cort Buffington, N0MJS'
__email__ = 'n0mjs@me.com'
# Slot Type Data types
VOICE_HEAD = '\x01'
VOICE_TERM = '\x02'
# Sync patterns used for LC and Voice Burst A packets
BS_VOICE_SYNC = bitarray()
BS_DATA_SYNC = bitarray()

View File

@ -34,7 +34,7 @@ def voice_head_term(_string):
lc = bptc.decode_full_lc(info).tobytes()
cc = to_bytes(slot_type[0:4])
dtype = to_bytes(slot_type[4:8])
return (lc, cc, dtype, sync)
return {'LC': lc, 'CC': cc, 'DTYPE': dtype, 'SYNC': sync}
def voice_sync(_string):
@ -44,7 +44,7 @@ def voice_sync(_string):
ambe[1] = burst[72:108] + burst[156:192]
ambe[2] = burst[192:264]
sync = burst[108:156]
return (ambe, sync)
return {'AMBE': ambe, 'SYNC': sync}
def voice(_string):
@ -54,10 +54,10 @@ def voice(_string):
ambe[1] = burst[72:108] + burst[156:192]
ambe[2] = burst[192:264]
emb = burst[108:116] + burst[148:156]
embedded = burst[116:148]
embed = burst[116:148]
cc = (to_bytes(emb[0:4]))
lcss = (to_bytes(emb[5:7]))
return (ambe, cc, lcss, embedded)
return {'AMBE': ambe, 'CC': cc, 'LCSS': lcss, 'EMBED': embed}
def to_bytes(_bits):
@ -89,85 +89,85 @@ if __name__ == '__main__':
voice_f = '\xee\xe7\x81\x75\x74\x61\x4d\xf2\xff\xcc\xf4\xa0\x55\x11\x10\x00\x00\x00\x0e\x24\x30\x59\xe7\xf9\xe9\x08\xa0\x75\x62\x02\xcc\xd6\x22'
voice_term = '\x2b\x0f\x04\xc4\x1f\x34\x2d\xa8\x0d\x80\x7d\xe1\x04\xad\xff\x57\xd7\x5d\xf5\xd9\x65\x01\x2d\x18\x77\xd2\x03\xc0\x37\x88\xdf\x95\xd1'
embedded_lc = bitarray()
embed_lc = bitarray()
print('DMR PACKET DECODER VALIDATION\n')
print('Header:')
t0 = time()
lc = voice_head_term(data_head)
t1 = time()
print('LC: OPT-{} SRC-{} DST-{}, SLOT TYPE: CC-{} DTYPE-{}'.format(h(lc[0][0:3]),h(lc[0][3:6]),h(lc[0][6:9]),h(lc[1]),h(lc[2])))
print('LC: OPT-{} SRC-{} DST-{}, SLOT TYPE: CC-{} DTYPE-{}'.format(h(lc['LC'][0:3]),h(lc['LC'][3:6]),h(lc['LC'][6:9]),h(lc['CC']),h(lc['DTYPE'])))
print('Decode Time: {}\n'.format(t1-t0))
print('Voice Burst A:')
t0 = time()
lc = voice_sync(voice_a)
pkt = voice_sync(voice_a)
t1 = time()
print('VOICE SYNC: {}'.format(h(lc[1])))
print('AMBE 0: {}, {}'.format(lc[0][0], len(lc[0][0])))
print('AMBE 1: {}, {}'.format(lc[0][1], len(lc[0][1])))
print('AMBE 2: {}, {}'.format(lc[0][2], len(lc[0][2])))
print('VOICE SYNC: {}'.format(h(lc['SYNC'])))
print('AMBE 0: {}, {}'.format(pkt['AMBE'][0], len(pkt['AMBE'][0])))
print('AMBE 1: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][1])))
print('AMBE 2: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][2])))
print(t1-t0, '\n')
print('Voice Burst B:')
t0 = time()
lc = voice(voice_b)
embedded_lc += lc[3]
pkt = voice(voice_b)
embed_lc += pkt['EMBED']
t1 = time()
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(lc[1]), h(lc[2]), h(lc[3].tobytes())))
print('AMBE 0: {}, {}'.format(lc[0][0], len(lc[0][0])))
print('AMBE 1: {}, {}'.format(lc[0][1], len(lc[0][1])))
print('AMBE 2: {}, {}'.format(lc[0][2], len(lc[0][2])))
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(pkt['CC']), h(pkt['LCSS']), h(pkt['EMBED'].tobytes())))
print('AMBE 0: {}, {}'.format(pkt['AMBE'][0], len(pkt['AMBE'][0])))
print('AMBE 1: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][1])))
print('AMBE 2: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][2])))
print(t1-t0, '\n')
print('Voice Burst C:')
t0 = time()
lc = voice(voice_c)
embedded_lc += lc[3]
pkt = voice(voice_c)
embed_lc += pkt['EMBED']
t1 = time()
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(lc[1]), h(lc[2]), h(lc[3].tobytes())))
print('AMBE 0: {}, {}'.format(lc[0][0], len(lc[0][0])))
print('AMBE 1: {}, {}'.format(lc[0][1], len(lc[0][1])))
print('AMBE 2: {}, {}'.format(lc[0][2], len(lc[0][2])))
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(pkt['CC']), h(pkt['LCSS']), h(pkt['EMBED'].tobytes())))
print('AMBE 0: {}, {}'.format(pkt['AMBE'][0], len(pkt['AMBE'][0])))
print('AMBE 1: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][1])))
print('AMBE 2: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][2])))
print(t1-t0, '\n')
print('Voice Burst D:')
t0 = time()
lc = voice(voice_d)
embedded_lc += lc[3]
pkt = voice(voice_d)
embed_lc += pkt['EMBED']
t1 = time()
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(lc[1]), h(lc[2]), h(lc[3].tobytes())))
print('AMBE 0: {}, {}'.format(lc[0][0], len(lc[0][0])))
print('AMBE 1: {}, {}'.format(lc[0][1], len(lc[0][1])))
print('AMBE 2: {}, {}'.format(lc[0][2], len(lc[0][2])))
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(pkt['CC']), h(pkt['LCSS']), h(pkt['EMBED'].tobytes())))
print('AMBE 0: {}, {}'.format(pkt['AMBE'][0], len(pkt['AMBE'][0])))
print('AMBE 1: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][1])))
print('AMBE 2: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][2])))
print(t1-t0, '\n')
print('Voice Burst E:')
t0 = time()
lc = voice(voice_e)
embedded_lc += lc[3]
embedded_lc = bptc.decode_emblc(embedded_lc)
pkt = voice(voice_e)
embed_lc += pkt['EMBED']
embed_lc = bptc.decode_emblc(embed_lc)
t1 = time()
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(lc[1]), h(lc[2]), h(lc[3].tobytes())))
print('COMPLETE EMBEDDED LC: {}'.format(h(embedded_lc)))
print('AMBE 0: {}, {}'.format(lc[0][0], len(lc[0][0])))
print('AMBE 1: {}, {}'.format(lc[0][1], len(lc[0][1])))
print('AMBE 2: {}, {}'.format(lc[0][2], len(lc[0][2])))
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(pkt['CC']), h(pkt['LCSS']), h(pkt['EMBED'].tobytes())))
print('COMPLETE EMBEDDED LC: {}'.format(h(embed_lc)))
print('AMBE 0: {}, {}'.format(pkt['AMBE'][0], len(pkt['AMBE'][0])))
print('AMBE 1: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][1])))
print('AMBE 2: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][2])))
print(t1-t0, '\n')
print('Voice Burst F:')
t0 = time()
lc = voice(voice_f)
pkt = voice(voice_f)
t1 = time()
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(lc[1]), h(lc[2]), h(lc[3].tobytes())))
print('AMBE 0: {}, {}'.format(lc[0][0], len(lc[0][0])))
print('AMBE 1: {}, {}'.format(lc[0][1], len(lc[0][1])))
print('AMBE 2: {}, {}'.format(lc[0][2], len(lc[0][2])))
print('EMB: CC-{} LCSS-{}, EMBEDDED LC: {}'.format(h(pkt['CC']), h(pkt['LCSS']), h(pkt['EMBED'].tobytes())))
print('AMBE 0: {}, {}'.format(pkt['AMBE'][0], len(pkt['AMBE'][0])))
print('AMBE 1: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][1])))
print('AMBE 2: {}, {}'.format(pkt['AMBE'][1], len(pkt['AMBE'][2])))
print(t1-t0, '\n')
print('Terminator:')
t0 = time()
lc = voice_head_term(voice_term)
t1 = time()
print('LC: OPT-{} SRC-{} DST-{} SLOT TYPE: CC-{} DTYPE-{}'.format(h(lc[0][0:3]),h(lc[0][3:6]),h(lc[0][6:9]),h(lc[1]),h(lc[2])))
print('LC: OPT-{} SRC-{} DST-{} SLOT TYPE: CC-{} DTYPE-{}'.format(h(lc['LC'][0:3]),h(lc['LC'][3:6]),h(lc['LC'][6:9]),h(lc['CC']),h(lc['DTYPE'])))
print('Decode Time: {}\n'.format(t1-t0))

View File

@ -24,6 +24,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 dec_dmr
import constants as const
# Import Bridging rules
# Note: A stanza *must* exist for any MASTER or CLIENT configured in the main
@ -73,41 +74,33 @@ class routerMASTER(HBMASTER):
def __init__(self, *args, **kwargs):
HBMASTER.__init__(self, *args, **kwargs)
self._last_stream_id = ''
self._last_seq_id = 0x00
self.lc_rx = ''
self.lc_tx = ''
self.embedded_lc_rx = [0,0,0,0]
self.embedded_lc_tx = [0,0,0,0]
self.embedded_lc = ''
self.lc_index = 0
self.have_lc_rx = False
self.have_lc_rx = False
self.embedded_lc_index = 0
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':
lc = dec_dmr.voice_head_term(_data[20:53])
if lc[2] == '\x01':
head = dec_dmr.voice_head_term(_data[20:53])
if head['DTYPE'] == const.VOICE_HEAD:
print('Voice Header: LC: {}, CC: {}, DTYPE: {}, SYNC: {}'.format(h(lc[0]), h(lc[1]), h(lc[2]), h(lc[3])))
if lc[2] == '\x02':
print('Voice Terminator: LC: {}, CC: {}, DTYPE: {}, SYNC: {}'.format(h(lc[0]), h(lc[1]), h(lc[2]), h(lc[3])))
if _frame_type == 'voice_sync':
lc = dec_dmr.voice_sync(_data[20:53])
print('Voice Burst A: SYNC: {}'.format(h(lc[1])))
if _frame_type == 'voice':
lc = dec_dmr.voice(_data[20:53])
if lc[2] == '\x01':
self.lc_index = 0
self.embedded_lc_rx[self.lc_index] = lc[3]
elif lc[2] == '\x03':
self.lc_index += 1
self.embedded_lc_rx[self.lc_index] = lc[3]
elif lc[2] == '\x02':
self.lc_index += 1
if self.lc_index == 3:
self.embedded_lc_rx[self.lc_index] = lc[3]
self.embedded_lc = dec_dmr.bptc.decode_emblc(self.embedded_lc_rx[0] + self.embedded_lc_rx[1] + self.embedded_lc_rx[2] + self.embedded_lc_rx[3])
print('Emedded LC Completed: {}'.format(h(self.embedded_lc)))
print('Voice Burst B-F: CC: {}, LCSS: {}, EMBEDDED LC: {}'.format(h(lc[1]), h(lc[2]), h(lc[3])))
_routed = False
for rule in RULES[self._master]['GROUP_VOICE']: