Doridian / Doridian/OpenBambuAPI

[Feature Request] HMS Code mapping

Open
#5 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
680
Forks
96
PR merge metrics
No merged PRs in 30d

Description

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:
```json
"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:
```js
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;
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.