// FDCReporter.cpp : ±¸Çö ÆÄÀÏÀÔ´Ï´Ù.
|
//
|
|
#include "stdafx.h"
|
#include "FDCReporter.h"
|
#include "MacroFile.h"
|
|
// CFDCReporter
|
|
CFDCReporter::CFDCReporter(const CString& strFileName, DWORD dwTime)
|
{
|
m_strFileName = strFileName;
|
m_dwTime = dwTime;
|
m_bIsRunThread = FALSE;
|
m_bThreadRun = FALSE;
|
m_pFDCR2P = NULL;
|
m_vecFDCData.clear();
|
|
InitializeCriticalSection(&m_csExit);
|
|
AddDefaultData();
|
}
|
|
CFDCReporter::~CFDCReporter()
|
{
|
DeleteCriticalSection(&m_csExit);
|
}
|
|
int CFDCReporter::StartThread()
|
{
|
return CreateTimerThread(this);
|
}
|
|
void CFDCReporter::StopThread()
|
{
|
CTimerThreadPools::StopThread();
|
}
|
|
// CTimerThreadPools
|
void CFDCReporter::TimerThreadProcess(PVOID pParameter)
|
{
|
Reporting();
|
}
|
|
// CFDCReporter ¸Þ½ÃÁö 󸮱âÀÔ´Ï´Ù.
|
void CFDCReporter::ClearOnceData() // GlassLoading ½Ã È£Ãâ
|
{
|
EnterCriticalSection(&m_csExit);
|
|
for (VectorSFDCDataIt it=m_vecFDCData.begin(); it!=m_vecFDCData.end(); it++)
|
{
|
if (it->nRepeatType==0)
|
{
|
it->dwLastTime = 1;
|
}
|
}
|
|
LeaveCriticalSection(&m_csExit);
|
}
|
|
void CFDCReporter::AddDefaultData()
|
{
|
CFileFind findFile;
|
|
if (findFile.FindFile(m_strFileName) == FALSE)
|
{
|
CMacroFile file;
|
|
file.SetItem(_T("FDC_DATA_COUNT"), 0);
|
|
file.SetItem(_T("00_DATA_NAME"), _T(""));
|
|
file.SetItem(_T("00_DATA_INDEX"), 0);
|
|
file.SetItem(_T("00_REPEAT_TYPE"), 0);
|
|
file.SetItem(_T("00_INTERVAL_TIME"), 0);
|
|
file.SetItem(_T("00_ADDRESS"), 0);
|
|
file.SetItem(_T("00_SIZE"), 0);
|
|
file.Write(m_strFileName);
|
}
|
}
|
|
void CFDCReporter::AddFDCData(const SFDCData& data)
|
{
|
m_vecFDCData.push_back(data);
|
}
|
|
BOOL CFDCReporter::LoadFDCData()
|
{
|
CMacroFile file;
|
if (file.Read(m_strFileName)==FALSE)
|
{
|
return FALSE;
|
}
|
|
EnterCriticalSection(&m_csExit);
|
|
m_vecFDCData.clear();
|
|
int nDataCount = 0;
|
file.GetItem(_T("FDC_DATA_COUNT"), nDataCount, 0);
|
|
SFDCData fdcData;
|
int nIntData;
|
CString strItem = _T("");
|
for (int i=0; i<nDataCount; i++)
|
{
|
fdcData.Reset();
|
|
strItem.Format(_T("%02d_DATA_NAME"), i);
|
file.GetItem(strItem, fdcData.strName, _T(""));
|
|
strItem.Format(_T("%02d_DATA_INDEX"), i);
|
file.GetItem(strItem, fdcData.nDataIndex, -1);
|
|
strItem.Format(_T("%02d_REPEAT_TYPE"), i);
|
file.GetItem(strItem, fdcData.nRepeatType, 0);
|
|
strItem.Format(_T("%02d_INTERVAL_TIME"), i);
|
file.GetItem(strItem, nIntData, 10000);
|
fdcData.dwInterval = DWORD(nIntData);
|
|
strItem.Format(_T("%02d_ADDRESS"), i);
|
file.GetItem(strItem, fdcData.nAddress, -1);
|
|
strItem.Format(_T("%02d_SIZE"), i);
|
file.GetItem(strItem, fdcData.nDataSize, 0);
|
|
m_vecFDCData.push_back(fdcData);
|
}
|
|
LeaveCriticalSection(&m_csExit);
|
|
return TRUE;
|
}
|
|
BOOL CFDCReporter::SaveFDCData()
|
{
|
CMacroFile file;
|
|
int nDataCount = (int)m_vecFDCData.size();
|
file.SetItem(_T("FDC_DATA_COUNT"), nDataCount);
|
|
int nIntData;
|
CString strItem = _T("");
|
for (int i=0; i<nDataCount; i++)
|
{
|
strItem.Format(_T("%02d_DATA_NAME"), i);
|
file.SetItem(strItem, m_vecFDCData[i].strName);
|
|
strItem.Format(_T("%02d_DATA_INDEX"), i);
|
file.SetItem(strItem, m_vecFDCData[i].nDataIndex);
|
|
strItem.Format(_T("%02d_REPEAT_TYPE"), i);
|
file.SetItem(strItem, m_vecFDCData[i].nRepeatType);
|
|
nIntData = int(m_vecFDCData[i].dwInterval);
|
strItem.Format(_T("%02d_INTERVAL_TIME"), i);
|
file.SetItem(strItem, nIntData);
|
|
strItem.Format(_T("%02d_ADDRESS"), i);
|
file.SetItem(strItem, m_vecFDCData[i].nAddress);
|
|
strItem.Format(_T("%02d_SIZE"), i);
|
file.SetItem(strItem, m_vecFDCData[i].nDataSize);
|
}
|
|
return file.Write(m_strFileName);
|
}
|
|
void CFDCReporter::Reporting()
|
{
|
if (m_pFDCR2P==NULL) return;
|
|
EnterCriticalSection(&m_csExit);
|
|
DWORD dwCurrentTime = 0;
|
|
for (VectorSFDCDataIt it=m_vecFDCData.begin(); it!=m_vecFDCData.end(); it++)
|
{
|
if (it->nRepeatType==0) // once
|
{
|
if (it->dwLastTime>0)
|
{
|
if (m_pFDCR2P->FDCR2P_GetFDCDataValue((*it))==TRUE)
|
{
|
m_pFDCR2P->FDCR2P_ReportFDCData((*it));
|
|
it->dwLastTime = 0;
|
}
|
}
|
}
|
else // repeat
|
{
|
dwCurrentTime = GetTickCount();
|
|
if(it->dwInterval<(dwCurrentTime-it->dwLastTime))
|
{
|
if (m_pFDCR2P->FDCR2P_GetFDCDataValue((*it))==TRUE)
|
{
|
m_pFDCR2P->FDCR2P_ReportFDCData((*it));
|
|
it->dwLastTime = dwCurrentTime;
|
}
|
continue;
|
}
|
}
|
}
|
|
LeaveCriticalSection(&m_csExit);
|
}
|