This commit is contained in:
f1iwq2
2020-12-23 12:12:19 +01:00
parent 77b55f6aee
commit db036a7bd8
16 changed files with 1434 additions and 2764 deletions

View File

@@ -20,7 +20,6 @@ uses
type
TFormPrinc = class(TForm)
ListBox1: TListBox;
Timer1: TTimer;
LabelTitre: TLabel;
ScrollBox1: TScrollBox;
@@ -91,6 +90,10 @@ type
ButtonLanceCDM: TButton;
Affichefentredebug1: TMenuItem;
StaticText: TStaticText;
FenRich: TRichEdit;
PopupMenuFenRich: TPopupMenu;
Copier1: TMenuItem;
Etatdessignaux1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure MSCommUSBLenzComm(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
@@ -98,8 +101,6 @@ type
procedure BoutVersionClick(Sender: TObject);
procedure ButtonCommandeClick(Sender: TObject);
procedure EditvalEnter(Sender: TObject);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure BoutonRafClick(Sender: TObject);
procedure ClientSocketLenzError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
@@ -143,7 +144,9 @@ type
procedure ButtonAffTCOClick(Sender: TObject);
procedure ButtonLanceCDMClick(Sender: TObject);
procedure Affichefentredebug1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FenRichChange(Sender: TObject);
procedure Copier1Click(Sender: TObject);
procedure Etatdessignaux1Click(Sender: TObject);
private
{ Déclarations privées }
procedure DoHint(Sender : Tobject);
@@ -236,7 +239,7 @@ var
branche : array [1..100] of string;
FormPrinc: TFormPrinc;
ack,portCommOuvert,trace,AffMem,AfficheDet,CDM_connecte,SocketCDM_connecte,
ack,portCommOuvert,traceTrames,AffMem,AfficheDet,CDM_connecte,SocketCDM_connecte,
Raz_Acc_signaux,AvecInit,AvecTCO,terminal,Srvc_Aig,Srvc_Det,Srvc_Act,
Srvc_PosTrain,Srvc_Sig,debugtrames : boolean;
tablo : array of byte; // tableau rx usb
@@ -414,10 +417,8 @@ begin
begin
brush.Color:=couleur;
Pen.Color:=clBlack;
//Affiche('clignote '+IntToSTR(x)+' '+intToSTR(y),clyellow);
Ellipse(x-rayon,y-rayon,x+rayon,y+rayon);
end;
//Affiche(IntToSTR(y),clyellow);
end;
// dessine les feux sur une cible à 2 feux dans le canvas spécifié
@@ -1045,7 +1046,7 @@ begin
cercle(ACanvas,12,13,6,GrisF);
cercle(ACanvas,25,13,6,GrisF);
end;
if EtatSignal=1 then
if EtatSignal=1 then
begin
cercle(ACanvas,12,13,6,clWhite);
cercle(ACanvas,25,13,6,GrisF);
@@ -1058,19 +1059,18 @@ begin
end;
// affiche un texte dans la fenêtre
procedure Affiche(s : string;lacouleur : TColor);
begin
couleur:=lacouleur;
with formprinc.ListBox1 do
with formprinc do
begin
Items.addObject(s,pointer(lacouleur));
TopIndex:= Items.Count - 1;
FenRich.lines.add(s);
RE_ColorLine(FenRich,FenRich.lines.count-1,lacouleur);
//FenRich.SetFocus;
//FenRich.SelStart := FenRich.GetTextLen;
//FenRich.Perform(EM_SCROLLCARET, 0, 0);
end;
end;
// renvoie l'index du feu dans le tableau feux[] en fonction de son adresse
//si pas de feu renvoie 0
function Index_feu(adresse : integer) : integer;
@@ -1265,7 +1265,7 @@ end;
// Affiche une chaîne en Hexa Ascii
procedure affiche_chaine_hex(s : string;couleur : Tcolor);
begin
if trace then Affiche(chaine_HEX(s),couleur);
if traceTrames then AfficheDebug(chaine_HEX(s),couleur);
end;
// temporisation en x 100 ms (0,1 s)
@@ -1285,7 +1285,7 @@ var i,timeout,valto : integer;
begin
// com:=formprinc.MSCommUSBLenz;
s:=entete+s+suffixe;
if Trace then Affiche('Tick='+IntToSTR(tick)+'/Env '+chaine_Hex(s),ClGreen);
if traceTrames then AfficheDebug('Tick='+IntToSTR(tick)+'/Env '+chaine_Hex(s),ClGreen);
// par port com-usb
if portCommOuvert then
@@ -3570,10 +3570,9 @@ begin
//affiche(s,cllime);
sa:=uppercase(Fonte_ch)+'=';
i:=pos(sa,s);
if i<>0 then
if i<>0 then
begin
inc(nv);
trouve_fonte:=true;
inc(nv);
trouve_fonte:=true;
delete(s,i,length(sa));
TailleFonte:=StrToINT(s);
@@ -4041,8 +4040,7 @@ begin
Affiche('définition des branches',clyellow);
// branches de réseau
NDetecteurs:=0; Nligne:=1;
i:=1;i_detect:=1;
NDetecteurs:=0; Nligne:=1;
i:=1;i_detect:=1;
repeat
s:=lit_ligne;
@@ -4077,6 +4075,7 @@ begin
end
else erreur:=0; // forcer erreur à 0 pour obliger à passer sur un détecteur
end;
// détecteur
if erreur=0 then
begin
@@ -5239,7 +5238,8 @@ end;
trouve:=trouve1 or trouve2 or trouve3 or trouve4;
if not(trouve) then inc(i);
until (trouve) or (i>=100);
if trouve then Index_feu_det:=i else Index_feu_det:=0;
if trouve then Index_feu_det:=i else Index_feu_det:=0;
end;
// renvoie l'adresse du détecteur suivant des deux éléments contigus
@@ -5253,7 +5253,7 @@ begin
j:=0;
PrecCalc:=prec;
TypeprecCalc:=TypeElprec;
TypeprecCalc:=TypeElprec;
ActuelCalc:=actuel;
TypeActuelCalc:=TypeELActuel;
// étape 1 trouver le sens
@@ -5270,6 +5270,7 @@ begin
actuelCalc:=aiguillage[ActuelCalc].APointe;
end;
end;
precCalc:=actuelCalc;
TypeprecCalc:=TypeActuelCalc;
actuelCalc:=AdrSuiv;
TypeActuelCalc:=typeGen;
@@ -5398,7 +5399,7 @@ begin
// étape 1 : trouver le sens de progression (en incrément ou en décrément)
repeat
//préparer les variables
//préparer les variables
AdrPrec:=el1;TypePrec:=typeDet1;
if j=1 then i1:=IndexBranche_det1+1;
if j=2 then i1:=IndexBranche_det1-1;
@@ -5434,7 +5435,7 @@ begin
AfficheDebug(s,clorange);
end;
AdrPrec:=AdrFonc;TypePrec:=TypeFonc;
AdrPrec:=AdrFonc;TypePrec:=TypeFonc;
AdrFonc:=Adr;TypeFonc:=typeGen;
inc(i);
sortie:=((typeDet2=TypeGen) and (Adr=el2)) or (Adr=0) or (Adr>=9996) or (i=15) or (N_Det=Nb_det_dist);
@@ -5443,7 +5444,7 @@ begin
if (N_det=Nb_det_dist) and (Nivdebug=3) then afficheDebug('Détecteurs trop distants',clred);
end
else
else
begin
// déja trouvé
adr:=el2;typeGen:=TypeDet2;
@@ -5458,6 +5459,7 @@ begin
Adr:=suivant_alg3(AdrPrec,TypePrec,AdrFonc,TypeFonc,1);
//AfficheDebug('Sortie Alg3: '+IntToSTR(Adr)+'/'+intToSTR(typeGen),clyellow);
if NivDebug=3 then
begin
s:='614 : trouvé='+intToSTR(Adr);
case typeGen of
@@ -5468,7 +5470,7 @@ begin
AfficheDebug(s,clorange);
end;
AdrPrec:=AdrFonc;TypePrec:=TypeFonc;
AdrPrec:=AdrFonc;TypePrec:=TypeFonc;
AdrFonc:=Adr;TypeFonc:=typeGen;
inc(i);
sortie:=(TypeGen=1) or (Adr=0) or (Adr>=9996) or (i=10);
@@ -5482,7 +5484,7 @@ begin
affichedebug('------------------',clyellow);
end;
detecteur_suivant_el:=Adr;
exit;
exit;
end;
end;
if (i=10) then if NivDebug=3 then AfficheDebug('201 : Itération trop longue',clred);
@@ -5866,7 +5868,7 @@ begin
Affiche('Erreur 650 - feu non trouvé',clred);
AfficheDebug('Erreur 650 - feu non trouvé',clred);
test_memoire_zones:=false;
end;
end;
Pres_train:=FALSE;
ife:=1; // index feu de 1 à 4 pour explorer les 4 détecteurs d'un feu
@@ -5934,7 +5936,7 @@ begin
prec:=actuel;TypePrec:=TypeActuel;
actuel:=AdrSuiv;TypeActuel:=typeGen;
if AdrSuiv>9990 then
begin
begin
test_memoire_zones:=false;exit;
end;
@@ -6072,13 +6074,13 @@ begin
begin
test_route_valide:=0;exit;
// si manipulation proche aiguillage
det_suiv:=detecteur_suivant_el(det3,1,det2,1);
if (det_suiv>=9996) or (det1<>det_suiv) then begin test_route_valide:=0; NivDebug:=0;exit;end;
end;
test_route_valide:=10 ;
end;
// présence train 3 détecteurs avant le feu
// présence train 3 détecteurs avant le feu
function PresTrainPrec(AdrFeu : integer) : boolean;
var PresTrain : boolean;
@@ -6104,27 +6106,27 @@ begin
begin
det_initial:=feux[i].Adr_det1;Adr_El_Suiv:=feux[i].Adr_el_suiv1;
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=4 then Btype_el_suivant:=2; // BType_suiv: 1=détecteur 2=aig ou TJD ou TJS 4=tri
end; // Btye_el_suivant: 1= détecteur 2= aiguillage 4=Buttoir
if feux[i].Btype_suiv1=2 then Btype_el_suivant:=2;
if feux[i].Btype_suiv1=4 then Btype_el_suivant:=2; // BType_suiv: 1=détecteur 2=aig ou TJD ou TJS 4=tri
end; // Btye_el_suivant: 1= détecteur 2= aiguillage 4=Buttoir
if (j=2) then
begin
det_initial:=feux[i].Adr_det2;Adr_El_Suiv:=feux[i].Adr_el_suiv2;
if feux[i].Btype_suiv2=1 then Btype_el_suivant:=1;
if feux[i].Btype_suiv1=2 then Btype_el_suivant:=2;
if feux[i].Btype_suiv1=4 then Btype_el_suivant:=2;
end;
if feux[i].Btype_suiv2=2 then Btype_el_suivant:=2;
if feux[i].Btype_suiv2=4 then Btype_el_suivant:=2;
end;
if (j=3) then
begin
det_initial:=feux[i].Adr_det3;Adr_El_Suiv:=feux[i].Adr_el_suiv3;
if feux[i].Btype_suiv3=1 then Btype_el_suivant:=1;
if feux[i].Btype_suiv1=2 then Btype_el_suivant:=2;
if feux[i].Btype_suiv1=4 then Btype_el_suivant:=2;
end;
if feux[i].Btype_suiv3=2 then Btype_el_suivant:=2;
if feux[i].Btype_suiv3=4 then Btype_el_suivant:=2;
end;
if (j=4) then
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_suiv4=1 then Btype_el_suivant:=1;
if feux[i].Btype_suiv4=2 then Btype_el_suivant:=2;
if feux[i].Btype_suiv4=4 then Btype_el_suivant:=2;
end;
@@ -6295,6 +6297,8 @@ begin
// sinon si signal suivant=jaune
if (TestBit(etat,jaune)) then Maj_Etat_Signal(AdrFeu,jaune_cli);
end;
end
else
// aiguille locale non déviée ou aspect feu<9
// si le signal suivant est rouge
begin
@@ -6505,7 +6509,7 @@ begin
// vérifier si le détecteur du nouveau train est associé à un feu vers un buttoir
for i:=1 to NbreFeux do
begin
begin
AdrFeu:=Feux[i].Adresse;
AdrDetfeu:=Feux[i].Adr_Det1;
if (AdrDetFeu=Det3) and (feux[i].aspect<10) then
@@ -6726,7 +6730,7 @@ begin
// sur le détecteur
for i:=1 to NbreFeux do
begin
AdrFeu:=Feux[i].Adresse;
AdrFeu:=Feux[i].Adresse;
AdrDetfeu:=Feux[i].Adr_Det1;
if (AdrDetFeu=Adresse) and (feux[i].aspect<10) then
begin
@@ -6885,22 +6889,22 @@ begin
end;
// état de l'aiguillage
if bitsITT=$00 then // module d'aiguillages, N=1
if bitsITT=$00 then // module d'aiguillages, N=1
begin
adraig:=((adresse * 4)+1 ); // *4 car N=1, c'est le "poids fort"
if (valeur and $C)=$8 then
begin
Event_Aig(adraig+3,const_droit,0);
Event_Aig(adraig+3,const_droit,0);
if traceTrames then begin s:='accessoire '+intToSTR(adraig+3)+'=2';AfficheDebug(s,clYellow);end;
end;
if (valeur and $C)=$4 then
begin
Event_Aig(adraig+3,const_devie,0);
Event_Aig(adraig+3,const_devie,0);
if traceTrames then begin s:='accessoire '+intToSTR(adraig+3)+'=1';AfficheDebug(s,clYellow);end;
end;
if (valeur and $3)=$2 then
begin
Event_Aig(adraig+2,const_droit,0);
Event_Aig(adraig+2,const_droit,0);
if traceTrames then begin s:='accessoire '+intToSTR(adraig+2)+'=2';AfficheDebug(s,clYellow);end;
end;
if (valeur and $3)=$1 then
@@ -6941,22 +6945,22 @@ begin
end;
end;
if bitsITT=$00 then // module d'aiguillages
if bitsITT=$00 then // module d'aiguillages
begin
adraig:=(adresse * 4)+1;
if (valeur and $C)=$8 then
begin
Event_Aig(adraig+1,const_droit,0);
Event_Aig(adraig+1,const_droit,0);
if traceTrames then begin s:='accessoire '+intToSTR(adraig+1)+'=2';AfficheDebug(s,clYellow);end;
end;
if (valeur and $C)=$4 then
begin
Event_Aig(adraig+1,const_devie,0);
Event_Aig(adraig+1,const_devie,0);
if traceTrames then begin s:='accessoire '+intToSTR(adraig+1)+'=1';AfficheDebug(s,clYellow);end;
end;
if (valeur and $3)=$2 then
begin
Event_Aig(adraig,const_droit,0);
Event_Aig(adraig,const_droit,0);
if traceTrames then begin s:='accessoire '+intToSTR(adraig)+'=2';AfficheDebug(s,clYellow);end;
end;
if (valeur and $3)=$1 then
@@ -6982,8 +6986,8 @@ begin
begin
case chaineINT[2] of // page 13 doc XpressNet
#1 : begin nack:=true;msg:='erreur timout transmission';end;
#2 : begin nack:=true;msg:='erreur timout centrale';end;
#3 : begin nack:=true;msg:='erreur communication inconnue';end;
#2 : begin nack:=true;msg:='erreur timout centrale';end;
#3 : begin nack:=true;msg:='erreur communication inconnue';end;
#4 : begin succes:=true;msg:='succès';end;
#5 : begin nack:=true;msg:='plus de time slot';end;
#6 : begin nack:=true;msg:='débordement tampon LI100';end;
@@ -7682,7 +7686,7 @@ begin
var i : integer;
begin
if MSCommUSBLenz.commEvent=comEvReceive then
begin
begin
tablo:=MSCommUSBLenz.Input;
for i:=0 to length(tablo)-1 do
begin
@@ -7946,17 +7950,6 @@ begin
pilote_acc(adr,valeur,aig);
end;
procedure TFormPrinc.EditvalEnter(Sender: TObject);
begin
if (Editval.Text<>'1') and (Editval.Text<>'2') then editval.text:='1';
end;
// gestion de la couleur des textes de la list box
procedure TFormPrinc.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
//with control as Tlistbox do
procedure TFormPrinc.EditvalEnter(Sender: TObject);
begin
@@ -8010,7 +8003,7 @@ procedure TFormPrinc.ClientSocketLenzRead(Sender: TObject;
ErrorCode:=0;
end;
// lecture depuis socket
// lecture depuis socket
procedure TFormPrinc.ClientSocketLenzRead(Sender: TObject;
Socket: TCustomWinSocket);
var s : string;
@@ -8035,7 +8028,6 @@ begin
procedure TFormPrinc.ButtonInfoClick(Sender: TObject);
begin
begin
Affiche('Ce programme pilote des signaux complexes de façon autonome ou avec CDM rail ',ClYellow);
Affiche('En fonction des détecteurs mis à 1 ou 0 par des locomotives',ClYellow);
@@ -8078,6 +8070,7 @@ procedure TFormPrinc.MenuConnecterEthernetClick(Sender: TObject);
procedure TFormPrinc.DeconnecterUSBClick(Sender: TObject);
begin
deconnecte_usb;
end;
procedure TFormPrinc.MenuConnecterEthernetClick(Sender: TObject);
begin
@@ -8484,20 +8477,19 @@ begin
// réception d'un message de CDM rail
procedure TFormPrinc.ClientSocketCDMRead(Sender: TObject;Socket: TCustomWinSocket);
var i,l,n : integer ;
s,ss,train : string;
s,ss,train : string;
traite,sort : boolean;
begin
inc(Nbre_recu_cdm);
begin
inc(Nbre_recu_cdm);
//if Nbre_recu_cdm>1 then Affiche('Empilement de trames CDM: '+intToSTR(Nbre_recu_cdm),clred);
recuCDM:=ClientSocketCDM.Socket.ReceiveText; // commandeCDM est le morceau tronquée de la fin de la réception précédente
recuCDM:=ClientSocketCDM.Socket.ReceiveText; // commandeCDM est le morceau tronquée de la fin de la réception précédente
//if residuCDM<>'' then Affiche(recuCDM,clLime);
if trace then
residuCDM:='';
if traceTrames then AfficheDebug(recuCDM,clWhite);
n:=80;
{begin
n:=80;
l:=length(recuCDM);
l:=length(recuCDM);
i:=0;
repeat
AfficheDebug(copy(recuCDM,(i*n)+1,n),clWhite);
@@ -8881,17 +8873,38 @@ begin
end;
procedure TFormPrinc.locoClick(Sender: TObject);
begin
// vitesse et direction 18 pas
begin
// vitesse et direction 18 pas
vitesse_loco(3,20,true);
vitesse_loco(3,20,true);
end;
// pour déplacer l'ascenseur de l'affichage automatiquement en bas
procedure TFormPrinc.FenRichChange(Sender: TObject);
begin
SendMessage(FenRich.handle, WM_VSCROLL, SB_BOTTOM, 0);
end;
procedure TFormPrinc.Copier1Click(Sender: TObject);
begin
FenRich.CopyToClipboard;
FenRich.SetFocus;
end;
procedure TFormPrinc.Etatdessignaux1Click(Sender: TObject);
var Adr,etat,i : integer;
aspect,combine : word;
s : string;
begin
for i:=1 to NbreFeux do
begin
Adr:=Feux[i].Adresse;
Etat:=Feux[i].EtatSignal;
s:='Feu '+IntToSTR(Adr)+' Etat=';
code_to_aspect(Etat,aspect,combine);
end;
s:=s+IntToSTR(etat)+'='+EtatSign[aspect]+' '+EtatSign[combine];
Affiche(s,clYellow);
end;