After checking out suggestions from @maze1980 and @Robin, I've created my TCP message handler, and it kinda works. I appear to be getting data corruption in the buffer that I copy the incoming data into, and I can't figure out what I'm doing wrong. The handler:
if(this.tcpBuffer && this.tcpBuffer.byteLength) {
let leftoverDataLen = this.tcpBuffer.byteLength;
let tmpBuffer = new Uint8Array(leftoverDataLen + chunk.length);
tmpBuffer.set(this.tcpBuffer, 0);
tmpBuffer.set(E.toUint8Array(chunk), leftoverDataLen);
this.tcpBuffer = tmpBuffer;
}
else {
this.tcpBuffer = E.toUint8Array(chunk);
}
So I either start off with a brand new copy of the incoming data (converted to Uint8Array), or I append the new data to the end of the current buffer. When done, this.tcpBuffer should contain all of the data that I've not yet processed. Am I doing this correctly / is there a better way to append the data?
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.
After checking out suggestions from @maze1980 and @Robin, I've created my TCP message handler, and it kinda works. I appear to be getting data corruption in the buffer that I copy the incoming data into, and I can't figure out what I'm doing wrong. The handler:
So I either start off with a brand new copy of the incoming data (converted to Uint8Array), or I append the new data to the end of the current buffer. When done, this.tcpBuffer should contain all of the data that I've not yet processed. Am I doing this correctly / is there a better way to append the data?