//////////////////////////////////////
// header file for TopStrap_auto project //
//////////////////////////////////////

#if !defined(AFX_TOPSTRAP_AUTO_H__6E1F4185_1C5F_11D4_82C5_00105AC8787D__INCLUDED_)
#define AFX_TOPSTRAP_AUTO_H__6E1F4185_1C5F_11D4_82C5_00105AC8787D__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "resource.h"

// TODO:	Insert additional constants, function prototypes etc. in this file

/* max size of buffer for data from string resource */
#define			MAX_LOADSTRING	100

/* max number of items in listbox */
#define			MAX_LB_ITEMS	500

#define		APP_WIDTH			640
#define		APP_HEIGHT			640

#define		GPI_UNKNOWN			-1
#define		GPI_OFF				0
#define		GPI_ON				1
#define		GPI_FORCE_OFF		2
#define		GPI_FORCE_ON		3

#define		BYPASS_PREVIEW_DESK 1
#define		BYPASS_PREVIEW_PVW	2

#define		PEC_PARAM_TYPE		0
#define		PEC_PARAM_DEV_ID	1
#define		PEC_PARAM_MIN		2
#define		PEC_PARAM_INDEX		3
#define		PEC_PARAM_VALUE		4

//Presentation infodriver slots
#define		SLOT_FLOOR_OFF		1
#define		SLOT_REH			2
#define		SLOT_TX				3
#define		SLOT_FLASH_TX		4
#define		SLOT_BYPASS_AV		5
//#define		SLOT_BYPASS_VIDEO_FLASHING		6
#define		SLOT_BYPASS_AUDIO		7
#define		SLOT_BYPASS_VISION_RES		60 // added by ADP

#define		SLOT_INT_PROG_CUT	11			//command="PROG_OFF" slot returns 1=on 0=off (-1=not available)
#define		SLOT_EXT_PROG_CUT	12			//command="PROG_OFF" slot returns 1=on 0=off (-1=not available)
#define		SLOT_TONE_VT1_6		13			// added by ADP
#define		SLOT_TONE_VT7_12	14			// added by ADP
#define		SLOT_VENT_OFF		15			// added by ADP

#define		SLOT_BARS_LINE		21			//command="BARS" slot returns 1=on 0=off (-1=not available)
#define		SLOT_BARS_RES1		22			//command="BARS" slot returns 1=on 0=off (-1=not available)

#define		SLOT_TONE_M1		31			//command="TONE" slot returns 1=on 0=off (-1=not available)
//#define		SLOT_TONE_M2		32			//command="TONE" slot returns 1=on 0=off (-1=not available)

#define		SLOT_TONE_RES1		41			//command="TONE" slot returns 1=on 0=off (-1=not available)
//#define		SLOT_TONE_RES2		42			//command="TONE" slot returns 1=on 0=off (-1=not available)


#define		SLOT_VIDEO_BYPASS_A			51	//command="BYPASS" slot returns 1=on 0=off -1=not available
#define		SLOT_VIDEO_BYPASS_B			52	// added by ADP
#define		SLOT_VIDEO_BYPASS_Res		53	// added by ADP


#define		SLOT_AUDIO_BYPASS_SRCE1		61		//source number 1-1024=studer and 1025-1088=AES
#define		SLOT_AUDIO_BYPASS_PVW1		62		//command="PREVIEW" slot returns 0=unknown 1=Desk 2=Bypass
#define		SLOT_AUDIO_BYPASS_ACTION1	63		//command="BYPASS" slot returns 1=on 0=off -1=not available
#define		SLOT_SRC_AUDIO_BYPASS1		64			// slot returns src number for bypass

#define		SLOT_AUDIO_BYPASS_SRCE2		71		//source number 1-1024=studer and 1025-1088=AES
#define		SLOT_AUDIO_BYPASS_PVW2		72		//command="PREVIEW" slot returns 0=unknown 1=Desk 2=Bypass
#define		SLOT_AUDIO_BYPASS_ACTION2	73		//command="BYPASS" slot returns 1=on 0=off -1=not available
#define		SLOT_SRC_AUDIO_BYPASS2		74			// slot returns src number for bypass
	
