Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Checkusm calcluation. Enter the command into the command string below, but do no inlcude the start byte, checksum, or end byte. The result will be printed below.
- --]]
- command = "\x01\x76\x1a\x01"
- local start, checksum, finish, output, readable = "\xfe", 0, "\xff", "", ""
- for c in command:gmatch(".") do
- checksum = checksum + string.byte(c)
- output = output .. c
- end
- checksum = checksum % 255
- output = output .. string.char(checksum)
- output = output:gsub("\x80", "\x80\x00")
- output = output:gsub("\xfe", "\x80\x7e")
- output = output:gsub("\xff", "\x80\x7f")
- output = start .. output .. finish
- for c in output:gmatch(".") do
- readable = readable .. string.format("\\x%02x", string.byte(c))
- end
- print(string.format("Checksum: %02x\r\nString for command button: \"%s\"", string.byte(checksum), readable))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement