Skip to content

Commit

Permalink
fix: EZSP: Enable software flow control only if RTS/CTS not enabled. (#…
Browse files Browse the repository at this point in the history
…897)

* Enable software flow control only if RTS/CTS not enabled.

* log
  • Loading branch information
Nerivec authored Jan 30, 2024
1 parent 73acff1 commit a0f2ce9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/adapter/ezsp/driver/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ const debug = Debug('zigbee-herdsman:adapter:ezsp:uart');

export class Parser extends stream.Transform {
private buffer: Buffer;
private flagXONXOFF: boolean;

public constructor() {
public constructor(flagXONXOFF: boolean = false) {
super();

this.flagXONXOFF = flagXONXOFF;
this.buffer = Buffer.from([]);
}

public _transform(chunk: Buffer, _: string, cb: () => void): void {
if (this.flagXONXOFF && (chunk.indexOf(consts.XON) >= 0 || chunk.indexOf(consts.XOFF) >= 0)) {
// XXX: should really throw, but just assert for now to flag potential problematic setups
console.assert(false, `Host driver did not remove XON/XOFF from input stream. Driver not setup for XON/XOFF?`);
}

if (chunk.indexOf(consts.CANCEL) >= 0) {
this.buffer = Buffer.from([]);
chunk = chunk.subarray(chunk.lastIndexOf(consts.CANCEL) + 1);
Expand Down
13 changes: 10 additions & 3 deletions src/adapter/ezsp/driver/uart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ export class SerialDriver extends EventEmitter {
autoOpen: false,
parity: 'none',
stopBits: 1,
xon: true,
xoff: true,
xon: false,
xoff: false,
};

// enable software flow control if RTS/CTS not enabled in config
if (!options.rtscts) {
debug(`RTS/CTS config is off, enabling software flow control.`);
options.xon = true;
options.xoff = true;
}

debug(`Opening SerialPort with ${JSON.stringify(options)}`);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand All @@ -84,7 +91,7 @@ export class SerialDriver extends EventEmitter {
this.writer = new Writer();
this.writer.pipe(this.serialPort);

this.parser = new Parser();
this.parser = new Parser(!options.rtscts);// flag unhandled XON/XOFF in logs if software flow control enabled
this.serialPort.pipe(this.parser);
this.parser.on('parsed', this.onParsed.bind(this));

Expand Down

0 comments on commit a0f2ce9

Please sign in to comment.