--[[
---------------------------------------------------------------------------
Remote Train Control Program for Windows

© Copyright 2019 by Mark DiVecchio

	This file is part of Remote Train Control.

	Remote Train Control is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Remote Train Control is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Remote Train Control.  If not, see <http://www.gnu.org/licenses/>.

 Home Page : http://www.silogic.com/trains/RTC_Running.html
---------------------------------------------------------------------------]]
-- Semicolons are not required in Lua code
title = "DTO DOD DCH Test"
require("defines");
-- Counter Labels
Counter01Label = "loops";
Counter02Label = "tests";

LOOPCOUNTER = COUNTER01;
TESTCOUNTER = COUNTER02;

--[[---------------------------------------------------------------------------------------]]
function setup(Engine, TIU)
	print(os.date("setup() %d %b %Y   %X"));
	return true;		-- false=setup failed, true=setup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
function loop(Engine, TIU)
	-- Always call Sleep() at least once in this function since it returns true;
	print(os.date("loop() %d %b %Y   %X"));
	MyTIUNo = TIU;
	AC, IAC = Counts();
	Sleep(5);
	print("TIU" .. TIU .. ": " .. AC .. " Active Engines - " .. IAC .. " Inactive Engines");
	BumpCounter(LOOPCOUNTER);		-- bump loop counter
	return true;	-- false=do not loop, true=continue to loop
	end
--[[---------------------------------------------------------------------------------------]]
function cleanup(Engine, TIU)
	-- this function is called once when the user presses the [STOP] button
	print(os.date("cleanup()  %d %b %Y   %X"));
	return true;		-- false=cleanup failed, true=cleanup succeeded
	end
--[[---------------------------------------------------------------------------------------]]
function GetDTO(Eng, TIU)
	-- Get the Trip Odometer
	print("DTO : " .. DTO(Eng, TIU) .. " Smiles");
	BumpCounter(TESTCOUNTER);		-- bump test counter
	return true;
end
Function01Name, Function01Label = GetDTO, "DTO";
--[[---------------------------------------------------------------------------------------]]
function GetDOD(Eng, TIU)
	-- Get the Odometer
	MyDOD = DOD(Eng, TIU);
	print("DOD : " .. MyDOD .. " Smiles");
	BumpCounter(TESTCOUNTER);		-- bump test counter
	return true;
end
Function02Name, Function02Label = GetDOD, "DOD";
--[[---------------------------------------------------------------------------------------]]
function GetDCH(Eng, TIU)
	-- Get the Chronometer
	MyDCH = DCH(Eng, TIU);
	print("DCH : " .. MyDCH .. " seconds");
	Myhours = MyDCH//(60 * 60);	-- use floor divide to get an integer
	Myminutes = (MyDCH//60) % 60;
	Myseconds = (MyDCH//1) % 60;	-- converts MyDCH to integer for modulo operation
	print(string.format("DCH : %02dh:%02dm:%02ds", Myhours, Myminutes, Myseconds)); 
	BumpCounter(TESTCOUNTER);		-- bump test counter
	return true;
end
Function03Name, Function03Label = GetDCH, "DCH";
--[[---------------------------------------------------------------------------------------]]
