<s> """<STR_LIT>""" <EOL> from collections import defaultdict <EOL> from bacpypes . debugging import bacpypes_debugging , ModuleLogger <EOL> from bacpypes . consolelogging import ConfigArgumentParser <EOL> from bacpypes . core import run <EOL> from bacpypes . app import LocalDeviceObject , BIPSimpleApplication <EOL> _debug = <NUM_LIT:0> <EOL> _log = ModuleLogger ( globals ( ) ) <EOL> this_device = None <EOL> this_application = None <EOL> who_has_counter = defaultdict ( int ) <EOL> i_have_counter = defaultdict ( int ) <EOL> @ bacpypes_debugging <EOL> class WhoHasIHaveApplication ( BIPSimpleApplication ) : <EOL> def __init__ ( self , device , address ) : <EOL> if _debug : WhoHasIHaveApplication . _debug ( "<STR_LIT>" , device , address ) <EOL> BIPSimpleApplication . __init__ ( self , device , address ) <EOL> def do_WhoHasRequest ( self , apdu ) : <EOL> """<STR_LIT>""" <EOL> if _debug : WhoHasIHaveApplication . _debug ( "<STR_LIT>" , apdu ) <EOL> key = ( str ( apdu . pduSource ) , ) <EOL> if apdu . object . objectIdentifier is not None : <EOL> key += ( str ( apdu . object . objectIdentifier ) , ) <EOL> elif apdu . object . objectName is not None : <EOL> key += ( apdu . object . objectName , ) <EOL> else : <EOL> print "<STR_LIT>" <EOL> apdu . debug_contents ( ) <EOL> print "<STR_LIT:)>" <EOL> return <EOL> who_has_counter [ key ] += <NUM_LIT:1> <EOL> def do_IHaveRequest ( self , apdu ) : <EOL> """<STR_LIT>""" <EOL> if _debug : WhoHasIHaveApplication . _debug ( "<STR_LIT>" , apdu ) <EOL> key = ( <EOL> str ( apdu . pduSource ) , <EOL> str ( apdu . deviceIdentifier ) , <EOL> str ( apdu . objectIdentifier ) , <EOL> apdu . objectName <EOL> ) <EOL> i_have_counter [ key ] += <NUM_LIT:1> <EOL> try : <EOL> args = ConfigArgumentParser ( description = __doc__ ) . parse_args ( ) <EOL> if _debug : _log . debug ( "<STR_LIT>" ) <EOL> if _debug : _log . debug ( "<STR_LIT>" , args ) <EOL> this_device = LocalDeviceObject ( <EOL> objectName = args . ini . objectname , <EOL> objectIdentifier = int ( args . ini . objectidentifier ) , <EOL> maxApduLengthAccepted = int ( args . ini . maxapdulengthaccepted ) , <EOL> segmentationSupported = args . ini . segmentationsupported , <EOL> vendorIdentifier = int ( args . ini . vendoridentifier ) , <EOL> ) <EOL> this_application = WhoHasIHaveApplication ( this_device , args . ini . address ) <EOL> services_supported = this_application . get_services_supported ( ) <EOL> if _debug : _log . debug ( "<STR_LIT>" , services_supported ) <EOL> this_device . protocolServicesSupported = services_supported . value <EOL> _log . debug ( "<STR_LIT>" ) <EOL> run ( ) <EOL> print "<STR_LIT>" <EOL> for ( src , objname ) , count in sorted ( who_has_counter . items ( ) ) : <EOL> print "<STR_LIT>" % ( src , objname , count ) <EOL> print <EOL> print "<STR_LIT>" <EOL> for ( src , devid , objid , objname ) , count in sorted ( i_have_counter . items ( ) ) : <EOL> print "<STR_LIT>" % ( src , devid , objid , objname , count ) <EOL> print <EOL> except Exception , e : <EOL> _log . exception ( "<STR_LIT>" , e ) <EOL> finally : <EOL> _log . debug ( "<STR_LIT>" ) </s>
