Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor - introduce dynamic Recv/Sent Exchange Types #95

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Contest.pas
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ TContest = class
constructor Create;
destructor Destroy; override;
procedure Init;
function GetSentExchTypes(
const AStationKind : TStationKind;
const AMyCallsign : string) : TExchTypes;
function GetRecvExchTypes(
const AStationKind : TStationKind;
const AMyCallsign : string;
const ADxCallsign : string) : TExchTypes;
function Minute: Single;
function GetAudio: TSingleArray;
procedure OnMeFinishedSending;
Expand Down Expand Up @@ -98,6 +105,33 @@ procedure TContest.Init;
end;


{
Return sent dynamic exchange types for the given kind-of-station and callsign.
}
function TContest.GetSentExchTypes(
const AStationKind : TStationKind;
const AMyCallsign : string) : TExchTypes;
begin
Result.Exch1 := ActiveContest.ExchType1;
Result.Exch2 := ActiveContest.ExchType2;
end;


{
Return received dynamic exchange types for the given kind-of-station,
user's (simulation callsign) and the dx station's callsign.
Different contests will use either user's callsign or dx station's callsign.
}
function TContest.GetRecvExchTypes(
const AStationKind : TStationKind;
const AMyCallsign : string;
const ADxCallsign : string) : TExchTypes;
begin
Result.Exch1 := ActiveContest.ExchType1;
Result.Exch2 := ActiveContest.ExchType2;
end;


function TContest.GetAudio: TSingleArray;
const
NOISEAMP = 6000;
Expand Down
7 changes: 5 additions & 2 deletions DxStn.pas
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ constructor TDxStation.CreateStation;

Wpm := Oper.GetWpm;

// DX's sent exchange types depends on kind-of-station and their callsign
SentExchTypes := Tst.GetSentExchTypes(skDxStation, MyCall);

// Adding a contest: DxStation.CreateStation - get Exch1 (e.g. Name), Exch2 (e.g. NR), and optional UserText
case SimContest of
scCwt: begin
Expand Down Expand Up @@ -215,15 +218,15 @@ procedure TDxStation.DataToLastQso;
TrueRst := Self.Rst;
TrueNR := Self.NR;
// Adding a contest: copy DxStation's Exch1 qso information into log
case ActiveContest.ExchType1 of
case SentExchTypes.Exch1 of
etRST: TrueExch1 := IntToStr(Self.RST);
etOpName: TrueExch1 := Self.OpName;
etFdClass: TrueExch1 := Self.Exch1;
else
assert(false);
end;
// Adding a contest: copy DxStation's Exch2 qso information into log
case ActiveContest.ExchType2 of
case SentExchTypes.Exch2 of
etSerialNr: TrueExch2 := IntToStr(Self.NR);
etCwopsNumber: TrueExch2 := IntToStr(Self.NR);
etCqZone: TrueExch2 := IntToStr(Self.NR);
Expand Down
14 changes: 7 additions & 7 deletions Log.pas
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ procedure SaveQso;
function ValidateExchField1(const text: string): Boolean;
begin
Result := false;
case ActiveContest.ExchType1 of
case Mainform.RecvExchTypes.Exch1 of
etRST: Result := Length(text) = 3;
etOpName: Result := Length(text) > 1;
etFdClass: Result := Length(text) > 1;
Expand All @@ -422,7 +422,7 @@ procedure SaveQso;
function ValidateExchField2(const text: string): Boolean;
begin
Result := false;
case ActiveContest.ExchType2 of
case Mainform.RecvExchTypes.Exch2 of
etSerialNr: Result := Length(text) > 0;
etCwopsNumber: Result := Length(text) > 0;
etArrlSection: Result := Length(text) > 1;
Expand Down Expand Up @@ -458,7 +458,7 @@ procedure SaveQso;

// Adding a contest: save contest-specific exchange values into QsoList
//save Exchange 1 (Edit2)
case ActiveContest.ExchType1 of
case Mainform.RecvExchTypes.Exch1 of
etRST: Qso.Rst := StrToInt(Edit2.Text);
etOpName: Qso.Exch1 := Edit2.Text;
etFdClass: Qso.Exch1 := Edit2.Text;
Expand All @@ -467,7 +467,7 @@ procedure SaveQso;
end;

//save Exchange2 (Edit3)
case ActiveContest.ExchType2 of
case Mainform.RecvExchTypes.Exch2 of
etSerialNr: Qso.Nr := StrToInt(Edit3.Text);
etCwopsNumber: Qso.Nr := StrToInt(Edit3.Text);
etArrlSection: Qso.Exch2 := Edit3.Text;
Expand Down Expand Up @@ -529,7 +529,7 @@ procedure SaveQso;
MainForm.WipeBoxes;

//inc NR
if ActiveContest.ExchType2 = etSerialNr then
if Tst.Me.SentExchTypes.Exch2 = etSerialNr then
Inc(Tst.Me.NR);
end;

