Пример #1
0
        /// <summary>
        /// Determines whether this command is same the same as the specified second.
        /// </summary>
        /// <param name="second">The second command to compare with.</param>
        /// <returns><c>true</c> if this command is the same as the specified second; otherwise, <c>false</c>.</returns>
        public bool IsSameCommand(WinLircCommand second)
        {
            if (second == null)
            {
                return(false);
            }

            return(_button.Equals(second.Button, StringComparison.Ordinal) &&
                   _remote.Equals(second.Remote, StringComparison.Ordinal));
        }
Пример #2
0
        /// <summary>
        /// Handles commands.
        /// </summary>
        /// <param name="cmd">The Command.</param>
        private void CommandHandler(WinLircCommand cmd)
        {
            if (_remoteButtonHandler == null)
            {
                return;
            }

            string buttonCode = String.Format("{0}: {1}", cmd.Remote, cmd.Button);

            _remoteButtonHandler(Name, buttonCode);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WinLircServer"/> class.
        /// </summary>
        /// <param name="ip">The ip address.</param>
        /// <param name="port">The port.</param>
        /// <param name="buttonReleaseTime">The button release time.</param>
        /// <param name="repeatDelay">The repeat delay.</param>
        public WinLircServer(IPAddress ip, int port, TimeSpan buttonReleaseTime, int repeatDelay)
        {
            _buttonReleaseTime = buttonReleaseTime;
            _repeatDelay       = repeatDelay;
            _lastCommand       = new WinLircCommand();

            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _socket.Connect(ip, port); // Connect; error handling is done in SetupDataCallback()

            SetupDataCallback();       // Setup callback function that will receive data
        }
Пример #4
0
        /// <summary>
        /// Process received data, i.e. send event to event handlers
        /// </summary>
        private void ProcessData(string data)
        {
            // Ignore commands we do not need (like the startup message)
            if (data.Equals("BEGIN", StringComparison.OrdinalIgnoreCase) ||
                data.Equals("END", StringComparison.OrdinalIgnoreCase) ||
                data.Equals("SIGHUP", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            WinLircCommand command = new WinLircCommand(data);

            #region Time-based repeat filter

            if (_lastCommand.IsSameCommand(command))
            {
                if (_repeatDelay > 0 && command.Repeats > 0 &&
                    command.Repeats < _repeatDelay)
                {
                    Trace.WriteLine(String.Format("WLirc: Command '{0}' ignored because of repeat delay filter", command.Button));
                    return;
                }
                if ((command.Time - _lastCommand.Time) < _buttonReleaseTime)
                {
                    Trace.WriteLine(String.Format("WLirc: Command '{0}' ignored because of repeat filter", command.Button));
                    return;
                }
            }

            #endregion Time-based repeat filter

            Trace.WriteLine(String.Format("WLirc: Command '{0}' accepted", command.Button));
            _lastCommand = command;

            if (CommandEvent != null)
            {
                CommandEvent(command);
            }
        }
    /// <summary>
    /// Handles commands.
    /// </summary>
    /// <param name="cmd">The Command.</param>
    private void CommandHandler(WinLircCommand cmd)
    {
      if (_remoteButtonHandler == null)
        return;

      string buttonCode = String.Format("{0}: {1}", cmd.Remote, cmd.Button);

      _remoteButtonHandler(Name, buttonCode);
    }
    /// <summary>
    /// Determines whether this command is same the same as the specified second.
    /// </summary>
    /// <param name="second">The second command to compare with.</param>
    /// <returns><c>true</c> if this command is the same as the specified second; otherwise, <c>false</c>.</returns>
    public bool IsSameCommand(WinLircCommand second)
    {
      if (second == null)
        return false;

      return (_button.Equals(second.Button, StringComparison.Ordinal) &&
              _remote.Equals(second.Remote, StringComparison.Ordinal));
    }