typedef struct {
    TCHAR MaterialID[128];
    int IDType;
    int MapFormat;
    int FNLocationDegrees;
    int FilmFramRotAngle;
    int OriginLoc;
    int ProcessAxisVal;
    TCHAR BinCodeEquivalent[128];
    TCHAR NullBinCodeVal[128];
} SGWaferMapSetupData;

#define S2_TYP(x, y) ((x << 2) | y) /* Archtype Entry               */
#define S2_B         S2_TYP(2, 0)   /* Binary                       */
#define S2_BOOLEAN   S2_TYP(3, 0)   /* Boolean                      */
#define S2_A         S2_TYP(4, 0)   /* ASCII                        */
#define S2_U1        S2_TYP(6, 0)   /* Unsigned Integer 1-Byte      */
#define S2_U2        S2_TYP(6, 1)   /* Unsigned Integer 2-Byte      */
#define S2_U4        S2_TYP(6, 2)   /* Unsigned Integer 4-Byte      */
#define S2_U8        S2_TYP(6, 3)   /* Unsigned Integer 8-Byte      */
#define S2_I1        S2_TYP(7, 0)   /* Signed Integer 1-Byte        */
#define S2_I2        S2_TYP(7, 1)   /* Signed Integer 2-Byte        */
#define S2_I4        S2_TYP(7, 2)   /* Signed Integer 4-Byte        */
#define S2_I8        S2_TYP(7, 3)   /* Signed Integer 8-Byte        */
#define S2_F4        S2_TYP(8, 2)   /* Floating Point 32-Bit        */
#define S2_F8        S2_TYP(8, 3)   /* Floating Point 64-Bit        */
#define S2_STRING    S2_TYP(9, 0)   /* 'string' target              */
#define S2_LONG      S2_TYP(12, 2)  /* 'long' target                */
#define S2_DOUBLE    S2_TYP(13, 3)  /* 'double' target              */
#define S2_CHAR      S2_TYP(12, 0)  /* 'char' target                */

/**************** MESSAGES USED BETWEEN HANDLER AND SECSGEM APPLICATION **************/
#define SG_CONTROL_STATE_CHANGE              3
#define SG_SPOOL_STATE_CHANGE                4
#define SG_LINK_STATE_CHANGE                 5
#define REMOTE_COMMAND_RECEIVED              7
#define RECIPE_ADDED                         9
#define RECIPE_DELETED                      10
#define GO_ONLINE                           11
#define GO_OFFLINE                          12
#define GO_REMOTE                           13
#define GO_LOCAL                            14
#define DISABLE_LINK                        15
#define ENABLE_LINK                         16
#define WAFERMAP_RECEIVED_AND_SAVED         17
#define RECIPE_DOWNLOADED                   18
#define WM_SDRLOGGING_MESSAGE               19
#define DISPLAY_TERMINAL_MSG                20
#define WM_TERMINAL_MESSAGE_DIALOG_DISPLAY  21
#define RESET_DATA                          22
#define UPDATE_RECIPE                       23
#define CLEAR_ALL_ALARM                     24
#define ASSIGN_SECSGEM_STATUS               25
#define DOWNLOAD_RECIPE                     26
#define UPLOAD_DATA                         27
#define ADD_USER_RECIPE                     28
#define UPDATED_RECIPE_LIST                 29
#define DELETE_RECIPE                       30
#define UPLOAD_RECIPE                       31
#define DOWNLOAD_DATA                       32
#define DOWNLOAD_WAFERMAP                   33
#define UPLOAD_WAFERMAP                     34
#define WAFERMAP_UPLOADED                   35
#define DOWNLOAD_STRIPMAP                   36
#define STRIPMAP_DOWNLOADED                 37
#define ADDED_USER_RECIPE                   38
#define UPLOADED_DATA                       39
#define DOWNLOADED_DATA                     40
#define UPLOADED_RECIPE                     41
#define MACHINE_STATE_MSG                   42
#define USER_LEVEL_MSG                      43
#define MAINMODE_MSG                        44
#define CURRENT_MACHINE_STATE_MSG           45
#define CURRENT_USER_LEVEL_MSG              46
#define CURRENT_MAINMODE_MSG                47

