Skip to content

Commit

Permalink
refactor: zniffer exports, add to /safe entrypoint (#6830)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored May 8, 2024
1 parent d127c77 commit e7c5470
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 57 deletions.
1 change: 1 addition & 0 deletions packages/core/src/capabilities/Protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export enum MPDUHeaderType {
Singlecast = 0x1,
Multicast = 0x2,
Acknowledgement = 0x3,
Explorer = 0x5,
Routed = 0x8,
}

Expand Down
12 changes: 6 additions & 6 deletions packages/zwave-js/src/Zniffer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { BeamingInfo, MPDUHeaderType } from "@zwave-js/core/safe";
export type { MPDU } from "./lib/zniffer/MPDU";
export type {
BeamFrame,
Expand All @@ -6,12 +7,11 @@ export type {
LongRangeFrame,
ZWaveFrame,
} from "./lib/zniffer/MPDU";
export { LongRangeMPDU, ZWaveMPDU, parseMPDU } from "./lib/zniffer/MPDU";
export type { ZnifferOptions } from "./lib/zniffer/Zniffer";
export { Zniffer } from "./lib/zniffer/Zniffer";
export {
ExplorerFrameCommand,
LongRangeFrameType,
LongRangeMPDU,
ZWaveFrameType,
ZWaveMPDU,
parseMPDU,
} from "./lib/zniffer/MPDU";
export type { ZnifferOptions } from "./lib/zniffer/Zniffer";
export { Zniffer } from "./lib/zniffer/Zniffer";
} from "./lib/zniffer/_Types";
7 changes: 7 additions & 0 deletions packages/zwave-js/src/Zniffer_safe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { BeamingInfo, MPDUHeaderType } from "@zwave-js/core/safe";
export type { ZnifferOptions } from "./lib/zniffer/Zniffer";
export {
ExplorerFrameCommand,
LongRangeFrameType,
ZWaveFrameType,
} from "./lib/zniffer/_Types";
1 change: 1 addition & 0 deletions packages/zwave-js/src/index_safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from "./Error";
export * from "./Node_safe";
export * from "./Utils_safe";
export * from "./Values";
export * from "./Zniffer_safe";
57 changes: 7 additions & 50 deletions packages/zwave-js/src/lib/zniffer/MPDU.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type CommandClass } from "@zwave-js/cc";
import {
type BeamingInfo,
MPDUHeaderType,
type MessageOrCCLogEntry,
type MessageRecord,
Protocols,
Expand All @@ -26,16 +28,11 @@ import {
} from "@zwave-js/shared";
import { padStart } from "alcalzone-shared/strings";
import { parseRSSI } from "../serialapi/transport/SendDataShared";

// FIXME: Parsing breaks on this chunk:
// 21003021030bdcb605840141020b03005e2101000021003421030adcb6058403
// 03020a011d2101000002002a21030ec5b9bc284641010e019f01be32d42101000002002a21030e
// c5b9bc284641010e019f01be32d42101000021002921030dc5b9bc284651010d019f01be2d2101
// 000002002a210311c5b9bc2846910111010010439f01beb6a32101000002002a
// 210311c5b9bc2846810111010010439f01be2235

// FIXME: Beam Stop frame is followed by 0x00, which gets discarded - why?
// 210500003000e6210100 00
import {
ExplorerFrameCommand,
LongRangeFrameType,
ZWaveFrameType,
} from "./_Types";

function getChannelConfiguration(region: ZnifferRegion): "1/2" | "3" | "4" {
switch (region) {
Expand Down Expand Up @@ -95,27 +92,6 @@ export interface MPDUOptions {
frameInfo: ZnifferFrameInfo;
}

export enum MPDUHeaderType {
Singlecast = 0x1,
Multicast = 0x2,
Acknowledgement = 0x3,
Explorer = 0x5,
Routed = 0x8,
}

export enum BeamingInfo {
None = 0b00,
ShortContinuous = 0b01,
LongContinuous = 0b10,
Fragmented = 0b100,
}

export enum ExplorerFrameCommand {
Normal = 0x00,
InclusionRequest = 0x01,
SearchResult = 0x02,
}

export interface MPDU {
frameInfo: ZnifferFrameInfo;
homeId: number;
Expand Down Expand Up @@ -934,18 +910,6 @@ export class BeamStop {
}
}

export enum ZWaveFrameType {
Singlecast,
Multicast,
AckDirect,
ExplorerNormal,
ExplorerSearchResult,
ExplorerInclusionRequest,
BeamStart,
BeamStop,
}

/** An application-oriented representation of a Z-Wave frame that was captured by the Zniffer */
export type ZWaveFrame =
// Common fields for all Z-Wave frames
& {
Expand Down Expand Up @@ -1042,13 +1006,6 @@ export type ZWaveFrame =
)
);

export enum LongRangeFrameType {
Singlecast,
Ack,
BeamStart,
BeamStop,
}

export type LongRangeFrame =
// Common fields for all Long Range frames
& {
Expand Down
2 changes: 1 addition & 1 deletion packages/zwave-js/src/lib/zniffer/Zniffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
CommandClasses,
type LogConfig,
MPDUHeaderType,
type RSSI,
SPANState,
SecurityClass,
Expand Down Expand Up @@ -61,7 +62,6 @@ import { ZnifferCCParsingContext } from "./CCParsingContext";
import {
type CorruptedFrame,
type Frame,
MPDUHeaderType,
beamToFrame,
mpduToFrame,
parseBeamFrame,
Expand Down
25 changes: 25 additions & 0 deletions packages/zwave-js/src/lib/zniffer/_Types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export enum ExplorerFrameCommand {
Normal = 0x00,
InclusionRequest = 0x01,
SearchResult = 0x02,
}

export enum ZWaveFrameType {
Singlecast,
Multicast,
AckDirect,
ExplorerNormal,
ExplorerSearchResult,
ExplorerInclusionRequest,
BeamStart,
BeamStop,
}

/** An application-oriented representation of a Z-Wave frame that was captured by the Zniffer */

export enum LongRangeFrameType {
Singlecast,
Ack,
BeamStart,
BeamStop,
}

0 comments on commit e7c5470

Please sign in to comment.