📄 debugdlg.cpp
字号:
// DebugDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MDF.h"
#include "DebugDlg.h"
#include "ClientSock.h"
#include "APortDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDebugDlg dialog
extern CMDFApp theApp ;
//##ModelId=44B6F886037C
CDebugDlg::CDebugDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDebugDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDebugDlg)
//}}AFX_DATA_INIT
bVoice = FALSE ;
m_Send = _T("");
m_iSend = 0 ;
m_iRecv = 0 ;
m_nTimeOut = 0 ;
m_nFault = 0 ;
m_bOpen = FALSE ;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
//##ModelId=44B6F886039C
void CDebugDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDebugDlg)
DDX_Control(pDX, IDC_LIST, m_ctrlList);
DDX_Control(pDX, IDC_COMMAND, m_Cmd);
DDX_Text(pDX, IDC_SENDEDIT, m_Send);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDebugDlg, CDialog)
//{{AFX_MSG_MAP(CDebugDlg)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BNSEND1, OnBnSend1)
ON_CBN_SELCHANGE(IDC_COMMAND, OnSelchangeCommand)
ON_BN_CLICKED(IDC_BNSEND2, OnBnSend2)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BNCLEAR, OnBnClear)
ON_BN_CLICKED(IDC_CLEARSC, OnClearsc)
ON_BN_CLICKED(IDC_CHECK1, OnCheck)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_GSMCHECK, OnGsmcheck)
ON_BN_CLICKED(IDC_BSENDMSG, OnBSendMsg)
ON_BN_CLICKED(IDC_BCALL, OnBCall)
ON_MESSAGE(MM_WOM_OPEN,OnMM_WOM_OPEN)
ON_MESSAGE(MM_WOM_DONE,OnMM_WOM_DONE)
ON_MESSAGE(MM_WOM_CLOSE,OnMM_WOM_CLOSE)
ON_BN_CLICKED(IDC_BVOICE, OnVoice)
ON_MESSAGE(WM_VOICE, GsmVoice)
ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDebugDlg message handlers
//##ModelId=44B6F88603BB
BOOL CDebugDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CString strTemp ;
CString strSend ;
m_iRecv = 0 ;
m_iSend = 0 ;
m_nAlarm = 0 ;
bVoice = TRUE ;
sCommEQ* pEQ ;
// TODO: Add extra initialization here
((CButton*)GetDlgItem(IDC_RADIO1))->SetCheck(1) ;
((CButton*)GetDlgItem(IDC_RADIO2))->SetCheck(0) ;
((CButton*)GetDlgItem(IDC_RADIO3))->SetCheck(0) ;
m_Cmd.AddString("初始化监测模块 60H") ;
m_Cmd.AddString("获取监测模块告警 44H") ;
m_Cmd.AddString("获取监测模块时间 4DH") ;
m_Cmd.AddString("设置监测模块时间 4EH") ;
m_Cmd.AddString("获取通讯协议版本 4FH") ;
m_Cmd.AddString("获取监测模块地址 50H") ;
m_Cmd.AddString("获取生产厂家信息 51H") ;
m_Cmd.AddString("监测模块复位 58H") ;
m_Cmd.AddString("初始化响应包生成") ;
m_Cmd.AddString("监测模块告警包生成") ;
m_Cmd.SetCurSel(0) ;
if( theApp.m_pComm->m_pEQPool->m_EQArray.GetSize() <= 0 )
{
AfxMessageBox("数据库中无设备数据!请检查是否已录入设备") ;
return FALSE;
}
pEQ = &(theApp.m_pComm->m_pEQPool->m_EQArray[0]) ;
if( theApp.m_pComm->m_pProtocol->Build(pEQ,0x60,strSend) != 0 )
{
AfxMessageBox("通讯协议包创建出错!") ;
return FALSE ;
}
m_Send = strSend ;
SetDlgItemText(IDC_SENDEDIT,m_Send) ;
SetDlgItemText(IDC_ALARM,"0条") ;
GetDlgItem(IDC_SHOWTEXT)->SetWindowText(m_strMsg) ;
SetTestLine() ;
SetDlgItemText(IDC_SENDNUM,"0条") ;
SetDlgItemText(IDC_RECVNUM,"0条") ;
SetDlgItemText(IDC_TIMEOUT,"0条") ;
SetDlgItemText(IDC_FAULT,"0条") ;
SetDlgItemText(IDC_TIMEEDIT,"4000") ;
strTemp.Format("设备数:%d",theApp.m_pComm->m_pEQPool->GetCount()) ;
SetDlgItemText(IDC_EQ,strTemp) ;
strTemp.Format("管理员:%d",theApp.m_pComm->m_pMan->m_sManager.GetCount()) ;
SetDlgItemText(IDC_MAN,strTemp) ;
SetDlgItemText(IDC_EPNUM,"86106024") ;
InitList() ;
m_ctrlList.SetItemState (0,0x2000, LVIS_STATEIMAGEMASK);
if( theApp.m_pComm->m_pCommPool->m_GSM.GetGsmRun() )
{
theApp.m_pComm->m_bIsMsgOpen = TRUE ;
theApp.m_pComm->m_bIsVoiceOpen = TRUE ;
GetDlgItem(IDC_EPNUM)->EnableWindow(TRUE) ;
//GetDlgItem(IDC_EMINDEX)->EnableWindow(TRUE) ;
//GetDlgItem(IDC_CHECKALL)->EnableWindow(TRUE) ;
//GetDlgItem(IDC_BCALL)->EnableWindow(TRUE) ;
GetDlgItem(IDC_BSENDMSG)->EnableWindow(TRUE) ;
//GetDlgItem(IDC_BDELMSG)->EnableWindow(TRUE) ;
GetDlgItem(IDC_EMSG)->EnableWindow(TRUE) ;
}
m_bOpen = TRUE ;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//##ModelId=44B6F88603C9
void CDebugDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
((CButton*)GetDlgItem(IDC_RADIO1))->SetCheck(1) ;
((CButton*)GetDlgItem(IDC_RADIO2))->SetCheck(0) ;
((CButton*)GetDlgItem(IDC_RADIO3))->SetCheck(0) ;
GetDlgItem(IDC_COMMAND)->EnableWindow(TRUE) ;
GetDlgItem(IDC_BNSEND1)->EnableWindow(TRUE) ;
GetDlgItem(IDC_SENDEDIT)->EnableWindow(FALSE) ;
GetDlgItem(IDC_BNSEND2)->EnableWindow(FALSE) ;
}
//##ModelId=44B6F88603CB
void CDebugDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
((CButton*)GetDlgItem(IDC_RADIO1))->SetCheck(0) ;
((CButton*)GetDlgItem(IDC_RADIO2))->SetCheck(1) ;
((CButton*)GetDlgItem(IDC_RADIO3))->SetCheck(0) ;
GetDlgItem(IDC_COMMAND)->EnableWindow(FALSE) ;
GetDlgItem(IDC_BNSEND1)->EnableWindow(FALSE) ;
GetDlgItem(IDC_SENDEDIT)->EnableWindow(TRUE) ;
GetDlgItem(IDC_BNSEND2)->EnableWindow(TRUE) ;
}
//##ModelId=44B6F88603D9
void CDebugDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString strCmdNote,strTip,strTemp ;
sCommEQ* pEQ ;
sCmd f_Cmd ;
CList<sCmd,sCmd> *pCmdList ;
//sCommItem* pItem ;
if( nIDEvent < 2000 )//监测模块超时定时器
{
pEQ = &(theApp.m_pComm->m_pEQPool->m_EQArray[nIDEvent]) ;
pCmdList = (CList<sCmd,sCmd> *)pEQ->pCmdList ;
if( !pCmdList->IsEmpty() )
{
//增加设备通讯超时计数
pEQ->nTimeOut++ ;
if( pEQ->nTimeOut >= CONFIRM_TIME )
{
strTip.Format("异常:%s 发生通讯故障 %d次超时 CDebugDlg::OnTimer",pEQ->strName,CONFIRM_TIME) ;
pEQ->nTimeOut = 0 ;
theApp.DebugShow(strTip) ;
theApp.OutPut(strTip) ;
pEQ->unCommState = 0 ;
}
AddTimeOut(nIDEvent,3,pEQ->nTimeOut) ;
if( !pCmdList->IsEmpty() )
{
f_Cmd = pCmdList->GetHead() ;
strCmdNote = theApp.m_pComm->m_pProtocol->GetCmdNote(pEQ,f_Cmd.ucCmd) ;
theApp.m_pAdoDB->WriteCommRd(f_Cmd.strTime,CRDR_TIMEOUT,CRDT_MODULE,"监测中心",strCmdNote,pEQ->strScanPack,theApp.m_pComm->m_sHostIp.strIp,"响应包超时无返回") ;
theApp.m_pComm->m_pEQPool->SubCommand(pEQ) ; //删除设备通讯命令
}
}
SetCommState(nIDEvent,1) ; //设置通讯为空闲状态
}
if( nIDEvent == ID_DEBUG_TEST )//-测试-
SendData(0) ;
if( nIDEvent == ID_COM_SCAN )
SendData(1) ;
if(nIDEvent == ID_MSG_TIMEOUT)//短信发送超时
{
sSIM f_Sim ;
if( theApp.m_pComm->m_pMsgPool->GetMsg(f_Sim) == 0 )
{
if( f_Sim.nFault >= MSG_TIME )
{
strTip.Format("异常:发送短信到 %s %d次不成功被取消 内容: \r\n%s", f_Sim.strName,MSG_TIME,f_Sim.strSend) ;
theApp.DebugShow(strTip) ;
theApp.Show(strTip) ;
theApp.OutPut(strTip) ;
}
else
{
f_Sim.nFault++ ;//短信发送出错
//将短信放到队列末尾
theApp.m_pComm->m_pMsgPool->DelMsg() ;
theApp.m_pComm->m_pMsgPool->AddSim(f_Sim) ;
strTip.Format("异常:发送短信到 %s 失败 内容: \r\n%s", f_Sim.strName, f_Sim.strSend) ;
theApp.DebugShow(strTemp) ;
theApp.OutPut(strTip) ;
}
}
theApp.ClearTimeOut(nIDEvent) ;
SetEvent( theApp.m_pComm->m_pCommPool->m_GSM.hMsg ) ;
}
if(nIDEvent == ID_VOICE_TIMEOUT)//电话语音超时处理
{
sVoice f_Voice ;
if( theApp.m_pComm->m_pVoicePool->GetVoice(f_Voice) == 0 )
{
if(f_Voice.nFault >= CALL_TIME )//拨打次数
{
strTip.Format("异常:%s 电话号码 %s 取消拨打语音电话 监测模块 %s 地址 %s 端口 %d 的电话语音告警 ", f_Voice.strName, f_Voice.strPhone, f_Voice.strEQName, f_Voice.strEQAddr, f_Voice.nEQPort) ;
theApp.DebugShow(strTip) ;
theApp.Show(strTip) ;
theApp.OutPut(strTip) ;
}
else
{
strTip.Format("异常:%s 电话号码 %s 无法拨通语音电话", f_Voice.strName, f_Voice.strPhone ) ;
theApp.DebugShow(strTip) ;
theApp.OutPut(strTip) ;
f_Voice.nFault++ ;//短信发送出错
//将语音放到队列末尾
theApp.m_pComm->m_pVoicePool->DelVoice() ;
theApp.m_pComm->m_pVoicePool->AddSVoice(f_Voice) ;
}
}
theApp.ClearTimeOut(nIDEvent) ;
SetEvent( theApp.m_pComm->m_pCommPool->m_GSM.hVoice ) ;
}
CDialog::OnTimer(nIDEvent);
}
//##ModelId=44B6F8870000
void CDebugDlg::OnBnSend1()
{
// TODO: Add your control notification handler code here
SendData(0) ;
}
//##ModelId=44B6F8870002
void CDebugDlg::OnSelchangeCommand()
{
// TODO: Add your control notification handler code here
//sCommEQ tempEQ ;
int i,nMax ;
UCHAR ucCmd ;
sCommEQ* pEQ ;
nMax = theApp.m_pComm->m_pEQPool->m_EQArray.GetSize() ;
for( i=0 ; i < nMax ; i++ )
{
pEQ = &(theApp.m_pComm->m_pEQPool->m_EQArray[i]) ;
if( m_ctrlList.GetItemState(pEQ->nNo,LVIS_STATEIMAGEMASK)==0x2000 )
break ;
}
ucCmd = GetBoxCmd(m_Cmd.GetCurSel()) ;
//生成通讯协议包
if( theApp.m_pComm->m_pProtocol->Build(pEQ,ucCmd,m_Send) != 0 )
{
m_Send = "创建通讯数据包出错!" ;
}
SetDlgItemText(IDC_SENDEDIT,m_Send);
}
//##ModelId=44B6F8870004
void CDebugDlg::OnBnSend2()
{
// TODO: Add your control notification handler code here
SendData(0) ;
}
//##ModelId=44B6F886036C
void CDebugDlg::SetTestLine()
{
CEdit* OutPut = (CEdit*)GetDlgItem(IDC_SHOWTEXT) ;
OutPut->LineScroll(OutPut->GetLineCount()) ;
}
//##ModelId=44B6F886035E
void CDebugDlg::ShowMsg(CString strMsg)
{
m_strMsg += strMsg + "\r\n";
if( m_bOpen )
{
GetDlgItem(IDC_SHOWTEXT)->SetWindowText(m_strMsg) ;
SetTestLine() ;
}
}
//##ModelId=44B6F8870010
void CDebugDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
m_strMsg.Empty() ;
}
//##ModelId=44B6F8870012
void CDebugDlg::OnBnClear()
{
// TODO: Add your control notification handler code here
int i,j ;
sCommEQ* pEQ ;
m_iRecv = 0 ;
m_iSend = 0 ;
m_nTimeOut = 0 ;
m_nFault = 0 ;
m_nAlarm = 0 ;
SetDlgItemText(IDC_SENDNUM,"0条");
SetDlgItemText(IDC_RECVNUM,"0条");
SetDlgItemText(IDC_TIMEOUT,"0条");
SetDlgItemText(IDC_FAULT,"0条") ;
SetDlgItemText(IDC_ALARM,"0条") ;
for( i=0 ; i < theApp.m_pComm->m_pEQPool->m_EQArray.GetSize() ; i++ )
{
pEQ = &( theApp.m_pComm->m_pEQPool->m_EQArray[i] ) ;
//增加一个项目到列表框
for( j=0 ; j < 128 ; j++ )
{
pEQ->sPort[j].nANum = 0 ;
}
}
}
//##ModelId=44B6F887001F
void CDebugDlg::OnClearsc()
{
// TODO: Add your control notification handler code here
m_strMsg.Empty() ;
SetDlgItemText(IDC_SHOWTEXT,"");
}
//##ModelId=44B6F8870021
void CDebugDlg::OnCheck()
{
// TODO: Add your control notification handler code here
CString str ;
int nModel ;
int i = ((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck() ;//获取复选框状态
GetDlgItemText(IDC_TIMEEDIT , str ) ;
if( i == 1 )//选中自动发送
{
nModel = ((CButton*)GetDlgItem(IDC_RADIO3))->GetCheck() ;
if(nModel == 1)
{
//串口扫描时间设置
theApp.SetTimeOut(ID_COM_SCAN,atoi(str.GetBuffer(0))) ;
}
else
{
SetTimer(ID_DEBUG_TEST,atoi(str.GetBuffer(0)),NULL) ;
/*循环写入数据库数据,每小时数百万条
CString strTime = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S") ;
while(1)
{
theApp.m_pAdoDB->WriteCommRd(strTime,1,1,"监测中心","测试","??",theApp.m_pComm->m_sHostIp.strIp,"测试") ;
}
*/
}
GetDlgItem(IDC_TIMEEDIT)->EnableWindow(FALSE) ;
GetDlgItem(IDC_RADIO1)->EnableWindow(FALSE) ;
GetDlgItem(IDC_RADIO2)->EnableWindow(FALSE) ;
GetDlgItem(IDC_RADIO3)->EnableWindow(FALSE) ;
}
else if ( i == 0)//取消自动发送
{
nModel = ((CButton*)GetDlgItem(IDC_RADIO3))->GetCheck() ;//取模拟选项
if(nModel == 1)
{
//nNum = ID_COM_SCAN + theApp.m_pComm->m_pCommPool->m_SCom.GetPort() ;
theApp.ClearTimeOut(ID_COM_SCAN) ;
GetDlgItem(IDC_TIMEEDIT)->EnableWindow(TRUE) ;
}
else
{
KillTimer(ID_DEBUG_TEST) ;
GetDlgItem(IDC_TIMEEDIT)->EnableWindow(TRUE) ;
}
GetDlgItem(IDC_TIMEEDIT)->EnableWindow(TRUE) ;
GetDlgItem(IDC_RADIO1)->EnableWindow(TRUE) ;
GetDlgItem(IDC_RADIO2)->EnableWindow(TRUE) ;
GetDlgItem(IDC_RADIO3)->EnableWindow(TRUE) ;
}
}
//##ModelId=44B6F886035C
int CDebugDlg::SendData(int nType)
{
//nType 类型为0 测试 1 模拟
int i,nRet ;
UCHAR ucCmd ;
CString strTime,strSend ;
sCommEQ* pEQ ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -