// CDialogStatusShow.cpp: 实现文件 // #include "pch.h" #include "MTerm1.h" #include "DialogStatusShow.h" #include "afxdialogex.h" //#include "KLink.h" #include "MTerm1Doc.h" // CDialogStatusShow 对话框 IMPLEMENT_DYNAMIC(CDialogStatusShow, CDialogEx) CDialogStatusShow::CDialogStatusShow(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_DIALOG_STATUS_SHOW, pParent) { } CDialogStatusShow::~CDialogStatusShow() { } void CDialogStatusShow::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST_STATUS1, m_liststatus1); } BEGIN_MESSAGE_MAP(CDialogStatusShow, CDialogEx) ON_WM_CLOSE() ON_WM_TIMER() ON_BN_CLICKED(IDC_BUTTON_CLEAR_STATISTICS, &CDialogStatusShow::OnBnClickedButtonClearStatistics) END_MESSAGE_MAP() // CDialogStatusShow 消息处理程序 BOOL CDialogStatusShow::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 ShowParams(); // m_liststatus1.SetExtendedStyle(); SetTimer(1, 100, NULL); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } int CDialogStatusShow::ShowParams() { // TODO: 在此处添加实现代码. m_liststatus1.SetExtendedStyle( LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE | LVS_EX_LABELTIP); m_liststatus1.DeleteAllItems(); while (m_liststatus1.DeleteColumn(0)); m_liststatus1.InsertColumn(0, _T("NO"), LVCFMT_LEFT, 96, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(1, _T("子机0"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(2, _T("子机1"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(3, _T("子机2"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(4, _T("子机3"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(5, _T("子机4"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(6, _T("子机5"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(7, _T("子机6"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(8, _T("子机7"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(9, _T("子机8"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(10, _T("子机9"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(11, _T("子机10"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(12, _T("子机11"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(13, _T("子机12"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(14, _T("子机13"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertColumn(15, _T("子机14"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER m_liststatus1.InsertItem(0, _T("状态")); m_liststatus1.InsertItem(1, _T("发送包计数")); m_liststatus1.InsertItem(2, _T("接收包计数")); m_liststatus1.InsertItem(3, _T("发送时间(uS)")); m_liststatus1.InsertItem(4, _T("丢包计数")); m_liststatus1.InsertItem(5, _T("连续丢包")); m_liststatus1.InsertItem(6, _T("最大连续")); m_liststatus1.InsertItem(7, _T("非包计数")); m_liststatus1.InsertItem(8, _T("包长错误")); m_liststatus1.InsertItem(9, _T("校验错误")); m_liststatus1.InsertItem(10, _T("超时错误")); m_liststatus1.InsertItem(11, _T("返回延迟(mS)")); m_liststatus1.InsertItem(12, _T("最大延迟(mS)")); m_liststatus1.InsertItem(13, _T("循环时间(mS)")); m_liststatus1.InsertItem(14, _T("子机接收")); m_liststatus1.InsertItem(15, _T("子机发送")); m_liststatus1.InsertItem(16, _T("子机非包")); m_liststatus1.InsertItem(17, _T("子机非ID")); m_liststatus1.InsertItem(18, _T("子机包长")); m_liststatus1.InsertItem(19, _T("子机校验")); m_liststatus1.InsertItem(20, _T("子机超时")); m_liststatus1.InsertItem(21, _T("子机超时")); m_liststatus1.InsertItem(22, _T("子机超时")); m_liststatus1.InsertItem(23, _T("子机超时")); m_liststatus1.InsertItem(24, _T("子机超时")); m_liststatus1.InsertItem(25, _T("子机超时")); m_liststatus1.InsertItem(26, _T("子机超时")); m_liststatus1.InsertItem(27, _T("子机超时")); return 0; } int CDialogStatusShow::GetParams() { // TODO: 在此处添加实现代码. return 0; } int CDialogStatusShow::DoMonitor() { // TODO: 在此处添加实现代码. return 0; } int CDialogStatusShow::UpdateDisplay() { CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame(); CView *pV = (CView*)pChild->GetActiveView(); CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument()); // TODO: 在此处添加实现代码. CString s1, s2; int nOffset = 0; KLink1::pChnStat pchnstat1; unsigned int nSendPackets; int nChilds = 14; //子机1 //子机2 for (int i = 0; i <= nChilds; i++) { nOffset = 0 + sizeof(KLink1::stChnStat) * i; pchnstat1 = (KLink1::pChnStat)&(pDoc->KBDB[nOffset + 0]); nSendPackets = pchnstat1->SendPackets; if (nSendPackets == 0) nSendPackets = 1; s1.Format(_T("%08X"), pchnstat1->Stat); m_liststatus1.SetItemText(0, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->SendPackets); m_liststatus1.SetItemText(1, 1 + i, s1); s1.Format(_T("%u (%.3f%%)"), pchnstat1->RecvPackets, pchnstat1->RecvPackets *100.0 / nSendPackets); m_liststatus1.SetItemText(2, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->LastSentTimeuS); m_liststatus1.SetItemText(3, 1 + i, s1); s1.Format(_T("%u (%.3f%%)"), pchnstat1->LostPackets, pchnstat1->LostPackets *100.0 / nSendPackets); m_liststatus1.SetItemText(4, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->CtnLstPkts); m_liststatus1.SetItemText(5, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->MaxCtnLstPkts); m_liststatus1.SetItemText(6, 1 + i, s1); s1.Format(_T("%u (%.3f%%)"), pchnstat1->NotPkgErr, pchnstat1->NotPkgErr * 100.0 / nSendPackets); m_liststatus1.SetItemText(7, 1 + i, s1); //s1.Format(_T("%u (%.2f%%)"), pchnstat1->NoEndErr, pchnstat1->NoEndErr * 100.0 / nSendPackets); //m_liststatus1.SetItemText(8, 1 + i, s1); s1.Format(_T("%u (%.3f%%)"), pchnstat1->PkgLenErr, pchnstat1->PkgLenErr * 100.0 / nSendPackets); m_liststatus1.SetItemText(8, 1 + i, s1); s1.Format(_T("%u (%.3f%%)"), pchnstat1->BCCErr, pchnstat1->BCCErr * 100.0 / nSendPackets); m_liststatus1.SetItemText(9, 1 + i, s1); s1.Format(_T("%u (%.3f%%)"), pchnstat1->TimeOutErr, pchnstat1->TimeOutErr * 100.0 / nSendPackets); m_liststatus1.SetItemText(10, 1 + i, s1); s1.Format(_T("%.1f"), pchnstat1->Delay/10.0f); m_liststatus1.SetItemText(11, 1 + i, s1); s1.Format(_T("%.1f"), pchnstat1->MaxDelay/10.0f); m_liststatus1.SetItemText(12, 1 + i, s1); s1.Format(_T("%.1f"), pchnstat1->SendTimeInterval/10.0f); m_liststatus1.SetItemText(13, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->ClientRecvPkts); m_liststatus1.SetItemText(14, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->ClientSendPkts); m_liststatus1.SetItemText(15, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->ClientNotPktErr); m_liststatus1.SetItemText(16, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->ClientMisIdPkts); m_liststatus1.SetItemText(17, 1 + i, s1); // s1.Format(_T("%u"), pchnstat1->ClientNoEndErr); // m_liststatus1.SetItemText(18, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->ClientPkgLenErr); m_liststatus1.SetItemText(18, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->ClientBccErr); m_liststatus1.SetItemText(19, 1 + i, s1); s1.Format(_T("%u"), pchnstat1->ClientTimeOutErr); m_liststatus1.SetItemText(20, 1 + i, s1); } return 0; } void CDialogStatusShow::OnTimer(UINT_PTR nIDEvent) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (nIDEvent ==0) { } else if (nIDEvent == 1) { DoMonitor(); UpdateDisplay(); }else {} CDialogEx::OnTimer(nIDEvent); } void CDialogStatusShow::OnClose() { // TODO: 在此添加消息处理程序代码和/或调用默认值 KillTimer(1); GetParams(); CDialogEx::OnClose(); } void CDialogStatusShow::OnBnClickedButtonClearStatistics() { // TODO: 在此添加控件通知处理程序代码 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame(); CView *pV = (CView*)pChild->GetActiveView(); CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument()); theApp.MyKLink1.ClearStatistics(1, 0); }