Gateway changes
This commit is contained in:
parent
f5f9e14349
commit
a77061e21b
150
ambe_audio.py
150
ambe_audio.py
|
@ -16,7 +16,9 @@ from bitstring import BitArray
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
from dmrlink import IPSC, NETWORK, networks, logger, int_id, hex_str_3
|
from dmrlink import IPSC, NETWORK, networks, logger, int_id, hex_str_3, get_info, talkgroup_ids, subscriber_ids
|
||||||
|
import socket
|
||||||
|
import ConfigParser
|
||||||
|
|
||||||
__author__ = 'Cortney T. Buffington, N0MJS'
|
__author__ = 'Cortney T. Buffington, N0MJS'
|
||||||
__copyright__ = 'Copyright (c) 2015 Cortney T. Buffington, N0MJS and the K0USY Group'
|
__copyright__ = 'Copyright (c) 2015 Cortney T. Buffington, N0MJS and the K0USY Group'
|
||||||
|
@ -32,13 +34,57 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
sys.exit('IPSC message types file not found or invalid')
|
sys.exit('IPSC message types file not found or invalid')
|
||||||
|
|
||||||
|
def ByteToHex( byteStr ):
|
||||||
|
return ''.join( [ "%02X " % ord(x) for x in byteStr ] ).strip()
|
||||||
|
|
||||||
|
|
||||||
|
_configFile='ambe_audio.cfg'
|
||||||
|
_debug = False
|
||||||
|
_outToFile = False
|
||||||
|
_outToUDP = True
|
||||||
|
#_gateway = "192.168.1.184"
|
||||||
|
_gateway = "127.0.0.1"
|
||||||
|
_gateway_port = 1234
|
||||||
|
_tg_filter = [2,3,13,3174,3777215,3100,9,9998,3112] #set this to the tg to monitor
|
||||||
|
_no_tg = -99
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
config = ConfigParser.ConfigParser()
|
||||||
|
try:
|
||||||
|
_tg_filter=[]
|
||||||
|
config.read(_configFile)
|
||||||
|
for sec in config.sections():
|
||||||
|
for key, val in config.items(sec):
|
||||||
|
print( '%s="%s"' % (key, val) )
|
||||||
|
_debug = config.get(sec, '_debug')
|
||||||
|
_outToFile = config.get(sec, '_outToFile')
|
||||||
|
_outToUDP = config.get(sec, '_outToUDP')
|
||||||
|
_gateway = config.get(sec, '_gateway')
|
||||||
|
_gateway_port = config.get(sec, '_gateway_port')
|
||||||
|
_tgs = config.get(sec, '_tg_filter')
|
||||||
|
_tg_filter = map(int, _tgs.split(','))
|
||||||
|
|
||||||
|
except:
|
||||||
|
sys.exit('Configuration file \''+_configFile+'\' is not a valid configuration file! Exiting...')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if _outToFile == True:
|
||||||
|
f = open('ambe.bin', 'wb')
|
||||||
|
if _outToUDP == True:
|
||||||
|
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||||
|
|
||||||
class ambeIPSC(IPSC):
|
class ambeIPSC(IPSC):
|
||||||
|
_currentTG = _no_tg
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
IPSC.__init__(self, *args, **kwargs)
|
IPSC.__init__(self, *args, **kwargs)
|
||||||
self.CALL_DATA = []
|
self.CALL_DATA = []
|
||||||
|
self._currentTG = _no_tg
|
||||||
|
print('DMRLink ambe server')
|
||||||
|
print('Send UDP frames to gateway {}:{}'.format(_gateway, _gateway_port))
|
||||||
|
|
||||||
#************************************************
|
#************************************************
|
||||||
# CALLBACK FUNCTIONS FOR USER PACKET TYPES
|
# CALLBACK FUNCTIONS FOR USER PACKET TYPES
|
||||||
#************************************************
|
#************************************************
|
||||||
|
@ -53,22 +99,92 @@ class ambeIPSC(IPSC):
|
||||||
_ambe_frame2 = _ambe_frames[50:99]
|
_ambe_frame2 = _ambe_frames[50:99]
|
||||||
_ambe_frame3 = _ambe_frames[100:149]
|
_ambe_frame3 = _ambe_frames[100:149]
|
||||||
|
|
||||||
if _payload_type == BURST_DATA_TYPE['VOICE_HEAD']:
|
_tg_id = int_id(_dst_sub)
|
||||||
print('Voice Transmission Start')
|
if _tg_id in _tg_filter: #All TGs
|
||||||
if _payload_type == BURST_DATA_TYPE['VOICE_TERM']:
|
_dst_sub = get_info(int_id(_dst_sub), talkgroup_ids)
|
||||||
print('Voice Transmission End')
|
if _payload_type == BURST_DATA_TYPE['VOICE_HEAD']:
|
||||||
if _payload_type == BURST_DATA_TYPE['SLOT1_VOICE']:
|
if self._currentTG == _no_tg:
|
||||||
print(_ambe_frames)
|
if _ts: _ts = 2
|
||||||
print('Frame 1:', _ambe_frame1.bytes)
|
else: _ts = 1
|
||||||
print('Frame 2:', _ambe_frame2.bytes)
|
_src_sub = get_info(int_id(_src_sub), subscriber_ids)
|
||||||
print('Frame 3:', _ambe_frame3.bytes)
|
print('Voice Transmission Start on TS {} and TG {} ({}) from {}'.format(_ts, _dst_sub, _tg_id, _src_sub))
|
||||||
if _payload_type == BURST_DATA_TYPE['SLOT2_VOICE']:
|
self._currentTG = _tg_id
|
||||||
print(_ambe_frames)
|
else:
|
||||||
print('Frame 1:', _ambe_frame1.bytes)
|
if self._currentTG != _tg_id:
|
||||||
print('Frame 2:', _ambe_frame2.bytes)
|
print('Transmission in progress, will not decode stream on TG {}'.format(_tg_id))
|
||||||
print('Frame 3:', _ambe_frame3.bytes)
|
if _payload_type == BURST_DATA_TYPE['VOICE_TERM']:
|
||||||
|
if self._currentTG == _tg_id:
|
||||||
|
print('Voice Transmission End')
|
||||||
|
self._currentTG = _no_tg
|
||||||
|
if _payload_type == BURST_DATA_TYPE['SLOT1_VOICE']:
|
||||||
|
if self._currentTG == _tg_id:
|
||||||
|
if _debug == True:
|
||||||
|
print(_ambe_frames)
|
||||||
|
print('Frame 1:', ByteToHex(_ambe_frame1.tobytes()))
|
||||||
|
print('Frame 2:', ByteToHex(_ambe_frame2.tobytes()))
|
||||||
|
print('Frame 3:', ByteToHex(_ambe_frame3.tobytes()))
|
||||||
|
|
||||||
|
if _outToFile == True:
|
||||||
|
f.write( _ambe_frame1.tobytes() )
|
||||||
|
f.write( _ambe_frame2.tobytes() )
|
||||||
|
f.write( _ambe_frame3.tobytes() )
|
||||||
|
|
||||||
|
if _outToUDP == True:
|
||||||
|
sock.sendto(_ambe_frame1.tobytes(), (_gateway, _gateway_port))
|
||||||
|
sock.sendto(_ambe_frame2.tobytes(), (_gateway, _gateway_port))
|
||||||
|
sock.sendto(_ambe_frame3.tobytes(), (_gateway, _gateway_port))
|
||||||
|
|
||||||
|
|
||||||
|
if _payload_type == BURST_DATA_TYPE['SLOT2_VOICE']:
|
||||||
|
if self._currentTG == _tg_id:
|
||||||
|
if _debug == True:
|
||||||
|
print(_ambe_frames)
|
||||||
|
print('Frame 1:', ByteToHex(_ambe_frame1.tobytes()))
|
||||||
|
print('Frame 2:', ByteToHex(_ambe_frame2.tobytes()))
|
||||||
|
print('Frame 3:', ByteToHex(_ambe_frame3.tobytes()))
|
||||||
|
|
||||||
|
if _outToFile == True:
|
||||||
|
f.write( _ambe_frame1.tobytes() )
|
||||||
|
f.write( _ambe_frame2.tobytes() )
|
||||||
|
f.write( _ambe_frame3.tobytes() )
|
||||||
|
|
||||||
|
if _outToUDP == True:
|
||||||
|
sock.sendto(_ambe_frame1.tobytes(), (_gateway, _gateway_port))
|
||||||
|
sock.sendto(_ambe_frame2.tobytes(), (_gateway, _gateway_port))
|
||||||
|
sock.sendto(_ambe_frame3.tobytes(), (_gateway, _gateway_port))
|
||||||
|
else:
|
||||||
|
if _payload_type == BURST_DATA_TYPE['VOICE_HEAD']:
|
||||||
|
_dst_sub = get_info(int_id(_dst_sub), talkgroup_ids)
|
||||||
|
print('Ignored Voice Transmission Start on TS {} and TG {}'.format(_ts, _dst_sub))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import thread
|
||||||
|
|
||||||
|
# Define a function for the thread
|
||||||
|
def remote_control(port):
|
||||||
|
s = socket.socket() # Create a socket object
|
||||||
|
host = socket.gethostname() # Get local machine name
|
||||||
|
s.bind((host, port)) # Bind to the port
|
||||||
|
|
||||||
|
s.listen(5) # Now wait for client connection.
|
||||||
|
print('listening on port ', host, port)
|
||||||
|
while True:
|
||||||
|
c, addr = s.accept() # Establish connection with client.
|
||||||
|
print( 'Got connection from', addr )
|
||||||
|
tgs = c.recv(1024)
|
||||||
|
if tgs:
|
||||||
|
_tg_filter = map(int, tgs.split(','))
|
||||||
|
print( 'New TGs=', _tg_filter )
|
||||||
|
c.close() # Close the connection
|
||||||
|
try:
|
||||||
|
thread.start_new_thread( remote_control, (1235, ) )
|
||||||
|
except:
|
||||||
|
print( "Error: unable to start thread" )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logger.info('DMRlink \'ambe_audio.py\' (c) 2015 N0MJS & the K0USY Group - SYSTEM STARTING...')
|
logger.info('DMRlink \'ambe_audio.py\' (c) 2015 N0MJS & the K0USY Group - SYSTEM STARTING...')
|
||||||
for ipsc_network in NETWORK:
|
for ipsc_network in NETWORK:
|
||||||
|
|
13
dmrlink.py
13
dmrlink.py
|
@ -286,14 +286,21 @@ subscriber_ids = {}
|
||||||
peer_ids = {}
|
peer_ids = {}
|
||||||
talkgroup_ids = {}
|
talkgroup_ids = {}
|
||||||
|
|
||||||
|
#try:
|
||||||
|
# with open(PATH+'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:
|
||||||
|
# logger.warning('subscriber_ids.csv not found: Subscriber aliases will not be available')
|
||||||
try:
|
try:
|
||||||
with open(PATH+'subscriber_ids.csv', 'rU') as subscriber_ids_csv:
|
with open(PATH+'subscriber_idsxxx.csv', 'rU') as subscriber_ids_csv:
|
||||||
subscribers = csv.reader(subscriber_ids_csv, dialect='excel', delimiter=',')
|
subscribers = csv.reader(subscriber_ids_csv, dialect='excel', delimiter=',')
|
||||||
for row in subscribers:
|
for row in subscribers:
|
||||||
subscriber_ids[int(row[1])] = (row[0])
|
subscriber_ids[int(row[0])] = (row[1])
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.warning('subscriber_ids.csv not found: Subscriber aliases will not be available')
|
logger.warning('subscriber_ids.csv not found: Subscriber aliases will not be available')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(PATH+'peer_ids.csv', 'rU') as peer_ids_csv:
|
with open(PATH+'peer_ids.csv', 'rU') as peer_ids_csv:
|
||||||
peers = csv.reader(peer_ids_csv, dialect='excel', delimiter=',')
|
peers = csv.reader(peer_ids_csv, dialect='excel', delimiter=',')
|
||||||
|
|
|
@ -1 +1,11 @@
|
||||||
Worldwide,1
Local,2
North America,3
T6-DCI Bridge,3100
Kansas Statewide,3120
Missouri,3129
Massachussetts,3125
Midwest,3169
Northeast,3172
|
Worldwide,1
Local,2
North America,3
|
||||||
|
DMRPlus,9
|
||||||
|
Worldwide English,13
|
||||||
|
TAC 310,310
|
||||||
|
DCI Bridge 2,3100
DCI 1,3160
|
||||||
|
Midwest,3169
Northeast,3172
|
||||||
|
Southeast,3174
|
||||||
|
Flordia,3112
|
||||||
|
Kansas Statewide,3120
Massachussetts,3125
Missouri,3129
|
||||||
|
DCI Comm 1,3777215
|
||||||
|
Echo Server,9998
|
|
Loading…
Reference in New Issue