module NXT::Command::Base
The base implementation of all commands, providing low-level details that are consistent across all supported types. These are things such as:
-
Errors.
-
Sending and receiving of responses.
-
Addressing the port safely.
-
Command
types.
Constants
- COMMAND_TYPES
- ERRORS
- PORTS
Private Instance Methods
port_as_byte(port)
click to toggle source
# File lib/nxt/commands/base.rb, line 52 def port_as_byte(port) PORTS[port] end
receive()
click to toggle source
# File lib/nxt/commands/base.rb, line 74 def receive response = @interface.receive raise 'Not a valid response package.' unless response[0] == 0x02 raise 'Not a valid response to the command that was sent.' unless response[1] == command_identifier raise ERRORS[response[2]] unless response[2].zero? response[3..] end
send(command_identifier, payload = [], response_required: true)
click to toggle source
# File lib/nxt/commands/base.rb, line 64 def send(command_identifier, payload = [], response_required: true) command_identifier |= 0x80 unless response_required @interface.send([ command_type, command_identifier, port_as_byte(port) ] + payload) end
send_and_receive(command_identifier, payload = [], response_required: true)
click to toggle source
# File lib/nxt/commands/base.rb, line 56 def send_and_receive(command_identifier, payload = [], response_required: true) send(command_identifier, payload, response_required) # We bail unless we need to wait for response. return unless response_required receive end