module Crc16
Constants
- CRC_LOOKUP
Public Class Methods
check_crc16(s, expecting)
click to toggle source
Returns boolean true or false if checksum of string s matches expected value
# File lib/ekm-omnimeter/crc16.rb, line 4 def self.check_crc16(s, expecting) (Crc16.crc16(s) == expecting) end
crc16(buf)
click to toggle source
Calculates CRC16 checksum of string buf
# File lib/ekm-omnimeter/crc16.rb, line 9 def self.crc16(buf) crc = 0x00 buf.each_byte do |b| crc = ((crc >> 8) & 0xff) ^ CRC_LOOKUP[(crc ^ b) & 0xff] end crc end