-------------------------------------------------------------------------------------- -- PZB Kombi (1000/2000Hz) Inductor -- (goes next to Hp or VR or Kombi signal) -- KUJU / Rail Simulator -- StS 03.04.2011 -- Slightly modified by Prellbock with the kind help of schuster 24-Okt-2012 (rail-sim.de) -- Changes: Added a request for distant signals -------------------------------------------------------------------------------------- -- debugging stuff DEBUG = true -- set to true to turn debugging on function DebugPrint( message ) if (DEBUG) then Print( message ) end end -- global constants CLEAR = 0 WARNING = 1 BLOCKED = 2 -- message ids CUSTOM_MSG = 15 -- args PZB_1000_ARG = "1000" PZB_2000_ARG = "2000" -------------------------------------------------------------------------------------- -- INITIALISE -- function Initialise () mDone = 0 end -------------------------------------------------------------------------------------- -- ON CONSIST PASS -- function OnConsistPass ( prevFrontDist, prevBackDist, frontDist, backDist, linkIndex ) -- if the consist is crossing the inductor now if ( frontDist > 0 and backDist < 0 ) or ( frontDist < 0 and backDist > 0 ) then -- if the consist was previously before signal then the crossing has just started if (prevFrontDist > 0 and prevBackDist > 0) then if (mDone ~= 1) then mDone = 1 -- Request state of next main signal (german: Hauptsignal) local nextSignalState = Call( "GetNextSignalState", "", 1, 1, 0 ) -- Request state of next distant signal (german: Vorsignal) local nextDistantState = Call( "GetNextDistantState", "", 1, 1, 0 ) DebugPrint( ("DEBUG: PZB Kombi OnConsistPass: Crossing started, next main signal state is " .. nextSignalState) ) DebugPrint( ("DEBUG: PZB Kombi OnConsistPass: Crossing started, next distant signal state is " .. nextDistantState) ) -- If the distant signal ahead is on warning if (nextDistantState == WARNING) then Call( "SendConsistMessage", CUSTOM_MSG, PZB_1000_ARG ) end -- If the main signal ahead is blocked if (nextSignalState == BLOCKED) then Call( "SendConsistMessage", CUSTOM_MSG, PZB_2000_ARG ) Call( "SendConsistMessage", CUSTOM_MSG, PZB_1000_ARG ) end end end else -- Reset once train has passed if (mDone ~= 0) then DebugPrint( ("DEBUG: PZB Kombi OnConsistPass: Crossing finished") ) mDone = 0 end end end -------------------------------------------------------------------------------------- -- ON SIGNAL MESSAGE -- function OnSignalMessage( message, parameter, direction, linkIndex ) -- Forward every message unchanged, unless it's from a train straddling our link if parameter ~= "DoNotForward" then Call( "SendSignalMessage", message, parameter, -direction, 1, linkIndex ) end end -------------------------------------------------------------------------------------- -- JUNCTION STATE CHANGE -- Left blank - PZB inductors always only have one link -- function OnJunctionStateChange( junction_state, parameter, direction, linkIndex ) end