This commit is contained in:
f1iwq2
2020-03-01 18:15:30 +01:00
parent 155b694a65
commit 11cc298114
25 changed files with 1769 additions and 624 deletions

View File

@@ -15,8 +15,8 @@ interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, ExtCtrls, jpeg, ComCtrls, ListeUSB,
ImgList, ScktComp, StrUtils, Menus, ActnList, MSCommLib_TLB ;
Dialogs, StdCtrls, OleCtrls, ExtCtrls, jpeg, ComCtrls,
ImgList, ScktComp, StrUtils, Menus, ActnList, MSCommLib_TLB , unitConfig ;
type
TFormPrinc = class(TForm)
@@ -35,7 +35,6 @@ type
ButtonCommande: TButton;
ButtonTest: TButton;
ButtonInfo: TButton;
GroupBox2: TGroupBox;
MainMenu1: TMainMenu;
Interface1: TMenuItem;
MenuConnecterUSB: TMenuItem;
@@ -73,8 +72,6 @@ type
Versions1: TMenuItem;
ChronoDetect: TMenuItem;
ClientSocketCDM: TClientSocket;
Label1: TLabel;
EditNbTrains: TEdit;
FichierSimu: TMenuItem;
ButtonEcrCV: TButton;
ButtonReprise: TButton;
@@ -88,6 +85,9 @@ type
EditGenli: TEdit;
Button1: TButton;
Button2: TButton;
Config: TMenuItem;
Label1: TLabel;
LabelNbTrains: TLabel;
procedure FormCreate(Sender: TObject);
procedure MSCommUSBLenzComm(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
@@ -130,7 +130,6 @@ type
procedure ClientSocketLenzDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ChronoDetectClick(Sender: TObject);
procedure EditNbTrainsKeyPress(Sender: TObject; var Key: Char);
procedure FichierSimuClick(Sender: TObject);
procedure ButtonEcrCVClick(Sender: TObject);
procedure ButtonRepriseClick(Sender: TObject);
@@ -139,6 +138,7 @@ type
procedure Quitter1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ConfigClick(Sender: TObject);
private
{ Déclarations privées }
@@ -159,6 +159,7 @@ const_droit=2;const_devieD=1; // positions transmises par la centrale LENZ
const_devieG=3;
MaxElParcours=4000;
EtatSign : array[0..13] of string[20] =('carré','sémaphore','sémaphore cli','vert','vert cli','violet',
'blanc','blanc cli','jaune','jaune cli','ral 30','ral 60','rappel 30','rappel 60');
@@ -204,42 +205,51 @@ TMA = (valide,devalide);
var ancien_tablo_signalCplx,EtatsignalCplx : array[0..MaxAcc] of word;
AvecInitAiguillages,tempsCli,combine,NbreFeux,pasreponse,AdrDevie,precedent ,
NombreImages,signalCpx,branche_trouve,Indexbranche_trouve,Actuel,Signal_suivant,
Nbre_recu_cdm,Tempo_chgt_feux,Adj1,Adj2,protocole,TempoOctet,TimoutMaxInterface : integer;
Nbre_recu_cdm,Tempo_chgt_feux,Adj1,Adj2,protocole : integer;
Hors_tension2,traceSign,TraceZone,Ferme,parSocket,ackCdm,
NackCDM,MsgSim : boolean;
TraceListe,clignotant,nack,Maj_feux_cours : boolean;
branche : array [1..100] of string;
Train : array [1..100,1..MaxElParcours] of integer;
const
ClBleuClair=$FF7070 ;
Cyan=$FFA0A0;
clviolet=$FF00FF;
//GrisF=$333333;
GrisF=$414141;
clOrange=$0077FF;
Feu_X=50;Feu_Y=91;
couleurTrain : array[1..8] of Tcolor = (clYellow,clLime,clOrange,clAqua,clFuchsia,clLtGray,clred,clWhite);
var
FormPrinc: TFormPrinc;
ack,portCommOuvert,trace,AffMem,AfficheDet,CDM_connecte,parSocketCDM,
DebugOuv,Raz_Acc_signaux,AvecInit,AvecTCO,terminal : boolean;
tablo : array of byte;
Enregistrement,AdresseIP,chaine_Envoi,chaine_recue,AdresseIPCDM,recuCDM,Id_CDM,Af,
ConfStCom,entete,suffixe : string;
maxaiguillage,detecteur_chgt,Temps,TpsRecuCom,NumPort,Tempo_init,Suivant,TypeGen,
NbreImagePligne,Port,NbreBranches,Index2_det,branche_det,Index_det,
portCDM,I_simule : integer;
Enregistrement,chaine_Envoi,chaine_recue,Id_CDM,Af,
entete,suffixe,ConfStCom : string;
maxaiguillage,detecteur_chgt,Temps,TpsRecuCom,Tempo_init,Suivant,TypeGen,
NbreImagePligne,NbreBranches,Index2_det,branche_det,Index_det,
I_simule : integer;
Ancien_detecteur,detecteur : array[0..1024] of boolean; // anciens état des détecteurs et adresses des détecteurs et leur état
Adresse_detecteur : array[0..60] of integer; // adresses des détecteurs par index
mem : array[0..1024] of boolean ; // mémoire des états des détecteurs
MemZone : array[0..1024,0..1024] of boolean ; // mémoires de zones
Train : array[1..30] of record
index : integer ; // nombre de routes pour ce train
route : array[1..2000] of record
Mem1,Mem2 : integer;
end;
end;
Tablo_Simule : array[0..200] of
record
tick : longint;
Detecteur,etat : integer ;
end;
N_Cv,index_simule,NDetecteurs,N_Trains : integer;
Route : array[1..2000] of record
Mem1,Mem2 : integer;
end;
N_Cv,index_simule,NDetecteurs,N_Trains,N_routes : integer;
tablo_CV : array [1..255] of integer;
couleur : Tcolor;
fichier : text;
@@ -285,7 +295,7 @@ var
{$R *.dfm}
// utilisation dans unité UnitPilote
// utilisation dans unité UnitPilote et configunit
function Index_feu(adresse : integer) : integer;
procedure dessine_feu2(Acanvas : Tcanvas;EtatSignal : word);
procedure dessine_feu3(Acanvas : Tcanvas;EtatSignal : word);
@@ -302,6 +312,9 @@ procedure Maj_Etat_Signal(adresse,aspect : integer);
procedure Affiche(s : string;lacouleur : TColor);
procedure envoi_signal(Adr : integer);
procedure pilote_direction(Adr,nbre : integer);
procedure connecte_USB;
procedure deconnecte_usb;
function IsWow64Process: Boolean;
implementation
@@ -1023,13 +1036,7 @@ begin
envoi:=ack;
end;
// insère l'id pour le serveur CDM dans une chaîne
function place_id(s : string) : string;
begin
delete(s,5,2);
insert(id_cdm,s,5);
place_id:=s;
end;
// prépare la chaîne de commande pour un accessoire via CDM
Function chaine_CDM_Acc(adresse,etat1 : integer) : string;
@@ -1059,28 +1066,7 @@ begin
chaine_CDM_Acc:=so+s;
end;
// envoi d'une chaîne à CDM par socket, puis attend l'ack ou le nack
function envoi_CDM(s : string) : boolean;
var temps : integer;
begin
if parsocketCDM=false then begin envoi_CDM:=false;exit;end;
//if NivDebug=3 then begin AfficheDebug('Envoi à CDM rail',clRed);afficheDebug(s,ClGreen);end;
Formprinc.ClientSocketCDM.Socket.SendText(s);
// attend l'ack
ackCDM:=false;nackCDM:=false;
if ParSocketCDM then
begin
temps:=0;
repeat
inc(temps);tempo(1);
until ferme or ackCDM or nackCDM or (temps>2); // CDM répond < 1s
if not(ackCDM) or nack then
begin
Affiche('Pas de réponse de CDM Rail',clRed);
end;
end;
envoi_CDM:=ackCDM;
end;
// active ou désactive une sortie. Une adresse comporte deux sorties identifiées par "octet"
// Adresse : adresse de l'accessoire
@@ -1298,6 +1284,8 @@ begin
if (EtatSignalCplx[adr]<>code) then
begin
if (traceSign) then Affiche('Signal directionnel: ad'+IntToSTR(adr)+'='+intToSTR(code),clOrange);
if AffSignal then AfficheDebug('Signal directionnel: ad'+IntToSTR(adr)+'='+intToSTR(code),clOrange);
case code of
0 : begin pilote_acc(adr,1,feu); // sortie 1 à 0
sleep(tempoFeu);
@@ -1344,6 +1332,7 @@ begin
if (EtatSignalCplx[adr]<>code) then
begin
if traceSign then Affiche('signal directionnel CDF: '+IntToSTR(adr)+' '+intToSTR(code),ClOrange);
if AffSignal then AfficheDebug('signal directionnel CDF: '+IntToSTR(adr)+' '+intToSTR(code),ClOrange);
case code of
// éteindre toutes les leds
@@ -1379,6 +1368,8 @@ begin
if (EtatSignalCplx[adr]<>code) then
begin
if traceSign then Affiche('signal directionnel LEB: '+IntToSTR(adr)+' '+intToSTR(code),ClOrange);
if aFFsIGNAL then AfficheDebug('signal directionnel LEB: '+IntToSTR(adr)+' '+intToSTR(code),ClOrange);
case code of
0 : begin pilote_acc(adr+5,2,feu) ; pilote_acc(adr+6,2,feu) ;end; //00
1 : begin pilote_acc(adr+5,1,feu) ; pilote_acc(adr+6,2,feu) ;end; //10
@@ -1402,6 +1393,8 @@ begin
ancien_tablo_signalCplx[adresse]:=EtatSignalCplx[adresse];
aspect:=code_to_aspect(code);
if traceSign then affiche('Signal CDF: '+intToSTR(adresse)+' '+intToSTR(code),clOrange);
if Affsignal then afficheDebug('Signal CDF: '+intToSTR(adresse)+' '+intToSTR(code),clOrange);
if (aspect=carre) then pilote_acc(adresse,2,feu) ;
if (aspect=semaphore) then pilote_acc(adresse,1,feu) ;
@@ -1452,6 +1445,14 @@ begin
if Combine<>0 then s:=s+' + '+etatSign[combine];
Affiche(s,clOrange);
end;
if AffSignal then
begin
s:='Signal LEB: ad'+IntToSTR(adr)+'='+etatSign[aspect];
//s:='Signal LEB: ad'+IntToSTR(adr)+' aspect='+intToSTR(aspect)+' combine='+intToSTR(combine);
if Combine<>0 then s:=s+' + '+etatSign[combine];
AfficheDebug(s,clOrange);
end;
Sleep(60); // si le feu se positionne à la suite d'un positionnement d'aiguillage, on peut avoir le message station occupée
if (Combine=0) then
@@ -1532,6 +1533,12 @@ begin
if Combine<>0 then s:=s+' + '+etatSign[combine];
Affiche(s,clOrange);
end;
if AffSignal then
begin
s:='Signal NMRA: ad'+IntToSTR(adresse)+'='+etatSign[aspect];
if Combine<>0 then s:=s+' + '+etatSign[combine];
AfficheDebug(s,clOrange);
end;
if combine=0 then
case (code) of
@@ -1588,7 +1595,13 @@ begin
if Combine<>0 then s:=s+' + '+etatSign[combine];
Affiche(s,clOrange);
end;
if AffSignal then
begin
s:='Signal UniSemaf: ad'+IntToSTR(adresse)+'='+etatSign[code];
if Combine<>0 then s:=s+' + '+etatSign[combine];
AfficheDebug(s,clOrange);
end;
// pour Unisemaf, la cible est définie dans le champ Unisemaf de la structure feux
modele:=feux[index].Unisemaf;
@@ -1881,6 +1894,8 @@ begin
ancien_tablo_signalCplx[adr]:=EtatSignalCplx[adr];
//if (tempo_ACC>0) then sleep(100); // les commandes entre 2 feux successives doivent être séparées au minimum de 100 ms
if traceSign then affiche('Signal LDT: '+IntToSTR(adr)+' '+intToSTR(mode)+' '+intTOSTR(codebin),clOrange);
if AffSignal then afficheDebug('Signal LDT: '+IntToSTR(adr)+' '+intToSTR(mode)+' '+intTOSTR(codebin),clOrange);
if (aspect=semaphore) or (aspect=vert) or (aspect=carre) or (aspect=jaune) then mode:=1 else mode:=2;
case mode of
@@ -1928,6 +1943,7 @@ begin
ancien_tablo_signalCplx[adresse]:=EtatSignalCplx[adresse];
aspect:=code_to_aspect(code); // transforme le motif de bits en numéro "code des aspects des signaux"
if (tracesign) then Affiche('Signal virtuel: ad'+intToSTR(adresse)+'='+etatSign[aspect],clOrange);
if AffSignal then AfficheDebug('Signal virtuel: ad'+intToSTR(adresse)+'='+etatSign[aspect],clOrange);
dessine_feu(adresse);
end;
end;
@@ -1959,6 +1975,12 @@ begin
if CombineLoc<>0 then s:=s+' + '+etatSign[combineLoc];
Affiche(s,clOrange);
end;
if AffSignal then
begin
s:='Signal bahn: ad'+IntToSTR(adresse)+'='+etatSign[aspect];
if CombineLoc<>0 then s:=s+' + '+etatSign[combineLoc];
AfficheDebug(s,clOrange);
end;
// spécifique au décodeur digital bahn:
// si le signal affichait un signal combiné, il faut éteindre le signal avec un sémaphore
// avant d'afficher le nouvel état non combiné
@@ -3017,40 +3039,8 @@ begin
// adresse ip et port de la centrale
// AfficheDet:=true;
s:=lit_ligne;
i:=pos(':',s);
if i<>0 then begin adresseIP:=copy(s,1,i-1);Delete(s,1,i);port:=StrToINT(s);end
else begin adresseIP:='0';parSocket:=false;end;
// configuration du port com
s:=lit_ligne; // COM3:57600,N,8,1,2
sa:=s;
protocole:=-1;
// supprimer la dernier paramètre
i:=pos(',',s);
if i<>0 then
begin
delete(s,1,i);
j:=i;
i:=pos(',',s);
j:=j+i;
if i<>0 then
begin
delete(s,1,i);
i:=pos(',',s);
j:=j+i;
if i<>0 then
begin
delete(s,1,i);
i:=pos(',',s);
j:=j+i;
if i<>0 then
begin
delete(s,1,i);
Val(s,protocole,erreur);
end;
end;
end;
end;
i:=pos(':',s);
if i<>0 then begin adresseIP:=copy(s,1,i-1);Delete(s,1,i);port:=StrToINT(s);end
else begin adresseIP:='0';parSocket:=false;end;
// configuration du port com
@@ -3064,14 +3054,14 @@ begin
if erreur<>0 then Affiche('Erreur temporisation entre 2 octets',clred);
// temporisation attente maximale interface
s:=lit_ligne;
s:=lit_ligne;
val(s,TimoutMaxInterface,erreur);
if erreur<>0 then Affiche('Erreur temporisation maximale interface',clred);
if erreur<>0 then Affiche('Erreur temporisation maximale interface',clred);
//entete
s:=lit_ligne;
val(s,Valeur_entete,erreur);
entete:='';
entete:='';
case Valeur_entete of
0 : begin entete:='';suffixe:='';end;
1 : begin entete:=#$FF+#$FE;suffixe:='';end;
@@ -4890,17 +4880,18 @@ end;
// transmis dans le tableau Event_det
// Variable globale: El_suivant : adresse du détecteur suivant le détecteur "actuel"
// Actuel,Suivant : nouveaux détecteurs du canton suivant
// Résultat:
// si 0 : pas de route
// si 1 : détecteur det1 non trouvé
// si 2 : détecteur det2 non trouvé
// si 3 : erreur fatale
// si 3 : erreur fatale
// si 10 : ok route trouvée
function calcul_zones_det(det1,det2 : integer) : integer;
function calcul_zones_det(det1,det2 : integer) : integer;
var
i,i1,i2,j,k,IndexBranche_det1,IndexBranche_det2,index_i1,index_i2,
branche_trouve_det1,branche_trouve_det2,Adr,AdrPrec,position,Btype,BTypePrec,
AdrFonc,TypePrec,TypeSuiv,TypeFonc,AdrSuiv : integer;
branche_trouve_det1,branche_trouve_det2,Adr,AdrPrec,position,Btype,BTypePrec,
AdrFonc,TypePrec,TypeSuiv,TypeFonc,AdrSuiv,Train_Courant : integer;
t,sortie,trouve : boolean;
s,ss : string;
@@ -4960,8 +4951,10 @@ begin
TypeSuiv:=Btype; // si aiguillage bis
//Affiche(intToSTR(adr)+'/'+intToStr(Btype),clorange);
AdrPrec:=AdrFonc;AdrFonc:=Adr;
TypePrec:=TypeFonc;TypeFonc:=typeGen;
i:=i+1;
TypePrec:=TypeFonc;TypeFonc:=typeGen;
i:=i+1;
sortie:=(Btype=1) or (Btype=4) or (i=20) or (Adr=0);
until (sortie) ; // boucle de parcours
end;
if (i=20) then
@@ -4985,8 +4978,8 @@ begin
begin
// trouvé la route si j=2 : - si j=3 : +
if (TraceListe) then AfficheDebug('Route trouvée',clyellow);
AdrSuiv:=detecteur_suivant_El(det1,1,det2,1);
AdrSuiv:=detecteur_suivant_El(det1,1,det2,1);
AdrPrec:=detecteur_suivant_El(det2,1,det1,1);
// le train vient de det1, quitte det2 et va vers Adr
@@ -5014,15 +5007,59 @@ begin
if TraceListe then AfficheDebug('route ok car '+IntToStr(AdrPrec)+'=0 à l''index '+intToSTR(i),clyellow);
Mem[AdrPrec]:=false; // inutile
//marquer l'adresse précédente comme traitée
//marquer l'adresse précédente comme traitée
event_det_tick[i].traite:=true;
if traceListe then AfficheDebug('Mise à 1 mémoire traitée pour l''index '+intToSTR(i),clyellow);
MemZone[det1,det2]:=FALSE; // efface zone précédente
MemZone[det2,AdrSuiv]:=TRUE; // valide la nouveau zone
//if N_trains=0 then inc(N_trains);
// ajouter la route dans le tableau des routes
if N_routes<2000 then inc(N_routes);
Route[N_routes].Mem1:=det2;Route[N_routes].Mem2:=AdrSuiv;
// affecter la route à un train
if N_trains=0 then N_trains:=1;
// premier train
if (N_trains=1) and (Train[1].index=0) then
begin
Train[1].index:=1;Train[1].route[1].Mem1:=det2;Train[1].route[1].Mem2:=AdrSuiv;
if traceListe then AfficheDebug('Mise à 1 mémoire traitée pour l''index '+intToSTR(i),clyellow);
MemZone[det1,det2]:=FALSE; // efface zone précédente
Train_Courant:=1;
//FormDebug.MemoDet.lines.add('Premier train');
Formprinc.LabelNbTrains.caption:='1';
end
else
begin
// parcourir les trains pour voir si det2 correspond à la derniere route du train exploré
i:=1;
repeat
j:=Train[i].index;
trouve:=Train[i].route[j].mem2=det2 ;
inc(i);
until (i>N_Trains) or trouve;
if trouve then
begin
dec(i);
//FormDebug.MemoDet.lines.add('route train '+intToSTR(i));
train_courant:=i;
inc(j);
Train[i].index:=j;Train[i].route[j].Mem1:=det2;Train[i].route[j].Mem2:=AdrSuiv;
end
else
// nouveau train
begin
//FormDebug.MemoDet.lines.add('Nouveau train');
With FormDebug.MemoDet do
begin
inc(N_Trains);
Train[N_trains].index:=1;Train[N_trains].route[1].Mem1:=det2;Train[N_trains].route[1].Mem2:=AdrSuiv;
Train_courant:=N_trains;
Formprinc.LabelNbTrains.caption:=IntToSTR(N_trains);
end;
end;
With FormDebug.RichEdit do
begin
s:='train '+IntToSTR(Train_Courant)+' '+intToStr(det1)+' à '+intToStr(det2)+' => Mem '+IntToSTR(det2)+' à '+IntTOStr(AdrSuiv);
Lines.Add(s);
RE_ColorLine(FormDebug.RichEdit,lines.count,CouleurTrain[((Train_Courant - 1) mod 8)+1 ]);
end;
@@ -5034,12 +5071,12 @@ begin
repeat
trouve:=Event_det[i]=Det1;
if not(trouve) then inc(i);
until (i>N_event_det) or trouve;
until (i>N_event_det) or trouve;
if trouve then
begin
supprime_event(i);
supprime_event(i);
if TraceListe then AfficheDebug('Efface index '+IntToSTR(i),clyellow);
end;
end;
calcul_zones_det:=10; // route trouvée et cohérente
exit;
@@ -5063,8 +5100,7 @@ var i,j,k1,k2,BtypeSuiv,Adr_det,etat,Adr,Aig,DetPrec1,DetPrec2,Detprec3,Detprec4
// mise à jour de l'état d'un feu en fontion de son environnement et affiche le feu
procedure Maj_Feu(Adrfeu : integer);
var i,j,k1,k2,BtypeSuiv,Adr_det,etat,Adr,Aig,DetPrec1,DetPrec2,Detprec3,Detprec4,Adr_El_Suiv,
Btype_el_suivant,det_initial,bt,el_suiv,modele : integer ;
var i,j,k1,k2,BtypeSuiv,Adr_det,etat,Adr,Aig,DetPrec1,DetPrec2,Detprec3,Detprec4,Adr_El_Suiv,
Btype_el_suivant,det_initial,bt,el_suiv,modele : integer ;
PresTrain,Aff_semaphore,car : boolean;
s : string;
@@ -5086,13 +5122,13 @@ begin
Signal_direction(AdrFeu);
exit;
end;
etat:=etat_signal_suivant(AdrFeu,1) ; // état du signal suivant + adresse du signal suivant dans Signal_Suivant
// signaux traités spécifiquement
if (AdrFeu=201) then
begin
//sprintf(Affiche,"Aiguille 27=%d \r\n",aiguillage[27].position);Display(Affiche);
etat:=etat_signal_suivant(AdrFeu,1) ; // état du signal suivant + adresse du signal suivant dans Signal_Suivant
// signaux traités spécifiquement
if (AdrFeu=201) then
begin
//sprintf(Affiche,"Aiguille 27=%d \r\n",aiguillage[27].position);Display(Affiche);
// sprintf(Affiche,"Aiguille 31=%d \r\n",aiguillage[31].position);Display(Affiche);
if ((aiguillage[28].position<>const_droit) and (aiguillage[29].position<>const_droit) and
(aiguillage[31].position=2)) then // attention spécial
@@ -5109,22 +5145,20 @@ begin
end;
if (Feux[i].aspect=2) then //or (feux[i].check<>nil) then // si carré violet
begin
if (Feux[i].aspect=2) then //or (feux[i].check<>nil) then // si carré violet
begin
if carre_signal(AdrFeu) and (Feux[i].aspect=2) then
begin Maj_Etat_Signal(AdrFeu,violet) ; Envoi_signauxCplx;
begin Maj_Etat_Signal(AdrFeu,violet) ; Envoi_signauxCplx;
exit;
end
else if not(carre_signal(AdrFeu)) then //ici ya pas de check and feux[i].check.checked then
begin Maj_Etat_Signal(AdrFeu,blanc);Envoi_signauxCplx;
else if not(carre_signal(AdrFeu)) then //ici ya pas de check and feux[i].check.checked then
begin Maj_Etat_Signal(AdrFeu,blanc);Envoi_signauxCplx;
exit;
end;
end;
//if AffSignal then AfficheDebug('Debut du traitement général',clYellow);
// traitement des feux >3 feux différents de violet (cas général)
if (Feux[i].aspect>=3) and (EtatSignalCplx[AdrFeu]<>violet_F) then
// traitement des feux >3 feux différents de violet (cas général)
if (Feux[i].aspect>=3) and (EtatSignalCplx[AdrFeu]<>violet_F) then
begin
// détecteurs précédent le feu , pour déterminer si leurs mémoires de zones sont à 1 pour libérer le carré
@@ -5162,7 +5196,7 @@ begin
det_initial:=feux[i].Adr_det4;Adr_El_Suiv:=feux[i].Adr_el_suiv4;
if feux[i].Btype_suiv1=1 then Btype_el_suivant:=1;
if feux[i].Btype_suiv1=2 then Btype_el_suivant:=2;
if feux[i].Btype_suiv1=5 then Btype_el_suivant:=3; // le type du feu 1=détécteur 2=aig 5=bis
if feux[i].Btype_suiv1=5 then Btype_el_suivant:=3; // le type du feu 1=détécteur 2=aig 5=bis
end;
if (det_initial<>0) then
begin
@@ -5170,7 +5204,7 @@ begin
if DetPrec1<9997 then // route bloquée par aiguillage mal positionné
begin
DetPrec2:=detecteur_suivant_El(det_initial,1,DetPrec1,1);
if DetPrec2<9997 then
if DetPrec2<9997 then
begin
DetPrec3:=detecteur_suivant_El(DetPrec1,1,DetPrec2,1);
if DetPrec3<9997 then
@@ -5180,13 +5214,13 @@ begin
PresTrain:=//MemZone[DetPrec4,detPrec3] or
MemZone[DetPrec3,detPrec2] or MemZone[DetPrec2,detPrec1] or MemZone[DetPrec1,Det_initial] or presTrain ;
// Affiche('MemZone'+intToSTR(DetPrec3)+' '+IntToSTR(detPrec2) = '+MemZone[DetPrec3,detPrec2]
end;
end;
end;
end;
end;
end;
inc(j);
until (j>=5);
if presTrain and AffSignal Then affiche('présence train feu '+intToSTR(AdrFeu),clorange);
if presTrain and AffSignal Then afficheDebug('présence train feu '+intToSTR(AdrFeu),clorange);
end;
if AffSignal then afficheDebug('Fin de la recherche des 4 détecteurs précédents-----',clOrange);
// si le signal peut afficher un carré et les aiguillages après le signal sont mal positionnées ou que pas présence train avant signal et signal
@@ -5194,13 +5228,11 @@ begin
car:=carre_signal(AdrFeu);
if AffSignal and car then AfficheDebug('le signal a des aiguilles en talon aval mal positionnées',clYellow);
if (NivDebug>=1) and car then AfficheDebug('le signal a des aiguilles en talon aval mal positionnées',clYellow);
if (Feux[i].aspect>=4) and ( (not(PresTrain) and Feux[i].VerrouCarre) or car) then Maj_Etat_Signal(AdrFeu,carre)
else
if (Feux[i].aspect>=4) and ( (not(PresTrain) and Feux[i].VerrouCarre) or car) then Maj_Etat_Signal(AdrFeu,carre)
else
begin
// si on quitte le détecteur on affiche un sémaphore : attention tester le sens de circulation
// trouver la mémoire de zone MemZone[Adr_det,?] qui a déclenché le feu rouge
if AffSignal then Affiche('test du sémaphore',clYellow);
// pour ne pas passer au rouge un feu à contresens.
// trouver la mémoire de zone MemZone[Adr_det,?] qui a déclenché le feu rouge
if AffSignal then AfficheDebug('test du sémaphore',clYellow);
Aff_semaphore:=test_memoire_zones(AdrFeu); // test si présence train après signal
@@ -5209,8 +5241,7 @@ begin
if AffSignal then AfficheDebug('train après signal-> sémaphore ou carré',clYellow);
if testBit(EtatSignalCplx[Adrfeu],carre)=FALSE then Maj_Etat_Signal(AdrFeu,semaphore);
end
else
begin
else
begin
// si aiguille locale déviée
Aig:=Aiguille_deviee(Adrfeu);
@@ -5228,8 +5259,7 @@ begin
begin
// sinon si signal suivant=jaune
if (TestBit(etat,jaune)) then Maj_Etat_Signal(AdrFeu,jaune_cli);
end;
end
end;
end
else
// aiguille locale non déviée
@@ -5251,10 +5281,10 @@ begin
end;
end
else
// si le signal suivant est jaune
// si le signal suivant est jaune
if TestBit(etat,jaune) then Maj_Etat_Signal(AdrFeu,jaune_cli)
end;
else Maj_Etat_Signal(AdrFeu,vert)
end;
end;
end;
end;
@@ -5426,6 +5456,7 @@ end;
Affiche('Demande état des aiguillages',ClYellow);
for i:=1 to maxaiguillage do
begin
demande_info_acc(i);
end;
end;
@@ -5454,6 +5485,7 @@ begin
event_det_tick[N_event_tick].suivant:=AdresseActuel;
//event_det_tick[i].train:=0; // traité
end;
end
else
if AffAffect then AfficheDebug('Pas trouvé',clyellow);
@@ -5490,7 +5522,7 @@ begin
inc(N_event_det);
event_det[N_event_det]:=Adresse;
calcul_zones; // en avant les calculs
end;
end;
// stocke les changements d'état des détecteurs dans le tableau chronologique
if (N_Event_tick<Max_Event_det_tick) then
@@ -5499,10 +5531,11 @@ begin
// event_det_tick[N_event_tick].train:=0;
event_det_tick[N_event_tick].tick:=tick;
event_det_tick[N_event_tick].detecteur[Adresse]:=etat01;
// Affiche('stockage de '+intToSTR(N_event_tick)+' à '+intToSTR(etat01),clyellow);
end;
exit;
//------------------------plus utilisé ----------------
{
// front descendant
@@ -5527,7 +5560,7 @@ begin
if AffAffect then
begin
s:='Nouveau train sur '+intToSTR(Adresse)+'='+intToSTR(N_trains);
affiche(s,clyellow);
affiche(s,clyellow);
afficheDebug(s,clyellow);
end;
event_det_tick[N_event_tick].train:=N_trains;
@@ -5537,7 +5570,7 @@ var i,index1,index2,AdresseE,Adet,det_suiv,pos,Btype,BtypeE,train1,train2,train,
end;
// évènement d'aiguillage
procedure Event_Aig(adresse : integer);
procedure Event_Aig(adresse : integer);
var i,index1,index2,AdresseE,Adet,det_suiv,pos,Btype,BtypeE,train1,train2,train,
index : integer;
trouve,trouve1,trouve2 : boolean;
@@ -5575,7 +5608,7 @@ begin
end;
if (i>20) then begin Affiche('Erreur 671',clRed);exit;end;
Affiche('le détecteur suivant sur aiguillage '+intToSTR(adresse)+' est '+intToSTR(Adet),clyellow);
// étape 2 : trouver si un train est sur le détecteur dans le tableau event_det_tick
i:=N_Event_tick;
repeat
@@ -5618,7 +5651,7 @@ begin
if trouve2 and (train2=train) then
begin
Affiche(' détecteur Adj2='+intToSTR(Adj2)+' train='+intToSTR(train),clyellow);
event_det_tick[index2].suivant:=Adet;
event_det_tick[index2].suivant:=Adet;
event_det_tick[index].suivant:=Adj1;
end;
@@ -5991,6 +6024,42 @@ begin
i:=1;
repeat
val('$'+copy(s,i,2),v,erreur);
st:=st+char(v);
inc(i,3);
until (i>=long);
HexToStr:=st;
end;
procedure deconnecte_CDM;
begin
with Formprinc do
begin
ClientSocketCDM.close;
end;
end;
{$J+}
function IsWow64Process: Boolean;
type
TIsWow64Process = function(hProcess: THandle; var Wow64Process: Boolean): Boolean; stdcall;
var
DLL: THandle;
pIsWow64Process: TIsWow64Process;
const
IsWow64: Boolean = False;
begin
IsWow64:=false;
DLL:=LoadLibrary('kernel32.dll');
if (DLL<>0) then
begin
pIsWow64Process:=GetProcAddress(DLL,'IsWow64Process');
if (Assigned(pIsWow64Process)) then
begin
pIsWow64Process(GetCurrentProcess,IsWow64);
end;
FreeLibrary(DLL);
end;
Result:=IsWow64;
@@ -6043,79 +6112,6 @@ begin
DeConnecterCDMRail.enabled:=false;
end;
end
else
begin
Affiche('port COM'+intToSTR(NumPort)+' NON ouvert',clRed) ;
end;
end;
procedure deconnecte_CDM;
begin
with Formprinc do
begin
ClientSocketCDM.close;
end;
end;
procedure connecte_CDM;
var s : string;
begin
// Initialisation de la comm socket CDM
if CDM_connecte then begin Affiche('CDM déja connecté',Cyan);exit;end;
if AdresseIPCDM<>'0' then
begin
with Formprinc do
begin
ClientSocketCDM.port:=portCDM;
ClientSocketCDM.Address:=AdresseIPCDM;
ClientSocketCDM.Open;
end;
tempo(5);
// connexion à CDM rail
s:='C-C-00-0001-CMDGEN-_CNCT|000|';
envoi_cdm(s);
if pos('_ACK',recuCDM)<>0 then
begin
CDM_connecte:=True;
Id_CDM:=copy(recuCDM,5,2); // récupère l'ID reçu de CDM, à utiliser dans toutes les futures trames
s:='Connecté au serveur CDM rail avec l''ID='+Id_CDM;
Affiche(s,clYellow);
AfficheDebug(s,clyellow);
// demande des services : ATNT=aiguillages, ADET=détecteurs AACT=actionneurs
s:=place_id('C-C-00-0002-RQSERV-RTSIM|030|03|SRV=ATNT;SRV=ADET;SRV=AACT;');
envoi_CDM(s);
if pos('_ACK',recuCDM)<>0 then Affiche('Services acceptés: aiguillages - détecteurs - actionneurs',clYellow);
// demande les trains
////s:=place_id('C-C-01-0002-DSCTRN-DLOAD|000|');
//envoi_CDM(s);
end;
end
else
begin
Affiche('La connexion à CDM n''est pas demandée car l''adresse IP est nulle dans config.cfg',cyan);
end;
end;
{$J+}
function IsWow64Process: Boolean;
type
TIsWow64Process = function(hProcess: THandle; var Wow64Process: Boolean): Boolean; stdcall;
var
DLL: THandle;
pIsWow64Process: TIsWow64Process;
const
IsWow64: Boolean = False;
begin
IsWow64:=false;
DLL:=LoadLibrary('kernel32.dll');
if (DLL<>0) then
begin
pIsWow64Process:=GetProcAddress(DLL,'IsWow64Process');
if (Assigned(pIsWow64Process)) then
begin
pIsWow64Process(GetCurrentProcess,IsWow64);
end;
else
begin
Affiche('port COM'+intToSTR(NumPort)+' NON ouvert',clRed) ;
@@ -6129,6 +6125,11 @@ begin
s,s2,Url,LocalFile : string;
trouve,AvecMaj : Boolean;
V_utile,V_publie : real;
begin
//AvecMaj:=false;
TraceSign:=True;
AF:='Client TCP-IP CDM Rail ou USB - système LENZ - Version '+Version;
Caption:=AF;
Application.onHint:=doHint;
// version d'OS pour info
@@ -6145,25 +6146,22 @@ begin
N_Trains:=0;
NivDebug:=0;
DebugOuv:=True;
//LireunaccessoireversunfichierdeCV1.Visible:=false;
AvecInit:=true; //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
AvecTCO:=false;
EditNbTrains.Text:=IntToSTR(N_Trains);
// créée la fenetre vérification de version
AvecInit:=true; //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
AvecTCO:=false;
// créée la fenetre vérification de version
FormVersion:=TformVersion.Create(Self);
ferme:=false;
CDM_connecte:=false;
pasreponse:=0;
Nbre_recu_cdm:=0;
AffMem:=true;
pasreponse:=0;
N_routes:=0;
N_trains:=0;
Train[1].index:=0;
@@ -6172,9 +6170,11 @@ begin
// TCO
if avectco then
begin
//créée la fenêtre TCO
FormTCO:=TformTCO.Create(Self);
FormTCO:=TformTCO.Create(Self);
FormTCO.show;
construit_TCO;
affiche_TCO;
//Formprinc.Hide;
end;
@@ -6197,7 +6197,7 @@ begin
if AdresseIP<>'0' then
begin
Affiche('demande connexion à la centrale Lenz par Ethernet',clyellow);
ClientSocketLenz.port:=port;
ClientSocketLenz.port:=port;
ClientSocketLenz.Address:=AdresseIP;
ClientSocketLenz.Open;
end
@@ -6278,7 +6278,7 @@ begin
//NivDebug:=3;
//test_memoire_zones(218);
//Det_Adj(520);
//Affiche(' Adj1='+intToStr(Adj1)+' Adj2='+intToStr(Adj2),clyellow);
//Affiche(' Adj1='+intToStr(Adj1)+' Adj2='+intToStr(Adj2),clyellow);
//trace:=true;
//TraceListe:=true;
@@ -6554,16 +6554,29 @@ begin
Affiche('En jaune : rétrosignalisation reçue depuis l''interface',ClWhite);
end;
procedure TFormPrinc.MenuConnecterUSBClick(Sender: TObject);
procedure TFormPrinc.MenuConnecterUSBClick(Sender: TObject);
begin
Hors_tension2:=false;
connecte_USB;
connecte_USB;
end;
procedure deconnecte_usb;
begin
Ferme:=true;
if portCommOuvert then
procedure TFormPrinc.DeconnecterUSBClick(Sender: TObject);
begin
Ferme:=true;
if portCommOuvert then begin portCommOuvert:=false;MSCommUSBLenz.Portopen:=false; end;
begin
portCommOuvert:=false;
Formprinc.MSCommUSBLenz.Portopen:=false;
end;
portCommOuvert:=false;
with formprinc do
begin
ClientSocketLenz.close;
MenuConnecterUSB.enabled:=true;
DeConnecterUSB.enabled:=false;
ConnecterCDMRail.enabled:=true;
DeConnecterCDMRail.enabled:=false;
end;
end;
@@ -6691,7 +6704,7 @@ end;
ButtonEcrCV.Enabled:=true;
LireunfichierdeCV1.enabled:=true;
LireunaccessoireversunfichierdeCV1.Enabled:=true;
LabelTitre.caption:=titre+' Interface connectée par Ethernet';
LabelTitre.caption:=titre+' Interface connectée par Ethernet';
end;
procedure TFormPrinc.ClientSocketCDMConnect(Sender: TObject;Socket: TCustomWinSocket);
@@ -6711,7 +6724,7 @@ begin
// réception d'un message de CDM rail
procedure TFormPrinc.ClientSocketCDMRead(Sender: TObject;Socket: TCustomWinSocket);
var i,j,k,erreur, adr,adr2,etat,etataig : integer ;
s,ss : string;
s,ss : string;
traite,sort : boolean;
begin
inc(Nbre_recu_cdm);
@@ -6765,7 +6778,7 @@ begin
j:=pos('CMDACC-ST_DT',recuCDM);
if j<>0 then
begin
i:=posEx('AD=',recuCDM,j);ss:=copy(recuCDM,i+3,10);
i:=posEx('AD=',recuCDM,j);ss:=copy(recuCDM,i+3,10);
val(ss,adr,erreur);
i:=posEx('STATE=',recuCDM,j);ss:=copy(recuCDM,i+6,10);
Delete(recuCDM,j,i+5-j);
@@ -6860,6 +6873,8 @@ begin
Affiche('Version 1.02 : vérification automatique des versions',clLime);
Affiche('Version 1.1 : gestion des tableaux indicateurs de direction',clLime);
Affiche(' gestion du décodeur de signaux Unisemaf Paco (expérimental)',clLime);
Affiche(' changement dynamique des feux en cliquant sur son image',clLime);
Affiche('Version 1.11 : compatibilité pour la rétrosignalisation non XpressNet (intellibox)',clLime);
Affiche(' verrouillages routes pour trains consécutifs',clLime);
Affiche('Version 1.2 : Renforcement de l''algorithme de suivi des trains',clLime);
Affiche('Version 1.3 : Décodeur Unisemaf fonctionnel - Lecture/écriture des CV',clLime);
@@ -6883,7 +6898,7 @@ begin
begin
s:=IntToSTR(i)+' Tick='+IntToSTR(event_det_tick[i].tick)+' Det=';
trouve:=false;
for j:=1 to 1100 do
for j:=1 to 1100 do
begin
etat:=event_det_tick[i].detecteur[j];
if etat<>-1 then
@@ -6894,15 +6909,6 @@ begin
trouve:=true;
end;
end;
if trouve then Affiche(s,clyellow);
end;
end;
procedure TFormPrinc.EditNbTrainsKeyPress(Sender: TObject; var Key: Char);
begin
if ord(Key) = VK_RETURN then
end;
if trouve then Affiche(s,clyellow);
end;
@@ -7086,5 +7092,13 @@ begin
end;
procedure TFormPrinc.Button2Click(Sender: TObject);
begin
if MSCommUSBLenz.CTSHolding=true then Affiche('CTS=1',Clyellow)
else Affiche('CTS=0',clyellow);
end;
procedure TFormPrinc.ConfigClick(Sender: TObject);
begin
Tformconfig.create(self);
formconfig.showmodal;