Class: Rapid::Baps::Responses::CommandWord

Inherits:
Object
  • Object
show all
Defined in:
lib/ury_rapid/baps/responses/command_word.rb

Overview

An object representing a BAPS command word

BAPS command words may be split into two separate codes:

  • A code, which identifies the general BAPS command itself;

  • A sub-code, which identifies variants of BAPS commands.

The CommandWord class contains a method, #split, for splitting the word into these two codes.

Constant Summary collapse

MAIN_CODE_MASK =

Masks for splitting a BAPS command code into its main and sub-code

0xFFF0
SUBCODE_MASK =
0x000F

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ CommandWord

Initialises a CommandWord

Examples:

Creating a new CommandWord

word = CommandWord.new(0x330)

Parameters:

  • raw (Integer)

    The raw 16-bit integer representing the command word as read from a BAPS server.


23
24
25
# File 'lib/ury_rapid/baps/responses/command_word.rb', line 23

def initialize(raw)
  @raw = raw
end

Instance Method Details

#main_codeInteger

Extracts the BAPS command code from this command word

Examples:

Retrieve the command code from a command word.

cw = CommandWord.new(0x330)
cw.main_code
#=> [0x300]

Returns:

  • (Integer)

    The command code of this command word.


60
61
62
# File 'lib/ury_rapid/baps/responses/command_word.rb', line 60

def main_code
  @raw & MAIN_CODE_MASK
end

#splitArray

Splits this command word into its code and subcode

BAPS uses various bit-masks of its command word for various purposes. The high bits generally encode the command type, while the low bits encode the target channel, sub-commands, and other things.

For our purposes, the subcode is the last four bits of the command word. This means that some subcommands in BAPS are full commands in the Rapid BAPS service, but most of the commands where this happens aren't supported by us anyway.

Examples:

Split a command word.

cw = CommandWord.new(0x330)
cw.split
#=> [0x300, 0x30]

Returns:

  • (Array)

    A pair of main command code and command sub-code.


46
47
48
# File 'lib/ury_rapid/baps/responses/command_word.rb', line 46

def split
  [main_code, sub_code]
end

#sub_codeInteger

Extracts the BAPS command sub-code from a command word

Examples:

Retrieve the command sub-code from a command word.

cw = CommandWord.new(0x330)
cw.sub_code
#=> [0x30]

Returns:

  • (Integer)

    The sub-code of this command word.


74
75
76
# File 'lib/ury_rapid/baps/responses/command_word.rb', line 74

def sub_code
  @raw & SUBCODE_MASK
end