Class: Sphero::Response::AsyncResponse
Constant Summary
collapse
- ID_CODE =
2
- DLEN_MSB =
3
- DLEN_LSB =
4
- POWER_NOTIFICATION =
0x01
- LEVEL_1_DIAGNOSTIC =
0x02
- SENSOR_DATA =
0x03
- CONFIG_BLOCK =
0x04
- PRESLEEP_WARNING =
0x05
- MACRO_MARKERS =
0x06
- COLLISION_DETECTED =
0x07
- VALID_REPONSES =
{POWER_NOTIFICATION => 'Sphero::Response::PowerNotification',
SENSOR_DATA => 'Sphero::Response::SensorData',
COLLISION_DETECTED => 'Sphero::Response::CollisionDetected'}
ASYNC_RESPONSE, CODE_OK, DLEN, MRSP, SEQ, SIMPLE_RESPONSE, SOP1, SOP2
Class Method Summary
collapse
Instance Method Summary
collapse
async?, #body, #initialize, simple?, #valid?
Class Method Details
.constantize(camel_cased_word) ⇒ Object
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/sphero/response.rb', line 132
def self.constantize(camel_cased_word)
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
constant = Object
names.each do |name|
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
constant
end
|
.response(header, body) ⇒ Object
127
128
129
130
|
# File 'lib/sphero/response.rb', line 127
def self.response , body
raise "no good" unless self.valid?()
constantize(VALID_REPONSES[[ID_CODE]]).new(, body)
end
|
.valid?(header) ⇒ Boolean
123
124
125
|
# File 'lib/sphero/response.rb', line 123
def self.valid?()
VALID_REPONSES.keys.include?([ID_CODE])
end
|
Instance Method Details
#empty? ⇒ Boolean
143
144
145
|
# File 'lib/sphero/response.rb', line 143
def empty?
@header[DLEN_LSB] == 1
end
|
#seq ⇒ Object
151
152
153
|
# File 'lib/sphero/response.rb', line 151
def seq
1
end
|
#success? ⇒ Boolean
147
148
149
|
# File 'lib/sphero/response.rb', line 147
def success?
AsyncResponse.valid?(@header)
end
|