Skip to content

Commit

Permalink
use filename suffix as smem number
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-demin committed Nov 6, 2023
1 parent 9e9a78d commit ab14b6f
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 455 deletions.
6 changes: 3 additions & 3 deletions cat_smem_pri.lpi → cat_smem.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<SaveFoldState Value="False"/>
</Flags>
<SessionStorage Value="None"/>
<Title Value="cat_smem_pri"/>
<Title Value="cat_smem"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
Expand All @@ -29,7 +29,7 @@
</RunParams>
<Units>
<Unit>
<Filename Value="cat_smem_pri.lpr"/>
<Filename Value="cat_smem.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
Expand All @@ -42,7 +42,7 @@
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="cat_smem_pri"/>
<Filename Value="cat_smem"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
Expand Down
6 changes: 3 additions & 3 deletions cat_smem_pri.lpr → cat_smem.lpr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
program cat_smem_pri;
program cat_smem;

{$mode objfpc}{$H+}

Expand Down Expand Up @@ -74,7 +74,7 @@ function FindNearest(constref a: array of Int32; v: Int32): Int32;
begin
if ParamCount() <> 6 then
begin
WriteLn('Usage: cat_smem_pri.exe port chan chan call port port');
WriteLn('Usage: cat_smem.exe port chan chan call port port');
Exit;
end;

Expand Down Expand Up @@ -117,7 +117,7 @@ function FindNearest(constref a: array of Int32; v: Int32): Int32;
ct.ReadTotalTimeoutConstant := 100;
SetCommTimeouts(s.hndl, ct);

s.smem.Open(0);
s.smem.Open;

repeat
Sleep(100);
Expand Down
6 changes: 3 additions & 3 deletions extio_smem_sec.lpi → extio_smem.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<SaveFoldState Value="False"/>
</Flags>
<SessionStorage Value="None"/>
<Title Value="extio_smem_sec"/>
<Title Value="extio_smem"/>
<Scaled Value="True"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
Expand Down Expand Up @@ -41,7 +41,7 @@
</RequiredPackages>
<Units>
<Unit>
<Filename Value="extio_smem_sec.lpr"/>
<Filename Value="extio_smem.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
Expand All @@ -54,7 +54,7 @@
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="extio_smem_sec"/>
<Filename Value="extio_smem"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
Expand Down
119 changes: 78 additions & 41 deletions extio_smem_pri.lpr → extio_smem.lpr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library extio_smem_pri;
library extio_smem;

{$mode objfpc}{$H+}

Expand Down Expand Up @@ -30,19 +30,17 @@ TState = class
thrd: TDataThread;
call: TCallback;
form: TForm;
prim: TCheckBox;
chan: TComboBox;
rate: TComboBox;
freq: Int32;
procedure ChangePrim(Sender: TObject);
procedure ChangeRate(Sender: TObject);
procedure ExitComboBox(Sender: TObject);
end;

const

path: String = '\Software\SDR_SMEM_0';

fmax: Int32 = 490000000;

rates: array of Int32 = (48, 96, 192, 384);

var
Expand All @@ -59,33 +57,53 @@ constructor TDataThread.Create;

procedure TDataThread.Execute;
var
chan, rate, size, limit, offset: Int32;
chan, freq, rate, size, limit, offset: Int32;
begin
chan := s.chan.ItemIndex;
s.smem.ctrl^.freq[chan] := s.freq;
rate := s.rate.ItemIndex;
s.smem.ctrl^.rate := rate;
size := 512 shl rate;
limit := 7 shr rate;
offset := 0;
repeat
if offset = 0 then
begin
chan := s.chan.ItemIndex;
if s.prim.Checked then
begin
s.smem.ctrl^.freq[chan] := s.freq;
rate := s.rate.ItemIndex;
s.smem.ctrl^.rate := rate;
end
else
begin
freq := s.smem.ctrl^.freq[chan];
if s.freq <> freq then
begin
s.freq := freq;
if s.call <> nil then s.call(-1, 101, 0.0, nil);
end;
rate := s.smem.ctrl^.rate;
if s.rate.ItemIndex <> rate then
begin
s.rate.ItemIndex := rate;
if s.call <> nil then s.call(-1, 100, 0.0, nil);
end;
end;
size := 512 shl rate;
limit := 7 shr rate;
end;
if not s.smem.Wait then Continue;
Move(s.smem.data^[chan], b[offset * size], size * 8);
Inc(offset);
if offset > limit then
begin
if s.call <> nil then s.call(4096, 0, 0.0, @b);
chan := s.chan.ItemIndex;
s.smem.ctrl^.freq[chan] := s.freq;
rate := s.rate.ItemIndex;
s.smem.ctrl^.rate := rate;
size := 512 shl rate;
limit := 7 shr rate;
offset := 0;
end;
until Terminated;
end;

