Exemplo n.º 1
0
    def waitForPacket(self, packetType, subSystem, command, timeout=3):
        packet = None
        currentTime = time.time()
        while not packet or \
                (not packet.isPacketValid(packetType, subSystem, command) and
                 not packet.isPacketError()):
            if time.time() - currentTime > timeout:
                raise TimeoutError

            try:
                bytes = self.device.receivePacket()
                if bytes:
                    packet = NebResponsePacket(bytes)
                else:
                    packet = None
            except NotImplementedError as e:
                logging.error("Dropped bad packet.")
                packet = None
                continue
            except InvalidPacketFormatError as e:
                logging.error("InvalidPacketFormatError")
                packet = None
                continue
            except CRCError as e:
                logging.error("CRCError : " + str(e))
                packet = None
                continue
            except KeyError as e:
                logging.error(
                    "Tried creating a packet with an invalid subsystem or command : "
                    + str(e))
                packet = None
                continue
            except TimeoutError as e:
                logging.error('Read timed out.')
                return NebResponsePacket.createEmptyResponsePacket(
                    subSystem, command)
            except KeyboardInterrupt as e:
                logging.error("KeyboardInterrupt.")
                return NebResponsePacket.createEmptyResponsePacket(
                    subSystem, command)
            except:
                packet = None
                logging.error("Unexpected error : ", exc_info=True)
                return NebResponsePacket.createEmptyResponsePacket(
                    subSystem, command)
        return packet
Exemplo n.º 2
0
    def waitForPacket(self, packetType, subSystem, command, timeout=3):
        packet = None
        currentTime = time.time()
        while not packet or \
                (not packet.isPacketValid(packetType, subSystem, command) and
                 not packet.isPacketError()):
            if time.time() - currentTime > timeout:
                raise TimeoutError

            try:
                bytes = self.device.receivePacket()
                if bytes:
                    packet = NebResponsePacket(bytes)
                else:
                    packet = None
            except NotImplementedError as e:
                logging.error("Dropped bad packet.")
                packet = None
                continue
            except InvalidPacketFormatError as e:
                logging.error("InvalidPacketFormatError")
                packet = None
                continue
            except CRCError as e:
                logging.error("CRCError : " + str(e))
                packet = None
                continue
            except KeyError as e:
                logging.error("Tried creating a packet with an invalid subsystem or command : " + str(e))
                packet = None
                continue
            except TimeoutError as e:
                logging.error('Read timed out.')
                return NebResponsePacket.createEmptyResponsePacket(subSystem, command)
            except KeyboardInterrupt as e:
                logging.error("KeyboardInterrupt.")
                return NebResponsePacket.createEmptyResponsePacket(subSystem, command)
            except:
                packet = None
                logging.error("Unexpected error : ", exc_info=True)
                return NebResponsePacket.createEmptyResponsePacket(subSystem, command)
        return packet