#define REMOTECOMMAND_REPLY_MSG_MIN         48
#define REMOTECOMMAND_REPLY_MSG_ACK         49
#define REMOTECOMMAND_REPLY_MSG_MAX         50

#define E10_STATE_CHANGE                    51

#define HANDLER_RECEIVED_MSG                52

#define ECID_CHANGED                        53 // phyu 10May2010

#define DELETED_ALL_RECIPE                  54 // Phyu 30 Oct 2009
#define EDITED_RECIPE                       55 // Phyu 30 Oct 2009

#define SG_CONTROL_STATE_KEYNAME            "GemControlState"
#define SG_SPOOL_STATE_KEYNAME              "GemSpoolState"
#define SG_LINK_STATE_KEYNAME               "GemLinkState"
#define DOWNLOAD_RECIPE_KEYNAME             "Download Recipe"
#define UPLOAD_DATA_KEYNAME                 "Upload Data"
#define ADD_USER_RECIPE_KEYNAME             "Add User Recipe"
#define DELETE_RECIPE_KEYNAME               "Delete Recipe"
#define UPLOAD_RECIPE_KEYNAME               "Upload Recipe"
#define DOWNLOAD_DATA_KEYNAME               "Download Data"
#define WAFER_MATERIAL_ID                   "Material ID"
#define WAFER_ID_TYPE                       "ID Type"
#define WAFER_FORMAT                        "Map Format"
#define WAFER_FILE_NOTCH_LOCATION           "FlatNotch Location"
#define WAFER_FILM_FRAME_ROATION            "Film Frame Rotation"
#define WAFER_ORIGIN_LOCATION               "Origin Location"
#define WAFER_PROCESS_AXIS                  "Process Axis"
#define WAFER_BINCODE_EQUIVALENT            "BinCode Equivalent"
#define WAFER_NULLBINCODE                   "Null BinCode"
#define UPLOAD_WAFERMAP_KEYNAME             "Upload WaferMap File"
#define STRIP_MATERIAL_ID                   "Material ID"
#define DOWNLOADED_STRIPMAP_ID              "Downloaded Strip Map"
#define WAFER_MAP_FILENAME_KEYNAME          "WaferMapFileName"
#define RMT_CMD_RECEIVED_KEYNAME            "RemoteCommandReceived"
#define SG_RECIPE_NAME_KEYNAME              "RecipeName"
#define ADDED_RECIPE_NAME_KEYNAME           "Added Recipe Name"
#define UPLOADED_WAFERMAP_KEYNAME           "Uploaded WaferMap File"
#define UPLOADED_DATASET_KEYNAME            "Uploaded Dataset Name"
#define DOWNLOADED_DATASET_KEYNAME          "Downloaded Dataset Name"
#define UPLOADED_RECIPE_KEYNAME             "Uploaded Recipe Name"
#define DELETED_RECIPE_KEYNAME              "Deleted Recipe Name"
#define RECEIVED_MESSAGE_KEYNAME            "Received Message"
#define E10_STATE                           "E10State"
#define ALL_DELETED_RECIPE_KEYNAME          "All Deleted Recipe Name" // Phyu 02Nov2009
#define EDITED_RECIPE_KEYNAME           "Edit Recipe Name"            // Phyu 02Nov2009

// FORMAT SendS12F3(char *strMaterialID,int iIDType, int iMapFormat, int iFNLoc, int iFFRotAngle, int iOrginLoc, int iProcessAxis, char * strBinCodeEq, char * strNullBinCdVal)
// GetMappingDataFromHost(sztmp,2,1,iFNLoc,0,0,0,strBinCodeEq,strNullBinCdVal))
#define TOHANDLER_INI   "C:\\Gem\\GwGemCPP\\TISECSGEM\\TOHANDLER.INI"
#define TOSECSGEM_INI   "C:\\Gem\\GwGemCPP\\TISECSGEM\\TOSECSGEM.INI"
#define TISECSGEM_EXE   "C:\\Gem\\GWGemCPP\\TISecsGem\\Bin\\TISecsGem.exe";

