def __init__(self): if _debug: MiddleMan._debug("__init__") Client.__init__(self) Server.__init__(self) # not connected self.connected = False
def __init__(self): if _debug: TrappedServer._debug("__init__") Server.__init__(self) # clear out some references self.indication_received = None self.response_sent = None
def __init__(self, host='', port=502, **kwargs): if _debug: ModbusServer._debug("__init__ host=%r port=%r %r", host, port, kwargs) Client.__init__(self) Server.__init__(self) # create and bind self.serverDirector = TCPServerDirector((host, port), **kwargs) bind(self, StreamToPacket(stream_to_packet), self.serverDirector)
def response(self, pdu): if _debug: TrappedServer._debug("response %r", pdu) # a reference for checking self.response_sent = pdu # continue with processing Server.response(self, pdu)
def __init__(self, sapID=None, cid=None, sid=None): """A MSTP node.""" if _debug: MSTPSimple._debug("__init__ sapID=%r cid=%r sid=%r", sapID, cid, sid) MSTPSAP.__init__(self, sapID) Client.__init__(self, cid) Server.__init__(self, sid)
def __init__(self, **kwargs): """Initialize a MODBUS client.""" if _debug: ModbusClient._debug("__init__ %r", kwargs) Client.__init__(self) Server.__init__(self) # create and bind the client side self.director = TCPClientDirector(**kwargs) bind(self, StreamToPacket(stream_to_packet), self.director)
def __init__(self, **terminals): if _debug: Switch._debug("__init__ %r", terminals) Client.__init__(self) Server.__init__(self) # wrap the terminals self.terminals = {k:Switch.TerminalWrapper(self, v) for k, v in terminals.items()} self.current_terminal = None
def __init__(self, **kwargs): """Initialize a MODBUS client.""" if _debug: ModbusClient._debug("__init__ %r", kwargs) Client.__init__(self) Server.__init__(self) # create and bind the client side self.clientDirector = TCPClientDirector(**kwargs) bind(self, StreamToPacket(stream_to_packet), self.clientDirector)
def __init__( self, lan, client, host=default_broker_host, port=default_broker_port, keepalive=default_broker_keepalive, sap=None, sid=None, ): if _debug: MQTTClient._debug( "__init__ %r %r %r %r %r", lan, client, host, port, keepalive ) ServiceAccessPoint.__init__(self, sap) Server.__init__(self, sid) # save the lan and client address self.lan = lan self.client = client # save the connection parameters self.host = host self.port = port self.keepalive = keepalive # create a client and set the callbacks self.mqtt_client = _paho_mqtt.Client() self.mqtt_client.on_connect = self.on_connect self.mqtt_client.on_disconnect = self.on_disconnect self.mqtt_client.on_subscribe = self.on_subscribe self.mqtt_client.on_message = self.on_message self.mqtt_client.on_publish = self.on_publish self.mqtt_client.on_unsubscribe = self.on_unsubscribe # we are not connected self.mqtt_connected = False self.local_topic = self.lan + "/" + addr2topic(client) if _debug: MQTTClient._debug(" - local topic: %r", self.local_topic) self.broadcast_topic = self.lan + "/" + BROADCAST_TOPIC if _debug: MQTTClient._debug(" - broadcast topic: %r", self.broadcast_topic) # build a LostConnection last will, encode it lost_connection = LostConnection(self.client) # set the last will response = self.mqtt_client.will_set( self.broadcast_topic, lost_connection.as_bytes(), 0, False ) if _debug: MQTTClient._debug(" - will_set: %r", response)
def __init__(self, port=502, sapID=None): if _debug: ModbusServiceAccessPoint._debug("__init__ port=%r sapID=%r", port, sapID) Client.__init__(self) Server.__init__(self) ServiceAccessPoint.__init__(self, sapID) # create and bind the client side self.clientDirector = TCPClientDirector() bind(self, StreamToPacket(stream_to_packet), self.clientDirector) # create and bind the server side self.serverDirector = TCPServerDirector(port) bind(self.serverDirector, StreamToPacket(stream_to_packet), self)
def __init__(self, addr, network, cid=None, sid=None): if _debug: FauxMux._debug("__init__") Client.__init__(self, cid) Server.__init__(self, sid) # get the unicast and broadcast tuples self.unicast_tuple = addr.addrTuple self.broadcast_tuple = addr.addrBroadcastTuple # make an internal node and bind to it, this takes the place of # both the direct port and broadcast port of the real UDPMultiplexer self.node = IPNode(addr, network) bind(self, self.node)
def __init__(self, name=''): if _debug: ServerStateMachine._debug("__init__") Server.__init__(self) StateMachine.__init__(self, name=name)
def __init__(self): Client.__init__(self) Server.__init__(self) ConsoleCmd.__init__(self)
def __init__(self): if _debug: ServerStateMachine._debug("__init__") Server.__init__(self) StateMachine.__init__(self)
def __init__(self): if _debug: NPDUCodec._debug("__init__") Client.__init__(self) Server.__init__(self)
def __init__( self, localDevice, address, timeout=0, reuse=False, actorClass=UDPActor, sid=None, sapID=None ): if _debug: MSTPDirector._debug( "__init__ %r timeout=%r reuse=%r actorClass=%r sid=%r sapID=%r", address, timeout, reuse, actorClass, sid, sapID ) Server.__init__(self, sid) ServiceAccessPoint.__init__(self, sapID) # check the actor class if not issubclass(actorClass, UDPActor): raise TypeError("actorClass must be a subclass of UDPActor") self.actorClass = actorClass # save the timeout for actors self.timeout = timeout # save the localDevice self.localDevice = localDevice # save the address self.address = address interface_filename = os.path.basename(self.localDevice._interface) interface_devname = self.localDevice._interface asyncore.dispatcher.__init__(self) # ask the dispatcher for a socket self.create_socket(socket.AF_UNIX, socket.SOCK_DGRAM) # if the reuse parameter is provided, set the socket option if reuse: self.set_reuse_addr() # proceed with the bind if hasattr(self.localDevice, '_mstp_dir'): mstp_dir = self.localDevice._mstp_dir else: mstp_dir = '/var/tmp' mstp_dir = tempfile.mkdtemp(prefix="ma_",dir=mstp_dir) MSTPDirector.mstp_dir = mstp_dir my_addr = '{}/mstp{}'.format(mstp_dir, interface_filename) try: os.remove(my_addr) except: pass # Call the library to init the mstp_agent dirname=os.path.dirname(__file__) libname = "libmstp_agent_{}.so".format(platform.system().lower()) libmstp_path=os.path.join(dirname, libname) mstp_lib = cdll.LoadLibrary(libmstp_path) MSTPDirector.mstp_lib = mstp_lib self.bind(my_addr) if _debug: MSTPDirector._debug(" - getsockname: %r", self.socket.getsockname()) # allow it to send broadcasts self.socket.setsockopt( socket.SOL_SOCKET, socket.SO_BROADCAST, 1 ) # create the request queue self.request = queue.Queue() # start with an empty peer pool self.peers = {} #send control stuff # 0x5 - Mac Address # 127 - Max Masters # 38400 - Baud rate # 0x1 - Max info Frames mac = str(self.address) mac = int(mac) max_masters = self.localDevice._max_masters baud_rate = self.localDevice._baudrate maxinfo = self.localDevice._maxinfo buf = struct.pack('iiii', mac, max_masters, baud_rate, maxinfo); if hasattr(self.localDevice, '_mstpdbgfile'): fname = self.localDevice._mstpdbgfile if six.PY3: mstp_lib.enable_debug_flag(six.ensure_binary(fname)) else: mstp_lib.enable_debug_flag(fname) if six.PY3: interface_devname_b = six.ensure_binary(interface_devname) mstp_dir_b=six.ensure_binary(mstp_dir) mstp_lib.init(buf, interface_devname_b, mstp_dir_b) else: mstp_lib.init(buf, interface_devname, mstp_dir) # to ensure that the server is ready time.sleep(0.5) # server to send the MSTP PDU's self.server_address = '{}/mstp_server'.format(mstp_dir) self.socket.connect(self.server_address)