diff --git a/blockControl_v2/EEP_LUA_Automatic_Train_Control_v2.pdf b/blockControl_v2/EEP_LUA_Automatic_Train_Control_v2.pdf index 44a984f..853097f 100644 Binary files a/blockControl_v2/EEP_LUA_Automatic_Train_Control_v2.pdf and b/blockControl_v2/EEP_LUA_Automatic_Train_Control_v2.pdf differ diff --git a/blockControl_v2/EEP_LUA_Automatische_Zugsteuerung_v2.pdf b/blockControl_v2/EEP_LUA_Automatische_Zugsteuerung_v2.pdf index 8a0eb56..d2ab46a 100644 Binary files a/blockControl_v2/EEP_LUA_Automatische_Zugsteuerung_v2.pdf and b/blockControl_v2/EEP_LUA_Automatische_Zugsteuerung_v2.pdf differ diff --git a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_Depots.anl3 b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_Depots.anl3 index fdfb08d..471a035 100644 --- a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_Depots.anl3 +++ b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_Depots.anl3 @@ -1,2 +1,2 @@ -PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBin0PosDirNorBinPosDirNorBin0PosDirNorBin0PosDirNorBinPosDirNorBin01PosDirNorBin00PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBin0PosDirNorBin0PosDirNorBin0PosDirNorBin0PosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBin0PosDirNorBin0PosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin2PosDirNorBinPosDirNorBin0PosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin +PosDirNorBinPosDirNorBinPosDirNorBin1PosDirNorBin
PosDirNorBin00PosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBin0PosDirNorBin0PosDirNorBin0PosDirNorBin0PosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBin2PosDirNorBin
PosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBin00PosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBin0PosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBinPosDirNorBin diff --git a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_Depots.lua b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_Depots.lua index 6b35faa..fc87a66 100644 --- a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_Depots.lua +++ b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_Depots.lua @@ -1,10 +1,10 @@ --- EEP File 'Depots B' +-- EEP File 'Depots' -- Lua program for module 'blockControl.lua' for track system 'Railroad' -- For every block entry sensor enter the following into field 'Lua function' (where ## is the number of the block signal): -- blockControl.enterBlock(Zugname, ##) -- Allowed blocks with wait time -local rt = { 20, 35 } +local rt = { 40, 60 } -- The additional entry showing dummy block 0 prevents some error messages but does not influence traffic on this layout. local all = { [0] = 1, -- (additional) Trains are allowed to leave the controlled part of the layout @@ -14,25 +14,25 @@ local all = { [9] = rt, -- Station CW [19] = rt, -- Station CW - [12] = 1, -- Entry Depot 2 - [11] = 1, -- Exit Depot 1 - - [5] = 1, -- Entry Depot 1 - [6] = 1, -- Exit Depot 2 + [6] = 99, -- Entry Depot 1 (ensure to drive to the end of the track) + [7] = 1, -- Exit Depot 1 + [11] = 99, -- Entry Depot 2 (ensure to drive to the end of the track) + [12] = 1, -- Exit Depot 2 } local trains = { + { name="#DB_216 beige", signal=22, slot=4, speed=70, allowed=all }, + { name="#Shuttle Red", signal=24, slot=6, speed=50, allowed=all }, + { name="#Steam", signal= 4, slot=3, speed=50, allowed=all }, { name="#Blue", signal=30, slot=1, speed=70, allowed=all }, { name="#Orange", signal=14, slot=2, speed=70, allowed=all }, - { name="#Steam", signal= 4, slot=3, speed=50, allowed=all }, - { name="#DB_216 beige", signal=22, slot=4, speed=70, allowed=all }, { name="#Shuttle Yellow", signal=23, slot=5, speed=50, allowed=all }, - { name="#Shuttle Red", signal=24, slot=6, speed=50, allowed=all }, } local main_signal = 3 -local block_signals = { 5, 6, 8, 9, 11, 12, 18, 19, } +local block_signals = { 6, 7, 8, 9, 11, 12, 18, 19, } +-- Blocks without any contact calling the corresponding enterBlock function: 8, -- 8 signals use BLKSIGRED = 1, BLKSIGGRN = 2 local two_way_blocks = { { 9, 18 }, } @@ -40,28 +40,20 @@ local two_way_blocks = { { 9, 18 }, } -- The additional entries showing dummy block 0 prevent some error messages but do not influence traffic on this layout. -- The deactivated entries had been generated but are useless on this layout. local routes = { - { 0, 5, }, -- (additional) Train enters controlled part of the layout - { 0, 11, }, -- (additional) Train enters controlled part of the layout - - { 5, 9, turn={ 7,2, 2,2, 17,1, } }, -- To station CW - { 5, 19, turn={ 7,2, 2,2, 17,2, } }, -- To station CW - ---{ 6, 5, turn={ 21,1, } }, -- (deactivated) - { 6, 0, }, -- (additional) Train leaves controlled part of the layout - - { 8, 12, turn={ 2,1, 7,1, 13,1, } }, -- From station CCW - - { 9, 6, turn={ 16,1, 1,2, 10,2, 20,2, } }, -- From station CW - - { 11, 8, turn={ 10,1, 1,1, } }, -- To station CCW - { 11, 18, turn={ 10,1, 1,2, 16,1, } }, -- To station CCW - ---{ 12, 12, turn={ 13,undefined, } }, -- (deactivated) - { 12, 0, }, -- (additional) Train leaves controlled part of the layout - - { 18, 12, turn={ 17,1, 2,2, 7,1, 13,1, } }, -- From station CCW - - { 19, 6, turn={ 16,2, 1,2, 10,2, 20,2, } }, -- From station CW + { 0, 7, }, -- (additional) Train enters controlled part of the layout + { 0, 12, }, -- (additional) Train enters controlled part of the layout + { 6, 8, turn={ 13,1, 1,2, }, reverse=true }, -- (useless) Trains never reach the signal behind a depot entry + { 6, 18, turn={ 13,1, 1,1, 2,1, }, reverse=true }, -- (useless) Trains never reach the signal behind a depot entry + { 7, 8, turn={ 13,2, 1,2, } }, + { 7, 18, turn={ 13,2, 1,1, 2,1, } }, + { 8, 11, turn={ 16,1, 15,2, } }, + { 9, 6, turn={ 2,1, 1,1, 13,1, } }, + { 11, 9, turn={ 15,2, 16,2, 17,1, }, reverse=true }, -- (useless) Trains never reach the signal behind a depot entry + { 11, 19, turn={ 15,2, 16,2, 17,2, }, reverse=true }, -- (useless) Trains never reach the signal behind a depot entry + { 12, 9, turn={ 15,1, 16,2, 17,1, } }, + { 12, 19, turn={ 15,1, 16,2, 17,2, } }, + { 18, 11, turn={ 17,1, 16,2, 15,2, } }, + { 19, 6, turn={ 2,2, 1,1, 13,1, } }, } local anti_deadlock_paths = { -- (Optional) Critical paths on which trains have to go to avoid lockdown situations @@ -112,11 +104,12 @@ blockControl.set({ function EEPMain() blockControl.run() return 1 -end +end + [EEPLuaData] -DS_1 = "speed=44.996 block=6 " -DS_2 = "speed=-38.147 block=11 " -DS_3 = "speed=-4.055 block=8 " -DS_4 = "speed=53.984 block=19 " -DS_5 = "speed=49.967 " -DS_6 = "speed=41.597 block=18 " +DS_1 = "speed=3.172 " +DS_2 = "speed=69.997 " +DS_3 = "speed=-26.507 block=19 " +DS_4 = "speed=60.039 " +DS_5 = "speed=49.995 " +DS_6 = "speed=25.221 " diff --git a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsB.bmp b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsB.bmp index c8a0beb..70bf1fa 100644 Binary files a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsB.bmp and b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsB.bmp differ diff --git a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsF.bmp b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsF.bmp index 7012609..2430418 100644 Binary files a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsF.bmp and b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsF.bmp differ diff --git a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsH.bmp b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsH.bmp index 5b4981a..f888dc6 100644 Binary files a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsH.bmp and b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsH.bmp differ diff --git a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsS.bmp b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsS.bmp index f77e193..05b1c03 100644 Binary files a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsS.bmp and b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsS.bmp differ diff --git a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsT.bmp b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsT.bmp index 9694421..3bfc070 100644 Binary files a/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsT.bmp and b/blockControl_v2/EEP_blockControl/EEP_LUA_ATC_DepotsT.bmp differ diff --git a/blockControl_v2/LUA/blockControl.lua b/blockControl_v2/LUA/blockControl.lua index 539c851..096ee80 100644 --- a/blockControl_v2/LUA/blockControl.lua +++ b/blockControl_v2/LUA/blockControl.lua @@ -67,18 +67,19 @@ Version history: - New function releaseTurnout usable in contacts in exceptional situations to release turnouts as early as possible (BetterContacts is required to call this function.) +2.4.1. 30.08.2022 +- Improved messages +- logLevel 3 shows line numbers, too +- Correction for findMode if trains vanish into a depot + --]] -local _VERSION = 'v2.4.0 - 19.08.2022' +local _VERSION = 'v2.4.1 - 30.08.2022' -- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -- @@@ MODULE blockControl -- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ --- Variables starting with an upper case letter are objects. --- Variables starting with a lower letter are primitive data types or arrays. --- Variables which are all upper case are constants. - -- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -- @@@ Language functions -- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -137,13 +138,23 @@ end local logLevel = 0 -- Log level 0: off, 1: normal, 2: full, 3: extreme local function printLog (level, ...) -- A variable number of arguments is passed as second parameter if logLevel >= level then - print(...) -- Print variable number of argument values + if logLevel >= 3 then + local info = debug.getinfo(2, "l") -- level 2 = caller; S: source, short_src, what, linedefined; l: currentline + print("["..info.currentline.."] ", ... ) -- Print variable number of argument values + else + print(...) -- Print variable number of argument values + end end end local function check (condition, ...) -- Check a condition and show a message (simnilar like assert but without stopping) if not condition then - print(...) -- Print variable number of argument values + if logLevel >= 3 then + local info = debug.getinfo(2, "l") -- level 2 = caller; S: source, short_src, what, linedefined; l: currentline + print("["..info.currentline.."] ", ... ) -- Print variable number of argument values + else + print(...) -- Print variable number of argument values + end end end @@ -266,14 +277,13 @@ local function storeTrainData( trainName, data ) }, trainName ) ) - if not Train.slot or Train.slot == 0 then - print(stringFormat({ + check(Train.slot and Train.slot > 0, + stringFormat({ GER = "Fehler beim Speichern von Daten: kein Slot für den Zug '%s' definiert", ENG = "Error while storing data: no slot defined for train '%s'", FRA = "Erreur lors de l'enregistrement des données: aucun emplacement défini pour le train '%s'", }, trainName ) ) - end end if Train and Train.slot and Train.slot > 0 then @@ -641,8 +651,8 @@ local function copyPaths (paths) end end -local routeTab = {} -- Routes -local TurnReserved = {} -- Stores the free/reserved state for every turnout, false=free, true=reseved +local RouteTab = {} -- Routes +local TurnReserved = {} -- For every turnout, the train which reserves it, is stored (false=free) local CrossingsTab = {} -- Crossings local function copyCrossings (crossings) @@ -663,7 +673,7 @@ local function copyCrossings (crossings) CrossingsTab[ entry[1] ] = { checkSwitch = false, addSwitch = entry[2] } end - -- Register turnouts + -- Register turnouts (false=free) if TurnReserved[ entry[1] ] == nil then TurnReserved[ entry[1] ] = false end @@ -691,7 +701,7 @@ local function copyRoutes (routes) -- Copy routes into route tabl -- Better solution: use the shortest route between both blocks local turn = Route.turn or {} -- turn is optional if there are no turnouts for this route local found = false - for _r, _Route in pairs(routeTab) do + for _r, _Route in pairs(RouteTab) do if _Route[1] == fromBlock and _Route[2] == toBlock then -- Do we know such a route already? found = true @@ -710,7 +720,7 @@ local function copyRoutes (routes) -- Copy routes into route tabl end if not found then - table.insert(routeTab, { -- Store only one route between both blocks + table.insert(RouteTab, { -- Store only one route between both blocks fromBlock, toBlock, turn = turn, @@ -726,6 +736,7 @@ local function copyRoutes (routes) -- Copy routes into route tabl local switch = Route.turn[to*2-1] local pos = Route.turn[to*2] + -- Register turnouts (false=free) if TurnReserved[ switch ] == nil then TurnReserved[ switch ] = false end @@ -1096,11 +1107,11 @@ local function printData () ":" ) local sortRoutes = function(a,b) - local ra = routeTab[a] - local rb = routeTab[b] + local ra = RouteTab[a] + local rb = RouteTab[b] return ra[1] == rb[1] and ra[2] < rb[2] or ra[1] < rb[1] end - for _, Route in pairsByKeys(routeTab, sortRoutes) do + for _, Route in pairsByKeys(RouteTab, sortRoutes) do print( stringFormat({ GER = "Von Block %d nach Block %d", @@ -1749,14 +1760,19 @@ local function findTrains () local finished = true local count = 0 for trainName, Train in pairs(TrainTab) do - printLog(3, "Train '",trainName,"' was found in block ", (Train.block or "-")) + printLog(3, stringFormat({ + GER = "Der Zug '%s' befindet sich in Block %d", + ENG = "Train '%s' is located in block %d", + FRA = "Le train '%s' est situé dans le bloc %d", + }, trainName, (Train.block or 0) + )) if not Train.block then finished = false else count = count + 1 end end - printLog(3, "FIND MODE finished ", finished and "yes " or "no ", count) + printLog(3, "FIND MODE finished ", finished and "finished " or "running ", count) if not finished and cycle % 50 == 1 then -- Do this every 10 seconds, given that EEPMain() runs 5x/s printLog(1, stringFormat({ @@ -1930,20 +1946,20 @@ local function showSignalStatus() end -- Turnouts - for s, train in pairs(TurnReserved) do - local pos = math.floor( EEPGetSwitch( s ) ) - EEPChangeInfoSwitch( s, + for switch, Train in pairs(TurnReserved) do + local pos = math.floor( EEPGetSwitch( switch ) ) + EEPChangeInfoSwitch( switch, stringFormat({ GER = "Weiche %d
Position %d
", ENG = "Turnout %d
Position %d
", FRA = "Aiguillage %d
Position %d
", - }, s, pos ) - .. (train + }, switch, pos ) + .. (Train and tippTextYELLOW .. stringFormat({ GER = "reserviert", ENG = "reserved", FRA = "réservé", }) or tippTextGREEN .. stringFormat({ GER = "frei", ENG = "free", FRA = "libre", }) ) ) - EEPShowInfoSwitch( s, showTippText and logLevel >= 0 ) + EEPShowInfoSwitch( switch, showTippText and logLevel >= 0 ) end end @@ -2171,11 +2187,11 @@ local function printStatus( periodicTime ) ) local sortRoutes = function(a,b) - local ra = routeTab[a] - local rb = routeTab[b] + local ra = RouteTab[a] + local rb = RouteTab[b] return ra[1] == rb[1] and ra[2] < rb[2] or ra[1] < rb[1] end - for r, Route in pairsByKeys(routeTab, sortRoutes) do + for r, Route in pairsByKeys(RouteTab, sortRoutes) do local text = stringFormat({ GER = "Route von Block %d nach %d", @@ -2455,6 +2471,11 @@ local function run () if not Block.occupied and Block.occupiedOld then -- A train released this block Block.occupiedOld = Block.occupied -- Set block memory old to 'free', now this 'if' statement won't run again + if Train.path and #Train.path == 1 and Train.path[1] == b then -- Finish path if this is the last part + --table.remove(Train.path, 1) + Train.path = {} + end + printLog(1, prefix, stringFormat({ GER = "Zug '%s' gibt Block %d frei", ENG = "Train '%s' releases block %d", @@ -2467,19 +2488,15 @@ local function run () FRA = " et bloc jumeau %d", }, Block.twoWayBlock ) or "") - , stringFormat({ + ,(Train.path and stringFormat({ GER = " und fährt weiter auf dem Pfad %s", ENG = " and continues on path %s", FRA = " et continue sur le chemin %s", }, table.concat((Train.path or {}), ", ") ) + or "") ) Train.block = nil -- Set train to be located outside of any block - - if Train.path and #Train.path == 1 and Train.path[1] == b then -- Finish path if this is the last part - --table.remove(Train.path, 1) - Train.path = {} - end Block.occupiedOld = nil -- Set block to 'free' @@ -2491,7 +2508,7 @@ local function run () Block.stopTimer = 0 local ok EEPSetSignal( Block.signal, BLKSIGRED, 1 ) -- Set the block signal to RED - printLog(2, prefix, "EEPSetSignal( ",Block.signal,", RED )",(ok == 1 and "" or " error") ) + printLog(2, prefix, "EEPSetSignal( ",Block.signal,", BLKSIGRED, RED )",(ok == 1 and "" or " error") ) if twoWayBlock then -- In case it was an reversing route... EEPSetSignal( twoWayBlock.signal, BLKSIGRED, 1 ) -- ... set the two way twin block signal to RED as well @@ -2614,7 +2631,7 @@ local function run () GER = "Der vorherige Block %d des Zuges '%s auf dem Pfad %s ist bereits freigegeben", ENG = "Previous block %d of train '%s on path %s is already released", FRA = "Le bloc %d précédent du train '%s sur le chemin %s est déjà libéré", - }, pb, Train.name, Train.path and table.concat(Train.path, ", ") or "" ) + }, pb or 0, Train.name, Train.path and table.concat(Train.path, ", ") or "" ) ) end @@ -2625,11 +2642,11 @@ local function run () GER = "Suche Route von Block %d nach Block %d zur Freigabe der Weichen", ENG = "Search route from block %d to block %d to release turnouts", FRA = "Recherche d'un itinéraire du bloc %d au bloc %d pour libérer les aiguillages", - }, pb, b ) + }, pb or 0, b ) ) local turn = nil -- Search route to release the turnouts - for r, Route in pairs(routeTab) do -- (Full table scan is not very efficent but it works fine.) + for r, Route in pairs(RouteTab) do -- (Full table scan is not very efficent but it works fine.) if Route[1] == pb and Route[2] == b then -- Assumption: there exist only one route between both blocks turn = Route.turn Route.visits = Route.visits + 1 -- Update statistics @@ -2748,7 +2765,7 @@ local function run () local fromBlock = Path[k] local toBlock = Path[k+1] if freePath then -- Is it still a free path? - for r, Route in pairs(routeTab) do -- Let's check if all turnouts are free to reach the next block + for r, Route in pairs(RouteTab) do -- Let's check if all turnouts are free to reach the next block if freePath and Route[1] == fromBlock and Route[2] == toBlock then -- Assumption: there exist only one route between both blocks for to = 1, #Route.turn / 2 do -- Check if the route turnouts are free local switch = Route.turn[to*2-1] @@ -2809,9 +2826,11 @@ local function run () if logLevel >= 3 then for k, v in pairs(availablePath) do -- Show free paths local Train, b, Path = table.unpack(v) - print( stringFormat( - "Train '%s' in block %d has free path %s", - Train.name, b, Path and table.concat(Path, ", ") or "" + printLog(3, stringFormat({ + GER = "Zug '%s' in Block %d hat den freien Pfad %s", + ENG = "Train '%s' in block %d has free path %s", + FRA = "Le train '%s' dans le bloc %d a un chemin libre %s", + }, Train.name, b, Path and table.concat(Path, ", ") or "" )) end end @@ -2857,7 +2876,7 @@ local function run () printLog(3, prefix, "EEPSetSignal( ",Block.signal,", ",(k==#Train.path and "RED" or "GREEN")," )",(ok == 1 and "" or " error") ) if k > 1 then - for r, Route in pairs(routeTab) do -- Search in all routes + for r, Route in pairs(RouteTab) do -- Search in all routes local fromBlock = Route[1] local toBlock = Route[2] if prevBlock == fromBlock and nextBlock == toBlock then -- Assumption: there exist only one route between both blocks @@ -2877,7 +2896,7 @@ local function run () }, fromBlock, toBlock, k-1, table.concat(Train.path, " ") ) ) if not Train.speed then - print(stringFormat({ + printLog(0, stringFormat({ GER = "Fehler beim Umkehren der Zugrichtung: Zug '%s' hat keine gespeicherte Geschwindigkeit", ENG = "Error during reversing train direction: Train '%s' has no stored speed", FRA = "Erreur lors de l'inversion du sens du train: Le train '%s' n'a pas de vitesse enregistrée", @@ -2905,7 +2924,7 @@ local function run () end if not Train.reversingSpeed then - print(stringFormat({ + printLog(0, stringFormat({ GER = "Fehler beim Umkehren der Zugrichtung: Der Zug '%s' hat keine Umkehrgeschwindigkeit", ENG = "Error during reversing train direction: Train '%s' does not have a reversing speed", FRA = "Erreur lors de l'inversion de la direction du train: Le train '%s' n'a pas de vitesse d'inversion", @@ -3006,7 +3025,7 @@ In this case the order of actions does not matter (after you have executed the L -- Parametrisied function which you can use in Lua contacts: blockControl.enterBlock(Zugname, 25) enterBlock = function (trainName, b) -- (The local variable 'enterBlock' is already defined above) local Train = TrainTab[trainName] -- Get train ... - local path = Train and Train.path or {} -- and current route of that train. + local path = Train and Train.path or {} -- and current path of that train. if not findMode then --if b then @@ -3043,7 +3062,7 @@ enterBlock = function (trainName, b) -- (The local variable 'enterB end elseif not path[1] then -- The train does not have a path - print(stringFormat({ + printLog(0, stringFormat({ GER = "Zug '%s' fährt in Block %d ein, folgt aber keinem Pfad", ENG = "Train '%s' enters block %d but does not follow a path", FRA = "Le train '%s' entre dans le bloc %d mais ne suit pas un chemin", @@ -3079,40 +3098,41 @@ enterBlock = function (trainName, b) -- (The local variable 'enterB end -- Parameterized function which you can use in Lua contacts: blockControl.leaveBlock(Zugname, 25) -leaveBlock = function (trainName, b) -- (The local variable 'leaveBlock' is already defined above) +leaveBlock = function (trainName, b) -- (The local variable 'leaveBlock' is already defined above) + local Train = TrainTab[trainName] -- Get train ... + local path = Train.path or {} -- and current route of that train. + local Block = BlockTab[b] -- Get block if not findMode then - local Train = TrainTab[trainName] -- Get train ... - local path = Train.path or {} -- and current route of that train. --if b then -- Consistency checks if path[1] and path[2] then -- The train has a path check(b == path[1], stringFormat({ - GER = "Zug '%s' verlässt den Block %d, sollte aber den Block %d verlassen", - ENG = "Train '%s' leaves block %d but was expected to leave block %d", - FRA = "Le train '%s' quitte le bloc %d mais était censé quitter le bloc %d", - }, trainName, b, path[1] ) + GER = "Zug '%s' verlässt den Block %d, sollte jedoch dem Pfad %s folgen", + ENG = "Train '%s' leaves block %d but was expected to follow path %s", + FRA = "Le train '%s' quitte le bloc %d mais était censé suivre le chemin %s", + }, trainName, b, table.concat(path, " ") ) ) printLog(2, stringFormat({ - GER = "Zug '%s' verlässt Block %d", - ENG = "Train '%s' leaves block %d", - FRA = "Le train '%s' quitte le bloc %d", - }, trainName, b ) + GER = "Zug '%s' verlässt Block %d auf dem Pfad %s", + ENG = "Train '%s' leaves block %d on path %s", + FRA = "Le train '%s' quitte le bloc %d sur le chemin %s", + }, trainName, b, table.concat(path, " ") ) ) elseif path[1] and not path[2] then -- Weird situation should not happen - print(stringFormat({ - GER = "Zug '%s' verlässt Block %d, hat aber einen unvollständigen Pfad", + printLog(0, stringFormat({ + GER = "Zug '%s' verlässt Block %d, hat aber einen unvollständigen Pfad %s", ENG = "Train '%s' leaves block %d but has an incomplete path", - FRA = "Le train '%s' quitte le bloc %d mais a un chemin incomplet", - }, trainName, b ) + FRA = "Le train '%s' quitte le bloc %d mais a un chemin incomplet %s", + }, trainName, b, table.concat(path, " ") ) ) elseif not path[1] then -- The train does not have a path - print(stringFormat({ + printLog(0, stringFormat({ GER = "Zug '%s' verlässt Block %d, folgt aber keinem Pfad", ENG = "Train '%s' leaves block %d but does not follow a path", FRA = "Le train '%s' quitte le bloc %d mais ne suit pas un chemin", @@ -3133,11 +3153,25 @@ leaveBlock = function (trainName, b) -- (The local variable 'leaveB ENG = "leaveBlock: Train '%s' leaves block %d, occupied='%s', reserved='%s'", FRA = "leaveBlock: Le train '%s' quitte le bloc %d, occupé='%s', réservé='%s'", }, trainName, b, - BlockTab[b].occupied and BlockTab[b].occupied or "NIL", - BlockTab[b].reserved and BlockTab[b].reserved.name or "NIL" + Block.occupied and Block.occupied or "NIL", + Block.reserved and Block.reserved.name or "NIL" )) - BlockTab[b].occupied = nil -- Train leaves block + Block.occupied = nil -- Train leaves block, function run will pick up this event + + if findMode then + if Train then -- In case of findMode, remove train from the block completely + Train.block = 0 -- .. but keep the information that we know this train + Train.path = nil + end + Block.reserved = nil + Block.occupied = nil + Block.occupiedOld = nil + local TwoWayBlock = (Block.twoWayBlock and BlockTab[ Block.twoWayBlock ] or nil) + if TwoWayBlock then TwoWayBlock.reserved = nil end + Block.request = nil + end + end