Skip to content

Commit

Permalink
feat: add option to limit captured frames
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed May 21, 2024
1 parent f5fa06a commit 7e3e9b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
27 changes: 25 additions & 2 deletions docs/api/zniffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ interface ZnifferOptions {
* Supported regions and their names have to be queried using the `getFrequencies` and `getFrequencyInfo(frequency)` commands.
*/
defaultFrequency?: number;

/** Limit the number of frames that are kept in memory. */
maxCapturedFrames?: number;
}
```

Expand Down Expand Up @@ -250,6 +253,14 @@ type ZWaveFrame =
)
>
)
// Broadcast frame. This is technically a singlecast frame,
// but the destination node ID is always 255 and it is not routed
| {
type: ZWaveFrameType.Broadcast;
destinationNodeId: typeof NODE_ID_BROADCAST;
ackRequested: boolean;
payload: Buffer | CommandClass;
}
| {
// Multicast frame, not routed
type: ZWaveFrameType.Multicast;
Expand All @@ -275,6 +286,7 @@ type ZWaveFrame =
} | {
type: ZWaveFrameType.ExplorerInclusionRequest;
networkHomeId: number;
payload: Buffer | CommandClass;
})
// Common fields for all explorer frames
& {
Expand Down Expand Up @@ -313,12 +325,21 @@ type LongRangeFrame =
}
// Different kinds of Long Range frames:
& (
{
| {
// Singlecast frame
type: LongRangeFrameType.Singlecast;
ackRequested: boolean;
payload: Buffer | CommandClass;
} | {
}
| {
// Broadcast frame. This is technically a singlecast frame,
// but the destination node ID is always 4095
type: LongRangeFrameType.Broadcast;
destinationNodeId: typeof NODE_ID_BROADCAST_LR;
ackRequested: boolean;
payload: Buffer | CommandClass;
}
| {
// Acknowledgement frame
type: LongRangeFrameType.Ack;
incomingRSSI: RSSI;
Expand Down Expand Up @@ -401,6 +422,7 @@ enum ZWaveFrameType {
ExplorerInclusionRequest,
BeamStart,
BeamStop,
Broadcast,
}
```

Expand All @@ -412,6 +434,7 @@ enum LongRangeFrameType {
Ack,
BeamStart,
BeamStop,
Broadcast,
}
```

Expand Down
2 changes: 1 addition & 1 deletion packages/zwave-js/src/lib/zniffer/MPDU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ export type LongRangeFrame =
}
| {
// Broadcast frame. This is technically a singlecast frame,
// but the destination node ID is always 4095 and it is not routed
// but the destination node ID is always 4095
type: LongRangeFrameType.Broadcast;
destinationNodeId: typeof NODE_ID_BROADCAST_LR;
ackRequested: boolean;
Expand Down
9 changes: 9 additions & 0 deletions packages/zwave-js/src/lib/zniffer/Zniffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export interface ZnifferOptions {
* Supported regions and their names have to be queried using the `getFrequencies` and `getFrequencyInfo(frequency)` commands.
*/
defaultFrequency?: number;

/** Limit the number of frames that are kept in memory. */
maxCapturedFrames?: number;
}

function is700PlusSeries(
Expand Down Expand Up @@ -399,6 +402,12 @@ export class Zniffer extends TypedEventEmitter<ZnifferEventCallbacks> {
frameData: dataMsg.payload,
};
this._capturedFrames.push(capture);
if (
this._options.maxCapturedFrames != undefined
&& this._capturedFrames.length > this._options.maxCapturedFrames
) {
this._capturedFrames.shift();
}
this.handleDataMessage(dataMsg, capture);
}
}
Expand Down

0 comments on commit 7e3e9b8

Please sign in to comment.