Exemplo n.º 1
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);
        }
Exemplo n.º 2
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;
        byte pullups    = BeagleApi.BG_I2C_PULLUP_OFF;
        byte target_pow = BeagleApi.BG_TARGET_POWER_OFF;
        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");

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

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

        i2cdump(len, num);

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

        return;
    }