Better Processing of MODE and FLAGS

This commit is contained in:
Cort Buffington 2013-12-12 16:12:36 -06:00
parent d9cf7c3b8a
commit 101c627d3f
1 changed files with 53 additions and 34 deletions

View File

@ -83,7 +83,6 @@ except ImportError:
# PARSE THE CONFIG FILE AND BUILD STRUCTURE # PARSE THE CONFIG FILE AND BUILD STRUCTURE
#************************************************ #************************************************
networks = {}
NETWORK = {} NETWORK = {}
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
@ -122,11 +121,9 @@ try:
NETWORK[section]['MASTER'].update({ NETWORK[section]['MASTER'].update({
'RADIO_ID': '\x00\x00\x00\x00', 'RADIO_ID': '\x00\x00\x00\x00',
'MODE': '\x00', 'MODE': '\x00',
'PEER_OPER': False, 'MODE_DECODE': '',
'PEER_MODE': '',
'TS1_LINK': False,
'TS2_LINK': False,
'FLAGS': '\x00\x00\x00\x00', 'FLAGS': '\x00\x00\x00\x00',
'FLAGS_DECODE': '',
'STATUS': { 'STATUS': {
'CONNECTED': False, 'CONNECTED': False,
'PEER_LIST': False, 'PEER_LIST': False,
@ -273,16 +270,16 @@ def process_flags_bytes(_hex_flags):
_master = bool(_byte4 & MSTR_PEER_MSK) _master = bool(_byte4 & MSTR_PEER_MSK)
return { return {
'CSBK Calls': _csbk, 'CSBK': _csbk,
'Repeater Monitor': _rpt_mon, 'RCM': _rpt_mon,
'3rd Party App': _con_app, 'CON_APP': _con_app,
'XNL Connected': _xnl_con, 'XNL_CON': _xnl_con,
'XNL Master': _xnl_master, 'XNL_MASTER': _xnl_master,
'XNL Slave': _xnl_slave, 'XNL_SLAVE': _xnl_slave,
'Authentication': _auth, 'AUTH': _auth,
'Data Calls': _data, 'DATA': _data,
'Voice Calls': _voice, 'VOICE': _voice,
'Master Peer': _master 'MASTER': _master
} }
@ -318,17 +315,16 @@ def process_peer_list(_data, _network):
# This means we'll re-register with a peer who we may have already been registered with, but # This means we'll re-register with a peer who we may have already been registered with, but
# that doesn't appear to hurt anything. # that doesn't appear to hurt anything.
NETWORK[_network]['PEERS'][_hex_radio_id] = { NETWORK[_network]['PEERS'][_hex_radio_id] = {
'IP': _ip_address, 'IP': _ip_address,
'PORT': _port, 'PORT': _port,
'MODE': _hex_mode, 'MODE': _hex_mode,
'PEER_OPER': _decoded_mode['PEER_OP'], 'MODE_DECODE': _decoded_mode,
'PEER_MODE': _decoded_mode['PEER_MODE'], 'FLAGS': '',
'TS1_LINK': _decoded_mode['TS_1'], 'FLAGS_DECODE': '',
'TS2_LINK': _decoded_mode['TS_2'],
'STATUS': { 'STATUS': {
'CONNECTED': False, 'CONNECTED': False,
'KEEP_ALIVES_SENT': 0, 'KEEP_ALIVES_SENT': 0,
'KEEP_ALIVES_MISSED': 0, 'KEEP_ALIVES_MISSED': 0,
'KEEP_ALIVES_OUTSTANDING': 0 'KEEP_ALIVES_OUTSTANDING': 0
} }
} }
@ -367,7 +363,14 @@ def print_peer_list(_network):
print('\tRADIO ID: {} {}' .format(int(h(peer), 16), me)) print('\tRADIO ID: {} {}' .format(int(h(peer), 16), me))
print('\t\tIP Address: {}:{}' .format(_this_peer['IP'], _this_peer['PORT'])) print('\t\tIP Address: {}:{}' .format(_this_peer['IP'], _this_peer['PORT']))
print('\t\tOperational: {}, Mode: {}, TS1 Link: {}, TS2 Link: {}' .format(_this_peer['PEER_OPER'], _this_peer['PEER_MODE'], _this_peer['TS1_LINK'], _this_peer['TS2_LINK'])) if _this_peer['MODE_DECODE']:
print('\t\tMode Values:')
for name, value in _this_peer['MODE_DECODE'].items():
print('\t\t\t{}: {}' .format(name, value))
if _this_peer['FLAGS_DECODE']:
print('\t\tService Flags:')
for name, value in _this_peer['FLAGS_DECODE'].items():
print('\t\t\t{}: {}' .format(name, value))
print('\t\tStatus: {}, KeepAlives Sent: {}, KeepAlives Outstanding: {}, KeepAlives Missed: {}' .format(_this_peer_stat['CONNECTED'], _this_peer_stat['KEEP_ALIVES_SENT'], _this_peer_stat['KEEP_ALIVES_OUTSTANDING'], _this_peer_stat['KEEP_ALIVES_MISSED'])) print('\t\tStatus: {}, KeepAlives Sent: {}, KeepAlives Outstanding: {}, KeepAlives Missed: {}' .format(_this_peer_stat['CONNECTED'], _this_peer_stat['KEEP_ALIVES_SENT'], _this_peer_stat['KEEP_ALIVES_OUTSTANDING'], _this_peer_stat['KEEP_ALIVES_MISSED']))
print('') print('')
@ -378,8 +381,14 @@ def print_master(_network):
_master = NETWORK[_network]['MASTER'] _master = NETWORK[_network]['MASTER']
print('Master for %s' % _network) print('Master for %s' % _network)
print('\tRADIO ID: {}' .format(int(h(_master['RADIO_ID']), 16))) print('\tRADIO ID: {}' .format(int(h(_master['RADIO_ID']), 16)))
print('\t\tIP Address: {}:{}' .format(_master['IP'], _master['PORT'])) if _master['MODE_DECODE']:
print('\t\tOperational: {}, Mode: {}, TS1 Link: {}, TS2 Link: {}' .format(_master['PEER_OPER'], _master['PEER_MODE'], _master['TS1_LINK'], _master['TS2_LINK'])) print('\t\tMode Values:')
for name, value in _master['MODE_DECODE'].items():
print('\t\t\t{}: {}' .format(name, value))
if _master['FLAGS_DECODE']:
print('\t\tService Flags:')
for name, value in _master['FLAGS_DECODE'].items():
print('\t\t\t{}: {}' .format(name, value))
print('\t\tStatus: {}, KeepAlives Sent: {}, KeepAlives Outstanding: {}, KeepAlives Missed: {}' .format(_master['STATUS']['CONNECTED'], _master['STATUS']['KEEP_ALIVES_SENT'], _master['STATUS']['KEEP_ALIVES_OUTSTANDING'], _master['STATUS']['KEEP_ALIVES_MISSED'])) print('\t\tStatus: {}, KeepAlives Sent: {}, KeepAlives Outstanding: {}, KeepAlives Missed: {}' .format(_master['STATUS']['CONNECTED'], _master['STATUS']['KEEP_ALIVES_SENT'], _master['STATUS']['KEEP_ALIVES_OUTSTANDING'], _master['STATUS']['KEEP_ALIVES_MISSED']))
@ -756,6 +765,15 @@ class IPSC(DatagramProtocol):
# Packets we send... # Packets we send...
if _packettype == PEER_ALIVE_REQ: if _packettype == PEER_ALIVE_REQ:
_hex_mode = (data[5])
_hex_flags = (data[6:10])
_decoded_mode = process_mode_byte(_hex_mode)
_decoded_flags = process_flags_bytes(_hex_flags)
self._peers[_peerid]['MODE'] = _hex_mode
self._peers[_peerid]['MODE_DECODE'] = _decoded_mode
self._peers[_peerid]['FLAGS'] = _hex_flags
self._peers[_peerid]['FLAGS_DECODE'] = _decoded_flags
# Generate a hashed packet from our template and send it. # Generate a hashed packet from our template and send it.
peer_alive_reply_packet = self.hashed_packet(self._local['AUTH_KEY'], self.PEER_ALIVE_REPLY_PKT) peer_alive_reply_packet = self.hashed_packet(self._local['AUTH_KEY'], self.PEER_ALIVE_REPLY_PKT)
self.transport.write(peer_alive_reply_packet, (host, port)) self.transport.write(peer_alive_reply_packet, (host, port))
@ -802,15 +820,16 @@ class IPSC(DatagramProtocol):
# When we hear from the master, record it's ID, flag that we're connected, and reset the dead counter. # When we hear from the master, record it's ID, flag that we're connected, and reset the dead counter.
elif _packettype == MASTER_REG_REPLY: elif _packettype == MASTER_REG_REPLY:
_hex_mode = (data[5]) _hex_mode = (data[5])
_decoded_mode = process_mode_byte(_hex_mode) _hex_flags = (data[6:10])
_decoded_mode = process_mode_byte(_hex_mode)
_decoded_flags = process_flags_bytes(_hex_flags)
self._master['RADIO_ID'] = _peerid self._master['RADIO_ID'] = _peerid
self._master['MODE'] = _hex_mode self._master['MODE'] = _hex_mode
self._master['PEER_OPER'] = _decoded_mode['PEER_OP'] self._master['MODE_DECODE'] = _decoded_mode
self._master['PEER_MODE'] = _decoded_mode['PEER_MODE'] self._master['FLAGS'] = _hex_flags
self._master['TS1_LINK'] = _decoded_mode['TS_1'] self._master['FLAGS_DECODE'] = _decoded_flags
self._master['TS2_LINK'] = _decoded_mode['TS_2']
self._master_stat['CONNECTED'] = True self._master_stat['CONNECTED'] = True
self._master_stat['KEEP_ALIVES_OUTSTANDING'] = 0 self._master_stat['KEEP_ALIVES_OUTSTANDING'] = 0
return return