Merge pull request #519 from OH1KH/squash_new_rig_comm_2

Fix for rig power on
This commit is contained in:
Petr Hlozek 2022-07-24 13:02:08 +02:00 committed by GitHub
commit ba9d0c769d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 254 additions and 128 deletions

View File

@ -366,6 +366,8 @@ begin
frmBandMap.CurrentBand := b; frmBandMap.CurrentBand := b;
frmBandMap.CurrentFreq := f * 1000; frmBandMap.CurrentFreq := f * 1000;
frmBandMap.CurrentMode := m; frmBandMap.CurrentMode := m;
if Assigned(radio) then
pnlPower.Enabled:=radio.Power;
end; end;
function TfrmTRXControl.GetModeNumber(mode : String) : Cardinal; function TfrmTRXControl.GetModeNumber(mode : String) : Cardinal;
@ -669,7 +671,6 @@ begin
end end
else begin else begin
pnlPower.Visible := True; pnlPower.Visible := True;
btPonClick(nil); //setting buttons visible sends PwrOn to sync button colors
mnuShowPwr.Checked := True; mnuShowPwr.Checked := True;
end; end;
cqrini.WriteBool('TRX', 'PowerButtons', pnlPower.Visible); cqrini.WriteBool('TRX', 'PowerButtons', pnlPower.Visible);
@ -1087,11 +1088,8 @@ begin
pnlPower.Visible := cqrini.ReadBool('TRX', 'PowerButtons', False); pnlPower.Visible := cqrini.ReadBool('TRX', 'PowerButtons', False);
mnuShowPwr.Checked := pnlPower.Visible; mnuShowPwr.Checked := pnlPower.Visible;
if pnlPower.Visible then btPonClick(nil);
// all rigs do not support rigctld power switching
//so we just put pwr button ON and send rigctld PWR ON cmd
//if rig does not support it that makes no harm.
//if supports we do know pwr state from now on.
if not radio.Connected then if not radio.Connected then
begin begin
@ -1110,7 +1108,8 @@ begin
Writeln('User ask: No reset and keyer not Hamlib: No restart by TRControl radio' Writeln('User ask: No reset and keyer not Hamlib: No restart by TRControl radio'
+ n + ' change'); + n + ' change');
end end
else begin else
Begin
frmNewQSO.InitializeCW; frmNewQSO.InitializeCW;
if ((dmData.DebugLevel >= 1) or ((abs(dmData.DebugLevel) and 8) = 8)) then if ((dmData.DebugLevel >= 1) or ((abs(dmData.DebugLevel) and 8) = 8)) then
Writeln('CW keyer reloaded by TRControl radio' + n + ' change'); Writeln('CW keyer reloaded by TRControl radio' + n + ' change');
@ -1424,6 +1423,8 @@ begin
btnFM.Font.Color := clRed; btnFM.Font.Color := clRed;
if Assigned(radio) then if Assigned(radio) then
begin
if radio.CanGetVfo then
begin begin
case radio.GetCurrVFO of case radio.GetCurrVFO of
VFOA: begin VFOA: begin
@ -1434,13 +1435,15 @@ begin
btnVFOB.Font.Color := clRed; btnVFOB.Font.Color := clRed;
btnVFOA.Font.Color := clDefault; btnVFOA.Font.Color := clDefault;
end; end;
else begin end;
end
else
begin
btnVFOB.Font.Color := clDefault; btnVFOB.Font.Color := clDefault;
btnVFOA.Font.Color := clDefault; btnVFOA.Font.Color := clDefault;
end; end;
end; end;
end; end;
end;
procedure TfrmTRXControl.Split(Up : Integer); procedure TfrmTRXControl.Split(Up : Integer);

View File

