Class: Sphero::Request
- Inherits:
-
Object
show all
- Defined in:
- lib/sphero/request.rb
Defined Under Namespace
Classes: ConfigureCollisionDetection, Heading, Roll, SetDataStreaming, SetPowerNotification, Sleep, Sphero
Constant Summary
collapse
- SOP1 =
0xFF
- SOP2 =
0xFF
- SetBackLEDOutput =
make_command Sphero, 0x21
- SetRotationRate =
make_command Sphero, 0x03
- SetRGB =
make_command Sphero, 0x20
- GetRGB =
make_command Sphero, 0x22
- Ping =
make_command Request, 0x01
- GetVersioning =
make_command Request, 0x02
- GetBluetoothInfo =
make_command Request, 0x11
- SetAutoReconnect =
make_command Request, 0x12
- GetAutoReconnect =
make_command Request, 0x13
- GetPowerState =
make_command Request, 0x20
- GYRO_AXIS_H_FILTERED =
0x0000_0001
- GYRO_AXIS_M_FILTERED =
0x0000_0002
- GYRO_AXIS_L_FILTERED =
0x0000_0004
- LEFT_MOTOR_BACK_EMF_FILTERED =
0x0000_0020
- RIGHT_MOTOR_BACK_EMF_FILTERED =
0x0000_0040
- MAGNETOMETER_AXIS_Z_FILTERED =
0x0000_0080
- MAGNETOMETER_AXIS_Y_FILTERED =
0x0000_0100
- MAGNETOMETER_AXIS_X_FILTERED =
0x0000_0200
- GYRO_AXIS_Z_FILTERED =
0x0000_0400
- GYRO_AXIS_Y_FILTERED =
0x0000_0800
- GYRO_AXIS_X_FILTERED =
0x0000_1000
- ACCELEROMETER_AXIS_Z_FILTERED =
0x0000_2000
- ACCELEROMETER_AXIS_Y_FILTERED =
0x0000_4000
- ACCELEROMETER_AXIS_X_FILTERED =
0x0000_8000
- IMU_YAW_ANGLE_FILTERED =
0x0001_0000
- IMU_ROLL_ANGLE_FILTERED =
0x0002_0000
- IMU_PITCH_ANGLE_FILTERED =
0x0004_0000
- LEFT_MOTOR_BACK_EMF_RAW =
0x0020_0000
- RIGHT_MOTOR_BACK_EMF_RAW =
0x0040_0000
- MAGNETOMETER_AXIS_Z_RAW =
0x0080_0000
- MAGNETOMETER_AXIS_Y_RAW =
0x0100_0000
- MAGNETOMETER_AXIS_X_RAW =
0x0200_0000
- GYRO_AXIS_Z_RAW =
0x0400_0000
- GYRO_AXIS_Y_RAW =
0x0800_0000
- GYRO_AXIS_X_RAW =
0x1000_0000
- ACCELEROMETER_AXIS_Z_RAW =
0x2000_0000
- ACCELEROMETER_AXIS_Y_RAW =
0x4000_0000
- ACCELEROMETER_AXIS_X_RAW =
0x8000_0000
- QUATERNION_Q0 =
0x0000_0001
- QUATERNION_Q1 =
0x0000_0002
- QUATERNION_Q2 =
0x0000_0004
- QUATERNION_Q3 =
0x0000_0008
- ODOMETER_X =
0x0000_0010
- ODOMETER_Y =
0x0000_0020
- ACCELONE =
0x0000_0040
- VELOCITY_X =
0x0000_0080
- VELOCITY_Y =
0x0000_0100
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(seq, data = []) ⇒ Request
Returns a new instance of Request.
8
9
10
11
12
|
# File 'lib/sphero/request.rb', line 8
def initialize seq, data = []
@seq = seq
@data = data
@did = 0x00
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6
7
8
|
# File 'lib/sphero/request.rb', line 6
def data
@data
end
|
Class Method Details
.make_command(klass, cid, &block) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/sphero/request.rb', line 59
def self.make_command klass, cid, &block
Class.new(klass) {
define_method(:initialize) do |seq, *args|
super(seq, args)
@cid = cid
end
}
end
|
Instance Method Details
#bytes ⇒ Object
44
45
46
|
# File 'lib/sphero/request.rb', line 44
def bytes
+ packet_body + checksum.chr
end
|
#checksum ⇒ Object
40
41
42
|
# File 'lib/sphero/request.rb', line 40
def checksum
~(( + packet_body).unpack('C*').drop(2).reduce(:+) % 256) & 0xFF
end
|
#dlen ⇒ Object
48
49
50
|
# File 'lib/sphero/request.rb', line 48
def dlen
packet_body.bytesize + 1
end
|
14
15
16
|
# File 'lib/sphero/request.rb', line 14
def
[SOP1, SOP2, @did, @cid, @seq, dlen]
end
|
#packet_body ⇒ Object
36
37
38
|
# File 'lib/sphero/request.rb', line 36
def packet_body
@data.pack 'C*'
end
|
32
33
34
|
# File 'lib/sphero/request.rb', line 32
def
.pack 'CCCCCC'
end
|
#response(header, body) ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/sphero/request.rb', line 23
def response , body
name = self.class.name.split('::').last
if Response.const_defined?(name)
Response.const_get(name).new , body
else
Response.new , body
end
end
|
#to_str ⇒ Object
The data to write to the socket
19
20
21
|
# File 'lib/sphero/request.rb', line 19
def to_str
bytes
end
|