From e5fa774d622d6852fe8e1f033045aed221649108 Mon Sep 17 00:00:00 2001 From: LYW <leeyeanwoo@diteam.co.kr> Date: 금, 15 10월 2021 13:24:54 +0900 Subject: [PATCH] Ongoing80 #3662 CF AOI Review 전설비 알람 발생 조치 --- ReviewHistory/ReveiwHistory/StackResultCSOT.cpp | 226 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 226 insertions(+), 0 deletions(-) diff --git a/ReviewHistory/ReveiwHistory/StackResultCSOT.cpp b/ReviewHistory/ReveiwHistory/StackResultCSOT.cpp new file mode 100644 index 0000000..0a26a55 --- /dev/null +++ b/ReviewHistory/ReveiwHistory/StackResultCSOT.cpp @@ -0,0 +1,226 @@ +#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; +} -- Gitblit v1.9.3