📄 projectpmudlg.cpp
字号:
// PROJECTPMUDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PROJECTPMU.h"
#include "PROJECTPMUDlg.h"
#include <direct.h>
#include <io.h>
#include <math.h>
#include "IDEDDlg.h"
#include "StationInfoDlg.h"
#include "DBListDlg.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
{
private:
CRect m_rollingrange; //滚动区域的矩形
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()
/////////////////////////////////////////////////////////////////////////////
// CPROJECTPMUDlg dialog
pPFuncCRC16 pFunCRC16;
//车外初始化26
unsigned char m_EDIDInit[26]={
0x55,0xFF,0xFF,0xFF,0xFF,0xFF,0x0D,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x05,
0x00,0x05,0x01,0x90,0x10,0x08,0x08,0xD8,0xC8,0xF6,0x0D};
//
//车外显示车厢号31
unsigned char m_VehicleNumMaster[31]={
0x55,0x01,0xFF,0xFF,0xFF,0xFF,0x0D,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,0x0A,
0x00,0x06,0x01,0x00,0x00,0x00,0x02,0x01,0x00,0x00,0x01,0x01,0x00,0x34,0x6F,
0x0D};
//区间滚动模式29
unsigned char m_IntervalRoll[29]={
0x55,0xFF,0xFF,0xFF,0xFF,0xFF,0x0D,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x08,
0x00,0x08,0x01,0x01,0x04,0x00,0x00,0x00,0x00,0x00,0x04,0x7C,0x69,0x0D};
//车次显示数据包头22个
unsigned char m_ucVecSequenceHead[22]={
0x55,0xFF,0xFF,0xFF,0xFF,0xFF,0x0D,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,
0x00,0x06,0x01,0x01,0x00,0x00,0x04};
CPROJECTPMUDlg::CPROJECTPMUDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPROJECTPMUDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPROJECTPMUDlg)
//}}AFX_DATA_INIT
//自己添加的
m_DBListDlg=new CDBListDlg;
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bSerialPortOpened=FALSE; //初始状态:串口没有打开
m_strPortRXData2="";
m_strChecksum2="";
m_bJin = TRUE;
}
void CPROJECTPMUDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPROJECTPMUDlg)
DDX_Control(pDX, IDC_STATIC_ROLLING, m_rolling);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPROJECTPMUDlg, CDialog)
//{{AFX_MSG_MAP(CPROJECTPMUDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_IDED_Button, OnIDEDButton)
ON_BN_CLICKED(IDC_DB_Button, OnDBButton)
ON_WM_CREATE()
ON_WM_CANCELMODE()
ON_WM_TIMER()
ON_WM_CAPTURECHANGED()
ON_WM_SHOWWINDOW()
ON_CBN_SELCHANGE(IDC_COMBO_CHECI, OnSelchangeComboCheci)
ON_MESSAGE(WM_COMM_RXCHAR, OnComm)
ON_CBN_SELCHANGE(IDC_COMBO_NEXTSTATION, OnSelchangeComboNextstation)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPROJECTPMUDlg message handlers
/*/////////////////////////////////////////////////////////////////////////////
EDSend thread 车外显示线程
/////////////////////////////////////////////////////////////////////////////*/
UINT EDSend_thread(LPVOID p)
{
// EDSend();
CPROJECTPMUDlg *dlg=(CPROJECTPMUDlg*)AfxGetApp()->GetMainWnd();
dlg->EDSend();
return 0;
//线程成功返回
}
/*/////////////////////////////////////////////////////////////////////////////
IDSend thread 车内显示线程
/////////////////////////////////////////////////////////////////////////////*/
UINT IDSend_thread(LPVOID p)
{
// EDSend();
CPROJECTPMUDlg *dlg=(CPROJECTPMUDlg*)AfxGetApp()->GetMainWnd();
dlg->IDSend();
return 0;
//线程成功返回
}
BOOL CPROJECTPMUDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_font2.CreateFont(28, 0,0,0,FW_BOLD, 0,0,0,
DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "黑体");
m_rolling.GetClientRect(&m_rollingrange);
SetTimer(1,15,NULL);
// 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
/*加载CRC动态链接库*/
HINSTANCE hdll=::LoadLibrary ("CRC16.dll");
pFunCRC16=(pPFuncCRC16)::GetProcAddress(hdll,"_CRC16");
m_DBListDlg->Create(IDD_DBList_DIALOG,this);
if(NULL != GetModuleFileName(NULL,mDir_Path,256)) //得到应用程序所在文件夹路径
{
int n=strlen(mDir_Path);
for (int i=n; i>=0; i--)
{
if (mDir_Path[i] == '\\')
{
mDir_Path[i] = '\0';
break;
}
}
strcpy(mMDB_Path,mDir_Path);
strcat(mMDB_Path,"\\PIS.mdb"); // 数据库路径
strcpy(mSetting_Path,mDir_Path);
strcat(mSetting_Path,"\\setting.ini"); // 文件setting.ini路径
}
//判断数据库文件是否存在,不存在就创建-------------
if ( _access(mMDB_Path,0) == 0 )
{
//存在
//MessageBox("yes");
}
else
{ //不存在
MessageBox("数据库不存在");
////使用ADOX::CatalogPtr来创建mdb文件----
// CoInitialize(NULL);
// using namespace ADOX;
CString strConnection,strTable;
ADOX::_CatalogPtr m_pCatalog = NULL;
strTable = mMDB_Path;
strConnection = _T("Provider=Microsoft.JET.OLEDB.4.0;Data source = ")
+ strTable + _T(";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Password=sri;"); //有密码的话加上这句话 Jet OLEDB:Database Password=111;
try
{
m_pCatalog.CreateInstance(__uuidof(ADOX::Catalog));
m_pCatalog->Create(_bstr_t(strConnection ));
}
catch(...)
{
//m_pCatalog->Release();
m_pCatalog = NULL;
CoUninitialize();
MessageBox("无法建立数据库!");
}
//m_pCatalog->Release(); //这个语句出错??
m_pCatalog = NULL;
}
// if (m_adoConnection.IsOpen())
// m_adoConnection.Close();
//int nPort=m_ctrlComboComPort.GetCurSel()+1; //得到串口号,想想为什么要加1
//打开GPS串口默认comm1
if(m_SerialPort.InitPort(this, 2, 9600,'N',8,1,EV_RXFLAG | EV_RXCHAR,512))
{
m_SerialPort.StartMonitoring();
m_bSerialPortOpened=TRUE;
}
else
{
AfxMessageBox("没有发现此串口或被占用");
m_bSerialPortOpened=FALSE;
}
m_Com2.Open(1); //打开串口2 ACU
b_IsChinese = true;
m_nextstation = _T("");
m_iBaoZhanJuLi = 1000;
return TRUE; // return TRUE unless you set the focus to a control
}
void CPROJECTPMUDlg::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 CPROJECTPMUDlg::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
{
CPaintDC dc(this); //device context for painting
CString string;
string ="EMU200 Passenger Information System Manage Center (Ver 2.0)";
CFont m_fontLogo;
m_fontLogo.CreateFont(35, 0, 0, 200, 1500, 400, 300,0,0,0,0,0,0, "Arial");
dc.SetBkMode(TRANSPARENT);
CRect rectText;
GetClientRect(&rectText);
CFont * OldFont = dc.SelectObject(&m_fontLogo);
// draw text in DC
COLORREF OldColor = dc.SetTextColor( ::GetSysColor( COLOR_3DHILIGHT));
dc.DrawText( string, rectText+CPoint(1,1) , DT_SINGLELINE|DT_LEFT|DT_CENTER); //字体在顶部
dc.SetTextColor( ::GetSysColor( COLOR_3DSHADOW));
dc.DrawText( string, rectText, DT_SINGLELINE|DT_LEFT|DT_CENTER); //字体在顶部
// restore old text color
dc.SetTextColor( OldColor);
dc.SelectObject(OldFont);
// CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPROJECTPMUDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CPROJECTPMUDlg::OnIDEDButton()
{
// TODO: Add your control notification handler code here
CIDEDDlg dlg;
dlg.DoModal();
}
void CPROJECTPMUDlg::OnDBButton()
{
// TODO: Add your control notification handler code here
//CDBListDlg dlg;
// dlg.DoModal();
CMima_Dlg dlg;
if (dlg.DoModal() == IDOK)
//MessageBox("s");
m_DBListDlg->ShowWindow(SW_SHOW);
}
int CPROJECTPMUDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
// this->ShowWindow(SW_SHOWMAXIMIZED);
return 0;
}
void CPROJECTPMUDlg::OnCancelMode()
{
CDialog::OnCancelMode();
// TODO: Add your message handler code here
}
#define CR 0X0D //回车
#define LF 0X0A //换行
/*##########################################################################
//$GPRMC,065330.00,A,3607.72956,N,12020.51178,E,1.435,217.20,200707,,,A*6C
GPS串口接收消息事件
########################################################################*/
LONG CPROJECTPMUDlg::OnComm(WPARAM ch, LPARAM port)
{
// AfxMessageBox(ch);
// UpdateData(FALSE); //将接收到的字符显示在接收编辑框中
static char checksum=0;
static char c1,c2; //用于计算半Byte校验
static int flag; //用于接收阶段标记
m_strPortRXData2 += (char)ch;
// AfxMessageBox(m_strPortRXData2);
switch(ch)
{
case '$':
checksum=0; //开始计算CheckSum
flag=0;
break;
case '*': //有效数据结束,可以$和*之间数据的半Byte校验值了
flag=2;
c2=checksum & 0x0f; c1=((checksum >> 4) & 0x0f);
if (c1 < 10) c1+= '0'; else c1 += 'A' - 10;
if (c2 < 10) c2+= '0'; else c2 += 'A' - 10;
break;
case CR: //这句必须加上,否则会出错的
break;
case LF: //数据包的最后一个字符
m_strPortRXData2.Empty();
break;
default:
if(flag>0) //注意:只有在接收到'*'后,flag才大于0
{
m_strChecksum2 += ch;
if(flag==1)
{
CString strCheck="";
CString gpr = "GPRMC";
strCheck.Format("%c%c",c1,c2);
if(strCheck!=m_strChecksum2) //校验计算不正确,说明接收数据出错
{
AfxMessageBox(strCheck);
AfxMessageBox(m_strChecksum2);
m_strPortRXData2.Empty();
}
else //校验计算正确则处理数据
{
CString strSwitchSetData;
char comma = ',';
char star = '*';
int commaa,commab;
strSwitchSetData = m_strPortRXData2.Mid(1,5);
if(!strSwitchSetData.Collate((LPCTSTR)gpr))
{
commaa = m_strPortRXData2.Find(comma,0);
commab = m_strPortRXData2.Find(comma,commaa+1);
/* m_sa = m_strPortRXData2.Mid(commaa+1,commab-commaa-1);
//时间
CString time = m_strPortRXData2.Mid(commaa+1,commab-commaa-1);
//AfxMessageBox(time);
CString hour = time.Mid(0,2);
//AfxMessageBox(hour);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -