#include "StdAfx.h"
|
#include "StackResultCSOT.h"
|
#include "akLoggerExt.h"
|
#include "akCore/akFileDB.h"
|
#include <process.h>
|
|
#ifdef _DEBUG
|
#undef THIS_FILE
|
static char THIS_FILE[]=__FILE__;
|
#define new DEBUG_NEW
|
#endif
|
|
CStackResultCSOT::CStackResultCSOT(void)
|
{
|
m_nThreadStackFileReadFlag = 0;
|
m_strConfigFile;
|
{
|
GetModuleFileName(NULL, m_strConfigFile, MAX_PATH);
|
char* ext = CakFileUtil::getFileExt(m_strConfigFile);
|
strcpy(ext, "ini");
|
}
|
|
m_nProcessState = SPS_StateIdle;
|
readOptionFile();
|
}
|
|
CStackResultCSOT::~CStackResultCSOT(void)
|
{
|
if(m_nThreadStackFileReadFlag == 1)
|
{
|
m_nThreadStackFileReadFlag = 2;
|
while(m_nThreadStackFileReadFlag != 0)
|
{
|
Sleep(1);
|
}
|
}
|
|
m_vecMacroDefect.clear();
|
}
|
|
BOOL CStackResultCSOT::openFile( char* pGlassID )
|
{
|
CString strFileName;
|
|
strFileName.Format("%s\\%s.txt", m_strLocalPath, pGlassID);
|
|
FILE* pf = fopen(strFileName.GetBuffer(0), "r");
|
|
if(pf == NULL)
|
return FALSE;
|
|
std::vector<_StackDefect> vecMacroDefect;
|
_StackDefect MacroDefect;
|
char buffer[1024];
|
|
char* pReadPoint = NULL;
|
char *pStr;
|
|
while(!feof(pf))
|
{
|
pStr = fgets(buffer, 1024, pf);
|
|
if(!strncmp(buffer, "ITEM,", 5)) continue;
|
|
|
if(strlen(buffer) <= 0 || pStr == NULL)
|
break;
|
|
if(!strncmp(buffer, "DATA,CELLDATA", 13))//ÆÄ½Ì ÅÂÇö[2017/3/29]
|
{
|
//¹«¶ó ¼¿ÆÇÁ¤µµ ¹Ý¿µ ÇØ¾ß Çϳª?
|
}
|
else if(!strncmp(buffer, "DATA,DEFECTDATA", 15))//ÆÄ½Ì ÅÂÇö[2017/3/29]
|
{
|
pReadPoint = buffer;
|
|
|
|
vecMacroDefect.push_back(MacroDefect);
|
}
|
}
|
|
fclose(pf);
|
|
m_vecMacroDefect = vecMacroDefect;
|
return TRUE;
|
}
|
|
char* CStackResultCSOT::getParsingData( char* pBuf, int nLen, CString* pOutData )
|
{
|
for(int i=nLen-1; i>=0; i--)
|
{
|
if(pBuf[i] != ' ')
|
{
|
pBuf[i+1] = 0;
|
break;
|
}
|
}
|
*pOutData = pBuf;
|
|
return &pBuf[nLen+1]; //±¸ºÐÀÚ °Ç³Ê ¶Ù¾î¼ ´ÙÀ½ ÀÐÀ» Æ÷ÀÎÆ® ³Ñ°ÜÁØ´Ù ÅÂÇö[2017/3/29]
|
}
|
|
char* CStackResultCSOT::getParsingData( char* pBuf, int nLen, int* pOutData )
|
{
|
pBuf[nLen] = 0;
|
|
*pOutData = atoi(pBuf);
|
|
return &pBuf[nLen+1]; //±¸ºÐÀÚ °Ç³Ê ¶Ù¾î¼ ´ÙÀ½ ÀÐÀ» Æ÷ÀÎÆ® ³Ñ°ÜÁØ´Ù ÅÂÇö[2017/3/29]
|
}
|
|
BOOL CStackResultCSOT::readOptionFile( char* pFileName /*= "C:\\AOIServer\\ConfigFile\\MacroInfo.cfg"*/ )
|
{
|
if(pFileName == NULL) pFileName = m_strConfigFile;
|
|
CakFileDB akFileDB;
|
akFileDB.openfile(pFileName);
|
|
akFileDB.getItem("Stack_Use", &m_bStackUse, 0);
|
akFileDB.getItem("Stack_LocalPath", m_strLocalPath, "D:\\DIT_ResultData\\Stack");
|
akFileDB.getItem("Stack_EquipID", m_strEquipID, "AAAAA");
|
akFileDB.getItem("Stack_Param1", m_strParam1, "");
|
|
|
if(m_bStackUse && m_nThreadStackFileReadFlag == 0)//¾²·¹µå »ý¼º [±èÅÂÇö 2019/1/12]
|
{
|
_beginthread(threadStackFileRead, NULL, this);
|
}
|
return TRUE;
|
}
|
|
void CStackResultCSOT::threadStackFileRead( void* pArg )
|
{
|
CStackResultCSOT* pThis = (CStackResultCSOT*)pArg;
|
|
pThis->m_nThreadStackFileReadFlag = 1;
|
int nSleepTime = 1000;
|
int nReadFailCount = 0;
|
int nThreadCount=0;
|
CString strGlassID;
|
|
while(pThis->m_nThreadStackFileReadFlag==1)
|
{
|
if(pThis->m_nProcessState == SPS_CmdFileRead) //½ºÅÃÆÄÀÏ Àб⠼öÇà [±èÅÂÇö 2019/1/12]
|
{
|
strGlassID = pThis->m_strGlassID;
|
pThis->m_nProcessState = SPS_StateFileRead;
|
nThreadCount = 0;
|
nReadFailCount = 0;
|
|
AKLOG("Stack File Read Start : %s\\%s.txt", pThis->m_strLocalPath, strGlassID);
|
|
while(pThis->m_nProcessState == SPS_StateFileRead && pThis->m_nThreadStackFileReadFlag==1)
|
{
|
if((nThreadCount++ % 20) != 0) //¸í·É ¼öÇàÀ» ºü¸£°Ô °¨Áö À§ÇÑ Á¶Ä¡ [±èÅÂÇö 2019/1/12]
|
{
|
Sleep(50);
|
continue;
|
}
|
|
if(pThis->openFile(strGlassID.GetBuffer(0)) == TRUE)
|
{
|
pThis->m_nProcessState = SPS_ResultReadOK;
|
AKLOG("Stack File Read Complete ");
|
break;
|
}
|
|
nReadFailCount++;
|
AKLOG("Stack File Read Try : %d", nReadFailCount);
|
|
if(nReadFailCount>100)
|
{
|
pThis->m_nProcessState = SPS_ResultReadFail;
|
AKLOG("Stack File Read Fail ");
|
break;
|
}
|
|
Sleep(50);
|
}
|
if(pThis->m_nProcessState != SPS_ResultReadOK)
|
{
|
pThis->m_nProcessState = SPS_ResultReadFail;
|
AKLOG("Stack File Read Stop ");
|
}
|
|
|
}
|
if(nReadFailCount)
|
|
|
Sleep(500);
|
}
|
|
pThis->m_nThreadStackFileReadFlag = 0;
|
}
|
|
BOOL CStackResultCSOT::StackFileReadStart( char* pGlassID )
|
{
|
if(m_nThreadStackFileReadFlag == 0)//¾²·¹µå »ý¼º [±èÅÂÇö 2019/1/12]
|
{
|
_beginthread(threadStackFileRead, NULL, this);
|
}
|
|
if(m_nProcessState == SPS_StateFileRead)
|
{
|
m_nProcessState = SPS_CmdFileStop;
|
while(m_nProcessState == SPS_CmdFileStop) Sleep(0);
|
}
|
|
m_strGlassID = pGlassID;
|
m_nProcessState = SPS_CmdFileRead;
|
|
return TRUE;
|
}
|
|
BOOL CStackResultCSOT::StackFileReadStop( BOOL bWait/*=TRUE*/ )
|
{
|
if(bWait == TRUE && m_nProcessState == SPS_StateFileRead)
|
{
|
m_nProcessState = SPS_CmdFileStop;
|
while(m_nProcessState == SPS_CmdFileStop) Sleep(0);
|
}
|
|
return TRUE;
|
}
|