Skip to content

Instantly share code, notes, and snippets.

@GeorgeDewar
Created April 22, 2014 09:21
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeorgeDewar/11171561 to your computer and use it in GitHub Desktop.
Save GeorgeDewar/11171561 to your computer and use it in GitHub Desktop.
Checksum calculation example for IR codes of a Fujitsu heat pump (remote AR-RAH1E)
# Sample data
data = []
data[0] = '00101000110001100000000000001000 00001000011111111001000000001100 00001101100000001000000000000000 00000000000000000000010001111111'
data[1] = '00101000110001100000000000001000 00001000011111111001000000001100 00000011100000001000000000000000 00000000000000000000010001110111'
data[2] = '00101000110001100000000000001000 00001000011111111001000000001100 00001101100011001000000000000000 00001011111110010000010011111010'
data[3] = '00101000110001100000000000001000 00001000011111111001000000001100 00001101100000001000100000000000 00000000000000000000010001110111'
data[4] = '00101000110001100000000000001000 00001000011111111001000000001100 00001101000000000000100000000000 00000000000000000000010000001111'
# Checksum function
def checksum(data)
bytes = data.gsub(/ /, '').scan(/.{8}/)
bytes = bytes[8..14]
numbers = bytes.map { |byte| byte.reverse.to_i(2) }
sum = numbers.inject { |sum, x| sum + x }
(208 - sum) % 256
end
data.each do |sample|
actualChecksum = sample.gsub(/ /, '').scan(/.{8}/).last
calculatedChecksum = checksum(sample).to_s(2).rjust(8, '0').reverse
diff = actualChecksum.reverse.to_i(2) - calculatedChecksum.reverse.to_i(2)
puts "Calculated: #{calculatedChecksum}, Actual: #{actualChecksum}, Diff: #{diff}"
end
@cosmopaco
Copy link

It could explain the calcul, I do not know this programming language?

@AnthonyMyatt
Copy link

Thanks George. Came across this whilst working on a project to control my AC unit using Apple Home Kit. Much appreciated.
https://stackoverflow.com/questions/48531654/fujitsu-ir-remote-checksum-calculation/48533869#48533869

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment