The Quectel BC95 module expects the data payload as hex strings. Are the following methods, the most memory efficient way of doing this?
//convert to a hex string
for (var i = 0; i < data.length; i++) {
var s = data.charCodeAt(i).toString(16);
while (s.length < 2) {
s = '0' + s;
}
msg += s;
}
and conversely:
for (let ndx = 0; ndx < (recvData[1] * 2); ndx += 2) {
let i = parseInt("0x" + recvData[2].substring(ndx, ndx + 2)); //ascii hex to integer
sockData[connection] += String.fromCharCode(i); //build a string
}
From my limited understanding, this code would create a string, append and create a new string, rinse and repeat. This seems like a bit of overhead. I did consider typed arrays, but how do I convert these back to a string in one go?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
The Quectel BC95 module expects the data payload as hex strings. Are the following methods, the most memory efficient way of doing this?
and conversely:
From my limited understanding, this code would create a string, append and create a new string, rinse and repeat. This seems like a bit of overhead. I did consider typed arrays, but how do I convert these back to a string in one go?