From e7c5470c06d5ff1ba63945fdfa8a9fdaa619fa5c Mon Sep 17 00:00:00 2001 From: AlCalzone Date: Wed, 8 May 2024 23:31:36 +0200 Subject: [PATCH] refactor: zniffer exports, add to `/safe` entrypoint (#6830) --- packages/core/src/capabilities/Protocols.ts | 1 + packages/zwave-js/src/Zniffer.ts | 12 ++--- packages/zwave-js/src/Zniffer_safe.ts | 7 +++ packages/zwave-js/src/index_safe.ts | 1 + packages/zwave-js/src/lib/zniffer/MPDU.ts | 57 +++----------------- packages/zwave-js/src/lib/zniffer/Zniffer.ts | 2 +- packages/zwave-js/src/lib/zniffer/_Types.ts | 25 +++++++++ 7 files changed, 48 insertions(+), 57 deletions(-) create mode 100644 packages/zwave-js/src/Zniffer_safe.ts create mode 100644 packages/zwave-js/src/lib/zniffer/_Types.ts diff --git a/packages/core/src/capabilities/Protocols.ts b/packages/core/src/capabilities/Protocols.ts index 57acdfc5ab18..777a7f665c57 100644 --- a/packages/core/src/capabilities/Protocols.ts +++ b/packages/core/src/capabilities/Protocols.ts @@ -128,6 +128,7 @@ export enum MPDUHeaderType { Singlecast = 0x1, Multicast = 0x2, Acknowledgement = 0x3, + Explorer = 0x5, Routed = 0x8, } diff --git a/packages/zwave-js/src/Zniffer.ts b/packages/zwave-js/src/Zniffer.ts index 695814358364..85c656d605d0 100644 --- a/packages/zwave-js/src/Zniffer.ts +++ b/packages/zwave-js/src/Zniffer.ts @@ -1,3 +1,4 @@ +export { BeamingInfo, MPDUHeaderType } from "@zwave-js/core/safe"; export type { MPDU } from "./lib/zniffer/MPDU"; export type { BeamFrame, @@ -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"; diff --git a/packages/zwave-js/src/Zniffer_safe.ts b/packages/zwave-js/src/Zniffer_safe.ts new file mode 100644 index 000000000000..fe9df8784945 --- /dev/null +++ b/packages/zwave-js/src/Zniffer_safe.ts @@ -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"; diff --git a/packages/zwave-js/src/index_safe.ts b/packages/zwave-js/src/index_safe.ts index 9043694834bc..17b702db6647 100644 --- a/packages/zwave-js/src/index_safe.ts +++ b/packages/zwave-js/src/index_safe.ts @@ -6,3 +6,4 @@ export * from "./Error"; export * from "./Node_safe"; export * from "./Utils_safe"; export * from "./Values"; +export * from "./Zniffer_safe"; diff --git a/packages/zwave-js/src/lib/zniffer/MPDU.ts b/packages/zwave-js/src/lib/zniffer/MPDU.ts index 283e965d183f..5ed005cc20b7 100644 --- a/packages/zwave-js/src/lib/zniffer/MPDU.ts +++ b/packages/zwave-js/src/lib/zniffer/MPDU.ts @@ -1,5 +1,7 @@ import { type CommandClass } from "@zwave-js/cc"; import { + type BeamingInfo, + MPDUHeaderType, type MessageOrCCLogEntry, type MessageRecord, Protocols, @@ -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) { @@ -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; @@ -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 & { @@ -1042,13 +1006,6 @@ export type ZWaveFrame = ) ); -export enum LongRangeFrameType { - Singlecast, - Ack, - BeamStart, - BeamStop, -} - export type LongRangeFrame = // Common fields for all Long Range frames & { diff --git a/packages/zwave-js/src/lib/zniffer/Zniffer.ts b/packages/zwave-js/src/lib/zniffer/Zniffer.ts index 5488d7a0012b..a068d07311b3 100644 --- a/packages/zwave-js/src/lib/zniffer/Zniffer.ts +++ b/packages/zwave-js/src/lib/zniffer/Zniffer.ts @@ -8,6 +8,7 @@ import { import { CommandClasses, type LogConfig, + MPDUHeaderType, type RSSI, SPANState, SecurityClass, @@ -61,7 +62,6 @@ import { ZnifferCCParsingContext } from "./CCParsingContext"; import { type CorruptedFrame, type Frame, - MPDUHeaderType, beamToFrame, mpduToFrame, parseBeamFrame, diff --git a/packages/zwave-js/src/lib/zniffer/_Types.ts b/packages/zwave-js/src/lib/zniffer/_Types.ts new file mode 100644 index 000000000000..88d34d11f587 --- /dev/null +++ b/packages/zwave-js/src/lib/zniffer/_Types.ts @@ -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, +}