Skip to content

Commit

Permalink
Prevzeti do rucniho rizeni z panelu.
Browse files Browse the repository at this point in the history
Close #13.
  • Loading branch information
horacekj committed Mar 28, 2017
1 parent 89d17b0 commit 81438cf
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 29 deletions.
39 changes: 26 additions & 13 deletions src/LokTokens.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ interface
uses SysUtils, Generics.Collections, Classes;

type
TTokenPurpose = (tpReg, tpMaus);
TTokenPurpose = record
slot: Integer;
ruc: boolean;
end;

TTokens = class
private
tokenPurpose:TDictionary<Word, Integer>; // mapa adresa -> maus slot
tokenPurpose:TDictionary<Word, TTokenPurpose>; // mapa adresa -> maus slot

class function Purpose(slot: Integer; ruc: boolean):TTokenPurpose;

public

Expand All @@ -18,7 +23,7 @@ TTokens = class

procedure ParseData(var parsed:TStrings);
procedure LokosToReg(orId:string; lokos:array of Word); // lokos: 1234|1235| ....
procedure LokosToMaus(orId:string; lokos:array of Word; slot:Integer);
procedure LokosToMaus(orId:string; lokos:array of Word; slot:Integer; ruc:boolean);
procedure ResetMausTokens();

end;
Expand All @@ -35,7 +40,7 @@ implementation
constructor TTokens.Create();
begin
inherited;
tokenPurpose := TDictionary<Word, Integer>.Create();
tokenPurpose := TDictionary<Word, TTokenPurpose>.Create();
end;

destructor TTokens.Destroy();
Expand All @@ -49,7 +54,7 @@ destructor TTokens.Destroy();
procedure TTokens.ParseData(var parsed:TStrings);
var HVs:THVDb;
i:Integer;
slot, gslot: Integer;
purpose, gpurpose:TTokenPurpose;
splitted:TStrings;
begin
if (parsed[2] = 'OK') then
Expand All @@ -60,18 +65,18 @@ procedure TTokens.ParseData(var parsed:TStrings);
HVs := THVDb.Create();
HVs.ParseHVsFromToken(parsed[3]);

gslot := 0;
gpurpose.slot := 0;
for i := 0 to HVs.count-1 do
begin
if ((gslot = 0) and (Self.tokenPurpose.TryGetValue(HVs.HVs[i].Adresa, slot))) then gslot := slot
else if ((gslot > 0) and ((not Self.tokenPurpose.TryGetValue(HVs.HVs[i].Adresa, slot)) or (slot <> gslot))) then
if ((gpurpose.slot = 0) and (Self.tokenPurpose.TryGetValue(HVs.HVs[i].Adresa, purpose))) then gpurpose := purpose
else if ((gpurpose.slot > 0) and ((not Self.tokenPurpose.TryGetValue(HVs.HVs[i].Adresa, purpose)) or (purpose.slot <> gpurpose.slot))) then
begin
gslot := 0;
gpurpose.slot := 0;
break;
end;
end;

case (gslot) of
case (gpurpose.slot) of
0: begin
try
HVs.OpenJerry();
Expand All @@ -82,7 +87,7 @@ procedure TTokens.ParseData(var parsed:TStrings);
end;

1..TBridgeClient._SLOTS_CNT: begin
if (BridgeClient.opened) then BridgeClient.LoksToSlot(HVs, gslot);
if (BridgeClient.opened) then BridgeClient.LoksToSlot(HVs, gpurpose.slot, gpurpose.ruc);
end;

end;//case
Expand Down Expand Up @@ -130,15 +135,15 @@ procedure TTokens.LokosToReg(orId:string; lokos:array of Word);
PanelTCPClient.SendLn(orId+';LOK-REQ;PLEASE;'+str);
end;

procedure TTokens.LokosToMaus(orId:string; lokos:array of Word; slot:Integer);
procedure TTokens.LokosToMaus(orId:string; lokos:array of Word; slot:Integer; ruc:boolean);
var i:Integer;
str:string;
begin
str := '';
for i := 0 to Length(lokos)-1 do
begin
str := str + IntToStr(lokos[i]) + '|';
Self.tokenPurpose.AddOrSetValue(lokos[i], slot);
Self.tokenPurpose.AddOrSetValue(lokos[i], Purpose(slot, ruc));
end;

PanelTCPClient.SendLn(orId+';LOK-REQ;PLEASE;'+str);
Expand All @@ -153,6 +158,14 @@ procedure TTokens.ResetMausTokens();

////////////////////////////////////////////////////////////////////////////////

class function TTokens.Purpose(slot: Integer; ruc: boolean):TTokenPurpose;
begin
Result.slot := slot;
Result.ruc := ruc;
end;

////////////////////////////////////////////////////////////////////////////////

initialization
tokens := TTokens.Create();

Expand Down
2 changes: 1 addition & 1 deletion src/fRegReq.pas
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ procedure TF_RegReq.B_LocalClick(Sender: TObject);
end;

if (Self.maus) then
tokens.LokosToMaus(Self.or_id, lokos, TButton(Sender).Tag)
tokens.LokosToMaus(Self.or_id, lokos, TButton(Sender).Tag, false)
else
tokens.LokosToReg(Self.or_id, lokos);

Expand Down
6 changes: 3 additions & 3 deletions src/fSprToSlot.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object F_SprToSlot: TF_SprToSlot
Top = 0
BorderStyle = bsToolWindow
Caption = 'Souprava do slotu'
ClientHeight = 133
ClientHeight = 155
ClientWidth = 447
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Expand Down Expand Up @@ -54,7 +54,7 @@ object F_SprToSlot: TF_SprToSlot
end
object L_Stav: TLabel
Left = 8
Top = 109
Top = 131
Width = 417
Height = 16
Align = alCustom
Expand All @@ -73,7 +73,7 @@ object F_SprToSlot: TF_SprToSlot
Left = 8
Top = 56
Width = 431
Height = 41
Height = 69
BevelOuter = bvNone
TabOrder = 0
end
Expand Down
39 changes: 36 additions & 3 deletions src/fSprToSlot.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ TF_SprToSlot = class(TForm)
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
B_Slots: array [1..TBridgeClient._SLOTS_CNT] of TButton;
B_Slots_Ruc: array [1..TBridgeClient._SLOTS_CNT] of TButton;

HVs:TWordAr;
orId:string;

procedure CreateSlotsButtons();
procedure ButtonSlotClick(Sender:TObject);
procedure ButtonSlotRucClick(Sender:TObject);

public

Expand Down Expand Up @@ -60,6 +63,19 @@ procedure TF_SprToSlot.CreateSlotsButtons();
Width := 70;
OnClick := Self.ButtonSlotClick;
Caption := IntToStr(i);
TabOrder := 2*i;
end;

Self.B_Slots_Ruc[i] := TButton.Create(Self.P_Buttons);
with (Self.B_Slots_Ruc[i]) do
begin
Parent := Self.P_Buttons;
Top := 35;
Tag := i;
Width := 70;
OnClick := Self.ButtonSlotRucClick;
Caption := IntToStr(i) + ' ruè.';
TabOrder := 2*i + 1;
end;
end;
end;
Expand Down Expand Up @@ -102,12 +118,20 @@ procedure TF_SprToSlot.RepaintSlots();
Visible := ((BridgeClient.sloty[i] = ssAvailable) or (BridgeClient.sloty[i] = ssFull));
Enabled := (BridgeClient.sloty[i] = ssAvailable);

if (Visible) then
Left := (partWidth*j + (partWidth div 2) - (Self.B_Slots[i].Width div 2)) + 10;
end;

with (Self.B_Slots_Ruc[i]) do
begin
Visible := Self.B_Slots[i].Visible;
Enabled := Self.B_Slots[i].Enabled;

if (Visible) then
begin
Self.B_Slots[i].Left := (partWidth*j + (partWidth div 2) - (Self.B_Slots[i].Width div 2)) + 10;
Left := (partWidth*j + (partWidth div 2) - (Self.B_Slots[i].Width div 2)) + 10;
Inc(j);
end;

end;
end;
end;
Expand All @@ -116,7 +140,15 @@ procedure TF_SprToSlot.RepaintSlots();

procedure TF_SprToSlot.ButtonSlotClick(Sender:TObject);
begin
tokens.LokosToMaus(Self.orId, Self.HVs, TButton(Sender).Tag);
tokens.LokosToMaus(Self.orId, Self.HVs, TButton(Sender).Tag, false);

Self.L_Stav.Caption := 'Odeslána žádost o vydání tokenù...';
Self.token_req_sent := true;
end;

procedure TF_SprToSlot.ButtonSlotRucClick(Sender:TObject);
begin
tokens.LokosToMaus(Self.orId, Self.HVs, TButton(Sender).Tag, true);

Self.L_Stav.Caption := 'Odeslána žádost o vydání tokenù...';
Self.token_req_sent := true;
Expand Down Expand Up @@ -145,6 +177,7 @@ procedure TF_SprToSlot.Open(orId:string; HVs:TWordAr);
if ((self.B_Slots[i].Visible) and (Self.B_Slots[i].Enabled)) then
begin
Self.B_Slots[i].Default := true;
Self.ActiveControl := Self.B_Slots[i];
break;
end;
end;
Expand Down
4 changes: 2 additions & 2 deletions src/hJOPpanel.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<VersionInfo Name="AutoIncBuild">True</VersionInfo>
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">4</VersionInfo>
<VersionInfo Name="Release">6</VersionInfo>
<VersionInfo Name="Release">7</VersionInfo>
<VersionInfo Name="Build">0</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
Expand All @@ -179,7 +179,7 @@
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription">Panel stanice hJOP</VersionInfoKeys>
<VersionInfoKeys Name="FileVersion">1.4.6.0</VersionInfoKeys>
<VersionInfoKeys Name="FileVersion">1.4.7.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName">hJOPpanel.exe</VersionInfoKeys>
<VersionInfoKeys Name="LegalCopyright">Jan Horáček</VersionInfoKeys>
<VersionInfoKeys Name="LegalTrademarks">Jan Horáček</VersionInfoKeys>
Expand Down
19 changes: 12 additions & 7 deletions src/uLIclient.pas
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TBridgeClient = class
procedure SendLn(str:string);
procedure Update();
procedure Auth();
procedure LoksToSlot(HVs:THVDb; slot:Integer);
procedure LoksToSlot(HVs:THVDb; slot:Integer; ruc:boolean);
procedure GetSlotsStatus();

property opened : boolean read GetOpened;
Expand Down Expand Up @@ -97,10 +97,11 @@ implementation
/////////////////////////// KLIENT -> SERVER ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
LOGIN;server;port;username;password - pozadavek k pripojeni k serveru a autorizaci regulatoru
LOKO;slot;[addr;token];[addr;token];... - pozadavek k umisteni lokomotiv do slotu \slot
SLOTS? - pozadavek na vraceni seznamu slotu a jejich obsahu
AUTH? - pozadavek na vraceni stavu autorizace vuci hJOPserveru
LOGIN;server;port;username;password - pozadavek k pripojeni k serveru a autorizaci regulatoru
LOKO;slot;[addr;token];[addr;token];... - pozadavek k umisteni lokomotiv do slotu \slot
LOKO-RUC;slot;[addr;token];[addr;token];... - pozadavek k umisteni lokomotiv do slotu \slot a autorizaci do totalniho rizeni
SLOTS? - pozadavek na vraceni seznamu slotu a jejich obsahu
AUTH? - pozadavek na vraceni stavu autorizace vuci hJOPserveru
////////////////////////////////////////////////////////////////////////////////
/////////////////////////// SERVER -> KLIENT ///////////////////////////////////
Expand Down Expand Up @@ -433,14 +434,18 @@ procedure TBridgeClient.Auth();

////////////////////////////////////////////////////////////////////////////////

procedure TBridgeClient.LoksToSlot(HVs:THVDb; slot:Integer);
procedure TBridgeClient.LoksToSlot(HVs:THVDb; slot:Integer; ruc:boolean);
var str:string;
i:Integer;
begin
str := '';
for i := 0 to HVs.count-1 do
str := str + '{' + IntToStr(HVs.HVs[i].Adresa) + ';' + HVs.HVs[i].token + '};';
Self.SendLn('LOKO;'+IntToStr(slot)+';'+str);

if (ruc) then
Self.SendLn('LOKO-RUC;'+IntToStr(slot)+';'+str)
else
Self.SendLn('LOKO;'+IntToStr(slot)+';'+str);
end;

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 81438cf

Please sign in to comment.