|
|
|
|
#include "simtest.h"
|
|
|
|
|
#include "skt.h"
|
|
|
|
|
#include "log.h"
|
|
|
|
|
#include "manage.h"
|
|
|
|
|
|
|
|
|
|
CSimTest::CSimTest(int index, const char* ate)
|
|
|
|
|
{
|
|
|
|
|
_start = 0;
|
|
|
|
|
_btest = false;
|
|
|
|
|
_bhome = false;
|
|
|
|
|
_index = index;
|
|
|
|
|
strcpy(_ate, ate);
|
|
|
|
|
m_brun = false;
|
|
|
|
|
_skt = INVALID_SKT;
|
|
|
|
|
m_hThread = INVALID_HANDLE;
|
|
|
|
|
_status = SOCKET_DISCONNECTED;
|
|
|
|
|
memset(_res, 0, MAX_BUF_LEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSimTest::~CSimTest(void)
|
|
|
|
|
{
|
|
|
|
|
Deinit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CSimTest::Init()
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ
|
|
|
|
|
RETURN_CHK_NOPRT(!m_brun, 0);
|
|
|
|
|
|
|
|
|
|
m_brun = true;
|
|
|
|
|
_skt = skt_client("127.0.0.1", 6050);
|
|
|
|
|
m_hThread = sys_CreateThread(ThreadFun, this);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CSimTest::Deinit()
|
|
|
|
|
{//<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
RETURN_CHK_NOPRT(m_brun, 0);
|
|
|
|
|
|
|
|
|
|
m_brun = false;
|
|
|
|
|
_status = SOCKET_DISCONNECTED;
|
|
|
|
|
sys_WaitForSingleObject(m_hThread);
|
|
|
|
|
sys_CloseHandle(m_hThread);
|
|
|
|
|
skt_close(_skt);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int WINAPI CSimTest::ThreadFun(void* param)
|
|
|
|
|
{
|
|
|
|
|
CSimTest* p = (CSimTest*)param;
|
|
|
|
|
return p->Process();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CSimTest::Process()
|
|
|
|
|
{
|
|
|
|
|
while(m_brun)
|
|
|
|
|
{//ѭ<><D1AD>
|
|
|
|
|
ChkConn();
|
|
|
|
|
ChkTest();
|
|
|
|
|
ChkHome();
|
|
|
|
|
RecvMsg();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
static const char* _endstr = "$";
|
|
|
|
|
static const int _endlen = (int)strlen(_endstr);
|
|
|
|
|
|
|
|
|
|
int CSimTest::FindEnd(char* pszmsg)
|
|
|
|
|
{
|
|
|
|
|
char* ptmp = NULL;
|
|
|
|
|
ptmp = strstr(pszmsg, _endstr);
|
|
|
|
|
if (!ptmp) return -1;
|
|
|
|
|
*ptmp = 0;
|
|
|
|
|
return (int)(ptmp - pszmsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSimTest::SendMsg(const char *pszFormat, ...)
|
|
|
|
|
{
|
|
|
|
|
int len = 0;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
va_list args;
|
|
|
|
|
char buff[1024] = {0};
|
|
|
|
|
|
|
|
|
|
va_start(args, pszFormat);
|
|
|
|
|
len = vsnprintf(buff, 1023, pszFormat, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
ZERO_CHK(len > 0);
|
|
|
|
|
|
|
|
|
|
len += sprintf(buff + len, "%s", _endstr); //<2F><><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
ret = skt_send(_skt, buff, len);
|
|
|
|
|
if (ERR_NO_CONNECT == ret)
|
|
|
|
|
{//<2F>Ѿ<EFBFBD><D1BE>Ͽ<EFBFBD>
|
|
|
|
|
_status = SOCKET_DISCONNECTED;
|
|
|
|
|
REPORT("ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ξ<EFBFBD>: %s <20>ѶϿ<D1B6><CFBF><EFBFBD><EFBFBD><EFBFBD>", _ate);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ins->testLog()) LOG_INF1("ģ<EFBFBD><EFBFBD><EFBFBD>ξ<EFBFBD>%s <20><><EFBFBD><EFBFBD>: %s", _ate, buff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSimTest::Disconnect()
|
|
|
|
|
{
|
|
|
|
|
_start = 0;
|
|
|
|
|
_bhome = false;
|
|
|
|
|
_btest = false;
|
|
|
|
|
_status = SOCKET_DISCONNECTED;
|
|
|
|
|
sprintf(_res, "0"); //ʧ<><CAA7>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define PASS 3
|
|
|
|
|
|
|
|
|
|
void CSimTest::ChkTest()
|
|
|
|
|
{
|
|
|
|
|
SYS_TIME tm;
|
|
|
|
|
uint res = 0;
|
|
|
|
|
|
|
|
|
|
ZERO_CHK(_btest);
|
|
|
|
|
|
|
|
|
|
if (_bsendgr)
|
|
|
|
|
{
|
|
|
|
|
SendMsg("GR");
|
|
|
|
|
_bsendgr = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//SN#Machine#User#Config#Lot#Mode#SiteID#ProjectID#RetryMode#Mes#Mtcp
|
|
|
|
|
//"SN,Machine,User,Config,Lot,Mode,SiteID,ProjectID,RetryMode,Status,SOCKET ID,Time"
|
|
|
|
|
if (sys_GetTickCount() > _start + ins->getSimCT() * 1000)
|
|
|
|
|
{//18s<38><73><EFBFBD><EFBFBD>
|
|
|
|
|
_btest = false;
|
|
|
|
|
srand((unsigned)time(NULL));
|
|
|
|
|
res = ((uint)rand()) % 100;
|
|
|
|
|
res = (res >= ins->getFail()) ? 1 : 0; //3%<25><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|
|
|
|
sys_GetLocalTime(&tm);
|
|
|
|
|
sprintf(_res, "1#%d#%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%04d/%02d/%02d %02d:%02d:%02d",
|
|
|
|
|
res, SN.c_str(), Machine.c_str(), User.c_str(), Config.c_str(), Lot.c_str(),
|
|
|
|
|
Mode.c_str(), SiteID.c_str(), ProjectID.c_str(), RetryMode.c_str(),
|
|
|
|
|
res ? "PASS" : "FAIL", _ate, tm.wYear, tm.wMonth, tm.wDay,
|
|
|
|
|
tm.wHour, tm.wMinute, tm.wSecond);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSimTest::ChkHome()
|
|
|
|
|
{
|
|
|
|
|
ZERO_CHK(_bhome);
|
|
|
|
|
|
|
|
|
|
if (sys_GetTickCount() > _start + HOMECT)
|
|
|
|
|
{//60s
|
|
|
|
|
_bhome = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSimTest::ChkConn()
|
|
|
|
|
{
|
|
|
|
|
ZERO_CHK(SOCKET_DISCONNECTED == _status);
|
|
|
|
|
|
|
|
|
|
if (SOCKET_DISCONNECTED == skt_status(_skt))
|
|
|
|
|
{//δ<><CEB4><EFBFBD><EFBFBD>
|
|
|
|
|
sys_Sleep(50);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_status = SOCKET_CONNECTED;
|
|
|
|
|
REPORT("ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ξ<EFBFBD>%d:%s <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.", _index, _ate);
|
|
|
|
|
SendMsg("Register#%s#%d#%s", _ate, _index,
|
|
|
|
|
"SN,Machine,User,Config,Lot,Mode,SiteID,"
|
|
|
|
|
"ProjectID,RetryMode,Status,SOCKET ID,Time");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSimTest::RecvMsg()
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
int total = 0;
|
|
|
|
|
int nlen = 0;
|
|
|
|
|
char* pdest = NULL;
|
|
|
|
|
char buff[1024] = {0};
|
|
|
|
|
|
|
|
|
|
ZERO_CHK(SOCKET_CONNECTED == _status);
|
|
|
|
|
|
|
|
|
|
total = skt_recv(_skt, buff, 1023 - 1, 100);
|
|
|
|
|
if (ERR_NO_CONNECT == total)
|
|
|
|
|
{//<2F>Ѿ<EFBFBD><D1BE>Ͽ<EFBFBD>
|
|
|
|
|
Disconnect();
|
|
|
|
|
REPORT("ģ<EFBFBD><EFBFBD><EFBFBD>ξ<EFBFBD>:%s <20>ѶϿ<D1B6><CFBF><EFBFBD><EFBFBD><EFBFBD>", _ate);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ZERO_CHK(total > 0); //error
|
|
|
|
|
|
|
|
|
|
pdest = buff;
|
|
|
|
|
while(total > 0)
|
|
|
|
|
{
|
|
|
|
|
nlen = FindEnd(pdest); //<2F><><EFBFBD>ҽ<EFBFBD><D2BD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if (nlen < 0)
|
|
|
|
|
{//δ<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
ParseMsg(pdest);
|
|
|
|
|
nlen += _endlen; //<2F><><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
total -= nlen;
|
|
|
|
|
pdest += nlen;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CSimTest::ParseMsg(char* pszmsg)
|
|
|
|
|
{
|
|
|
|
|
char* ptmp = NULL;
|
|
|
|
|
|
|
|
|
|
RETURN_CHK_NOPRT(pszmsg, ERR_INPUT_PARAM);
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, REG))
|
|
|
|
|
{//ע<><D7A2><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, STATUS))
|
|
|
|
|
{//<2F>ξ<EFBFBD>״̬<D7B4>ظ<EFBFBD>
|
|
|
|
|
SendMsg("%s#%d", STATUS, isRun() ? 0 : 1);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, GRIP))
|
|
|
|
|
{//<2F><>צ<EFBFBD>ظ<EFBFBD>
|
|
|
|
|
SendMsg("%s#%d", GRIP, isRun() ? 0 : 1);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, PAUSE))
|
|
|
|
|
{//<2F><>ͣ<EFBFBD>ظ<EFBFBD> -- <20><><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><D0B2><EFBFBD><EFBFBD><EFBFBD>ͣ
|
|
|
|
|
SendMsg("%s#%d", PAUSE, isRun() ? 1 : 0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, START))
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Իظ<D4BB>
|
|
|
|
|
if (isRun() || ParseStartParam(pszmsg))
|
|
|
|
|
{//is run/parse error
|
|
|
|
|
SendMsg("%s#0", START);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{//ok
|
|
|
|
|
_btest = true;
|
|
|
|
|
_bsendgr = true;
|
|
|
|
|
sprintf(_res, "0"); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
_start = sys_GetTickCount();
|
|
|
|
|
SendMsg("%s#1", START);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, RESET))
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
SendMsg("%s#1", RESET);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, HOME))
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>ظ<EFBFBD>
|
|
|
|
|
if (!isRun())
|
|
|
|
|
{//<2F><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
_bhome = true;
|
|
|
|
|
_start = sys_GetTickCount();
|
|
|
|
|
SendMsg("%s#1", HOME);
|
|
|
|
|
}
|
|
|
|
|
else SendMsg("%s#0", HOME);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, RES))
|
|
|
|
|
{//ѯ<>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>ظ<EFBFBD>
|
|
|
|
|
SendMsg("%s#%s", RES, _res);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, ERR))
|
|
|
|
|
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>
|
|
|
|
|
SendMsg("%s#0", ERR);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(ptmp, GR))
|
|
|
|
|
{//GR<47><52><EFBFBD><EFBFBD>
|
|
|
|
|
char buff[256] = { 0 };
|
|
|
|
|
comm_strncpy(buff, pszmsg, 240);
|
|
|
|
|
REPORT("recv: %s#%s$", ptmp, buff);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
REPORT("ģ<EFBFBD><EFBFBD><EFBFBD>ξ<EFBFBD>%s <20>յ<EFBFBD><D5B5>쳣ָ<ECB3A3><D6B8>: %s%s%s", _ate, ptmp,
|
|
|
|
|
(pszmsg && *pszmsg) ? "#" : "", pszmsg ? pszmsg : "");
|
|
|
|
|
return ERR_INPUT_PARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//SN#Machine#User#Config#Lot#Mode#SiteID#ProjectID#RetryMode
|
|
|
|
|
int CSimTest::ParseStartParam(char* pszmsg)
|
|
|
|
|
{
|
|
|
|
|
char* ptmp = NULL;
|
|
|
|
|
|
|
|
|
|
RETURN_CHK_NOPRT(pszmsg, ERR_INPUT_PARAM);
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
SN = ptmp;
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
Machine = ptmp;
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
User = ptmp;
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
Config = ptmp;
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
Lot = ptmp;
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
Mode = ptmp;
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
SiteID = ptmp;
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
ProjectID = ptmp;
|
|
|
|
|
|
|
|
|
|
ptmp = sys_strtok(NULL, SPLIT, &pszmsg);
|
|
|
|
|
RETURN_CHK_NOPRT(ptmp && *ptmp, ERR_INPUT_PARAM);
|
|
|
|
|
RetryMode = ptmp;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|