Skip to content

Leading 0 in binary Ook to Sub (Tool-SubGhz) gets dropped #22

@NZSmartie

Description

@NZSmartie

I have a generic key fob with a HS1527 chip

image

Messages are sent with a preamble, 20bit unique ID and then 4bit value representing which buttons are pressed.
the preamble looks exactly like a binary '0', Thus when using the Ook to Sub tool with a binary input, the leading 0 gets truncated.

For example, here is the result for the input 0 1010 1010 1010 1010 0100 and (and transpose (1 -> 1110 and 0 0> 1000, with a width 333 for on and off)

image

A work around is to invert the binary message and use the transpose fields to flip them back, preserving the initial binary 0 required for preamble.

image

I believe the culprit is the following line:

getFormBinHexOok(getValue = false){
if(getValue){
var raw = this.getForm().elements["binHexOokToSub"].value.toString().trim();
raw = cleanString(raw).toString();
var isHex = allHex(raw);
var isBin = allBinary(raw);
var isNumber = allNumeric(raw);
var cleanValue = 0;
if (isBin){
cleanValue = BigInt("0b"+raw);
//console.log("base2~"+cleanValue.toString());
} else if (isHex){
cleanValue = BigInt("0x"+raw);
//console.log("base16~"+cleanValue.toString());
} else if (isNumber){ //should never reach this because all ints are also hex
cleanValue = parseInt(raw, 10);
//console.log("base10~"+cleanValue.toString());
}
return cleanValue.toString(10);
}else{
return this.getForm().elements["binHexOokToSub"];
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions