Example #1
0
        public bool Verify(uint address, byte[] data)
        {
            const uint sectorSIZE = 0x20000; // 128KB blocks
            var        start      = address;

            LibMain.UpdateStatus("Verifying... sector) 0x{0:X}", address);

            var tempData = new byte[sectorSIZE];

            for (uint i = 0; i < data.Length; i += sectorSIZE)
            {
                address = start + i;
                var oData = ReadSector(address / 2, sectorSIZE);
                Debug.WriteLine(string.Format("{0} KB / {1} KB", (i + sectorSIZE) / 1024, data.Length / 1024));

                Buffer.BlockCopy(data, (int)i, tempData, 0, (int)sectorSIZE);
                if (ByteArraysEqual(oData, tempData))
                {
                    continue;
                }

                LibMain.UpdateStatus("Verification failed! Please repeat write command!");

                return(false);
            }
            return(true);
        }
    void Start()
    {
        Debug.Log(LibMain.doTestStaticFunc(1, 2));
        Debug.Log(LibMain.doTestInstanceFunc(3, 4));

        LibMain.doUnitySendMessage(this.gameObject.name, "ReceiveFromAndroid", 5, 6);
        LibMain.FragmentInit();
    }
Example #3
0
        private void OnDeviceNotify(object sender, DeviceNotifyEventArgs e)
        {
            if (e.Device.IdVendor != _vid || e.Device.IdProduct != _pid)
            {
                return; //Ignore this one!
            }
            switch (e.EventType)
            {
            case EventType.DeviceArrival:
                LibMain.OnConnectedChanged(true);     // Notify we found device
                break;

            case EventType.DeviceRemoveComplete:
                CloseDevice();
                LibMain.OnConnectedChanged(false);     // Notify we lost the device
                break;
            }
        }
Example #4
0
        private void OpenDevice()
        {
            if (_usbDevice != null && _usbDevice.IsOpen)
            {
                return;
            }

            // Find and open the usb device.
            _usbDevice = UsbDevice.OpenUsbDevice(_usbFinder);

            // If the device is open and ready
            Debug.Assert(_usbDevice != null, string.Format("No device with PID: {0:X4} & VID: {1:X4} Found!", _pid, _vid));

            // If this is a "whole" usb device (libusb-win32, linux libusb)
            // it will have an IUsbDevice interface. If not (WinUSB) the
            // variable will be null indicating this is an interface of a
            // device.
            var wholeUsbDevice = _usbDevice as IUsbDevice;

            if (!ReferenceEquals(wholeUsbDevice, null))
            {
                // This is a "whole" USB device. Before it can be used,
                // the desired configuration and interface must be selected.

                // Select config #1
                wholeUsbDevice.SetConfiguration(1);

                // Claim interface #0.
                wholeUsbDevice.ClaimInterface(0);
            }

            // open read endpoint 1.
            _epReader = _usbDevice.OpenEndpointReader((ReadEndpointID)EpIn);
            _epReader.Flush();

            // open write endpoint 1.
            _epWriter = _usbDevice.OpenEndpointWriter((WriteEndpointID)EpOut);
            LibMain.OnConnectedChanged(true);
        }