Module: Rplidar::Util
- Included in:
- Driver
- Defined in:
- lib/rplidar/util.rb
Overview
Binary encoding, decoding, checksum methods.
Instance Method Summary collapse
- #binary_to_ints(string, format = 'C*') ⇒ Object
- #checksum(string) ⇒ Object
- #ints_to_binary(array, format = 'C*') ⇒ Object
Instance Method Details
#binary_to_ints(string, format = 'C*') ⇒ Object
12 13 14 |
# File 'lib/rplidar/util.rb', line 12 def binary_to_ints(string, format = 'C*') string.unpack(format) end |
#checksum(string) ⇒ Object
4 5 6 |
# File 'lib/rplidar/util.rb', line 4 def checksum(string) binary_to_ints(string).reduce(:^) end |
#ints_to_binary(array, format = 'C*') ⇒ Object
8 9 10 |
# File 'lib/rplidar/util.rb', line 8 def ints_to_binary(array, format = 'C*') [array].flatten.pack(format) end |