calculate the checksum of the incoming data instead of the expected packet

This commit is contained in:
King Kévin 2015-07-30 08:54:01 +02:00
parent 9287f90d25
commit 24413dce2d
1 changed files with 2 additions and 1 deletions

View File

@ -102,9 +102,10 @@ class Telegram
to_return.data = bytes[3..-3]
# parse checksum (CS)
checksum = (bytes[-2]<<8)+bytes[-1]
bytes[0..-3].each { |b| checksum -= b }
# run some checks
raise "wrong length. expected #{length}, got #{to_return.data.length-1}" if (to_return.transmission==SEND or to_return.transmission==ANSWER) and length != to_return.data.length-1
raise "wrong checksum. expected #{to_return.checksum}, got #{checksum}" if checksum != to_return.checksum
raise "wrong checksum. off by #{checksum}" if checksum != 0
return to_return
end