XOR and ADD of the buffer numbers

I found one more small problem. Main unit isn't accepting when I wll send a object and I must transform back to buffer. :frowning:
But I hope buffer maker will help
maybe better way is not transfer buffer to bject, but stay with buffer

back to my first question. I reworked it to work with buffer.
Is it possible rework this :

const data = Object.entries(msg.payload);

let ADDS = 0;
let XORS = 0;
for (let index = 0; index < data.length; index++) {
    const item = data[index][0];
    const value = data[index][1];
    if (item === "ADDS") continue; //skip ADDS prop
    if (item === "XORS") continue; //skip XORS prop
    if (item === "END") continue; //skip END prop
    ADDS += value;
    XORS ^= value;
}
msg.payload.ADDS = (ADDS ^ 0xAA) & 0xFF;
msg.payload.XORS = (XORS ^ 0xAA) & 0xFF;

return msg;

to work with this buffer ?:

I tried this, but result isn't ok:

let ADDS = 0;
let XORS = 0;
for (let index = 0; index < 15; index++) {
    const value = msg.payload.readUInt8(index);
    ADDS += value;
    XORS ^= value;
}
ADDS = (ADDS ^ 0xAA) & 0xFF;
XORS = (XORS ^ 0xAA) & 0xFF;
msg.payload.writeUInt8(ADDS,12)
msg.payload.writeUInt8(XORS,13)
return msg;

I got it, problem is buffer length. Not 15 but only 13 :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.