Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/serial_interface.rb

Overview

FIXME: this should probably be put in a separate file

Instance Method Summary collapse

Instance Method Details

#crc_xmodemObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/serial_interface.rb', line 12

def crc_xmodem
  self.to_enum(:each_byte).inject(0) { |crc,byte|
    crc = (crc ^ (byte << 8)) % 0x10000
    8.times {
      crc <<= 1
      crc ^= 0x1021 if crc[16] == 1
    }
    crc
  } % 0x10000
end