/*************************************************************************************/
/********************************* SECSGEM TO HANDLER COMMANDS***********************/
#define CMD_SG_APPLICATION                  "#S2H_SG_APPLN"
#define CMD_CONTROLSTATE                    "#S2H_CONTROL_STATE"
#define CMD_LINKSTATE                       "#S2H_LINK_STATE"
#define CMD_SPOOLSTATE                      "#S2H_SPOOL_STATE"
#define CMD_WAFERMAP_DOWNLOADED             "#S2H_WAFERMAP_DOWNLOADED"
#define CMD_STRIPMAP_DOWNLOADED             "#S2H_STRIPMAP_DOWNLOADED"
#define CMD_WAFERMAP_UPLOADED               "#S2H_WAFERMAP_UPLOADED"
#define CMD_RECIPE_DOWNLOADED               "#S2H_RECIPE_DOWNLOADED"
#define CMD_RECIPE_UPLOADED                 "#S2H_RECIPE_UPLOADED"
#define CMD_RECIPE_DELETED                  "#S2H_RECIPE_DELETED"
#define CMD_ADDED_RECIPE                    "#S2H_RECIPE_ADDED"
#define CMD_DATASET_UPLOADED                "#S2H_DATASET_UPLOADED"
#define CMD_DATASET_DOWNLOADED              "#S2H_DATASET_DOWNLOADED"
#define CMD_UPDATED_RECIPE_LIST             "#S2H_UPDATED_RECIPE_LIST"
#define CMD_REMOTE_CMD_RECEIVED             "#S2H_REMOTE_CMD_RECEIVED"
#define CMD_E10STATE                        "#S2H_E10STATE"
#define CMD_ALL_RECIPE_DELETED              "#S2H_ALL_RECIPE_DELETED" // Phyu 30 Oct 2009
#define CMD_RECIPE_EDITED                   "#S2H_RECIPE_EDITED"      // Phyu 02Nov2009
#define CMD_EC_CHANGED                      "#S2H_EC_CHANGED"         // Phyu 10May2010
/*************************************************************************************/
#define CMD_H2S_CLOSE_SG_APPLN              "#H2S_CLOSE_SG_APPLN"
#define CMD_H2S_SGCOMMAND_GOONLINE          "#H2S_SGCOMMAND_GOONLINE"
#define CMD_H2S_SGCOMMAND_GOOFFLINE         "#H2S_SGCOMMAND_GOOFFLINE"
#define CMD_H2S_SGCOMMAND_GOREMOTE          "#H2S_SGCOMMAND_GOREMOTE"
#define CMD_H2S_SGCOMMAND_GOLOCAL           "#H2S_SGCOMMAND_GOLOCAL"
#define CMD_H2S_SGCOMMAND_DISABLELINK       "#H2S_SGCOMMAND_DISABLELINK"
#define CMD_H2S_SGCOMMAND_ENABLELINK        "#H2S_SGCOMMAND_ENABLELINK"
#define CMD_H2S_MAINMODE                    "#H2S_MAINMODE"
#define CMD_H2S_USERLEVEL                   "#H2S_USERLEVEL"
#define CMD_H2S_MACHINE_STATE               "#H2S_MACHINE_STATE"
#define CMD_H2S_CURRENT_MAINMODE            "#H2S_CURRENT_MAINMODE"
#define CMD_H2S_CURRENT_USERLEVEL           "#H2S_CURRENT_USERLEVEL"
#define CMD_H2S_CURRENT_MACHINE_STATE       "#H2S_CURRENT_MACHINE_STATE"
#define CMD_H2S_SEND_EVENT                  "#H2S_SEND_EVENT"
#define CMD_H2S_SET_VARIABLE_VALUE          "#H2S_SET_VARIABLE_VALUE"
#define CMD_H2S_SEND_ALARM                  "#H2S_SEND_ALARM"
#define CMD_H2S_DOWNLOAD_RECIPE             "#H2S_DOWNLOAD_RECIPE"
#define CMD_H2S_UPLOAD_DATA                 "#H2S_UPLOAD_DATA"
#define CMD_H2S_ADD_RECIPE                  "#H2S_ADD_RECIPE"
#define CMD_H2S_RESET_DATA                  "#H2S_RESET_DATA"
#define CMD_H2S_DELETE_RECIPE               "#H2S_DELETE_RECIPE"
#define CMD_H2S_UPLOAD_RECIPE               "#H2S_UPLOAD_RECIPE"
#define CMD_H2S_DOWNLOAD_DATA               "#H2S_DOWNLOAD_DATA"
#define CMD_H2S_WAFER_MAP_DOWNLOAD          "#H2S_WAFER_MAP_DOWNLOAD"
#define CMD_H2S_UPLOAD_WAFERMAP             "#H2S_UPLOAD_WAFERMAP"
#define CMD_H2S_DOWNLOAD_STRIPMAP           "#H2S_DOWNLOAD_STRIPMAP"
#define CMD_H2S_DISPLAY_TERMINAL_MSG_DLG    "#H2S_DISPLAY_TERMINAL_MSG_DLG"
#define CMD_H2S_UPDATE_RECIPE_LIST          "#H2S_UPDATE_RECIPE_LIST"
#define CMD_CLEAR_ALL_ALARM                 "#H2S_CLEAR_ALL_ALARM"
#define CMD_ACKNOWLEDGE_REMOTE_CMD          "#H2S_ACK_REMOTE_COMMAND"

