Пример #1
0
class LUNABackend(ViewSBBackend):
    """ Capture backend that captures packets from a LUNA board. """

    UI_NAME = "luna"
    UI_DESCRIPTION = "LUNA hardware analyzers"

    @staticmethod
    def reason_to_be_disabled():

        # If we can't import LUNA, it's probably not installed.
        if not 'USBAnalyzerConnection' in globals():
            return "python luna package not available"

        return None

    @staticmethod
    def speed_from_string(string):

        try:
            return SPEEDS[string]
        except KeyError:
            return string

    @classmethod
    def add_options(cls, parser):

        # Parse user input and try to extract our class options.
        parser.add_argument('--speed',
                            dest='capture_speed',
                            default='high',
                            choices=SPEEDS.keys(),
                            help="The speed of the USB data to capture.")

    def __init__(self, capture_speed, suppress_packet_callback=None):
        """ Creates a new LUNA capture backend.

        Args:
            capture_speed -- The speed at which to capture.
        """

        super().__init__()

        # TODO: validate
        self.capture_speed = self.speed_from_string(capture_speed)

        # Set up our connection to the analyzer.
        self.analyzer = USBAnalyzerConnection()

        # Build our analyzer gateware, and configure our FPGA.
        self.analyzer.build_and_configure(self.capture_speed)

    def run_capture(self):

        # Capture a single packet from LUNA.
        raw_packet, timestamp, _ = self.analyzer.read_raw_packet()

        # TODO: handle flags
        packet = USBPacket.from_raw_packet(raw_packet, timestamp=timestamp)
        self.emit_packet(packet)
Пример #2
0
    def __init__(self, capture_speed, suppress_packet_callback=None):
        """ Creates a new LUNA capture backend.

        Args:
            capture_speed -- The speed at which to capture.
        """

        super().__init__()

        # TODO: validate
        self.capture_speed = self.speed_from_string(capture_speed)

        # Set up our connection to the analyzer.
        self.analyzer = USBAnalyzerConnection()
Пример #3
0
    def __init__(self, capture_speed, suppress_packet_callback=None):
        """ Creates a new LUNA capture backend.

        Args:
            capture_speed -- The speed at which to capture.
        """

        # TODO: validate
        self.capture_speed = capture_speed

        # Set up our connection to the analyzer.
        self.analyzer = USBAnalyzerConnection()

        # Build our analyzer gateware, and configure our FPGA.
        self.analyzer.build_and_configure(capture_speed)
Пример #4
0
class LUNABackend(ViewSBBackend):
    """ Capture backend that captures packets from a LUNA board. """

    UI_NAME = "luna"
    UI_DESCRIPTION = "LUNA hardware analyzers"

    @staticmethod
    def reason_to_be_disabled():

        # If we can't import LUNA, it's probably not installed.
        if not 'USBAnalyzerConnection' in globals():
            return "python luna package not available"

        return None

    @staticmethod
    def speed_from_string(string):
        speeds = {
            'high': USB_SPEED_HIGH,
            'full': USB_SPEED_FULL,
            'low': USB_SPEED_LOW
        }

        try:
            return speeds[string]
        except KeyError:
            return None

    @classmethod
    def parse_arguments(cls, args, parent_parser=[]):

        # Parse user input and try to extract our class options.
        parser = argparse.ArgumentParser(parents=parent_parser, add_help=False)
        parser.add_argument(
            '--speed',
            type=cls.speed_from_string,
            default='high',
            help=
            "the speed of the USB data to capture [valid: {high, full, low}]")
        args, leftover_args = parser.parse_known_args()

        if args.speed is None:
            sys.stderr.write("speed must be 'high', 'full', or 'low'\n")
            sys.exit(errno.EINVAL)

        #  Return the class and leftover arguments.
        return (args.speed, ), leftover_args

    def __init__(self, capture_speed, suppress_packet_callback=None):
        """ Creates a new LUNA capture backend.

        Args:
            capture_speed -- The speed at which to capture.
        """

        # TODO: validate
        self.capture_speed = capture_speed

        # Set up our connection to the analyzer.
        self.analyzer = USBAnalyzerConnection()

        # Build our analyzer gateware, and configure our FPGA.
        self.analyzer.build_and_configure(capture_speed)

    def run_capture(self):

        # Capture a single packet from LUNA.
        raw_packet, timestamp, _ = self.analyzer.read_raw_packet()

        # TODO: handle flags
        packet = USBPacket.from_raw_packet(raw_packet, timestamp=timestamp)
        self.emit_packet(packet)