#include "SecsManager.h"
#include "SecsBase.h"
#include "SecsEquip.h"
#include "logic.h"
#include "cgemdriver.h"
#include "claserdriver_base.h"
//#include "driversecsmes.h"
//#include "claserpathdriver_epulse.h"
//#include "claserpathdriver_thorlab.h"
#pragma comment(lib,"SecsPort.lib")
SecsManager g_SecsManager;

SecsManager::SecsManager()
{
	m_pSecs = nullptr;
	m_CurCommState = eCOMM_DISABLED;//当前的通信状态
	m_CurCtrlState = eCONTROL_OFFLINE_EQUIPMENT;//当前的控制状态
}

SecsManager::~SecsManager()
{
	if(nullptr != m_pSecs)
	{
		m_pSecs->Abort();
		delete m_pSecs;
	}
}

int SecsManager::InitConnect()
{
    if(m_gSystem.IsSimulator()) {
        return 0;
    }

	m_pSecs = new CSecsEquip();
	RcResult rc = m_pSecs->Start();

	if (rc.rc != 0)
	{
		m_pSecs->Abort();
		delete m_pSecs;
		m_pSecs = nullptr;
		//MessageBox(rc.ToString().c_str(), "JNG_Server.exe没有初始化");

		//// 暴力退出不推荐
		//exit(0);

        return rc.rc;
	}

	//DriverSecsMES* pSecsMES = GET_CARD(CARD_SECS_MES, DriverSecsMES);

	// 初始化其他
	// 设置参数
	/*rc = m_pSecs->SetIP(pSecsMES->m_pAddress);
	rc = m_pSecs->SetPort(pSecsMES->m_nPort);
	rc = m_pSecs->SetPassive(pSecsMES->m_bPassive);
	rc = m_pSecs->SetDeviceID(pSecsMES->m_nDeviceID);
	rc = m_pSecs->SetMDLN(pSecsMES->m_pInterfaceName);
	rc = m_pSecs->SetEnableLog(pSecsMES->m_bEnableLog);

	rc = m_pSecs->SetT1(pSecsMES->m_nTimeout[0]);
	rc = m_pSecs->SetT2(pSecsMES->m_nTimeout[1]);
	rc = m_pSecs->SetT3(pSecsMES->m_nTimeout[2]);
	rc = m_pSecs->SetT4(pSecsMES->m_nTimeout[3]);
	rc = m_pSecs->SetT5(pSecsMES->m_nTimeout[4]);
	rc = m_pSecs->SetT6(pSecsMES->m_nTimeout[5]);
	rc = m_pSecs->SetT7(pSecsMES->m_nTimeout[6]);*/

	CGEMDriver* pDrvier = GET_CARD(GEM_DRIVER_JNG, CGEMDriver);
	Q_ASSERT(pDrvier);

	//add param
	rc = m_pSecs->SetIP(pDrvier->m_Variants.get_VData(Var_MES_ClientIP)->toString().toStdString().c_str());
	rc = m_pSecs->SetPort(pDrvier->m_Variants.get_VData(Var_MES_ClientPort)->toInt());
	rc = m_pSecs->SetPassive(pDrvier->m_Variants.get_VData(Var_MES_IsPassive)->toBool());
	rc = m_pSecs->SetDeviceID(pDrvier->m_Variants.get_VData(Var_MES_DeviceID)->toInt());
	rc = m_pSecs->SetMDLN(pDrvier->m_Variants.get_VData(Var_MES_MDLN)->toString().toStdString().c_str());
	rc = m_pSecs->SetEnableLog(pDrvier->m_Variants.get_VData(Var_MES_EnableLog)->toBool());

	rc = m_pSecs->SetT1(pDrvier->m_Variants.get_VData(Var_MES_Timeout1)->toInt());
	rc = m_pSecs->SetT2(pDrvier->m_Variants.get_VData(Var_MES_Timeout2)->toInt());
	rc = m_pSecs->SetT3(pDrvier->m_Variants.get_VData(Var_MES_Timeout3)->toInt());
	rc = m_pSecs->SetT4(pDrvier->m_Variants.get_VData(Var_MES_Timeout4)->toInt());
	rc = m_pSecs->SetT5(pDrvier->m_Variants.get_VData(Var_MES_Timeout5)->toInt());
	rc = m_pSecs->SetT6(pDrvier->m_Variants.get_VData(Var_MES_Timeout6)->toInt());
	rc = m_pSecs->SetT7(pDrvier->m_Variants.get_VData(Var_MES_Timeout7)->toInt());

	m_pSecs->SetRecipeDirectory(CMakePath::make_data_path(pDrvier->m_Variants.get_VData(Var_MES_RecipeRoot)->toString().toStdString().c_str()).toStdString());
	m_pSecs->PPAllowHostDowmload(pDrvier->m_Variants.get_VData(Var_MES_AllowHostDownload)->toBool());

	m_pSecs->SetSOFTREV(pDrvier->m_Variants.get_VData(Var_MES_SoftVersion)->toString().toStdString().c_str());

	/*m_pSecs->SetMDLN("LS1530G1");
	m_pSecs->SetDeviceID(0);
	m_pSecs->SetSOFTREV("1.0.0");*/

	// 设置winrar.exe的路径
	// 如果recipe是单个文档，无需设置
	//m_pSecs->SetWinrarPath("C:/Program Files/WinRAR/WinRAR.exe");

	// 设置回调
	m_pSecs->SetClientData(this);
	m_pSecs->m_pTerminalCallback = ::OnTerminalProc;
	m_pSecs->m_pStateChangeCallback = ::OnStateChangeProc;
	m_pSecs->m_pRemoteCallback = ::OnRemoteProc;

	// 示例的回调	
	m_pSecs->m_pConstantsChangeCallback = ::OnConstantChangeProc;
	m_pSecs->m_pVarValueProc = ::OnVarValueProc;
	m_pSecs->m_pConstantValueProc = ::OnConstVarValueProc;
	m_pSecs->m_pPPNameListProc = ::OnPPNameListProc;
	m_pSecs->m_pPPEventProc = ::OnSecsPPEventProc;
	// 示例的回调内容结束	

	// 特殊
	m_pSecs->m_pPPFormatValueProc = OnPPFormatValueProc;

	// 通过Csv文件加载配置
	rc = m_pSecs->LoadDataByCsvFile();
	//SHOW_MSG_RC(rc);



	uint ctlMode = pDrvier->m_Variants.get_VData(Var_MES_ControlMode)->toUInt();
	// 建立通讯
	//rc = m_pSecs->SetControlMode((CONTROL_MODE)pSecsMES->m_nControlMode);
	rc = m_pSecs->SetControlMode((CONTROL_MODE)ctlMode);

	bool bCommEnable = pDrvier->m_Variants.get_VData(Var_MES_EnableComm)->toBool();
	if(bCommEnable)
		rc = m_pSecs->CommEnable();

    return 0;

}

void SecsManager::UninitConnect()
{
    if (m_pSecs != nullptr)
	{
		QMutexLocker l(&m_Mutex);
		//注销回调函数，要不然会卡住
		m_pSecs->m_pTerminalCallback = nullptr;
		m_pSecs->m_pStateChangeCallback = nullptr;
		m_pSecs->m_pRemoteCallback = nullptr;
		m_pSecs->m_pRemoteExCallback = nullptr;
		m_pSecs->m_pConstantsChangeCallback = nullptr;
		m_pSecs->m_pClockProc = nullptr;

		m_pSecs->Abort();
		//gLogMgr->WriteDebugLog("Secs---->Secs Abort");
		delete m_pSecs;
		m_pSecs = nullptr;
	}
}

bool SecsManager::SendEvent(_EventID eventID)
{
	//LOG(INFO)<<"Send Event:" << eventID;
    QMutexLocker l(&m_Mutex);
	if(nullptr == m_pSecs) {
		return false;
	}
	//执行发送
	RcResult rc = m_pSecs->EventPos(eventID);
	if (rc.rc != 0)
	{
		QString s = QString::asprintf("Ret---->SendEvent Failed[id=%d]", eventID);
		//gLogMgr->WriteDebugLog(s);
        //LOG_ERR(s.toStdString());
		return false;
	}

	return true;
}

bool SecsManager::SendAlarm(_ALAM_ID alarmID)
{
    QMutexLocker l(&m_Mutex);
	if(nullptr == m_pSecs) {
		return false;
	}
	if(alarmID<ALARM_RESERVED && alarmID>=ALARM_MACHINE_RESERVED){
		return false;
	}

	RcResult rc = m_pSecs->AlarmSet(alarmID, true);
	if (rc.rc != 0)
	{
		QString s = QString::asprintf("Ret---->SendAlarm Failed[id=%d]", alarmID);
		//LOG(INFO) << INFO_TITTLE()<< s.toLatin1().data();
		return false;
	}
	m_TriggerAlarm.insert(alarmID);
	return true;
}

bool SecsManager::SendAlarmClear(_ALAM_ID alarmID)
{
    QMutexLocker l(&m_Mutex);
	if(nullptr == m_pSecs) {
		return false;
	}

	if(alarmID<ALARM_RESERVED && alarmID>=ALARM_MACHINE_RESERVED){
		return false;
	}

	RcResult rc = m_pSecs->AlarmSet(alarmID, false);
	if (rc.rc != 0)
	{
		QString s = QString::asprintf("Ret---->ClearAlarm Failed[id=%d]", alarmID);
		//gLogMgr->WriteDebugLog(s);
		//LOG(INFO) << INFO_TITTLE() << s.toLatin1().data();
		return false;
	}
	m_TriggerAlarm.erase(alarmID);
    return true;
}

void SecsManager::ClearAllAlarm()
{
    if(nullptr == m_pSecs) {
        return;
    }

	std::set<int> listAlarm;
	{
		QMutexLocker l(&m_Mutex);
		if (nullptr == m_pSecs)
		{
			m_TriggerAlarm.clear();
			return;
		}

		listAlarm = m_TriggerAlarm;
	}
	for (auto iter = listAlarm.begin(); iter != listAlarm.end(); iter++) {
		_ALAM_ID alarmId = (_ALAM_ID)(*iter);
		SendAlarmClear(alarmId);
	}

    //LOG_INFO("Clear all alarm");
}

bool SecsManager::SwitchCommEnable(bool enable)
{
    QMutexLocker l(&m_Mutex);
	if(nullptr == m_pSecs) {
		return false;
	}

    if(enable == true){
        m_pSecs->CommEnable();
    }else{
       m_pSecs->CommDisable();
    }

    return true;
}

bool SecsManager::SwitchCtrlMode(CONTROL_MODE mode)
{
    QMutexLocker l(&m_Mutex);
	if(nullptr == m_pSecs) {
		return false;
	}

    m_pSecs->SetControlMode(mode);


	CGEMDriver* pDrvier = GET_CARD(GEM_DRIVER_JNG, CGEMDriver);
	pDrvier->m_Variants.get_VData(Var_MES_ControlMode)->setValue((uint)mode);

    return true;
}

bool SecsManager::SetVariable(_SVID svid, const string newValue)
{
	if(m_pSecs == nullptr) {
		return false;
	}

	RcResult rc = m_pSecs->VariableSet(svid, newValue);
	return rc.rc == 0;
}

bool SecsManager::OnSetConstVariable(_ECID ecid, const string newValue)
{
	switch(ecid){
	case ECID_REERVED:
		break;
	case ECID_QualityCheckMethod:
		break;
	case ECID_LaserPowerCheckMethod:
		break;
	case ECID_LaserPowerCheckTimeInterval:
		break;
	case ECID_LaserPowerCheckEvervyPCSInterval:
		break;
	case ECID_LaserPowerCheckPowerAllowRange:
		break;
	case ECID_LocationDiameterAllowRange:
		break;
	case ECID_BeforeLocationStableTime:
		break;
	case ECID_BeforeAlignStableTime:
		break;
	case ECID_BeforeKerfStableTime:
		break;
	case ECID_AfterLocationStableTime:
		break;
	case ECID_AfterAlignStableTime:
		break;
	case ECID_AfterKerfStableTime:
		break;
	default:
		break;
	}
	return true;
}

string SecsManager::GetCommStateStr(COMM_STATE State)

{
	string s;
	switch (State)
	{
	case eCOMM_DISABLED:
		s = "DISABLE";
		break;
	case eCOMM_ENABLED_NOT_COMMUNICATING:
		s = "NOT COMMUNICATION";
		break;
	case eCOMM_COMMUNICATING:
		s = "COMMUNICATION";
		break;
	default:
		s = "Unkown";
		break;
	}
	return s;
}

string SecsManager::GetCtrlStateStr(CONTROL_STATE State)
{
	string s;
	switch (State)
	{
	case eCONTROL_OFFLINE_EQUIPMENT:
		s = "OFF-LINE Equip";
		break;
	case eCONTROL_OFFLINE_ATTEMPT_ONLINE:
		s = "OFF-LINE Attempt Online";
		break;
	case eCONTROL_OFFLINE_HOST:
		s = "OFF-LINE Host";
		break;
	case eCONTROL_ONLINE_LOCAL:
		s = "ON-LINE Local";
		break;
	case eCONTROL_ONLINE_REMOTE:
		s = "ON-LINE Remote";
		break;
	default:
		s = "Unkown";
		break;
	}
	return s;
}

void SecsManager::setCurCommState(const COMM_STATE &CurCommState)
{
    m_CurCommState = CurCommState;
	//TODO:
	//m_gSystem.SendEAPStateChange();
}

void SecsManager::setCurCtrlState(const CONTROL_STATE &CurCtrlState)
{
    m_CurCtrlState = CurCtrlState;
	//TODO:
    //m_gSystem.SendEAPStateChange();
}

int SecsManager::getControlMode()
{
    //return m_pSecs->m_nControlMode;
	return 1;
}

bool SecsManager::getCommEnable()
{
	/*DriverSecsMES* pSecsMES = GET_CARD(CARD_SECS_MES, DriverSecsMES);
	return pSecsMES->m_bCommEnable;*/
	return true;
}

CONTROL_STATE SecsManager::getCurCtrlState() const
{
    return m_CurCtrlState;
}

COMM_STATE SecsManager::getCurCommState() const
{
    return m_CurCommState;
}

void SecsManager::OnReciveTerminalMsg(string s)
{
	m_gSystem.SendTerminalMessage(s);
}

const char * SecsManager::SecsVarValue(int vId)
{
	static string result = "";
	result = "";
	_SVID svId = (_SVID)vId;
	switch(svId){
	case SVID_RESERVED:
		break;
	case SVID_PPRootFolder:
		result = "data";
		break;
	case SVID_PPExeName:
		result = m_gSystem.GetCurFile().toStdString();
		break;
	case SVID_SlotID:
		result = "";
		break;
	case SVID_TransWaferID:
		break;
	case SVID_CoatingWaferID:
		break;
	case SVID_CleaningWaferID:
		break;
	case SVID_CuttingWaferID:
		break;
	case SVID_CuttingCheckWaferID:
		break;
	case SVID_CoatingQualityCheckWaferID:
		break;
	case SVID_CoatingLiquidUsedVolume:
		{
#ifdef __USE_CLEAR_COAT_STAGE__
			CProcess_Coat* pCoat=GET_PROCESS(PROCESS_COAT,
			SM_COAT,CProcess_Coat);
			result = QString::number(pCoat->m_dTotalBump, 'f', 2).toStdString();
#endif
		}
		break;
	case SVID_CoatingLiquidDetectedVolume:
		{
#ifdef __USE_CLEAR_COAT_STAGE__
			CProcess_Coat* pCoat = GET_PROCESS(PROCESS_COAT,
			SM_COAT,CProcess_Coat);
			result = QString::number(pCoat->m_dVolumeActual, 'f', 2).toStdString();
#endif
		}	
		break;
	case SVID_CuttingSpeed:
		break;
	case SVID_CuttingPower:
		{
			/*CLaserPathDriver_Epulse* pPathDriver=GET_CARD(LASERPATH_DRIVER,CLaserPathDriver_Epulse);
			result = QString::number((int)pPathDriver->m_dCurPower).toStdString();*/
		}
		break;
	case SVID_LaserFreq:
		{
            /*CLaserPathDriver_Epulse* pPathDriver=GET_CARD(LASERPATH_DRIVER,CLaserPathDriver_Epulse);
            result = QString::number((int)pPathDriver->m_dFreq).toStdString();*/
		}
		break;
	case SVID_LaserEpulseFreq:
		{
			CLaserDriver_Base* pLaserDriver = GET_CARD(LASER_DRIVER, CLaserDriver_Base);
			result = QString::number(pLaserDriver->m_iEpulseFreq).toStdString();
		}
		
		break;
	case SVID_LaserElectricCurrent:
		{
			CLaserDriver_Base* pLaserDriver = GET_CARD(LASER_DRIVER, CLaserDriver_Base);
			result = QString::number(pLaserDriver->m_dDiode, 'f', 2).toStdString();
		}
		break;
	case SVID_LaserTemperature:
		{
			CLaserDriver_Base* pLaserDriver = GET_CARD(LASER_DRIVER, CLaserDriver_Base);
			result = QString::number(pLaserDriver->m_dTemperature, 'f', 2).toStdString();
		}
		break;
	case SVID_LaserCheckPower:
		break;
	case SVID_LaserDetectedPower:
		break;
	default:
		break;

	}

	return result.c_str();
}

const char * SecsManager::SecsVarConstValue(int cId)
{
	static string ecid_result = "";

	_ECID ecid = (_ECID)cId;
	switch(ecid){
	case ECID_REERVED:
		break;
	case ECID_QualityCheckMethod:
		break;
	case ECID_LaserPowerCheckMethod:
		break;
	case ECID_LaserPowerCheckTimeInterval:
		break;
	case ECID_LaserPowerCheckEvervyPCSInterval:
		break;
	case ECID_LaserPowerCheckPowerAllowRange:
		break;
	case ECID_LocationDiameterAllowRange:
		break;
	case ECID_BeforeLocationStableTime:
		break;
	case ECID_BeforeAlignStableTime:
		break;
	case ECID_BeforeKerfStableTime:
		break;
	case ECID_AfterLocationStableTime:
		break;
	case ECID_AfterAlignStableTime:
		break;
	case ECID_AfterKerfStableTime:
		break;
	default:
		break;

	}

	return ecid_result.c_str();
}

const char* SecsManager::SecsPPFormatValue(PP_FORMAT_CMD pp_cmd, const char* pCmd)
{
	if(pp_cmd == eLOAD_TMP_PPID){
		//导出Recipe
		//成功返回"0"
		return 0;
	}else if(pp_cmd == eGET_PPID_VALUE){
		int nCode = atoi(pCmd);
		switch(nCode){
		case 1:
			return "param1";
		case 2:
			return "param2";

		}
	}
	return "";
}

// 状态改变
void OnStateChangeProc(CSecsEquip* pSH, const char* varname, int nState)
{
    SecsManager* pHV = (SecsManager*)pSH->GetClientData();
	if (pHV != nullptr)
	{
		string pType = varname;
		if (pType == "comm_state")
		{
			pHV->setCurCommState((COMM_STATE)nState);
		}
		else if (pType == "control_state")
		{
			pHV->setCurCtrlState((CONTROL_STATE)nState);
		}
	}
}

// 远程
REMOTE_REPLY OnRemoteProc(CSecsEquip* pSH, REMOTE_DATA* pRD)
{
	if(pRD->pRCMD == "JOB_START"){
		m_gSystem.publish_msg(V_Msg(VarMsg_StartAuto_ID,
			QObject::trUtf8("Start Auto")));
		return ::eCOMMAND_PERFORMED;
	}else if(pRD->pRCMD == "JOB_START"){
		//TODO:检查状态后才能执行
		m_gSystem.publish_msg(V_Msg(VarMsg_StartAuto_ID,
			QObject::trUtf8("Start Auto")));
		return ::eCOMMAND_PERFORMED;
	}
	else if(pRD->pRCMD == "JOB_PAUSE")
	{
		//TODO:检查状态后才能执行
		m_gSystem.FindSM(SM_MAIN)->pushfront_Msg(VarMsg_Pause_ID,
			QObject::trUtf8("Pause Sig"));

		m_gSystem.FindSM(SM_TRANS)->pushfront_Msg(VarMsg_Pause_ID,
			QObject::trUtf8("Pause Sig"));

		//TODO:如果涂敷或清洗还在运行，则后续再返回

		//TODO:如果涂敷清洗完成了，则直接返回

		return ::eCOMMAND_ACK_AND_WITH_SIGNAL;
	}
	else if(pRD->pRCMD == "JOB_STOP"){
		//TODO:检查状态后才能执行
		m_gSystem.publish_msg(V_Msg(VarMsg_Stop_ID,QObject::trUtf8("Stop All")));
		m_gSystem.m_totalWorkTime.PauseTime();
		return ::eCOMMAND_PERFORMED;
	}

	return eCOMMAND_NOT_EXIST;
}

// 远程
void OnRemoteProcEx(CSecsEquip* pSH, string pReplyMailbox, REMOTE_DATA rd)
{
	//CEquipViewAppDlg* pHV = (CEquipViewAppDlg*)pSH->GetClientData();

	//REMOTE_REPLY nHack = eCOMMAND_PERFORMED;
	//if (pHV != nullptr)
	//{
	//	REMOTE_REPLY nHack = (REMOTE_REPLY)pHV->SendMsgToView("Remote", ON_REMOTE, 0, (LPARAM)&rd);
	//}
	//pSH->RemoteCmdReply(pReplyMailbox, nHack);

	// 已经答复服务器，接下来可用继续处理其他事务
	// 例如阻塞的事务
	Sleep(2000);

}


// 消息
TERMINAL_REPLY OnTerminalProc(CSecsEquip* pSH, TERMINAL_DATA td)
{
	SecsManager* pHV = (SecsManager*)pSH->GetClientData();
	if (pHV != nullptr)
	{
		pHV->OnReciveTerminalMsg(td.pText);
	}
	return eDISPLAY_IN_WINDOW;
}


// 常量改变
void OnConstantChangeProc(CSecsEquip* pSH, int nID, const char* value)
{
	SecsManager* pHV = (SecsManager*)pSH->GetClientData();
	if (pHV != nullptr)
	{
		bool b;
		_ECID ecid = (_ECID)nID;
		pHV->OnSetConstVariable(ecid, value);
		return;
	}
}

// 变量数据
const char* OnVarValueProc(CSecsEquip* pSH, int var)
{
	SecsManager* pHV = (SecsManager*)pSH->GetClientData();
	if (pHV != nullptr)
	{
		return pHV->SecsVarValue(var);
	}
    return "";
}

// 变量数据
const char* OnConstVarValueProc(CSecsEquip* pSH, int var)
{
	SecsManager* pHV = (SecsManager*)pSH->GetClientData();
	if (pHV != nullptr)
	{
		return pHV->SecsVarConstValue(var);
	}

	return "";
}

// 时间改变
void OnHostClockProc(CSecsEquip*, const char* second_offset, SYSTEMTIME time)
{
	SetLocalTime(&time);
}

// PP格式化数据,获取值
void OnPPFormatValueProc(CSecsEquip* pSH, PP_FORMAT_HANDLE* pPpFormat)
{
	//CEquipViewAppDlg* pHV = (CEquipViewAppDlg*)pSH->GetClientData();
	//if (pHV != nullptr)
	//{
	//	return pHV->SecsPPFormatValue(pp_cmd, pCmd);
	//}
	SecsManager* pHV = (SecsManager*)pSH->GetClientData();
	if (pHV != nullptr)
	{
		//TODO:
	}
}

// PP列表
std::list<std::string> OnPPNameListProc(CSecsEquip*)
{
	std::list<std::string> listPP;
	return listPP;
}

// PP数据获取
// 数据需要释放
// 不会出现多线程同时调用该函数
char* pPPData = NULL;
const char* OnSecsPPDataLoadProc(CSecsEquip*, const char* ppid, int& nLength)
{
	if (pPPData != NULL)
	{
		free(pPPData);
		pPPData = NULL;
	}

	nLength = 1024 * 1;
	pPPData = (char*)malloc(nLength);
	if (pPPData != NULL)
	{
		for (int i = 0; i < nLength; i++)
		{
			pPPData[i] = i & 0xFF;
		}
	}
	return pPPData;
}

// PP数据更新
PP_HANDLE_REPLY OnSecsPPDataDownProc(CSecsEquip*, const char* ppid, const char* pData, int nLength)
{
	if (nLength >= 1024 * 1024 * 2)
	{
		return ePPLengthError;
	}

	for (int i = 0; i < nLength; i++)
	{
		if (pData[i] != (char)(i & 0xFF))
		{
			int a;
			a = 0;	//	打断点测试数据正确性
		}
	}
	return ePPSuccess;
}

PP_HANDLE_REPLY DeleteRecipe(const char* ppid)
{
	return ::ePPPermissionNotGranted;
}

PP_HANDLE_REPLY LoadInquire(const char* ppid, int nSize)
{
	return ::ePPSuccess;
	return ::ePPModeUnsupported;
}

// 自定义处理recipe
void OnSecsPPEventProc(CSecsEquip* pSE, PP_HANDLE_DATA* pPPHandleData)
{
	if (pPPHandleData->nEvent == ::ePPEventLoadData)
	{
		pPPHandleData->pPPData = OnSecsPPDataLoadProc(pSE, pPPHandleData->pPPID, pPPHandleData->nLength);
	}
	else if (pPPHandleData->nEvent == ::ePPEventDownData)
	{
		pPPHandleData->nAck = OnSecsPPDataDownProc(pSE, pPPHandleData->pPPID, pPPHandleData->pPPData, pPPHandleData->nLength);
	}
	else if (pPPHandleData->nEvent == ::ePPEventDelete)
	{
		pPPHandleData->nAck = DeleteRecipe(pPPHandleData->pPPID);
	}
	else if (pPPHandleData->nEvent == ::ePPEventLoadInquire)
	{
		pPPHandleData->nAck = LoadInquire(pPPHandleData->pPPID, pPPHandleData->nLength);
	}
}