#define		COL_OUTPUT			0
#define		COL_ONFLOOR			1
#define		COL_STATE			2

#define TX_FLASHING_TIMER_ID 2
#define TX_FLASHING_INTERVAL  998 // ms - every second or so lights toggle on or off

/* main.cpp */
/* prototypes for main functionality */
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK DlgProcChild(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT				InitApp(HWND);
void				CloseApp(HWND);

void				LoadIni(void);
char*				r_p(char* file, char* section, char* entry, char* defval, BOOL fWrite);
void				w_p(char* file, char* section, char* entry, char* setting);
int					getWS(void);

void				Debug(LPCSTR szFmt, ...);
void				Log(LPCSTR szFmt, ...);
int					SplitString(char *string, char *delim, UINT count, char **outarray );

/* TopStrap_auto.cpp /*

/* prototypes for the notification functions */
void UpdateCounters(void);
void InfoNotify(extinfo* pex,UINT iSlot,LPCSTR szSlot);
LRESULT CSIClientNotify(extclient* pec,LPCSTR szMsg);


// TODO: add prototypes for functions from TopStrap_auto_x.cpp
int getInstanceDevice(const bncs_string & instance);
bncs_string getObjectSetting(const bncs_string& strObject, const bncs_string& strSetting);

void revMGNOutputTX(int intValue);
void revMGNOutputReh(int intValue);
void revSDICCALine(int intSource);
void revSDICCARes1(int intSource);
void revSDIBypass(int intSource);

//void revHDCCALine(int intSource);
//void revHDCCARes1(int intSource);
//void revHDBypass(int intSource);

//void revAESCCAM1(int intSource);
//void revAESCCAM2(int intSource);
//void revAESCCARES1(int intSource);
//void revAESCCARES2(int intSource);

//void revAESBYPASS1(int intSource);
//void revAESBYPASS2(int intSource);

//void revSTUDERBYPASS1(int intSource);
//void revSTUDERBYPASS2(int intSource);

void revINTPROGCUT(int intSource);
void revEXTPROGCUT(int intSource);

void setMGNOutputList(bncs_stringlist sltOutputs, bncs_stringlist sltFloor, int intValue);
void setMGNBypassList( int intValue);

void setFloorOff(int intValue);

void infoPoll(int intDevice, int intMin, int intMax);
void infoWriteString(int intDevice, const bncs_string& strValue, int intIndex);
void infoWriteInt(int intDevice, int intValue, int intIndex);

void routerCrosspoint(int intDevice, int intSource, int intDest, const bncs_string& strMask = "");
void routerPoll(int intDevice, int intMin, int intMax);

void tielineCrosspoint(int intDevice, int intSource, int intDest, const bncs_string& strMask = "");


void getAppSettings();
void initStatusDialog();
void setOutputItemState(int intOutput, int intState);

void setReh(int intState);
void setTX(int intState);
void setFlashingTX(int intState);
BOOL InTXMode( void );

void setBarsLine(int intState);
void setBarsRes1(int intState);
void setVideoBypass(int intState, int intSlot = 0);
void setSingleVideoBypass(int iBypassSource, int iDestSource, int* iBypassStatus, int* iPreBypass, int intState, int intSlot);

void setTone(int intSlot, int intState);
void progCut(int intSlot, int intState);
//void setAudioBypassPreview(int intBypass, int intState);
//void setAudioBypassSource(int intBypass, int intSource);
//void setAudioBypassState(int intBypass, int intState);

//void updateAudioBypassTally(int intBypass);
// void updateBypassAV();

void updateUI(int intSlot);

//void setIntProgCut(int intState);
//void setExtProgCut(int intState);
void setVentOff(int intState);	// added adp
//void updateIntProgCut(void);
//void updateExtProgCut(void);

#ifndef EXT
#define EXT extern
#endif

/////////////////////////////////////////////////////////////////////
// Global Variables for the TopStrap_auto project
/////////////////////////////////////////////////////////////////////

EXT HINSTANCE hInst;						// current instance
EXT TCHAR szTitle[MAX_LOADSTRING];			// The title bar text
EXT TCHAR szWindowClass[MAX_LOADSTRING];	// The title bar text
EXT char szResult[256];						// global for profile reads
EXT BOOL fLog;								// log enable flag
EXT BOOL fDebug;							// debug enable flag
EXT BOOL fDebugHide;						// debug visible flag
EXT HWND hWndMain,hWndList;					// window handles, main and debug
EXT HWND hWndDlg;							// window handle for child dialog
EXT int iChildHeight;						// height of child dialog
EXT RECT rc;
EXT int iDevice;							// command line parameter = external driver #
EXT int iWorkstation;						// workstation number from CSI.INI
EXT ULONG lTXDEV;							// Device tx count
EXT ULONG lRXDEV;							// Device rx count
EXT ULONG lTXID;							// ID tx count
EXT ULONG lRXID;							// ID rx count
EXT extinfo ei;								// an external infodriver class
EXT extclient ec;							// a client connection class

// TODO: add additional global variables here, preceded by EXT

EXT int intDeviceMGNOutputs;		//42
EXT int intDeviceSDI;				//101
//EXT int intDeviceHD;				//91
//EXT int intDeviceAES;				//121
//EXT int intDeviceStuder;			//131
//EXT int intDeviceTieline;			//181 - this not a tieline manager/automatic 
									//		it is a tieline database only 
									//		i.e.	srce0001-srce1024=studer
									//		and		srce1025-srce1088=aes

//EXT int intAESRouterSize;			//64
//EXT int intStuderRouterSize;		//1024
//EXT int intTielineRouterSize;		//1088

EXT	int intSDI_SRCE_BARS;			//38	
EXT int intSDI_SRCE_MIXER_OUT;		//46
EXT int intSDI_SRCE_MIXER_RES;		//116
EXT	int intSDI_SRCE_BYPASS;			//91
EXT	int intSDI_SRCE_BYPASS_B;				// added by ADP	
EXT	int intSDI_SRCE_BYPASS_RES;				// added by ADP	

EXT int intSDI_DEST_BYPASS;			//15
EXT int intSDI_DEST_BYPASS_RES;				//added by ADP
EXT int intSDI_DEST_CCA_LINE;		//1
EXT int intSDI_DEST_CCA_LINE_B;		//2
EXT int intSDI_DEST_CCA_RES1;		//3

//EXT	int intHD_SRCE_BARS;			//63
//EXT int intHD_SRCE_MIXER_OUT;		//60
//EXT int intHD_SRCE_MIXER_RES;		//61
//EXT	int intHD_SRCE_BYPASS;			//59

//EXT int intHD_DEST_BYPASS;			//2
//EXT int intHD_DEST_CCA_LINE;		//1
//EXT int intHD_DEST_CCA_RES1;		//32


//EXT int intAES_SRCE_HWY_BYPASS1;	//4
//EXT int intAES_SRCE_HWY_BYPASS2;	//5
//EXT int intAES_SRCE_TONE1;			//53
//EXT int intAES_SRCE_TONE2;			//54
//EXT int intAES_SRCE_DESK1;			//56
//EXT int intAES_SRCE_DESK2;			//57
//EXT int intTielineSourceDesk1;		//56+1024=1080
//EXT int intTielineSourceDesk2;		//57+1024=1081

//EXT int intAES_DEST_CCA_M1;			//61
//EXT int intAES_DEST_CCA_M2;			//62
//EXT int intAES_DEST_CCA_RES1;		//63
//EXT int intAES_DEST_CCA_RES2;		//64
//EXT int intAES_DEST_BYPASS1;		//59
//EXT int intAES_DEST_BYPASS2;		//60
              
//EXT int intSTUDER_SRCE_SILENCE;  // 1
//EXT int intSTUDER_SRCE_PROGRAM;  // ?? unknown ?? see object settings
//EXT int intSTUDER_DEST_INT_PROG_CUT; // 84
//EXT int intSTUDER_DEST_EXT_PROG_CUT; // 85

//EXT int intSTUDER_DEST_HWY_BYPASS1;	//111
//EXT int intSTUDER_DEST_HWY_BYPASS2;	//112

EXT int intMGN_OUTPUT_REH;						//161			BLUE lights
EXT bncs_stringlist sltMGN_OUTPUT_REH_LIST;		//162,166,169	BLUE lights
EXT bncs_stringlist sltMGN_OUTPUT_REH_FLOOR;	//162			BLUE lights

EXT int intMGN_OUTPUT_TX;						//163			Red LIGHTS
EXT bncs_stringlist sltMGN_OUTPUT_TX_LIST;		//164,165,168	Red LIGHTS
EXT bncs_stringlist sltMGN_OUTPUT_TX_FLOOR;		//164			Red LIGHTS

EXT int intMGN_OUTPUT_BYPASS;						//????		AMBER Lights
EXT bncs_stringlist	sltMGN_OUTPUT_BYPASS_LIST;	//167,170		AMBER Lights

//Added by Simon
EXT bncs_string sltMGN_OUTPUT_VENT_OFF; 
EXT bncs_string sltMGN_OUTPUT_VTTONE16;
EXT bncs_string sltMGN_OUTPUT_VTONE712;
EXT bncs_string sltMGN_OUTPUT_TONEM1;
EXT bncs_string sltMGN_OUTPUT_TONERES1;
EXT bncs_string sltMGN_OUTPUT_INT_CUT;
EXT bncs_string sltMGN_OUTPUT_EXT_CUT;


EXT int intRehState;				//The last known state of the REH GPI
EXT int intTXState;					//The last known state of the TX GPI   

// note v1.2 - this TXstate can be off but as auto can be in flashing mode - so tx still in an ON state  !!
EXT BOOL bTXFlashingMode;  // new ver 1.2    -  true if TX in flashing mode rather than just revertive fromTX GPI on or off
EXT BOOL bTXFullMode;  // new ver 1.2    -  true if TX permanently on - ie after flashing stops or TX button pressed to bring TX on
EXT int intFlashTXCounter;
EXT BOOL bTXLightsOn;
EXT int int_MAX_TX_FLASH;  // loaded from obj settings at startup in seconds
EXT BOOL bStartTXMode;  // used to flag when first going into a tx mode to store reh value and set interlocks

EXT BOOL bBypassFlashingMode ;
EXT BOOL bBypassLightsOn;


EXT int intFloorOffState;			//The current state of floor off
EXT int intSDIBarsLineState;		//The current state of bars to line
EXT int intSDIBarsRes1State;		//The current state of bars to reserve
EXT int intSDIBypassState;			//The current state of video bypass
EXT int intSDIBypassState_B;		//The current state of video res bypass			added by ADP
EXT int intSDIBypassState_RES;


EXT int intSDIBypassSource;			//the current source on this dest
EXT int intSDIBypassRes1Source;		//the current source on this dest				added by ADP
EXT int intSDILineSource;			//the current source on this dest
EXT int intSDIRes1Source;			//the current source on this dest

//EXT int intHDBypassSource;			//the current source on this dest
//EXT int intHDLineSource;			//the current source on this dest
//EXT int intHDRes1Source;			//the current source on this dest

EXT int intSDILineSourcePreBars;	//the source that was on main before Bars to line state entered
EXT int intSDIRes1SourcePreBars;	//the source that was on res1 before Bars to line state entered
EXT int intSDILineSourcePreBypass;	//the source that was on main before Bypass state entered
EXT int intSDILineSourcePreBypass_B;
EXT int intSDILineSourcePreBypass_RES;	//the source that was on res1 before Bypass state entered

//EXT int intHDLineSourcePreBars;		//the source that was on main before Bars to line state entered
//EXT int intHDRes1SourcePreBars;		//the source that was on res1 before Bars to line state entered
//EXT int intHDLineSourcePreBypass;	//the source that was on main before Bypass state entered
//EXT int intHDRes1SourcePreBypass;	//the source that was on res1 before Bypass state entered

//EXT int intAESToneM1State;			//The current state of Tone to M1
//EXT int intAESToneM2State;			//The current state of Tone to M1
//EXT int intAESToneRes1State;		//The current state of Tone to Res1
//EXT int intAESToneRes2State;		//The current state of Tone to Res2
//EXT int intAESBypass1State;			//The current state of audio bypass1
//EXT int intAESBypass2State;			//The current state of audio bypass2
//EXT int intAESBypass1PreviewState;	//The current state of audio bypass1 preview
//EXT int intAESBypass2PreviewState;	//The current state of audio bypass1 preview


//EXT int intINTProgCutSrc; // The current src of internal progamme cut - should be either silence or program
//EXT int intEXTProgCutSrc; // The current src of external progamme cut - should be either silence or program
EXT int intFlashTXButtonState; // The current state of flash tx button
EXT int intVTTone16State;			// added adp
EXT int intVTTone712State;			// added adp
EXT int intVentOffState;			// added adp

EXT int intToneM1State;			//Added by Simon
EXT int intToneRes1State;		//Added by Simon

EXT int intINTProgCutState; // The current State of internal progamme cut - on or off
EXT int intEXTProgCutState; // The current State of external progamme cut - on or off

//EXT int intAESM1Source;				//the current source on the line
//EXT int intAESM2Source;				//the current source on the line
//EXT int intAESRes1Source;			//the current source on the line
//EXT int intAESRes2Source;			//the current source on the line

//EXT int intAESM1SourcePreTone;		//the source that was on the line before tone to line state entered
//EXT int intAESM2SourcePreTone;		//the source that was on the line before tone to line state entered
//EXT int intAESRes1SourcePreTone;	//the source that was on the line before tone to line state entered
//EXT int intAESRes2SourcePreTone;	//the source that was on the line before tone to line state entered
//EXT int intAESM1SourcePreBypass;	//the source that was on the line before bypass state entered
//EXT int intAESM2SourcePreBypass;	//the source that was on the line before bypass state entered
//EXT int intAESRes1SourcePreBypass;	//the source that was on the line before bypass state entered
//EXT int intAESRes2SourcePreBypass;	//the source that was on the line before bypass state entered

//EXT int	intAESSourceBypass1;		//the source that has been selected for audio bypass1 - it may be the tieline from Studer
//EXT int	intAESSourceBypass2;		//the source that has been selected for audio bypass2 - it may be the tieline from Studer
//EXT int	intStuderSourceBypass1;		//the source that has been selected to the bypass1 highway from studer to AES
//EXT int	intStuderSourceBypass2;		//the source that has been selected to the bypass2 highway from studer to AES
//EXT int	intTielineSourceBypass1;	//the source that has been selected for audio bypass1 expressed as a tieline source
//EXT int	intTielineSourceBypass2;	//the source that has been selected for audio bypass2 expressed as a tieline source

//EXT int	intAudioBypassTally1;		//the current source that is routed on audio bypass1 expressed as a tieline source
//EXT int	intAudioBypassTally2;		//the current source that is routed on audio bypass2 expressed as a tieline source

EXT HWND hWndOutputsReh;			//handle for the listview showing the rehearse details
EXT HWND hWndOutputsTX;				//handle for the listview showing the tx details

EXT bool blnRehWasForced;			//flag to store if the REH lights were forced on when TX goes on

EXT int intBypassAVState;			//overall bypass summary - OR of Video, Audio1, Audio2
EXT int intBypassAudioState;			//audio summary - OR of Audio1, Audio2
EXT int intBypassVisionState;			// Video summary


#endif // !defined(AFX_TOPSTRAP_AUTO_H__6E1F4185_1C5F_11D4_82C5_00105AC8787D__INCLUDED_)
