예제 #1
0
        private static SpiEngineStatus GetSpiEngineStatusFromBytes(byte[] data)
        {
            // according with the manual, the command never faults
            SpiEngineStatus response = new SpiEngineStatus();

            response.ExternalRequestPending = data[2] == 0;

            switch (data[3])
            {
            case 0:
                response.BusOwner = SpiBusOwner.NoOwner;
                break;

            case 1:
                response.BusOwner = SpiBusOwner.UsbBridge;
                break;

            case 2:
                response.BusOwner = SpiBusOwner.ExternalMaster;
                break;

            default:
                throw new NotImplementedException();
            }

            response.AttemptedPasswordAccesses = data[4];
            response.PasswordGuessed           = data[5] == 1;

            return(response);
        }
예제 #2
0
        public SpiEngineStatus CancelCurrentTransfer()
        {
            // create the packet
            byte[] packet = new byte[Constants.PacketsSize];
            packet[0] = CommandCodes.CancelCurrentSpiTransfer;

            // send the packet
            byte[] reply = _hidHandler.WriteData(packet);

            // check for errors
            if (reply[0] != CommandCodes.CancelCurrentSpiTransfer)
            {
                throw new PacketReplyFormatException();
            }

            // according with the manual, the command never faults
            SpiEngineStatus response = GetSpiEngineStatusFromBytes(reply);

            return(response);
        }
예제 #3
0
        public SpiEngineStatus ReadEngineStatus()
        {
            // create the packet
            byte[] packet = new byte[Constants.PacketsSize];
            packet[0] = CommandCodes.ReadCurrentSpiStatus;

            // send the packet
            byte[] reply = _hidHandler.WriteData(packet);

            // check for errors
            if (reply[0] != CommandCodes.ReadCurrentSpiStatus)
            {
                throw new PacketReplyFormatException();
            }

            // get the response
            SpiEngineStatus response = GetSpiEngineStatusFromBytes(reply);

            return(response);
        }