2022-03-22, 10:09 PM
I finally found the solution (as a non developer)
The solution by e-sailing was in the right direction but not correct.
1) the problem is in the reading, exports.parseMXPGN and not in exports.encodeMXPGN which is I assume the sending part.
2) the code for reversing the Bytes is not working.
I found a function on internet
So added it in the stringMsg.js
And updated like:
For incomming messages it's working fine now.
I did not test for outgoing yet, but I expect the same function should be used.
I will propose this change in github.
The solution by e-sailing was in the right direction but not correct.
1) the problem is in the reading, exports.parseMXPGN and not in exports.encodeMXPGN which is I assume the sending part.
2) the code for reversing the Bytes is not working.
I found a function on internet
Code:
const changeEndianness = (string) => {
const result = [];
let len = string.length - 2;
while (len >= 0) {
result.push(string.substr(len, 2));
len -= 2;
}
return result.join('');
}
So added it in the stringMsg.js
And updated like:
Code:
exports.parseMXPGN = (input) => {
console.log('MXpgn parse input' + input)
const [ prefix, pgn, attr_word, data ] = input.split(',')
console.log('MXpgn parse data ' + data)
var buff = changeEndianness(rmChecksum(data));
const send_prio_len = (parseInt(attr_word.substr(0,2), 16).toString(2)).padStart(8, '0');
const addr = (parseInt(attr_word.substr(2,2), 16));
const send = parseInt(send_prio_len.substr(0,1), 2);
const prio = parseInt(send_prio_len.substr(1,3), 2);
const len = parseInt(send_prio_len.substr(4,4), 2);
console.log('stringMsg:MXpgn parse: attr_word ' + attr_word)
console.log('stringMsg:MXpgn parse: ' + addr + ' ' + send + ' ' + prio + ' ' + len)
let src, dst;
send ? dst = addr: src = addr;
return buildMsg(
buildCanId(0, parseInt(pgn, 16), 255, parseInt(src, 16)),
'MXPGN',
Buffer.from(buff, 'hex'),
{ coalesced: true, prefix },
)
}
For incomming messages it's working fine now.
I did not test for outgoing yet, but I expect the same function should be used.
I will propose this change in github.