Class: Rplidar::ResponseDescriptor
Overview
Incapsulates Response Descriptor processing. Format of Response Descriptor:
Start Flag 1 Start Flag 2 Data Response Length Send Mode Data Type 1 byte (0xA5) 1 bytes (0x5A) 30 bits 2 bits 1 byte
Instance Attribute Summary
Attributes inherited from Response
#raw_response
Instance Method Summary
collapse
Methods inherited from Response
#initialize
Instance Method Details
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rplidar/response_descriptor.rb', line 19
def
unless correct_first_byte?
raise 'Wrong first byte of the response descriptor: ' \
"'#{int_to_hex(raw_response[0])}'"
end
unless correct_second_byte?
raise 'Wrong second byte of the response descriptor: ' \
"'#{int_to_hex(raw_response[1])}'"
end
end
|
#check_payload ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/rplidar/response_descriptor.rb', line 31
def check_payload
unless correct_send_mode?
raise 'Wrong send mode value of the response descriptor: ' \
"'#{int_to_hex(send_mode)}'"
end
unless correct_data_type?
raise 'Wrong data type value of the response descriptor: ' \
"'#{int_to_hex(data_type)}'"
end
end
|
#check_response ⇒ Object
14
15
16
17
|
# File 'lib/rplidar/response_descriptor.rb', line 14
def check_response
check_payload
end
|
#correct_data_type? ⇒ Boolean
#correct_first_byte? ⇒ Boolean
43
44
45
|
# File 'lib/rplidar/response_descriptor.rb', line 43
def correct_first_byte?
raw_response[0] == 0xA5
end
|
#correct_second_byte? ⇒ Boolean
47
48
49
|
# File 'lib/rplidar/response_descriptor.rb', line 47
def correct_second_byte?
raw_response[1] == 0x5A
end
|
#correct_send_mode? ⇒ Boolean
#data_response_length ⇒ Object
64
65
66
|
# File 'lib/rplidar/response_descriptor.rb', line 64
def data_response_length
(raw_response[4] << 16) + (raw_response[3] << 8) + raw_response[2]
end
|
#data_type ⇒ Object
The 1byte Data Type describes the type of the incoming data response packets.
82
83
84
|
# File 'lib/rplidar/response_descriptor.rb', line 82
def data_type
raw_response[6]
end
|
#response ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/rplidar/response_descriptor.rb', line 86
def response
{
data_response_length: data_response_length,
send_mode: send_mode,
data_type: data_type
}
end
|
#send_mode ⇒ Object
The 2 bits Send Mode field describes the request/response mode of the current session. Values:
-
0x0 - Single Request - Single Response mode, RPLIDAR will send
only one data response packet in the current session.
-
0x1 - Single Request - Multiple Response mode, RPLIDAR will
continuously send out data response packets with the same format
in the current session.
-
0x2 and 0x3 are reserved for future use
76
77
78
|
# File 'lib/rplidar/response_descriptor.rb', line 76
def send_mode
raw_response[5] >> 6
end
|