Skip to content

Commit dd244b5

Browse files
committed
feat(tuner-relay): add command history tracking and related configurations
1 parent 2582a8b commit dd244b5

10 files changed

Lines changed: 253 additions & 16 deletions

File tree

cli/source/types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,34 @@ export interface TunerRelayStatus {
8080
bytesReceived: number
8181
lastCommand?: string
8282
lastCommandAt?: string
83+
lastCommandValue?: number
8384
lastFrequency?: number
8485
lastSampleRate?: number
8586
lastGain?: number
8687
lastPpm?: number
88+
commandHistoryLimit?: number
89+
commandStats?: TunerRelayCommandStat[]
90+
commandHistory?: TunerRelayCommandHistoryEntry[]
8791
lastError?: string
8892
}
8993

94+
export interface TunerRelayCommandStat {
95+
id: number
96+
name: string
97+
count: number
98+
lastValue: number
99+
lastSeenAt: string
100+
}
101+
102+
export interface TunerRelayCommandHistoryEntry {
103+
id: number
104+
name: string
105+
value: number
106+
at: string
107+
clientId?: string
108+
clientRemote?: string
109+
}
110+
90111
// ============================================================================
91112
// Backpressure Types
92113
// ============================================================================

config/default.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ audio:
201201
# sourceId - Source to expose (default: first configured source)
202202
# controlPolicy - "exclusive" (first client controls) or "shared"
203203
# maxClients - Optional cap on number of connected clients
204+
# commandHistoryLimit - Number of command entries to retain (0 disables)
204205
# note - Relay streams the primary source (first in `sources`)
205206
#
206207
# Example:
@@ -211,11 +212,13 @@ audio:
211212
# sourceId: "rtl-pi"
212213
# controlPolicy: "exclusive"
213214
# maxClients: 2
215+
# commandHistoryLimit: 200
214216

215217
tunerRelay:
216218
enabled: false
217219
host: "0.0.0.0"
218220
port: 1234
221+
commandHistoryLimit: 200
219222

220223
# -----------------------------------------------------------------------------
221224
# API Server

config/dev_test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ tunerRelay:
124124
sourceId: pi-iq
125125
controlPolicy: exclusive
126126
maxClients: 1
127+
commandHistoryLimit: 200
127128

128129
api:
129130
host: 0.0.0.0

docs/API.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,30 @@ curl http://localhost:9000/api/status
115115
"bytesSent": 421000000,
116116
"bytesReceived": 120,
117117
"lastFrequency": 446524920,
118-
"lastSampleRate": 2048000
118+
"lastSampleRate": 2048000,
119+
"lastCommand": "set-frequency",
120+
"lastCommandAt": "2024-05-21T03:12:01.123Z",
121+
"lastCommandValue": 446524920,
122+
"commandHistoryLimit": 200,
123+
"commandStats": [
124+
{
125+
"id": 1,
126+
"name": "set-frequency",
127+
"count": 6,
128+
"lastValue": 446524920,
129+
"lastSeenAt": "2024-05-21T03:12:01.123Z"
130+
}
131+
],
132+
"commandHistory": [
133+
{
134+
"id": 1,
135+
"name": "set-frequency",
136+
"value": 446524920,
137+
"at": "2024-05-21T03:12:01.123Z",
138+
"clientId": "client-1",
139+
"clientRemote": "192.168.1.50:50522"
140+
}
141+
]
119142
}
120143
}
121144
```
@@ -181,7 +204,30 @@ curl http://localhost:9000/api/tuner-relay
181204
"bytesSent": 421000000,
182205
"bytesReceived": 120,
183206
"lastFrequency": 446524920,
184-
"lastSampleRate": 2048000
207+
"lastSampleRate": 2048000,
208+
"lastCommand": "set-frequency",
209+
"lastCommandAt": "2024-05-21T03:12:01.123Z",
210+
"lastCommandValue": 446524920,
211+
"commandHistoryLimit": 200,
212+
"commandStats": [
213+
{
214+
"id": 1,
215+
"name": "set-frequency",
216+
"count": 6,
217+
"lastValue": 446524920,
218+
"lastSeenAt": "2024-05-21T03:12:01.123Z"
219+
}
220+
],
221+
"commandHistory": [
222+
{
223+
"id": 1,
224+
"name": "set-frequency",
225+
"value": 446524920,
226+
"at": "2024-05-21T03:12:01.123Z",
227+
"clientId": "client-1",
228+
"clientRemote": "192.168.1.50:50522"
229+
}
230+
]
185231
}
186232
```
187233

docs/DOCKER-SETUP.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,18 @@ make docker-build-sdrpp # SDR++ only
6868

6969
### Environment Variables
7070

71-
| Variable | Default | Description |
72-
| -------------------------------- | ------- | --------------------------------- |
73-
| `WAVEKIT_API_PORT` | 3000 | API server port |
74-
| `WAVEKIT_LOG_LEVEL` | info | Log level (debug/info/warn/error) |
75-
| `WAVEKIT_SOURCES_0_HOST` | - | First source hostname |
76-
| `WAVEKIT_SOURCES_0_PORT` | - | First source port |
77-
| `WAVEKIT_TUNER_RELAY__ENABLED` | false | Enable RTL-TCP tuner relay |
78-
| `WAVEKIT_TUNER_RELAY__PORT` | 1234 | Tuner relay port |
79-
| `WAVEKIT_TUNER_RELAY__SOURCE_ID` | - | Source ID to expose |
80-
| `RTL_TCP_HOST` | - | rtl_tcp host (full mode) |
81-
| `RTL_TCP_PORT` | 1234 | rtl_tcp port (full mode) |
71+
| Variable | Default | Description |
72+
| -------------------------------------------- | ------- | --------------------------------- |
73+
| `WAVEKIT_API_PORT` | 3000 | API server port |
74+
| `WAVEKIT_LOG_LEVEL` | info | Log level (debug/info/warn/error) |
75+
| `WAVEKIT_SOURCES_0_HOST` | - | First source hostname |
76+
| `WAVEKIT_SOURCES_0_PORT` | - | First source port |
77+
| `WAVEKIT_TUNER_RELAY__ENABLED` | false | Enable RTL-TCP tuner relay |
78+
| `WAVEKIT_TUNER_RELAY__PORT` | 1234 | Tuner relay port |
79+
| `WAVEKIT_TUNER_RELAY__SOURCE_ID` | - | Source ID to expose |
80+
| `WAVEKIT_TUNER_RELAY__COMMAND_HISTORY_LIMIT` | 200 | Tuner relay command history size |
81+
| `RTL_TCP_HOST` | - | rtl_tcp host (full mode) |
82+
| `RTL_TCP_PORT` | 1234 | rtl_tcp port (full mode) |
8283