procedure TState.ChangePrim(Sender: TObject);
begin
s.rate.Enabled := s.prim.Checked;
end;

procedure TState.ChangeRate(Sender: TObject);
begin
if s.call <> nil then s.call(-1, 100, 0.0, nil);
Expand All @@ -96,12 +114,11 @@ procedure TState.ExitComboBox(Sender: TObject);
(Sender as TComboBox).SelLength := 0;
end;

procedure SetupControl(c: TWinControl; p: TForm; e: TNotifyEvent; y: Int32);
procedure SetupControl(c: TWinControl; p: TForm; y: Int32);
begin
with c do
begin
Parent := p;
OnExit := e;
Width := 112;
Left := 136;
Top := y;
Expand All @@ -126,15 +143,14 @@ procedure Init;
var
c, chan, r, rate, rmax: Int32;
begin
chan := 0;
rate := 2;
s := TState.Create;
s.rgst := TRegistry.Create;
with s.rgst do
begin
OpenKey(path, True);
if ValueExists('Chan') then chan := ReadInteger('Chan') else WriteInteger('Chan', chan);
if ValueExists('Rate') then rate := ReadInteger('Rate') else WriteInteger('Rate', rate);
s.rgst := s.smem.Open;
try
chan := s.rgst.ReadInteger('Chan');
rate := s.rgst.ReadInteger('Rate');
except
chan := 0;
rate := 2;
end;
if chan < 0 then chan := 0;
if chan > 7 then chan := 7;
Expand All @@ -151,27 +167,40 @@ procedure Init;
BorderStyle := bsSingle;
Caption := 'Settings';
PixelsPerInch := 96;
Height := 68;
Height := 100;
Width := 256;
end;

s.prim := TCheckBox.Create(s.form);
SetupControl(s.prim, s.form, 8);
with s.prim do
begin
Checked := True;
OnChange := @s.ChangePrim;
end;

CreateLabel(s.form, 'Primary', s.prim);

s.chan := TComboBox.Create(s.form);
SetupControl(s.chan, s.form, @s.ExitComboBox, 8);
SetupControl(s.chan, s.form, 40);
with s.chan do
begin
ReadOnly := True;
OnExit := @s.ExitComboBox;
for c := 0 to 7 do Items.Add(IntToStr(c));
ItemIndex := chan;
end;

CreateLabel(s.form, 'RX channel', s.chan);

s.rate := TComboBox.Create(s.form);
SetupControl(s.rate, s.form, @s.ExitComboBox, 40);
SetupControl(s.rate, s.form, 72);
with s.rate do
begin
Enabled := True;
ReadOnly := True;
OnChange := @s.ChangeRate;
OnExit := @s.ExitComboBox;
for r in rates do Items.Add(IntToStr(r) + ' kSPS');
ItemIndex := rate;
end;
Expand All @@ -181,17 +210,20 @@ procedure Init;

procedure Free;
begin
s.rgst.WriteInteger('Chan', s.chan.ItemIndex);
s.rgst.WriteInteger('Rate', s.rate.ItemIndex);
try
s.rgst.WriteInteger('Chan', s.chan.ItemIndex);
s.rgst.WriteInteger('Rate', s.rate.ItemIndex);
except
end;
s.smem.Close;
s.form.Free;
s.rgst.Free;
s.Free;
end;

function InitHW(name, model: PChar; var format: Int32): Boolean; stdcall;
begin
format := 7;
StrPCopy(name, 'SMEM Primary');
StrPCopy(name, s.smem.name);
StrPCopy(model, '');
Result := True;
end;
Expand All @@ -204,7 +236,6 @@ function OpenHW: Boolean; stdcall;
function StartHW(freq: Int32): Int32; stdcall;
begin
SetHWLO(freq);
s.smem.Open(0);
s.thrd := TDataThread.Create;
Result := 4096;
end;
Expand All @@ -213,7 +244,6 @@ procedure StopHW; stdcall;
begin
s.thrd.Terminate;
Sleep(200);
s.smem.Close;
end;

procedure CloseHW; stdcall;
Expand All @@ -228,14 +258,21 @@ procedure SetCallback(call: TCallback); stdcall;

function SetHWLO(freq: Int32): Int32; stdcall;
begin
if freq > fmax then
if s.prim.Checked then
begin
s.freq := fmax;
Result := fmax;
if freq > fmax then
begin
s.freq := fmax;
Result := fmax;
end
else
begin
s.freq := freq;
Result := 0;
end;
end
else
begin
s.freq := freq;
Result := 0;
end;
if (s.freq <> freq) and (s.call <> nil) then s.call(-1, 101, 0.0, nil);
Expand Down

0 comments on commit ab14b6f

Please sign in to comment.