You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

325 lines
9.7 KiB
C++

#include "StdAfx.h"
#include "AllThreadMgr.h"
#include "CStringFuc.h"
#include "FileMgr.h"
#include "WorkTime.h"
#include "LogMgr.h"
CAllThreadMgr gAllThreadMgr;
bool gbStopAllThread= false;//ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
CAllThreadMgr::CAllThreadMgr(void)
{
InitThreadInfoVec();
}
CAllThreadMgr::~CAllThreadMgr(void)
{
}
//<2F><>ʼ<EFBFBD><CABC><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD>
void CAllThreadMgr::InitThreadInfoVec()
{
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_AutoWorkFlowCtrlThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̿<EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_LaserSleepThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_GetDataPtThread,
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_ExecuteStepThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_FastReadInfoThread;
ThreadInfo.m_ThreadName = "״̬<EFBFBD><EFBFBD>ȡ<EFBFBD>߳<EFBFBD>(fast)";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_SlowReadInfoThread;
ThreadInfo.m_ThreadName = "״̬<EFBFBD><EFBFBD>ȡ<EFBFBD>߳<EFBFBD>(slow)";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_PlcReadInfoThread;
ThreadInfo.m_ThreadName = "PLC ͨ<><CDA8><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_SwitchLaserLddThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ldd <20>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
#ifdef __LASER_DEVICE_BEAMTECH__
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_BeamtechSetParToLaserThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
#endif
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_TimingProgressThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_RecordTimeThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD>ʱ<EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_WaitTransferLoadEndThread;
ThreadInfo.m_ThreadName = "<EFBFBD>ȴ<EFBFBD>load <20><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_CheckTransferLoadThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>Ҫload <20><><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_DlgDeviceStateInfoTimer;
ThreadInfo.m_ThreadName = "״̬<EFBFBD><EFBFBD>Ϣtimer1";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_DlgDeviceStateInfoTimer2;
ThreadInfo.m_ThreadName = "״̬<EFBFBD><EFBFBD>Ϣtimer2";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_ReadLaserPower;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_LaserDisMeterReadThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>timer";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_ReadLaserInfoThread;
ThreadInfo.m_ThreadName = "<EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ȡ<EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_ReadRedLaserInfoThread;
ThreadInfo.m_ThreadName = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ȡ<EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_AutoTransferFlowThread;
ThreadInfo.m_ThreadName = "<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>Ƭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_ReadTransferArmInfoThread;
ThreadInfo.m_ThreadName = "TransferArm ͨ<><CDA8><EFBFBD>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_UpdateSecsDataThread;
ThreadInfo.m_ThreadName = "SecsVariable <20>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_CtrlHostJobThread;
ThreadInfo.m_ThreadName = "CtrlHostJob <20>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
{
CThreadInfo ThreadInfo;
ThreadInfo.m_ThreadType = _EThreadType_CyclicRunThread;
ThreadInfo.m_ThreadName = "CyclicRun <20>߳<EFBFBD>";
m_ThreadInfoVec.push_back(ThreadInfo);
}
}
void CAllThreadMgr::InsertThreadInfoList(CListCtrl &List,bool bInsert)
{
if(bInsert)
List.DeleteAllItems();
int size = m_ThreadInfoVec.size();
for(int i=0;i<size;i++)
{
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
int idx = 0;
if(bInsert)
{
List.InsertItem(i," ");//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
}
List.SetItemText(i,idx++,Int2CString(i+1));//<2F><><EFBFBD><EFBFBD>
List.SetItemText(i,idx++,ThreadInfo.m_ThreadName);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CString s;
if(ThreadInfo.m_bRunning)
s = "On";
else
s = "Off";
List.SetItemText(i,idx++,s);//״̬
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>̵߳<DFB3><CCB5><EFBFBD><EFBFBD><EFBFBD>״̬
void CAllThreadMgr::SetThreadInfoState(EThreadType ThreadType,bool bRunning)
{
int size = m_ThreadInfoVec.size();
for(int i=0;i<size;i++)
{
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
if(ThreadInfo.m_ThreadType == ThreadType)
{
ThreadInfo.m_bRunning = bRunning;
break;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>ʱ<EFBFBD><CAB1>
//UpdateThreadTime(ThreadType);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>ʱ<EFBFBD><CAB1>
void CAllThreadMgr::UpdateThreadTime(EThreadType ThreadType)
{
int size = m_ThreadInfoVec.size();
for(int i=0;i<size;i++)
{
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
if(ThreadInfo.m_ThreadType == ThreadType)
{
CString RunTime;
CWorkTime WorkTime;
ThreadInfo.m_LastRunTime = WorkTime.GetDateTime("/",":");
break;
}
}
}
COLORREF CAllThreadMgr::GetStateColor(int idx)
{
COLORREF c = RGB_GRAY2;
int size = m_ThreadInfoVec.size();
if(idx>=0 && idx < size)
{
if(m_ThreadInfoVec[idx].m_bRunning)
{
c = RGB_GREEN;
}
}
return c;
}
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5>߳<EFBFBD>
bool CAllThreadMgr::HasThreadRunning()
{
int size = m_ThreadInfoVec.size();
for(int i=0;i<size;i++)
{
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
if(ThreadInfo.m_bRunning)
{
return true;
}
}
return false;
}
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>̵߳<DFB3><CCB5><EFBFBD><EFBFBD><EFBFBD>
void CAllThreadMgr::ShowRunningThreadName()
{
int size = m_ThreadInfoVec.size();
for(int i=0;i<size;i++)
{
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
if(ThreadInfo.m_bRunning)
{
CString s("RunningThread : ");
s += ThreadInfo.m_ThreadName;
gLogMgr->WriteDebugLog(s);
}
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>̵߳<DFB3>ַ
void CAllThreadMgr::BindingThreadAdr(EThreadType ThreadType,CWinThread*p)
{
int size = m_ThreadInfoVec.size();
for(int i=0;i<size;i++)
{
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
if(ThreadInfo.m_ThreadType == ThreadType)
{
ThreadInfo.m_pThread = p;
break;
}
}
}
//<2F><><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD>е<EFBFBD>ʱ<EFBFBD><CAB1>д<EFBFBD><D0B4><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
void CAllThreadMgr::WriteAllTreadTimeToFile()
{
CString FileName = "\\CommPar\\TreadTimeFile.txt";
CFileMgr FileMgr;
char filepath[1024];
FileMgr.GetFullFilePath(filepath,FileName);
ofstream FileStream;
FileStream.open(filepath);
int size = m_ThreadInfoVec.size();
for(int i=0;i<size;i++)
{
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
FileStream<<ThreadInfo.m_ThreadName<<" "<<ThreadInfo.m_LastRunTime<<"\n";
}
FileStream<<endl;
FileStream.close();
}
//<2F><>ѯ<EFBFBD>߳<EFBFBD>ThreadType <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool CAllThreadMgr::IsThreadRunning(EThreadType ThreadType)
{
int size = m_ThreadInfoVec.size();
for(int i=0;i<size;i++)
{
CThreadInfo &ThreadInfo = m_ThreadInfoVec[i];
if(ThreadInfo.m_ThreadType == ThreadType)
{
return ThreadInfo.m_bRunning;
}
}
return false;
}
void CAllThreadMgr::StopAllThread()
{
gbStopAllThread = true;
}
bool CAllThreadMgr::IsbStopAllThread()
{
return gbStopAllThread;
}