From d5b4eab971c3f9b02cc5981ea3ae36679d7fa566 Mon Sep 17 00:00:00 2001 From: busticated Date: Mon, 30 Nov 2020 17:32:10 -0800 Subject: [PATCH 1/3] re-enable global rejection handler fixes: UnhandledPromiseRejectionWarning and related deprecation warnings --- src/app/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/cli.js b/src/app/cli.js index b9ba77b52..fb2de139a 100644 --- a/src/app/cli.js +++ b/src/app/cli.js @@ -10,7 +10,7 @@ const commandProcessor = require('./command-processor'); module.exports = class CLI { constructor() { - //process.on('unhandledRejection', this.globalRejectionHandler.bind(this)); + process.on('unhandledRejection', this.globalRejectionHandler.bind(this)); this.rootCategory = this.setupCommandProcessor(); } From 7e2877467ad076b93d164464ef3339ffd1870db4 Mon Sep 17 00:00:00 2001 From: busticated Date: Mon, 30 Nov 2020 17:35:02 -0800 Subject: [PATCH 2/3] update buffer initialization calls for node@8 and beyond fixes (node:15707) [DEP0005] DeprecationWarning: Buffer() is deprecated --- src/lib/ymodem.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/ymodem.js b/src/lib/ymodem.js index 8710b8a33..eefa5bd7a 100644 --- a/src/lib/ymodem.js +++ b/src/lib/ymodem.js @@ -169,28 +169,28 @@ module.exports = class YModem { return send(); }) .then(() => { - let buf = new Buffer([ymodem.EOT]); + let buf = Buffer.from([ymodem.EOT]); log.verbose('write', self.seq, buf, buf.length); return self._sendRawPacket(buf); }); } _sendFileHeader(name, length){ - let buf = new Buffer(name + '\0' + length + ' '); + let buf = Buffer.from(name + '\0' + length + ' '); return this._sendPacket(buf); } _sendPacket(packet){ if (packet.length < this.options.packetLength){ - let filler = new Buffer(this.options.packetLength - packet.length); + let filler = Buffer.alloc(this.options.packetLength - packet.length); filler.fill(0); packet = Buffer.concat([packet, filler], this.options.packetLength); } let seqchr = this.seq & 0xFF; let seqchrNeg = (-this.seq - 1) & 0xFF; - let header = new Buffer([this.mark, seqchr, seqchrNeg]); - let crc16 = new Buffer([0, 0]); + let header = Buffer.from([this.mark, seqchr, seqchrNeg]); + let crc16 = Buffer.from([0, 0]); packet = Buffer.concat([header, packet, crc16]); log.verbose('write', this.seq, header, packet.length); @@ -200,7 +200,7 @@ module.exports = class YModem { _sendRawPacket(packet){ const self = this; const response = new Promise((resolve, reject) => { - let resp = new Buffer([]); + let resp = Buffer.from([]); function writeResponse(){ let data = self.port.read(); From d0436d26c3352a624e72d1e5d52164a0b3bd1d1c Mon Sep 17 00:00:00 2001 From: busticated Date: Mon, 30 Nov 2020 20:43:00 -0800 Subject: [PATCH 3/3] ensure line-break is received when opening a serial connection to a device --- src/lib/ymodem.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/ymodem.js b/src/lib/ymodem.js index eefa5bd7a..45d9d6abc 100644 --- a/src/lib/ymodem.js +++ b/src/lib/ymodem.js @@ -101,14 +101,17 @@ module.exports = class YModem { } // wait for initial response + const readyMsg = "Waiting for the binary file to be sent ... (press 'a' to abort)"; + const linebreakPtn = /\r?\n/; let line = ''; function cmdResponse(){ let data = self.port.read(); self._logData(data); line += data.toString(); + const lines = line.split(linebreakPtn); // if not in listening mode, we get CRC16 back - // if in listening mode, we get this string - if (data[0] === ymodem.CRC16 || line.trim() === "Waiting for the binary file to be sent ... (press 'a' to abort)"){ + // if in listening mode, we get the ready message + if (data[0] === ymodem.CRC16 || (lines.length > 1 && lines.some(l => l === readyMsg))){ self.port.removeListener('readable', cmdResponse); return resolve(); }