# Path: nfc/clf.py
# class ProtocolError(DigitalProtocolError): pass
# 
# class TransmissionError(DigitalProtocolError): pass
# 
# class TimeoutError(DigitalProtocolError): pass


import logging
import nfc.clf
import nfc.dev
import os
import time
import socket
import select
    import platform
from nfc.clf import ProtocolError, TransmissionError, TimeoutError
                self.socket.sendto(data, self.addr)
            else: break
            if len(select.select([self.socket], [], [], 0.1)[0]) == 1:
                data, self.addr = self.socket.recvfrom(1024)
                log.debug("<< {0} {1}".format(data.encode("hex"), self.addr))
            else: return None

        self.exchange = self.send_rsp_recv_cmd
        return target, cmd
        
    def send_cmd_recv_rsp(self, data, timeout):
        log.debug("send_cmd_recv_rsp with timeout {0} sec".format(timeout))

        # trash data if any, as on nfc we only recv future data
        rfd, wfd, xfd = select.select([self.socket], [], [], 0)
        if rfd and rfd[0] == self.socket:
            self.socket.recvfrom(1024)
        
        # send data, data should normally not be none for initiator
        if data is not None:
            log.debug(">> {0}".format(str(data).encode("hex")))
            self.socket.sendto(data, self.addr)
        
        # recv response data unless the timeout is zero
        if timeout > 0:
            rfd, wfd, xfd = select.select([self.socket], [], [], timeout)
            if rfd and rfd[0] == self.socket:
                data, self.addr = self.socket.recvfrom(1024)
                log.debug("<< {0}".format(data.encode("hex")))
                return bytearray(data) if len(data) else None

# Path: nfc/clf.py
# class ProtocolError(DigitalProtocolError): pass
# 
# class TransmissionError(DigitalProtocolError): pass
# 
# class TimeoutError(DigitalProtocolError): pass


# Path: nfc/dev/udp.py
import logging
import nfc.clf
import nfc.dev
import os
import time
import socket
import select
    import platform
from nfc.clf import ProtocolError, TransmissionError, TimeoutError

                self.socket.sendto(data, self.addr)
            else: break
            if len(select.select([self.socket], [], [], 0.1)[0]) == 1:
                data, self.addr = self.socket.recvfrom(1024)
                log.debug("<< {0} {1}".format(data.encode("hex"), self.addr))
            else: return None

        self.exchange = self.send_rsp_recv_cmd
        return target, cmd
        
    def send_cmd_recv_rsp(self, data, timeout):
        log.debug("send_cmd_recv_rsp with timeout {0} sec".format(timeout))

        # trash data if any, as on nfc we only recv future data
        rfd, wfd, xfd = select.select([self.socket], [], [], 0)
        if rfd and rfd[0] == self.socket:
            self.socket.recvfrom(1024)
        
        # send data, data should normally not be none for initiator
        if data is not None:
            log.debug(">> {0}".format(str(data).encode("hex")))
            self.socket.sendto(data, self.addr)
        
        # recv response data unless the timeout is zero
        if timeout > 0:
            rfd, wfd, xfd = select.select([self.socket], [], [], timeout)
            if rfd and rfd[0] == self.socket:
                data, self.addr = self.socket.recvfrom(1024)
                log.debug("<< {0}".format(data.encode("hex")))
                return bytearray(data) if len(data) else None

            else: log.debug("TimeoutError"); raise TimeoutError