From 2092f2a1e524084a681cb909dc555c79c39c64dd Mon Sep 17 00:00:00 2001 From: Mike Zingman Date: Wed, 16 Dec 2015 15:20:01 -0500 Subject: [PATCH] Add reread_subscribers remote control command --- ambe_audio.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/ambe_audio.py b/ambe_audio.py index 49c257c..91c1d57 100755 --- a/ambe_audio.py +++ b/ambe_audio.py @@ -16,8 +16,9 @@ from bitstring import BitArray import sys, socket, ConfigParser, thread, traceback import cPickle as pickle -from dmrlink import IPSC, NETWORK, networks, logger, int_id, hex_str_3, get_info, talkgroup_ids, subscriber_ids, peer_ids +from dmrlink import IPSC, NETWORK, networks, logger, int_id, hex_str_3, get_info, talkgroup_ids, subscriber_ids, peer_ids, PATH from time import time +import csv __author__ = 'Cortney T. Buffington, N0MJS' __copyright__ = 'Copyright (c) 2015 Cortney T. Buffington, N0MJS and the K0USY Group' @@ -84,7 +85,6 @@ class ambeIPSC(IPSC): traceback.print_exc() print( "Error: unable to start thread" ) - # Utility function to convert bytes to string of hex values (for debug) def ByteToHex( self, byteStr ): return ''.join( [ "%02X " % ord(x) for x in byteStr ] ).strip() @@ -176,11 +176,21 @@ class ambeIPSC(IPSC): self._sock.sendto(_ambe_frame3.tobytes(), (self._gateway, self._gateway_port)) + def reread_subscribers(self): + try: + with open(PATH+'subscriber_ids.csv', 'rU') as subscriber_ids_csv: + subscribers = csv.reader(subscriber_ids_csv, dialect='excel', delimiter=',') + subscriber_ids = {} + for row in subscribers: + subscriber_ids[int(row[0])] = (row[1]) + print('Subscriber file has been updated') + except ImportError: + logger.warning('subscriber_ids.csv not found: Subscriber aliases will not be available') # # Define a function for the thread # Use netcat to dynamically change the TGs that are forwarded to Allstar - # echo "x,y,z" | nc 127.0.0.1 1235 + # echo -n "x,y,z" | nc 127.0.0.1 1235 # def remote_control(self, port): s = socket.socket() # Create a socket object @@ -193,13 +203,16 @@ class ambeIPSC(IPSC): c, addr = s.accept() # Establish connection with client. print( 'Got connection from', addr ) tgs = c.recv(1024) + print('Command:"{}"'.format(tgs)) if tgs: - self._tg_filter = map(int, tgs.split(',')) - print( 'New TGs=', self._tg_filter ) + if tgs == 'reread_subscribers': + self.reread_subscribers() + else: + self._tg_filter = map(int, tgs.split(',')) + print( 'New TGs=', self._tg_filter ) c.close() # Close the connection - if __name__ == '__main__': logger.info('DMRlink \'ambe_audio.py\' (c) 2015 N0MJS & the K0USY Group - SYSTEM STARTING...') for ipsc_network in NETWORK: