Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] HMS Code mapping #5

Open
WolfwithSword opened this issue Apr 28, 2023 · 0 comments
Open

[Feature Request] HMS Code mapping #5

WolfwithSword opened this issue Apr 28, 2023 · 0 comments

Comments

@WolfwithSword
Copy link
Contributor

Wasn't sure where this would fit in the current layout, so I will give my findings here.

In the report print payload for all sensors (or a subset if the P1P as it does not send all unless pushall is invoked), there is the value hms with an array.

If it contains values, it is as such:

"hms": [
    {
        "code": "somecode",
        "attr": "somecode"
    },
    {
        "code": "somecode",
        "attr": "somecode"
    }
]

The codes and attributes are not recognizable at first, but can be mapped to errors. Both the code and attr are decimal numbers that when converted to Hex with Two's complement, then append the code after the attr and separate each set of 4 character with an underscore, it will be in the format of Bambu's official HMS code errors as per their website.

Note: Not all hms codes are documented yet.

Here is a snippet of how I convert them in nodered:

function DecimalHexTwosComplement(decimal) {
    var size = 8;
    var hexadecimal;
    if (decimal >= 0) {
        hexadecimal = decimal.toString(16);

        while ((hexadecimal.length % size) != 0) {
            hexadecimal = "" + 0 + hexadecimal;
        }

        return hexadecimal;
    } else {
        hexadecimal = Math.abs(decimal).toString(16);
        while ((hexadecimal.length % size) != 0) {
            hexadecimal = "" + 0 + hexadecimal;
        }

        var output = '';
        for (var i = 0; i < hexadecimal.length; i++) {
            output += (0x0F - parseInt(hexadecimal[i], 16)).toString(16);
        }

        output = (0x01 + parseInt(output, 16)).toString(16);
        return output;
    }
}

let template = [];
if(msg.payload.print.hms != undefined){
    for (var hms_code of msg.payload.print.hms) {
        var attr = DecimalHexTwosComplement(hms_code.attr);
        var code = DecimalHexTwosComplement(hms_code.code);
        let full_code = (attr + code).replace(/(.{4})/g, "$1_");
        full_code = full_code.substring(0, full_code.length - 1);
        let url = "https://wiki.bambulab.com/en/x1/troubleshooting/hmscode/"+full_code;
        template.push({"code": "HMS_"+full_code, "url": url});
    }
    msg.payload.print.hms = template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant