-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEEP_blockControl.html
682 lines (597 loc) · 25.7 KB
/
EEP_blockControl.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
<!DOCTYPE html>
<html lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<META http-equiv="Content-Script-Type" content="text/javascript">
<title>Lua Modul blockControl</title>
<meta name="description" content="Dieses Programm generiert die erforderlichen Daten für das Lua Modul 'blockControl'">
<meta name="author" content="Frank Buchholz">
<meta name="keywords" content="EEP,.anl3,blockControl" />
<meta name="language" content="de" />
<link rel="icon" href="https://www.eepforum.de/images/favicon.ico" type="image/x-icon">
<script type="text/javascript" src="js/EEP_Texts.js"></script> <!-- Load texts and translations -->
<link rel="stylesheet" href="css/EEP_Texts.css">
<script type="text/javascript" src="js/EEP_Signale_Daten.js"></script> <!-- Lade Zusatzdaten zu Signalen: Name, Signalstellungen -->
</head>
<body>
<main>
<header>
<h3><span lang="de">EEP-Modul 'blockControl'</span><span lang="en">EEP module 'blockControl'</span><span lang="fr">EEP module 'blockControl'</span></h3>
</header>
<article>
<p><span lang="de">Daten für das Lua-Modul "blockControl" erstellen.</span><span lang="en">Create data for Lua module "blockControl".</span><span lang="fr">Créez des données pour le module Lua "blockControl".</span></p>
<ol>
<li><span lang="de">Öffnen Sie das EEP-Layout im 'Gleisplan'-Programm in einem anderen Fenster oder Tab desselben Browsers.</span><span lang="en">Open the EEP layout in the 'Gleisplan' program in another windor or tab of the same browser.</span><span lang="fr">Ouvrez la mise en page EEP dans le programme 'Gleisplan' dans un autre volet ou onglet du même navigateur.</span></li>
<li><span lang="de">Generieren Sie die Daten.</span><span lang="en">Generate the data.</span><span lang="fr">Générez les données.</span></li>
</ol>
<form id="form">
<table>
<tr><td><span lang="de">Gleissystem</span><span lang="en">Track system</span><span lang="fr">Système de voies</span>:</td>
<td><label><input type="radio" name="GleissystemID" value="1" checked><span lang="de">Eisenbahn</span><span lang="en">Railroad</span><span lang="fr">Ferroviaire</span></label>
<label><input type="radio" name="GleissystemID" value="2"><span lang="de">Straßenbahn</span><span lang="en">Tram</span><span lang="fr">Tram</span></label>
<label><input type="radio" name="GleissystemID" value="3"><span lang="de">Straße</span><span lang="en">Road</span><span lang="fr">Routière</span></label>
<label><input type="radio" name="GleissystemID" value="4"><span lang="de">Wasserwege</span><span lang="en">Waterways</span><span lang="fr">Navigable</span></label>
<label><input type="radio" name="GleissystemID" value="5"><span lang="de">Steuerstrecken</span><span lang="en">Control routes</span><span lang="fr">Itinéraires de contrôle</span></label>
<!-- <label><input type="radio" name="GleissystemID" value="6"><span lang="de">GBS</span><span lang="en">GBS</span><span lang="fr">GBS</span></label> -->
</td></tr>
<tr><td><label><span lang="de">Block-Signale (optional)</span><span lang="en">Block signals (optional)</span><span lang="fr">Block-Signale (optional)</span>:</td>
<td><input id="blockSignalsString" type="text" size="70">
<span lang="de">Nur diese Signale werden als Block-Signale verwendet (leer: alle)</span><span lang="en">Only these signals are used as block signals (blank: all)</span><span lang="fr">Seuls ces signaux sont utilisés comme signaux de bloc (vide : tous)</span>
</td></label></tr>
<tr><label><td><span lang="de">Andere Signale (optional)</span><span lang="en">Other signals (optional)</span><span lang="fr">Block-Signale (optional)</span>:</td>
<td><input id="otherSignalsString" type="text" size="70">
<span lang="de">Diese Signale werden nicht als Block-Signale verwendet (leer: keine)</span><span lang="en">These signals are not used as block signals (blank: none)</span><span lang="fr">Ces signaux ne sont pas utilisés comme signaux de bloc (vide : aucun)</span>
</td></label></tr>
<tr><label><td><span lang="de">Max. Anzahl der Weichen</span><span lang="en">Max. count of turnouts</span><span lang="fr">Max. nombre de aiguillages</span>:</td>
<td><input id="maxTurnouts" type="number" value="30"></td></label></tr>
<tr><label><td><span lang="de">Gleisdaten der Blocks</span><span lang="en">Track data of blocks</span><span lang="fr">Données ferroviaires des cantons</span>:</td>
<td><input id="trackdata" type="checkbox"></td></label></tr>
<tr><label><td><span lang="de">Erweiterte Daten</span><span lang="en">Extended data</span><span lang="fr">Données étendues</span>:</td>
<td><input id="extended" type="checkbox"></td></label></tr>
</table>
<br>
<button type="submit"><span lang="de">Generieren</span><span lang="en">Generate</span><span lang="fr">Générer</span></button>
</form>
</article>
<section>
<p id="msg"></p>
<pre id="data"></pre>
</section>
<script type="text/javascript"> // Create data for Lua module "blockControl"
"use strict";
// Initialization: Connection to a broadcast channel
// https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API
const blockControlChannel = new BroadcastChannel("blockControl");
function TrackSystemText(GleissystemID) {
const TrackSystemTexts = {
1 : _('Eisenbahn'),
2 : _('Strassenbahn'),
3 : _('Strasse'),
4 : _('Wasserwege'),
5 : _('Steuerstrecken'), // nicht in EEP 9
6 : _('GBS'), // nicht in EEP 9
};
return TrackSystemTexts[GleissystemID];
}
function calculate(event) {
event.preventDefault();
const msg = document.getElementById('msg');
msg.textContent = "";
const data = document.getElementById('data');
data.textContent = `Request Submitted! Time stamp: ${event.timeStamp.toFixed(2)}`;
const GleissystemID = form.querySelector('input[name="GleissystemID"]:checked').value;
const blockSignalsStrings = document.getElementById('blockSignalsString').value.match(/\d+/g);
const blockSignals = (blockSignalsStrings ? blockSignalsStrings.map(Number) : null);
const otherSignalsStrings = document.getElementById('otherSignalsString').value.match(/\d+/g);
const otherSignals = (otherSignalsStrings ? otherSignalsStrings.map(Number) : null);
const maxTurnouts = +document.getElementById('maxTurnouts').value;
// Send request to calculate data
blockControlChannel.postMessage({
command : "calculate",
GleissystemID : GleissystemID,
blockSignals : blockSignals,
otherSignals : otherSignals,
maxTurnouts : maxTurnouts,
maxTracks : 1000,
});
}
const form = document.getElementById('form');
form.addEventListener('submit', calculate);
// Initialization: Connection to a broadcast channel
const EEPchannel = new BroadcastChannel('EEP');
function postIDMessage(ID, GleissystemID, GleisID) { // Signal oder Weiche
EEPchannel.postMessage({
command: "showID",
ID: ID,
/*
GleissystemID: GleissystemID,
GleisID: GleisID,
shiftDown: global.shiftDown,
strgDown: global.strgDown,
altDown: global.altDown,
*/
});
}
function _id (ID) {
if (ID > 0) {
return `<a href="javascript:void(0);" onclick="javascript:postIDMessage(${ID});">`
+ ID
+ `<\/a>`;
} else {
return ID;
}
}
function getSignalPositionText (File, Position) {
let Text = '';
if (!Signalstellung[File]) {
// no text
} else if (typeof(Signalstellung[File].Pos[Position]) === "string") {
Text = Signalstellung[File].Pos[Position];
} else if (typeof(Signalstellung[File].Pos[Position]) === "object") {
Text = Signalstellung[File].Pos[Position][EEP_Texts.getLanguage()]
|| Signalstellung[File].Pos[Position].DE // primary language
|| Signalstellung[File].Pos[Position].EN // secondary language
;
} else {
// no text
}
// Default translations
if (Text === "Fahrt") { Text = _("Fahrt") };
if (Text === "Halt") { Text = _("Halt") };
return Text;
}
function getSignalstellungenText (File, countSignalPositions) {
let SignalFile = File;
if (Signalstellung[SignalFile]) {
// 1st try: Get texts using case sensitive file name
} else {
// 2nd try: Get texts using case insensitive file name
for (SignalFile in Signalstellung) {
if (SignalFile.toLowerCase() == File.toLowerCase()) {
break;
}
}
}
let SignalstellungenText = '';
for (const StellungPos in Signalstellung[SignalFile].Pos) {
SignalstellungenText += StellungPos + ': ' + getSignalPositionText(SignalFile, StellungPos) + ', ';
}
// Inspect German texts of first two positions to identify signal positions
const Pos1 = Signalstellung[SignalFile].Pos[1]["DE"];
const Pos2 = Signalstellung[SignalFile].Pos[2]["DE"];
if (Pos1.substr(0, 4) === "Halt" && Pos2.substr(0, 5) === "Fahrt") {
countSignalPositions.RED_GRN += 1;
} else if (Pos1.substr(0, 5) === "Fahrt" && Pos2.substr(0, 4) === "Halt") {
countSignalPositions.GRN_RED += 1;
}
return SignalstellungenText;
}
// Event handler to receive data
blockControlChannel.onmessage = function(event) {
const command = event.data.command;
if (command == "data") {
const filename = event.data.filename;
const EEPversion = Number(event.data.EEPversion);
const blockSignals = event.data.blockSignals;
const ignoredSignals = event.data.ignoredSignals;
const twoWayBlocks = event.data.twoWayBlocks;
const routes = event.data.routes;
const trains = event.data.trains;
const startSignals = event.data.startSignals;
const LuaFunctions = event.data.LuaFunctions;
const message = event.data.message;
const trackdata = document.getElementById('trackdata').checked;
const blockTracks = {};
const extended = document.getElementById('extended').checked;
const msg = document.getElementById('msg');
msg.textContent = message || "";
const data = document.getElementById('data');
data.textContent = `Received! Time stamp: ${event.timeStamp.toFixed(2)}`;
//if (trackdata) { // Does the uses requests generating track data?
/*
Use the routes data to calculate the tracks of a block:
previous tracks of a block = tracks before last turnout of a route
first track of a block = track after last turnout of a route
last track of a block = track with block signal
next tracks of a block = tracks after the track with the block signal
Dead ends require a different result:
last track = first track
next tracks = previous tracks
*/
for (const route of routes) {
const turns = route.turns;
// Ingnore routes on single tracks (two signals on same track)
if ( !turns[1] ) {
console.log("Both blocks " + route.startSignalID + " and " + route.SignalID + " are located on the same track " + turns[0].GleisID )
continue;
}
// Find trans at the beginning of a block
if (!blockTracks[route.SignalID]) { // Do we know this target signal already?
blockTracks[route.SignalID] = { // If not, create it.
SignalID : route.SignalID,
prev : new Set(), // Use set instead of array to omit duplicate entries
first : null,
last : null,
next : new Set(),
}
}
let blockTrack = blockTracks[route.SignalID];
// Tracks of a block: previous tracks (before turnout), first track (after turnout)
for (let i = turns.length - 1; i > 0; i--) {
if (turns[i].GleisID === turns[i-1].GleisID) { // Detect reversing direction at dead end before reaching the block signal
blockTrack.reverseDirection = true;
}
if (turns[i].WeicheID) { // If there is a turnout, then take the track before and after this turnout
blockTrack.prev.add( turns[i-1].GleisID );
blockTrack.first = turns[i+1].GleisID;
break;
}
}
if (!blockTrack.first) { // If there is no turnout, then take the first two tracks
blockTrack.prev.add( turns[0].GleisID );
blockTrack.first = turns[1].GleisID;
}
// Find tracks at the end of a block
if (!blockTracks[route.startSignalID]) { // Do we know this start signal already?
blockTracks[route.startSignalID] = { // If not, create it.
SignalID : route.startSignalID,
prev : new Set(),
first : null,
last : null,
next : new Set(),
}
}
blockTrack = blockTracks[route.startSignalID];
// Tracks of a block: last track (with signal), next tracks (after signal)
for (let i = 1; i < turns.length - 1; i++) {
if (turns[i].GleisID === turns[i-1].GleisID) { // Detect reversing direction at dead end after reaching the block signal
blockTrack.reverseDirection = true;
break;
}
if (turns[i].WeicheID) { // Stop if there is a turnout
break;
} }
blockTrack.last = turns[0].GleisID;
if (turns[1].WeicheID) {
blockTrack.next.add( turns[2].GleisID ); // If there is a turnout, then take the track before and after this turnout
} else {
blockTrack.next.add( turns[1].GleisID ); // If there is no turnout, then take the first two tracks
}
}
/*
Dead ends require a different result:
last track = first track
next tracks = previous tracks
*/
for (const b in blockTracks) {
const blockTrack = blockTracks[b];
if (blockTrack.reverseDirection) {
blockTrack.last = blockTrack.first;
blockTrack.next = blockTrack.prev;
}
}
//}
// Check if Lua functions in contacts require module BetterContacts
let useBetterContacts = false;
const calledBlocks = {};
// /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/
const specialChars = /[`!@#$%^&*()+\-=\[\]{};':"\\|,<>\/?~]/; // Allow: space _ .
for (const LuaFn of LuaFunctions) {
if (specialChars.test(LuaFn)) {
useBetterContacts = true;
//break;
}
// Identify block numbers from following patterns:
// blockControl.enterBlock_##
// blockControl.enterBlock(Zugname, ##)
//const regex = /blockControl.(?:enter|leave)Block(?:_|\(Zugname, )?(\d+)(?:\))?/;
const regex = /blockControl.enterBlock(?:_|\(Zugname, )?(\d+)(?:\))?/;
const groups = regex.exec(LuaFn);
if (groups && groups[1]) {
const b = parseInt(groups[1]);
calledBlocks[b] = true;
}
}
let text = [];
// Output header
const GleissystemID = form.querySelector('input[name="GleissystemID"]:checked').value;
text.push(`-- EEP ${_("Datei")} '${filename}'`);
text.push(`-- ` + EEP_Texts.getText("msg", 'LuaProgramBlockControl', TrackSystemText(GleissystemID)));
text.push(`-- For every block entry sensor enter the following into field 'Lua function' (where ## is the number of the block signal):`);
if (useBetterContacts) {
text.push(`-- blockControl.enterBlock(Zugname, ##)`);
} else {
text.push(`-- blockControl.enterBlock_##`);
};
// Output EEProutes
text.push("\n-- " + _("allowedBlocks"));
let maxTrainLength = 0;
let maxEEProuteLength = 0;
const EEProutes = {};
for (const train of trains) {
// Calculate max length of train names
if (maxTrainLength < train.name.length) { maxTrainLength = train.name.length; }
// Prepare table of EEP routes
if (train.routeName && train.routeName != "") {
if (!EEProutes[train.routeName]) {
const varName = train.routeName
.replace(/ä/g, "ae")
.replace(/ö/g, "oe")
.replace(/ü/g, "ue")
.replace(/Ä/g, "Ae")
.replace(/Ö/g, "Oe")
.replace(/Ü/g, "Ue")
.replace(/ß/g, "ss")
.replace(/\W/g, '_');
EEProutes[train.routeName] = varName;
// Calculate max length of train names
if (maxEEProuteLength < varName.length) { maxEEProuteLength = varName.length; }
}
} else {
EEProutes["all"] = "all";
if (maxEEProuteLength < 3) { maxEEProuteLength = 3; }
}
}
for (const routeName in EEProutes) {
let t = `local ${EEProutes[routeName]}${" ".repeat(1+maxEEProuteLength - EEProutes[routeName].length)}= {`;
for (const entry of blockSignals) {
t += ` [${_id(entry.SignalID)}]=1,`;
};
t += ` }`;
text.push(t);
}
// Output trains
text.push("\nlocal trains = {");
let i = 1;
for (const train of trains) {
const varName = EEProutes[train.routeName] || "all";
text.push(
` { `
+`name="${train.name}", ${" ".repeat(maxTrainLength - train.name.length)}`
+`signal=0, `
+(EEPversion && EEPversion < 14.2 ? `slot=${i}, ` : ``)
//+(train.currentSpeed != 0 ? `currentSpeed=${train.currentSpeed.toFixed(0)}, ` : ``)
+(train.targetSpeed != 0 ? `speed=${Math.abs(train.targetSpeed).toFixed(0)}, ` : ``)
+`allowed=${varName} ${" ".repeat(maxEEProuteLength - varName.length)}`
+`},`
);
i++;
}
text.push("}");
// Output start signal
const startSignal = (startSignals && startSignals[0] ? startSignals[0].SignalID : 0);
text.push(`\nlocal main_signal = ${_id(startSignal)}`); // Show lowest signal id of one of following signals: "Switch_standing", "Switch_lying", "StartSwitch_usertex"
// Output block signals
const countBlockSignalPositions = {
RED_GRN : 0, // Count of signals with RED = 1, GREEN = 2
GRN_RED : 0, // Count of signals with RED = 2, GREEN = 1
}
if (!extended) {
let t = "\nlocal block_signals = { ";
for (const entry of blockSignals) {
const SignalstellungenText = getSignalstellungenText(entry.name, countBlockSignalPositions); // The function counts RED/GREEN positions, too.
t += `${_id(entry.SignalID)}, `;
};
t += "}";
text.push(t);
} else {
text.push("\nlocal block_signals = {");
for (const entry of blockSignals) {
const SignalstellungenText = getSignalstellungenText(entry.name, countBlockSignalPositions);
text.push(` ${_id(entry.SignalID)}, -- ${SignalstellungenText}'${entry.name}' ${_("auf")} ${TrackSystemText(entry.GleissystemID)}-${entry.GleisID}`);
};
text.push("}");
}
// Show list of blocks without any contact calling the enterBlock function
let t = "";
for (const entry of blockSignals) {
if (!calledBlocks[entry.SignalID]) {
t += `${_id(entry.SignalID)}, `;
}
};
if (t != "") {
text.push("-- Blocks without any contact calling the corresponding enterBlock function: " + t);
}
// Show result of checking signal patterns
if (countBlockSignalPositions.RED_GRN > 0 && countBlockSignalPositions.GRN_RED > 0) {
text.push(`-- Caution:`);
}
if (countBlockSignalPositions.RED_GRN > 0) {
text.push(`-- ${countBlockSignalPositions.RED_GRN} signals use BLKSIGRED = 1, BLKSIGGRN = 2`);
}
if (countBlockSignalPositions.GRN_RED > 0) {
text.push(`-- ${countBlockSignalPositions.GRN_RED} signals use BLKSIGRED = 2, BLKSIGGRN = 1`);
}
let BLKSIGRED = 1;
let BLKSIGGRN = 2;
if (countBlockSignalPositions.RED_GRN < countBlockSignalPositions.GRN_RED) {
BLKSIGRED = 2;
BLKSIGGRN = 1;
}
// Output ignored signals
if (ignoredSignals.length > 0) {
let t = "-- Ignored signals: ";
for (const entry of ignoredSignals) {
t += `${_id(entry.SignalID)}, `;
};
text.push(t);
}
// Output two way blocks
if (!extended) {
let t = "\nlocal two_way_blocks = { ";
for (const entry of twoWayBlocks) {
t += `{ ${_id(entry[0])}, ${_id(entry[1])} }, `;
};
t += "}";
text.push(t);
} else {
text.push("\nlocal two_way_blocks = {");
for (const entry of twoWayBlocks) {
text.push(` { ${_id(entry[0])}, ${_id(entry[1])} }, `);
};
text.push("}");
}
if (trackdata) {
// Output block tracks
if (!extended) {
text.push(`\nlocal track_system = ${GleissystemID}`);
} else {
text.push(`\nlocal track_system = ${GleissystemID} -- ${TrackSystemText(GleissystemID)}`);
}
text.push("local block_tracks = {");
if (!extended) {
for (const SignalID in blockTracks) {
const blockTrack = blockTracks[SignalID];
let t = ` [${_id(SignalID)}] = {`;
t += ` ${(blockTrack.prev.size === 1) ? "" : "{ "}${Array.from(blockTrack.prev).join(', ')}${(blockTrack.prev.size === 1) ? "" : " }"},`;
t += ` ${blockTrack.first}, ${blockTrack.last},`;
t += ` ${(blockTrack.next.size === 1) ? "" : "{ "}${Array.from(blockTrack.next).join(', ')}${(blockTrack.next.size === 1) ? "" : " }"} },`;
text.push(t);
}
} else {
for (const SignalID in blockTracks) {
const blockTrack = blockTracks[SignalID];
let t = ` [${_id(SignalID)}] = {`;
t += ` prev = { ${Array.from(blockTrack.prev).join(', ')} },`;
t += ` first = ${blockTrack.first}, last = ${blockTrack.last},`;
t += ` next = { ${Array.from(blockTrack.next).join(', ')} } },`;
text.push(t);
}
}
text.push("}");
}
// Output routes
text.push("\nlocal routes = {");
for (const entry of routes) {
let line = "";
// reverse direction
const blockTrack = blockTracks[entry.startSignalID];
const reverse = (blockTrack && blockTrack.reverseDirection ? `, reverse=true` : ``);
// Header
if (!extended) {
line += ` { ${_id(entry.startSignalID)}, ${_id(entry.SignalID)}, turn={`;
} else {
line += `\n { ${_id(entry.startSignalID)}${reverse}, turn={ -- Track`;
}
// Entries
for (const turn of entry.turns) {
if (turn.WeicheID) {
const position = { "Ende" : 1, "EndeAbzweig" : 2, "EndeKoAbzweig" : 3 }[turn.Anschluss];
if (!extended) {
line += ` ${_id(turn.WeicheID)},${position},`;
} else {
line += `\n ${_id(turn.WeicheID)},${position},`
+ ` -- Track`
;
}
} else if (turn.GleisID) {
if (!extended) {
//line += "";
} else {
line += ` `
// + `${(turn.Anschluss === "Anfang" ? "+" : "-")}`
+ `${turn.GleisID}`
;
}
}
}
// Footer
if (!extended) {
line += ` }${reverse} },`;
} else {
line += `\n },`
+ `\n ${_id(entry.SignalID)}},`;
}
text.push(line);
}
text.push("}");
// Remaining part of main script in EEP
const LuaCode = [ `
local anti_deadlock_paths = { -- (Optional) Critical paths on which trains have to go to avoid lockdown situations
}
local crossings_protection = { -- (Optional) Coupled turnouts to protect crossings
}
-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
-- Remaining part of main script in EEP
-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
clearlog()`,`
require("BetterContacts_BH2") -- Load module BetterContacts from Benny
blockControl = require("blockControl") -- Load the module (global variable to serve BetterContacts)`,`
local blockControl = require("blockControl") -- Load the module`,`
blockControl.init({ -- Initialize the module
logLevel = 1, -- (Optional) Log level 0 (default): off, 1: normal, 2: full, 3: extreme
trains = trains, -- (Optional) Unknown trains get detected automatically, however, such trains do not have a train signal and can go everywhere.
blockSignals = block_signals, -- (Optional) Block signals
twoWayBlocks = two_way_blocks, -- (Optional) Two way twin blocks (pairs of related blocks)
routes = routes, -- Routes via turnouts from one block to the next block
paths = anti_deadlock_paths, -- (Optional) Critical paths on which trains have to go to avoid lockdown situations
crossings = crossings_protection, -- (Optional) Coupled turnouts to protect crossings`,`
trackSystem = track_system, -- Track system (required to define block tracks)
blockTracks = block_tracks, -- Previous, first, last and nexts tracks of blocks`,`
MAINSW = main_signal, -- ID of the main switch (optional)
MAINON = 1, -- ON state of main switch
MAINOFF = 2, -- OFF state of main switch
BLKSIGRED = ${BLKSIGRED}, -- RED state of block signals
BLKSIGGRN = ${BLKSIGGRN}, -- GREEN state of block signals
TRAINSIGRED = 1, -- RED state of train signals
TRAINSIGGRN = 2, -- GREEN state of train signals
})
-- [[ Optional: Set one or more runtime parameters at any time
blockControl.set({
logLevel = 1, -- (Optional) Log level 0 (default): off, 1: normal, 2: full, 3: extreme
showTippText = true, -- (Optional) Show tipp texts true / false (Later you can toggle the visibility of the tipp texts using the main switch.)
start = false, -- (Optional) Activate / deactivate main signal. Useful to start automatic block control after finding all known trains.
startAllTrains = true, -- (Optional) Activate / deactivate all train signals
})
--]]
function EEPMain()
blockControl.run()
return 1
end
`];
text.push(LuaCode[0]);
if (useBetterContacts) {
text.push(LuaCode[1]);
} else {
text.push(LuaCode[2]);
}
text.push(LuaCode[3]);
if (trackdata) {
text.push(LuaCode[4]);
}
text.push(LuaCode[5]);
// Output
// data.textContent = text.join("\n");
data.innerHTML = text.join("\n");
// Copy data to clipboard
navigator.clipboard.writeText(data.textContent).then(() => {
// Inform the user that the action took place.
// Nobody likes hidden stuff being done under the hood!
//alert("Data copied to clipboard");
const msg = document.getElementById('msg');
if (useBetterContacts) {
msg.innerHTML = `
Next steps:<ol>
<li>In EEP go to 3D mode</li>
<li>Paste the Lua code shown below, which is already copied into the clipboard, into the 'LUA script editor' window.</li>
<li>Click the 'Reload script' button</li>
</ol>
`;
} else {
msg.innerHTML = `
Next steps:<ol>
<li>In EEP go to 3D mode</li>
<li>Paste the Lua code shown below, which is already copied into the clipboard, into the 'LUA script editor' window.</li>
<li>Click the 'Reload script' button, this automatically creates the sensor functions needed.</li>
<li>Go to 2D mode</li>
<li>For every block entry sensor enter the following into field 'Lua function' (where ## is the number of the block signal): <span style="font-family:monospace;">blockControl.enterBlock_##</span></li>
</ol>
`;
}
});
}
}
</script>
</main>
</body>
</html>