Expand Down Expand Up @@ -581,7 +581,7 @@ procedure CheckErr;
Err := 'DUP';
if Err.IsEmpty then
// Adding a contest: check for contest-specific exchange field 1 errors
case ActiveContest.ExchType1 of
case Mainform.RecvExchTypes.Exch1 of
etRST: if TrueRst <> Rst then Err := 'RST';
etOpName: if TrueExch1 <> Exch1 then Err := 'NAME';
etFdClass: if TrueExch1 <> Exch1 then Err := 'CL ';
Expand All @@ -590,7 +590,7 @@ procedure CheckErr;
end;
if Err.IsEmpty then
// Adding a contest: check for contest-specific exchange field 2 errors
case ActiveContest.ExchType2 of
case Mainform.RecvExchTypes.Exch2 of
etSerialNr: if TrueNr <> NR then Err := 'NR ';
etCwopsNumber: if TrueNr <> NR then Err := 'NR ';
etCqZone: if TrueNr <> NR then Err := 'ZN ';
Expand Down
45 changes: 30 additions & 15 deletions Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ TMainForm = class(TForm)

private
MustAdvance: boolean;
ExchangeField1Type: TExchange1Type;
ExchangeField2Type: TExchange2Type;
procedure ConfigureExchangeFields(
AExchType1: TExchange1Type;
AExchType2: TExchange2Type);
Expand All @@ -373,6 +371,14 @@ TMainForm = class(TForm)
procedure IncSpeed;
public
CompetitionMode: boolean;

// Received Exchange information is contest-specific and depends on contest,
// user's QTH/location, DX station's QTH/location, and whether the user's
// station is local/DX relative to the contest.
// This value is set by calling the virtual TContest.GetSentExchTypes()
// function.
RecvExchTypes: TExchTypes;

procedure Run(Value: TRunMode);
procedure WipeBoxes;
procedure PopupScoreWpx;
Expand Down Expand Up @@ -420,8 +426,8 @@ function ToStr(const val : TExchange2Type) : string; overload;
function Edit2IsRST: Boolean;
begin
assert((not (SimContest in [scWpx, scHst])) or
(MainForm.ExchangeField1Type = etRST));
Result := MainForm.ExchangeField1Type = etRST;
(MainForm.RecvExchTypes.Exch1 = etRST));
Result := MainForm.RecvExchTypes.Exch1 = etRST;
end;

procedure TMainForm.FormCreate(Sender: TObject);
Expand Down Expand Up @@ -517,7 +523,7 @@ procedure TMainForm.Edit1KeyPress(Sender: TObject; var Key: Char);

procedure TMainForm.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
case ExchangeField1Type of
case RecvExchTypes.Exch1 of
etRST:
begin
if RunMode <> rmHst then
Expand Down Expand Up @@ -546,13 +552,13 @@ procedure TMainForm.Edit2KeyPress(Sender: TObject; var Key: Char);
end;
else
assert(false, Format('invalid exchange field 1 type: %s',
[ToStr(ExchangeField1Type)]));
[ToStr(RecvExchTypes.Exch1)]));
end;
end;

procedure TMainForm.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
case ExchangeField2Type of
case RecvExchTypes.Exch2 of
etSerialNr, etCwopsNumber, etCqZone, etItuZone, etAge:
begin
if RunMode <> rmHst then
Expand Down Expand Up @@ -590,7 +596,7 @@ procedure TMainForm.Edit3KeyPress(Sender: TObject; var Key: Char);
end;
else
assert(false, Format('invalid exchange field 2 type: %s',
[ToStr(ExchangeField2Type)]));
[ToStr(RecvExchTypes.Exch2)]));
end;
end;

Expand Down Expand Up @@ -880,6 +886,9 @@ procedure TMainForm.SetContest(AContestNum: TSimContest);
sbar.Font.Color := clDefault;
sbar.Visible := mnuShowCallsignInfo.Checked;

// update my sent exchange types
Tst.Me.SentExchTypes := Tst.GetSentExchTypes(skMyStation, Ini.Call);

// update Exchange field labels and length settings (e.g. RST, Nr.)
ConfigureExchangeFields(ActiveContest.ExchType1, ActiveContest.ExchType2);
end;
Expand All @@ -892,19 +901,22 @@ procedure TMainForm.SetContest(AContestNum: TSimContest);
end;}

{
Set my exchange fields using the exchange string containing two values,
Set my "sent" exchange fields using the exchange string containing two values,
separated by a space. Error/warning messages are displayed in the status bar.
}
procedure TMainForm.SetMyExchange(const AExchange: string);
var
sl: TStringList;
SentExchTypes : TExchTypes;
Field1Def: PFieldDefinition;
Field2Def: PFieldDefinition;
begin
sl:= TStringList.Create;
try
Field1Def := @Exchange1Settings[ActiveContest.ExchType1];
Field2Def := @Exchange2Settings[ActiveContest.ExchType2];
SentExchTypes:= Tst.GetSentExchTypes(skMyStation, Ini.Call);
assert(Tst.Me.SentExchTypes = SentExchTypes, 'this is already set; above call not necessary');
Field1Def := @Exchange1Settings[SentExchTypes.Exch1];
Field2Def := @Exchange2Settings[SentExchTypes.Exch2];

// parse into two strings [Exch1, Exch2]
ExtractStrings([' '], [], PChar(AExchange), sl);
Expand Down Expand Up @@ -934,8 +946,9 @@ procedure TMainForm.SetMyExchange(const AExchange: string);
end;

// set contest-specific exchange values
SetMyExch1(ActiveContest.ExchType1, sl[0]);
SetMyExch2(ActiveContest.ExchType2, sl[1]);
SetMyExch1(SentExchTypes.Exch1, sl[0]);
SetMyExch2(SentExchTypes.Exch2, sl[1]);
assert(Tst.Me.SentExchTypes = SentExchTypes);

// update the Exchange field value
ExchangeEdit.Text := AExchange;
Expand Down Expand Up @@ -1001,7 +1014,7 @@ procedure TMainForm.ConfigureExchangeFields(
ToStr(TExchange1Type(Exchange1Settings[AExchType1].T))]));
Label2.Caption:= Exchange1Settings[AExchType1].C;
Edit2.MaxLength:= Exchange1Settings[AExchType1].L;
ExchangeField1Type := AExchType1;
RecvExchTypes.Exch1 := AExchType1;

// setup Exchange Field 2 (e.g. Serial #)
assert(AExchType2 = TExchange2Type(Exchange2Settings[AExchType2].T),
Expand All @@ -1010,7 +1023,7 @@ procedure TMainForm.ConfigureExchangeFields(
ToStr(TExchange2Type(Exchange2Settings[AExchType2].T))]));
Label3.Caption := Exchange2Settings[AExchType2].C;
Edit3.MaxLength := Exchange2Settings[AExchType2].L;
ExchangeField2Type := AExchType2;
RecvExchTypes.Exch2 := AExchType2;

// Set my exchange value (from INI file)
// UI assumes uppercase only, so convert .ini files to uppercase.
Expand Down Expand Up @@ -1050,6 +1063,7 @@ procedure TMainForm.SetMyExch1(const AExchType: TExchange1Type;
else
assert(false, Format('Unsupported exchange 1 type: %s.', [ToStr(AExchType)]));
end;
Tst.Me.SentExchTypes.Exch1 := AExchType;
end;

procedure TMainForm.SetMyExch2(const AExchType: TExchange2Type;
Expand Down Expand Up @@ -1113,6 +1127,7 @@ procedure TMainForm.SetMyExch2(const AExchType: TExchange2Type;
else
assert(false, Format('Unsupported exchange 2 type: %s.', [ToStr(AExchType)]));
end;
Tst.Me.SentExchTypes.Exch2 := AExchType;
end;


Expand Down
8 changes: 6 additions & 2 deletions MyStn.pas
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ procedure TMyStation.Init;
Wpm := Ini.Wpm;
Amplitude := 300000;

// My sent exchange types depends on my callsign
SentExchTypes:= Tst.GetSentExchTypes(skMyStation, MyCall);

// Adding a contest: Initialize Exch1 and Exch2
// (try to use the generalized Exch1 and Exch2 fields for new contests.)
OpName := HamName;
Expand Down Expand Up @@ -87,12 +90,13 @@ procedure TMyStation.AbortSend;

procedure TMyStation.SendText(AMsg: string);
begin
if ActiveContest.ExchType1 = etOpName then
// Adding a contest: some field types have specific behaviors
if SentExchTypes.Exch1 = etOpName then
begin
assert(OpName = HamName, 'HamName doesn''t change; should already be set');
OpName := HamName;
end;
if ActiveContest.ExchType2 = etCwopsNumber then
if SentExchTypes.Exch2 = etCwopsNumber then
begin
//assert(NR = strtoint(CWOPSNUM), 'CWOPS Num doesn''t change, should be set');
NR := strtoint(CWOPSNum);
Expand Down
6 changes: 6 additions & 0 deletions QrmStn.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ TQrmStation = class(TStation)

implementation

uses
Contest;

constructor TQrmStation.CreateStation;
begin
inherited Create(nil);
Expand All @@ -32,6 +35,9 @@ constructor TQrmStation.CreateStation;
Pitch := Round(RndGaussLim(0, 300));
Wpm := 30 + Random(20);

// DX's sent exchange types depends on kind-of-station and their callsign
SentExchTypes:= Tst.GetSentExchTypes(skDxStation, MyCall);

case Random(7) of
0: SendMsg(MsgQrl);
1,2: SendMsg(MsgQrl2);
Expand Down
4 changes: 4 additions & 0 deletions QrnStn.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ constructor TQrnStation.CreateStation;
begin
inherited Create(nil);

// QrnStation doesn't send messages, so no call nor exchange types
SentExchTypes.Exch1:= TExchange1Type(-1);
SentExchTypes.Exch2:= TExchange2Type(-1);

Dur := SecondsToBlocks(Random) * Ini.BufSize;
SetLength(Envelope, Dur);
Amplitude := 1E5*Power(10, 2*Random);
Expand Down
Loading