a
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Crc16.cpp: implementation of the Crc16 class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Crc16.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Crc16::Crc16()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// Crc16::~Crc16()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
unsigned short Crc16::table[ 256 ];
|
||||
int Crc16::initialized = 0;
|
||||
|
||||
Crc16::Crc16( unsigned short init_value )
|
||||
{
|
||||
if ( !initialized ) {
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int crc;
|
||||
|
||||
for ( i = 0 ; i < 256 ; i++ ) {
|
||||
k = i << 8;
|
||||
crc = 0;
|
||||
for ( j = 0 ; j < 8 ; j++ ) {
|
||||
if ( ( crc ^ k ) & 0x8000 )
|
||||
crc = ( crc << 1 ) ^ 0x1021;
|
||||
else
|
||||
crc <<= 1;
|
||||
k <<= 1;
|
||||
}
|
||||
table[ i ] = (unsigned short) crc;
|
||||
}
|
||||
initialized = 1;
|
||||
}
|
||||
crc = init_value;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// Crc32.cpp: implementation of the Crc32 class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Crc32.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Crc32::Crc32()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// Crc32::~Crc32()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
unsigned long Crc32::table[ 256 ];
|
||||
int Crc32::initialized = 0;
|
||||
|
||||
Crc32::Crc32( unsigned long init_value )
|
||||
{
|
||||
if ( !initialized ) {
|
||||
int i;
|
||||
int j;
|
||||
unsigned long coeff;
|
||||
|
||||
for ( i = 0; i < 256 ; i++ ) {
|
||||
coeff = i;
|
||||
for ( j = 0; j < 8; j++ ) {
|
||||
if ( coeff & 1 )
|
||||
coeff = ( coeff >> 1 ) ^ 0xEDB88320L;
|
||||
else
|
||||
coeff >>= 1;
|
||||
}
|
||||
table[ i ] = coeff;
|
||||
}
|
||||
initialized = 1;
|
||||
}
|
||||
crc = init_value;
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
// FileOperTools.cpp: implementation of the CFileOperTools class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "FileOperTools.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
extern SYSTEMTIME g_sysCurTime;
|
||||
extern int g_iUILanguage;
|
||||
CFileOperTools* CFileOperTools::m_pFileOper= NULL;
|
||||
|
||||
CFileOperTools::CFileOperTools()
|
||||
{
|
||||
m_pComLog = NULL;
|
||||
m_pWriteLogSection = NULL;
|
||||
if (NULL == m_pWriteLogSection)
|
||||
{
|
||||
m_pWriteLogSection = new CRITICAL_SECTION;
|
||||
if (NULL == m_pWriteLogSection)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("分配日志的临界区失败!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Allocate critical section of log failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return ;
|
||||
}
|
||||
InitializeCriticalSection(m_pWriteLogSection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CFileOperTools::~CFileOperTools()
|
||||
{
|
||||
CloseComLog();
|
||||
|
||||
}
|
||||
CFileOperTools* CFileOperTools::GetInstance()
|
||||
{
|
||||
if (NULL == m_pFileOper)
|
||||
{
|
||||
m_pFileOper = new CFileOperTools();
|
||||
}
|
||||
return m_pFileOper;
|
||||
|
||||
}
|
||||
//strSrcPath:代表源目录,strDstPath代表目的目录
|
||||
//在这里需要注意的是,strDstPath需要将源目录的文件名也包含进来
|
||||
//比如想将c:\test目录拷贝到d盘下,那么此时strDstPath的值应该为d:\test
|
||||
bool CFileOperTools::CopyFolder(CString strSrcPath, CString strDstPath)
|
||||
{
|
||||
CString strError = _T("");
|
||||
if (strDstPath.IsEmpty() || strDstPath.IsEmpty())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("src_path和dst_path都不能为空!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Neither src_path nor dst_path can be empty!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strSrcPath.Right(1) == _T("\\"))
|
||||
{
|
||||
strSrcPath = strSrcPath.Left(strSrcPath.GetLength() - 1);
|
||||
}
|
||||
if (strDstPath.Right(1) == _T("\\"))
|
||||
{
|
||||
strDstPath = strDstPath.Left(strDstPath.GetLength() - 1);
|
||||
}
|
||||
CreateDirectory(strDstPath,NULL);
|
||||
CFileFind finder;
|
||||
// 打开指定的文件夹进行搜索
|
||||
BOOL bWorking = finder.FindFile(strSrcPath + _T("\\") + _T("*.*"));
|
||||
while(bWorking)
|
||||
{
|
||||
// 从当前目录搜索文件
|
||||
bWorking = finder.FindNextFile();
|
||||
CString strFileName = finder.GetFileName();
|
||||
CString strSrc = strSrcPath + _T("\\") + strFileName;
|
||||
CString strDst = strDstPath + _T("\\") + strFileName;
|
||||
|
||||
// 判断搜索到的是不是"."和".."目录
|
||||
if(!finder.IsDots())
|
||||
{
|
||||
// 判断搜索到的目录是否是文件夹
|
||||
if(finder.IsDirectory())
|
||||
{
|
||||
// 如果是文件夹的话,进行递归
|
||||
if(!CopyFolder(strSrc, strDst))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果是文件,进行复制
|
||||
if(!CopyFile(strSrc, strDst, FALSE))
|
||||
{
|
||||
DWORD dwError = GetLastError();
|
||||
strError.Empty();
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strError.Format(_T("复制文件夹失败,src_path = %s, dst_path = %s, errorno = %d"), strSrc, strDst, dwError);
|
||||
AfxMessageBox(strError);
|
||||
}
|
||||
else
|
||||
{
|
||||
strError.Format(_T("Copy folder failed,src_path = %s, dst_path = %s, errorno = %d"), strSrc, strDst, dwError);
|
||||
MessageBoxEx(NULL, strError, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool CFileOperTools::IsFileExist(CString strFileInfo)
|
||||
{
|
||||
return (INVALID_FILE_ATTRIBUTES == GetFileAttributes(strFileInfo)) ? false : true;
|
||||
}
|
||||
|
||||
|
||||
void CFileOperTools::CloseComLog()
|
||||
{
|
||||
if (NULL != m_pComLog)
|
||||
{
|
||||
fclose(m_pComLog);
|
||||
m_pComLog = NULL;
|
||||
}
|
||||
|
||||
if (NULL != m_pWriteLogSection)
|
||||
{
|
||||
DeleteCriticalSection(m_pWriteLogSection);
|
||||
delete m_pWriteLogSection;
|
||||
m_pWriteLogSection = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool CFileOperTools::WriteComLog(unsigned char *pszData, int iDateLen)
|
||||
{
|
||||
if (NULL == m_pWriteLogSection)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
EnterCriticalSection(m_pWriteLogSection);
|
||||
if (NULL == m_pComLog)
|
||||
{
|
||||
m_pComLog = fopen(m_strGeneralLogName, "ab+");
|
||||
if (NULL == m_pComLog)
|
||||
{
|
||||
LeaveCriticalSection(m_pWriteLogSection);
|
||||
DWORD dwLastError = GetLastError();
|
||||
CString strErr = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErr.Format(_T("打开%s失败!错误码(%d)"), m_strGeneralLogName, dwLastError);
|
||||
AfxMessageBox(strErr);
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Format(_T("Open %s failed!Errorcode(%d)"), m_strGeneralLogName, dwLastError);
|
||||
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char chTemp[100];
|
||||
sprintf_s(chTemp, sizeof(chTemp), "threadid = %d,%04d-%02d-%02d %02d:%02d:%02d.%03d ",GetCurrentThreadId(), g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay,
|
||||
g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond, g_sysCurTime.wMilliseconds);
|
||||
fwrite(chTemp, 1, strlen(chTemp), m_pComLog);
|
||||
|
||||
|
||||
fwrite(pszData, 1, iDateLen, m_pComLog);
|
||||
|
||||
strcpy(chTemp,"\r\n");
|
||||
fwrite(chTemp, 1, strlen(chTemp), m_pComLog);
|
||||
|
||||
|
||||
fflush(m_pComLog);
|
||||
|
||||
|
||||
LeaveCriticalSection(m_pWriteLogSection);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFileOperTools::WriteComLog(const CString& strInfo)
|
||||
{
|
||||
if (NULL == m_pWriteLogSection)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
EnterCriticalSection(m_pWriteLogSection);
|
||||
if (NULL == m_pComLog)
|
||||
{
|
||||
m_pComLog = fopen(m_strGeneralLogName, "ab+");
|
||||
if (NULL == m_pComLog)
|
||||
{
|
||||
LeaveCriticalSection(m_pWriteLogSection);
|
||||
DWORD dwLastError = GetLastError();
|
||||
CString strErr = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErr.Format(_T("打开%s失败!错误码(%d)"), m_strGeneralLogName, dwLastError);
|
||||
AfxMessageBox(strErr);
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Format(_T("Open %s failed!Errorcode(%d)"), m_strGeneralLogName, dwLastError);
|
||||
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
CString strOutPut = _T("");
|
||||
strOutPut.Format(_T("threadid = %d,%04d-%02d-%02d %02d:%02d:%02d.%03d %s \r\n"), GetCurrentThreadId(), g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay,
|
||||
g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond, g_sysCurTime.wMilliseconds, strInfo);
|
||||
fwrite(strOutPut.GetBuffer(0), 1, strOutPut.GetLength(), m_pComLog);
|
||||
fflush(m_pComLog);
|
||||
|
||||
LeaveCriticalSection(m_pWriteLogSection);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFileOperTools::DeleteFileDirect(CString strFilePath)
|
||||
{
|
||||
if (strFilePath.IsEmpty())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("删除文件名不能为空!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Input filename can not be empty in deletefile!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
if (IsFileExist(strFilePath))
|
||||
{
|
||||
if (!DeleteFile(strFilePath))
|
||||
{
|
||||
CString strInfo = _T("");
|
||||
strInfo.Format(_T("[%d]delete file failed!file_path = %s,error_code=%d"),__LINE__,strFilePath,GetLastError());
|
||||
WriteComLog(strInfo);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool CFileOperTools::DeleteDirectory(CString strDirPath)
|
||||
{
|
||||
if (strDirPath.IsEmpty())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("输入参数错误!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Input paramter error in DeleteDirectory!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
if (strDirPath.Right(1) == _T("\\"))
|
||||
{
|
||||
strDirPath = strDirPath.Left(strDirPath.GetLength() - 1);
|
||||
}
|
||||
if (!IsFileExist(strDirPath))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
CString strDelDirParh = _T("");
|
||||
CFileFind tempFind;
|
||||
strDelDirParh.Format(_T("%s\\*.*"),strDirPath);
|
||||
BOOL IsFinded = tempFind.FindFile(strDelDirParh);
|
||||
CString strInfo = _T("");
|
||||
while (IsFinded)
|
||||
{
|
||||
IsFinded = tempFind.FindNextFile();
|
||||
if (!tempFind.IsDots())
|
||||
{
|
||||
CString strFileName = tempFind.GetFileName();
|
||||
CString strNeedDelete = strDirPath + _T("\\") + strFileName;
|
||||
if (tempFind.IsDirectory())
|
||||
{
|
||||
if (!DeleteDirectory(strNeedDelete))
|
||||
{
|
||||
tempFind.Close();
|
||||
strInfo.Empty();
|
||||
strInfo.Format(_T("[%d]delete directory failed!path = %s,error_code = %d"),__LINE__,strNeedDelete, GetLastError());
|
||||
WriteComLog(strInfo);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!DeleteFile(strNeedDelete))
|
||||
{
|
||||
tempFind.Close();
|
||||
strInfo.Empty();
|
||||
strInfo.Format(_T("[%d]delete file failed!path = %s,error_code = %d"),__LINE__,strNeedDelete, GetLastError());
|
||||
WriteComLog(strInfo);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tempFind.Close();
|
||||
if(!RemoveDirectory(strDirPath))
|
||||
{
|
||||
strInfo.Empty();
|
||||
strInfo.Format(_T("[%d]Remove directory failed!path = %s,error_code = %d"),__LINE__,strDirPath, GetLastError());
|
||||
WriteComLog(strInfo);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFileOperTools::GeneralLogName()
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
GetLocalTime(&st);
|
||||
m_strGeneralLogName.Format(_T("log\\general\\%04d%02d%02d.txt"), st.wYear, st.wMonth, st.wDay);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFileOperTools::DealGeneralLogFunc()
|
||||
{
|
||||
HANDLE hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DealGeneralLogThread, this, 0, 0);
|
||||
if (INVALID_HANDLE_VALUE == hThread)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("Create Thread failed to simulate script run method"));
|
||||
return false;
|
||||
}
|
||||
CloseHandle(hThread);
|
||||
return true;
|
||||
}
|
||||
|
||||
UINT CFileOperTools::DealGeneralLogThread(LPVOID lParam)
|
||||
{
|
||||
CFileOperTools* pThis = (CFileOperTools*)lParam;
|
||||
if (pThis == NULL)
|
||||
return false;
|
||||
//遍历general整个目录
|
||||
//获取文件名,判断日期是否为两天前,满足删除
|
||||
CString szCurFilePath = _T("");
|
||||
szCurFilePath.Empty();
|
||||
szCurFilePath.GetBufferSetLength(256);
|
||||
::GetCurrentDirectory(szCurFilePath.GetLength(), szCurFilePath.GetBuffer(szCurFilePath.GetLength()));
|
||||
szCurFilePath.ReleaseBuffer();
|
||||
|
||||
CString strRecordDir;
|
||||
CString strRecordPath;
|
||||
strRecordPath.Format(_T("%s\\log\\general"), szCurFilePath);
|
||||
strRecordDir.Format(_T("%s\\*.*"), strRecordPath);
|
||||
WIN32_FIND_DATA wfd;
|
||||
HANDLE hFind = FindFirstFile(strRecordDir, &wfd);
|
||||
if (INVALID_HANDLE_VALUE == hFind)
|
||||
return false;
|
||||
|
||||
CString strRecordFile = _T("");
|
||||
CString strTmp;
|
||||
CString strFileExt = _T("");
|
||||
|
||||
CString strFileName;
|
||||
CString strTodayDate;
|
||||
SYSTEMTIME st;
|
||||
GetLocalTime(&st);
|
||||
strTodayDate.Format(_T("%04d%02d%02d"), st.wYear, st.wMonth, st.wDay);
|
||||
do
|
||||
{
|
||||
strRecordFile.Format(_T("%s\\%s"), strRecordPath, wfd.cFileName);
|
||||
strFileExt = PathFindExtension(strRecordFile);
|
||||
if ((wfd.dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE) && (_tcscmp(strFileExt, _T(".txt")) == 0))
|
||||
{
|
||||
strTmp.Format(_T("CFileOperTools::DeleteGeneralLog delete general log file:%s"), strRecordFile);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strTmp);
|
||||
strFileName = wfd.cFileName;
|
||||
if (strFileName.Find('.') != -1)
|
||||
{
|
||||
strFileName = strFileName.Mid(0, strFileName.Find('.'));
|
||||
|
||||
if (atoll(strTodayDate) - 1 > atoll(strFileName))
|
||||
{
|
||||
pThis->DeleteFileDirect(strRecordFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (FindNextFile(hFind, &wfd));
|
||||
FindClose(hFind);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CString CFileOperTools::GetDstFilePathFolder()
|
||||
{
|
||||
LPITEMIDLIST rootLoation;
|
||||
BROWSEINFO bi;
|
||||
TCHAR targetPath[ MAX_PATH ];
|
||||
SHGetSpecialFolderLocation( NULL, CSIDL_DESKTOP, &rootLoation );
|
||||
ZeroMemory( &bi, sizeof( bi ) );
|
||||
bi.pidlRoot = rootLoation;
|
||||
bi.lpszTitle = _T( "保存路径" );
|
||||
|
||||
LPITEMIDLIST targetLocation = SHBrowseForFolder( &bi );
|
||||
|
||||
if ( targetLocation == NULL )
|
||||
return "";
|
||||
|
||||
SHGetPathFromIDList( targetLocation, targetPath );
|
||||
CString szPath(targetPath);
|
||||
return szPath;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// FileTransfer.cpp: implementation of the FileTransfer class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "FileTransfer.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// FileTransfer::FileTransfer()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// FileTransfer::~FileTransfer()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
void FileTransfer::error( char *fmt, ... )
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start( argptr, fmt );
|
||||
vprintf( fmt, argptr );
|
||||
putc( '\n', stdout );
|
||||
va_end( argptr );
|
||||
}
|
||||
|
||||
void FileTransfer::status( char *fmt, ... )
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start( argptr, fmt );
|
||||
vprintf( fmt, argptr );
|
||||
putc( '\n', stdout );
|
||||
va_end( argptr );
|
||||
}
|
||||
@@ -0,0 +1,493 @@
|
||||
// DownloadFile.cpp: implementation of the CFileTransfer_crul class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "FileTransfer_crul.h"
|
||||
#include "Constant.h"
|
||||
#include "CtrlProtocolDef.h"
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
|
||||
extern SYSTEMTIME g_sysCurTime;
|
||||
extern int g_iUILanguage;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
/////////////////////////////z/////////////////////////////////////////
|
||||
DOUBLE CFileTransfer_crul::m_RecvFileSize = 0;
|
||||
int CFileTransfer_crul::m_nWriteFileSize = 0;
|
||||
CFileTransfer_crul::CFileTransfer_crul()
|
||||
{
|
||||
//curl_global_init(CURL_GLOBAL_ALL);
|
||||
m_pCrEasyHandl = NULL;
|
||||
m_pCrPuteasyHandl = NULL;
|
||||
//m_nWriteFileSize = 0;
|
||||
m_strSavePath = _T("");
|
||||
m_strSaveName = _T("");
|
||||
m_strUrl = _T("");
|
||||
m_lTotalRecvFileSize = 0;
|
||||
m_lCurRecvSize = 0;
|
||||
// m_pDownLoadFile = NULL;
|
||||
m_nTimeOut = 120;
|
||||
m_bIsNeedProgress = false;
|
||||
m_bIsNeedErrInfo = false;
|
||||
m_bIsGobalInitial = false;
|
||||
m_pLog = NULL;
|
||||
m_bIsHttpsFlag = false;
|
||||
m_bIsSSLCertify = false;
|
||||
InitalLogInfo();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
CFileTransfer_crul::~CFileTransfer_crul()
|
||||
{
|
||||
// curl_easy_cleanup(m_pCrEasyHandl);
|
||||
curl_global_cleanup();
|
||||
m_bIsGobalInitial = false;
|
||||
if (m_pLog)
|
||||
{
|
||||
fclose(m_pLog);
|
||||
m_pLog = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CFileTransfer_crul::InitalLogInfo()
|
||||
{
|
||||
if (NULL == m_pLog)
|
||||
{
|
||||
m_pLog = fopen("LOG\\filetrans_crul_log.txt","ab+");
|
||||
if (NULL == m_pLog)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("打开 filetrans_crul_log.txt 失败!!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Open filetrans_crul_log.txt failed!!!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CFileTransfer_crul::Inital()
|
||||
{
|
||||
|
||||
if (m_bIsGobalInitial)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
CURLcode res;
|
||||
res = curl_global_init(CURL_GLOBAL_WIN32);
|
||||
CString strTmp = _T("");
|
||||
if (CURLE_OK != res)
|
||||
{
|
||||
strTmp.Format(_T("[%d] global Inital crul failed! error_code = %d"),__LINE__, res);
|
||||
PrintLog(strTmp);
|
||||
return false;
|
||||
}
|
||||
if (LIBCURL_VERSION_NUM < 0x072000)
|
||||
{
|
||||
strTmp.Format(_T("[%d] libcrul version is low!!!, version_num = %d"), __LINE__, LIBCURL_VERSION_NUM);
|
||||
PrintLog(strTmp);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
m_bIsGobalInitial = true;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CFileTransfer_crul::UnInital()
|
||||
{
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
void CFileTransfer_crul::SetOption(EnOptFlag enFlag, CString strInfo, bool bFlag)
|
||||
{
|
||||
switch (enFlag)
|
||||
{
|
||||
case OPT_URL_ADDRESS:
|
||||
m_strUrl = strInfo;
|
||||
break;
|
||||
case OPT_DOWNLOAD_PATH:
|
||||
m_strSavePath = strInfo;
|
||||
break;
|
||||
case OPT_DOWNLOAD_NAME:
|
||||
m_strSaveName = strInfo;
|
||||
break;
|
||||
case OPT_TIMEOUT:
|
||||
m_nTimeOut = atoi(strInfo.GetBuffer(0));
|
||||
break;
|
||||
case OPT_NEED_PROGRESS:
|
||||
m_bIsNeedProgress = bFlag;
|
||||
break;
|
||||
case OPT_NEED_ERRORINFO:
|
||||
m_bIsNeedErrInfo = bFlag;
|
||||
break;
|
||||
case OPT_HTTPS_ACCESS:
|
||||
m_bIsHttpsFlag = bFlag;
|
||||
break;
|
||||
case OPT_SSL_CERTIFY:
|
||||
m_bIsSSLCertify = bFlag;
|
||||
break;
|
||||
default:
|
||||
CString strTmp = _T("");
|
||||
strTmp.Format(_T("[%d] Unknow Opt_Flag, value = %d"), __LINE__, enFlag);
|
||||
PrintLog(strTmp);
|
||||
break;
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
bool CFileTransfer_crul::DownloadFile()
|
||||
{
|
||||
CString strTmp = _T("");
|
||||
if (m_strUrl.IsEmpty() || m_strSaveName.IsEmpty() || m_strSavePath.IsEmpty())
|
||||
{
|
||||
strTmp.Format(_T("[%d] Url or SaveFileInfo is not set!!!"),__LINE__);
|
||||
PrintLog(strTmp);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_bIsHttpsFlag && m_bIsSSLCertify)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("不支持协议https的ssl认证。"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Ssl certify of protocol https is not supported."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GetUrlResConValild())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("下载文件失败!!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("DownLoad file failed!!!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE *pFile = NULL;
|
||||
CString strDownLoadFile = m_strSavePath + m_strSaveName;
|
||||
pFile = fopen(strDownLoadFile.GetBuffer(0), "wb+");
|
||||
if (NULL == pFile)
|
||||
{
|
||||
strTmp.Format(_T("[%d] open file failed, errorno = %d, file_path = %s"), __LINE__, GetLastError(), strDownLoadFile.GetBuffer(0));
|
||||
//AfxMessageBox(strTmp.GetBuffer(0));
|
||||
PrintLog(strTmp);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
m_pCrEasyHandl = curl_easy_init();
|
||||
if (NULL == m_pCrEasyHandl)
|
||||
{
|
||||
strTmp.Format(_T("[%d] curl_easy_init failed!!!"), __LINE__);
|
||||
PrintLog(strTmp);
|
||||
return false;
|
||||
}
|
||||
|
||||
STWriteInfo stWriteInfo;
|
||||
stWriteInfo.pFile = pFile;
|
||||
stWriteInfo.pFileTrans = (void *)this;
|
||||
char chErrorInfo[CURL_ERROR_SIZE];
|
||||
memset(chErrorInfo, 0, sizeof(chErrorInfo));
|
||||
long nOnOff = (true == m_bIsNeedProgress) ? 0 : 1;
|
||||
// struct curl_slist *headers=NULL;
|
||||
// headers = curl_slist_append(headers, "Pragma:no-cache");
|
||||
// headers = curl_slist_append(headers, "Cache-Control:max-age=0");
|
||||
// headers = curl_slist_append(headers, "Cache-Control: no-cache");
|
||||
// headers = curl_slist_append(headers, "Cache-Control: max-age=0");
|
||||
// headers = curl_slist_append(headers, "Cache-Control: no-store");
|
||||
CURLcode resSetOpt;
|
||||
//设置可选项
|
||||
// resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_HTTPHEADER, headers);
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_URL, m_strUrl.GetBuffer(0));
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_TIMEOUT, m_nTimeOut);
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_WRITEDATA, &stWriteInfo);
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_WRITEFUNCTION, &WriteToFile);
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_NOPROGRESS, nOnOff);
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_ERRORBUFFER, chErrorInfo);//设置错误信息
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_VERBOSE, 1);
|
||||
if (m_bIsNeedProgress)
|
||||
{
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_XFERINFOFUNCTION, xferinfo);
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_XFERINFODATA, this);
|
||||
|
||||
}
|
||||
//取消SSL验证
|
||||
if (m_bIsHttpsFlag && !m_bIsSSLCertify)
|
||||
{
|
||||
resSetOpt = curl_easy_setopt(m_pCrEasyHandl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
}
|
||||
strTmp.Empty();
|
||||
strTmp.Format(_T("[%d] url = %s, timeout = %d, show_progress = %d"), __LINE__,
|
||||
m_strUrl.GetBuffer(0), m_nTimeOut, m_bIsNeedProgress);
|
||||
PrintLog(strTmp);
|
||||
//show progress
|
||||
|
||||
m_nWriteFileSize = 0;
|
||||
CURLcode resCode = curl_easy_perform(m_pCrEasyHandl);
|
||||
// curl_slist_free_all(headers);
|
||||
|
||||
if (CURLE_OK != resCode)
|
||||
{
|
||||
strTmp.Empty();
|
||||
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strTmp.Format(_T("下载文件失败,请检查网络环境."));
|
||||
AfxMessageBox(strTmp.GetBuffer(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
strTmp.Format(_T("Download failed, please check the network environment."));
|
||||
MessageBoxEx(NULL, strTmp, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
|
||||
|
||||
strTmp.Empty();
|
||||
strTmp.Format(_T("[%d]Download failed, excute easy_perform failed!!!, return_code = %d, error_msg = %s"), __LINE__, resCode, chErrorInfo);
|
||||
PrintLog(strTmp);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// if (0 == m_nWriteFileSize)
|
||||
// {
|
||||
// // AfxMessageBox(_T("download file failed!"));
|
||||
// strTmp.Empty();
|
||||
// strTmp.Format(_T("[%d] excute easy_perform ok,but Dst_File_Length is 0!"),__LINE__);
|
||||
// PrintLog(strTmp);
|
||||
// resCode = CURLE_REMOTE_FILE_NOT_FOUND;;
|
||||
//
|
||||
//
|
||||
// }
|
||||
// }
|
||||
fclose(pFile);
|
||||
pFile = NULL;
|
||||
curl_easy_cleanup(m_pCrEasyHandl);
|
||||
return (CURLE_OK == resCode) ? true : false;
|
||||
|
||||
}
|
||||
|
||||
size_t CFileTransfer_crul::WriteToFile(void *ptr, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
STWriteInfo* pWriteInfo = (STWriteInfo*)userp;
|
||||
size_t szRes = fwrite(ptr, size, nmemb, pWriteInfo->pFile);
|
||||
m_nWriteFileSize += szRes;
|
||||
if (szRes == size * nmemb)
|
||||
{
|
||||
return szRes;
|
||||
}
|
||||
else
|
||||
{
|
||||
CString strTmp = _T("");
|
||||
CFileTransfer_crul* pFileTrans = (CFileTransfer_crul*)pWriteInfo->pFileTrans;
|
||||
if (0 == szRes)
|
||||
{
|
||||
strTmp.Format(_T("[%d] write File failed!, FileName = %s, errorno = %d"),__LINE__,
|
||||
pFileTrans->m_strSaveName.GetBuffer(0), GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
strTmp.Format(_T("[%d] writed bytes is not equal to received bytes! FileName = %s, Writed_number = %d, Received_number = %d"),
|
||||
__LINE__, pFileTrans->m_strSaveName.GetBuffer(0), szRes, size * nmemb);
|
||||
}
|
||||
pFileTrans->PrintLog(strTmp);
|
||||
return szRes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DOUBLE CFileTransfer_crul::GetFileSize()
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
DOUBLE FileSize=0;
|
||||
|
||||
curl = curl_easy_init();
|
||||
|
||||
if(curl)
|
||||
{
|
||||
|
||||
|
||||
// struct curl_slist *headers=NULL;
|
||||
// headers = curl_slist_append(headers, "Cache-Control: no-cache");
|
||||
// headers = curl_slist_append(headers, "Cache-Control: max-age=0");
|
||||
// headers = curl_slist_append(headers, "Cache-Control: no-store");
|
||||
// curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, m_strUrl);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 120);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
||||
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
// curl_slist_free_all(headers);
|
||||
|
||||
if(res != CURLE_OK)
|
||||
return FALSE;
|
||||
|
||||
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &FileSize);
|
||||
|
||||
if(res != CURLE_OK)
|
||||
return FALSE;
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
return FileSize;
|
||||
}
|
||||
|
||||
bool CFileTransfer_crul::GetUrlResConValild()
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
DOUBLE FileSize=0;
|
||||
|
||||
curl = curl_easy_init();
|
||||
CString strLog = _T("");
|
||||
int iTest = 1;
|
||||
|
||||
|
||||
if(curl)
|
||||
{
|
||||
char chErrInfo[CURL_ERROR_SIZE];
|
||||
memset(chErrInfo, 0, sizeof(chErrInfo));
|
||||
|
||||
|
||||
// struct curl_slist *headers=NULL;
|
||||
// headers = curl_slist_append(headers, "Cache-Control: no-cache");
|
||||
// headers = curl_slist_append(headers, "Cache-Control: max-age=0");
|
||||
// headers = curl_slist_append(headers, "Cache-Control: no-store");
|
||||
// curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, m_strUrl);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &iTest);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteFuncForUrlTest);
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, chErrInfo);//设置错误信息
|
||||
//为了防止偶尔报无法解析网站的问题,在这里只使用IPV4进行DNS的解析
|
||||
curl_easy_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
//temp 临时版本,添加重试功能,次数为3
|
||||
int iTimes = 3;
|
||||
while(iTimes > 0)
|
||||
{
|
||||
res = curl_easy_perform(curl);
|
||||
if (res == CURLE_OK)
|
||||
break;
|
||||
|
||||
iTimes--;
|
||||
}
|
||||
|
||||
if(res != CURLE_OK)
|
||||
{
|
||||
//此时如果错误原因是Failed writing body,代表回调函数返回值和回调函数传入的大小不一致,则会引起中断,并报错
|
||||
//如果没有设置回调函数,则会用默认的回调函数代替,默认的回调函数是将数据写入到标准的输入出里去
|
||||
strLog.Format(_T("[%d]GetUrlResContent::excute curl_perform 3 times failed!,errmsg = %s,url = %s"),__LINE__ ,chErrInfo,m_strUrl);
|
||||
PrintLog(strLog);
|
||||
curl_easy_cleanup(curl);
|
||||
return false;
|
||||
}
|
||||
|
||||
long retCode = 0;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE , &retCode);
|
||||
//如果返回200,则说明正确的找到了网址
|
||||
if ((CURLE_OK == res) && (200 == retCode))
|
||||
{
|
||||
curl_easy_cleanup(curl);
|
||||
return true;
|
||||
}
|
||||
strLog.Format(_T("[%d]GetUrlResConValild::get_crul_info failed, resCode = %d, ResponseCode = %d, ErrorMSg = %s, url = %s"),
|
||||
__LINE__, res, retCode, chErrInfo, m_strUrl);
|
||||
PrintLog(strLog);
|
||||
curl_easy_cleanup(curl);
|
||||
return false;
|
||||
|
||||
}
|
||||
strLog.Format(_T("[%d]GetUrlResConValild:: crul inital failed!!!"),__LINE__);
|
||||
PrintLog(strLog);
|
||||
return false;
|
||||
}
|
||||
|
||||
VOID CFileTransfer_crul::SetRecvSize(size_t f_size)
|
||||
{
|
||||
m_RecvFileSize += f_size;
|
||||
}
|
||||
|
||||
// BOOL CFileTransfer_crul::GetFileList(char *f_buff)
|
||||
// {
|
||||
// CURL *curl;
|
||||
// CURLcode res;
|
||||
// DOUBLE FileSize;
|
||||
//
|
||||
// curl = curl_easy_init();
|
||||
//
|
||||
// if(curl)
|
||||
// {
|
||||
// curl_easy_setopt(curl, CURLOPT_URL, m_strUrl);
|
||||
// curl_easy_setopt(curl, CURLOPT_TIMEOUT, 120);
|
||||
// curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)f_buff);
|
||||
// curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteToBuff);
|
||||
//
|
||||
// res = curl_easy_perform(curl);
|
||||
//
|
||||
// if(res != CURLE_OK)
|
||||
// return FALSE;
|
||||
//
|
||||
// curl_easy_cleanup(curl);
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
||||
size_t CFileTransfer_crul::WriteToBuff(void *ptr, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
memcpy((char *)userp, ptr, (size * nmemb));
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
int CFileTransfer_crul::xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
CFileTransfer_crul* pFileTrans = (CFileTransfer_crul*)p;
|
||||
pFileTrans->m_lTotalRecvFileSize = dltotal;
|
||||
pFileTrans->m_lCurRecvSize = dlnow;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void CFileTransfer_crul::PrintLog(CString strLog)
|
||||
{
|
||||
if (NULL == m_pLog)
|
||||
{
|
||||
MessageBox(NULL, "can't write fileTransfer_crul_log, log File point is NULL", "LOG_ERROR", MB_OK);
|
||||
return;
|
||||
}
|
||||
CString strOutPut = _T("");
|
||||
strOutPut.Format(_T("%04d-%02d-%02d %02d:%02d:%02d.%03d %s \r\n"),g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay,
|
||||
g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond, g_sysCurTime.wMilliseconds, strLog.GetBuffer(0));
|
||||
fwrite(strOutPut.GetBuffer(0), 1, strOutPut.GetLength(), m_pLog);
|
||||
fflush(m_pLog);
|
||||
}
|
||||
|
||||
size_t CFileTransfer_crul::WriteFuncForUrlTest(void *ptr, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
|
||||
return size * nmemb;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,394 @@
|
||||
// GUCodeCreator.cpp: implementation of the CGUCodeCreator class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "GUCodeCreator.h"
|
||||
#include "Constant.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
CGUCodeCreator::CGUCodeCreator()
|
||||
{
|
||||
int iIndex = (int)VAL_ZERO;
|
||||
char cChar = '0';
|
||||
/*
|
||||
while (iIndex < 6)
|
||||
{
|
||||
m_aMacAddress[iIndex++] = (int)VAL_ZERO;
|
||||
}
|
||||
*/
|
||||
memset(m_aMacAddress, 0, sizeof(m_aMacAddress));
|
||||
|
||||
iIndex = (int)VAL_ZERO;
|
||||
while (iIndex < 10)
|
||||
{
|
||||
m_aMappingTable[iIndex++] = cChar++;
|
||||
}
|
||||
|
||||
cChar = 'A';
|
||||
while (iIndex < 32)
|
||||
{
|
||||
m_aMappingTable[iIndex++] = cChar++;
|
||||
}
|
||||
}
|
||||
|
||||
CGUCodeCreator::~CGUCodeCreator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CGUCodeCreator::GetMacAddress(BYTE *pMacAddress)
|
||||
{
|
||||
PIP_ADAPTER_INFO pAdapterInfo;
|
||||
DWORD dwAdapterInfoSize;
|
||||
DWORD dwErr;
|
||||
int iIndex = 0;
|
||||
|
||||
dwAdapterInfoSize = 0;
|
||||
dwErr = GetAdaptersInfo(NULL, &dwAdapterInfoSize);
|
||||
if ((dwErr != (int)VAL_ZERO) && (dwErr != ERROR_BUFFER_OVERFLOW))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pAdapterInfo = (PIP_ADAPTER_INFO)GlobalAlloc(GPTR, dwAdapterInfoSize);
|
||||
if (pAdapterInfo == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
PIP_ADAPTER_INFO pTemp = pAdapterInfo;
|
||||
if (GetAdaptersInfo(pAdapterInfo, &dwAdapterInfoSize) != (int)VAL_ZERO)
|
||||
{
|
||||
GlobalFree(pAdapterInfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
while (pAdapterInfo)
|
||||
{
|
||||
if (pAdapterInfo->Type == MIB_IF_TYPE_ETHERNET)
|
||||
{
|
||||
for (iIndex = (int)VAL_ZERO; iIndex < 6; iIndex++)
|
||||
{
|
||||
*pMacAddress++ = pAdapterInfo->Address[iIndex];
|
||||
}
|
||||
break;
|
||||
}
|
||||
pAdapterInfo = pAdapterInfo->Next;
|
||||
}
|
||||
|
||||
if (pTemp)
|
||||
{
|
||||
GlobalFree(pTemp);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DWORD CGUCodeCreator::GetTotalSecond()
|
||||
{
|
||||
int iYear = (int)YEAR_BASE;
|
||||
int iCurYear = (int)VAL_ZERO;
|
||||
int iCurDay = (int)VAL_ZERO;
|
||||
int iCurHour = (int)VAL_ZERO;
|
||||
int iCurMin = (int)VAL_ZERO;
|
||||
int iCurSec = (int)VAL_ZERO;
|
||||
DWORD dwSecond = (DWORD)VAL_ZERO;
|
||||
time_t lTime = (time_t)VAL_ZERO;
|
||||
struct tm *pTM = NULL;
|
||||
|
||||
Sleep(1000);
|
||||
time(&lTime);
|
||||
|
||||
pTM = localtime(&lTime);
|
||||
|
||||
iCurYear = 1900 + pTM->tm_year;
|
||||
iCurDay = pTM->tm_yday;
|
||||
iCurHour = pTM->tm_hour;
|
||||
iCurMin = pTM->tm_min;
|
||||
iCurSec = pTM->tm_sec;
|
||||
|
||||
dwSecond = iCurDay*86400+((iCurHour*60+iCurMin)*60+iCurSec+1);
|
||||
|
||||
while (iYear < iCurYear)
|
||||
{
|
||||
if (((iYear % 4 == (int)VAL_ZERO) && (iYear % 100 != (int)VAL_ZERO)) || (iYear % 400 == (int)VAL_ZERO))
|
||||
{
|
||||
dwSecond += 31622400;
|
||||
}
|
||||
else
|
||||
{
|
||||
dwSecond += 31536000;
|
||||
}
|
||||
iYear++;
|
||||
}
|
||||
|
||||
return dwSecond;
|
||||
}
|
||||
|
||||
bool CGUCodeCreator::ChangeMacAddressToCode(char *pCode)
|
||||
{
|
||||
BYTE bTempVal = (BYTE)VAL_ZERO;
|
||||
BYTE bHTempVal = (BYTE)VAL_ZERO, bMTempVal = (BYTE)VAL_ZERO, bLTempVal = (BYTE)VAL_ZERO;
|
||||
int aTempVal[10] = {(int)VAL_ZERO};
|
||||
int iIndex = (int)VAL_ZERO;
|
||||
|
||||
bLTempVal = this->m_aMacAddress[5];
|
||||
bLTempVal &= 0x1F;
|
||||
aTempVal[9] = (int)bLTempVal;
|
||||
|
||||
bLTempVal = (BYTE)VAL_ZERO;
|
||||
bHTempVal = (BYTE)VAL_ZERO;
|
||||
bLTempVal = m_aMacAddress[5];
|
||||
bLTempVal >>= 5;
|
||||
bHTempVal = m_aMacAddress[4];
|
||||
bHTempVal <<= 3;
|
||||
bHTempVal &= 0x18;
|
||||
aTempVal[8] = (int)(bHTempVal | bLTempVal);
|
||||
|
||||
bLTempVal = (BYTE)VAL_ZERO;
|
||||
bHTempVal = (BYTE)VAL_ZERO;
|
||||
bLTempVal = m_aMacAddress[4];
|
||||
bLTempVal >>= 2;
|
||||
bLTempVal &= 0x1F;
|
||||
aTempVal[7] = (int)bLTempVal;
|
||||
|
||||
bLTempVal = (BYTE)VAL_ZERO;
|
||||
bHTempVal = (BYTE)VAL_ZERO;
|
||||
bLTempVal = m_aMacAddress[4];
|
||||
bLTempVal >>= 7;
|
||||
bHTempVal = m_aMacAddress[3];
|
||||
bHTempVal <<= 1;
|
||||
bHTempVal &= 0x1E;
|
||||
aTempVal[6] = (int)(bHTempVal | bLTempVal);
|
||||
|
||||
bLTempVal = (BYTE)VAL_ZERO;
|
||||
bHTempVal = (BYTE)VAL_ZERO;
|
||||
bLTempVal = m_aMacAddress[3];
|
||||
bLTempVal >>= 4;
|
||||
bHTempVal = m_aMacAddress[2];
|
||||
bHTempVal <<= 4;
|
||||
bHTempVal &= 0x10;
|
||||
aTempVal[5] = (int)(bHTempVal | bLTempVal);
|
||||
|
||||
bLTempVal = (BYTE)VAL_ZERO;
|
||||
bHTempVal = (BYTE)VAL_ZERO;
|
||||
bLTempVal = m_aMacAddress[2];
|
||||
bLTempVal >>= 1;
|
||||
bLTempVal &= 0x1F;
|
||||
aTempVal[4] = (int)bLTempVal;
|
||||
|
||||
bLTempVal = (BYTE)VAL_ZERO;
|
||||
bHTempVal = (BYTE)VAL_ZERO;
|
||||
bLTempVal = m_aMacAddress[2];
|
||||
bLTempVal >>= 6;
|
||||
bHTempVal = m_aMacAddress[1];
|
||||
bHTempVal <<= 2;
|
||||
bHTempVal &= 0x1C;
|
||||
aTempVal[3] = (int)(bHTempVal | bLTempVal);
|
||||
|
||||
bLTempVal = (BYTE)VAL_ZERO;
|
||||
bHTempVal = (BYTE)VAL_ZERO;
|
||||
bLTempVal = m_aMacAddress[1];
|
||||
bLTempVal >>= 3;
|
||||
aTempVal[2] = (int)bLTempVal;
|
||||
|
||||
bLTempVal = (BYTE)VAL_ZERO;
|
||||
bHTempVal = (BYTE)VAL_ZERO;
|
||||
bLTempVal = m_aMacAddress[0];
|
||||
bLTempVal &= 0x1F;
|
||||
aTempVal[1] = (int)bLTempVal;
|
||||
|
||||
bLTempVal = (BYTE)VAL_ZERO;
|
||||
bHTempVal = (BYTE)VAL_ZERO;
|
||||
bLTempVal = this->m_aMacAddress[0];
|
||||
bLTempVal >>= 5;
|
||||
aTempVal[0] = (int)bLTempVal;
|
||||
|
||||
iIndex = 9;
|
||||
while (iIndex >= (int)VAL_ZERO)
|
||||
{
|
||||
*(pCode+iIndex) = m_aMappingTable[(int)aTempVal[iIndex]];
|
||||
iIndex--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGUCodeCreator::ChangeTotalSecToCode(char *pCode)
|
||||
{
|
||||
int aTempVal[GUC_LENGTH-11] = {(int)VAL_ZERO};
|
||||
int iIndex = (int)VAL_ZERO;
|
||||
DWORD dwSec = (DWORD)VAL_ZERO;
|
||||
|
||||
dwSec = m_dwCurTotalSec;
|
||||
for (iIndex = (GUC_LENGTH-12); iIndex >= (int)VAL_ZERO; iIndex--)
|
||||
{
|
||||
aTempVal[iIndex] = dwSec & 0x0000001F;
|
||||
dwSec >>= 5;
|
||||
}
|
||||
|
||||
for (iIndex = (GUC_LENGTH-12); iIndex >= (int)VAL_ZERO; iIndex--)
|
||||
{
|
||||
*(pCode+iIndex) = m_aMappingTable[(int)aTempVal[iIndex]];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CString CGUCodeCreator::GenerateGUCode()
|
||||
{
|
||||
int iIndex = (int)VAL_ZERO;
|
||||
char aGUCode[GUC_LENGTH] = {0};
|
||||
CString szGUCode;
|
||||
|
||||
while (iIndex < GUC_LENGTH)
|
||||
{
|
||||
aGUCode[iIndex++] = (int)VAL_ZERO;
|
||||
}
|
||||
|
||||
memset(m_aMacAddress, 0, sizeof(m_aMacAddress));
|
||||
GetMacAddress((BYTE*)m_aMacAddress);
|
||||
m_dwCurTotalSec = GetTotalSecond();
|
||||
|
||||
ChangeMacAddressToCode((char*)aGUCode);
|
||||
ChangeTotalSecToCode((char*)(aGUCode+10));
|
||||
|
||||
szGUCode.Empty();
|
||||
szGUCode = (LPCTSTR)aGUCode;
|
||||
return szGUCode;
|
||||
}
|
||||
|
||||
CString CGUCodeCreator::GenerateGUIDCode()
|
||||
{
|
||||
CString szGUID = _T("");
|
||||
GUID guid;
|
||||
|
||||
::CoInitialize(NULL);
|
||||
|
||||
if(S_OK == ::CoCreateGuid(&guid))
|
||||
{
|
||||
szGUID.Empty();
|
||||
szGUID.Format("%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
|
||||
guid.Data1,
|
||||
guid.Data2,
|
||||
guid.Data3,
|
||||
guid.Data4[0], guid.Data4[1],
|
||||
guid.Data4[2], guid.Data4[3],
|
||||
guid.Data4[4], guid.Data4[5],
|
||||
guid.Data4[6], guid.Data4[7]);
|
||||
}
|
||||
|
||||
::CoUninitialize();
|
||||
return szGUID;
|
||||
}
|
||||
|
||||
CString CGUCodeCreator::GenerateMacAddress(void)
|
||||
{
|
||||
|
||||
CString szMacAddress = _T("");
|
||||
|
||||
|
||||
memset(m_aMacAddress, 0, sizeof(m_aMacAddress));
|
||||
GetMacAddress((BYTE*)m_aMacAddress);
|
||||
|
||||
//////////////////////////////add by lsq 20160402////////////////////////////////////////////
|
||||
//在这里由于去除注册功能的需要,因此将所有机器的MAC地址用
|
||||
//统一的一个MAC地址来代替
|
||||
memset(m_aMacAddress, 0, sizeof(m_aMacAddress));
|
||||
m_aMacAddress[0] = 0x00;
|
||||
m_aMacAddress[1] = 0x00;
|
||||
m_aMacAddress[2] = 0x00;
|
||||
m_aMacAddress[3] = 0xFF;
|
||||
m_aMacAddress[4] = 0xFF;
|
||||
m_aMacAddress[5] = 0xFF;
|
||||
|
||||
/////////////////////////////////end/////////////////////////////////////////
|
||||
|
||||
|
||||
szMacAddress.Empty();
|
||||
szMacAddress.Format(_T("%02X%02X%02X%02X%02X%02X"),
|
||||
m_aMacAddress[0],
|
||||
m_aMacAddress[1],
|
||||
m_aMacAddress[2],
|
||||
m_aMacAddress[3],
|
||||
m_aMacAddress[4],
|
||||
m_aMacAddress[5]);
|
||||
|
||||
return szMacAddress;
|
||||
}
|
||||
|
||||
void CGUCodeCreator::GetMacList(CStringArray *f_macArray)
|
||||
{
|
||||
//added by lsq 20160406
|
||||
//由于上下微机统一使用一个MAC地址,所以这里直接用这个MAC地址返回,之前的代码就不用了
|
||||
f_macArray->Add(_T("000000FFFFFF"));
|
||||
return;
|
||||
|
||||
/////////////////////////////end/////////////////////////////////////////////
|
||||
PIP_ADAPTER_INFO pAdapterInfo;
|
||||
DWORD dwAdapterInfoSize;
|
||||
DWORD dwErr;
|
||||
int iIndex = 0;
|
||||
|
||||
BYTE bMac[16];
|
||||
memset(bMac, 0, 16);
|
||||
CString szTmp = _T("");
|
||||
|
||||
dwAdapterInfoSize = 0;
|
||||
dwErr = GetAdaptersInfo(NULL, &dwAdapterInfoSize);
|
||||
if ((dwErr != (int)VAL_ZERO) && (dwErr != ERROR_BUFFER_OVERFLOW))
|
||||
{
|
||||
f_macArray->Add("000000000000");
|
||||
return;
|
||||
}
|
||||
|
||||
pAdapterInfo = (PIP_ADAPTER_INFO)GlobalAlloc(GPTR, dwAdapterInfoSize);
|
||||
if (pAdapterInfo == NULL)
|
||||
{
|
||||
f_macArray->Add("000000000000");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetAdaptersInfo(pAdapterInfo, &dwAdapterInfoSize) != (int)VAL_ZERO)
|
||||
{
|
||||
GlobalFree(pAdapterInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
while (pAdapterInfo)
|
||||
{
|
||||
if (pAdapterInfo->Type == MIB_IF_TYPE_ETHERNET)
|
||||
{
|
||||
for (iIndex = (int)VAL_ZERO; iIndex < 6; iIndex++)
|
||||
{
|
||||
bMac[iIndex] = pAdapterInfo->Address[iIndex];
|
||||
}
|
||||
|
||||
szTmp.Format(_T("%02X%02X%02X%02X%02X%02X"),
|
||||
bMac[0],
|
||||
bMac[1],
|
||||
bMac[2],
|
||||
bMac[3],
|
||||
bMac[4],
|
||||
bMac[5]);
|
||||
f_macArray->Add(szTmp);
|
||||
}
|
||||
pAdapterInfo = pAdapterInfo->Next;
|
||||
}
|
||||
|
||||
if (f_macArray->GetSize() == 0)
|
||||
{
|
||||
f_macArray->Add("000000000000");
|
||||
}
|
||||
|
||||
GlobalFree(pAdapterInfo);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// GetProcessInfo.cpp: implementation of the CGetProcessInfo class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "GetProcessInfo.h"
|
||||
#include <tlhelp32.h>
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
#ifndef PSAPI_VERSION
|
||||
#define PSAPI_VERSION 1
|
||||
#endif
|
||||
|
||||
#include <Psapi.h>
|
||||
#pragma comment (lib,"Psapi.lib")
|
||||
|
||||
#define ProcessBasicInformation 0
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CGetProcessInfo* CGetProcessInfo::m_pGetProcessInfo = NULL;
|
||||
|
||||
CGetProcessInfo::CGetProcessInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CGetProcessInfo::~CGetProcessInfo()
|
||||
{
|
||||
if (m_pGetProcessInfo)
|
||||
{
|
||||
delete m_pGetProcessInfo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
CGetProcessInfo* CGetProcessInfo::CreateInstance()
|
||||
{
|
||||
if (NULL == m_pGetProcessInfo)
|
||||
{
|
||||
m_pGetProcessInfo = new CGetProcessInfo();
|
||||
}
|
||||
return m_pGetProcessInfo;
|
||||
}
|
||||
|
||||
DWORD CGetProcessInfo :: GetProcessIdFromName(CString strProcessName, DWORD &dwParentProcessId)
|
||||
{
|
||||
DWORD dwProcessID =0;
|
||||
|
||||
//进行一个进程快照
|
||||
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
||||
if (hProcessSnap == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
OutputDebugString(_T("进程快照失败!"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
PROCESSENTRY32 pe;
|
||||
pe.dwSize = sizeof(pe);
|
||||
BOOL bProcess = Process32First(hProcessSnap,&pe);
|
||||
while (bProcess)
|
||||
{
|
||||
if (strProcessName.CompareNoCase(pe.szExeFile) == 0)
|
||||
{
|
||||
dwProcessID = pe.th32ProcessID;
|
||||
dwParentProcessId = pe.th32ParentProcessID; //pe结构中包含有父进程的ID
|
||||
}
|
||||
bProcess = Process32Next(hProcessSnap,&pe);
|
||||
}
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
|
||||
return dwProcessID;
|
||||
}
|
||||
|
||||
DWORD CGetProcessInfo :: GetParentProcessId(DWORD dwChildProcessId)
|
||||
{
|
||||
//NtQueryInformationProcess函数的使用需要加载进ntdll.dll
|
||||
PROCNTQSIP NtQueryInformationProcess = (PROCNTQSIP)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQueryInformationProcess");
|
||||
|
||||
if(!NtQueryInformationProcess)
|
||||
{
|
||||
OutputDebugString(_T("ntdll.dll中检索NtQueryInformationProcess失败!"));
|
||||
}
|
||||
|
||||
DWORD dwParentProcessId = 0;
|
||||
LONG status;
|
||||
PROCESS_BASIC_INFORMATION pbi;
|
||||
|
||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,dwChildProcessId);
|
||||
if (!hProcess)
|
||||
{
|
||||
OutputDebugString(_T("OpenProcess Error!"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
status = NtQueryInformationProcess( hProcess, ProcessBasicInformation, (PVOID)&pbi, sizeof(PROCESS_BASIC_INFORMATION), NULL);
|
||||
|
||||
if (!status)
|
||||
{
|
||||
dwParentProcessId = (DWORD)pbi.InheritedFromUniqueProcessId;
|
||||
CString strParentID;
|
||||
strParentID.Format(_T("%d"), dwParentProcessId);
|
||||
OutputDebugString(_T("ParentProcessID:")+strParentID);
|
||||
}
|
||||
|
||||
return dwParentProcessId;
|
||||
}
|
||||
|
||||
CString CGetProcessInfo :: GetProcessNameFromId(DWORD dwProcessId)
|
||||
{
|
||||
CString strProcessName;
|
||||
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, dwProcessId);
|
||||
if (NULL != hProcess )
|
||||
{
|
||||
|
||||
HMODULE hMod;
|
||||
DWORD cbNeeded;
|
||||
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
|
||||
{
|
||||
GetModuleBaseName( hProcess, hMod, strProcessName.GetBuffer(MAX_PATH), MAX_PATH);
|
||||
strProcessName.ReleaseBuffer();
|
||||
}
|
||||
}
|
||||
return strProcessName;
|
||||
}
|
||||
|
||||
|
||||
DWORD CGetProcessInfo :: GetSpcialProcessIdFromName(CString strProcessName, DWORD dwParentProcessId)
|
||||
{
|
||||
DWORD dwProcessID =0;
|
||||
|
||||
//进行一个进程快照
|
||||
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
|
||||
if (hProcessSnap == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
OutputDebugString(_T("进程快照失败!"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
PROCESSENTRY32 pe;
|
||||
pe.dwSize = sizeof(pe);
|
||||
BOOL bProcess = Process32First(hProcessSnap,&pe);
|
||||
CString strInfo = _T("");
|
||||
while (bProcess)
|
||||
{
|
||||
if (strProcessName.CompareNoCase(pe.szExeFile) == 0)
|
||||
{
|
||||
if (dwParentProcessId == pe.th32ParentProcessID)
|
||||
{
|
||||
dwProcessID = pe.th32ProcessID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bProcess = Process32Next(hProcessSnap,&pe);
|
||||
}
|
||||
|
||||
CloseHandle(hProcessSnap);
|
||||
|
||||
return dwProcessID;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// HandleProcessor.cpp: implementation of the CHandleProcessor class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "HandleProcessor.h"
|
||||
#include "Constant.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CHandleProcessor::CHandleProcessor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CHandleProcessor::~CHandleProcessor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DWORD CHandleProcessor::GenerateHandle(DWORD dwID, UINT uStyle)
|
||||
{
|
||||
DWORD dwtempHandle = (DWORD)VAL_ZERO;
|
||||
DWORD dwTempID = (DWORD)VAL_ZERO;
|
||||
DWORD dwTempStyle = (DWORD)VAL_ZERO;
|
||||
|
||||
dwTempID = (DWORD)dwID;
|
||||
dwTempStyle = (DWORD)uStyle;
|
||||
|
||||
dwTempStyle <<= HANDLE_OFFSET;
|
||||
dwtempHandle = dwTempID | dwTempStyle;
|
||||
|
||||
return dwtempHandle;
|
||||
}
|
||||
|
||||
DWORD CHandleProcessor::GenerateNewHandle(DWORD dwID, UINT uStyle)
|
||||
{
|
||||
DWORD dwtempHandle = (DWORD)VAL_ZERO;
|
||||
DWORD dwTempID = (DWORD)VAL_ZERO;
|
||||
DWORD dwTempStyle = (DWORD)VAL_ZERO;
|
||||
|
||||
dwTempID = dwID&0x07FFFFFF;
|
||||
dwTempStyle = (DWORD)uStyle;
|
||||
|
||||
dwTempStyle <<= HANDLE_OFFSET;
|
||||
dwtempHandle = dwTempID | dwTempStyle;
|
||||
|
||||
return dwtempHandle;
|
||||
}
|
||||
|
||||
void CHandleProcessor::AnalyseHandle(DWORD dwHandle, DWORD& dwID, UINT& uStyle)
|
||||
{
|
||||
DWORD dwTempHandle = VAL_ZERO;
|
||||
DWORD dwTempID = VAL_ZERO;
|
||||
DWORD dwTempStyle = VAL_ZERO;
|
||||
|
||||
dwTempHandle = dwHandle;
|
||||
dwTempID = dwTempHandle & 0x7FFFFFF;
|
||||
dwTempStyle = dwTempHandle & 0xF8000000;
|
||||
dwTempStyle >>= HANDLE_OFFSET;
|
||||
|
||||
dwID = dwTempID;
|
||||
uStyle = (UINT)dwTempStyle;
|
||||
}
|
||||
|
||||
DWORD CHandleProcessor::GetIDFromHandle(DWORD dwHandle)
|
||||
{
|
||||
DWORD dwTempHandle = VAL_ZERO;
|
||||
DWORD dwTempID = VAL_ZERO;
|
||||
|
||||
dwTempHandle = dwHandle;
|
||||
dwTempID = dwTempHandle & 0x7FFFFFF;
|
||||
|
||||
return dwTempID;
|
||||
}
|
||||
|
||||
UINT CHandleProcessor::GetStyleFromHandle(DWORD dwHandle)
|
||||
{
|
||||
DWORD dwTempHandle = VAL_ZERO;
|
||||
DWORD dwTempStyle = VAL_ZERO;
|
||||
|
||||
dwTempHandle = dwHandle;
|
||||
dwTempStyle = dwTempHandle & 0xF8000000;
|
||||
dwTempStyle >>= HANDLE_OFFSET;
|
||||
|
||||
return (UINT)dwTempStyle;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,154 @@
|
||||
// MyCopyFile.cpp: implementation of the CMyCopyFile class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "MyCopyFile.h"
|
||||
#include "DetcGD10Dev.h"
|
||||
#include "FileOperTools.h"
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
FILE* CMyCopyFile::g_pCopyFileLog = NULL;
|
||||
CRITICAL_SECTION* CMyCopyFile::g_pLogCriticSec = NULL;
|
||||
extern SYSTEMTIME g_sysCurTime;
|
||||
extern BOOL g_bCancelCopyFile;
|
||||
extern int g_iUILanguage;
|
||||
CMyCopyFile::CMyCopyFile()
|
||||
{
|
||||
if (NULL == g_pCopyFileLog)
|
||||
{
|
||||
g_pCopyFileLog = fopen("LOG\\transfer_file.txt","ab+");
|
||||
if (NULL == g_pCopyFileLog)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("打开转发文件日志失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Open transfer file log failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == g_pLogCriticSec)
|
||||
{
|
||||
g_pLogCriticSec = new CRITICAL_SECTION;
|
||||
if (NULL == g_pLogCriticSec)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("创建临界区失败!"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Create CRITICAL_SECTION failed!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
else
|
||||
InitializeCriticalSection(g_pLogCriticSec);
|
||||
}
|
||||
memset(&m_liTotalFileSize, 0, sizeof(m_liTotalFileSize));
|
||||
memset(&m_liTransferedBytes, 0, sizeof(m_liTransferedBytes));
|
||||
m_iErrorCode = -1;
|
||||
m_bIsCancelCopy = FALSE;
|
||||
|
||||
}
|
||||
|
||||
CMyCopyFile::~CMyCopyFile()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMyCopyFile::Initialize()
|
||||
{
|
||||
memset(&m_liTotalFileSize, 0, sizeof(m_liTotalFileSize));
|
||||
memset(&m_liTransferedBytes, 0, sizeof(m_liTransferedBytes));
|
||||
m_iErrorCode = -1;
|
||||
}
|
||||
|
||||
|
||||
void CMyCopyFile::GetTransferInfo(DWORD &dwTransferedBytes, DWORD &dwTotalFileSize)
|
||||
{
|
||||
dwTransferedBytes = m_liTransferedBytes.LowPart;
|
||||
dwTotalFileSize = m_liTotalFileSize.LowPart;
|
||||
}
|
||||
|
||||
bool CMyCopyFile::TransferFile(CString strSrcDir, CString strDstDir, CString strFileName)
|
||||
{
|
||||
CString strText = _T("");
|
||||
CString strDstFilePath = _T("");
|
||||
strDstFilePath.Format(_T("%s\\%s"),strDstDir,strFileName);
|
||||
DeleteFile(strDstFilePath);
|
||||
CString strSrcFilePath = _T("");
|
||||
strSrcFilePath.Format(_T("%s\\%s"),strSrcDir,strFileName);
|
||||
if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(strSrcFilePath))
|
||||
{
|
||||
strText.Empty();
|
||||
strText.Format(_T("Get SrcFile Attributes failed, filepath = %s"),strSrcFilePath);
|
||||
PrintLog(strText);
|
||||
m_iErrorCode = EN_GET_SRCATTRI_FAILED;
|
||||
return false;
|
||||
}
|
||||
m_bIsCancelCopy = FALSE;
|
||||
if (0 == CopyFileEx(strSrcFilePath,strDstFilePath,CopyProgressInfo,(LPVOID)this,
|
||||
&m_bIsCancelCopy,COPY_FILE_FAIL_IF_EXISTS))
|
||||
{
|
||||
m_iErrorCode = GetLastError();
|
||||
strText.Empty();
|
||||
if (ERROR_REQUEST_ABORTED == m_iErrorCode)
|
||||
strText.Format(_T("copy file failed because of progress_routine cancel copy operation,srcfile = %s,dstfile = %s"),
|
||||
strSrcFilePath,strDstFilePath);
|
||||
else
|
||||
strText.Format(_T("copy file failed, errorno = %d, srcfile = %s, dstfile = %s"),
|
||||
m_iErrorCode, strSrcFilePath, strDstFilePath);
|
||||
PrintLog(strText);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMyCopyFile::PrintLog(const CString& strLog)
|
||||
{
|
||||
if (NULL == g_pCopyFileLog)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("无法写入transfer_log,日志文件点为空"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Can't write transfer_log, log File point is NULL"), _T("LOG_ERROR"), MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
if (NULL == g_pLogCriticSec)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("不能写transfer_log,日志临界切片点为空"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Can't write transfer_log, log critical section point is NULL"), _T("LOG_ERROR"), MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return;
|
||||
}
|
||||
EnterCriticalSection(g_pLogCriticSec);
|
||||
CString strOutPut = _T("");
|
||||
strOutPut.Format(_T("%04d-%02d-%02d %02d:%02d:%02d.%03d %s \r\n"),g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay,
|
||||
g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond, g_sysCurTime.wMilliseconds, strLog);
|
||||
fwrite(strOutPut, 1, strOutPut.GetLength(), g_pCopyFileLog);
|
||||
fflush(g_pCopyFileLog);
|
||||
LeaveCriticalSection(g_pLogCriticSec);
|
||||
}
|
||||
|
||||
DWORD CALLBACK CMyCopyFile::CopyProgressInfo(LARGE_INTEGER iTotalFileSize, LARGE_INTEGER iTotalBytesTransferred, LARGE_INTEGER iStreamSize,
|
||||
LARGE_INTEGER iStreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason,
|
||||
HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData)
|
||||
{
|
||||
CMyCopyFile* pCopyFile = (CMyCopyFile*)lpData;
|
||||
pCopyFile->m_liTotalFileSize = iTotalFileSize;
|
||||
pCopyFile->m_liTransferedBytes = iTotalBytesTransferred;
|
||||
//如果此时发现USB设备被拔出,则取消传输
|
||||
if (FALSE == CDetcGD10Dev::GetInstance()->IsGD10DevConnect())
|
||||
{
|
||||
CString strLog = _T("");
|
||||
strLog.Format(_T("[CopyFile][%d]Usb device was pull out,copy file was canceled!"), __LINE__);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return PROGRESS_CANCEL;
|
||||
}
|
||||
return PROGRESS_CONTINUE;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,706 @@
|
||||
// NetWorkOper.cpp: implementation of the CNetWorkOper class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#include "StdAfx.h"
|
||||
#include "GeoMative.h"
|
||||
#include "NetWorkOper.h"
|
||||
#include "TransferCtrl.h"
|
||||
#include "TaskDataOper.h"
|
||||
#include "Lock\AutoLock.h"
|
||||
#include "FileOperTools.h"
|
||||
#include "MainFrm.h"
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
extern int g_iTransFileMode;
|
||||
extern BOOL g_bIsOnlineTransfer;
|
||||
extern int g_iUILanguage;
|
||||
extern CGeoMativeApp theApp;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CNetWorkOper::CNetWorkOper()
|
||||
{
|
||||
InitializeCriticalSection(&m_netCs);
|
||||
InitializeCriticalSection(&m_realHwndCs);
|
||||
m_tcpClient = NULL;
|
||||
m_bIsRunning = false;
|
||||
m_pThread = NULL;
|
||||
m_bIsTransfer = false;
|
||||
m_pNotifyFunc = NULL;
|
||||
m_bIsNeedResp = false;
|
||||
m_bIsNeedSend = false;
|
||||
m_ucCmd = 0;
|
||||
m_pNotifyParam = NULL;
|
||||
m_pDevNotifyFunc = NULL;
|
||||
memset(m_chSendBuf, 0, sizeof(m_chSendBuf));
|
||||
m_pDevNotfiyParam = NULL;
|
||||
m_bIsSuspend = false;
|
||||
m_bIsGetDevAddr = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
CNetWorkOper::~CNetWorkOper()
|
||||
{
|
||||
ConsumerThread::StopThread();
|
||||
ProducerThread::StopThread();
|
||||
DeleteCriticalSection(&m_netCs);
|
||||
DeleteCriticalSection(&m_realHwndCs);
|
||||
if (m_tcpClient)
|
||||
{
|
||||
m_tcpClient->CloseConnect();
|
||||
delete m_tcpClient;
|
||||
}
|
||||
}
|
||||
|
||||
bool CNetWorkOper::Initialize()
|
||||
{
|
||||
if (NULL != m_tcpClient)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
InitializeCriticalSection(&m_MutexSec);
|
||||
m_tcpClient = new CTransferCtrl();
|
||||
return m_tcpClient->Initialize();
|
||||
}
|
||||
|
||||
bool CNetWorkOper::StartConnect(CString strDstIP, int iPort)
|
||||
{
|
||||
if (strDstIP.IsEmpty() || iPort < 1)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("输入服务器参数错误"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Input server param error"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
CString strLog;
|
||||
strLog.Format(_T("zm: CNetWorkOper::StartConnect connect to server ip=%s, port=%d"), strDstIP, iPort);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
if (NULL == m_tcpClient || !m_tcpClient->ConnectToServer(strDstIP, iPort))
|
||||
{
|
||||
strLog.Format(_T("zm: CNetWorkOper::StartConnect connect to server ip=%s, port=%d failed."), strDstIP, iPort);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return false;
|
||||
}
|
||||
|
||||
strLog.Format(_T("zm: CNetWorkOper::StartConnect connect to server ip=%s, port=%d success."), strDstIP, iPort);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CNetWorkOper::StartWork()
|
||||
{
|
||||
if (NULL == m_tcpClient || !m_tcpClient->GetConnectStatus())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("请先连接服务器"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Please connect to server firstly."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
if (m_pThread)
|
||||
{
|
||||
// AfxMessageBox(_T("Thread has been started,no need to start."));
|
||||
return true;
|
||||
}
|
||||
ConsumerThread::StartThread();
|
||||
ProducerThread::StartThread();
|
||||
|
||||
/*m_pThread = AfxBeginThread(StartProcFunc,(LPVOID)this);
|
||||
if (NULL == m_pThread)
|
||||
{
|
||||
AfxMessageBox(_T("Create process data thread failed."));
|
||||
return false;
|
||||
}*/
|
||||
//ProducerThread::StartThread();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool CNetWorkOper::TransferOper(BYTE ucCmd, STSendDataInfo* pSendCtrl, bool bIsNeedResp, STRespDataInfo* pRespInfo, PNOTIFY_FUNC pNotifyFunc, LPVOID lpParam)
|
||||
{
|
||||
if (m_bIsTransfer)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("请等待转发完成,在启动一个新的转发前"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Please wait for transfer complete before start a new taransfer"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
EnterCriticalSection(&m_MutexSec);
|
||||
|
||||
m_ucCmd = ucCmd;
|
||||
memset(m_chSendBuf, 0, sizeof(m_chSendBuf));
|
||||
memcpy(m_chSendBuf, pSendCtrl->pData, pSendCtrl->wDataLen);
|
||||
m_stSendCtrlInfo.pData = m_chSendBuf;
|
||||
m_stSendCtrlInfo.wDataLen = pSendCtrl->wDataLen;
|
||||
m_stSendCtrlInfo.ucDstType = pSendCtrl->ucDstType;
|
||||
m_stSendCtrlInfo.uiDevID = pSendCtrl->uiDevID;
|
||||
m_bIsNeedSend = true;
|
||||
|
||||
m_bIsNeedResp = bIsNeedResp;
|
||||
memcpy(&m_stRespDataInfo, pRespInfo, sizeof(STRespDataInfo));
|
||||
m_pNotifyFunc = pNotifyFunc;
|
||||
m_pNotifyParam = lpParam;
|
||||
LeaveCriticalSection(&m_MutexSec);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CNetWorkOper::ProcPlcStatus(char* pData, int iLen)
|
||||
{
|
||||
if (iLen != sizeof(STRemPlcDataInfo))
|
||||
{
|
||||
CString strErr = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErr.Format(_T("接受PLC状态长度错误,接收长度 %d,实际长度 %d"), iLen, sizeof(STRemPlcDataInfo));
|
||||
AfxMessageBox(strErr);
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Format(_T("Recv Plc status length error,recv_value = %d,should be %d"), iLen, sizeof(STRemPlcDataInfo));
|
||||
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
const char* pPlcData = pData;
|
||||
//////////////////////////temp add 临时增加接收到定时任务后发送回应////////////////////////////////////////////////
|
||||
SendCtrlMsgDirect(0x88, ntohl(m_tcpClient->GetPlcAddr()), 4, NULL, 0);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CTaskDataOper dataOper;
|
||||
return dataOper.InsertPlcStatusData((const STRemPlcDataInfo*)pPlcData);
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool CNetWorkOper::SendCtrlMsgDirect(BYTE ucCmd, UINT32 uiDevID, BYTE ucDevType, const char* pData, WORD wDataLen)
|
||||
{
|
||||
if (NULL == m_tcpClient || !m_tcpClient->GetConnectStatus())
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("zm: SendCtrlMsgDirect GetConnectStatus --------------------------"));
|
||||
return false;
|
||||
}
|
||||
EnterCriticalSection(&m_MutexSec);
|
||||
STTransCtrlInfo stTransCtrl;
|
||||
stTransCtrl.ucCmd = ucCmd;
|
||||
stTransCtrl.uiDevID = uiDevID;
|
||||
stTransCtrl.ucDevType = ucDevType;
|
||||
|
||||
bool bRes = m_tcpClient->SendCtrlInfo((const char*)(&stTransCtrl), pData, wDataLen);
|
||||
LeaveCriticalSection(&m_MutexSec);
|
||||
if (bRes)
|
||||
m_ucCmd = ucCmd;
|
||||
return bRes;
|
||||
|
||||
}
|
||||
|
||||
int CNetWorkOper::RecvMsgDirect(char* pData, int* pRecvLen, int iMaxRecvLen, int iTimeout)
|
||||
{
|
||||
if (NULL == m_tcpClient || !m_tcpClient->GetConnectStatus())
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("zm: RecvMsgDirect GetConnectStatus --------------------------"));
|
||||
//AfxMessageBox(_T("Line break;"));
|
||||
return EN_RECV_LINK_INTERRUPT;
|
||||
}
|
||||
EnterCriticalSection(&m_MutexSec);
|
||||
int iRet = m_tcpClient->RecvRspMsg(pData, pRecvLen, iMaxRecvLen, iTimeout);
|
||||
LeaveCriticalSection(&m_MutexSec);
|
||||
return iRet;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CNetWorkOper::ClearSendInfo()
|
||||
{
|
||||
CAutoLock clsLock(&m_MutexSec);
|
||||
m_ucCmd = 0;
|
||||
m_bIsNeedSend = false;
|
||||
m_bIsNeedResp = false;
|
||||
memset(&m_stSendCtrlInfo, 0, sizeof(m_stSendCtrlInfo));
|
||||
memset(&m_stRespDataInfo, 0, sizeof(m_stRespDataInfo));
|
||||
}
|
||||
|
||||
void CNetWorkOper::ClearNotfiyFuncInfo()
|
||||
{
|
||||
CAutoLock clsLock(&m_MutexSec);
|
||||
m_pNotifyFunc = NULL;
|
||||
m_pNotifyParam = NULL;
|
||||
|
||||
}
|
||||
|
||||
bool CNetWorkOper::SendLoginMsgBrocast()
|
||||
{
|
||||
|
||||
BYTE ucData = 3;
|
||||
UINT32 uiDevID = 0;
|
||||
SendCtrlMsgDirect(0xFE, uiDevID, 3, (char*)(&ucData), 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CNetWorkOper::PutRequestPacket(const STRequestPacket& clsRequestPacket)
|
||||
{
|
||||
LPEQUESTPACKET pRequestPacket = new STRequestPacket();
|
||||
pRequestPacket->dwMsgID = clsRequestPacket.dwMsgID;
|
||||
pRequestPacket->hWnd = clsRequestPacket.hWnd;
|
||||
pRequestPacket->clsPacketBase.ucCmd = clsRequestPacket.clsPacketBase.ucCmd;
|
||||
pRequestPacket->clsPacketBase.ucDevType = clsRequestPacket.clsPacketBase.ucDevType;
|
||||
pRequestPacket->clsPacketBase.uiDevID = clsRequestPacket.clsPacketBase.uiDevID;
|
||||
pRequestPacket->wDataLen = clsRequestPacket.wDataLen;
|
||||
pRequestPacket->iMaxRecvLen = clsRequestPacket.iMaxRecvLen;
|
||||
pRequestPacket->iTimeout = clsRequestPacket.iTimeout;
|
||||
|
||||
pRequestPacket->pData = new char[clsRequestPacket.wDataLen];
|
||||
memcpy_s((void *)pRequestPacket->pData, clsRequestPacket.wDataLen, clsRequestPacket.pData, clsRequestPacket.wDataLen);
|
||||
|
||||
this->PutDataToQue(pRequestPacket);
|
||||
}
|
||||
|
||||
void CNetWorkOper::ReleaseData(void* pData)
|
||||
{
|
||||
LPEQUESTPACKET pRequestPacket = (LPEQUESTPACKET)pData;
|
||||
if (NULL == pRequestPacket)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRequestPacket->pData != NULL)
|
||||
{
|
||||
delete[] pRequestPacket->pData;
|
||||
pRequestPacket->pData = NULL;
|
||||
}
|
||||
delete[] pRequestPacket;
|
||||
pRequestPacket = NULL;
|
||||
}
|
||||
|
||||
void CNetWorkOper::ConsumeDataFromQue(void * pData)
|
||||
{
|
||||
LPEQUESTPACKET pRequestPacket = (LPEQUESTPACKET)pData;
|
||||
if (NULL == pRequestPacket)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD dwWParam = -1; //0-获取消息成功 1-发送消息失败 2-获取数据失败
|
||||
char *pRecvDataBuf = NULL;
|
||||
int iRet = 0;
|
||||
int iLen = 0;
|
||||
{
|
||||
CAutoLock clsAutoLock(&m_netCs);
|
||||
if (!SendCtrlMsgDirect(pRequestPacket->clsPacketBase.ucCmd, pRequestPacket->clsPacketBase.uiDevID,
|
||||
pRequestPacket->clsPacketBase.ucDevType, pRequestPacket->pData, pRequestPacket->wDataLen))
|
||||
{
|
||||
dwWParam = 11;
|
||||
}
|
||||
|
||||
//只有点名函数需要处理
|
||||
if ((EN_CTRL_ROLLCALL_CABLE == pRequestPacket->clsPacketBase.ucCmd)
|
||||
|| (EN_REQ_DOWNLOAD_CABLE_INFO == pRequestPacket->clsPacketBase.ucCmd))
|
||||
{
|
||||
::SendMessage(pRequestPacket->hWnd, WM_MSG_SEND_CABLE_ROLLCALL, dwWParam, pRequestPacket->clsPacketBase.ucCmd);
|
||||
}
|
||||
|
||||
pRecvDataBuf = new char[pRequestPacket->iMaxRecvLen];
|
||||
|
||||
iLen = pRequestPacket->iMaxRecvLen;
|
||||
iRet = RecvMsgDirect(pRecvDataBuf, &iLen, pRequestPacket->iMaxRecvLen, pRequestPacket->iTimeout);
|
||||
if (EN_RECV_SUCCESS != iRet)
|
||||
{
|
||||
dwWParam = 22;
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 != dwWParam)
|
||||
{
|
||||
::SendMessage(pRequestPacket->hWnd, pRequestPacket->dwMsgID, iRet, NULL);
|
||||
//::SendMessage(pRequestPacket->hWnd, pRequestPacket->dwMsgID, dwWParam, NULL);
|
||||
delete[] pRecvDataBuf;
|
||||
return;
|
||||
}
|
||||
|
||||
dwWParam = 0;
|
||||
ST_RESPONSE_PACKET clsResponsePacket;
|
||||
clsResponsePacket.clsPacketBase.ucCmd = pRequestPacket->clsPacketBase.ucCmd;
|
||||
clsResponsePacket.clsPacketBase.ucDevType = pRequestPacket->clsPacketBase.ucDevType;
|
||||
clsResponsePacket.clsPacketBase.uiDevID = pRequestPacket->clsPacketBase.uiDevID;
|
||||
clsResponsePacket.pData = pRecvDataBuf;
|
||||
clsResponsePacket.wDataLen = iLen;
|
||||
|
||||
::SendMessage(pRequestPacket->hWnd, pRequestPacket->dwMsgID, dwWParam, (LPARAM)&clsResponsePacket);
|
||||
delete[] pRecvDataBuf;
|
||||
pRecvDataBuf = NULL;
|
||||
}
|
||||
|
||||
void CNetWorkOper::RegeditRealMsgCall(HWND hWnd)
|
||||
{
|
||||
CAutoLock clsLock(&m_realHwndCs);
|
||||
list<HWND>::iterator iterFind = std::find(m_listRealHwnd.begin(), m_listRealHwnd.end(), hWnd);
|
||||
if (iterFind != m_listRealHwnd.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_listRealHwnd.push_back(hWnd);
|
||||
}
|
||||
|
||||
void CNetWorkOper::UnRegeditRealMsgCall(HWND hWnd)
|
||||
{
|
||||
CAutoLock clsLock(&m_realHwndCs);
|
||||
list<HWND>::iterator iterFind = std::find(m_listRealHwnd.begin(), m_listRealHwnd.end(), hWnd);
|
||||
if (iterFind == m_listRealHwnd.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_listRealHwnd.erase(iterFind);
|
||||
}
|
||||
void CNetWorkOper::ThreadFunction()
|
||||
{
|
||||
while (ProducerThread::m_bEngineRunning)
|
||||
{
|
||||
if (!m_tcpClient->GetConnectStatus())
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("zm: ThreadFunction() GetConnectStatus --------------------------"));
|
||||
//隔30秒进行重连操作
|
||||
//m_tcpClient->CloseConnect();
|
||||
//Sleep(10000);
|
||||
if (!m_tcpClient->ReConnect())
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("zm: ThreadFunction() ReConnect() --------------------------"));
|
||||
Sleep(5000);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int iCtrlLen = 0;
|
||||
int iRet;
|
||||
int iCtrlRes;
|
||||
|
||||
{
|
||||
CAutoLock clsAutoLock(&m_netCs);
|
||||
//接收实时消息并判断是否有接受到控制类的报文
|
||||
iCtrlRes = m_tcpClient->RecvCtrlMsg(m_chRcvCtrlBuf, &iCtrlLen, MAX_RCV_CTRLBUF, 100);
|
||||
}
|
||||
if (EN_RECV_CTRL_CMD == iCtrlRes)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:EN_RECV_CTRL_CMD begin..................");
|
||||
|
||||
BYTE ucCmd = m_tcpClient->GetCurrCtrlCmd();
|
||||
if (m_pDevNotifyFunc)
|
||||
{
|
||||
STCtrlCmdInfo stCtrlCmd;
|
||||
stCtrlCmd.iDataLen = iCtrlLen;
|
||||
stCtrlCmd.pData = m_chRcvCtrlBuf;
|
||||
m_pDevNotifyFunc(&stCtrlCmd, ucCmd, m_pDevNotfiyParam);
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:EN_RECV_CTRL_CMD ..................");
|
||||
}
|
||||
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:EN_RECV_CTRL_CMD end..................");
|
||||
//如果是WIFI连接的话,则需要发送回应
|
||||
if (EN_TRANSFER_FILE_BY_WIFI == g_iTransFileMode && 0 == ucCmd)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:EN_TRANSFER_FILE_BY_WIFI begin ..................");
|
||||
if (iCtrlLen != 7 || ntohs(*(WORD*)(m_chRcvCtrlBuf)) != 1)
|
||||
{
|
||||
CString strErrTxt = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strErrTxt.Format(_T("严重错误.命令长度 = %d, 设备号 = %d"), iCtrlLen, ntohs(*(WORD*)(m_chRcvCtrlBuf)));
|
||||
AfxMessageBox(strErrTxt);
|
||||
}
|
||||
else
|
||||
{
|
||||
strErrTxt.Format(_T("Serious error.ctr_data_len = %d, dev_number = %d"), iCtrlLen, ntohs(*(WORD*)(m_chRcvCtrlBuf)));
|
||||
MessageBoxEx(NULL, strErrTxt, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
STTransCtrlInfo stTransCtrl;
|
||||
stTransCtrl.ucCmd = 0;
|
||||
stTransCtrl.ucDevType = 3;
|
||||
stTransCtrl.uiDevID = *((UINT*)(m_chRcvCtrlBuf + 3));
|
||||
BYTE ucData = 3;
|
||||
CAutoLock clsAutoLock(&m_netCs);
|
||||
m_tcpClient->SendCtrlInfo((const char*)(&stTransCtrl), (char*)(&ucData), 1, 2);
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:EN_TRANSFER_FILE_BY_WIFI end ..................");
|
||||
}
|
||||
|
||||
}
|
||||
else if (EN_RECV_PLC_STATUS == iCtrlRes)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:EN_RECV_PLC_STATUS begin...............");
|
||||
CAutoLock clsAutoLock(&m_netCs);
|
||||
ProcPlcStatus(m_chRcvCtrlBuf, iCtrlLen);
|
||||
memset(m_chRcvCtrlBuf, 0, sizeof(m_chRcvCtrlBuf));
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:EN_RECV_PLC_STATUS end...............");
|
||||
continue;
|
||||
}
|
||||
else if (EN_REAL_TIME_TESTING_DATA == iCtrlRes)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:CNetWorkOper::ThreadFunction EN_REAL_TIME_TESTING_DATA begin...............");
|
||||
//if (ucCmd == EN_CTRL_MEASURE_DATA)//接收到服务端正在测量的数据
|
||||
{
|
||||
if (m_listRealHwnd.size() <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
CString str;
|
||||
list<HWND>::iterator iterCur = m_listRealHwnd.begin();
|
||||
list<HWND>::iterator iterEnd = m_listRealHwnd.end();
|
||||
str.Format(_T("zm:wnd address iterCur=%0x, *iterCur=%0x"), iterCur, *iterCur);
|
||||
CFileOperTools::GetInstance()->WriteComLog(str);
|
||||
if (iCtrlLen == 0)
|
||||
{
|
||||
iCtrlLen = MAX_RCV_CTRLBUF;
|
||||
}
|
||||
for (; iterCur != iterEnd; ++iterCur)
|
||||
{
|
||||
if (IsWindowVisible(*iterCur))
|
||||
{
|
||||
::SendMessage(*iterCur, WM_NET_RECV_REAL_TIME_DATA, (WPARAM)m_chRcvCtrlBuf, iCtrlLen);
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:CNetWorkOper::ThreadFunction EN_REAL_TIME_TESTING_DATA end...............");
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (EN_RECV_SUCCESS == iCtrlRes)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:CNetWorkOper::ThreadFunction EN_RECV_SUCCESS == iCtrlRes...............");
|
||||
memset(m_chRcvCtrlBuf, 0, sizeof(m_chRcvCtrlBuf));
|
||||
}
|
||||
else if (EN_RECV_NOTIFY_DEVICE_ONLINE == iCtrlRes)
|
||||
{
|
||||
if (NULL == m_chRcvCtrlBuf)
|
||||
continue;
|
||||
|
||||
//数量(2bytes),1类型(1byte),1sn(4byte),2类型,2sn
|
||||
u_short* pDevNum = NULL;
|
||||
pDevNum = (u_short*)(&m_chRcvCtrlBuf);
|
||||
u_short usDevNum = ntohs(*pDevNum);
|
||||
UINT32* uiDevID = NULL;
|
||||
BYTE* pByDevType = NULL;
|
||||
BYTE devType = 0;
|
||||
CString strDevSN,strLog;
|
||||
for (int i = 0; i < usDevNum; i++)
|
||||
{
|
||||
pByDevType = (BYTE*)(&m_chRcvCtrlBuf[sizeof(short)]);
|
||||
devType = *pByDevType;
|
||||
switch (devType)
|
||||
{
|
||||
case EN_DEV_GD10:
|
||||
{
|
||||
uiDevID = (UINT32*)(&m_chRcvCtrlBuf[sizeof(short) + (i + 1)*sizeof(BYTE) + i*sizeof(UINT)]);
|
||||
strDevSN.Format(_T("SN%d"), ntohl(*uiDevID));
|
||||
strLog.Format(_T("zm:设备列表添加设备GD CNetWorkOper::ThreadFunction 接收到设备上线:%s"), strDevSN);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
STSigRemoteDev stRemoteDev;
|
||||
stRemoteDev.ucDevType = EN_DEV_GD10;
|
||||
stRemoteDev.uiDevID = ntohl(*uiDevID);
|
||||
//开机
|
||||
theApp.m_pDevManager->AddRemoteDevice(stRemoteDev);
|
||||
theApp.m_pDevManager->DeleteObjInMem(strDevSN);
|
||||
}
|
||||
break;
|
||||
case EN_DEV_PLC:
|
||||
{
|
||||
uiDevID = (UINT32*)(&m_chRcvCtrlBuf[sizeof(short) + (i + 1)*sizeof(BYTE) + i*sizeof(UINT)]);
|
||||
strDevSN.Format(_T("PLC%d"), ntohl(*uiDevID));
|
||||
strLog.Format(_T("zm:设备列表添加设备PLC CNetWorkOper::ThreadFunction 接收到设备上线:%s"), strDevSN);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
STSigRemoteDev stRemoteDev;
|
||||
stRemoteDev.ucDevType = EN_DEV_PLC;
|
||||
stRemoteDev.uiDevID = ntohl(*uiDevID);
|
||||
//开机
|
||||
theApp.m_pDevManager->AddRemoteDevice(stRemoteDev);
|
||||
theApp.m_pDevManager->DeleteObjInMem(strDevSN);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*CString strLog;
|
||||
UINT32* uiDevID = NULL;
|
||||
CString strDevSN;
|
||||
uiDevID = (UINT32*)(&m_chRcvCtrlBuf[3]);
|
||||
strDevSN.Format(_T("SN%d"), ntohl(*uiDevID));
|
||||
strLog.Format(_T("zm:设备列表添加设备CNetWorkOper::ThreadFunction 接收到设备上线:%s"), strDevSN);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
STSigRemoteDev stRemoteDev;
|
||||
stRemoteDev.ucDevType = EN_DEV_GD10;
|
||||
stRemoteDev.uiDevID = ntohl(*uiDevID);
|
||||
//开机
|
||||
theApp.m_pDevManager->AddRemoteDevice(stRemoteDev);
|
||||
theApp.m_pDevManager->DeleteObjInMem(strDevSN);*/
|
||||
CMainFrame* pMainFrm = (CMainFrame*)AfxGetApp()->GetMainWnd();
|
||||
if (NULL != pMainFrm)
|
||||
{
|
||||
pMainFrm->SendMessage(WM_MSG_NOTIFY_DEVICE_ON_OR_OFF, (WPARAM)0, (LPARAM)0);
|
||||
}
|
||||
}
|
||||
else if (EN_RECV_NOTIFY_DEVICE_OFFLINE == iCtrlRes)
|
||||
{
|
||||
if (NULL == m_chRcvCtrlBuf)
|
||||
continue;
|
||||
|
||||
CString strLog;
|
||||
UINT32* uiDevID = NULL;
|
||||
CString strDevSN;
|
||||
uiDevID = (UINT32*)(&m_chRcvCtrlBuf);
|
||||
strDevSN.Format(_T("SN%d"), ntohl(*uiDevID));
|
||||
strLog.Format(_T("zm:设备列表移除设备CNetWorkOper::ThreadFunction 接收到设备离线:%s"), strDevSN);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
|
||||
STSigRemoteDev stRemoteDev;
|
||||
stRemoteDev.ucDevType = EN_DEV_GD10;
|
||||
stRemoteDev.uiDevID = ntohl(*uiDevID);
|
||||
//关机
|
||||
theApp.m_pDevManager->DeleteRemoteDevice(stRemoteDev);
|
||||
theApp.m_pDevManager->AddOfflineObjInMem(strDevSN);
|
||||
CMainFrame* pMainFrm = (CMainFrame*)AfxGetApp()->GetMainWnd();
|
||||
if (NULL != pMainFrm)
|
||||
{
|
||||
pMainFrm->SendMessage(WM_MSG_NOTIFY_DEVICE_ON_OR_OFF, (WPARAM)0, (LPARAM)0);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_bIsNeedSend)
|
||||
{
|
||||
OutputDebugString(_T("zm:zm is enter if (m_bIsNeedSend) \n\n"));
|
||||
CString strLog;
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:m_bIsNeedSend begin..............");
|
||||
CAutoLock clsAutoLock(&m_netCs);
|
||||
STTransCtrlInfo stTransCtrl;
|
||||
stTransCtrl.ucCmd = m_ucCmd;
|
||||
stTransCtrl.ucDevType = m_stSendCtrlInfo.ucDstType;
|
||||
stTransCtrl.uiDevID = m_stSendCtrlInfo.uiDevID;
|
||||
//如果之前的接收操作失败,则在发送数据之前清空接收缓冲区
|
||||
// if (iRet!=EN_RECV_SUCCESS)
|
||||
// {
|
||||
// pNetOper->m_tcpClient->ClearRecvBuffer();
|
||||
// }
|
||||
//如果发送失败,则中断此次操作
|
||||
if (false == m_tcpClient->SendCtrlInfo((const char*)&stTransCtrl, m_stSendCtrlInfo.pData, m_stSendCtrlInfo.wDataLen))
|
||||
{
|
||||
//如果有通知的函数接口,则进行操作结果的通知
|
||||
if (m_pNotifyFunc)
|
||||
{
|
||||
strLog.Format(_T("zm:m_bIsNeedSend TransferOper cmd=%0x, DevType=%d, DevID=%u failed"), stTransCtrl.ucCmd, stTransCtrl.ucDevType, stTransCtrl.uiDevID);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
m_pNotifyFunc(EN_NETWORK_SEND, EM_SEND_FAILED, m_pNotifyParam);
|
||||
}
|
||||
ClearNotfiyFuncInfo();
|
||||
|
||||
ClearSendInfo();
|
||||
// pNetOper->m_tcpClient->ClearRecvBuffer();
|
||||
continue;
|
||||
}
|
||||
m_bIsNeedSend = false;
|
||||
strLog.Format(_T("zm:m_bIsNeedSend TransferOper cmd=%0x, DevType=%d, DevID=%u success"), stTransCtrl.ucCmd, stTransCtrl.ucDevType, stTransCtrl.uiDevID);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
//如果需要接受数据的话,则此刻进行数据的接收操作
|
||||
if (m_bIsNeedResp)
|
||||
{
|
||||
int iRecvLen = 0;
|
||||
|
||||
iRet = m_tcpClient->RecvRspMsg(m_stRespDataInfo.pData, m_stRespDataInfo.pRecvLen,
|
||||
m_stRespDataInfo.iMaxRcvLen, m_stRespDataInfo.iTimeout);
|
||||
while ((EN_RECV_CTRL_CMD == iRet) || (EN_RECV_PLC_STATUS == iCtrlRes))
|
||||
{
|
||||
if (EN_RECV_PLC_STATUS == iCtrlRes)
|
||||
{
|
||||
ProcPlcStatus(m_stRespDataInfo.pData, *(m_stRespDataInfo.pRecvLen));
|
||||
// memset(pNetOper->m_chRcvCtrlBuf, 0, sizeof(pNetOper->m_chRcvCtrlBuf));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EN_TRANSFER_FILE_BY_WIFI == g_iTransFileMode)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("在WiFi模式接收数据时控制命令不能被接收"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Ctrl_cmd can not be received when rece data in wifi mode"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
break;
|
||||
}
|
||||
if (m_pDevNotifyFunc)
|
||||
{
|
||||
STCtrlCmdInfo stCtrlCmd;
|
||||
stCtrlCmd.iDataLen = *(m_stRespDataInfo.pRecvLen);
|
||||
stCtrlCmd.pData = m_stRespDataInfo.pData;
|
||||
m_pDevNotifyFunc(&stCtrlCmd, m_tcpClient->GetCurrCtrlCmd(), m_pDevNotfiyParam);
|
||||
}
|
||||
}
|
||||
|
||||
iRet = m_tcpClient->RecvRspMsg(m_stRespDataInfo.pData, m_stRespDataInfo.pRecvLen,
|
||||
m_stRespDataInfo.iMaxRcvLen, m_stRespDataInfo.iTimeout);
|
||||
}
|
||||
|
||||
if (m_ucCmd == EN_CTRL_MEASURE_DATA)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("zm:debugging measure task wnd m_ucCmd == EN_CTRL_MEASURE_DATA is need transfer"));
|
||||
//调测测量窗口,可能关闭了
|
||||
if (g_bIsOnlineTransfer == FALSE)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("zm:debugging measure task wnd g_bIsOnlineTransfer == FALSE"));
|
||||
if (m_pNotifyFunc)
|
||||
{
|
||||
// if (iRet != EN_RECV_SUCCESS)
|
||||
// {
|
||||
// pNetOper->m_tcpClient->ClearRecvBuffer();
|
||||
// }
|
||||
m_pNotifyFunc(EN_NETWORK_RECV, iRet, m_pNotifyParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_pNotifyFunc)
|
||||
{
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("zm:m_ucCmd != EN_CTRL_MEASURE_DATA"));
|
||||
strLog.Format(_T("zm: m_stRespDataInfo.pData="));
|
||||
for (int i = 0; i < *m_stRespDataInfo.pRecvLen; i++)
|
||||
{
|
||||
strLog.AppendFormat(_T(" %02x"), m_stRespDataInfo.pData[i]);
|
||||
}
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
|
||||
strLog.Format(_T("zm:m_stRespDataInfo.pRecvLen=%d"), *m_stRespDataInfo.pRecvLen);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
// if (iRet != EN_RECV_SUCCESS)
|
||||
// {
|
||||
// pNetOper->m_tcpClient->ClearRecvBuffer();
|
||||
// }
|
||||
m_pNotifyFunc(EN_NETWORK_RECV, iRet, m_pNotifyParam);
|
||||
}
|
||||
}
|
||||
|
||||
CFileOperTools::GetInstance()->WriteComLog("zm:m_bIsNeedSend end..............");
|
||||
}
|
||||
ClearNotfiyFuncInfo();
|
||||
ClearSendInfo();
|
||||
}/*else if (iCtrlRes == EN_RECV_SUCCESS)
|
||||
{
|
||||
//bRet = true;
|
||||
list<HWND>::iterator iterCur = m_listRealHwnd.begin();
|
||||
list<HWND>::iterator iterEnd = m_listRealHwnd.end();
|
||||
for (; iterCur != iterEnd; ++iterCur)
|
||||
{
|
||||
::SendMessage(*iterCur, WM_NET_RECV_REAL_TIME_DATA, (WPARAM)m_chRcvCtrlBuf, iCtrlLen);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
void CNetWorkOper::SetSuspendForThread(bool bIsSuspend)
|
||||
{
|
||||
m_bIsSuspend = bIsSuspend;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// OperPLC.cpp: implementation of the COperPLC class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "OperPLC.h"
|
||||
#include "FileOperTools.h"
|
||||
#include "CtrlProtocolDef.h"
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
extern int g_iUILanguage;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
COperPLC* COperPLC::m_pOperPlc = NULL;
|
||||
COperPLC::COperPLC()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
COperPLC::~COperPLC()
|
||||
{
|
||||
|
||||
}
|
||||
COperPLC* COperPLC::GetInstance()
|
||||
{
|
||||
if (NULL == m_pOperPlc)
|
||||
{
|
||||
m_pOperPlc = new COperPLC;
|
||||
}
|
||||
return m_pOperPlc;
|
||||
}
|
||||
|
||||
int COperPLC::ParsePlcOperResInfo(char* pData, int iLen)
|
||||
{
|
||||
if (iLen != sizeof(STRemPlcDataInfo))
|
||||
{
|
||||
return EN_PLC_RES_LEN_ERR;
|
||||
}
|
||||
STRemPlcDataInfo* pPlcInfo = (STRemPlcDataInfo*)pData;
|
||||
if ( 1== pPlcInfo->ucResult)
|
||||
return EN_PLC_RES_SUCCESS;
|
||||
else
|
||||
return EN_PLC_RES_FAILED;
|
||||
}
|
||||
|
||||
void COperPLC::GetPlcCmdInfo(BYTE ucCmd, char* pData, int& iLen, int iMaxLen)
|
||||
{
|
||||
iLen = 0;
|
||||
CString str = _T("");
|
||||
if (iMaxLen < sizeof(STRemPlcDataInfo))
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
str.Format(_T("获取plc cmd长度错误.max_len=%d, should_len=%d"), iMaxLen, sizeof(STRemPlcDataInfo));
|
||||
AfxMessageBox(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
str.Format(_T("Get plc cmd length error.max_len=%d, should_len=%d"), iMaxLen, sizeof(STRemPlcDataInfo));
|
||||
MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return;
|
||||
}
|
||||
switch (ucCmd)
|
||||
{
|
||||
case EN_PLC_POWER_ON:
|
||||
GetPowerOnCmd(pData,iLen);
|
||||
break;
|
||||
case EN_PLC_POWER_OFF:
|
||||
GetPowerOffCmd(pData,iLen);
|
||||
break;
|
||||
default:
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
str.Format(_T("未知PLC命令(%d)"), ucCmd);
|
||||
AfxMessageBox(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
str.Format(_T("Unknow plc cmd(%d)"), ucCmd);
|
||||
MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void COperPLC::GetPowerOffCmd(char* pCmdData,int& iCmdLen)
|
||||
{
|
||||
STRemPlcDataInfo* pPlcDataInfo = (STRemPlcDataInfo*)pCmdData;
|
||||
iCmdLen = sizeof(STRemPlcDataInfo);
|
||||
memset(pPlcDataInfo, 0, sizeof(STRemPlcDataInfo));
|
||||
pPlcDataInfo->ucPacketIndex = 1;
|
||||
pPlcDataInfo->ucCtrlK3 = 0;
|
||||
pPlcDataInfo->ucCtrlK4 = 0;
|
||||
//1,2,5,6设置成2
|
||||
pPlcDataInfo->ucCtrlK1 = 2;
|
||||
pPlcDataInfo->ucCtrlK2 = 2;
|
||||
pPlcDataInfo->ucCtrlK5 = 2;
|
||||
pPlcDataInfo->ucCtrlK6 = 2;
|
||||
}
|
||||
|
||||
void COperPLC::GetPowerOnCmd(char* pCmdData,int& iCmdLen)
|
||||
{
|
||||
STRemPlcDataInfo* pPlcDataInfo = (STRemPlcDataInfo*)pCmdData;
|
||||
iCmdLen = sizeof(STRemPlcDataInfo);
|
||||
memset(pPlcDataInfo, 0, sizeof(STRemPlcDataInfo));
|
||||
pPlcDataInfo->ucPacketIndex = 1;
|
||||
pPlcDataInfo->ucCtrlK3 = 1;
|
||||
pPlcDataInfo->ucCtrlK4 = 1;
|
||||
//1,2,5,6设置成2
|
||||
pPlcDataInfo->ucCtrlK1 = 2;
|
||||
pPlcDataInfo->ucCtrlK2 = 2;
|
||||
pPlcDataInfo->ucCtrlK5 = 2;
|
||||
pPlcDataInfo->ucCtrlK6 = 2;
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
// OperTxtFile.cpp: implementation of the COperTxtFile class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "OperTxtFile.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
extern int g_iUILanguage;
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
COperTxtFile::COperTxtFile()
|
||||
{
|
||||
m_uiParamWidth = 18;
|
||||
m_pFile = NULL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
COperTxtFile::~COperTxtFile()
|
||||
{
|
||||
if (m_pFile)
|
||||
{
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void COperTxtFile::SetParamWidth(UINT uiWidth)
|
||||
{
|
||||
if (uiWidth < 6 || uiWidth >50)
|
||||
{
|
||||
CString str = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
str.Format(_T("设置参数宽度错误!值为%d"), uiWidth);
|
||||
AfxMessageBox(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
str.Format(_T("Set Parameter Width error!value = %d"), uiWidth);
|
||||
MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return;
|
||||
}
|
||||
m_uiParamWidth = uiWidth;
|
||||
}
|
||||
|
||||
void COperTxtFile::CloseFile()
|
||||
{
|
||||
if (m_pFile)
|
||||
{
|
||||
fclose(m_pFile);
|
||||
m_pFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool COperTxtFile::OpenFileforWrite(CString strFileName)
|
||||
{
|
||||
if (strFileName.IsEmpty())
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("文件名不能为空"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("File's name can not be empty!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
if (m_pFile)
|
||||
{
|
||||
CloseFile();
|
||||
}
|
||||
m_pFile = fopen(strFileName, "w+");
|
||||
if (NULL == m_pFile)
|
||||
{
|
||||
CString strShow = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strShow.Format(_T("打开文件 %s 失败!错误码 = %d"), strFileName, GetLastError());
|
||||
AfxMessageBox(strShow);
|
||||
}
|
||||
else
|
||||
{
|
||||
strShow.Format(_T("Open file %s failed!ErrorCode = %d"), strFileName, GetLastError());
|
||||
MessageBoxEx(NULL, strShow, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CFileOperTools::GetInstance()->WriteComLog(_T("zm: COperTxtFile::OpenFileforWrite export file : -------------------") + strFileName);
|
||||
return true;
|
||||
|
||||
}
|
||||
//按照m_uiParamWidth来写TXT文件,不足的部分以空格来填充
|
||||
bool COperTxtFile::WriteFileContent(const CStringArray& strArrContent)
|
||||
{
|
||||
CString strText = _T("");
|
||||
for (int i = 0; i < strArrContent.GetSize(); i++)
|
||||
{
|
||||
int nLen = strArrContent[i].GetLength();
|
||||
if (nLen > m_uiParamWidth)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
strText.Format(_T("内容长度(%s)(%d)超过参数宽度(%d)!"), strArrContent[i], nLen, m_uiParamWidth);
|
||||
AfxMessageBox(strText);
|
||||
}
|
||||
else
|
||||
{
|
||||
strText.Format(_T("The length of content(%s)(%d) is over than parameter width(%d)!"), strArrContent[i], nLen, m_uiParamWidth);
|
||||
MessageBoxEx(NULL, strText, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
|
||||
//return false;
|
||||
}
|
||||
strText.Empty();
|
||||
strText = strArrContent[i];
|
||||
for (int j = 0; j < (m_uiParamWidth - nLen); j++)
|
||||
{
|
||||
strText += _T(" ");
|
||||
}
|
||||
//在最后一个元素前面加上换行符
|
||||
if (i == strArrContent.GetSize()-1)
|
||||
{
|
||||
strText += _T("\r\n");
|
||||
}
|
||||
nLen = fwrite(strText, 1, strText.GetLength(), m_pFile);
|
||||
if (nLen != strText.GetLength())
|
||||
{
|
||||
CString str = _T("");
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
{
|
||||
str.Format(_T("写文件错误!应该写长度= %d,写长度=%d, error_code=%d"),
|
||||
strText.GetLength(), nLen, GetLastError());
|
||||
AfxMessageBox(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
str.Format(_T("Write file error!should write length = %d, writed length = %d, error_code = %d"),
|
||||
strText.GetLength(), nLen, GetLastError());
|
||||
MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fflush(m_pFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COperTxtFile::WriteEmptyRow()
|
||||
{
|
||||
CString strText = _T("\r\n");
|
||||
fwrite(strText, 1, strText.GetLength(), m_pFile);
|
||||
fflush(m_pFile);
|
||||
return true;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,386 @@
|
||||
// Res3DDatFile.cpp: implementation of the CRes3DDatFile class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "Res3DDatFile.h"
|
||||
|
||||
#include "Res3DDatFileRecord.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CRes3DDatFile::CRes3DDatFile()
|
||||
{
|
||||
m_szTitle.Empty();
|
||||
m_iRowCount = (int)VAL_ZERO;
|
||||
m_iColCount = (int)VAL_ZERO;
|
||||
m_fRowSpacing = (float)VAL_ZERO;
|
||||
m_fColSpacing = (float)VAL_ZERO;
|
||||
m_iMedium = (int)VAL_ZERO;
|
||||
m_iPtCount = (int)VAL_ZERO;
|
||||
|
||||
this->m_paRecordArray.RemoveAll();
|
||||
}
|
||||
|
||||
CRes3DDatFile::~CRes3DDatFile()
|
||||
{
|
||||
ClearAllRecord();
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::SetTitle(CString szTitle)
|
||||
{
|
||||
if (szTitle.IsEmpty() == TRUE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
this->m_szTitle = szTitle;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::SetGriding(int iRowCount, int iColCount)
|
||||
{
|
||||
if ((iRowCount <= 0) || (iColCount <= 0))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
this->m_iRowCount = iRowCount;
|
||||
this->m_iColCount = iColCount;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::SetSpacing(float fRowSpacing, float fColSpacing)
|
||||
{
|
||||
if ((fRowSpacing <= 0) || (fColSpacing <= 0))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
this->m_fRowSpacing = fRowSpacing;
|
||||
this->m_fColSpacing = fColSpacing;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::SetMedium(int iMedium)
|
||||
{
|
||||
m_iMedium = (int)VAL_ZERO;
|
||||
switch (iMedium)
|
||||
{
|
||||
case 1:
|
||||
this->m_iMedium = 1;
|
||||
break;
|
||||
case 2:
|
||||
this->m_iMedium = 4;
|
||||
break;
|
||||
case 3:
|
||||
this->m_iMedium = 5;
|
||||
break;
|
||||
case 11:
|
||||
this->m_iMedium = 7;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::AddRecord(int iCableNum, int iA, int iB, int iM, int iN, float fR0)
|
||||
{
|
||||
CRes3DDatFileRecord* pRes3DDatFileRecord = NULL;
|
||||
|
||||
if ((iCableNum < 1) || ((iA < 1) && (iB < 1) && (iM < 1) && (iN < 1)) || (fR0 < 0) || m_fRowSpacing <= 0.0 || m_fColSpacing <= 0.0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pRes3DDatFileRecord = new CRes3DDatFileRecord;
|
||||
if (pRes3DDatFileRecord != NULL)
|
||||
{
|
||||
if (iA > (int)VAL_ZERO)
|
||||
{
|
||||
pRes3DDatFileRecord->m_fAX = (float)((iCableNum - 1) * m_fRowSpacing);
|
||||
pRes3DDatFileRecord->m_fAY = (float)((iA - 1) * m_fColSpacing);
|
||||
}
|
||||
else
|
||||
{
|
||||
pRes3DDatFileRecord->m_fAX = (float)VAL_MINUS_ONE;
|
||||
pRes3DDatFileRecord->m_fAY = (float)VAL_MINUS_ONE;
|
||||
}
|
||||
|
||||
if (iB > (int)VAL_ZERO)
|
||||
{
|
||||
pRes3DDatFileRecord->m_fBX = (float)((iCableNum - 1) * m_fRowSpacing);
|
||||
pRes3DDatFileRecord->m_fBY = (float)((iB - 1) * m_fColSpacing);
|
||||
}
|
||||
else
|
||||
{
|
||||
pRes3DDatFileRecord->m_fBX = (float)VAL_MINUS_ONE;
|
||||
pRes3DDatFileRecord->m_fBY = (float)VAL_MINUS_ONE;
|
||||
}
|
||||
|
||||
if (iM > (int)VAL_ZERO)
|
||||
{
|
||||
pRes3DDatFileRecord->m_fMX = (float)((iCableNum - 1) * m_fRowSpacing);
|
||||
pRes3DDatFileRecord->m_fMY = (float)((iM - 1) * m_fColSpacing);
|
||||
}
|
||||
else
|
||||
{
|
||||
pRes3DDatFileRecord->m_fMX = (float)VAL_MINUS_ONE;
|
||||
pRes3DDatFileRecord->m_fMY = (float)VAL_MINUS_ONE;
|
||||
}
|
||||
|
||||
if (iN > (int)VAL_ZERO)
|
||||
{
|
||||
pRes3DDatFileRecord->m_fNX = (float)((iCableNum - 1) * m_fRowSpacing);
|
||||
pRes3DDatFileRecord->m_fNY = (float)((iN - 1) * m_fColSpacing);
|
||||
}
|
||||
else
|
||||
{
|
||||
pRes3DDatFileRecord->m_fNX = (float)VAL_MINUS_ONE;
|
||||
pRes3DDatFileRecord->m_fNY = (float)VAL_MINUS_ONE;
|
||||
}
|
||||
|
||||
pRes3DDatFileRecord->m_fR0 = fR0;
|
||||
|
||||
this->m_paRecordArray.Add((void*)pRes3DDatFileRecord);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::Generate(CString szFile)
|
||||
{
|
||||
HANDLE hFile = NULL;
|
||||
|
||||
if (szFile.IsEmpty() == TRUE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DeleteFile(szFile);
|
||||
|
||||
hFile = CreateFile(szFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
this->WriteHead(hFile);
|
||||
this->WriteRecord(hFile);
|
||||
this->WriteTail(hFile);
|
||||
|
||||
CloseHandle(hFile);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::WriteHead(HANDLE hFile)
|
||||
{
|
||||
DWORD dwWrites = (DWORD)VAL_ZERO;
|
||||
CString szContent = _T("");
|
||||
|
||||
if (NULL == hFile)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dwWrites = (DWORD)VAL_ZERO;
|
||||
szContent.Empty();
|
||||
szContent.Format(_T("%s\r\n"), this->m_szTitle);
|
||||
if (FALSE == WriteFile(hFile, szContent, szContent.GetLength(), &dwWrites, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dwWrites = (DWORD)VAL_ZERO;
|
||||
szContent.Empty();
|
||||
szContent.Format(_T("%d\r\n"), this->m_iColCount);
|
||||
if (FALSE == WriteFile(hFile, szContent, szContent.GetLength(), &dwWrites, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dwWrites = (DWORD)VAL_ZERO;
|
||||
szContent.Empty();
|
||||
szContent.Format(_T("%d\r\n"), this->m_iRowCount);
|
||||
if (FALSE == WriteFile(hFile, szContent, szContent.GetLength(), &dwWrites, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dwWrites = (DWORD)VAL_ZERO;
|
||||
szContent.Empty();
|
||||
szContent.Format(_T("%7.2f\r\n"), this->m_fColSpacing);
|
||||
if (FALSE == WriteFile(hFile, szContent, szContent.GetLength(), &dwWrites, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dwWrites = (DWORD)VAL_ZERO;
|
||||
szContent.Empty();
|
||||
szContent.Format(_T("%7.2f\r\n"), this->m_fRowSpacing);
|
||||
if (FALSE == WriteFile(hFile, szContent, szContent.GetLength(), &dwWrites, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dwWrites = (DWORD)VAL_ZERO;
|
||||
szContent.Empty();
|
||||
szContent.Format(_T("%d\r\n"), this->m_iMedium);
|
||||
if (FALSE == WriteFile(hFile, szContent, szContent.GetLength(), &dwWrites, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
dwWrites = (DWORD)VAL_ZERO;
|
||||
this->m_iPtCount = this->m_paRecordArray.GetSize();
|
||||
szContent.Empty();
|
||||
szContent.Format(_T("%d\r\n"), this->m_iPtCount);
|
||||
if (FALSE == WriteFile(hFile, szContent, szContent.GetLength(), &dwWrites, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::WriteRecord(HANDLE hFile)
|
||||
{
|
||||
CString szCoordinate = _T("");
|
||||
CString szR0 = _T("");
|
||||
CString szRecord = _T("");
|
||||
|
||||
DWORD dwWrites = (DWORD)VAL_ZERO;
|
||||
|
||||
CRes3DDatFileRecord* pRes3DDatFileRecord = NULL;
|
||||
int iIndex = (int)VAL_ZERO;
|
||||
|
||||
if (NULL == hFile)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
iIndex = (int)VAL_ZERO;
|
||||
while (iIndex <= this->m_paRecordArray.GetUpperBound())
|
||||
{
|
||||
szRecord.Empty();
|
||||
pRes3DDatFileRecord = (CRes3DDatFileRecord*)this->m_paRecordArray.GetAt(iIndex);
|
||||
|
||||
if ((pRes3DDatFileRecord->m_fAX != (float)VAL_MINUS_ONE) && (pRes3DDatFileRecord->m_fAY != (float)VAL_MINUS_ONE))
|
||||
{
|
||||
szCoordinate.Empty();
|
||||
szCoordinate.Format(_T("%9.3f%9.3f"), pRes3DDatFileRecord->m_fAY, pRes3DDatFileRecord->m_fAX);
|
||||
szRecord = szRecord + szCoordinate;
|
||||
}
|
||||
|
||||
if ((pRes3DDatFileRecord->m_fBX != (float)VAL_MINUS_ONE) && (pRes3DDatFileRecord->m_fBY != (float)VAL_MINUS_ONE))
|
||||
{
|
||||
szCoordinate.Empty();
|
||||
szCoordinate.Format(_T("%9.3f%9.3f"), pRes3DDatFileRecord->m_fBY, pRes3DDatFileRecord->m_fBX);
|
||||
szRecord = szRecord + szCoordinate;
|
||||
}
|
||||
|
||||
if ((pRes3DDatFileRecord->m_fMX != (float)VAL_MINUS_ONE) && (pRes3DDatFileRecord->m_fMY != (float)VAL_MINUS_ONE))
|
||||
{
|
||||
szCoordinate.Empty();
|
||||
szCoordinate.Format(_T("%9.3f%9.3f"), pRes3DDatFileRecord->m_fMY, pRes3DDatFileRecord->m_fMX);
|
||||
szRecord = szRecord + szCoordinate;
|
||||
}
|
||||
|
||||
if ((pRes3DDatFileRecord->m_fNX != (float)VAL_MINUS_ONE) && (pRes3DDatFileRecord->m_fNY != (float)VAL_MINUS_ONE))
|
||||
{
|
||||
szCoordinate.Empty();
|
||||
szCoordinate.Format(_T("%9.3f%9.3f"), pRes3DDatFileRecord->m_fNY, pRes3DDatFileRecord->m_fNX);
|
||||
szRecord = szRecord + szCoordinate;
|
||||
}
|
||||
|
||||
szR0.Empty();
|
||||
szR0.Format(_T("%9.4f"), pRes3DDatFileRecord->m_fR0);
|
||||
|
||||
szRecord = szRecord + szR0 + _T("\r\n");
|
||||
dwWrites = (DWORD)VAL_ZERO;
|
||||
if (FALSE == WriteFile(hFile, szRecord, szRecord.GetLength(), &dwWrites, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
iIndex ++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::WriteTail(HANDLE hFile)
|
||||
{
|
||||
int iZeroNum = (int)VAL_ZERO;
|
||||
|
||||
DWORD dwWrites = (DWORD)VAL_ZERO;
|
||||
CString szContent = _T("");
|
||||
|
||||
if (NULL == hFile)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
while (iZeroNum < 5)
|
||||
{
|
||||
dwWrites = (DWORD)VAL_ZERO;
|
||||
szContent.Empty();
|
||||
szContent.Format(_T("%d\r\n"), (int)VAL_ZERO);
|
||||
if (FALSE == WriteFile(hFile, szContent, szContent.GetLength(), &dwWrites, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
iZeroNum ++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::ClearAllRecord()
|
||||
{
|
||||
int iIndex = (int)VAL_ZERO;
|
||||
|
||||
if (this->m_paRecordArray.GetSize() == 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
iIndex = (int)VAL_ZERO;
|
||||
while (iIndex < m_paRecordArray.GetSize())
|
||||
{
|
||||
DelRecord(iIndex);
|
||||
iIndex ++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CRes3DDatFile::DelRecord(int iIndex)
|
||||
{
|
||||
CRes3DDatFileRecord* pRes3DDatFileRecord = NULL;
|
||||
pRes3DDatFileRecord = (CRes3DDatFileRecord*)this->m_paRecordArray.GetAt(iIndex);
|
||||
|
||||
if ((pRes3DDatFileRecord == NULL) || (iIndex < 0))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
delete pRes3DDatFileRecord;
|
||||
this->m_paRecordArray.RemoveAt(iIndex);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Res3DDatFileRecord.cpp: implementation of the CRes3DDatFileRecord class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "Res3DDatFileRecord.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CRes3DDatFileRecord::CRes3DDatFileRecord()
|
||||
{
|
||||
m_fAX = 0.0;
|
||||
m_fAY = 0.0;
|
||||
|
||||
m_fBX = 0.0;
|
||||
m_fBY = 0.0;
|
||||
|
||||
m_fMX = 0.0;
|
||||
m_fMY = 0.0;
|
||||
|
||||
m_fNX = 0.0;
|
||||
m_fNY = 0.0;
|
||||
|
||||
m_fR0 = 0.0;
|
||||
}
|
||||
|
||||
CRes3DDatFileRecord::~CRes3DDatFileRecord()
|
||||
{
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
// StateProcessor.cpp: implementation of the CStateProcessor class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "geomative.h"
|
||||
#include "StateProcessor.h"
|
||||
#include "Constant.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CStateProcessor::CStateProcessor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CStateProcessor::~CStateProcessor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UINT CStateProcessor::ChangeToImageState(UINT uItemState)
|
||||
{
|
||||
return INDEXTOSTATEIMAGEMASK(uItemState);
|
||||
}
|
||||
|
||||
UINT CStateProcessor::ChangeToItemState(UINT uImageState)
|
||||
{
|
||||
UINT uItemState = 0;
|
||||
uItemState = uImageState;
|
||||
uItemState >>= STATE_OFFSET;
|
||||
return uItemState;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// GeoMative.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,449 @@
|
||||
// TcpClient.cpp: implementation of the CTcpClient class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "GeoMative.h"
|
||||
#include "TcpClient.h"
|
||||
#include "FileOperTools.h"
|
||||
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
#define MODULE_NAME "TcpClient"
|
||||
#define SHUT_RDWR 2
|
||||
#define MAX_SKIP_BYTE 60
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CTcpClient::CTcpClient()
|
||||
{
|
||||
m_strIP = _T("");
|
||||
m_wPort = 0;
|
||||
m_sockClient = INVALID_SOCKET;
|
||||
m_iRcvBuf = m_iSndBuf = 64*1024;
|
||||
m_bIsConnect = false;
|
||||
m_pClearRcvBuf = NULL;
|
||||
|
||||
}
|
||||
|
||||
CTcpClient::~CTcpClient()
|
||||
{
|
||||
closesocket(m_sockClient);
|
||||
if (m_pClearRcvBuf)
|
||||
{
|
||||
delete []m_pClearRcvBuf;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//默认为套接字的属性为阻塞的
|
||||
bool CTcpClient::InitailTcp()
|
||||
{
|
||||
if (INVALID_SOCKET != m_sockClient)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("需要初始化的套接字不为空"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("The socket that needs to be initialized is not empty"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
m_sockClient = socket(AF_INET, SOCK_STREAM, 0);
|
||||
CString strLog = _T("");
|
||||
if (INVALID_SOCKET == m_sockClient)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("创建套接字失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Create socket failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
//这里不需要优雅关闭,最多进行重传
|
||||
struct linger stLinger;
|
||||
stLinger.l_onoff = 0;
|
||||
stLinger.l_linger = 0;
|
||||
if (SOCKET_ERROR == setsockopt(m_sockClient, SOL_SOCKET, SO_LINGER, (const char*)&stLinger, sizeof(stLinger)))
|
||||
{
|
||||
strLog.Format(_T("[%s][%d]set socketopt(SO_LINGER) failed. error_no = %d"), MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return false;
|
||||
}
|
||||
|
||||
//设置套接字缓冲区
|
||||
if ((SOCKET_ERROR == setsockopt(m_sockClient, SOL_SOCKET, SO_RCVBUF, (const char*)&m_iRcvBuf, sizeof(int))) ||
|
||||
(SOCKET_ERROR == setsockopt(m_sockClient, SOL_SOCKET, SO_SNDBUF, (const char*)&m_iSndBuf, sizeof(int))) )
|
||||
{
|
||||
strLog.Format(_T("[%s][%d]set socketopt(SOCKET_BUF) failed. error_no = %d"), MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
BOOL bKeepAlive = TRUE;
|
||||
if (SOCKET_ERROR == setsockopt(m_sockClient, SOL_SOCKET, SO_KEEPALIVE, (const char*)&bKeepAlive, sizeof(BOOL)))
|
||||
{
|
||||
strLog.Empty();
|
||||
strLog.Format(_T("[%s][%d]Set keep alive failed.error = %d"), MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool CTcpClient::ConnectServer(CString strAddr, WORD wPort)
|
||||
{
|
||||
CString strLog;
|
||||
if (INVALID_SOCKET == m_sockClient)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("请初始化套接字"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Please initial socket."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
strLog.Format(_T("[%s][%d] INVALID_SOCKET == m_sockClient"), MODULE_NAME, __LINE__);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return false;
|
||||
}
|
||||
struct sockaddr_in socket_DstAddr;
|
||||
socket_DstAddr.sin_family = AF_INET;
|
||||
socket_DstAddr.sin_port = htons(wPort);
|
||||
socket_DstAddr.sin_addr.S_un.S_addr = inet_addr(strAddr.GetBuffer(0));
|
||||
if (SOCKET_ERROR == connect(m_sockClient, (struct sockaddr*)&socket_DstAddr, sizeof(sockaddr)))
|
||||
{
|
||||
strLog.Format(_T("[%s][%d]connect to %s:%d error = %d failed. m_sockClient=%d"), MODULE_NAME, __LINE__, strAddr, wPort, WSAGetLastError(), m_sockClient);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return false;
|
||||
}
|
||||
|
||||
strLog.Format(_T("[%s][%d]connect to %s:%d success. m_sockClient=%d"), MODULE_NAME, __LINE__, strAddr, wPort, m_sockClient);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
InitialClient();
|
||||
m_bIsConnect = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTcpClient::ConnectToServer(CString strIP, WORD wPort)
|
||||
{
|
||||
CString strLog;
|
||||
if (ConnectServer(strIP,wPort))
|
||||
{
|
||||
m_strIP = strIP;
|
||||
m_wPort = wPort;
|
||||
strLog.Format(_T("zm:CTcpClient::ConnectToServer success m_strIP=%s , Port=%d"), strIP, wPort);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return true;
|
||||
}
|
||||
strLog.Format(_T("zm:CTcpClient::ConnectToServer failed m_strIP=%s , Port=%d"), strIP, wPort);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int CTcpClient::SendData(const char*pData, int wLen)
|
||||
{
|
||||
CString strErr = _T("");
|
||||
if (!GetConnectStatus())
|
||||
{
|
||||
strErr.Format(_T("[%s][%d]link has been interrupt before send data error"), MODULE_NAME, __LINE__);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return -1;
|
||||
}
|
||||
int iLen = send(m_sockClient, pData, wLen, 0);
|
||||
if (SOCKET_ERROR == iLen)
|
||||
{
|
||||
strErr.Format(_T("[%s][%d]send data error, error = %d"), MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CString strLog,strContent;
|
||||
strLog.Format(_T("[%s][%d]CTcpClient::SendData size=%d\n send data:"), MODULE_NAME, __LINE__, iLen);
|
||||
//打印接收数据流
|
||||
unsigned char *pszTempData = (unsigned char*)pData;
|
||||
for (int i = 0; i < iLen; i++)
|
||||
{
|
||||
strContent.AppendFormat("%02x ", pszTempData[i]);
|
||||
}
|
||||
strLog.AppendFormat(_T("%s\n"), strContent);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return iLen;
|
||||
}
|
||||
|
||||
bool CTcpClient::CloseConnect()
|
||||
{
|
||||
CString strLog;
|
||||
strLog.Format(_T("[%s][%d]zm: closesocket m_sockClient=%d"), MODULE_NAME, __LINE__, m_sockClient);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
if (INVALID_SOCKET == m_sockClient)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (SOCKET_ERROR == closesocket(m_sockClient))
|
||||
{
|
||||
strLog.Format(_T("[%s][%d]zm: closesocket error, errorno = %d"), MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
m_sockClient = INVALID_SOCKET;
|
||||
return false;
|
||||
}
|
||||
m_bIsConnect = false;
|
||||
strLog.Format(_T("[%s][%d]zm: closesocket success end"), MODULE_NAME, __LINE__);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
m_sockClient = INVALID_SOCKET;
|
||||
return true;
|
||||
}
|
||||
bool CTcpClient::GetConnectStatus()
|
||||
{
|
||||
CString strLog;
|
||||
if (!m_bIsConnect || (INVALID_SOCKET == m_sockClient))
|
||||
{
|
||||
strLog.Format(_T("[%s][%d]zm:CTcpClient::GetConnectStatus:m_bIsConnect=%d,m_sockClient=%d"), MODULE_NAME, __LINE__, m_bIsConnect, m_sockClient);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return false;
|
||||
}
|
||||
FD_SET fdReadSet;
|
||||
FD_ZERO(&fdReadSet);
|
||||
FD_SET(m_sockClient, &fdReadSet);
|
||||
struct timeval stTimeVal;
|
||||
stTimeVal.tv_sec = 0;
|
||||
stTimeVal.tv_usec = 0;
|
||||
int iRet = select(m_sockClient+1, &fdReadSet, NULL, NULL, &stTimeVal);
|
||||
CString strErr;
|
||||
char msg[1] = {0};
|
||||
if (SOCKET_ERROR == iRet)
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d] zm:CTcpClient::GetConnectStatus() select error in CheckLinkStatus, errorno = %d"), MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
m_bIsConnect = false;
|
||||
}
|
||||
if (iRet > 0)
|
||||
{
|
||||
int iRecvLen = recv(m_sockClient, msg, sizeof(msg), MSG_PEEK);
|
||||
if (iRecvLen <= 0)
|
||||
{
|
||||
//如果此时<=0,则表示收到了FIN包或者连接出了问题
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]zm:CTcpClient::GetConnectStatus() LinkStatus has been interrupt"), MODULE_NAME, __LINE__);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
m_bIsConnect = false;
|
||||
}
|
||||
CString strLog,strContent;
|
||||
//打印接收数据流
|
||||
unsigned char *pszTempData = (unsigned char*)msg;
|
||||
for (int i = 0; i < iRecvLen; i++)
|
||||
{
|
||||
strContent.AppendFormat(" %02x", pszTempData[i]);
|
||||
}
|
||||
strLog.Format(_T("[%s][%d]CTcpClient::GetConnectStatus() recv data size=%d\n recv data:%s\n"), MODULE_NAME, __LINE__, iRecvLen, strContent);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
strContent.Empty();
|
||||
}
|
||||
|
||||
return m_bIsConnect;
|
||||
}
|
||||
|
||||
bool CTcpClient::ReConnect()
|
||||
{
|
||||
// Disconnect();
|
||||
//在这里必须释放上一个socket资源,并重新申请新的socket才能重新连接上
|
||||
//如果只是关闭连接,再重新连接,则无法成功,不知道为啥
|
||||
CString strLog;
|
||||
strLog.Format(_T("zm:CTcpClient::ReConnect() begin"));
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
CloseConnect();
|
||||
if (InitailTcp())
|
||||
{
|
||||
strLog.Format(_T("zm:CTcpClient::ReConnect() "));
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return ConnectToServer(m_strIP, m_wPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("套接字初始化失败"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("Socket initialization failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
}
|
||||
|
||||
strLog.Format(_T("zm:CTcpClient::ReConnect() end"));
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool CTcpClient::RecvData(char*pData, int iLen,int &iActualLen)
|
||||
{
|
||||
CString strErr = _T("");
|
||||
// if (!GetConnectStatus())
|
||||
// {
|
||||
// strErr.Format(_T("[%s][%d]link has been interrupt before recv data error"), MODULE_NAME, __LINE__);
|
||||
// CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
// return false;
|
||||
// }
|
||||
if (!m_bIsConnect)
|
||||
{
|
||||
strErr.Format(_T("[%s][%d]zm:CTcpClient::RecvData() link has been interrupt before recv data error=%d"), MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return false;
|
||||
}
|
||||
FD_SET fdReadSet;
|
||||
FD_ZERO(&fdReadSet);
|
||||
FD_SET(m_sockClient, &fdReadSet);
|
||||
struct timeval stTimeVal;
|
||||
stTimeVal.tv_sec = 0;
|
||||
stTimeVal.tv_usec = 25000;
|
||||
int iRet = select(m_sockClient+1, &fdReadSet, NULL, NULL, &stTimeVal);
|
||||
if (SOCKET_ERROR == iRet)
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]select error in RecvData, errorno = %d"), MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return false;
|
||||
}
|
||||
else if (0 == iRet)
|
||||
{
|
||||
iActualLen = 0;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FD_ISSET(m_sockClient, &fdReadSet)>0)
|
||||
{
|
||||
int iRecvLen = recv(m_sockClient, pData, iLen, 0);
|
||||
if (iRecvLen <= 0)
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]link interrupt in RecvData, errorno = %d"), MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
m_bIsConnect = false;
|
||||
return false;
|
||||
}
|
||||
iActualLen = iRecvLen;
|
||||
|
||||
CString strLog,strContent;
|
||||
strLog.Format(_T("[%s][%d]CTcpClient::RecvData recv size=%d\n recv data:"), MODULE_NAME, __LINE__, iRecvLen);
|
||||
//CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
//打印接收数据流
|
||||
unsigned char *pszTempData = (unsigned char*)pData;
|
||||
for (int i = 0; i < iRecvLen; i++)
|
||||
{
|
||||
strContent.AppendFormat("%02x ", pszTempData[i]);
|
||||
}
|
||||
strLog.AppendFormat(_T("%s\n"),strContent);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]FD_ISSET is not detect read signal when select found read signal,errorno = %d"),MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool CTcpClient::Disconnect()
|
||||
{
|
||||
if (m_sockClient == INVALID_SOCKET )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
m_bIsConnect = false;
|
||||
CString strLog;
|
||||
strLog.Format(_T("zm:CTcpClient::Disconnect() m_bIsConnect = false"));
|
||||
CFileOperTools::GetInstance()->WriteComLog(strLog);
|
||||
shutdown(m_sockClient, SHUT_RDWR);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool CTcpClient::ClearRecvBuffer()
|
||||
{
|
||||
if (INVALID_SOCKET == m_sockClient)
|
||||
{
|
||||
if (LANG_ZHCN == g_iUILanguage)
|
||||
AfxMessageBox(_T("套接字在ClearRecvBuffer中无效"));
|
||||
else
|
||||
MessageBoxEx(NULL, _T("The socket is invalid in ClearRecvBuffer."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
||||
return false;
|
||||
}
|
||||
//如果处于断练状态,则不需要进行操作
|
||||
if (!m_bIsConnect)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (NULL == m_pClearRcvBuf)
|
||||
{
|
||||
m_pClearRcvBuf = new char[m_iRcvBuf];
|
||||
}
|
||||
CString strErr = _T("");
|
||||
struct timeval stTimeVal;
|
||||
stTimeVal.tv_sec = 0;
|
||||
stTimeVal.tv_usec = 1000;
|
||||
bool bRes = true;
|
||||
fd_set fdsRead;
|
||||
|
||||
FD_ZERO(&fdsRead);
|
||||
FD_SET(m_sockClient, &fdsRead);
|
||||
int iRet = select(m_sockClient+1, &fdsRead, NULL, NULL, &stTimeVal);
|
||||
int iRecvLen = 0;
|
||||
if (iRet > 0)
|
||||
{
|
||||
if (FD_ISSET(m_sockClient, &fdsRead) > 0)
|
||||
{
|
||||
iRecvLen = recv(m_sockClient, m_pClearRcvBuf, m_iRcvBuf, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]FD_ISSET is not detect read signal when select found read signal,errorno = %d"),MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
bRes = false;
|
||||
}
|
||||
}
|
||||
else if (iRet < 0)
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]select error in ClearRecvBuffer,errorno = %d"),MODULE_NAME, __LINE__, WSAGetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
bRes = false;
|
||||
}
|
||||
|
||||
/*if (iRecvLen > 0)
|
||||
{
|
||||
CString strContent;
|
||||
CString strPrintContent;
|
||||
strContent.Format(_T("[%s][%d]CTcpClient::GetConnectStatus() recv data begin size=%d------\n"), MODULE_NAME, __LINE__, iRecvLen);
|
||||
//CFileOperTools::GetInstance()->WriteComLog(strContent);
|
||||
//打印接收数据流
|
||||
unsigned char *pszTempData = (unsigned char*)m_pClearRcvBuf;
|
||||
for (int i = 0; i < iRecvLen; i++)
|
||||
{
|
||||
strContent.AppendFormat(" %02x", pszTempData[i]);
|
||||
strPrintContent.AppendFormat("%c", pszTempData[i]);
|
||||
if ((i != 0 && i % 15 == 0) || (i == iRecvLen - 1))
|
||||
{
|
||||
strContent += "|";
|
||||
strContent += strPrintContent;
|
||||
//strContent += "\n";
|
||||
CFileOperTools::GetInstance()->WriteComLog(strContent);
|
||||
strContent.Empty();
|
||||
strPrintContent.Empty();
|
||||
}
|
||||
}
|
||||
strContent.Format(_T("[%s][%d]CTcpClient::GetConnectStatus() recv data end size=%d--------\n"), MODULE_NAME, __LINE__, iRecvLen);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strContent);
|
||||
} */
|
||||
return bRes;
|
||||
}
|
||||
@@ -0,0 +1,615 @@
|
||||
// TransferCtrl.cpp: implementation of the CTransferCtrl class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include "TransferCtrl.h"
|
||||
#include "FileOperTools.h"
|
||||
#include "GeoMative.h"
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[]=__FILE__;
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
extern BYTE BBCCalculate(const char *pData, int iSize,BYTE ucOrgRes);
|
||||
extern CGeoMativeApp theApp;
|
||||
extern int g_iTransFileMode;
|
||||
extern BOOL g_bIsOnlineTransfer;
|
||||
//extern BYTE g_byCurTestType;
|
||||
#define MODULE_NAME _T("CTransferCtrl")
|
||||
#define MAX_SKIP_ERR_BYTES 60
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CTransferCtrl::CTransferCtrl()
|
||||
{
|
||||
|
||||
// memset(&m_stCtrlRcvMsg, 0, sizeof(m_stCtrlRcvMsg));
|
||||
m_bIsNeedSendCtrMsg = false;
|
||||
m_iLastErrNo = 0;
|
||||
m_bIsInitialed = false;
|
||||
m_ucCmd = 0;
|
||||
m_iSeriNo = 1;
|
||||
m_ucDevType =0;
|
||||
m_ucCtrlCmd = 0;
|
||||
m_iLastSeriNo = 0;
|
||||
m_uiPlcAddr = 0;
|
||||
|
||||
}
|
||||
|
||||
CTransferCtrl::~CTransferCtrl()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CTransferCtrl::InitialClient()
|
||||
{
|
||||
return true;
|
||||
/*
|
||||
char chRcvBuf[MAX_RCV_CTRLBUF]={0};
|
||||
int iCtrlLen = 0;
|
||||
int iRepeat = 100;
|
||||
while(iRepeat > 0)
|
||||
{
|
||||
int iCtrlRes = RecvCtrlMsg(chRcvBuf, &iCtrlLen, MAX_RCV_CTRLBUF, 100);
|
||||
if (EN_RECV_CTRL_CMD == iCtrlRes)
|
||||
{
|
||||
if (EN_FORCE_LOGIN == GetCurrCtrlCmd())
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool CTransferCtrl::Initialize()
|
||||
{
|
||||
m_bIsInitialed = InitailTcp();
|
||||
return m_bIsInitialed;
|
||||
}
|
||||
|
||||
//DEL bool CTransferCtrl::ConnectToServer(CString strIP, WORD wPort)
|
||||
//DEL {
|
||||
//DEL if (ConnectServer(strIP,wPort))
|
||||
//DEL {
|
||||
//DEL m_strIPAddr = strIP;
|
||||
//DEL m_wPort = wPort;
|
||||
//DEL return true;
|
||||
//DEL }
|
||||
//DEL return false;
|
||||
//DEL }
|
||||
|
||||
|
||||
//DEL bool CTransferCtrl::ReConnect()
|
||||
//DEL {
|
||||
//DEL return ConnectToServer(m_strIPAddr, m_wPort);
|
||||
//DEL }
|
||||
|
||||
//DEL bool CTransferCtrl::SendCtrlInfo(BYTE ucCmd, WORD wTsn, const char* pData, WORD wLen, int iTimeOut)
|
||||
//DEL {
|
||||
//DEL EnterCriticalSection(&m_MutexSec);
|
||||
//DEL if (0 != m_stProCtrlInfo.ucCmd)
|
||||
//DEL {
|
||||
//DEL return false;
|
||||
//DEL }
|
||||
//DEL memset(&m_stProCtrlInfo, 0, sizeof(m_stProCtrlInfo));
|
||||
//DEL if (wLen > 0)
|
||||
//DEL {
|
||||
//DEL if (wLen > MAX_CTRL_CONTENT)
|
||||
//DEL {
|
||||
//DEL CString str = _T("");
|
||||
//DEL str.Format(_T("send ctrl cmd information overlength,value = %d, max_length = %d"), wLen, MAX_CTRL_CONTENT);
|
||||
//DEL AfxMessageBox(str);
|
||||
//DEL return false;
|
||||
//DEL }
|
||||
//DEL m_stProCtrlInfo.wLen = wLen;
|
||||
//DEL memcpy(m_stProCtrlInfo.chData, pData, wLen);
|
||||
//DEL }
|
||||
//DEL else
|
||||
//DEL m_stProCtrlInfo.wLen =0;
|
||||
//DEL m_stProCtrlInfo.ucCmd = ucCmd;
|
||||
//DEL m_stProCtrlInfo.wTsn = wTsn;
|
||||
//DEL m_stProCtrlInfo.iTimeOut = iTimeOut;
|
||||
//DEL // m_stProCtrlInfo.wRespLen = GetCtrlRspLength(ucCmd);
|
||||
//DEL m_bIsNeedSendCtrMsg = true;
|
||||
//DEL
|
||||
//DEL LeaveCriticalSection(&m_MutexSec);
|
||||
//DEL return true;
|
||||
//DEL }
|
||||
bool CTransferCtrl::SendCtrlInfo(const char*pCtrlHeader, const char* pData, WORD wDataLen,BYTE DataType)
|
||||
{
|
||||
STTransCtrlInfo *pTransCtrl = (STTransCtrlInfo*)pCtrlHeader;
|
||||
return SendCtrlInfoToDev(pTransCtrl,pData, wDataLen,DataType);
|
||||
}
|
||||
|
||||
|
||||
bool CTransferCtrl::SendCtrlInfoToDev(const STTransCtrlInfo * pTransInfo,const char* pData, WORD wDataLen, BYTE ucDataType)
|
||||
{
|
||||
BYTE ucBuf[4096]={0};
|
||||
STCtrlProtoHeader* pHeader = (STCtrlProtoHeader*)ucBuf;
|
||||
pHeader->wIDCode = htonl(CTRL_GD10_CODE) ;
|
||||
pHeader->ucSrcAddr = htonl(theApp.m_uiUserID);
|
||||
pHeader->ucSrcType = 2;
|
||||
// if (0 == pTransInfo->ucCmd)
|
||||
// pHeader->ucDstAddr = 0xFFFFFFFF;
|
||||
// else
|
||||
pHeader->ucDstAddr = htonl(pTransInfo->uiDevID);
|
||||
|
||||
|
||||
pHeader->ucDstType = pTransInfo->ucDevType;
|
||||
pHeader->ucCMD = pTransInfo->ucCmd;
|
||||
pHeader->ucDataType = ucDataType;
|
||||
if (1 == ucDataType)
|
||||
pHeader->dwSeriNO = htonl(m_iSeriNo++);
|
||||
else
|
||||
pHeader->dwSeriNO = htonl(m_iLastSeriNo);
|
||||
pHeader->Status_code = 0;
|
||||
pHeader->ucPacketNum = 1;
|
||||
memset(pHeader->ucReverse, 0, sizeof(pHeader->ucReverse));
|
||||
WORD wTotalLen = sizeof(STCtrlProtoHeader)+1;
|
||||
|
||||
if (wDataLen > 0)
|
||||
{
|
||||
memcpy(ucBuf+sizeof(STCtrlProtoHeader), pData, wDataLen);
|
||||
wTotalLen += wDataLen;
|
||||
}
|
||||
pHeader->wTotalLen = htons(wTotalLen);
|
||||
*((BYTE*)(ucBuf+wTotalLen-1)) = BBCCalculate((const char*)(ucBuf), wTotalLen-1, 0);
|
||||
int iSendLen = SendData((const char*)ucBuf, wTotalLen);
|
||||
//如果发送成功,则设置接收数据相关的控制信息
|
||||
if (iSendLen == wTotalLen)
|
||||
{
|
||||
m_ucCmd = pTransInfo->ucCmd;
|
||||
m_ucDevType = pTransInfo->ucDevType;
|
||||
// m_stCtrlRcvMsg.wTsn = wTsn;
|
||||
return true;
|
||||
}
|
||||
CString str = _T("");
|
||||
str.Format(_T("[%s][%d]send data error, shoule_send_length = %d, actually_val = %d,error = %d"),
|
||||
MODULE_NAME, __LINE__, wTotalLen, iSendLen, GetLastError());
|
||||
CFileOperTools::GetInstance()->WriteComLog(str);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool CTransferCtrl::RecvEnoughMsg(char* pData, int iLen, int iTimeOut)
|
||||
{
|
||||
DWORD dwTick = GetTickCount();
|
||||
DWORD dwCostTick = 0;
|
||||
int iTmpLen = 0, iRcvLen = 0;
|
||||
CString str = _T("");
|
||||
while(dwCostTick < iTimeOut)
|
||||
{
|
||||
iTmpLen = 0;
|
||||
if (!RecvData(pData+iRcvLen, iLen-iRcvLen, iTmpLen))
|
||||
{
|
||||
str.Format(_T("[%s][%d]zm:CTransferCtrl::RecvEnoughMsg() !RecvData(pData+iRcvLen, iLen-iRcvLen, iTmpLen)"), MODULE_NAME, __LINE__);
|
||||
CFileOperTools::GetInstance()->WriteComLog(str);
|
||||
return false;
|
||||
}
|
||||
iRcvLen += iTmpLen;
|
||||
if (iRcvLen > iLen)
|
||||
{
|
||||
str.Format(_T("[%s][%d]zm: CTransferCtrl::RecvEnoughMsg() %s"), MODULE_NAME, __LINE__, str);
|
||||
CFileOperTools::GetInstance()->WriteComLog(str);
|
||||
return false;
|
||||
}
|
||||
else if (iRcvLen == iLen)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
Sleep(100);
|
||||
dwCostTick = GetTickCount() - dwTick;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CTransferCtrl::IsCtrlMsg(BYTE ucCMd)
|
||||
{
|
||||
if (EN_TRANSFER_FILE_BY_WIFI == g_iTransFileMode)
|
||||
{
|
||||
if ( 0 == ucCMd)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else if (EN_TRANSFER_FILE_BY_CLOUND == g_iTransFileMode)
|
||||
{
|
||||
if (ucCMd == EN_DEV_ONLINE || ucCMd == EN_FORCE_LOGIN )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
bool CTransferCtrl::IsPlcStatusMsg(BYTE ucCmd, BYTE ucSrcType)
|
||||
{
|
||||
if ((5 == ucCmd) && (ucSrcType == EN_DEV_PLC) && (EN_TRANSFER_FILE_BY_CLOUND == g_iTransFileMode))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
int CTransferCtrl::RecvCommRspMsg(char* pRcvData, int* pRcvLen, int iMaxRcvLen, int iRcvTimeout,bool bIsRcvCtrl)
|
||||
{
|
||||
// iRcvTimeout =5000;
|
||||
DWORD dwTick = GetTickCount();
|
||||
DWORD dwCostTick = 0;
|
||||
//这里包括一个字节的CRC位置
|
||||
int iHeaderSize = sizeof(STCtrlProtoHeader)+1;
|
||||
int iGetReceivedDataTime = 1000;
|
||||
CString strErr = _T("");
|
||||
char chData[100]={0};
|
||||
WORD wSkipByte = 0;
|
||||
|
||||
while(dwCostTick < iRcvTimeout)
|
||||
{
|
||||
if (!RecvEnoughMsg(chData, iHeaderSize, iRcvTimeout-dwCostTick))
|
||||
{
|
||||
if (GetTickCount()-dwTick >= iRcvTimeout)
|
||||
{
|
||||
if (!bIsRcvCtrl)
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]receive data(HeaderSize) timeout,max_time=%d"),MODULE_NAME, __LINE__,iRcvTimeout);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
}
|
||||
|
||||
return EN_RECV_TIMEOUT;
|
||||
}
|
||||
return EN_RECV_TIMEOUT;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
bool bIsFoundID = false;
|
||||
UINT dwIDCode = 0;
|
||||
for (i = 0; i <= iHeaderSize; i++)
|
||||
{
|
||||
dwIDCode = ntohl(*(UINT*)(chData+i));
|
||||
if (dwIDCode == CTRL_GD10_CODE )
|
||||
{
|
||||
bIsFoundID = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//如果查找到
|
||||
if (bIsFoundID)
|
||||
{
|
||||
//如果是在数据的中间部分查找到,则还需要在接收缓冲区里寻找数据控制协议的后半部分
|
||||
if (i > 0)
|
||||
{
|
||||
char chTmpData[100]= {0};
|
||||
//如果已经找到顺利在数据之间找到了起始标志,那么可以认为这个包的剩下信息也已经到数据缓冲区了
|
||||
//所以此时可以设置1秒为最大延时
|
||||
if (!RecvEnoughMsg(chTmpData+(iHeaderSize-i), i,iGetReceivedDataTime))
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]receive data timeout when found pro_ctrl_id_code"),MODULE_NAME, __LINE__);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_TIMEOUT;
|
||||
}
|
||||
//将pRcvData起始位置到结束位置都拷贝到新的缓冲区里,形成一个新的PRO_CTRL_HEADER
|
||||
memcpy(chTmpData, chData+i, iHeaderSize-i);
|
||||
//再将新缓冲区的内容拷贝回来
|
||||
memcpy(chData, chTmpData, iHeaderSize);
|
||||
}
|
||||
//进行数据控制协议的校验
|
||||
STCtrlProtoHeader* pHeaderInfo = (STCtrlProtoHeader*)chData;
|
||||
|
||||
WORD wLen = ntohs(pHeaderInfo->wTotalLen);
|
||||
//长度校验
|
||||
if ((wLen-iHeaderSize) > iMaxRcvLen)
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]receive data len error, MaxRcvLen = %d, RecvDataLen = %d"),MODULE_NAME, __LINE__,
|
||||
iMaxRcvLen, wLen - iHeaderSize);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_DATA_ERROR;
|
||||
}
|
||||
if (wLen > iHeaderSize)
|
||||
{
|
||||
//由于可能存在超长报文而被分包,所以这里等待时间延长设置为原来等待已经到达数据的2倍时间
|
||||
pRcvData[0] = chData[iHeaderSize-1];//因为此时数据的第一个个字节已经存储到控制报文中去了
|
||||
if (!RecvEnoughMsg(pRcvData+1, wLen-iHeaderSize, 2*iGetReceivedDataTime))
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]receive data timeout when found pro_ctrl_id_code"),MODULE_NAME, __LINE__);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_TIMEOUT;
|
||||
}
|
||||
}
|
||||
//如果这里收到的是云端发过来的强制登录信息,则直接忽略进行获取下一个报文
|
||||
// if (0xFE == pHeaderInfo->ucCMD )
|
||||
// {
|
||||
// //清空之间的数据
|
||||
// if (wLen > iHeaderSize)
|
||||
// memset(pRcvData, 0, iMaxRcvLen);
|
||||
// return RecvCommRspMsg(pRcvData, pRcvLen, iMaxRcvLen, iRcvTimeout);
|
||||
// }
|
||||
|
||||
if (pHeaderInfo->ucCMD == EN_CTRL_MEASURE_DATA && (g_bIsOnlineTransfer == TRUE))
|
||||
{
|
||||
//校验CRC
|
||||
BYTE ucCRc = BBCCalculate(chData, iHeaderSize - 1, 0);
|
||||
if (wLen > iHeaderSize)
|
||||
ucCRc = BBCCalculate(pRcvData, wLen - iHeaderSize, ucCRc);
|
||||
BYTE ucRecvCRC = (wLen > iHeaderSize) ? *((BYTE*)(pRcvData + wLen - iHeaderSize)) : *(BYTE*)(chData + iHeaderSize - 1);
|
||||
if (ucCRc != *((BYTE*)(pRcvData + wLen - iHeaderSize)))
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]CRC error, calucate_crc = %d, org_data_crc = %d"), MODULE_NAME, __LINE__, ucCRc, *((BYTE*)(pRcvData + wLen - iHeaderSize - 1)));
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_DATA_ERROR;
|
||||
}
|
||||
strErr.Format(_T("[%s][%d]:recv real time wnd %0x begin***************"), MODULE_NAME, __LINE__, pHeaderInfo->ucCMD);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_REAL_TIME_TESTING_DATA;
|
||||
}
|
||||
|
||||
if (pHeaderInfo->ucCMD == EN_RECV_DEVICE_ONLINE)
|
||||
{
|
||||
//校验CRC
|
||||
BYTE ucCRc = BBCCalculate(chData, iHeaderSize - 1, 0);
|
||||
if (wLen > iHeaderSize)
|
||||
ucCRc = BBCCalculate(pRcvData, wLen - iHeaderSize, ucCRc);
|
||||
BYTE ucRecvCRC = (wLen > iHeaderSize) ? *((BYTE*)(pRcvData + wLen - iHeaderSize)) : *(BYTE*)(chData + iHeaderSize - 1);
|
||||
if (ucCRc != *((BYTE*)(pRcvData + wLen - iHeaderSize)))
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]CRC error, calucate_crc = %d, org_data_crc = %d"), MODULE_NAME, __LINE__, ucCRc, *((BYTE*)(pRcvData + wLen - iHeaderSize - 1)));
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_DATA_ERROR;
|
||||
}
|
||||
return EN_RECV_NOTIFY_DEVICE_ONLINE;
|
||||
}
|
||||
else if (pHeaderInfo->ucCMD == EN_RECV_DEVICE_OFFLINE)
|
||||
{
|
||||
//校验CRC
|
||||
BYTE ucCRc = BBCCalculate(chData, iHeaderSize - 1, 0);
|
||||
if (wLen > iHeaderSize)
|
||||
ucCRc = BBCCalculate(pRcvData, wLen - iHeaderSize, ucCRc);
|
||||
BYTE ucRecvCRC = (wLen > iHeaderSize) ? *((BYTE*)(pRcvData + wLen - iHeaderSize)) : *(BYTE*)(chData + iHeaderSize - 1);
|
||||
if (ucCRc != *((BYTE*)(pRcvData + wLen - iHeaderSize)))
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]CRC error, calucate_crc = %d, org_data_crc = %d"), MODULE_NAME, __LINE__, ucCRc, *((BYTE*)(pRcvData + wLen - iHeaderSize - 1)));
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_DATA_ERROR;
|
||||
}
|
||||
return EN_RECV_NOTIFY_DEVICE_OFFLINE;
|
||||
}
|
||||
|
||||
int iRet = 0;
|
||||
if (IsCtrlMsg(pHeaderInfo->ucCMD))
|
||||
{
|
||||
m_ucCtrlCmd = pHeaderInfo->ucCMD;
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]receive ctrl msg.msg_cmd = %d"),MODULE_NAME, __LINE__,pHeaderInfo->ucCMD);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
*pRcvLen = wLen -iHeaderSize;
|
||||
iRet = EN_RECV_CTRL_CMD;
|
||||
m_iLastSeriNo = ntohl(pHeaderInfo->dwSeriNO);
|
||||
}
|
||||
else if (IsPlcStatusMsg(pHeaderInfo->ucCMD,pHeaderInfo->ucSrcType))
|
||||
{
|
||||
iRet = EN_RECV_PLC_STATUS;
|
||||
m_uiPlcAddr = pHeaderInfo->ucSrcAddr;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pHeaderInfo->ucCMD != EN_CTRL_MEASURE_DATA) && (pHeaderInfo->ucCMD != m_ucCmd))
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]recv response's cmd(%d) is not equal to ctrl's cmd(%d)"),MODULE_NAME, __LINE__,
|
||||
pHeaderInfo->ucCMD, m_ucCmd);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_DATA_DISORDER;
|
||||
}
|
||||
if (pHeaderInfo->Status_code != 0)
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]recv send cmd (%d) failed info from clound "),MODULE_NAME, __LINE__, pHeaderInfo->ucCMD);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_CLOUND_SND_FAILED;
|
||||
}
|
||||
if (m_ucDevType != pHeaderInfo->ucSrcType)
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]recv response's type(%d) is not equal to ctrl's dstType(%d)"),MODULE_NAME, __LINE__,
|
||||
pHeaderInfo->ucSrcType, m_ucDevType);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_DATA_DISORDER;
|
||||
}
|
||||
}
|
||||
|
||||
//校验CRC
|
||||
BYTE ucCRc = BBCCalculate(chData, iHeaderSize-1, 0);
|
||||
if (wLen > iHeaderSize)
|
||||
ucCRc = BBCCalculate(pRcvData, wLen -iHeaderSize, ucCRc);
|
||||
BYTE ucRecvCRC = (wLen > iHeaderSize) ? *((BYTE*)(pRcvData + wLen -iHeaderSize)) : *(BYTE*)(chData+iHeaderSize-1);
|
||||
if (ucCRc != *((BYTE*)(pRcvData + wLen -iHeaderSize)))
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]CRC error, calucate_crc = %d, org_data_crc = %d"), MODULE_NAME, __LINE__, ucCRc, *((BYTE*)(pRcvData + wLen -iHeaderSize-1)));
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_DATA_ERROR;
|
||||
}
|
||||
if ((EN_TRANSFER_FILE_BY_WIFI == g_iTransFileMode) && ( 0 == pHeaderInfo->ucCMD))
|
||||
{
|
||||
// memcpy(pRcvData, )
|
||||
|
||||
*((WORD*)pRcvData) = htons(1);
|
||||
pRcvData[2] = EN_DEV_GD10;
|
||||
*((UINT*)(pRcvData+3)) = pHeaderInfo->ucSrcAddr;
|
||||
*pRcvLen = 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
*((BYTE*)(pRcvData + wLen -iHeaderSize)) = 0;
|
||||
*pRcvLen = wLen -iHeaderSize;
|
||||
}
|
||||
|
||||
if (iRet > 0)
|
||||
{
|
||||
return iRet;
|
||||
}
|
||||
return EN_RECV_SUCCESS;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
wSkipByte += iHeaderSize;
|
||||
if (wSkipByte > MAX_SKIP_ERR_BYTES)
|
||||
{
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d] can not fouund pro_ctrl_id when skip max error bytes"), MODULE_NAME, __LINE__);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_DATA_ERROR;
|
||||
}
|
||||
Sleep(100);
|
||||
dwCostTick = GetTickCount() - dwTick;
|
||||
|
||||
}
|
||||
}
|
||||
strErr.Empty();
|
||||
strErr.Format(_T("[%s][%d]receive data packer timeout,max_time=%d"),MODULE_NAME, __LINE__,iRcvTimeout);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_TIMEOUT;
|
||||
}
|
||||
|
||||
|
||||
int CTransferCtrl::RecvRspMsg(char* pData, int* pLen, int iMaxLen,int iTimeout)
|
||||
{
|
||||
// if (m_ucCmd < 1)
|
||||
// {
|
||||
// AfxMessageBox(_T("There is no need to recv response because of empty cmd"));
|
||||
// return EM_RECV_FAILED;
|
||||
// }
|
||||
if (!GetConnectStatus())
|
||||
{
|
||||
return EN_RECV_LINK_INTERRUPT;
|
||||
}
|
||||
int iRet;
|
||||
DWORD dwTicket = GetTickCount();
|
||||
DWORD dwCostTicket = 0;
|
||||
memset(pData, 0, iMaxLen);
|
||||
while(dwCostTicket < iTimeout)
|
||||
{
|
||||
iRet = RecvCommRspMsg(pData, pLen, iMaxLen,iTimeout-dwCostTicket);
|
||||
//只有这三种情况立即返回,其他的都在继续获取数据,直到成功或者超时
|
||||
if (EN_RECV_CTRL_CMD == iRet || EN_CLOUND_SND_FAILED == iRet || EN_RECV_SUCCESS == iRet)
|
||||
{
|
||||
return iRet;
|
||||
}
|
||||
dwCostTicket = GetTickCount()-dwTicket;
|
||||
}
|
||||
CString strErr = _T("");
|
||||
strErr.Format(_T("[%s][%d]receive total response data timeout,max_time=%d"),MODULE_NAME, __LINE__,iTimeout);
|
||||
CFileOperTools::GetInstance()->WriteComLog(strErr);
|
||||
return EN_RECV_TIMEOUT;
|
||||
|
||||
}
|
||||
|
||||
int CTransferCtrl::RecvCtrlMsg( char* pData, int* pLen, int iMaxLen, int iTimeout)
|
||||
{
|
||||
if (!GetConnectStatus())
|
||||
{
|
||||
return EN_RECV_LINK_INTERRUPT;
|
||||
}
|
||||
return RecvCommRspMsg(pData, pLen, iMaxLen,iTimeout,true);
|
||||
}
|
||||
|
||||
// void CTransferCtrl::ClearCtrlInfo()
|
||||
// {
|
||||
// if (m_vtProCtrl.empty())
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// for (int i = 0; i < m_vtProCtrl.size(); i++)
|
||||
// {
|
||||
// if (m_vtProCtrl[i].lpData)
|
||||
// {
|
||||
// delete []m_vtProCtrl[i].lpData;
|
||||
// }
|
||||
// }
|
||||
// m_vtProCtrl.clear();
|
||||
// }
|
||||
|
||||
//DEL bool CTransferCtrl::StartWork()
|
||||
//DEL {
|
||||
//DEL if (!m_bIsInitialed)
|
||||
//DEL {
|
||||
//DEL AfxMessageBox(_T("please initiallize firstly."));
|
||||
//DEL return false;
|
||||
//DEL }
|
||||
//DEL m_bIsRunning = true;
|
||||
//DEL m_pThread = AfxBeginThread(StartProcFunc,(LPVOID)this);
|
||||
//DEL if (NULL == m_pThread)
|
||||
//DEL {
|
||||
//DEL AfxMessageBox(_T("Create process data thread failed."));
|
||||
//DEL return false;
|
||||
//DEL }
|
||||
//DEL return true;
|
||||
//DEL }
|
||||
|
||||
bool CTransferCtrl::IsNeedSendCtrl()
|
||||
{
|
||||
return m_bIsNeedSendCtrMsg;
|
||||
|
||||
}
|
||||
|
||||
//DEL void CTransferCtrl::ShowStatusInfo(WORD wMsg, WORD wStatus)
|
||||
//DEL {
|
||||
//DEL if (m_pShowInfoCwnd)
|
||||
//DEL {
|
||||
//DEL m_pShowInfoCwnd->PostMessage(wStatus, wStatus);
|
||||
//DEL }
|
||||
//DEL
|
||||
//DEL }
|
||||
/*
|
||||
UINT CTransferCtrl::StartProcFunc(LPVOID lParam)
|
||||
{
|
||||
CTransferCtrl* pTransfer = (CTransferCtrl*)lParam;
|
||||
InitializeCriticalSection(&(pTransfer->m_MutexSec));
|
||||
while (pTransfer->m_bIsRunning)
|
||||
{
|
||||
if (!pTransfer->GetConnectStatus())
|
||||
{
|
||||
pTransfer->ShowStatusInfo(WM_CONNECT_STATUS, EN_STATUS_DISCONNECT);
|
||||
//隔30秒进行重连操作
|
||||
Sleep(30000);
|
||||
if (!pTransfer->ReConnect())
|
||||
{
|
||||
pTransfer->ShowStatusInfo(WM_CONNECT_STATUS, EN_STATUS_RECONNECT_FAIL);
|
||||
Sleep(10000);
|
||||
continue;
|
||||
}
|
||||
pTransfer->ShowStatusInfo(WM_CONNECT_STATUS, EN_STATUS_CONNECT_SUCCESS);
|
||||
|
||||
}
|
||||
if (pTransfer->IsNeedSendCtrl())
|
||||
{
|
||||
if (pTransfer->SendCtrlInfoToDev())
|
||||
{
|
||||
int iRet = pTransfer->RecvRspMsg()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,281 @@
|
||||
// floatedit.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "geomative.h"
|
||||
#include "floatedit.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#undef THIS_FILE
|
||||
static char THIS_FILE[] = __FILE__;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CFloatEdit
|
||||
|
||||
CFloatEdit::CFloatEdit()
|
||||
{
|
||||
m_iIntLimitLen = 4;
|
||||
m_iDecLimitLen = 2;
|
||||
|
||||
m_bIsMinus = FALSE;
|
||||
}
|
||||
|
||||
CFloatEdit::~CFloatEdit()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CFloatEdit, CEdit)
|
||||
//{{AFX_MSG_MAP(CFloatEdit)
|
||||
ON_WM_CHAR()
|
||||
ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus)
|
||||
ON_CONTROL_REFLECT(EN_SETFOCUS, OnSetfocus)
|
||||
ON_WM_KEYDOWN()
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CFloatEdit message handlers
|
||||
|
||||
void CFloatEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
|
||||
{
|
||||
// TODO: Add your message handler code here and/or call default
|
||||
CString szText = _T("");
|
||||
int iLen = 0;
|
||||
int iIntLen = 0;
|
||||
int iDecLen = 0;
|
||||
|
||||
int iStartChar = 0;
|
||||
int iEndChar = 0;
|
||||
|
||||
int iMinus = 0;
|
||||
|
||||
GetWindowText(szText);
|
||||
iLen = szText.GetLength();
|
||||
|
||||
GetSel(iStartChar, iEndChar);
|
||||
|
||||
if ((FALSE == m_bIsMinus) && ('-' == nChar))
|
||||
{
|
||||
nChar = 0;
|
||||
}
|
||||
|
||||
if((nChar >= '0' && nChar <= '9' ) || ('.' == nChar) || ('-' == nChar))
|
||||
{
|
||||
iMinus = 0;
|
||||
|
||||
if ((szText.Left(1) != _T("-")) && ((iStartChar == iEndChar) && (0 == iStartChar)) && ('-' == nChar))
|
||||
{
|
||||
szText.Insert(0, (TCHAR)nChar);
|
||||
SetWindowText(szText);
|
||||
SetSel(1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((szText.Left(1) == _T("-")) && ('-' == nChar))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (szText.Find("-") == 0)
|
||||
{
|
||||
iMinus = 1;
|
||||
}
|
||||
|
||||
if (szText.Find('.') < 0)
|
||||
{
|
||||
if ('.' == nChar)
|
||||
{
|
||||
if (iLen > 0)
|
||||
{
|
||||
szText = szText + '.';
|
||||
SetWindowText(szText);
|
||||
SetSel(iLen, ++iLen); //依据C++参数传递顺序,先执行++iLen,此时iLen等于iLen+1
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iStartChar == iEndChar)
|
||||
{
|
||||
if (iLen < (m_iIntLimitLen + iMinus))
|
||||
{
|
||||
if (nChar != '-')
|
||||
{
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
iIntLen = szText.Find('.') - iMinus;
|
||||
iDecLen = iLen - szText.Find('.') - 1;
|
||||
|
||||
if ('.' != nChar)
|
||||
{
|
||||
/*
|
||||
if ((iStartChar == iEndChar) && (iStartChar > iIntLen) && (iDecLen < m_iDecLimitLen)) //控制小数位长度
|
||||
{
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
|
||||
if ((iStartChar == iEndChar) && (iStartChar <= iIntLen) && (iIntLen < m_iIntLimitLen)) //控制整数位长度
|
||||
{
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
*/
|
||||
if (iStartChar == iEndChar)
|
||||
{
|
||||
if (iStartChar > iIntLen)
|
||||
{
|
||||
if (iDecLen < m_iDecLimitLen) //控制小数位长度
|
||||
{
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (iIntLen < (m_iIntLimitLen)) //控制整数位长度
|
||||
{
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (0x0008 == nChar) //VK_BACK == 0x0008
|
||||
{
|
||||
if (szText.Find('.') >= 0)
|
||||
{
|
||||
iIntLen = szText.Find('.');
|
||||
iDecLen = iLen - szText.Find('.') - 1;
|
||||
|
||||
if ((iIntLen + 1) == iStartChar)
|
||||
{
|
||||
szText = szText.Left(iIntLen);
|
||||
SetWindowText(szText);
|
||||
|
||||
iLen = szText.GetLength();
|
||||
SetSel(iLen, ++iLen);
|
||||
return;
|
||||
}
|
||||
}
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
}
|
||||
|
||||
void CFloatEdit::OnKillfocus()
|
||||
{
|
||||
// TODO: Add your control notification handler code here
|
||||
CString szText = _T("");
|
||||
int iLen = (int)VAL_ZERO;
|
||||
int iIntLen = (int)VAL_ZERO;
|
||||
|
||||
GetWindowText(szText);
|
||||
|
||||
if ((szText.GetLength() > (int)VAL_ZERO) && (float)VAL_ZERO == atof(szText))
|
||||
{
|
||||
szText = _T("0");
|
||||
// SetWindowText(szText);
|
||||
// return;
|
||||
}
|
||||
else
|
||||
{
|
||||
szText.TrimLeft('0');
|
||||
// szText.TrimRight('0');
|
||||
}
|
||||
|
||||
iLen = szText.GetLength();
|
||||
|
||||
if ((iLen - 1) == szText.Find('.'))
|
||||
{
|
||||
szText.Delete(--iLen, 1);
|
||||
}
|
||||
|
||||
iIntLen = szText.Find('.');
|
||||
if (0 == iIntLen)
|
||||
{
|
||||
szText = '0' + szText;
|
||||
SetSel(iLen, ++iLen);
|
||||
}
|
||||
SetWindowText(szText);
|
||||
}
|
||||
|
||||
void CFloatEdit::SetIntLimitLen(int iIntLimitLen)
|
||||
{
|
||||
this->m_iIntLimitLen = iIntLimitLen;
|
||||
}
|
||||
|
||||
void CFloatEdit::SetDecLimitLen(int iDecLimitLen)
|
||||
{
|
||||
this->m_iDecLimitLen = iDecLimitLen;
|
||||
}
|
||||
|
||||
void CFloatEdit::SetIsMinus(BOOL bIsMinus)
|
||||
{
|
||||
this->m_bIsMinus = bIsMinus;
|
||||
}
|
||||
|
||||
void CFloatEdit::OnSetfocus()
|
||||
{
|
||||
// TODO: Add your control notification handler code here
|
||||
CString szText = _T("");
|
||||
int iLen = 0;
|
||||
|
||||
GetWindowText(szText);
|
||||
iLen = szText.GetLength();
|
||||
SetSel(iLen, ++iLen);
|
||||
}
|
||||
|
||||
void CFloatEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
|
||||
{
|
||||
// TODO: Add your message handler code here and/or call default
|
||||
|
||||
CString szText = _T("");
|
||||
int iLen = 0;
|
||||
int iIntLen = 0;
|
||||
int iDecLen = 0;
|
||||
|
||||
int iStartChar = 0;
|
||||
int iEndChar = 0;
|
||||
|
||||
GetWindowText(szText);
|
||||
iLen = szText.GetLength();
|
||||
|
||||
GetSel(iStartChar, iEndChar);
|
||||
if (0x002E == nChar) //VK_DELETE == 0x002E
|
||||
{
|
||||
if (szText.Find('.') >= 0)
|
||||
{
|
||||
iIntLen = szText.Find('.');
|
||||
iDecLen = iLen - szText.Find('.') - 1;
|
||||
|
||||
if (iIntLen == iStartChar)
|
||||
{
|
||||
szText = szText.Left(iIntLen);
|
||||
SetWindowText(szText);
|
||||
|
||||
iLen = szText.GetLength();
|
||||
SetSel(iLen, ++iLen);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user