Class: Sphero::Response
- Inherits:
-
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 , body
@header =
@body = body
end
|
Class Method Details
.async?(header) ⇒ Boolean
17
18
19
|
# File 'lib/sphero/response.rb', line 17
def self.async?()
[SOP2] == ASYNC_RESPONSE
end
|
.simple?(header) ⇒ Boolean
13
14
15
|
# File 'lib/sphero/response.rb', line 13
def self.simple?()
[SOP2] == SIMPLE_RESPONSE
end
|
Instance Method Details
#body ⇒ Object
42
43
44
|
# File 'lib/sphero/response.rb', line 42
def body
@body.unpack 'C*'
end
|
#empty? ⇒ Boolean
30
31
32
|
# File 'lib/sphero/response.rb', line 30
def empty?
valid? && @header[DLEN] == 1
end
|
#seq ⇒ Object
38
39
40
|
# File 'lib/sphero/response.rb', line 38
def seq
valid? && @header[SEQ]
end
|
#success? ⇒ Boolean
34
35
36
|
# File 'lib/sphero/response.rb', line 34
def success?
valid? && @header[MRSP] == CODE_OK
end
|
#valid? ⇒ Boolean
26
27
28
|
# File 'lib/sphero/response.rb', line 26
def valid?
@header && @body
end
|