add stations and an Auto tab following each station's band
Parse N1MM RadioInfo packets, map sender IPs to configured stations, and let the front-end auto-select the rotator for the selected station's current band. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+28
-3
@@ -1,6 +1,6 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import RotClient from './RotClient.js';
|
||||
import type { Config, DynamicData, InitialState, TurnMessage, TurnMessageHandler } from './types.js';
|
||||
import type { FullConfig, StationConfig, DynamicData, InitialState, TurnMessage, TurnMessageHandler } from './types.js';
|
||||
|
||||
export interface TurnEvent {
|
||||
label: string;
|
||||
@@ -10,8 +10,11 @@ export interface TurnEvent {
|
||||
|
||||
export default class RotRouter implements TurnMessageHandler {
|
||||
private readonly clients: Record<string, RotClient> = {};
|
||||
private readonly stations: Record<string, StationConfig> = {};
|
||||
private readonly stationsByIp: Record<string, string> = {};
|
||||
private readonly routerDataHandlers: Array<(rotator: RotClient, data: DynamicData) => void> = [];
|
||||
private readonly turnEventHandlers: Array<(event: TurnEvent) => void> = [];
|
||||
private readonly radioInfoHandlers: Array<(station: string, band: number, freq: number) => void> = [];
|
||||
|
||||
constructor() {
|
||||
this.loadConfig();
|
||||
@@ -19,12 +22,34 @@ export default class RotRouter implements TurnMessageHandler {
|
||||
|
||||
private loadConfig(): void {
|
||||
const raw = readFileSync('config.json', 'utf-8');
|
||||
const parsed = JSON.parse(raw) as Config;
|
||||
for (const [label, clientConfig] of Object.entries(parsed)) {
|
||||
const parsed = JSON.parse(raw) as FullConfig;
|
||||
for (const [label, clientConfig] of Object.entries(parsed.rotators)) {
|
||||
const client = new RotClient(label, clientConfig);
|
||||
client.onDynamicDataUpdate(data => this.routerDataHandlers.forEach(h => h(client, data)));
|
||||
this.clients[label] = client;
|
||||
}
|
||||
for (const [name, stationConfig] of Object.entries(parsed.stations)) {
|
||||
this.stations[name] = stationConfig;
|
||||
this.stationsByIp[stationConfig.ip] = name;
|
||||
}
|
||||
}
|
||||
|
||||
resolveStation(ip: string): string | null {
|
||||
return this.stationsByIp[ip] ?? null;
|
||||
}
|
||||
|
||||
getStations(): Record<string, StationConfig> {
|
||||
return this.stations;
|
||||
}
|
||||
|
||||
handleRadioInfo(sourceIp: string, band: number, freq: number): void {
|
||||
const station = this.resolveStation(sourceIp);
|
||||
if (!station) return;
|
||||
this.radioInfoHandlers.forEach(h => h(station, band, freq));
|
||||
}
|
||||
|
||||
onRadioInfo(handler: (station: string, band: number, freq: number) => void): void {
|
||||
this.radioInfoHandlers.push(handler);
|
||||
}
|
||||
|
||||
private findClientForBand(band: number): RotClient | null {
|
||||
|
||||
Reference in New Issue
Block a user