Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.35 KB | None | 0 0
  1.  
  2. def get_checksum mtk_msg
  3.     matchdata = /^\$(.+)\*/.match(mtk_msg)
  4.     result = 0x00
  5.     matchdata[1].chars.each do |c|
  6.         result ^= c.ord
  7.     end
  8.  
  9.     result
  10. end
  11.  
  12. #
  13. # assert_equal(31, get_checksum('$PMTK605*'))
  14. # assert_equal(4, get_checksum('$PMTK226,3,30*'))
  15.  
  16.  
  17. loop do
  18.     result = get_checksum(gets)
  19.     puts "#{result} \t 0x#{result.to_s(16)}"
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement