#pragma once

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

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

    REMOTECOMMAND_REPLY_MSG_MIN = 48,
    REMOTECOMMAND_REPLY_MSG_ACK = 49,
    REMOTECOMMAND_REPLY_MSG_MAX = 50,

    E10_STATE_CHANGE = 51,

    HANDLER_RECEIVED_MSG = 52,

    ECID_CHANGED = 53,

    DELETED_ALL_RECIPE = 54,
    EDITED_RECIPE      = 55
};

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

// 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))
constexpr const char* TOHANDLER_INI = "C:\\Gem\\GwGemCPP\\TISECSGEM\\TOHANDLER.INI";
constexpr const char* TOSECSGEM_INI = "C:\\Gem\\GwGemCPP\\TISECSGEM\\TOSECSGEM.INI";
constexpr const char* TISECSGEM_EXE = "C:\\Gem\\GWGemCPP\\TISecsGem\\Bin\\TISecsGem.exe";

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

constexpr const char* CMD_H2S_RECIPE_VERIFICATION = "#H2S_RECIPE_VERIFICATION";

constexpr const char* CMD_H2S_EDIT_RECIPE       = "#H2S_EDIT_RECIPE";
constexpr const char* CMD_H2S_DELETE_ALL_RECIPE = "#H2S_DELETE_ALL_RECIPE";
constexpr const char* CMD_H2S_EPT_STATE         = "#H2S_EPT_STATE";

/*************************************************************************************/
/*************************************************************************************/
enum class REMOTE_ACK_CODE
{
    HAS_BEEN_PERFORMED_HCACK                 = 0,
    DOES_NOT_EXIST_HCACK                     = 1,
    CANNOT_BE_PERFORMED_NOW_HCACK            = 2,
    HAS_BAD_PARAMETER_HCACK                  = 3,
    WILL_PERFORM_LATER_HCACK                 = 4,
    REJECTED_ALREADY_DESIRED_CONDITION_HCACK = 5,
    NO_SUCH_OBJECT_EXIST_HCACK               = 6,
    HANDLER_REJECT_HCACK                     = 7,
    HANDLER_TIMEOUT_HCACK                    = 8,
    HANDLER_PROCESS_FAIL_HCACK               = 9
};
/************************************************************************************/
/************************************************************************************/
// EPT Data
enum BLOCKREASON
{
    NOT_BLOCKED = 0,
    UNKNOWN,
    SAFETY_THRESHOLD,
    ERROR_CONDITION,
    PARAMETRIC_EXCEPTION,
    ABORTING_ABORTED,
    PAUSING_PAUSED,
    RESERVED1,
    RESERVED2,
    RESERVED3,
    MAX_BLOCKEDREASON
};

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

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

using g_stRemoteCmd = struct _stRemoteCmd
{
    char cRemoteName[256]{};
    int  nReply{};
};
/************************************************************************************/
