Class: MovingsignApi::Command
- Inherits:
-
Object
- Object
- MovingsignApi::Command
- Includes:
- Utilities
- Defined in:
- lib/movingsign_api/commands/command.rb
Overview
Command class, subclassed by each MovingsignApi class
When subclassing, be sure to implement #command_code and #command_payload_bytes
Also see some useful subclasses: WriteTextCommand, WriteControlCommand
Direct Known Subclasses
Instance Attribute Summary collapse
-
#receiver ⇒ Object
The receiving sign’s address.
-
#sender ⇒ Object
The sender’s address.
Instance Method Summary collapse
-
#command_code ⇒ String
Returns the command identifier string.
-
#to_bytes ⇒ Array<Byte>
Returns a byte array representing this command, appropriate for sending to the sign’s serial port.
Instance Attribute Details
#receiver ⇒ Object
The receiving sign’s address. See SenderReceiverAddress
16 17 18 |
# File 'lib/movingsign_api/commands/command.rb', line 16 def receiver @receiver end |
#sender ⇒ Object
The sender’s address. See SenderReceiverAddress
14 15 16 |
# File 'lib/movingsign_api/commands/command.rb', line 14 def sender @sender end |
Instance Method Details
#command_code ⇒ String
Returns the command identifier string. See specification for list of valid command codes.
29 30 31 |
# File 'lib/movingsign_api/commands/command.rb', line 29 def command_code raise MovingsignApi::NotImplementedError, "Needs to be implemented in subclass." end |
#to_bytes ⇒ Array<Byte>
Returns a byte array representing this command, appropriate for sending to the sign’s serial port
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/movingsign_api/commands/command.rb', line 36 def to_bytes # set defaults self.sender ||= :pc self.receiver ||= 1 bytes = [] bytes.concat [0x00] * 5 # start of command bytes.concat [0x01] # <SOH> bytes.concat self.sender.to_bytes # Sender Address bytes.concat self.receiver.to_bytes # Reciver Address bytes.concat [0x02] # <STX> bytes.concat string_to_ascii_bytes(command_code) # Command Code bytes.concat command_payload_bytes # command specific payload bytes.concat [0x03] # <ETX> bytes.concat generate_checksum_bytes(bytes[10..-1]) # Checksum bytes (4) bytes.concat [0x04] # <EOT> bytes end |