8384
### Mount Configuration
8485

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ tunerRelay:
191191
port: 1234
192192
sourceId: "rtl-pi"
193193
controlPolicy: "exclusive" # or "shared"
194+
commandHistoryLimit: 200 # 0 disables command history
194195
```
195196
196197
**Usage:**
@@ -204,6 +205,7 @@ tunerRelay:
204205
- The relay expects an IQ source in `U8_IQ` format (standard RTL-TCP/rtlmux output).
205206
- In `exclusive` mode, the first client gets control and others are read-only.
206207
- The relay streams the primary source (first in `sources`), so set `sourceId` to match it.
208+
- RTL-TCP commands are tracked and available via `GET /api/tuner-relay`.
207209

208210
## Configuration
209211

src/api/routes/health.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,41 @@ const tunerRelayStatusSchema = {
128128
bytesReceived: { type: "number" },
129129
lastCommand: { type: "string" },
130130
lastCommandAt: { type: "string", format: "date-time" },
131+
lastCommandValue: { type: "number" },
131132
lastFrequency: { type: "number" },
132133
lastSampleRate: { type: "number" },
133134
lastGain: { type: "number" },
134135
lastPpm: { type: "number" },
136+
commandHistoryLimit: { type: "number" },
137+
commandStats: {
138+
type: "array",
139+
items: {
140+
type: "object",
141+
properties: {
142+
id: { type: "number" },
143+
name: { type: "string" },
144+
count: { type: "number" },
145+
lastValue: { type: "number" },
146+
lastSeenAt: { type: "string", format: "date-time" },
147+
},
148+
required: ["id", "name", "count", "lastValue", "lastSeenAt"],
149+
},
150+
},
151+
commandHistory: {
152+
type: "array",
153+
items: {
154+
type: "object",
155+
properties: {
156+
id: { type: "number" },
157+
name: { type: "string" },
158+
value: { type: "number" },
159+
at: { type: "string", format: "date-time" },
160+
clientId: { type: "string" },
161+
clientRemote: { type: "string" },
162+
},
163+
required: ["id", "name", "value", "at"],
164+
},
165+
},
135166
lastError: { type: "string" },
136167
rtlTcpHeader: {
137168
type: "object",

src/api/routes/tuner-relay.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,41 @@ const tunerRelayStatusSchema = {
3030
bytesReceived: { type: "number" },
3131
lastCommand: { type: "string" },
3232
lastCommandAt: { type: "string", format: "date-time" },
33+
lastCommandValue: { type: "number" },
3334
lastFrequency: { type: "number" },
3435
lastSampleRate: { type: "number" },
3536
lastGain: { type: "number" },
3637
lastPpm: { type: "number" },
38+
commandHistoryLimit: { type: "number" },
39+
commandStats: {
40+
type: "array",
41+
items: {
42+
type: "object",
43+
properties: {
44+
id: { type: "number" },
45+
name: { type: "string" },
46+
count: { type: "number" },
47+
lastValue: { type: "number" },
48+
lastSeenAt: { type: "string", format: "date-time" },
49+
},
50+
required: ["id", "name", "count", "lastValue", "lastSeenAt"],
51+
},
52+
},
53+
commandHistory: {
54+
type: "array",
55+
items: {
56+
type: "object",
57+
properties: {
58+
id: { type: "number" },
59+
name: { type: "string" },
60+
value: { type: "number" },
61+
at: { type: "string", format: "date-time" },
62+
clientId: { type: "string" },
63+
clientRemote: { type: "string" },
64+
},
65+
required: ["id", "name", "value", "at"],
66+
},
67+
},
3768
lastError: { type: "string" },
3869
rtlTcpHeader: {
3970
type: "object",

src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export const TunerRelayConfigSchema = z.object({
115115
controlPolicy: z.enum(["exclusive", "shared"]).default("exclusive"),
116116
/** Max number of connected clients (optional cap) */
117117
maxClients: z.number().int().positive().optional(),
118+
/** Command history entries to retain (0 disables history) */
119+
commandHistoryLimit: z.number().int().min(0).max(10000).default(200),
118120
})
119121

120122
/**
@@ -595,6 +597,7 @@ export function getSupportedEnvVars(): string[] {
595597
"WAVEKIT_TUNER_RELAY__SOURCE_ID",
596598
"WAVEKIT_TUNER_RELAY__CONTROL_POLICY",
597599
"WAVEKIT_TUNER_RELAY__MAX_CLIENTS",
600+
"WAVEKIT_TUNER_RELAY__COMMAND_HISTORY_LIMIT",
598601
"WAVEKIT_LOGGING__LEVEL",
599602
"WAVEKIT_LOGGING__DIR",
600603
"WAVEKIT_SOURCES__<ID>__HOST",

0 commit comments

Comments
 (0)