示例#1
0
 private void open_handle()
 {
     handle = BeagleApi.bg_open(port);
     if (handle <= 0)
     {
         Console.WriteLine("Unable to open Beagle device on port {0}", port);
         Console.WriteLine("error: {0}", BeagleApi.bg_status_string(handle));
     }
 }
示例#2
0
        public WiiReaderV1(int controllerId)
        {
            if (!Environment.Is64BitProcess)
            {
                throw new IOException("WiiReaderV1 is only support in 64 bit RetroSpy!");
            }

            wm_rand = new byte[10];
            wm_key  = new byte[6];
            wm_ft   = new byte[8];
            wm_sb   = new byte[8];

            // Setup the Beagle
            hBeagle = BeagleApi.bg_open(controllerId);
            if (hBeagle <= 0)
            {
                throw new IOException(String.Format("WiiReaderV1 could not find Beagle USB Protocol Analyzer on port {0}.", controllerId));
            }

            isOpened = true;

            int samplerate = 10000;

            samplerate = BeagleApi.bg_samplerate(hBeagle, samplerate);
            if (samplerate < 0)
            {
                Finish();
                throw new IOException(String.Format("WiiReaderV1 error: {0:s}\n", BeagleApi.bg_status_string(samplerate)));
            }

            BeagleApi.bg_timeout(hBeagle, milliseconds: 500);
            BeagleApi.bg_latency(hBeagle, milliseconds: 0);
            BeagleApi.bg_target_power(hBeagle, BeagleApi.BG_TARGET_POWER_OFF);
            BeagleApi.bg_i2c_pullup(hBeagle, BeagleApi.BG_I2C_PULLUP_OFF);

            if (BeagleApi.bg_enable(hBeagle, BeagleProtocol.BG_PROTOCOL_I2C) != (int)BeagleStatus.BG_OK)
            {
                Finish();
                throw new IOException("WiiReaderV1 error: could not enable I2C capture\n");
            }
            isEnabled = true;

            packetPool = new I2CPacket[1024];

            for (int i = 0; i < 100; ++i)
            {
                packetPool[i] = new I2CPacket();
            }

            Thread usbParsingThread = new Thread(ProcessPacketWorker);
            Thread usbReadingThread = new Thread(ReadI2CWorker);

            usbParsingThread.Start(this);
            usbReadingThread.Start(this);
        }
示例#3
0
        public XboxReader(int controllerId)
        {
            if (!Environment.Is64BitProcess)
            {
                throw new IOException("XboxReader is only support in 64 bit RetroSpy!");
            }

            // Setup the Beagle
            hBeagle = BeagleApi.bg_open(controllerId);
            if (hBeagle <= 0)
            {
                throw new IOException(String.Format("XboxReader could not find Beagle USB Protocol Analyzer on port {0}.", controllerId));
            }

            isOpened = true;

            int samplerate = 0;

            samplerate = BeagleApi.bg_samplerate(hBeagle, samplerate);
            if (samplerate < 0)
            {
                Finish();
                throw new IOException(String.Format("XboxReader error: {0:s}\n", BeagleApi.bg_status_string(samplerate)));
            }

            BeagleApi.bg_timeout(hBeagle, milliseconds: 500);
            BeagleApi.bg_latency(hBeagle, milliseconds: 0);
            BeagleApi.bg_target_power(hBeagle, BeagleApi.BG_TARGET_POWER_OFF);

            if (BeagleApi.bg_enable(hBeagle, BeagleProtocol.BG_PROTOCOL_USB) != (int)BeagleStatus.BG_OK)
            {
                Finish();
                throw new IOException("XboxReader error: could not enable USB capture\n");
            }
            isEnabled = true;

            packetPool = new USBPacket[100];

            for (int i = 0; i < 100; ++i)
            {
                packetPool[i] = new USBPacket();
            }

            Thread usbParsingThread = new Thread(ProcessPacketWorker);
            Thread usbReadingThread = new Thread(ReadUSBWorker);

            usbParsingThread.Start(this);
            usbReadingThread.Start(this);
        }
    /*=====================================================================
     | MAIN PROGRAM
     | ====================================================================*/
    public static void Main(String[] args)
    {
        int  port    = 0;      // open port 0 by default
        uint timeout = 100;    // in milliseconds
        uint latency = 200;    // in milliseconds
        int  num     = 0;

        if (args.Length < 1)
        {
            printUsage();
            Environment.Exit(1);
        }

        num = Convert.ToInt32(args[0]);

        // Open the device
        beagle = BeagleApi.bg_open(port);
        if (beagle <= 0)
        {
            Console.Write("Unable to open Beagle device on port {0:d}\n", port);
            Console.Write("Error code = {0:d}\n", beagle);
            Environment.Exit(1);
        }
        Console.Write("Opened Beagle device on port {0:d}\n", port);

        // Query the samplerate since Beagle USB has a fixed sampling rate
        samplerateKHz = BeagleApi.bg_samplerate(beagle, samplerateKHz);
        if (samplerateKHz < 0)
        {
            Console.Write("error: {0:s}\n",
                          BeagleApi.bg_status_string(samplerateKHz));
            Environment.Exit(1);
        }
        Console.Write("Sampling rate set to {0:d} KHz.\n", samplerateKHz);

        // Set the idle timeout.
        // The Beagle read functions will return in the specified time
        // if there is no data available on the bus.
        BeagleApi.bg_timeout(beagle, timeout);
        Console.Write("Idle timeout set to {0:d} ms.\n", timeout);

        // Set the latency.
        // The latency parameter allows the programmer to balance the
        // tradeoff between host side buffering and the latency to
        // receive a packet when calling one of the Beagle read
        // functions.
        BeagleApi.bg_latency(beagle, latency);
        Console.Write("Latency set to {0:d} ms.\n", latency);

        Console.Write("Host interface is {0:s}.\n",
                      ((BeagleApi.bg_host_ifce_speed(beagle)) != 0) ?
                      "high speed" : "full speed");

        Console.Write("\n");
        Console.Out.Flush();

        // Configure the capture buffer
        usbConfigBuffer();

        // Configure the complex match
        usbConfigComplexMatch();

        usbDump(num);

        // Close the device
        BeagleApi.bg_close(beagle);

        return;
    }
