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

feat: zniffer #3706

Merged
merged 124 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
547377a
feat: zniffer
robertsLando May 8, 2024
8569237
fix: recursive frame parsing
robertsLando May 8, 2024
80e8fa0
fix: build issues
robertsLando May 8, 2024
cbe088c
feat: start with ui implementation
robertsLando May 8, 2024
1e37d20
feat: add cc tree view
robertsLando May 8, 2024
bd073a1
fix: add some other props to table
robertsLando May 8, 2024
fd09755
fix: import error
robertsLando May 8, 2024
cb3911e
fix: import error
robertsLando May 9, 2024
5beac99
feat: allow to disable the driver
robertsLando May 9, 2024
7941382
fix: only restart zniffer/driver based on changed settings
robertsLando May 9, 2024
f3ede90
feat: workl in progress with UI
robertsLando May 10, 2024
2fde83f
fix: improvements on scroll
robertsLando May 10, 2024
47a9243
Merge branch 'master' into feat-zniffer
robertsLando May 13, 2024
f057ace
fix: sticky header
robertsLando May 13, 2024
bb94e7c
fix: parse payload
robertsLando May 13, 2024
5567691
fix: cc not parsed
robertsLando May 13, 2024
fb07ef4
feat: frame details
robertsLando May 13, 2024
10d5f9c
fix: scroll and resize
robertsLando May 14, 2024
0a1677f
fix: protocol data rate
robertsLando May 14, 2024
adf116e
feat: add frame color based on type
robertsLando May 14, 2024
13c2099
fix: colors
robertsLando May 14, 2024
380e38f
fix: capture text
robertsLando May 14, 2024
6cab792
feat: search with function
robertsLando May 14, 2024
ba3372a
fix: persistent hints
robertsLando May 14, 2024
3b22e6b
fix: move zniffer to last page
robertsLando May 14, 2024
16f30a9
fix: verify route on startup
robertsLando May 14, 2024
4b18e88
fix: pane resizing
robertsLando May 14, 2024
8048b08
fix: offsets
robertsLando May 14, 2024
98d5bb7
fix: offsets
robertsLando May 14, 2024
2c948a5
fix: pause auto scroll when selecting a frame
robertsLando May 14, 2024
e9489bd
fix: remove useless padding
robertsLando May 14, 2024
11967f0
fix: change selected row color
robertsLando May 14, 2024
a88d1af
fix: add abbreviations
robertsLando May 14, 2024
7e2c962
fix: filtered frames size
robertsLando May 14, 2024
98d7129
fix: clear and capture
robertsLando May 14, 2024
b8c6f69
fix: zniffer regions
robertsLando May 14, 2024
486ad44
fix: regions
robertsLando May 14, 2024
cf0d28c
feat: style of resizer
robertsLando May 14, 2024
3f24834
fix: setup events on init not on start
robertsLando May 14, 2024
67d1c70
Merge branch 'master' into feat-zniffer
robertsLando May 14, 2024
541c130
fix: better timestamp
robertsLando May 14, 2024
18a8685
fix: imporve frame details
robertsLando May 14, 2024
85feeb2
fix: hide details with no value
robertsLando May 14, 2024
4874ad7
fix: frame details error
robertsLando May 14, 2024
db1b336
fix: window resize
robertsLando May 14, 2024
f22e628
fix: parse values in frame details
robertsLando May 14, 2024
99eacd1
fix: frame details
robertsLando May 14, 2024
7603841
fix: remove duplicated header
robertsLando May 14, 2024
e2fea3c
fix: minor fixes
robertsLando May 14, 2024
e484178
fix: parse protocol
robertsLando May 14, 2024
b1dbff6
add trailing 0 to milliseconds
AlCalzone May 14, 2024
e484a1c
fix double dBm in RSSI
AlCalzone May 14, 2024
8a95870
fix typo
AlCalzone May 14, 2024
beb3222
fix: spacing and route info
robertsLando May 15, 2024
c5a0256
fix: route informations
robertsLando May 15, 2024
bd5f984
fix: remove hint from frequency
robertsLando May 15, 2024
c8a6327
fix: clarify expression
robertsLando May 15, 2024
3b9ac82
fix: reset error on expression
robertsLando May 15, 2024
eed858c
fix: highlight hop
robertsLando May 15, 2024
c4b6e80
fix: rssi error
robertsLando May 15, 2024
f0af637
fix: hide rssi from table
robertsLando May 15, 2024
c9730bc
fix: with speed modified
robertsLando May 15, 2024
3e57de0
fix: improve search filter by passing frame
robertsLando May 15, 2024
a159cf6
fix: parsed payload not shown
robertsLando May 15, 2024
6da5c62
fix: typo
robertsLando May 15, 2024
6a36905
fix: zniffer frequency empty on startup
robertsLando May 15, 2024
33a32fa
fix: make both panes full width
robertsLando May 15, 2024
dd1c2fe
fix: make top col responsive
robertsLando May 15, 2024
7738bd9
fix: ui improvements
robertsLando May 17, 2024
88817d1
fix: move settings to right drawer
robertsLando May 17, 2024
fffcb45
fix: send back new freq on change
robertsLando May 17, 2024
d504c2f
fix: hide snack on frequency set
robertsLando May 17, 2024
4c89711
fix: disable sorting on table
robertsLando May 17, 2024
a7a9b8f
fix: remove inverted from serach
robertsLando May 17, 2024
c7dab06
fix: make frame details columns width fixed
robertsLando May 17, 2024
0a42cfe
fix: parsing of encapsulated cc
robertsLando May 17, 2024
6d1eeb9
fix: encapsulated parsing
robertsLando May 17, 2024
3255db4
fix: parsing of encapsulated cc
robertsLando May 17, 2024
fbe36b7
fix: switch to custom tree view
robertsLando May 17, 2024
eee25a4
fix: switch back to treeview
robertsLando May 17, 2024
b865ebd
fix: tree view styling
robertsLando May 17, 2024
140d1d6
fix: expand all
robertsLando May 17, 2024
0fbb59a
fix: expand all
robertsLando May 17, 2024
e71aa6f
fix: improve frames rendiring
robertsLando May 17, 2024
25fa1a0
fix: remove queue check
robertsLando May 17, 2024
28a6a9b
chore: update zwave-js
AlCalzone May 21, 2024
7e36bca
fix: correct type for LR frames
AlCalzone May 21, 2024
932fb1a
fix: consistent colors for Z-Wave and LR frames
AlCalzone May 21, 2024
78beda9
fix: show falsy frame details
AlCalzone May 21, 2024
006d9d2
fix: auto expand all
robertsLando May 21, 2024
5863913
feat: get frames from zniffer and clear
robertsLando May 21, 2024
df2901d
fix: show raw/parsed payload
robertsLando May 21, 2024
b54454b
fix: publish status after init
robertsLando May 21, 2024
63c65ed
fix: styling
robertsLando May 22, 2024
254f68f
fix: infinite loop
robertsLando May 22, 2024
175080c
fix: minor style issues
robertsLando May 22, 2024
1201794
Merge branch 'master' into feat-zniffer
robertsLando May 22, 2024
44cd8ef
fix: frame details issues
robertsLando May 23, 2024
54b64a1
fix: move raw payload below
robertsLando May 23, 2024
d1be057
fix(ui): apply trimStart to cc list values
robertsLando May 23, 2024
83a59d3
fix: resizer
robertsLando May 24, 2024
d153130
fix: add speed modified on ui
robertsLando May 24, 2024
effbb18
Fix: display total frames
robertsLando May 24, 2024
1657a65
fix: skip frames get if socket is disconnected
robertsLando May 24, 2024
288da78
fix: style issues
robertsLando May 24, 2024
d494c53
fix: use monospace font for buffers
robertsLando May 24, 2024
e415d45
fix: add id to frames
robertsLando May 24, 2024
d6e9aff
fix: placeholder when no frame is selected
robertsLando May 24, 2024
4490559
fix: add tooltips to buttons
robertsLando May 24, 2024
1004d3a
fix: add open in new window
robertsLando May 24, 2024
6e2fe4c
fix: settings drawer z-index
robertsLando May 24, 2024
bed7370
fix: unified debug style with zniffer
robertsLando May 24, 2024
0fb668d
style: make divider nicer
AlCalzone May 24, 2024
03ab337
fix: border in layout-v
AlCalzone May 24, 2024
c2b026a
fix: spacing issues
robertsLando May 24, 2024
03319f6
fix: resizer style on dark theme
robertsLando May 27, 2024
954d8ec
fix: port validation on settings
robertsLando May 27, 2024
fdac63e
feat: put a button to enable/disable auto scroll
robertsLando May 28, 2024
a896f64
Merge branch 'master' of https://github.com/zwave-js/zwave-js-ui into…
robertsLando May 28, 2024
3569b8d
feat: add protocol icon
robertsLando May 28, 2024
60d4316
fix: typo
robertsLando May 28, 2024
9bff914
fix: auto scroll improvements
robertsLando May 29, 2024
126291d
fix: auto scorll edge cases
robertsLando May 30, 2024
b8840fd
feat: add badge when zniffer is running
robertsLando May 30, 2024
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
112 changes: 103 additions & 9 deletions api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import * as utils from './lib/utils'
import backupManager from './lib/BackupManager'
import { readFile, realpath } from 'fs/promises'
import { generate } from 'selfsigned'
import ZnifferManager, { ZnifferConfig } from './lib/ZnifferManager'

