Module: SpheroUtilities
- Included in:
- SpheroClient, SpheroRequest, SpheroResponse
- Defined in:
- lib/rubysphero.rb
Instance Method Summary collapse
-
#add_checksum(full_bytes) ⇒ Object
def.
- #do_checksum(bytes) ⇒ Object
- #print_format_bytes(bytes) ⇒ Object
Instance Method Details
#add_checksum(full_bytes) ⇒ Object
def
34 35 36 37 38 |
# File 'lib/rubysphero.rb', line 34 def add_checksum(full_bytes) to_chk_bytes = full_bytes.drop(2) full_bytes.push do_checksum(to_chk_bytes) return full_bytes end |
#do_checksum(bytes) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubysphero.rb', line 21 def do_checksum(bytes) total=0 bytes.each do | a_byte | total+=a_byte end # each logd "Checksum of these bytes: #{print_format_bytes(bytes)}" chk1= (total%256) chk2= (chk1 ^ 0b11111111) logd "Checksum calculated: #{chk2.to_s(16)}" return chk2 end |
#print_format_bytes(bytes) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/rubysphero.rb', line 11 def print_format_bytes(bytes) return_str="" bytes.each do |rsp_array| return_str += rsp_array.to_s(16) return_str += " " end # each return return_str end |