//---------------------------------------------------------------------------
/*
Remote Train Control Program for Windows

© Copyright 2015 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
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef Engine_Status_ThreadH
#define Engine_Status_ThreadH
//---------------------------------------------------------------------------
#include <Classes.hpp>

class TEngineStatus;

//---------------------------------------------------------------------------
class TEngineStatusThread : public TThread
{
private:
    unsigned char EngineNo, TIUNo, RemoteNo;
    bool bRepeat;
    DWORD DelayValue;
    TEngineStatus * CallingOpScreen; 	// this pointer must be local to each Thread
    HWND ParentHandle;					// for messages back to the Parent
    int TestValue;

    byte StatusbyteResp[CMDMAX]; 		// Array for decoded binary response
    int iStatusCount;
    byte SpeedbyteResp[CMDMAX]; 		// Array for decoded binary response
    int iSpeedCount;
    byte InstantSpeedbyteResp[CMDMAX]; 	// Array for decoded binary response
    int iInstantCount;
    byte DirbyteResp[CMDMAX]; 			// Array for decoded binary response
    int iDirCount;
   	byte DTObyteResp[CMDMAX]; 			// Array for decoded binary response
    int iDTOCount;
	byte FactorResp[CMDMAX]; 			// Array for decoded binary response
    int iFactorCount;

    float fSF;					// Scaling Factor

   	bool DTOUpdate;
   	bool StatusUpdate;
    bool SpeedUpdate;
    bool InstantSpeedUpdate;

    String PrintLine;
    TColor PrintColor;

    __fastcall TEngineStatusThread(bool CreateSuspended);
    DWORD ThreadID;

protected:
	void __fastcall Execute();
    void __fastcall EI();
    void __fastcall CleanUp();
    void __fastcall Initialize();
    void __fastcall RunOnTerminate(TObject * Sender);
    void __fastcall CheckUpdateFlags(void);
    bool __fastcall Query(char * CommandString, byte * QBuf, int Engine, int TIU, int Remote);
    void __fastcall PrintItem();
public:
    __fastcall TEngineStatusThread(bool CreateSuspended, TEngineStatus * CallingOp, HWND Parent,
		int Eng, int TIU, int Remote, DWORD delay, bool RepeatParameter);
    __fastcall ~TEngineStatusThread();
};
//---------------------------------------------------------------------------
#endif
