This commit is contained in:
coco
2026-07-03 16:05:30 +08:00
commit df489d5640
1101 changed files with 779140 additions and 0 deletions
+467
View File
@@ -0,0 +1,467 @@
// ProgressDlg.cpp : implementation file
//
#include "stdafx.h"
#include "geomative.h"
#include "ProgressDlg.h"
#include "DetcGD10Dev.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern SYSTEMTIME g_sysCurTime;
extern int g_iTransFileMode;
extern int g_iUILanguage;
/////////////////////////////////////////////////////////////////////////////
// CProgressDlg dialog
CProgressDlg::CProgressDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProgressDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CProgressDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_exCode = FALSE;
m_RecvOrSend = FALSE;
m_pThread = NULL;
m_zmodem = NULL;
m_device = NULL;
m_szHostFileName = _T("");
m_szHostFilePath = _T("");
m_szLocFileName = _T("");
m_szLocFilePath = _T("");
m_nThreadStatus = -1;
m_dwTotalFileSize = 0;
m_dwTotalRcvSize = 0;
}
void CProgressDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProgressDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProgressDlg, CDialog)
//{{AFX_MSG_MAP(CProgressDlg)
ON_WM_TIMER()
ON_MESSAGE(WM_BYTERECV, ShowProgress)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProgressDlg message handlers
BOOL CProgressDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
if (LANG_ZHCN == g_iUILanguage)
{
GetDlgItem(IDC_STATIC_TIP_INFO)->SetWindowText(_T(" 数据加载中,请稍后......"));
}
else
{
GetDlgItem(IDC_STATIC_TIP_INFO)->SetWindowText(_T(" Data loading, please wait..."));
}
m_zmodem = new Zmodem(&m_device->m_sComPort);
//log
m_pFile = fopen("log\\Progress.txt", "ab+");
CString szLog2 = _T("");
szLog2.Format("\r\nbegin---------------------------\r\n");
fwrite(szLog2.GetBuffer(0), 1, szLog2.GetLength(), m_pFile);
fflush(m_pFile);
//log
m_dwTotalFileSize = 0;
m_dwTotalRcvSize = 0;
if (!m_zmodem)
{
m_exCode = FALSE;
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("m_zodem是空exCode = FALSE"));
else
MessageBoxEx(NULL, _T("m_zodem is NULL, exCode = FALSE!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
SendMessage(WM_CLOSE,NULL,NULL);
}
else
{
if(m_RecvOrSend)
{
m_pThread = AfxBeginThread(SendFile, (LPVOID)this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
if (m_pThread)
{
m_pThread->m_bAutoDelete = FALSE;
m_nThreadStatus = -1;
m_pThread->ResumeThread();
SetTimer(1,40,NULL);
}
else
{
m_exCode = FALSE;
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("创建SendFileThread失败,exCode=False"));
else
MessageBoxEx(NULL, _T("Create SendFileThread Failed, exCode = FALSE!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
SendMessage(WM_CLOSE,NULL,NULL);
}
}
else
{
m_pThread = AfxBeginThread(RecvFile, (LPVOID)this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
if (m_pThread)
{
m_pThread->m_bAutoDelete = FALSE;
m_pThread->ResumeThread();
SetTimer(1,40,NULL);
}
else
{
m_exCode = FALSE;
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("创建RecvFileThread失败,exCode=FALSE"));
else
MessageBoxEx(NULL, _T("Create RecvFileThread Failed, exCode = FALSE!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
SendMessage(WM_CLOSE,NULL,NULL);
}
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
UINT CProgressDlg::RecvFile(LPVOID wparam)
{
CProgressDlg *pDlg;
pDlg = (CProgressDlg *)wparam;
CString strText = _T("");
if (EN_TRANSFER_FILE_BY_USB == g_iTransFileMode)
{
if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect())
{
pDlg->m_exCode = FALSE;
strText.Empty();
strText.Format(_T("[%d] Receive file failed because of gd20 device can not to be detected! srcDir = %s, dstPath = %s"),
__LINE__, pDlg->m_szHostFileName, pDlg->m_szLocFilePath);
pDlg->PrintLog(strText);
return FALSE;
}
//此时的m_szHostFileName包含文件名,将此时有原来的GD10的格式转化为USB格式
int nIndex = pDlg->m_szHostFileName.ReverseFind(_T('/'));
if (-1 == nIndex)
{
strText.Empty();
strText.Format(_T("[%d] Hostfilename path error, path = %s"), __LINE__, pDlg->m_szHostFileName);
pDlg->m_exCode = FALSE;
pDlg->PrintLog(strText);
return FALSE;
}
CString strFileName = pDlg->m_szHostFileName.Mid(nIndex+1,pDlg->m_szHostFileName.GetLength()-nIndex-1);
CString strCovert = pDlg->m_szHostFileName.Mid(0,nIndex+1);
strCovert.Replace(_T("/"),_T("\\"));
CString strHostFileFullPath = _T("");
strHostFileFullPath.Format(_T("%s%s"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(),strCovert);
pDlg->m_myCopyFile.Initialize();
pDlg->m_exCode = (true ==pDlg->m_myCopyFile.TransferFile(strHostFileFullPath, pDlg->m_szLocFilePath, strFileName)) ? true : false;
return pDlg->m_exCode;
}
//?20200810
/*CString szOrder = _T("");
CString szResBuff = _T("");
szOrder.Empty();
szOrder.Format(_T("sz(\"%s\")\r\n"), pDlg->m_szHostFileName);
// if (pDlg->m_szHostFileName == "/SD/users/0024E81931EB.xml")
// {
// int n = 1;
// }
if (!pDlg->m_device->ExecuteOrder(szOrder, "...", &szResBuff))
{
pDlg->m_exCode = FALSE;
CString strTmp =_T("");
if (LANG_ZHCN == g_iUILanguage)
{
strTmp.Format(_T("[%d] ExecuteOrder失败, szOrder = %s, exCode = FALSE!"), __LINE__, szOrder.GetBuffer(0));
AfxMessageBox(strTmp.GetBuffer(0));
}
else
{
strTmp.Format(_T("[%d] ExecuteOrder Failed, szOrder = %s, exCode = FALSE!"), __LINE__, szOrder.GetBuffer(0));
MessageBoxEx(NULL, strTmp, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return FALSE;
}
if (TRUE != pDlg->m_zmodem->Receive(pDlg->m_szLocFilePath))
{
pDlg->m_device->m_sComPort.ClearCommReceiveBuff();
pDlg->m_device->m_sComPort.ClearCommSendBuff();
pDlg->m_exCode = FALSE;
CString strTmp =_T("");
strTmp.Format(_T("[%d] Receive file Failed, m_szLocFilePath = %s, exCode = FALSE!"), __LINE__, pDlg->m_szLocFilePath.GetBuffer(0));
// AfxMessageBox(strTmp.GetBuffer(0));
pDlg->PrintLog(strTmp);
return FALSE;
}
else
{
// delete zmodem;
pDlg->m_device->m_sComPort.ClearCommReceiveBuff();
pDlg->m_device->m_sComPort.ClearCommSendBuff();
pDlg->m_exCode = TRUE;
return TRUE;
}*/
}
UINT CProgressDlg::SendFile(LPVOID wparam)
{
CProgressDlg *pDlg;
pDlg = (CProgressDlg *)wparam;
///////////////////////////test111///////////////////////////////////////////////
pDlg->m_nThreadStatus = 1;
//////////////////////////////////////////////////////////////////////////
CString strText = _T("");
//去掉驱动部分改成U盘模式同USB模式
//if (EN_TRANSFER_FILE_BY_USB == g_iTransFileMode)
{
if (!CDetcGD10Dev::GetInstance()->IsGD10DevConnect())
{
pDlg->m_exCode = FALSE;
strText.Empty();
strText.Format(_T("[%d] Send file failed because of gd20 device can not to be detected! srcDir = %s, dstPath = %s,name = %s"),
__LINE__, pDlg->m_szLocFilePath, pDlg->m_szHostFilePath, pDlg->m_szHostFilePath, pDlg->m_szLocFileName);
pDlg->PrintLog(strText);
return FALSE;
}
//此时的m_szHostFileName包含文件名,将此时有原来的GD10的格式转化为USB格式
CString strCovert = pDlg->m_szHostFilePath;
strCovert.Replace(_T("/"),_T("\\"));
CString strHostFileFullPath = _T("");
strHostFileFullPath.Format(_T("%s%s"),CDetcGD10Dev::GetInstance()->GetGD10DevAddr(),strCovert);
pDlg->m_myCopyFile.Initialize();
pDlg->m_exCode = (true ==pDlg->m_myCopyFile.TransferFile(pDlg->m_szLocFilePath, strHostFileFullPath, pDlg->m_szLocFileName)) ? true : false;
return pDlg->m_exCode;
}
CString szOrder = _T("");
CString szResBuff = _T("");
char *aLocFile[2] = {0,0};
CString szLocFile = _T("");
/*szOrder.Empty();
szOrder.Format(_T("rz(\"%s\")\r\n"), pDlg->m_szHostFilePath);
if (!pDlg->m_device->ExecuteOrder(szOrder, "...", &szResBuff))
{
pDlg->m_exCode = FALSE;
CString strTmp =_T("");
if (LANG_ZHCN == g_iUILanguage)
{
strTmp.Format(_T("[%d] ExecuteOrder 文件失败, szOrder = %s, exCode = FALSE!"), __LINE__, szOrder.GetBuffer(0));
AfxMessageBox(strTmp.GetBuffer(0));
}
else
{
strTmp.Format(_T("[%d] ExecuteOrder file Failed, szOrder = %s, exCode = FALSE!"), __LINE__, szOrder.GetBuffer(0));
MessageBoxEx(NULL, strTmp, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return FALSE;
}*/
szLocFile = pDlg->m_szLocFilePath + pDlg->m_szLocFileName;
aLocFile[0] = szLocFile.GetBuffer(szLocFile.GetLength());
aLocFile[1] = 0;
if (TRUE != pDlg->m_zmodem->Send(aLocFile))
{
pDlg->m_device->m_sComPort.ClearCommReceiveBuff();
pDlg->m_device->m_sComPort.ClearCommSendBuff();
pDlg->m_exCode = FALSE;
CString strTmp =_T("");
strTmp.Format(_T("[%d] Send file Failed, aLocFile = %s, exCode = FALSE!"), __LINE__, szLocFile.GetBuffer(szLocFile.GetLength()));
///////////////////////////test111///////////////////////////////////////////////
pDlg->m_nThreadStatus = 0;
//////////////////////////////////////////////////////////////////////////
// AfxMessageBox(strTmp.GetBuffer(0));
pDlg->PrintLog(strTmp);
return FALSE;
}
else
{
szLocFile.ReleaseBuffer();
pDlg->m_device->m_sComPort.ClearCommReceiveBuff();
pDlg->m_device->m_sComPort.ClearCommSendBuff();
pDlg->m_exCode = TRUE;
///////////////////////////test111///////////////////////////////////////////////
pDlg->m_nThreadStatus = 0;
//////////////////////////////////////////////////////////////////////////
return TRUE;
}
}
void CProgressDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (m_pThread)
{
DWORD dwRes;
dwRes = WaitForSingleObject(m_pThread->m_hThread,5);
switch (dwRes)
{
case WAIT_ABANDONED:
break;
case WAIT_OBJECT_0:
if (m_RecvOrSend)
{
// if (-1 == m_nThreadStatus)
// {
CString strLogInfo=_T("");
strLogInfo.Format(_T("[%d] nThreadStatus = %d when thread_handle is signaled!"),__LINE__,m_nThreadStatus);
PrintLog(strLogInfo);
/* }*/
}
KillTimer(1);
SendMessage(WM_CLOSE,NULL,NULL);
break;
case WAIT_TIMEOUT:
//zmomde这个时候还没有
if (EN_TRANSFER_FILE_BY_USB == g_iTransFileMode)
{
m_myCopyFile.GetTransferInfo(m_dwTotalRcvSize, m_dwTotalFileSize);
SendMessage(WM_BYTERECV,(WPARAM)m_dwTotalRcvSize,(LPARAM)m_dwTotalFileSize);
}
else if (m_zmodem)
{
SendMessage(WM_BYTERECV,(WPARAM)m_zmodem->GetTransferPosit(),(LPARAM)m_zmodem->GetFileSize());
}
break;
case WAIT_FAILED:
break;
}
}
//SendMessage(WM_FINISH,NULL,NULL);
CDialog::OnTimer(nIDEvent);
}
LRESULT CProgressDlg::ShowProgress(WPARAM f_wparam, LPARAM f_lparam)
{
DOUBLE nByte = 0;
DOUBLE nFileSize = 0;
DOUBLE nPercent = 0;
int nPercentShow = 0;
nByte = (DOUBLE)f_wparam;
nFileSize = (DOUBLE)f_lparam;
if (nFileSize == 0)
{
nPercent = 0;
}
else
{
nPercent = (DOUBLE)(nByte / nFileSize);
//log
CString szLog = _T("");
szLog.Format("%f = %f / %f\r\n", nPercent, nByte, nFileSize);
fwrite(szLog.GetBuffer(0),1 , szLog.GetLength(), m_pFile);
fflush(m_pFile);
//log
}
nPercentShow = nPercent * 100;
CString szProgress = _T("");
szProgress.Format("%d%%",nPercentShow);
this->GetDlgItem(IDC_PERCENT)->SetWindowText(szProgress);
UpdateData(TRUE);
return 0;
}
void CProgressDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
//log
if (m_pFile)
{
//log
CString szLog2 = _T("");
szLog2.Format("\r\nend---------------------------\r\n");
fwrite(szLog2.GetBuffer(0), 1, szLog2.GetLength(), m_pFile);
fflush(m_pFile);
fclose(m_pFile);
}
//log
if (m_zmodem)
{
delete m_zmodem;
m_zmodem = NULL;
}
if (m_pThread)
{
CloseHandle(m_pThread->m_hThread);
m_pThread = NULL;
}
CDialog::OnClose();
}
BOOL CProgressDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
{
return TRUE;
}
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_ESCAPE)
{
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CProgressDlg::PrintLog(CString& strLog)
{
if (NULL == m_pFile)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("无法写入device_log,日志文件点为空"));
else
MessageBoxEx(NULL, _T("Can't write device_log, log File point is NULL"), _T("LOG_ERROR"), MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
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_pFile);
fflush(m_pFile);
}