mirror of
https://github.com/ShaYmez/hblink3.git
synced 2024-11-21 23:45:15 -05:00
Merge branch 'private-call-dev' of https://github.com/n0mjs710/hblink3 into private-call-dev
This commit is contained in:
commit
c246f3e5db
143
blank_app.py
Executable file
143
blank_app.py
Executable file
@ -0,0 +1,143 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
# Copyright (C) 2020 Cortney T. Buffington, N0MJS <n0mjs@me.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
'''
|
||||||
|
This is a blank application template to build on top of hblink.py. It contains
|
||||||
|
only the things you need to, essentially, run hblink.py underneath and do nothing
|
||||||
|
else. The expected behaviour is to override the dmrd_received function from
|
||||||
|
hblink.py to do somethign meaningful, so that framework is completed, but as
|
||||||
|
it stands, still does nothing with the DMRD packet.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Python modules we need
|
||||||
|
import sys
|
||||||
|
from bitarray import bitarray
|
||||||
|
from time import time
|
||||||
|
from importlib import import_module
|
||||||
|
from types import ModuleType
|
||||||
|
|
||||||
|
# Twisted is pretty important, so I keep it separate
|
||||||
|
from twisted.internet.protocol import Factory, Protocol
|
||||||
|
from twisted.protocols.basic import NetstringReceiver
|
||||||
|
from twisted.internet import reactor, task
|
||||||
|
|
||||||
|
# Things we import from the main hblink module
|
||||||
|
from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, config_reports, mk_aliases, acl_check
|
||||||
|
from dmr_utils3.utils import bytes_3, int_id, get_alias
|
||||||
|
from dmr_utils3 import decode, bptc, const
|
||||||
|
import config
|
||||||
|
import log
|
||||||
|
import const
|
||||||
|
|
||||||
|
# The module needs logging logging, but handlers, etc. are controlled by the parent
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# Does anybody read this stuff? There's a PEP somewhere that says I should do this.
|
||||||
|
__author__ = 'Cortney T. Buffington, N0MJS'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 Cortney T. Buffington'
|
||||||
|
__credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT'
|
||||||
|
__license__ = 'GNU GPLv3'
|
||||||
|
__maintainer__ = 'Cort Buffington, N0MJS'
|
||||||
|
__email__ = 'n0mjs@me.com'
|
||||||
|
__status__ = 'pre-alpha'
|
||||||
|
|
||||||
|
# Module gobal varaibles
|
||||||
|
|
||||||
|
|
||||||
|
class blankSYSTEM(HBSYSTEM):
|
||||||
|
|
||||||
|
def __init__(self, _name, _config, _report):
|
||||||
|
HBSYSTEM.__init__(self, _name, _config, _report)
|
||||||
|
|
||||||
|
def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
#************************************************
|
||||||
|
# MAIN PROGRAM LOOP STARTS HERE
|
||||||
|
#************************************************
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
|
from dmr_utils3.utils import try_download, mk_id_dict
|
||||||
|
|
||||||
|
# Change the current directory to the location of the application
|
||||||
|
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
|
||||||
|
|
||||||
|
# CLI argument parser - handles picking up the config file from the command line, and sending a "help" message
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-c', '--config', action='store', dest='CONFIG_FILE', help='/full/path/to/config.file (usually hblink.cfg)')
|
||||||
|
parser.add_argument('-l', '--logging', action='store', dest='LOG_LEVEL', help='Override config file logging level.')
|
||||||
|
cli_args = parser.parse_args()
|
||||||
|
|
||||||
|
# Ensure we have a path for the config file, if one wasn't specified, then use the default (top of file)
|
||||||
|
if not cli_args.CONFIG_FILE:
|
||||||
|
cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg'
|
||||||
|
|
||||||
|
# Call the external routine to build the configuration dictionary
|
||||||
|
CONFIG = config.build_config(cli_args.CONFIG_FILE)
|
||||||
|
|
||||||
|
# Start the system logger
|
||||||
|
if cli_args.LOG_LEVEL:
|
||||||
|
CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL
|
||||||
|
logger = log.config_logging(CONFIG['LOGGER'])
|
||||||
|
logger.info('\n\nCopyright (c) 2013, 2014, 2015, 2016, 2018, 2019\n\tThe Regents of the K0USY Group. All rights reserved.\n')
|
||||||
|
logger.debug('Logging system started, anything from here on gets logged')
|
||||||
|
|
||||||
|
# Set up the signal handler
|
||||||
|
def sig_handler(_signal, _frame):
|
||||||
|
logger.info('SHUTDOWN: >>>BLANK APP<<< IS TERMINATING WITH SIGNAL %s', str(_signal))
|
||||||
|
hblink_handler(_signal, _frame)
|
||||||
|
logger.info('SHUTDOWN: ALL SYSTEM HANDLERS EXECUTED - STOPPING REACTOR')
|
||||||
|
reactor.stop()
|
||||||
|
|
||||||
|
# Set signal handers so that we can gracefully exit if need be
|
||||||
|
for sig in [signal.SIGTERM, signal.SIGINT]:
|
||||||
|
signal.signal(sig, sig_handler)
|
||||||
|
|
||||||
|
# Create the name-number mapping dictionaries
|
||||||
|
peer_ids, subscriber_ids, talkgroup_ids = mk_aliases(CONFIG)
|
||||||
|
|
||||||
|
|
||||||
|
# INITIALIZE THE REPORTING LOOP
|
||||||
|
if CONFIG['REPORTS']['REPORT']:
|
||||||
|
report_server = config_reports(CONFIG, reportFactory)
|
||||||
|
else:
|
||||||
|
report_server = None
|
||||||
|
logger.info('(REPORT) TCP Socket reporting not configured')
|
||||||
|
|
||||||
|
# HBlink instance creation
|
||||||
|
logger.info('HBlink \'blank_app.py\' -- SYSTEM STARTING...')
|
||||||
|
for system in CONFIG['SYSTEMS']:
|
||||||
|
if CONFIG['SYSTEMS'][system]['ENABLED']:
|
||||||
|
if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE':
|
||||||
|
systems[system] = OPENBRIDGE(system, CONFIG, report_server)
|
||||||
|
else:
|
||||||
|
systems[system] = HBSYSTEM(system, CONFIG, report_server)
|
||||||
|
|
||||||
|
reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP'])
|
||||||
|
logger.debug('%s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system])
|
||||||
|
|
||||||
|
reactor.run()
|
@ -250,7 +250,7 @@ class routerOBP(OPENBRIDGE):
|
|||||||
self.STATUS[_stream_id]['LC'] = LC_OPT + _dst_id + _rf_src
|
self.STATUS[_stream_id]['LC'] = LC_OPT + _dst_id + _rf_src
|
||||||
|
|
||||||
|
|
||||||
logger.info('(%s) *GROUP CALL START* STREAM ID: %s SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s', \
|
logger.info('(%s) *GROUP CALL START* OBP STREAM ID: %s SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s', \
|
||||||
self._system, int_id(_stream_id), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot)
|
self._system, int_id(_stream_id), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot)
|
||||||
if CONFIG['REPORTS']['REPORT']:
|
if CONFIG['REPORTS']['REPORT']:
|
||||||
self._report.send_bridgeEvent('GROUP VOICE,START,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore'))
|
self._report.send_bridgeEvent('GROUP VOICE,START,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore'))
|
||||||
@ -949,6 +949,7 @@ class routerHBP(HBSYSTEM):
|
|||||||
# From the same group as the last TX to this HBSystem, but from a different subscriber, and it has been less than stream timeout
|
# From the same group as the last TX to this HBSystem, but from a different subscriber, and it has been less than stream timeout
|
||||||
# The "continue" at the end of each means the next iteration of the for loop that tests for matching rules
|
# The "continue" at the end of each means the next iteration of the for loop that tests for matching rules
|
||||||
#
|
#
|
||||||
|
'''
|
||||||
if ((_dst_id != _target_status[_slot]['RX_TGID']) and ((pkt_time - _target_status[_slot]['RX_TIME']) < _target_system['GROUP_HANGTIME'])):
|
if ((_dst_id != _target_status[_slot]['RX_TGID']) and ((pkt_time - _target_status[_slot]['RX_TIME']) < _target_system['GROUP_HANGTIME'])):
|
||||||
if _frame_type == HBPF_DATA_SYNC and _dtype_vseq == HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id:
|
if _frame_type == HBPF_DATA_SYNC and _dtype_vseq == HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id:
|
||||||
logger.info('(%s) Call not routed to destination %s, target active or in group hangtime: HBSystem: %s, TS: %s, DEST: %s', self._system, int_id(_dst_id), _target, _slot, int_id(_target_status[_slot]['RX_TGID']))
|
logger.info('(%s) Call not routed to destination %s, target active or in group hangtime: HBSystem: %s, TS: %s, DEST: %s', self._system, int_id(_dst_id), _target, _slot, int_id(_target_status[_slot]['RX_TGID']))
|
||||||
@ -957,6 +958,7 @@ class routerHBP(HBSYSTEM):
|
|||||||
if _frame_type == HBPF_DATA_SYNC and _dtype_vseq == HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id:
|
if _frame_type == HBPF_DATA_SYNC and _dtype_vseq == HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id:
|
||||||
logger.info('(%s) Call not routed to destination %s, target in group hangtime: HBSystem: %s, TS: %s, DEST: %s', self._system, int_id(_dst_id), _target, _slot, int_id(_target_status[_slot]['TX_TGID']))
|
logger.info('(%s) Call not routed to destination %s, target in group hangtime: HBSystem: %s, TS: %s, DEST: %s', self._system, int_id(_dst_id), _target, _slot, int_id(_target_status[_slot]['TX_TGID']))
|
||||||
continue
|
continue
|
||||||
|
'''
|
||||||
if (_dst_id == _target_status[_slot]['RX_TGID']) and ((pkt_time - _target_status[_slot]['RX_TIME']) < STREAM_TO):
|
if (_dst_id == _target_status[_slot]['RX_TGID']) and ((pkt_time - _target_status[_slot]['RX_TIME']) < STREAM_TO):
|
||||||
if _frame_type == HBPF_DATA_SYNC and _dtype_vseq == HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id:
|
if _frame_type == HBPF_DATA_SYNC and _dtype_vseq == HBPF_SLT_VHEAD and self.STATUS[_slot]['RX_STREAM_ID'] != _stream_id:
|
||||||
logger.info('(%s) Call not routed to destination %s, matching call already active on target: HBSystem: %s, TS: %s, DEST: %s', self._system, int_id(_dst_id), _target, _slot, int_id(_target_status[_slot]['RX_TGID']))
|
logger.info('(%s) Call not routed to destination %s, matching call already active on target: HBSystem: %s, TS: %s, DEST: %s', self._system, int_id(_dst_id), _target, _slot, int_id(_target_status[_slot]['RX_TGID']))
|
||||||
|
143
data_dev.py
Executable file
143
data_dev.py
Executable file
@ -0,0 +1,143 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
# Copyright (C) 2020 Cortney T. Buffington, N0MJS <n0mjs@me.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
'''
|
||||||
|
This is a blank application template to build on top of hblink.py. It contains
|
||||||
|
only the things you need to, essentially, run hblink.py underneath and do nothing
|
||||||
|
else. The expected behaviour is to override the dmrd_received function from
|
||||||
|
hblink.py to do somethign meaningful, so that framework is completed, but as
|
||||||
|
it stands, still does nothing with the DMRD packet.
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Python modules we need
|
||||||
|
import sys
|
||||||
|
from bitarray import bitarray
|
||||||
|
from time import time
|
||||||
|
from importlib import import_module
|
||||||
|
from types import ModuleType
|
||||||
|
|
||||||
|
# Twisted is pretty important, so I keep it separate
|
||||||
|
from twisted.internet.protocol import Factory, Protocol
|
||||||
|
from twisted.protocols.basic import NetstringReceiver
|
||||||
|
from twisted.internet import reactor, task
|
||||||
|
|
||||||
|
# Things we import from the main hblink module
|
||||||
|
from hblink import HBSYSTEM, OPENBRIDGE, systems, hblink_handler, reportFactory, REPORT_OPCODES, config_reports, mk_aliases, acl_check
|
||||||
|
from dmr_utils3.utils import bytes_3, int_id, get_alias
|
||||||
|
from dmr_utils3 import decode, bptc, const
|
||||||
|
import config
|
||||||
|
import log
|
||||||
|
import const
|
||||||
|
|
||||||
|
# The module needs logging logging, but handlers, etc. are controlled by the parent
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# Does anybody read this stuff? There's a PEP somewhere that says I should do this.
|
||||||
|
__author__ = 'Cortney T. Buffington, N0MJS'
|
||||||
|
__copyright__ = 'Copyright (c) 2020 Cortney T. Buffington'
|
||||||
|
__credits__ = 'Colin Durbridge, G4EML, Steve Zingman, N4IRS; Mike Zingman, N4IRR; Jonathan Naylor, G4KLX; Hans Barthen, DL5DI; Torsten Shultze, DG1HT'
|
||||||
|
__license__ = 'GNU GPLv3'
|
||||||
|
__maintainer__ = 'Cort Buffington, N0MJS'
|
||||||
|
__email__ = 'n0mjs@me.com'
|
||||||
|
__status__ = 'pre-alpha'
|
||||||
|
|
||||||
|
# Module gobal varaibles
|
||||||
|
|
||||||
|
|
||||||
|
class dataSYSTEM(HBSYSTEM):
|
||||||
|
|
||||||
|
def __init__(self, _name, _config, _report):
|
||||||
|
HBSYSTEM.__init__(self, _name, _config, _report)
|
||||||
|
|
||||||
|
def dmrd_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data):
|
||||||
|
print(_rf_src, _stream_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq)
|
||||||
|
|
||||||
|
|
||||||
|
#************************************************
|
||||||
|
# MAIN PROGRAM LOOP STARTS HERE
|
||||||
|
#************************************************
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import signal
|
||||||
|
from dmr_utils3.utils import try_download, mk_id_dict
|
||||||
|
|
||||||
|
# Change the current directory to the location of the application
|
||||||
|
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
|
||||||
|
|
||||||
|
# CLI argument parser - handles picking up the config file from the command line, and sending a "help" message
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-c', '--config', action='store', dest='CONFIG_FILE', help='/full/path/to/config.file (usually hblink.cfg)')
|
||||||
|
parser.add_argument('-l', '--logging', action='store', dest='LOG_LEVEL', help='Override config file logging level.')
|
||||||
|
cli_args = parser.parse_args()
|
||||||
|
|
||||||
|
# Ensure we have a path for the config file, if one wasn't specified, then use the default (top of file)
|
||||||
|
if not cli_args.CONFIG_FILE:
|
||||||
|
cli_args.CONFIG_FILE = os.path.dirname(os.path.abspath(__file__))+'/hblink.cfg'
|
||||||
|
|
||||||
|
# Call the external routine to build the configuration dictionary
|
||||||
|
CONFIG = config.build_config(cli_args.CONFIG_FILE)
|
||||||
|
|
||||||
|
# Start the system logger
|
||||||
|
if cli_args.LOG_LEVEL:
|
||||||
|
CONFIG['LOGGER']['LOG_LEVEL'] = cli_args.LOG_LEVEL
|
||||||
|
logger = log.config_logging(CONFIG['LOGGER'])
|
||||||
|
logger.info('\n\nCopyright (c) 2013, 2014, 2015, 2016, 2018, 2019\n\tThe Regents of the K0USY Group. All rights reserved.\n')
|
||||||
|
logger.debug('Logging system started, anything from here on gets logged')
|
||||||
|
|
||||||
|
# Set up the signal handler
|
||||||
|
def sig_handler(_signal, _frame):
|
||||||
|
logger.info('SHUTDOWN: DATA APP IS TERMINATING WITH SIGNAL %s', str(_signal))
|
||||||
|
hblink_handler(_signal, _frame)
|
||||||
|
logger.info('SHUTDOWN: ALL SYSTEM HANDLERS EXECUTED - STOPPING REACTOR')
|
||||||
|
reactor.stop()
|
||||||
|
|
||||||
|
# Set signal handers so that we can gracefully exit if need be
|
||||||
|
for sig in [signal.SIGTERM, signal.SIGINT]:
|
||||||
|
signal.signal(sig, sig_handler)
|
||||||
|
|
||||||
|
# Create the name-number mapping dictionaries
|
||||||
|
peer_ids, subscriber_ids, talkgroup_ids = mk_aliases(CONFIG)
|
||||||
|
|
||||||
|
|
||||||
|
# INITIALIZE THE REPORTING LOOP
|
||||||
|
if CONFIG['REPORTS']['REPORT']:
|
||||||
|
report_server = config_reports(CONFIG, reportFactory)
|
||||||
|
else:
|
||||||
|
report_server = None
|
||||||
|
logger.info('(REPORT) TCP Socket reporting not configured')
|
||||||
|
|
||||||
|
# HBlink instance creation
|
||||||
|
logger.info('HBlink \'data_dev.py\' -- SYSTEM STARTING...')
|
||||||
|
for system in CONFIG['SYSTEMS']:
|
||||||
|
if CONFIG['SYSTEMS'][system]['ENABLED']:
|
||||||
|
if CONFIG['SYSTEMS'][system]['MODE'] == 'OPENBRIDGE':
|
||||||
|
systems[system] = OPENBRIDGE(system, CONFIG, report_server)
|
||||||
|
else:
|
||||||
|
systems[system] = HBSYSTEM(system, CONFIG, report_server)
|
||||||
|
|
||||||
|
reactor.listenUDP(CONFIG['SYSTEMS'][system]['PORT'], systems[system], interface=CONFIG['SYSTEMS'][system]['IP'])
|
||||||
|
logger.debug('%s instance created: %s, %s', CONFIG['SYSTEMS'][system]['MODE'], system, systems[system])
|
||||||
|
|
||||||
|
reactor.run()
|
Loading…
Reference in New Issue
Block a user