示例#5
0
    /*=====================================================================
     | MAIN PROGRAM
     | ====================================================================*/
    public static void Main(String[] args)
    {
        int  port       = 0;     // open port 0 by default
        int  samplerate = 10000; // in kHz
        uint timeout    = 500;   // in milliseconds
        uint latency    = 200;   // in milliseconds
        int  len        = 0;
        int  num        = 0;

        if (args.Length < 2)
        {
            print_usage();
            Environment.Exit(1);
        }
        len = Convert.ToInt32(args[0]);
        num = Convert.ToInt32(args[1]);

        // Open the device
        beagle = BeagleApi.bg_open(port);
        if (beagle <= 0)
        {
            Console.Write("Unable to open Beagle device on port {0:d}\n",
                          port);
            Console.Write("Error code = {0:d}\n", beagle);
            Environment.Exit(1);
        }
        Console.Write("Opened Beagle device on port {0:d}\n", port);

        // Set the samplerate
        samplerate = BeagleApi.bg_samplerate(beagle, samplerate);
        if (samplerate < 0)
        {
            Console.Write("error: {0:s}\n",
                          BeagleApi.bg_status_string(samplerate));
            Environment.Exit(1);
        }
        Console.Write("Sampling rate set to {0:d} KHz.\n", samplerate);

        // Set the idle timeout.
        // The Beagle read functions will return in the specified time
        // if there is no data available on the bus.
        BeagleApi.bg_timeout(beagle, timeout);
        Console.Write("Idle timeout set to {0:d} ms.\n", timeout);

        // Set the latency.
        // The latency parameter allows the programmer to balance the
        // tradeoff between host side buffering and the latency to
        // receive a packet when calling one of the Beagle read
        // functions.
        BeagleApi.bg_latency(beagle, latency);
        Console.Write("Latency set to {0:d} ms.\n", latency);

        Console.Write("Host interface is {0:s}.\n",
                      ((BeagleApi.bg_host_ifce_speed(beagle)) != 0) ? "high speed" :
                      "full speed");
        // Configure the device for SPI
        BeagleApi.bg_spi_configure(
            beagle,
            BeagleSpiSSPolarity.BG_SPI_SS_ACTIVE_LOW,
            BeagleSpiSckSamplingEdge.BG_SPI_SCK_SAMPLING_EDGE_RISING,
            BeagleSpiBitorder.BG_SPI_BITORDER_MSB);

        // There is usually no need for target power when using the
        // Beagle as a passive monitor.
        BeagleApi.bg_target_power(beagle, BeagleApi.BG_TARGET_POWER_OFF);

        Console.Write("\n");
        Console.Out.Flush();

        spidump(len, num);

        // Close the device
        BeagleApi.bg_close(beagle);

        return;
    }