@ -5,11 +5,11 @@ unit uRigControl;
interface interface
uses uses
Classes, SysUtils, Process, ExtCtrls, lNetComponents, lnet; Classes, SysUtils, Process, ExtCtrls, lNetComponents, lnet,Forms;
type TRigMode = record type TRigMode = record
mode : String[10]; mode : String[10];
pass : word; pass : integer; //this can not be word as rigctld uses "-1"="keep as is" IntToStr gives 65535 for word with -1
raw : String[10]; raw : String[10];
end; end;
@ -20,7 +20,7 @@ type
TExplodeArray = Array of String; TExplodeArray = Array of String;
type TRigControl = class type TRigControl = class
rcvdFreqMode : TLTCPComponent; RigctldConnect : TLTCPComponent;
rigProcess : TProcess; rigProcess : TProcess;
tmrRigPoll : TTimer; tmrRigPoll : TTimer;
private private
@ -40,15 +40,21 @@ type TRigControl = class
RigCommand : TStringList; RigCommand : TStringList;
fRigSendCWR : Boolean; fRigSendCWR : Boolean;
fRigChkVfo : Boolean; fRigChkVfo : Boolean;
BadRcvd : Integer;
fRXOffset : Double; fRXOffset : Double;
fTXOffset : Double; fTXOffset : Double;
fMorse : boolean;
fPower : boolean;
fGetVfo : boolean;
AllowCommand : integer; //things to do before start polling
function RigConnected : Boolean; function RigConnected : Boolean;
function StartRigctld : Boolean; function StartRigctld : Boolean;
function Explode(const cSeparator, vString: String): TExplodeArray; function Explode(const cSeparator, vString: String): TExplodeArray;
procedure OnReceivedRcvdFreqMode(aSocket: TLSocket);
procedure OnReceivedRigctldConnect(aSocket: TLSocket);
procedure OnConnectRigctldConnect(aSocket: TLSocket);
procedure OnRigPollTimer(Sender: TObject); procedure OnRigPollTimer(Sender: TObject);
public public
@ -84,6 +90,12 @@ public
//send CWR instead of CW //send CWR instead of CW
property RigChkVfo : Boolean read fRigChkVfo write fRigChkVfo; property RigChkVfo : Boolean read fRigChkVfo write fRigChkVfo;
//test if rigctld "--vfo" start parameter is used //test if rigctld "--vfo" start parameter is used
property Morse : Boolean read fMorse;
//can rig send CW
property Power : Boolean read fPower;
//can rig switch power
property CanGetVfo : Boolean read fGetVfo;
//can rig show vfo (many Icoms can not)
property LastError : String read fLastError; property LastError : String read fLastError;
//last error during operation //last error during operation
@ -135,15 +147,15 @@ begin
fRigCtldPort := 4532; fRigCtldPort := 4532;
fRigPoll := 500; fRigPoll := 500;
fRunRigCtld := True; fRunRigCtld := True;
rcvdFreqMode := TLTCPComponent.Create(nil); RigctldConnect := TLTCPComponent.Create(nil);
rigProcess := TProcess.Create(nil); rigProcess := TProcess.Create(nil);
tmrRigPoll := TTimer.Create(nil); tmrRigPoll := TTimer.Create(nil);
tmrRigPoll.Enabled := False; tmrRigPoll.Enabled := False;
VfoStr := ''; //defaults to non-"--vfo" (legacy) mode VfoStr := ''; //defaults to non-"--vfo" (legacy) mode
if DebugMode then Writeln('All objects created'); if DebugMode then Writeln('All objects created');
tmrRigPoll.OnTimer := @OnRigPollTimer; tmrRigPoll.OnTimer := @OnRigPollTimer;
BadRcvd := 0; RigctldConnect.OnReceive := @OnReceivedRigctldConnect;
rcvdFreqMode.OnReceive := @OnReceivedRcvdFreqMode RigctldConnect.OnConnect := @OnConnectRigctldConnect;
end; end;
function TRigControl.StartRigctld : Boolean; function TRigControl.StartRigctld : Boolean;
@ -192,6 +204,7 @@ end;
function TRigControl.RigConnected : Boolean; function TRigControl.RigConnected : Boolean;
const const
ERR_MSG = 'Could not connect to rigctld'; ERR_MSG = 'Could not connect to rigctld';
begin begin
if fDebugMode then if fDebugMode then
begin begin
@ -227,28 +240,30 @@ begin
if fDebugMode then Writeln('rigctld failed to start!'); if fDebugMode then Writeln('rigctld failed to start!');
Result := False; Result := False;
exit exit
end else end
else
if fDebugMode then Writeln('rigctld started!'); if fDebugMode then Writeln('rigctld started!');
end else end
else
if fDebugMode then Writeln('Not started rigctld process. (Run is set FALSE)'); if fDebugMode then Writeln('Not started rigctld process. (Run is set FALSE)');
rcvdFreqMode.Host := fRigCtldHost; RigctldConnect.Host := fRigCtldHost;
rcvdFreqMode.Port := fRigCtldPort; RigctldConnect.Port := fRigCtldPort;
//rcvdFreqMode.Connect(fRigCtldHost,fRigCtldPort); if RigctldConnect.Connect(fRigCtldHost,fRigCtldPort) then //this does not work as connection indicator, is always true!!
if rcvdFreqMode.Connect(fRigCtldHost,fRigCtldPort) then //even when it can not connect rigctld.
begin begin
if fDebugMode then Writeln('Connected to rigctld @ ',fRigCtldHost,':',fRigCtldPort); if fDebugMode then Writeln('Waiting for rigctld @ ',fRigCtldHost,':',fRigCtldPort);
result := True; result := True;
ParmVfoChkd:= not(RigChkVfo); //default: check of "--vfo" not done is false, assigned by preferences not(RigVfoChk) AllowCommand:=-1;
ParmHasVfo:=0; //default: "--vfo" is not used as start parameter ParmHasVfo:=0; //default: "--vfo" is not used as start parameter
tmrRigPoll.Interval := fRigPoll; tmrRigPoll.Interval := fRigPoll;
tmrRigPoll.Enabled := True; tmrRigPoll.Enabled := True;
RigCommand.Clear; RigCommand.Clear;
end end
else begin else begin
if fDebugMode then Writeln('NOT connected to rigctld @ ',fRigCtldHost,':',fRigCtldPort); if fDebugMode then Writeln('ERROR: *NOT* connected to rigctld @ ',fRigCtldHost,':',fRigCtldPort);
fLastError := ERR_MSG; fLastError := ERR_MSG;
Result := False Result := False
end end
@ -263,64 +278,77 @@ begin
VFOB : Begin VFOB : Begin
RigCommand.Add('V VFOB');//sendCommand.SendMessage('V VFOB'+LineEnding); RigCommand.Add('V VFOB');//sendCommand.SendMessage('V VFOB'+LineEnding);
end; end;
end //case end; //case
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.SetModePass(mode : TRigMode); procedure TRigControl.SetModePass(mode : TRigMode);
begin begin
if (mode.mode='CW') and fRigSendCWR then if (mode.mode='CW') and fRigSendCWR then
mode.mode := 'CWR'; mode.mode := 'CWR';
RigCommand.Add('+M'+VfoStr+' '+mode.mode+' '+IntToStr(mode.pass)) RigCommand.Add('+M'+VfoStr+' '+mode.mode+' '+IntToStr(mode.pass));
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.SetFreqKHz(freq : Double); procedure TRigControl.SetFreqKHz(freq : Double);
begin begin
RigCommand.Add('+F'+VfoStr+' '+FloatToStr(freq*1000-TXOffset*1000000)) RigCommand.Add('+F'+VfoStr+' '+FloatToStr(freq*1000-TXOffset*1000000));
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.ClearRit; procedure TRigControl.ClearRit;
begin begin
RigCommand.Add('+J'+VfoStr+' 0') RigCommand.Add('+J'+VfoStr+' 0');
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.DisableRit; procedure TRigControl.DisableRit;
Begin Begin
RigCommand.Add('+U'+VfoStr+' RIT 0'); RigCommand.Add('+U'+VfoStr+' RIT 0');
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.SetSplit(up:integer); procedure TRigControl.SetSplit(up:integer);
Begin Begin
RigCommand.Add('+Z'+VfoStr+' '+IntToStr(up)); RigCommand.Add('+Z'+VfoStr+' '+IntToStr(up));
RigCommand.Add('+U'+VfoStr+' XIT 1'); RigCommand.Add('+U'+VfoStr+' XIT 1');
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.ClearXit; procedure TRigControl.ClearXit;
begin begin
RigCommand.Add('+Z'+VfoStr+' 0') RigCommand.Add('+Z'+VfoStr+' 0');
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.DisableSplit; procedure TRigControl.DisableSplit;
Begin Begin
RigCommand.Add('+U'+VfoStr+' XIT 0'); RigCommand.Add('+U'+VfoStr+' XIT 0');
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.PttOn; procedure TRigControl.PttOn;
begin begin
RigCommand.Add('+T'+VfoStr+' 1') RigCommand.Add('+T'+VfoStr+' 1');
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.PttOff; procedure TRigControl.PttOff;
begin begin
RigCommand.Add('+T'+VfoStr+' 0') RigCommand.Add('+T'+VfoStr+' 0');
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.PwrOn; procedure TRigControl.PwrOn;
begin begin
RigCommand.Add(#$87+' 1') AllowCommand:=8; //high prority passes -1 state
end; end;
procedure TRigControl.PwrOff; procedure TRigControl.PwrOff;
begin begin
RigCommand.Add(#$87+' 0') RigCommand.Add('+\set_powerstat 0');
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.PwrStBy; procedure TRigControl.PwrStBy;
begin begin
RigCommand.Add(#$87+' 2') RigCommand.Add('+\set_powerstat 2');
AllowCommand:=1; //call queue
end; end;
procedure TRigControl.UsrCmd(cmd:String); procedure TRigControl.UsrCmd(cmd:String);
begin begin
RigCommand.Add(cmd) RigCommand.Add(cmd);
AllowCommand:=1; //call queue
end; end;
function TRigControl.GetCurrVFO : TVFO; function TRigControl.GetCurrVFO : TVFO;
begin begin
@ -431,7 +459,7 @@ begin
result := fFreq result := fFreq
end; end;
procedure TRigControl.OnReceivedRcvdFreqMode(aSocket: TLSocket); procedure TRigControl.OnReceivedRigctldConnect(aSocket: TLSocket);
var var
msg : String; msg : String;
a,b : TExplodeArray; a,b : TExplodeArray;
@ -440,20 +468,10 @@ var
begin begin
if aSocket.GetMessage(msg) > 0 then if aSocket.GetMessage(msg) > 0 then
begin begin
//Writeln('Whole MSG:|',msg,'|'); msg := StringReplace(upcase(trim(msg)),#$09,' ',[rfReplaceAll]); //note the char case upper for now on! Remove TABs
msg := upcase(trim(msg)); //note the char case!
if DebugMode then if DebugMode then
Writeln('Msg from rig: ',msg); Writeln('Msg from rig:|',msg,'|'+LineEnding);
if not ParmVfoChkd then
Begin
ParmVfoChkd:=true;
if (msg[1]='1') then ParmHasVfo := 1; //Hamlib 4.3
if (pos('CHKVFO 1',msg)>0) then ParmHasVfo := 2; //Hamlib 3.3
if DebugMode then Writeln('"--vfo" checked:',ParmHasVfo);
if ParmHasVfo > 0 then VfoStr:=' currVFO'; //note set leading one space to string!
end;
a := Explode(LineEnding,msg); a := Explode(LineEnding,msg);
for i:=0 to Length(a)-1 do //this handles received message line by line for i:=0 to Length(a)-1 do //this handles received message line by line
@ -469,10 +487,10 @@ begin
if TryStrToFloat(b[1],f) then if TryStrToFloat(b[1],f) then
Begin Begin
fFReq := f; fFReq := f;
BadRcvd := 0;
end end
else else
fFReq := 0; fFReq := 0;
AllowCommand:=1; //check pending commands
end; end;
if b[0]='MODE:' then if b[0]='MODE:' then
@ -482,7 +500,8 @@ begin
if (fMode.mode = 'USB') or (fMode.mode = 'LSB') then if (fMode.mode = 'USB') or (fMode.mode = 'LSB') then
fMode.mode := 'SSB'; fMode.mode := 'SSB';
if fMode.mode = 'CWR' then if fMode.mode = 'CWR' then
fMode.mode := 'CW' fMode.mode := 'CW';
AllowCommand:=1;
end; end;
//FT-920 returned VFO as MEM //FT-920 returned VFO as MEM
@ -504,6 +523,64 @@ begin
else else
fVFO := VFOA; fVFO := VFOA;
end; end;
AllowCommand:=1;
end;
if b[0]='CHKVFO:' then //Hamlib 4.3
Begin
ParmVfoChkd:=true;
if b[1]='1' then
ParmHasVfo := 1;
if DebugMode then Writeln('"--vfo" checked:',ParmHasVfo);
if ParmHasVfo > 0 then VfoStr:=' currVFO'; //note set leading one space to string!
AllowCommand:=9; //next dump caps
end;
if b[0]='CHKVFO' then //Hamlib 3.1
Begin
ParmVfoChkd:=true;
if b[1]='1' then
ParmHasVfo := 2;
if DebugMode then Writeln('"--vfo" checked:',ParmHasVfo);
if ParmHasVfo > 0 then VfoStr:=' currVFO'; //note set leading one space to string!
AllowCommand:=9; //next dump caps
end;
if pos('CAN SET POWER STAT:',a[i])>0 then
Begin
fPower:= b[4]='Y';
if DebugMode then Writeln('Switch power: ',fPower);
end;
if pos('CAN GET VFO:',a[i])>0 then
Begin
fGetVfo:= b[3]='Y';
if DebugMode then Writeln(LineEnding+'Get VFO: ',fGetVfo);
end;
if pos('CAN SEND MORSE:',a[i])>0 then
Begin
fMorse:= b[3]='Y';
if DebugMode then Writeln('Send Morse: ',fMorse,LineEnding);
if fPower then
AllowCommand:=8 //issue power on
else
AllowCommand:=1 //check pending commands
end;
if pos('SET_POWERSTAT:',a[i])>0 then
Begin
if pos('1',a[i])>0 then //line may have 'STAT: 1' or 'STAT: CURRVFO 1'
Begin
if DebugMode then Writeln('Power on, start polling');
AllowCommand:=93; //check pending commands via delay
end
else
Begin
if DebugMode then Writeln('Power off, stop polling');
AllowCommand:=-1;
end;
end; end;
end; end;
end; end;
@ -515,26 +592,58 @@ var
cmd : String; cmd : String;
i : Integer; i : Integer;
begin begin
if not ParmVfoChkd then case AllowCommand of
RigCommand.Clear; // chk must be first thing to do //delay up to 10 timer rounds with this selecting one of numbers
99: AllowCommand:=98;
98: AllowCommand:=97;
97: AllowCommand:=96;
96: AllowCommand:=95;
95: AllowCommand:=94;
94: AllowCommand:=93;
93: AllowCommand:=92;
92: AllowCommand:=91;
91: AllowCommand:=1;
//high priority commands
10: Begin
cmd:='+\chk_vfo'+LineEnding;
if DebugMode then
Writeln('Sending: '+cmd);
RigctldConnect.SendMessage(cmd);
AllowCommand:=-1; //waiting for reply
end;
9: Begin
cmd:='+\dump_caps'+LineEnding;
if DebugMode then
Writeln('Sending: '+cmd);
RigctldConnect.SendMessage(cmd);
AllowCommand:=-1; //waiting for reply
end;
8: Begin
cmd:= '+\set_powerstat 1'+LineEnding;
if DebugMode then
Writeln('Sending: '+cmd);
RigctldConnect.SendMessage(cmd);
AllowCommand:=-1; //waiting for reply
end;
//lower priority commands queue handled here
1: Begin
if (RigCommand.Text<>'') then if (RigCommand.Text<>'') then
begin begin
for i:=0 to RigCommand.Count-1 do for i:=0 to RigCommand.Count-1 do
begin Begin
sleep(100);
cmd := RigCommand.Strings[i]+LineEnding; cmd := RigCommand.Strings[i]+LineEnding;
rcvdFreqMode.SendMessage(cmd); RigctldConnect.SendMessage(cmd);
if DebugMode then if DebugMode then
Writeln('Sending: '+cmd) Writeln('Queue Sending: [',i,'] '+cmd);
end;
RigCommand.Clear
end end
else end;
begin RigCommand.Clear;
if not ParmVfoChkd then AllowCommand:=0; //polling
cmd := '\chk_vfo'+LineEnding end;
else //polling has lowest prority, do if there is nothing else to do
0: begin
if ParmHasVfo=2 then if ParmHasVfo=2 then
cmd := '+f'+VfoStr+' +m'+VfoStr+' +v'+VfoStr+LineEnding //chk this with rigctld v3.1 cmd := '+f'+VfoStr+' +m'+VfoStr+' +v'+VfoStr+LineEnding //chk this with rigctld v3.1
else else
@ -542,15 +651,29 @@ begin
if DebugMode then if DebugMode then
Writeln('Poll Sending: '+cmd); Writeln('Poll Sending: '+cmd);
rcvdFreqMode.SendMessage(cmd) RigctldConnect.SendMessage(cmd);
AllowCommand:=-1; //waiting for reply
end; end;
inc(BadRcvd); //we use this now as "no freq reply" counter end;//case
if BadRcvd > 10 then // if missed to get frequency during 10 polls, rig connection is dead(?)
Begin
fFReq := 0;
BadRcvd := 10; // prevent overflow
end; end;
procedure TRigControl.OnConnectRigctldConnect(aSocket: TLSocket);
Begin
if DebugMode then
Writeln('Connected to rigctld');
if RigChkVfo then
Begin
AllowCommand:=10; //start with chkvfo
ParmVfoChkd:=false;
end
else
Begin
AllowCommand:=9; //otherwise start with dump caps
ParmVfoChkd:=false;
end;
RigCommand.Clear;
end; end;
procedure TRigControl.Restart; procedure TRigControl.Restart;
@ -559,7 +682,7 @@ var
begin begin
rigProcess.Terminate(excode); rigProcess.Terminate(excode);
tmrRigPoll.Enabled := False; tmrRigPoll.Enabled := False;
rcvdFreqMode.Disconnect(); RigctldConnect.Disconnect();
RigConnected RigConnected
end; end;
@ -591,7 +714,7 @@ var
excode : Integer=0; excode : Integer=0;
begin begin
inherited; inherited;
if DebugMode then Writeln(1); if DebugMode then Writeln('Destroy rigctld'+LineEnding+'1');
if fRunRigCtld then if fRunRigCtld then
begin begin
if rigProcess.Running then if rigProcess.Running then
@ -603,13 +726,13 @@ begin
if DebugMode then Writeln(2); if DebugMode then Writeln(2);
tmrRigPoll.Enabled := False; tmrRigPoll.Enabled := False;
if DebugMode then Writeln(3); if DebugMode then Writeln(3);
rcvdFreqMode.Disconnect(); RigctldConnect.Disconnect();
if DebugMode then Writeln(4); if DebugMode then Writeln(4);
FreeAndNil(rcvdFreqMode); FreeAndNil(RigctldConnect);
if DebugMode then Writeln(5); if DebugMode then Writeln(5);
FreeAndNil(rigProcess); FreeAndNil(rigProcess);
FreeAndNil(RigCommand); FreeAndNil(RigCommand);
if DebugMode then Writeln(6) if DebugMode then Writeln('6'+LineEnding+'Done!')
end; end;
end. end.

View File

@ -21,7 +21,7 @@ const
cRELEAS = 0; cRELEAS = 0;
cBUILD = 1; cBUILD = 1;
cBUILD_DATE = '2022-06-08'; cBUILD_DATE = '2022-06-30';
implementation implementation