Class: Sphero::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/sphero/response.rb

Defined Under Namespace

Classes: AsyncResponse, CollisionDetected, GetAutoReconnect, GetBluetoothInfo, GetPowerState, GetRGB, PowerNotification, SensorData

Constant Summary collapse

SOP1 =
0
SOP2 =
1
MRSP =
2
SEQ =
3
DLEN =
4
CODE_OK =
0
SIMPLE_RESPONSE =
0xFF
ASYNC_RESPONSE =
0xFE

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header, body) ⇒ Response

Returns a new instance of Response.



21
22
23
24
# File 'lib/sphero/response.rb', line 21

def initialize header, body
  @header = header
  @body   = body
end

Class Method Details

.async?(header) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/sphero/response.rb', line 17

def self.async?(header)
  header[SOP2] == ASYNC_RESPONSE
end

.simple?(header) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/sphero/response.rb', line 13

def self.simple?(header)
  header[SOP2] == SIMPLE_RESPONSE
end

Instance Method Details

#bodyObject



42
43
44
# File 'lib/sphero/response.rb', line 42

def body
  @body.unpack 'C*'
end

#empty?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/sphero/response.rb', line 30

def empty?
  valid? && @header[DLEN] == 1
end

#seqObject



38
39
40
# File 'lib/sphero/response.rb', line 38

def seq
  valid? && @header[SEQ]
end

#success?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/sphero/response.rb', line 34

def success?
  valid? && @header[MRSP] == CODE_OK
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/sphero/response.rb', line 26

def valid?
  @header && @body  
end