Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix/ch68743/serial-flash-windows #598

Merged
merged 3 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
19 changes: 11 additions & 8 deletions src/lib/ymodem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
busticated marked this conversation as resolved.
Show resolved Hide resolved
// 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();
}
Expand Down Expand Up @@ -169,28 +172,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);

Expand All @@ -200,7 +203,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();

Expand Down