Created
June 10, 2021 08:26
-
-
Save anszom/732b5b7dda9ccb624980153dff1d7c1f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/perl | |
# usage: gatttool -b FC:58:FA:xx:xx:xx --char-read --listen -a 9 | decoder.pl | |
my %digits = ( | |
'1110111' => 0, | |
'0010010' => 1, | |
'1011101' => 2, | |
'1011011' => 3, | |
'0111010' => 4, | |
'1101011' => 5, | |
'1101111' => 6, | |
'1010010' => 7, | |
'1111111' => 8, | |
'1111011' => 9, | |
); | |
sub decode | |
{ | |
return (@_[0]=='1'?'.':'').$digits{join("", @_[3,2,7,6,1,5,4])}; | |
} | |
my @bits1 = ( | |
); | |
my @bits2 = ( | |
"HOLD", "degF", "degC", "->", "MAX", "MIN", "%", "AC", | |
"F", "u(F)", "?5", "n(F)", "Hz", "ohm", "K(ohm)", "M(ohm)", | |
"V", "m(V)", "DC", "A", "auto", "?7", "u(A)", "m(A)", | |
"?8", "?9", "?10", "?11" | |
); | |
# missing: low battery, mF (maybe ?5) | |
# also: somewhere there may be the BT icon permanently lit | |
# part1 | |
# 1101 1000 0010 0001 0000 1110 1000 | |
# 1101 1000 0010 0001 0000 1110 1100 delta bit | |
my $xorkey = "\x41\x21\x73\x55\xa2\xc1\x32\x71\x66\xaa\x3b\xd0\xe2\xa8\x33\x14\x20\x21\xaa\xbb"; | |
while(<>) { | |
chomp; | |
s/.*value://; | |
s/[^0-9a-fA-F]//g; | |
my $data = pack("H*", $_); | |
$data ^= $xorkey; #"\x1b\x84\x70\x51\xa2\xc1\x32\x71\x66\xaa\x3b"; | |
@a=split("", unpack("b*", $data)); | |
$d0=decode(@a[28..35]); | |
$d0=~s/\./-/; | |
$d1=decode(@a[36..43]); | |
$d2=decode(@a[44..51]); | |
$d3=decode(@a[52..59]); | |
# print @a[0..27], " " , @a[28..59], " ", @a[60..87], " "; | |
print "$d0$d1$d2$d3 "; | |
for(0..$#bits2) { | |
if($a[60+$_]) { | |
print $bits2[$_],", "; | |
} | |
} | |
print "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More Reversedatas:
"?5" --> m(F)
Bit 24 = CRC or Parityerror ??
Bit 25 = Delta / Rel
Bit 26 = BT?
Bit 27 = Buzzer/Beeper