Skip to content

Commit

Permalink
fix flush command handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thingersoft committed Jun 11, 2018
1 parent cfb1b7b commit 0a973b5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/g2core-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class G2coreAPI extends EventEmitter {
this.emit('setupDone');

// Allow data to be sent. We'll start with 5 lines to fill the buffer.
this.linesRequested = 5;
this._resetLinesRequested();
this._sendLines();
});
}; // _completeConnection
Expand Down Expand Up @@ -467,7 +467,15 @@ class G2coreAPI extends EventEmitter {
this.emit('sentLine', lastLineSent);
}; // _sendLines


/**
* _resetLinesRequested - internal only
*/
_resetLinesRequested() {
this.linesRequested = 5;
}; // _resetLinesRequested


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

// Reset line requested
this.linesRequested = 5;
this._resetLinesRequested();

// Send a queue flush followed by an alarm clear
this._write('\x04'); // send the ^D
Expand Down Expand Up @@ -603,6 +611,15 @@ class G2coreAPI extends EventEmitter {
this.ignoredResponses++;
}
this._write(value);

// handle flush command
if(typeof value === 'string' && value.match(/^[!]+$/)) {
this._resetLinesRequested();
this.linesSent = 0;
this.ignoredResponses = 0;
this.lineBuffer.length = 0;
}

return;
}

Expand Down

0 comments on commit 0a973b5

Please sign in to comment.