Broke Alias File Into Multiples
Why parse several thousand dictionary entries when all you need to do is find which of a couple hundred repeaters or a handful of TGIDs?
This commit is contained in:
parent
8615e40e51
commit
7a63b3d25f
70
dmrlink.py
70
dmrlink.py
@ -46,14 +46,36 @@ try:
|
||||
except ImportError:
|
||||
sys.exit('IPSC mask values file not found or invalid')
|
||||
|
||||
ids = {}
|
||||
# Import the Alias files for numeric ids. This is split to save
|
||||
# time making lookukps in one huge dictionary
|
||||
#
|
||||
subscriber_ids = {}
|
||||
peer_ids = {}
|
||||
talkgroup_ids = {}
|
||||
|
||||
try:
|
||||
with open('./radioids.csv', 'r') as radioids_csv:
|
||||
radio_ids = csv.reader(radioids_csv, dialect='excel', delimiter=',')
|
||||
for row in radio_ids:
|
||||
ids[int(row[1])] = (row[0])
|
||||
with open('./subscriber_ids.csv', 'rU') as subscriber_ids_csv:
|
||||
subscribers = csv.reader(subscriber_ids_csv, dialect='excel', delimiter=',')
|
||||
for row in subscribers:
|
||||
subscriber_ids[int(row[1])] = (row[0])
|
||||
except ImportError:
|
||||
sys.exit('No Radio ID CSV file found')
|
||||
print('subscriber_ids.csv not found: Subscriber aliases will not be avaiale')
|
||||
|
||||
try:
|
||||
with open('./peer_ids.csv', 'rU') as peer_ids_csv:
|
||||
peers = csv.reader(peer_ids_csv, dialect='excel', delimiter=',')
|
||||
for row in peers:
|
||||
peer_ids[int(row[1])] = (row[0])
|
||||
except ImportError:
|
||||
print('peer_ids.csv not found: Peer aliases will not be avaiale')
|
||||
|
||||
try:
|
||||
with open('./talkgroup_ids.csv', 'rU') as talkgroup_ids_csv:
|
||||
talkgroups = csv.reader(talkgroup_ids_csv, dialect='excel', delimiter=',')
|
||||
for row in talkgroups:
|
||||
talkgroup_ids[int(row[1])] = (row[0])
|
||||
except ImportError:
|
||||
print('talkgroup_ids.csv not found: Talkgroup aliases will not be avaiale')
|
||||
|
||||
|
||||
#************************************************
|
||||
@ -140,8 +162,8 @@ for section in config.sections():
|
||||
|
||||
if NETWORK[section]['LOCAL']['AUTH_ENABLED']:
|
||||
# 0x1C - Voice and Data calls only, 0xDC - Voice, Data and XCMP/XNL
|
||||
#NETWORK[section]['LOCAL']['FLAGS'] = '\x00\x00\x00\x1C'
|
||||
NETWORK[section]['LOCAL']['FLAGS'] = '\x00\x00\x00\xDC'
|
||||
NETWORK[section]['LOCAL']['FLAGS'] = '\x00\x00\x00\x1C'
|
||||
#NETWORK[section]['LOCAL']['FLAGS'] = '\x00\x00\x00\xDC'
|
||||
else:
|
||||
NETWORK[section]['LOCAL']['FLAGS'] = '\x00\x00\x00\x0C'
|
||||
|
||||
@ -175,9 +197,9 @@ def dmr_nat(_data, _nat_id):
|
||||
|
||||
# Lookup text data for numeric IDs
|
||||
#
|
||||
def get_info(_id):
|
||||
if _id in ids:
|
||||
return ids[_id]
|
||||
def get_info(_id, _dict):
|
||||
if _id in _dict:
|
||||
return _dict[_id]
|
||||
return _id
|
||||
|
||||
# Remove the hash from a packet and return the payload
|
||||
@ -448,33 +470,33 @@ class IPSC(DatagramProtocol):
|
||||
print('({}) XCMP/XNL Packet Received From: {}' .format(_network, _src_sub))
|
||||
|
||||
def group_voice(self, _network, _src_sub, _dst_sub, _ts, _end, _peerid, _data):
|
||||
_dst_sub = get_info(int_id(_dst_sub))
|
||||
_peerid = get_info(int_id(_peerid))
|
||||
_src_sub = get_info(int_id(_src_sub))
|
||||
_dst_sub = get_info(int_id(_dst_sub), talkgroup_ids)
|
||||
_peerid = get_info(int_id(_peerid), peer_ids)
|
||||
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||
print('({}) Group Voice Packet Received From: {}, IPSC Peer {}, Destination {}' .format(_network, _src_sub, _peerid, _dst_sub))
|
||||
|
||||
def private_voice(self, _network, _src_sub, _dst_sub, _ts, _end, _peerid, _data):
|
||||
_dst_sub = get_info(int_id(_dst_sub))
|
||||
_peerid = get_info(int_id(_peerid))
|
||||
_src_sub = get_info(int_id(_src_sub))
|
||||
_dst_sub = get_info(int_id(_dst_sub), subscriber_ids)
|
||||
_peerid = get_info(int_id(_peerid), peer_ids)
|
||||
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||
print('({}) Private Voice Packet Received From: {}, IPSC Peer {}, Destination {}' .format(_network, _src_sub, _peerid, _dst_sub))
|
||||
|
||||
def group_data(self, _network, _src_sub, _dst_sub, _ts, _end, _peerid, _data):
|
||||
_dst_sub = get_info(int_id(_dst_sub))
|
||||
_peerid = get_info(int_id(_peerid))
|
||||
_src_sub = get_info(int_id(_src_sub))
|
||||
_dst_sub = get_info(int_id(_dst_sub), talkgroup_ids)
|
||||
_peerid = get_info(int_id(_peerid), peer_ids)
|
||||
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||
print('({}) Group Data Packet Received From: {}, IPSC Peer {}, Destination {}' .format(_network, _src_sub, _peerid, _dst_sub))
|
||||
|
||||
def private_data(self, _network, _src_sub, _dst_sub, _ts, _end, _peerid, _data):
|
||||
_dst_sub = get_info(int_id(_dst_sub))
|
||||
_peerid = get_info(int_id(_peerid))
|
||||
_src_sub = get_info(int_id(_src_sub))
|
||||
_dst_sub = get_info(int_id(_dst_sub), subscriber_ids)
|
||||
_peerid = get_info(int_id(_peerid), peer_ids)
|
||||
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||
print('({}) Private Data Packet Received From: {}, IPSC Peer {}, Destination {}' .format(_network, _src_sub, _peerid, _dst_sub))
|
||||
|
||||
def unknown_message(self, _network, _packettype, _peerid, _data):
|
||||
_time = time.strftime('%m/%d/%y %H:%M:%S')
|
||||
_packettype = binascii.b2a_hex(_packettype)
|
||||
_peerid = get_info(int_id(_peerid))
|
||||
_peerid = get_info(int_id(_peerid), peer_ids)
|
||||
print('{} ({}) Unknown message type encountered\n\tPacket Type: {}\n\tFrom: {}' .format(_time, _network, _packettype, _peerid))
|
||||
print('\t', binascii.b2a_hex(_data))
|
||||
|
||||
|
26
log.py
26
log.py
@ -15,7 +15,7 @@ import struct
|
||||
import time
|
||||
import binascii
|
||||
import dmrlink
|
||||
from dmrlink import IPSC, UnauthIPSC, NETWORK, networks, get_info, int_id
|
||||
from dmrlink import IPSC, UnauthIPSC, NETWORK, networks, get_info, int_id, subscriber_ids, peer_ids, talkgroup_ids
|
||||
|
||||
class logIPSC(IPSC):
|
||||
|
||||
@ -48,9 +48,9 @@ class logIPSC(IPSC):
|
||||
print('RSSI (not quite correct yet): ', rssi)
|
||||
if (_ts not in self.ACTIVE_CALLS) or _end:
|
||||
_time = time.strftime('%m/%d/%y %H:%M:%S')
|
||||
_dst_sub = get_info(int_id(_dst_sub))
|
||||
_peerid = get_info(int_id(_peerid))
|
||||
_src_sub = get_info(int_id(_src_sub))
|
||||
_dst_sub = get_info(int_id(_dst_sub), talkgroup_ids)
|
||||
_peerid = get_info(int_id(_peerid), peer_ids)
|
||||
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||
if not _end: self.ACTIVE_CALLS.append(_ts)
|
||||
if _end: self.ACTIVE_CALLS.remove(_ts)
|
||||
|
||||
@ -65,9 +65,9 @@ class logIPSC(IPSC):
|
||||
# _log = logger.debug
|
||||
if (_ts not in self.ACTIVE_CALLS) or _end:
|
||||
_time = time.strftime('%m/%d/%y %H:%M:%S')
|
||||
_dst_sub = get_info(int_id(_dst_sub))
|
||||
_peerid = get_info(int_id(_peerid))
|
||||
_src_sub = get_info(int_id(_src_sub))
|
||||
_dst_sub = get_info(int_id(_dst_sub), subscriber_ids)
|
||||
_peerid = get_info(int_id(_peerid), peer_ids)
|
||||
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||
if not _end: self.ACTIVE_CALLS.append(_ts)
|
||||
if _end: self.ACTIVE_CALLS.remove(_ts)
|
||||
|
||||
@ -79,15 +79,15 @@ class logIPSC(IPSC):
|
||||
print('{} ({}) Call {} Private Voice: \n\tIPSC Source:\t{}\n\tSubscriber:\t{}\n\tDestination:\t{}\n\tTimeslot\t{}' .format(_time, _network, _end, _peerid, _src_sub, _dst_sub, _ts))
|
||||
|
||||
def group_data(self, _network, _src_sub, _dst_sub, _ts, _end, _peerid, _data):
|
||||
_dst_sub = get_info(int_id(_dst_sub))
|
||||
_peerid = get_info(int_id(_peerid))
|
||||
_src_sub = get_info(int_id(_src_sub))
|
||||
_dst_sub = get_info(int_id(_dst_sub), talkgroup_ids)
|
||||
_peerid = get_info(int_id(_peerid), peer_ids)
|
||||
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||
print('({}) Group Data Packet Received From: {}' .format(_network, _src_sub))
|
||||
|
||||
def private_data(self, _network, _src_sub, _dst_sub, _ts, _end, _peerid, _data):
|
||||
_dst_sub = get_info(int_id(_dst_sub))
|
||||
_peerid = get_info(int_id(_peerid))
|
||||
_src_sub = get_info(int_id(_src_sub))
|
||||
_dst_sub = get_info(int_id(_dst_sub), subscriber_ids)
|
||||
_peerid = get_info(int_id(_peerid), peer_ids)
|
||||
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||
print('({}) Private Data Packet Received From: {} To: {}' .format(_network, _src_sub, _dst_sub))
|
||||
|
||||
class logUnauthIPSC(logIPSC):
|
||||
|
1
peer_ids.csv
Normal file
1
peer_ids.csv
Normal file
File diff suppressed because one or more lines are too long
3488
radioids.csv
3488
radioids.csv
File diff suppressed because it is too large
Load Diff
1
subscriber_ids.csv
Normal file
1
subscriber_ids.csv
Normal file
File diff suppressed because one or more lines are too long
1
talkgroup_ids.csv
Normal file
1
talkgroup_ids.csv
Normal file
@ -0,0 +1 @@
|
||||
Worldwide,1
Local,2
North America,3
T6-DCI Bridge,3100
Kansas Statewide,3120
Massachussetts,3125
Midwest,3169
Northeast,3172
|
|
Loading…
x
Reference in New Issue
Block a user