mirror of
https://git.vladimir.cc/vladimir/ewsdr.git
synced 2026-08-25 20:37:33 +00:00
Phase 4: extract CAT into its own adapter (CATAdapter.pas)
CAT becomes a peer adapter over the controller, alongside WebAdapter. TCATAdapter owns the CAT engine + serial/TCP transports and builds the TCATContext: getters read FController directly (CAT thread), setters/commands call controller commands marshaled via FController.Invoke. No MainForm or WebAdapter dependency — the historical CAT->WebAdapter.OnXxx coupling (Mode/AGC/Band/etc.) is gone; CAT talks only to the controller. MainForm keeps CAT *settings* (FCATLastGlobal + OnCATSettingsChange + SettingsForm wiring), now calling FCATAdapter.ApplySettings on change/connect. Removed InitCATEngine, CATApplySettings, all CATGet*/CATSet*/CATDo*/SyncCAT* and the FCATEngine/FCATSerial/FCATTcp/FCATSyncFreq fields. Fixes a latent bug: CATSetFilterIdx routed a filter index through the web BW handler as a negative-encoded value, but that branch was dead since batch 21 — CAT now calls FController.SetFilterIdx directly. Adds StoreVfoA (store VFO A without retune when B is active) and uses the now-real SetBand/BandUp/BandDown/TuneActiveBy commands. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
daee5672a9
commit
682025e99b
+9
-234
@@ -31,7 +31,7 @@ uses
|
||||
WDSP, WDSPEngine, AudioOutput, AudioInput,
|
||||
Settings,
|
||||
WebServer, WebAdapter,
|
||||
CATEngine, CATSerial, CATTcp,
|
||||
CATAdapter,
|
||||
SpectrumView, SpectrumViewOpengl,
|
||||
WidebandView,
|
||||
StatusBar,
|
||||
@@ -177,11 +177,8 @@ type
|
||||
FWebUser: string;
|
||||
FWebPass: string;
|
||||
// --- CAT ---
|
||||
FCATEngine: TCATEngine;
|
||||
FCATSerial: TCATSerialManager;
|
||||
FCATTcp: TCATTcpServer;
|
||||
FCATSyncFreq: Double;
|
||||
FCATLastGlobal: TGlobalSettings; // текущие CAT-настройки (для сохранения)
|
||||
FCATAdapter: TCATAdapter; // адаптер CAT поверх контроллера (движок+транспорты+контекст)
|
||||
FCATLastGlobal: TGlobalSettings; // текущие CAT-настройки (UI/persist; ApplySettings → адаптер)
|
||||
// Временные поля для передачи параметров в Synchronize-методы
|
||||
FWebSyncFreq: Double;
|
||||
FWebSyncInt: Integer;
|
||||
@@ -453,39 +450,7 @@ type
|
||||
procedure PushDeviceListToWeb; // store → FWebServer.SetDeviceList
|
||||
// Synchronize-обёртки (выполняются в UI-потоке) — только host-зависимые
|
||||
procedure SyncWebRun;
|
||||
// --- CAT callbacks -------------------------------------------------------
|
||||
function CATGetVfoA: Double;
|
||||
function CATGetVfoB: Double;
|
||||
function CATGetMode: Integer;
|
||||
function CATGetActiveVfo: Integer;
|
||||
function CATGetAGCMode: Integer;
|
||||
function CATGetVolume: Integer;
|
||||
function CATGetDriveLevel: Integer;
|
||||
function CATGetFilterIdx: Integer;
|
||||
function CATGetFilterBW: Integer;
|
||||
function CATGetNRMode: Integer;
|
||||
function CATGetNBMode: Integer;
|
||||
function CATGetSNB: Boolean;
|
||||
function CATGetANF: Boolean;
|
||||
function CATGetTX: Boolean;
|
||||
function CATGetRunning: Boolean;
|
||||
function CATGetSMeter: Double;
|
||||
function CATGetBand: Integer;
|
||||
procedure CATSetVfoA(V: Double);
|
||||
procedure CATSetVfoB(V: Double);
|
||||
procedure CATSetFilterIdx(V: Integer);
|
||||
procedure CATDoBandUp;
|
||||
procedure CATDoBandDown;
|
||||
procedure CATDoTuneUp;
|
||||
procedure CATDoTuneDown;
|
||||
procedure SyncCATVfoA;
|
||||
procedure SyncCATVfoB;
|
||||
procedure SyncCATBandUp;
|
||||
procedure SyncCATBandDown;
|
||||
procedure SyncCATTuneUp;
|
||||
procedure SyncCATTuneDown;
|
||||
procedure InitCATEngine;
|
||||
procedure CATApplySettings(const G: TGlobalSettings);
|
||||
// --- CAT settings (UI/persist; контекст+движок — в TCATAdapter) ----------
|
||||
procedure OnCATSettingsChange(
|
||||
const SerEnabled: array of Boolean;
|
||||
const SerPort: array of string;
|
||||
@@ -908,8 +873,8 @@ begin
|
||||
end;
|
||||
FController.FSettings.LoadCATSettings(FCATLastGlobal);
|
||||
FLightTheme := FController.FSettings.LoadTheme;
|
||||
InitCATEngine;
|
||||
CATApplySettings(FCATLastGlobal);
|
||||
FCATAdapter := TCATAdapter.Create(FController);
|
||||
FCATAdapter.ApplySettings(FCATLastGlobal);
|
||||
FSMeterPeak := -130;
|
||||
FSMeterMin := -130;
|
||||
FSMeterAvg := -130;
|
||||
@@ -1079,9 +1044,7 @@ begin
|
||||
FWebServer.Stop;
|
||||
FreeAndNil(FWebAdapter); // адаптер не владеет сервером — освобождаем после Stop
|
||||
FWebServer.Free;
|
||||
if Assigned(FCATTcp) then begin FCATTcp.Stop; FreeAndNil(FCATTcp); end;
|
||||
if Assigned(FCATSerial) then begin FCATSerial.StopAll; FreeAndNil(FCATSerial); end;
|
||||
FreeAndNil(FCATEngine);
|
||||
FreeAndNil(FCATAdapter); // его Destroy останавливает+освобождает CAT движок/транспорты
|
||||
// Ядро освобождаем последним — его Destroy закрывает и освобождает движки
|
||||
// (FreeEngines) и FSettings.
|
||||
FreeAndNil(FController);
|
||||
@@ -1350,7 +1313,7 @@ begin
|
||||
// Тема — app-global (своё хранилище LoadTheme/SaveTheme), не из device-блоба:
|
||||
// возвращаем живое значение в persist-буфер, чтобы blob нёс актуальную тему.
|
||||
FController.FLoadedGlobal.LightTheme := FLightTheme;
|
||||
CATApplySettings(FController.FLoadedGlobal);
|
||||
FCATAdapter.ApplySettings(FController.FLoadedGlobal);
|
||||
RebuildXvtrButtons;
|
||||
PushXvtrToWeb;
|
||||
TrkDrive.Position := FController.FDrivePercent; // слайдер ← drive%
|
||||
@@ -5542,78 +5505,6 @@ end;
|
||||
// CAT subsystem
|
||||
// ===========================================================================
|
||||
|
||||
procedure TMainForm.InitCATEngine;
|
||||
var
|
||||
Ctx: TCATContext;
|
||||
begin
|
||||
FillChar(Ctx, SizeOf(Ctx), 0);
|
||||
Ctx.GetVfoA := CATGetVfoA;
|
||||
Ctx.GetVfoB := CATGetVfoB;
|
||||
Ctx.GetMode := CATGetMode;
|
||||
Ctx.GetActiveVfo := CATGetActiveVfo;
|
||||
Ctx.GetAGCMode := CATGetAGCMode;
|
||||
Ctx.GetVolume := CATGetVolume;
|
||||
Ctx.GetDriveLevel := CATGetDriveLevel;
|
||||
Ctx.GetFilterIdx := CATGetFilterIdx;
|
||||
Ctx.GetFilterBW := CATGetFilterBW;
|
||||
Ctx.GetNRMode := CATGetNRMode;
|
||||
Ctx.GetNBMode := CATGetNBMode;
|
||||
Ctx.GetSNBEnabled := CATGetSNB;
|
||||
Ctx.GetANFEnabled := CATGetANF;
|
||||
Ctx.GetTransmitting := CATGetTX;
|
||||
Ctx.GetRunning := CATGetRunning;
|
||||
Ctx.GetSMeter := CATGetSMeter;
|
||||
Ctx.GetCurrentBand := CATGetBand;
|
||||
Ctx.SetVfoA := CATSetVfoA;
|
||||
Ctx.SetVfoB := CATSetVfoB;
|
||||
Ctx.SetMode := FWebAdapter.OnMode;
|
||||
Ctx.SetActiveVfo := FWebAdapter.OnActiveVfo;
|
||||
Ctx.SetAGCMode := FWebAdapter.OnAGC;
|
||||
Ctx.SetVolume := FWebAdapter.OnVolume;
|
||||
Ctx.SetDriveLevel := FWebAdapter.OnDrive;
|
||||
Ctx.SetFilterIdx := CATSetFilterIdx;
|
||||
Ctx.SetNRMode := FWebAdapter.OnNR;
|
||||
Ctx.SetNBMode := FWebAdapter.OnNB;
|
||||
Ctx.SetSNBEnabled := FWebAdapter.OnSNB;
|
||||
Ctx.SetANFEnabled := FWebAdapter.OnANF;
|
||||
Ctx.SetTransmitting := FWebAdapter.OnMOX;
|
||||
Ctx.DoBandUp := CATDoBandUp;
|
||||
Ctx.DoBandDown := CATDoBandDown;
|
||||
Ctx.DoTuneUp := CATDoTuneUp;
|
||||
Ctx.DoTuneDown := CATDoTuneDown;
|
||||
Ctx.DoBandByIndex := FWebAdapter.OnBand;
|
||||
FCATEngine := TCATEngine.Create(Ctx);
|
||||
FCATSerial := TCATSerialManager.Create(FCATEngine);
|
||||
FCATTcp := TCATTcpServer.Create(FCATEngine);
|
||||
end;
|
||||
|
||||
procedure TMainForm.CATApplySettings(const G: TGlobalSettings);
|
||||
var
|
||||
Cfgs: array[0..3] of TCATSerialConfig;
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 0 to 3 do
|
||||
begin
|
||||
Cfgs[i].Enabled := G.CATSerialEnabled[i];
|
||||
Cfgs[i].PortName := G.CATSerialPort[i];
|
||||
Cfgs[i].BaudRate := G.CATSerialBaud[i];
|
||||
Cfgs[i].DataBits := G.CATSerialDataBits[i];
|
||||
Cfgs[i].StopBits := G.CATSerialStopBits[i];
|
||||
case G.CATSerialParity[i] of
|
||||
1: Cfgs[i].Parity := cspOdd;
|
||||
2: Cfgs[i].Parity := cspEven;
|
||||
else Cfgs[i].Parity := cspNone;
|
||||
end;
|
||||
end;
|
||||
FCATSerial.ApplyConfig(Cfgs);
|
||||
FCATTcp.Stop;
|
||||
if G.CATTcpEnabled then
|
||||
begin
|
||||
FCATTcp.Port := G.CATTcpPort;
|
||||
FCATTcp.Start;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.OnCATSettingsChange(
|
||||
const SerEnabled: array of Boolean;
|
||||
const SerPort: array of string;
|
||||
@@ -5642,126 +5533,10 @@ begin
|
||||
FController.FLoadedGlobal.CATSerialParity := FCATLastGlobal.CATSerialParity;
|
||||
FController.FLoadedGlobal.CATTcpEnabled := FCATLastGlobal.CATTcpEnabled;
|
||||
FController.FLoadedGlobal.CATTcpPort := FCATLastGlobal.CATTcpPort;
|
||||
CATApplySettings(FCATLastGlobal);
|
||||
FCATAdapter.ApplySettings(FCATLastGlobal);
|
||||
FController.FSettings.SaveCATSettings(FCATLastGlobal);
|
||||
FController.SaveGlobalSettings;
|
||||
FController.FSettings.Save;
|
||||
end;
|
||||
|
||||
// --- Getters (called from CAT thread — read only, no sync needed) -----------
|
||||
|
||||
function TMainForm.CATGetVfoA: Double; begin Result := FController.FVfoA; end;
|
||||
function TMainForm.CATGetVfoB: Double; begin Result := FController.FVfoB; end;
|
||||
function TMainForm.CATGetMode: Integer; begin Result := FController.FMode; end;
|
||||
function TMainForm.CATGetActiveVfo: Integer; begin Result := FController.FActiveVfo; end;
|
||||
function TMainForm.CATGetAGCMode: Integer; begin Result := FController.FAGCMode; end;
|
||||
function TMainForm.CATGetVolume: Integer; begin Result := FController.FVolume; end;
|
||||
function TMainForm.CATGetDriveLevel: Integer;begin Result := FController.FDrivePercent; end;
|
||||
function TMainForm.CATGetFilterIdx: Integer; begin Result := FController.FFilter; end;
|
||||
function TMainForm.CATGetFilterBW: Integer; begin Result := FController.FFilterBW; end;
|
||||
function TMainForm.CATGetNRMode: Integer; begin Result := FController.FNRMode; end;
|
||||
function TMainForm.CATGetNBMode: Integer; begin Result := FController.FNBMode; end;
|
||||
function TMainForm.CATGetSNB: Boolean; begin Result := FController.FSNB; end;
|
||||
function TMainForm.CATGetANF: Boolean; begin Result := FController.FANF; end;
|
||||
function TMainForm.CATGetTX: Boolean; begin Result := FController.FTransmitting; end;
|
||||
function TMainForm.CATGetRunning: Boolean; begin Result := FController.FRunning; end;
|
||||
function TMainForm.CATGetSMeter: Double; begin Result := FController.FLastSMeter; end;
|
||||
function TMainForm.CATGetBand: Integer; begin Result := FController.FCurrentBand; end;
|
||||
|
||||
// --- Setters ----------------------------------------------------------------
|
||||
|
||||
procedure TMainForm.CATSetVfoA(V: Double);
|
||||
begin
|
||||
FCATSyncFreq := V;
|
||||
TThread.Synchronize(nil, SyncCATVfoA);
|
||||
end;
|
||||
|
||||
procedure TMainForm.CATSetVfoB(V: Double);
|
||||
begin
|
||||
FCATSyncFreq := V;
|
||||
TThread.Synchronize(nil, SyncCATVfoB);
|
||||
end;
|
||||
|
||||
procedure TMainForm.CATSetFilterIdx(V: Integer);
|
||||
begin
|
||||
// OnFilter: negative value encodes 0-based index as -(idx+1)
|
||||
FWebAdapter.OnFilter(-(V + 1));
|
||||
end;
|
||||
|
||||
procedure TMainForm.CATDoBandUp;
|
||||
begin TThread.Synchronize(nil, SyncCATBandUp); end;
|
||||
|
||||
procedure TMainForm.CATDoBandDown;
|
||||
begin TThread.Synchronize(nil, SyncCATBandDown); end;
|
||||
|
||||
procedure TMainForm.CATDoTuneUp;
|
||||
begin TThread.Synchronize(nil, SyncCATTuneUp); end;
|
||||
|
||||
procedure TMainForm.CATDoTuneDown;
|
||||
begin TThread.Synchronize(nil, SyncCATTuneDown); end;
|
||||
|
||||
// --- Sync methods (run in main thread) --------------------------------------
|
||||
|
||||
procedure TMainForm.SyncCATVfoA;
|
||||
var BandIdx: Integer;
|
||||
begin
|
||||
FController.FVfoA := FCATSyncFreq;
|
||||
if FController.FActiveVfo = 0 then
|
||||
begin
|
||||
ApplyVfoA(Round(FController.FVfoA));
|
||||
end
|
||||
else
|
||||
begin
|
||||
// VFO A is not active — just update display and band indicator
|
||||
FreqDispA.Frequency := Round(FController.FVfoA);
|
||||
BandIdx := FreqToBandIdx(FController.FVfoA);
|
||||
if (BandIdx >= 0) and (BandIdx <> FController.FCurrentBand) then
|
||||
begin
|
||||
StyleButton(BtnBand[FController.FCurrentBand], False);
|
||||
FController.FCurrentBand := BandIdx;
|
||||
StyleButton(BtnBand[FController.FCurrentBand], True);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.SyncCATVfoB;
|
||||
begin
|
||||
// Унифицировано с десктопом/вебом: та же команда SetVfoB.
|
||||
FController.SetVfoB(FCATSyncFreq);
|
||||
end;
|
||||
|
||||
procedure TMainForm.SyncCATBandUp;
|
||||
begin
|
||||
if FController.FCurrentBand < BAND_COUNT - 1 then
|
||||
FWebAdapter.OnBand(FController.FCurrentBand + 1);
|
||||
end;
|
||||
|
||||
procedure TMainForm.SyncCATBandDown;
|
||||
begin
|
||||
if FController.FCurrentBand > 0 then
|
||||
FWebAdapter.OnBand(FController.FCurrentBand - 1);
|
||||
end;
|
||||
|
||||
procedure TMainForm.SyncCATTuneUp;
|
||||
begin
|
||||
if FController.FActiveVfo = 0 then
|
||||
ApplyVfoA(Round(FController.FVfoA) + 10)
|
||||
else
|
||||
begin
|
||||
FCATSyncFreq := FController.FVfoB + 10;
|
||||
SyncCATVfoB;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.SyncCATTuneDown;
|
||||
begin
|
||||
if FController.FActiveVfo = 0 then
|
||||
ApplyVfoA(Round(FController.FVfoA) - 10)
|
||||
else
|
||||
begin
|
||||
FCATSyncFreq := FController.FVfoB - 10;
|
||||
SyncCATVfoB;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user