示例#1
0
        /// <summary>
        /// Checks to see if a specific command is available, given the current hardware status.
        /// </summary>
        /// <param name="command">The command whose availability is being tested.</param>
        /// <param name="hardwareStatus">Current hardware status of the device.</param>
        /// <returns><c>true</c> if the command can be executed under the given hardware status.</returns>
        public bool IsCommandAvailable(ProtocolCommandId command, HardwareStatusFlags hardwareStatus)
        {
            bool commandAvailable = AlwaysAvailableCommands.Contains(command);

            if (!commandAvailable)
            {
                Tuple <HardwareStatusFlags, FeatureCompatibility> commandAvailability = null;
                if (_commandAvailability.TryGetValue(command, out commandAvailability))
                {
                    commandAvailable = commandAvailability.Item1 == HardwareStatusFlags.None;
                    if (!commandAvailable)
                    {
                        if (commandAvailability.Item2 == FeatureCompatibility.Incompatible)
                        {
                            commandAvailable = (hardwareStatus & commandAvailability.Item1) == HardwareStatusFlags.None;
                        }
                        else if (commandAvailability.Item2 == FeatureCompatibility.Requires)
                        {
                            commandAvailable = (hardwareStatus & commandAvailability.Item1) == commandAvailability.Item1;
                        }
                    }
                }
            }
            return(commandAvailable);
        }
 /// <summary>
 /// Helper method to execute emulate hardware status bits changing when attached to the Locutus simulator.
 /// </summary>
 /// <param name="device">The device to send the command to.</param>
 /// <param name="flags">The hardware status flags to assign to the simulator.</param>
 internal static void SetHardwareStatus(Device device, HardwareStatusFlags flags)
 {
     if (!device.IsCommandInProgress)
     {
         var executeCommandTaskData = new ExecuteDeviceCommandAsyncTaskData(device, INTV.LtoFlash.Model.Commands.ProtocolCommandId.DebugSetHardwareStatus)
         {
             Data      = flags,
             OnFailure = (m, e) =>
             {
                 INTV.Shared.View.OSMessageBox.Show(m, "Toggle Power Command", SingleInstanceApplication.SharedSettings.ShowDetailedErrors ? e : null, null);
                 return(true);
             }
         };
         executeCommandTaskData.StartTask(SetHardwareStatus);
     }
 }
示例#3
0
        public void DeviceStatusFlagsLo_ToHardwareStatusFlags_ReturnsExpectedFlags(DeviceStatusFlagsLo statusFlagsLo, HardwareStatusFlags expectedHardwareStatusFlags)
        {
            var actualHardwareStatusFlags = statusFlagsLo.ToHardwareStatusFlags();

            Assert.Equal(expectedHardwareStatusFlags, actualHardwareStatusFlags);
        }
示例#4
0
 /// <summary>
 /// Creates an instance of the DebugSetHardwareStatus command.
 /// </summary>
 /// <param name="hardwareStatusFlags">The hardware status flags to set on the simulator.</param>
 /// <returns>A new instance of the command.</returns>
 public static DebugSetHardwareStatus Create(HardwareStatusFlags hardwareStatusFlags)
 {
     return(new DebugSetHardwareStatus(hardwareStatusFlags));
 }
示例#5
0
 private DebugSetHardwareStatus(HardwareStatusFlags hardwareStatusFlags)
     : base(ProtocolCommandId.DebugSetHardwareStatus, DefaultResponseTimeout, (uint)hardwareStatusFlags)
 {
 }
示例#6
0
        /// <summary>
        /// Places hardware status flags into the more generic DeviceStatusFlagsLo bit array.
        /// </summary>
        /// <param name="hardwareStatus">The hardware status flags to convert.</param>
        /// <returns>The flags placed in a DeviceStatusFlagsLo bit array.</returns>
        internal static DeviceStatusFlagsLo ToDeviceStatusFlagsLo(this HardwareStatusFlags hardwareStatus)
        {
            var deviceStatusFlags = (DeviceStatusFlagsLo)hardwareStatus;

            return(deviceStatusFlags);
        }
示例#7
0
        /// <summary>
        /// Verifies that all the commands in an enumerable of commands can be executed.
        /// </summary>
        /// <param name="commands">The commands whose total availability is being tested.</param>
        /// <param name="hardwareStatus">Current hardware status of the device.</param>
        /// <returns><c>true</c> if all of the commands can be executed under the given hardware status.</returns>
        public bool AllProtocolCommandsAvailable(IEnumerable <ProtocolCommandId> commands, HardwareStatusFlags hardwareStatus)
        {
            var allCommandsAvailable = (commands == null) || !commands.Any();

            if (commands != null)
            {
                foreach (var command in commands)
                {
                    allCommandsAvailable = IsCommandAvailable(command, hardwareStatus);
                    if (!allCommandsAvailable)
                    {
                        break;
                    }
                }
            }
            return(allCommandsAvailable);
        }
示例#8
0
 /// <summary>
 /// Alter the availability of a command. This may be used, for example, to modify the availability of commands not implemented
 /// in the simulator, or only available in hardware, et. al.
 /// </summary>
 /// <param name="command">The command whose availability is being changed.</param>
 /// <param name="hardwareStatus">Hardware status associated with command availability.</param>
 /// <param name="compatibility">Whether the given hardware flag(s) are required, or must not be set.</param>
 public void ChangeCommandAvailablility(ProtocolCommandId command, HardwareStatusFlags hardwareStatus, FeatureCompatibility compatibility)
 {
     _commandAvailability[command] = new Tuple <HardwareStatusFlags, FeatureCompatibility>(hardwareStatus, compatibility);
 }