Last active
August 29, 2015 14:10
-
-
Save patrick99e99/c8e0200e0e1a02e1970b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LpcFrameParser | |
extend self | |
BITS = [4,1,6,5,5,4,4,4,4,4,3,3,3] | |
def hexify(data) | |
bit_pattern = data.map do |frame| | |
frame.map.each_with_index do |d, index| | |
bits = d.to_s(2) | |
while bits.length < BITS[index] | |
pad_with_zero(bits) | |
end | |
bits | |
end | |
end.flatten.compact.join | |
bytes(bit_pattern).map do |byte| | |
reversed_hex_byte byte | |
end.join(',') | |
end | |
def reversed_hex_byte(byte) | |
reversed = byte.join.to_i(2).to_s(16).reverse | |
if reversed.length == 1 | |
reversed << '0' | |
end | |
reversed | |
end | |
def bytes(bits) | |
bits.scan(/\d{4}/).map(&:reverse).each_slice(2) | |
end | |
def pad_with_zero(str) | |
str.insert(0, '0') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
frames = [ | |
[11, 0, 18, 29, 3, 2, 6, 6, 4, 6, 3, 3, 3], | |
[11, 0, 38, 25, 3, 2, 6, 5, 8, 6, 4, 2, 2], | |
[12, 0, 34, 22, 7, 2, 9, 6, 8, 8, 4, 3, 1], | |
[11, 0, 17, 18, 14, 8, 8, 6, 7, 9, 4, 4, 1], | |
[10, 0, 25, 18, 15, 7, 6, 8, 8, 8, 4, 3, 3], | |
[10, 0, 23, 17, 11, 7, 6, 9, 8, 9, 5, 2, 2], | |
[8, 0, 23, 15, 10, 5, 14, 3, 2, 9, 4, 3, 2], | |
[7, 0, 23, 7, 20, 9, 12, 1, 5, 11, 2, 3, 3], | |
[7, 0, 23, 6, 21, 7, 9, 5, 7, 8, 3, 3, 3], | |
[11, 0, 23, 15, 8, 7, 9, 8, 8, 7, 3, 3, 3], | |
[11, 0, 23, 16, 9, 4, 5, 10, 7, 9, 4, 4, 5], | |
[12, 0, 23, 21, 17, 11, 10, 1, 8, 2, 3, 2, 3], | |
[10, 0, 23, 19, 30, 8, 10, 3, 9, 6, 4, 2, 4], | |
[10, 0, 23, 15, 19, 4, 11, 4, 7, 5, 4, 4, 4], | |
[7, 0, 23, 15, 30, 1, 10, 3, 9, 5, 4, 7, 3], | |
[8, 0, 23, 16, 30, 1, 9, 7, 7, 7, 4, 6, 4], | |
[7, 0, 23, 16, 24, 2, 10, 6, 7, 9, 4, 7, 4], | |
[9, 0, 23, 19, 19, 6, 10, 2, 10, 4, 5, 6, 2], | |
[9, 0, 27, 19, 17, 7, 9, 3, 11, 8, 6, 4, 3], | |
[11, 0, 29, 20, 18, 7, 7, 5, 10, 8, 5, 3, 2], | |
[11, 0, 29, 20, 20, 7, 6, 5, 7, 10, 5, 3, 1], | |
[11, 0, 29, 21, 13, 6, 7, 5, 8, 8, 5, 4, 1], | |
[11, 0, 29, 20, 14, 2, 8, 3, 6, 10, 4, 5, 2], | |
[11, 0, 31, 17, 12, 5, 8, 6, 8, 9, 3, 3, 3], | |
[12, 0, 29, 20, 9, 7, 10, 4, 9, 8, 3, 5, 3], | |
[11, 0, 29, 25, 18, 6, 9, 5, 8, 8, 3, 4, 4], | |
[12, 0, 54, 25, 19, 12, 11, 9, 9, 7, 3, 4, 4], | |
[10, 0, 30, 24, 19, 11, 11, 11, 11, 9, 3, 5, 2], | |
[12, 0, 30, 20, 15, 5, 5, 4, 9, 7, 4, 5, 3], | |
[10, 0, 30, 18, 14, 5, 7, 4, 10, 6, 6, 5, 3], | |
[10, 0, 31, 16, 13, 8, 8, 8, 5, 7, 6, 4, 5], | |
[9, 0, 31, 15, 16, 8, 8, 3, 7, 7, 5, 4, 6], | |
[9, 0, 31, 11, 18, 7, 9, 4, 9, 6, 4, 6, 4], | |
[9, 0, 31, 12, 16, 7, 11, 3, 10, 5, 4, 6, 4], | |
[9, 0, 32, 12, 15, 7, 12, 3, 8, 5, 5, 6, 3], | |
[11, 0, 33, 19, 9, 5, 12, 1, 6, 8, 5, 3, 5], | |
[12, 0, 35, 19, 13, 8, 9, 3, 7, 9, 6, 3, 5], | |
[12, 0, 36, 20, 14, 8, 6, 3, 8, 9, 6, 3, 4], | |
[12, 0, 38, 21, 12, 6, 5, 4, 9, 8, 6, 4, 3], | |
[12, 0, 40, 23, 16, 4, 4, 4, 9, 7, 6, 5, 3], | |
[11, 0, 41, 23, 17, 4, 2, 3, 9, 7, 6, 5, 3], | |
[12, 0, 43, 24, 15, 6, 3, 1, 9, 8, 5, 6, 4], | |
[12, 0, 43, 23, 11, 5, 3, 2, 11, 9, 5, 5, 4], | |
[11, 0, 44, 24, 17, 7, 3, 0, 7, 6, 6, 5, 4], | |
[11, 0, 46, 25, 19, 11, 11, 3, 5, 3, 2, 2, 3], | |
[11, 0, 46, 27, 23, 10, 13, 10, 12, 6, 2, 2, 3], | |
[10, 0, 37, 26, 23, 10, 13, 11, 10, 8, 3, 3, 2], | |
[11, 0, 37, 27, 20, 10, 12, 10, 12, 7, 3, 3, 4], | |
[8, 0, 37, 27, 25, 8, 13, 11, 12, 8, 4, 3, 4], | |
[10, 0, 39, 24, 17, 10, 10, 4, 4, 0, 3, 5, 4], | |
[12, 0, 47, 20, 14, 7, 5, 3, 7, 7, 6, 4, 3], | |
[12, 0, 47, 21, 9, 8, 6, 2, 8, 6, 6, 6, 3], | |
[9, 0, 51, 19, 8, 3, 6, 8, 5, 5, 6, 3, 3], | |
[8, 0, 50, 15, 9, 3, 13, 8, 6, 7, 3, 4, 2], | |
[7, 0, 51, 10, 11, 5, 13, 5, 7, 7, 3, 3, 2], | |
[8, 0, 53, 19, 11, 5, 5, 3, 6, 7, 3, 3, 3], | |
[8, 0, 52, 23, 11, 9, 7, 6, 3, 7, 3, 3, 2], | |
[8, 0, 43, 25, 15, 10, 9, 8, 6, 7, 3, 4, 4], | |
[9, 0, 43, 24, 14, 12, 9, 8, 7, 8, 3, 5, 3], | |
[9, 0, 50, 21, 11, 7, 5, 4, 7, 7, 6, 3, 1], | |
[7, 0, 50, 21, 16, 9, 6, 3, 5, 7, 6, 6, 2], | |
[1, 0, 50, 20, 19, 4, 5, 6, 7, 12, 5, 3, 4], | |
[0], | |
[0], | |
[1, 0, 34, 24, 9, 2, 6, 8, 9, 7, 3, 3, 5], | |
[8, 0, 34, 22, 4, 3, 5, 8, 13, 11, 5, 1, 3], | |
[9, 0, 32, 23, 9, 3, 2, 4, 12, 11, 5, 1, 3], | |
[10, 0, 30, 23, 13, 3, 2, 4, 12, 9, 6, 2, 4], | |
[9, 0, 29, 21, 13, 1, 7, 6, 10, 9, 6, 2, 4], | |
[8, 0, 29, 16, 13, 5, 8, 5, 9, 10, 6, 2, 3], | |
[6, 0, 29, 8, 19, 11, 8, 3, 11, 8, 6, 2, 1], | |
[6, 0, 29, 8, 28, 9, 4, 4, 9, 10, 5, 4, 2], | |
[7, 0, 30, 11, 29, 6, 6, 3, 8, 9, 5, 4, 4], | |
[9, 0, 30, 14, 22, 8, 9, 4, 5, 6, 6, 4, 1], | |
[8, 0, 33, 16, 24, 6, 7, 5, 6, 8, 6, 4, 2], | |
[10, 0, 35, 18, 18, 5, 8, 5, 8, 4, 6, 5, 2], | |
[10, 0, 35, 20, 21, 5, 7, 4, 8, 3, 5, 5, 2], | |
[9, 0, 35, 21, 22, 2, 5, 3, 11, 5, 5, 5, 2], | |
[9, 0, 35, 10, 12, 8, 12, 5, 8, 10, 3, 3, 5], | |
[9, 0, 36, 10, 11, 8, 12, 6, 6, 10, 3, 2, 4], | |
[8, 0, 36, 9, 12, 8, 13, 6, 6, 9, 4, 2, 4], | |
[8, 0, 37, 10, 11, 7, 13, 7, 6, 9, 4, 2, 4], | |
[9, 0, 37, 10, 11, 6, 12, 6, 8, 10, 4, 2, 3], | |
[11, 0, 39, 19, 18, 6, 5, 3, 8, 11, 5, 1, 4], | |
[12, 0, 41, 20, 15, 9, 8, 3, 7, 9, 5, 2, 2], | |
[12, 0, 47, 21, 13, 10, 9, 4, 6, 6, 6, 2, 3], | |
[13, 0, 48, 22, 10, 10, 10, 4, 7, 5, 5, 3, 3], | |
[12, 0, 49, 21, 11, 11, 11, 3, 8, 5, 5, 2, 3], | |
[12, 0, 48, 20, 11, 12, 11, 3, 7, 5, 5, 2, 3], | |
[11, 0, 48, 20, 10, 12, 12, 2, 7, 7, 5, 2, 3], | |
[11, 0, 48, 20, 10, 12, 12, 2, 6, 6, 5, 3, 3], | |
[11, 0, 47, 19, 10, 12, 12, 2, 6, 7, 6, 2, 3], | |
[10, 0, 47, 19, 11, 13, 13, 3, 5, 5, 5, 3, 4], | |
[10, 0, 45, 18, 11, 13, 13, 2, 5, 6, 5, 3, 4], | |
[10, 0, 43, 16, 13, 13, 13, 2, 5, 6, 5, 3, 4], | |
[9, 0, 40, 16, 13, 13, 12, 1, 5, 7, 5, 3, 4], | |
[8, 0, 40, 14, 12, 13, 13, 0, 6, 7, 5, 3, 3], | |
[8, 0, 38, 8, 16, 13, 12, 1, 6, 7, 4, 2, 3], | |
[9, 0, 38, 8, 19, 8, 7, 3, 10, 7, 3, 1, 5], | |
[7, 0, 38, 10, 15, 7, 7, 4, 10, 5, 4, 2, 4], | |
[8, 0, 41, 14, 13, 7, 8, 3, 10, 6, 4, 2, 4], | |
[5, 0, 44, 10, 11, 11, 14, 4, 7, 1, 3, 3, 6], | |
[9, 0, 43, 16, 12, 9, 11, 8, 10, 0, 5, 3, 3], | |
[12, 0, 44, 17, 12, 10, 11, 5, 8, 1, 5, 4, 4], | |
[12, 0, 45, 19, 12, 8, 12, 6, 5, 4, 5, 4, 5], | |
[12, 0, 44, 18, 15, 7, 10, 3, 5, 7, 4, 4, 6], | |
[9, 0, 43, 15, 12, 6, 9, 5, 6, 8, 6, 3, 6], | |
[10, 0, 43, 17, 12, 5, 10, 3, 5, 9, 7, 3, 4], | |
[12, 0, 43, 17, 12, 6, 10, 4, 6, 10, 6, 4, 2], | |
[11, 0, 43, 17, 10, 9, 8, 6, 7, 8, 7, 5, 1], | |
[10, 0, 44, 18, 9, 7, 8, 4, 6, 5, 6, 4, 2], | |
[6, 0, 46, 16, 11, 4, 6, 4, 7, 8, 4, 4, 4], | |
[5, 0, 47, 15, 10, 5, 6, 4, 6, 8, 5, 4, 5], | |
[9, 0, 39, 19, 12, 7, 6, 4, 7, 7, 5, 2, 4], | |
[13, 0, 42, 18, 11, 8, 7, 5, 6, 9, 6, 3, 2], | |
[12, 0, 43, 19, 12, 8, 7, 3, 7, 9, 7, 4, 2], | |
[8, 0, 44, 19, 9, 3, 10, 2, 5, 8, 5, 4, 2], | |
[3, 0, 47, 15, 8, 6, 7, 1, 5, 8, 4, 3, 2], | |
[2, 0, 47, 20, 8, 7, 7, 4, 4, 5, 4, 4, 3], | |
[0], | |
[0], | |
[0], | |
[0], | |
[11, 0, 43, 26, 15, 8, 9, 8, 7, 6, 3, 3, 3], | |
[13, 0, 47, 26, 13, 12, 10, 7, 4, 5, 3, 3, 1], | |
[11, 0, 31, 23, 14, 12, 12, 6, 8, 6, 5, 3, 4], | |
[11, 0, 31, 22, 14, 11, 11, 8, 8, 6, 5, 3, 3], | |
[12, 0, 36, 20, 10, 10, 8, 2, 6, 2, 4, 2, 2], | |
[11, 0, 36, 17, 21, 9, 6, 3, 6, 6, 4, 2, 2], | |
[9, 0, 35, 17, 25, 9, 6, 3, 6, 7, 4, 2, 3], | |
[9, 0, 35, 18, 28, 10, 6, 2, 8, 8, 4, 2, 3], | |
[9, 0, 35, 18, 27, 11, 7, 2, 8, 8, 4, 2, 4], | |
[9, 0, 34, 18, 26, 10, 8, 2, 9, 8, 4, 2, 5], | |
[9, 0, 33, 18, 20, 10, 10, 2, 7, 9, 5, 1, 5], | |
[10, 0, 33, 18, 20, 10, 9, 3, 6, 8, 6, 2, 5], | |
[9, 0, 34, 17, 26, 7, 6, 3, 8, 9, 3, 2, 4], | |
[1, 0, 46, 19, 17, 9, 8, 6, 6, 9, 3, 2, 3], | |
[1, 0, 34, 17, 18, 12, 7, 6, 7, 7, 4, 4, 4], | |
[1, 0, 34, 18, 21, 12, 9, 5, 6, 6, 4, 5, 4], | |
[0], | |
[0], | |
[2, 0, 0, 16, 18, 5, 6], | |
[0], | |
[4, 0, 41, 14, 9, 2, 14, 10, 4, 8, 3, 3, 4], | |
[7, 0, 41, 19, 10, 0, 10, 13, 7, 4, 5, 2, 5], | |
[9, 0, 41, 18, 9, 1, 11, 10, 7, 5, 5, 3, 5], | |
[8, 0, 41, 18, 8, 1, 11, 12, 8, 4, 5, 3, 5], | |
[9, 0, 40, 18, 10, 3, 10, 4, 7, 9, 6, 3, 5], | |
[11, 0, 39, 20, 14, 7, 9, 3, 6, 8, 6, 3, 4], | |
[11, 0, 39, 19, 11, 8, 10, 3, 7, 8, 6, 5, 3], | |
[11, 0, 38, 20, 10, 7, 11, 3, 5, 5, 5, 5, 4], | |
[10, 0, 38, 18, 11, 6, 11, 3, 5, 4, 5, 6, 4], | |
[6, 0, 39, 13, 14, 8, 10, 2, 4, 6, 6, 3, 5], | |
[4, 0, 39, 11, 11, 9, 9, 4, 8, 8, 4, 4, 2], | |
[1, 0, 39, 17, 14, 9, 8, 6, 7, 7, 3, 4, 3], | |
[1, 0, 39, 17, 10, 9, 8, 7, 6, 6, 4, 4, 3], | |
[0], | |
[0], | |
[5, 0, 40, 20, 15, 7, 8, 6, 8, 5, 3, 4, 4], | |
[9, 0, 45, 17, 12, 6, 12, 7, 3, 4, 6, 3, 5], | |
[10, 0, 47, 18, 9, 8, 12, 6, 8, 1, 6, 4, 5], | |
[11, 0, 49, 19, 13, 10, 11, 4, 8, 3, 6, 4, 4], | |
[12, 0, 50, 20, 15, 9, 10, 5, 8, 5, 6, 4, 3], | |
[11, 0, 51, 20, 17, 8, 10, 4, 8, 5, 7, 3, 3], | |
[12, 0, 52, 20, 18, 7, 9, 4, 7, 6, 6, 3, 4], | |
[12, 0, 52, 20, 18, 8, 9, 4, 7, 5, 6, 3, 4], | |
[11, 0, 49, 19, 19, 7, 8, 3, 8, 8, 6, 1, 3], | |
[8, 0, 54, 19, 12, 7, 7, 4, 5, 4, 5, 1, 1], | |
[9, 0, 52, 25, 13, 8, 7, 7, 4, 4, 2, 4, 3], | |
[9, 0, 52, 28, 13, 8, 10, 10, 8, 6, 2, 5, 4], | |
[10, 0, 54, 27, 16, 11, 9, 11, 7, 7, 2, 5, 4], | |
[9, 0, 56, 28, 15, 10, 9, 12, 11, 7, 2, 5, 3], | |
[9, 0, 51, 29, 17, 8, 10, 13, 10, 8, 2, 4, 5], | |
[6, 0, 51, 30, 20, 10, 9, 9, 9, 7, 4, 3, 2], | |
[2, 0, 51, 28, 18, 6, 9, 7, 6, 6, 3, 3, 3], | |
[8, 0, 51, 26, 17, 6, 10, 8, 6, 6, 4, 3, 4], | |
[11, 0, 52, 23, 14, 5, 8, 3, 5, 6, 6, 4, 6], | |
[12, 0, 54, 22, 17, 7, 9, 2, 6, 5, 5, 4, 7], | |
[12, 0, 55, 22, 18, 7, 7, 2, 7, 5, 5, 4, 7], | |
[12, 0, 56, 22, 20, 7, 6, 2, 7, 5, 4, 4, 7], | |
[10, 0, 59, 21, 21, 6, 5, 3, 8, 6, 5, 5, 7], | |
[9, 0, 60, 21, 23, 4, 5, 4, 9, 6, 5, 5, 6], | |
[8, 0, 61, 21, 21, 4, 5, 5, 10, 6, 5, 6, 5], | |
[8, 0, 61, 21, 24, 3, 7, 4, 8, 5, 6, 5, 4], | |
[5, 0, 62, 20, 18, 2, 6, 6, 10, 6, 5, 6, 3], | |
[6, 0, 60, 20, 17, 2, 7, 5, 8, 7, 5, 4, 4], | |
[6, 0, 61, 20, 13, 5, 6, 4, 8, 8, 5, 4, 4], | |
[6, 0, 63, 22, 11, 7, 8, 1, 6, 6, 6, 5, 4], | |
[5, 0, 31, 25, 9, 7, 8, 3, 7, 3, 5, 6, 5], | |
[5, 0, 45, 30, 17, 7, 11, 8, 4, 4, 1, 4, 4], | |
[4, 0, 45, 30, 18, 10, 8, 8, 7, 7, 2, 3, 4], | |
[4, 0, 35, 30, 19, 7, 10, 9, 7, 7, 2, 4, 4], | |
[4, 0, 35, 30, 21, 9, 10, 7, 10, 5, 3, 4, 5], | |
[2, 0, 35, 30, 21, 7, 10, 9, 9, 5, 4, 3, 4], | |
[2, 0, 54, 29, 20, 8, 11, 9, 9, 4, 4, 4, 4], | |
[5, 0, 56, 28, 14, 9, 11, 9, 10, 5, 3, 4, 3], | |
[3, 0, 57, 23, 14, 13, 11, 7, 7, 7, 2, 4, 3], | |
[2, 0, 59, 22, 16, 13, 9, 4, 7, 6, 3, 3, 3], | |
[2, 0, 64, 23, 12, 11, 10, 6, 6, 6, 3, 5, 3], | |
[2, 0, 63, 21, 16, 11, 9, 6, 7, 6, 2, 4, 3], | |
[2, 0, 64, 23, 13, 9, 7, 7, 5, 6, 3, 3, 3], | |
[2, 0, 64, 24, 14, 8, 7, 7, 7, 4, 3, 3, 3], | |
] | |
puts LpcFrameParser.hexify frames |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment