Skip to content

Commit ae49e8f

Browse files
committed
fix flush command handling
1 parent cfb1b7b commit ae49e8f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/g2core-api.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ class G2coreAPI extends EventEmitter {
424424
this.emit('setupDone');
425425

426426
// Allow data to be sent. We'll start with 5 lines to fill the buffer.
427-
this.linesRequested = 5;
427+
this._resetLinesRequested();
428428
this._sendLines();
429429
});
430430
}; // _completeConnection
@@ -467,7 +467,15 @@ class G2coreAPI extends EventEmitter {
467467
this.emit('sentLine', lastLineSent);
468468
}; // _sendLines
469469

470+
471+
/**
472+
* _resetLinesRequested - internal only
473+
*/
474+
_resetLinesRequested() {
475+
this.linesRequested = 5;
476+
}; // _resetLinesRequested
470477

478+
471479
/**
472480
* flush - empty the send buffer, without sending what's left
473481
*/
@@ -479,7 +487,7 @@ class G2coreAPI extends EventEmitter {
479487
this.lineBuffer.length = 0;
480488

481489
// Reset line requested
482-
this.linesRequested = 5;
490+
this._resetLinesRequested();
483491

484492
// Send a queue flush followed by an alarm clear
485493
this._write('\x04'); // send the ^D
@@ -603,6 +611,15 @@ class G2coreAPI extends EventEmitter {
603611
this.ignoredResponses++;
604612
}
605613
this._write(value);
614+
615+
// handle flush command
616+
if(typeof value === 'string' && value.match(/^[%]+$/)) {
617+
this._resetLinesRequested();
618+
this.linesSent = 0;
619+
this.ignoredResponses = 0;
620+
this.lineBuffer.length = 0;
621+
}
622+
606623
return;
607624
}
608625

0 commit comments

Comments
 (0)