Module: LIRC::Protocol
- Includes:
- EventMachine::Protocols::LineProtocol
- Defined in:
- lib/lirc/protocol.rb
Overview
EventMachine Protocol for LIRC.
Internally relies on Messages for parsing. Can send Commands to LIRC with send_command.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(*args, logger: Logger.new(STDERR), **kwargs) ⇒ Object
- #receive_line(line) ⇒ Object
- #send_command(command) ⇒ Object
Class Method Details
.connect!(server:, port: DEFAULT_PORT, &block) ⇒ Object
14 15 16 |
# File 'lib/lirc/protocol.rb', line 14 def self.connect!(server:, port: DEFAULT_PORT, &block) EventMachine.connect(server, port, self, &block) end |
Instance Method Details
#initialize(*args, logger: Logger.new(STDERR), **kwargs) ⇒ Object
18 19 20 21 22 |
# File 'lib/lirc/protocol.rb', line 18 def initialize(*args, logger: Logger.new(STDERR), **kwargs) @logger = logger super(*args, **kwargs) end |
#receive_line(line) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lirc/protocol.rb', line 29 def receive_line(line) line = line.chomp if @response_parser (line) elsif line.eql?("BEGIN") (line) elsif line =~ /^[0-9a-f]/ (Messages::ButtonPress.parse(line)) else logger.warn "Received unknown line from lirc: #{line}" end end |
#send_command(command) ⇒ Object
24 25 26 27 |
# File 'lib/lirc/protocol.rb', line 24 def send_command(command) send_data "#{command.serialize}\n" response_deferrables[command.serialize] ||= EM::DefaultDeferrable.new end |