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

EZSP: Enable software flow control only if RTS/CTS not enabled. #897

Merged
merged 2 commits into from
Jan 30, 2024
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
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