// blocks the current thread if a command is pending, then sets the current command as the pending command (note does not apply to all commands)
        private void WaitAndSetPendingCommand(InsteonDirectCommands command, byte value)
        {
            InsteonDirectCommands latchedPendingCommand;

            lock (pendingEvent)
            {
                if (pendingCommand == null)
                {
                    pendingCommand = command;
                    pendingValue = value;
                    pendingRetry = 0;
                    return;
                }
                latchedPendingCommand = pendingCommand.Value;
            }

            // block current thread if a command is pending
            logger.DebugFormat("Device {0} blocking command {1} for pending command {2}", Address.ToString(), command.ToString(), latchedPendingCommand.ToString());
            pendingEvent.Reset();
            if (!pendingEvent.WaitOne(Constants.deviceAckTimeout)) // wait at most deviceAckTimeout seconds
            {
                ClearPendingCommand(); // break deadlock and warn
                logger.WarnFormat("Device {0} unblocking command {1} for pending command {2}", Address.ToString(), command.ToString(), latchedPendingCommand.ToString());
            }

            WaitAndSetPendingCommand(command, value); // try again
        }
Beispiel #2
0
        // blocks the current thread if a command is pending, then sets the current command as the pending command (note does not apply to all commands)
        private void WaitAndSetPendingCommand(InsteonDirectCommands command, byte value)
        {
            InsteonDirectCommands latchedPendingCommand;

            lock (pendingEvent)
            {
                if (pendingCommand == null)
                {
                    pendingCommand = command;
                    pendingValue   = value;
                    pendingRetry   = 0;
                    return;
                }
                latchedPendingCommand = pendingCommand.Value;
            }

            // block current thread if a command is pending
            logger.DebugFormat("Device {0} blocking command {1} for pending command {2}", Address.ToString(), command.ToString(), latchedPendingCommand.ToString());
            pendingEvent.Reset();
            if (!pendingEvent.WaitOne(Constants.deviceAckTimeout)) // wait at most deviceAckTimeout seconds
            {
                ClearPendingCommand();                             // break deadlock and warn
                logger.WarnFormat("Device {0} unblocking command {1} for pending command {2}", Address.ToString(), command.ToString(), latchedPendingCommand.ToString());
            }

            WaitAndSetPendingCommand(command, value); // try again
        }
        private bool TryCommandInternal(InsteonDirectCommands command, byte value)
        {
            var message = GetStandardMessage(Address, (byte)command, value);
            logger.DebugFormat("Device {0} Command(command:{1}, value:{2:X2})", Address.ToString(), command.ToString(), value);

            var status = network.Messenger.TrySend(message);
            if (status == EchoStatus.ACK)
            {
                ackTimer.Change(Constants.deviceAckTimeout, Timeout.Infinite); // start ACK timeout timer  
                ClearPendingCommand();
                return true;
            }
            ClearPendingCommand();
            return false;
        }
Beispiel #4
0
        private bool TryCommandInternal(InsteonDirectCommands command, byte value)
        {
            var message = GetStandardMessage(Address, (byte)command, value);

            logger.DebugFormat("Device {0} Command(command:{1}, value:{2:X2})", Address.ToString(), command.ToString(), value);

            var status = network.Messenger.TrySend(message);

            if (status == EchoStatus.ACK)
            {
                ackTimer.Change(Constants.deviceAckTimeout, Timeout.Infinite); // start ACK timeout timer
                ClearPendingCommand();
                return(true);
            }
            ClearPendingCommand();
            return(false);
        }