#define CMD_H2S_RECIPE_VERIFICATION         "#H2S_RECIPE_VERIFICATION" // Phyu 08 Oct 2009

#define CMD_H2S_EDIT_RECIPE                 "#H2S_EDIT_RECIPE"         // Phyu 30 Oct 2009
#define CMD_H2S_DELETE_ALL_RECIPE           "#H2S_DELETE_ALL_RECIPE"   // Phyu 30 Oct 2009
#define CMD_H2S_EPT_STATE                   "#H2S_EPT_STATE"           // Phyu 04Jan2009

/*************************************************************************************/
/*************************************************************************************/
#define GW_CMD_HAS_BEEN_PERFORMED_HCACK 0
#define GW_CMD_DOES_NOT_EXIST_HCACK 1
#define GW_CMD_CANNOT_BE_PERFORMED_NOW_HCACK 2
#define GW_CMD_HAS_BAD_PARAMETER_HCACK 3
#define GW_CMD_WILL_PERFORM_LATER_HCACK 4
#define GW_CMD_REJECTED_ALREADY_DESIRED_CONDITION_HCACK 5
#define GW_CMD_NO_SUCH_OBJECT_EXIST_HCACK 6
#define GW_CMD_HANDLER_REJECT_HCACK 7
#define GW_CMD_HANDLER_TIMEOUT_HCACK 8
#define GW_CMD_HANDLER_PROCESS_FAIL_HCACK 9 // Phyu 11Aug2010
/************************************************************************************/
/************************************************************************************/
// EPT Data
enum BLOCKREASON
{
    NOT_BLOCKED = 0,
    UNKNOWN,
    SAFETY_THRESHOLD,
    ERROR_CONDITION,
    PARAMETRIC_EXCEPTION,
    ABORTING_ABORTED,
    PAUSING_PAUSED,
    RESERVED1,
    RESERVED2,
    RESERVED3,
    MAX_BLOCKEDREASON
};

enum EPT_STATE
{
    EPT_IDLE = 0,
    EPT_BUSY,
    EPT_BLOCKED,
    EPT_NO_STATE
};

enum EPT_TASK_TYPE
{
    N0_TASK = 0,
    UNSPECIFIED,
    PROCESS,
    SUPPORT,
    EQUIPMENT_MAINTENANCE,
    EQUIPMENT_DIAGNOSTICS,
    WAITING,
    MAX_TASKTYPE
};

struct g_stRemoteCmd // phyu 02-Oct-2012
{
    char cRemoteName[256];
    int nReply;
};
/************************************************************************************/
