コード例 #1
0
    def handle_read(self):
        if _debug: MSTPDirector._debug("handle_read")

        try:
            msg, addr = self.socket.recvfrom(512)
            if _debug: MSTPDirector._debug("    - received %d octets ", len(msg))
            pdu = PDU(msg,destination=int(str(self.address)))
            mstp_src = pdu.get()
            pdu.pduSource = Address(mstp_src)

            if _debug: MSTPDirector._debug("Received MSTP PDU={}".format(str(pdu)))

            # send the PDU up to the client
            deferred(self._response, pdu)

        except socket.timeout as err:
            if _debug: MSTPDirector._debug("    - socket timeout: %s", err)

        except socket.error as err:
            if err.args[0] == 11:
                pass
            else:
                if _debug: MSTPDirector._debug("    - socket error: %s", err)

                # pass along to a handler
                self.handle_error(err)

        except Exception as e:
            MSTPDirector._error('Exception in handle_read: {}'.format(e))
コード例 #2
0
    # Add debugging into the middle of the stack
    # Upstream when traveling from server to client
    # Downstream when traveling from client to server
    d = Debug("middle")
    bind(client, d, server)
    client.request('Hi')

#%% Protocol data units

from bacpypes.comm import PDU

pdu = PDU(b'hello')  # Data portion of PDU only
pdu.debug_contents()
# Add source and destination information
pdu = PDU(b'hello', source=1, destination=2)
pdu.pduSource = 1
pdu.pduDestination = 2
pdu.debug_contents()

# Encoding and decoding a PDU
"""THis process consists of consuming content from a PDU (data, source, destination)
and generating content in the destination
Think if Decoding a PDU like taking characters out of an array
Encoding a PDU is like stacking characters into an array"""
pdu = PDU(b'hello!!!', source=1, destination=2)
pdu.debug_contents()
pdu.get()  # 104
pdu.get_short()  # 25964
pdu.get_long()  # 1819222305

pdu.put_long(1819222305)