📄 newlmsdlg.cpp
字号:
// NewLmsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NewLms.h"
#include "NewLmsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewLmsDlg dialog
CNewLmsDlg::CNewLmsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNewLmsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNewLmsDlg)
m_RecvData = _T("");
m_FilePath = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CNewLmsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNewLmsDlg)
DDX_Control(pDX, IDC_SaveEa, m_SaveEa);
DDX_Control(pDX, IDC_RecvEn, m_RecvEn);
DDX_Control(pDX, IDC_COMBCMD, m_CombCmd);
DDX_Text(pDX, IDC_RCVDATA, m_RecvData);
DDX_Text(pDX, IDC_EDIT2, m_FilePath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNewLmsDlg, CDialog)
//{{AFX_MSG_MAP(CNewLmsDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_COM1, OnCom1)
ON_BN_CLICKED(IDC_COM2, OnCom2)
ON_BN_CLICKED(IDC_COM3, OnCom3)
ON_CBN_SELCHANGE(IDC_COMBCMD, OnSelchangeCombcmd)
ON_BN_CLICKED(IDC_SNDCMD, OnSndcmd)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_BN_CLICKED(IDC_RecvEn, OnRecvEn)
ON_BN_CLICKED(IDC_SAVECMD, OnSavecmd)
ON_BN_CLICKED(IDC_CANCEL, OnCancel)
ON_BN_CLICKED(IDC_SaveEa, OnSaveEa)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_COMM_RXCHAR, OnCommunication)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewLmsDlg message handlers
BOOL CNewLmsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_GPS_RECV_EA=FALSE;
m_Save_Checked=FALSE;
m_GPS_PORT=1;
m_File_Save_EA=FALSE;
m_Continue_Select=FALSE;
m_Continue_Send=FALSE;
m_SerialGPS[0].InitPort(this,1,9600);
m_SerialGPS[0].StartMonitoring();
m_SerialGPS[1].InitPort(this,2,9600);
m_SerialGPS[1].StartMonitoring();
m_SerialGPS[2].InitPort(this,3,460800);
m_SerialGPS[2].StartMonitoring();
return TRUE; // return TRUE unless you set the focus to a control
}
void CNewLmsDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CNewLmsDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CNewLmsDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CNewLmsDlg::OnCancel()
{
// TODO: Add your control notification handler code here
for(int i=0;i<3;i++)m_SerialGPS[i].ClosePort();
if(m_File_Save.Open(m_FilePath, CFile::modeCreate | CFile::modeWrite ))m_File_Save.Close();
CDialog::OnCancel();
}
void CNewLmsDlg::OnCom1()
{
// TODO: Add your control notification handler code here
m_GPS_PORT=1;
}
void CNewLmsDlg::OnCom2()
{
// TODO: Add your control notification handler code here
m_GPS_PORT=2;
}
void CNewLmsDlg::OnCom3()
{
// TODO: Add your control notification handler code here
m_GPS_PORT=3;
}
void CNewLmsDlg::OnSelchangeCombcmd()
{
// TODO: Add your control notification handler code here
int index=m_CombCmd.GetCurSel();
switch(index)
{
case 0:
m_SendOut.Pos[0]=0x02;
m_SendOut.Pos[1]=0x00;
m_SendOut.Pos[2]=0x02;
m_SendOut.Pos[3]=0x00;
m_SendOut.Pos[4]=0x20;
m_SendOut.Pos[5]=0x41;
m_SendOut.Pos[6]=0x51;
m_SendOut.Pos[7]=0x08;
m_SendOut.Lengh=8;
break;
case 1:
m_SendOut.Pos[0]=0x02;
m_SendOut.Pos[1]=0x00;
m_SendOut.Pos[2]=0x02;
m_SendOut.Pos[3]=0x00;
m_SendOut.Pos[4]=0x20;
m_SendOut.Pos[5]=0x40;
m_SendOut.Pos[6]=0x50;
m_SendOut.Pos[7]=0x08;
m_SendOut.Lengh=8;
break;
case 2:
m_SendOut.Pos[0]=0x02;
m_SendOut.Pos[1]=0x00;
m_SendOut.Pos[2]=0x02;
m_SendOut.Pos[3]=0x00;
m_SendOut.Pos[4]=0x20;
m_SendOut.Pos[5]=0x48;
m_SendOut.Pos[6]=0x58;
m_SendOut.Pos[7]=0x08;
m_SendOut.Lengh=8;
break;
case 3:
m_SendOut.Pos[0]=0x02;
m_SendOut.Pos[1]=0x00;
m_SendOut.Pos[2]=0x02;
m_SendOut.Pos[3]=0x00;
m_SendOut.Pos[4]=0x20;
m_SendOut.Pos[5]=0x42;
m_SendOut.Pos[6]=0x52;
m_SendOut.Pos[7]=0x08;
m_SendOut.Lengh=8;
break;
case 4:
m_SendOut.Pos[0]=0x02;
m_SendOut.Pos[1]=0x00;
m_SendOut.Pos[2]=0x02;
m_SendOut.Pos[3]=0x00;
m_SendOut.Pos[4]=0x30;
m_SendOut.Pos[5]=0x01;
m_SendOut.Pos[6]=0x31;
m_SendOut.Pos[7]=0x18;
m_SendOut.Lengh=8;
break;
case 5:
m_SendOut.Pos[0]=0x02;
m_SendOut.Pos[1]=0x00;
m_SendOut.Pos[2]=0x02;
m_SendOut.Pos[3]=0x00;
m_SendOut.Pos[4]=0x20;
m_SendOut.Pos[5]=0x24;
m_SendOut.Pos[6]=0x34;
m_SendOut.Pos[7]=0x08;
m_SendOut.Lengh=8;
m_Continue_Select=TRUE;
break;
case 6:
m_SendOut.Pos[0]=0x02;
m_SendOut.Pos[1]=0x00;
m_SendOut.Pos[2]=0x02;
m_SendOut.Pos[3]=0x00;
m_SendOut.Pos[4]=0x20;
m_SendOut.Pos[5]=0x25;
m_SendOut.Pos[6]=0x35;
m_SendOut.Pos[7]=0x08;
m_SendOut.Lengh=8;
m_Continue_Select=FALSE;
break;
case 7:
m_SendOut.Pos[0]=0x02;
m_SendOut.Pos[1]=0x00;
m_SendOut.Pos[2]=0x01;
m_SendOut.Pos[3]=0x00;
m_SendOut.Pos[4]=0x31;
m_SendOut.Pos[5]=0x15;
m_SendOut.Pos[6]=0x12;
m_SendOut.Lengh=7;
break;
}
}
void CNewLmsDlg::OnSndcmd()
{
// TODO: Add your control notification handler code here
if(m_Continue_Select)
{
m_Continue_Send=TRUE;
}
else
{
m_Continue_Send=FALSE;
}
m_SerialGPS[m_GPS_PORT-1].WriteToPort((LPCTSTR)m_SendOut.Pos,m_SendOut.Lengh);
}
void CNewLmsDlg::OnClear()
{
// TODO: Add your control notification handler code here
LastLen=0;
m_RecvData=_T("");
UpdateData(FALSE);
}
void CNewLmsDlg::OnRecvEn()
{
// TODO: Add your control notification handler code here
if(m_RecvEn.GetCheck())
{
//m_SerialGPS.StartMonitoring();
m_GPS_RECV_EA=TRUE;
}
else
{
m_GPS_RECV_EA=FALSE;
}
}
void CNewLmsDlg::OnCommunication(WPARAM ch, LPARAM port)
{
if(m_GPS_RECV_EA && port==m_GPS_PORT)
{
CString StrTemp;
StrTemp.Format("%02X ",ch);
len=m_RecvData.GetLength();
m_RecvData+=StrTemp;
//m_SaveData=m_RecvData;
if(len-LastLen>=2)
{
UpdateData(FALSE);
LastLen=len;
if(!m_Continue_Send)
{
if(m_Save_Checked && m_File_Save_EA)
{
pThread=AfxBeginThread(ThreadFunc,this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
ASSERT(pThread);
pThread->m_bAutoDelete=FALSE;
pThread->ResumeThread();
WaitForSingleObject(pThread->m_hThread,INFINITE);
delete pThread;
}
}
}
if(len>=8784)
{
if(m_Continue_Send)
{
if(m_Save_Checked && m_File_Save_EA)
{
pThread=AfxBeginThread(ThreadFunc,this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
ASSERT(pThread);
pThread->m_bAutoDelete=FALSE;
pThread->ResumeThread();
WaitForSingleObject(pThread->m_hThread,INFINITE);
delete pThread;
}
}
m_RecvData="";
LastLen=0;
}
}
}
void CNewLmsDlg::OnSavecmd()
{
// TODO: Add your control notification handler code here
char filters[] = "*.txt | *.txt|";
CFileDialog oFileDialog(FALSE, NULL, "*.txt", NULL, filters, NULL);
if (oFileDialog.DoModal() == IDOK)
{
CString csPath;
csPath = oFileDialog.GetPathName();
CFile oFile;
m_FilePath=csPath;
UpdateData(false);
}
m_File_Save.Open(m_FilePath, CFile::modeCreate | CFile::modeWrite );
m_File_Save_EA=TRUE;
}
UINT CNewLmsDlg::ThreadFunc(LPVOID param) //线程处理程序
{
CNewLmsDlg * pTaskMain = (CNewLmsDlg *) param;
pTaskMain->m_File_Save.Write( pTaskMain->m_RecvData , pTaskMain->len);
pTaskMain->m_RecvData="";
return TRUE;
}
void CNewLmsDlg::OnSaveEa()
{
// TODO: Add your control notification handler code here
if(m_SaveEa.GetCheck())
{
//m_SerialGPS.StartMonitoring();
m_Save_Checked=TRUE;
}
else
{
m_Save_Checked=FALSE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -