Work on adding timers

transmission resets and reciprocal actions not yet completed, but
basics are here.
This commit is contained in:
Cort Buffington 2016-08-06 10:58:53 -05:00
parent fffdd01dd2
commit 2e06ece1f3
2 changed files with 27 additions and 7 deletions

View File

@ -88,9 +88,8 @@ for _ipsc in RULES_FILE:
_rule['ON'][i] = hex_str_3(_rule['ON'][i])
for i, e in enumerate(_rule['OFF']):
_rule['OFF'][i] = hex_str_3(_rule['OFF'][i])
_rule['ON_TIMEOUT']= _rule['ON_TIMEOUT']*60
_rule['OFF_TIMEOUT'] = _rule['OFF_TIMEOUT']*60
_rule['TIMER'] = time()
_rule['TIMEOUT']= _rule['TIMEOUT']*60
_rule['TIMER'] = time() + _rule['TIMEOUT']
if _ipsc not in NETWORK:
sys.exit('ERROR: Bridge rules found for an IPSC network not configured in main configuration')
for _ipsc in NETWORK:
@ -144,7 +143,22 @@ else:
# Run this every minute for rule timer updates
def rule_timer_loop():
pass
logger.debug('Rule timer loop started')
_now = time()
for _network in RULES:
for _rule in RULES[_network]['GROUP_VOICE']:
if _rule['TO_TYPE'] == 'ON':
if _rule['ACTIVE'] == True:
if _rule['TIMER'] < _now:
_rule['ACTIVE'] = False
logger.info('(%s) Rule timout DEACTIVATE: Rule name: %s, Target IPSC: %s, TS: %s, TGID: %s', _network, _rule['NAME'], _rule['DST_NET'], _rule['DST_TS']+1, int_id(_rule['DST_GROUP']))
elif _rule['TO_TYPE'] == 'OFF':
if _rule['ACTIVE'] == False:
if _rule['TIMER'] < _now:
_rule['ACTIVE'] = True
logger.info('(%s) Rule timout ACTIVATE: Rule name: %s, Target IPSC: %s, TS: %s, TGID: %s', _network, _rule['NAME'], _rule['DST_NET'], _rule['DST_TS']+1, int_id(_rule['DST_GROUP']))
else:
logger.debug('Rule timer loop made no rule changes')
class bridgeIPSC(IPSC):
def __init__(self, *args, **kwargs):
@ -319,10 +333,10 @@ class bridgeIPSC(IPSC):
# Action happens on un-key
if _burst_data_type == BURST_DATA_TYPE['VOICE_TERM']:
_now = time()
# Iterate the rules dictionary
for rule in RULES[_network]['GROUP_VOICE']:
rule['TIMER'] = time()
# TGID matches an ACTIVATION trigger
if _dst_group in rule['ON']:

View File

@ -27,6 +27,12 @@ NOTES:
* ACTIVE should be set to True if you want the rule active by default, False to be inactive
* ON and OFF are LISTS of Talkgroup IDs used to trigger this rule off and on. Even if you
only want one (as shown in the ON example), it has to be in list format.
* TO_TYPE is timeout type. If you want to use timers, ON means when it's turned on, it will
turn off afer the timout period and OFF means it will turn back on after the timout
period. If you don't want to use timers, set it to anything else, but 'NONE' might be
a good value for documentation!
* TIMOUT is a value in minutes for the timout timer. No, I won't make it 'seconds', so don't
ask. Timers are performance "expense".
'''
RULES = {
@ -34,7 +40,7 @@ RULES = {
'TRUNK': False,
'GROUP_HANGTIME': 5,
'GROUP_VOICE': [
{'NAME': 'STATEWIDE', 'ACTIVE': False, 'ON': [8,], 'OFF': [9,10], 'SRC_TS': 1, 'SRC_GROUP': 1, 'DST_NET': 'IPSC_BAR', 'DST_TS': 2, 'DST_GROUP': 2},
{'NAME': 'STATEWIDE', 'ACTIVE': False, 'TO_TYPE': 'ON', 'TIMEOUT': 2, 'ON': [8,], 'OFF': [9,10], 'SRC_TS': 1, 'SRC_GROUP': 1, 'DST_NET': 'IPSC_BAR', 'DST_TS': 2, 'DST_GROUP': 2},
# Send the IPSC_FOO network Time Slice 1, Talk Group 1 to the IPSC_BAR network on Time Slice 2 Talk Group 2
# Repeat the above line for as many rules for this IPSC network as you want.
],
@ -45,7 +51,7 @@ RULES = {
'TRUNK': False,
'GROUP_HANGTIME': 5,
'GROUP_VOICE': [
{'NAME': 'STATEWIDE', 'ACTIVE': False, 'ON': [8,], 'OFF': [9,10], 'SRC_TS': 2, 'SRC_GROUP': 2, 'DST_NET': 'IPSC_FOO', 'DST_TS': 1, 'DST_GROUP': 1},
{'NAME': 'STATEWIDE', 'ACTIVE': False, 'TO_TYPE': 'ON', 'TIMEOUT': 2, 'ON': [8,], 'OFF': [9,10], 'SRC_TS': 2, 'SRC_GROUP': 2, 'DST_NET': 'IPSC_FOO', 'DST_TS': 1, 'DST_GROUP': 1},
# Send the IPSC_BAR network Time Slice 2, Talk Group 2 to the IPSC_FOO network on Time Slice 1 Talk Group 1
# Repeat the above line for as many rules for this IPSC network as you want.
],