#ifndef RxTx_INCLUDED
	#define RxTx_INCLUDED

#include <bncs_script_helper.h>

#ifdef WIN32
	#ifdef DOEXPORT_SCRIPT
		#define EXPORT_SCRIPT __declspec(dllexport) 
	#else
		#define EXPORT_SCRIPT 
	#endif
#else 
	#define EXPORT_SCRIPT
#endif
 
class RxTx : public bncs_script_helper
{
public:
	RxTx(bncs_client_callback * parent, const char* path);
	virtual ~RxTx();

	void buttonCallback(buttonNotify *b);
	int revertiveCallback(revertiveNotify *r);
	void databaseCallback(revertiveNotify *r);
	bncs_string parentCallback(parentNotify *p);
	void timerCallback(int);
	
private:
	bncs_string offmode, rehmode, txmode;	// Hold statesheet strings for off, rehearse and trnsmit.

	int currentState_A;				// Holds the current Gallery A Off/Reh/TX status
	int currentState_B;				// Holds the current Gallery B Off/Reh/TX status (really a placeholder as B gallery does not exist)
	int currentState_C;				// Holds the current Gallery C Off/Reh/TX status
	int tallyInfodriver;			// Holds the BNCS driver ID for the tally infodriver
	int sdiRouterdriver;			// Holds the BNCS driver ID for the sdi router
	int audioRouterdriver;			// Holds the BNCS driver ID for the audio router
	int GPIdriver;					// Holds the number of the GPI driver used for Blue/Red control
	int GPIcontact_1;				// Holds the GPI slot for the first GPI output
	int StA_Floor;					// Holds the current control mode for Studio A floor
	int StC_Floor;					// Holds the current control mode for Studio C floor
	int StC_News;					// Holds the current control mode for News Studio C
	int StC_Video_Line;				// Line output destination for SDI video to CTA
	int StC_Video_Line_Src;			// Holds the video source id for feeding the vision line out during Tx
	int StC_Video_Current;			// Holds the current video source id feeding to vision output line.
	int StC_Audio_Line;				// Line output destination for analogue
	int StC_Audio_Line_Src;			// Holds the audio source id for feeding line during TX
	int StC_Audio_Current;			// Holds the current audio to line index.
	UINT tallyrx;					// Builds a flag list to check all 6 tally slots have returned values

	bool tallyReg;					// Flags that show if the drivers have been registered for revertives
	bool SDIReg;
	bool audioReg;
	bool processActive;				// Set false during initial Tally Infodriver data poll, true when operating normally

	// Private methods
	void setStC_TXgpi(void);					// Sets the GPI relay states needed for Transmission mode active
	void setStC_REHgpi(void);					// Sets the GPI relay states needed for Rehearse mode active
	void setStC_OFFgpi(void);					// Clear all relays to "off" to set the OFF condition
	void setOutputToLine(void);					// Sets the audio and video sources to correct TX versions.
	void Update_C_Floor_Relays(int TX_State);	// Sets Studio C Floor Reh/Tx relays according to parameter TX_State
	void Update_C_News_Relays(int TX_State);	// Sets Studio C News Floor Reh/Tx relays according to parameter TX_State
	void update_C_Floor_Tally(int newstate);	// Sets local panel mimic to show Studio C floor controlled state
	void update_C_News_Tally(int newstate);		// Sets local panel mimic to show Studio C News studio controlled state
	void update_A_Floor_Tally(int newstate);	// Sets local panel mimic to show Studio A Floor controlled state
};


#endif // RxTx_INCLUDED