const createCertificate = promisify(generate)

Expand Down Expand Up @@ -158,6 +159,7 @@ socketManager.authMiddleware = function (
}

let gw: Gateway // the gateway instance
let zniffer: ZnifferManager // the zniffer instance
const plugins: CustomPlugin[] = []
let pluginsRouter: Router

Expand Down Expand Up @@ -257,6 +259,7 @@ export async function startServer(port: number | string, host?: string) {
setupInterceptor()
await loadSnippets()
await loadManager()
startZniffer(settings.zniffer)
await startGateway(settings)
}

Expand Down Expand Up @@ -424,6 +427,12 @@ async function startGateway(settings: Settings) {
restarting = false
}

function startZniffer(settings: ZnifferConfig) {
if (settings) {
zniffer = new ZnifferManager(settings, socketManager.io)
}
}

async function destroyPlugins() {
while (plugins.length > 0) {
const instance = plugins.pop()
Expand Down Expand Up @@ -619,10 +628,17 @@ function setupSocket(server: HttpServer) {
// Server: https://socket.io/docs/v4/server-application-structure/#all-event-handlers-are-registered-in-the-indexjs-file
// Client: https://socket.io/docs/v4/client-api/#socketemiteventname-args
socket.on(inboundEvents.init, (data, cb = noop) => {
let state = {} as any

if (gw.zwave) {
const state = gw.zwave.getState()
cb(state)
state = gw.zwave.getState()
}

if (zniffer) {
state.zniffer = zniffer.status()
}

cb(state)
})

socket.on(
Expand Down Expand Up @@ -730,6 +746,49 @@ function setupSocket(server: HttpServer) {

cb(result)
})

// eslint-disable-next-line @typescript-eslint/no-misused-promises
socket.on(inboundEvents.zniffer, async (data, cb = noop) => {
logger.info(`Zniffer api call: ${data.api}`)

let res: any, err: string
try {
switch (data.apiName) {
case 'start':
res = await zniffer.start()
break
case 'stop':
res = await zniffer.stop()
break
case 'clear':
res = zniffer.clear()
break
case 'getFrames':
res = zniffer.getFrames()
break
case 'setFrequency':
res = await zniffer.setFrequency(data.frequency)
break
case 'saveCaptureToFile':
res = await zniffer.saveCaptureToFile()
break
default:
throw new Error(`Unknown ZNIFFER api ${data.apiName}`)
}
} catch (error) {
logger.error('Error while calling ZNIFFER api', error)
err = error.message
}

const result = {
success: !err,
message: err || 'Success ZNIFFER api call',
result: res,
api: data.apiName,
}

cb(result)
})
})

// emitted every time a new client connects/disconnects
Expand Down Expand Up @@ -1074,15 +1133,50 @@ app.post(
}
// TODO: validate settings using calss-validator
const settings = req.body

const actualSettings = jsonStore.get(store.settings) as Settings

const shouldRestartGw = !utils.deepEqual(
{
zwave: actualSettings.zwave,
gateway: actualSettings.gateway,
mqtt: actualSettings.mqtt,
},
{
zwave: settings.zwave,
gateway: settings.gateway,
mqtt: settings.mqtt,
},
)

const shouldRestartZniffer = !utils.deepEqual(
actualSettings.zniffer,
settings.zniffer,
)

// nothing changed, consider it a forced restart
const restartAll = !shouldRestartGw && !shouldRestartZniffer

restarting = true
await jsonStore.put(store.settings, settings)
await gw.close()
await destroyPlugins()
// reload loggers settings
setupLogging(settings)
// restart clients and gateway
await startGateway(settings)
backupManager.init(gw.zwave)

if (restartAll || shouldRestartGw) {
await gw.close()

await destroyPlugins()
// reload loggers settings
setupLogging(settings)
// restart clients and gateway
await startGateway(settings)
backupManager.init(gw.zwave)
}

if (restartAll || shouldRestartZniffer) {
if (zniffer) {
await zniffer.close()
}
startZniffer(settings.zniffer)
}

res.json({
success: true,
Expand Down
2 changes: 2 additions & 0 deletions api/config/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { GatewayConfig } from '../lib/Gateway'
import { MqttConfig } from '../lib/MqttClient'
import { ZnifferConfig } from '../lib/ZnifferManager'
import { ZwaveConfig, deviceConfigPriorityDir } from '../lib/ZwaveClient'

export type StoreKeys = 'settings' | 'scenes' | 'nodes' | 'users'
Expand All @@ -21,6 +22,7 @@ export interface Settings {
mqtt?: MqttConfig
zwave?: ZwaveConfig
gateway?: GatewayConfig
zniffer?: ZnifferConfig
}

const store: Record<StoreKeys, StoreFile> = {
Expand Down
3 changes: 3 additions & 0 deletions api/lib/SocketEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export enum socketEvents {
grantSecurityClasses = 'GRANT_SECURITY_CLASSES',
validateDSK = 'VALIDATE_DSK',
inclusionAborted = 'INCLUSION_ABORTED',
znifferFrame = 'ZNIFFER_FRAME',
znifferState = 'ZNIFFER_STATE',
}

// events from client ---> server
Expand All @@ -27,4 +29,5 @@ export enum inboundEvents {
zwave = 'ZWAVE_API', // call a zwave api
hass = 'HASS_API', // call an hass api
mqtt = 'MQTT_API', // call an mqtt api
zniffer = 'ZNIFFER_API', // call a zniffer api
}
1 change: 1 addition & 0 deletions api/lib/SocketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface SocketManagerEventCallbacks {
[inboundEvents.zwave]: (socket: Socket, data: any) => void
[inboundEvents.hass]: (socket: Socket, data: any) => void
[inboundEvents.mqtt]: (socket: Socket, data: any) => void
[inboundEvents.zniffer]: (socket: Socket, data: any) => void
clients: (
event: 'connection' | 'disconnect',
sockets: Map<string, Socket>,
Expand Down
Loading
Loading