class Rplidar::ResponseDescriptor
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
Public Instance Methods
check_header()
click to toggle source
# File lib/rplidar/response_descriptor.rb, line 19 def check_header 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()
click to toggle source
# 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()
click to toggle source
# File lib/rplidar/response_descriptor.rb, line 14 def check_response check_header check_payload end
correct_data_type?()
click to toggle source
# File lib/rplidar/response_descriptor.rb, line 58 def correct_data_type? [ DATA_TYPE_DEVICE_INFO, DATA_TYPE_CURRENT_STATE, DATA_TYPE_SCAN ].include?(data_type) end
correct_first_byte?()
click to toggle source
# File lib/rplidar/response_descriptor.rb, line 43 def correct_first_byte? raw_response[0] == 0xA5 end
correct_second_byte?()
click to toggle source
# File lib/rplidar/response_descriptor.rb, line 47 def correct_second_byte? raw_response[1] == 0x5A end
correct_send_mode?()
click to toggle source
# File lib/rplidar/response_descriptor.rb, line 51 def correct_send_mode? [ SEND_MODE_SINGLE_REQUEST_SINGLE_RESPONSE, SEND_MODE_SINGLE_REQUEST_MULTIPLE_RESPONSE ].include?(send_mode) end
data_response_length()
click to toggle source
# 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()
click to toggle source
The 1byte Data Type describes the type of the incoming data response packets.
# File lib/rplidar/response_descriptor.rb, line 82 def data_type raw_response[6] end
response()
click to toggle source
# 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()
click to toggle source
The 2 bits Send Mode field describes the request/response mode of the current session. Values:
-
0x0 - Single Request - Single
Response
mode, RPLIDAR will sendonly one data response packet in the current session.
-
0x1 - Single Request - Multiple
Response
mode, RPLIDAR willcontinuously send out data response packets with the same format in the current session.
-
0x2 and 0x3 are reserved for future use
# File lib/rplidar/response_descriptor.rb, line 76 def send_mode raw_response[5] >> 6 end
Private Instance Methods
int_to_hex(value)
click to toggle source
# File lib/rplidar/response_descriptor.rb, line 96 def int_to_hex(value) if value "0x#{value.to_s(16).upcase}" else value.inspect end end