📄 debugdlg.cpp
字号:
//添加命令入命令队列
for( i=0 ; i < theApp.m_pComm->m_pEQPool->m_EQArray.GetSize() ; i++ )
{
pEQ = &(theApp.m_pComm->m_pEQPool->m_EQArray[i]) ;
if( m_ctrlList.GetItemState(pEQ->nNo,LVIS_STATEIMAGEMASK) == 0x2000)//设备选中
{
ucCmd = GetBoxCmd(m_Cmd.GetCurSel()) ;
//发送数据
if( nType == 1 )//模拟模式
{
if( pEQ->unCommState == 0 )//通讯未连接
{
ucCmd = 0x60 ;
theApp.m_pComm->m_pProtocol->Build(pEQ,ucCmd,strSend) ;
m_Send = strSend ;
}
else if( pEQ->unCommState == 1 )
{
ucCmd = 0x44 ;
m_Send = pEQ->strScanPack ;
}
}
else//测试模式
{
theApp.m_pComm->m_pProtocol->Build(pEQ,ucCmd,strSend) ;
m_Send = strSend ;
}
//出错处理
if( m_Send.IsEmpty() )
{
m_strMsg += "发送数据: 无法生成数据包,数据不能发送! \r\n" ;
SetDlgItemText(IDC_SHOWTEXT,m_strMsg);
continue ;
}
nRet = theApp.m_pComm->SendData(m_Send,pEQ,ucCmd) ;
if( m_strMsg.GetLength() > 8192 )
m_strMsg = "" ;
if( nRet == 1 )
{
m_strMsg += "发送数据: 设备为未知类型:数据不能发送! \r\n" ;
SetDlgItemText(IDC_SHOWTEXT,m_strMsg);
continue ;
}
else if( nRet == 2 )
{
m_strMsg += "发送数据: 通讯 Socket 未建立,数据不能发送! \r\n" ;
SetDlgItemText(IDC_SHOWTEXT,m_strMsg);
continue ;
}
else if( nRet == 3 )
{
m_strMsg += "发送数据: 发送时出现未知异常:数据不能发送!\r\n" ;
SetDlgItemText(IDC_SHOWTEXT,m_strMsg);
continue;
}
m_strMsg += "发送数据:" + m_Send + " 到 地址 " + pEQ->strIDAddr + " 的设备\r\n" ;
SetDlgItemText(IDC_SHOWTEXT,m_strMsg);
//增加发送记录数
m_iSend++ ;
CString temp ;
temp.Format("%d条",m_iSend) ;
//显示发送数据包
SetDlgItemText(IDC_SENDNUM,temp);
SetTestLine() ;
}
}
return 0 ;
}
//##ModelId=44B6F887002E
void CDebugDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
((CButton*)GetDlgItem(IDC_RADIO1))->SetCheck(0) ;
((CButton*)GetDlgItem(IDC_RADIO2))->SetCheck(0) ;
((CButton*)GetDlgItem(IDC_RADIO3))->SetCheck(1) ;
GetDlgItem(IDC_COMMAND)->EnableWindow(FALSE) ;
GetDlgItem(IDC_BNSEND1)->EnableWindow(FALSE) ;
GetDlgItem(IDC_SENDEDIT)->EnableWindow(FALSE) ;
GetDlgItem(IDC_BNSEND2)->EnableWindow(FALSE) ;
}
//##ModelId=44B6F88603BA
void CDebugDlg::InitList()
{
//设备列表视图初始化
sCommEQ* pEQ ;
CString strTemp ;
int i ;
m_ctrlList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES);
//m_ctrlList.SetBkColor(RGB(0x00,0x00,0x00));
//m_ctrlList.SetTextBkColor(RGB(0xec,0xf1,0xfd));
m_ctrlList.InsertColumn(0,"名称",LVCFMT_LEFT,55) ;
m_ctrlList.InsertColumn(1,"地址",LVCFMT_LEFT,45) ;
m_ctrlList.InsertColumn(2,"通讯",LVCFMT_LEFT,45) ;
m_ctrlList.InsertColumn(3,"超时",LVCFMT_LEFT,45) ;
m_ctrlList.InsertColumn(4,"模式",LVCFMT_LEFT,55) ;
m_ctrlList.InsertColumn(5,"状态",LVCFMT_LEFT,50) ;
for( i=0 ; i < theApp.m_pComm->m_pEQPool->m_EQArray.GetSize() ; i++ )
{
pEQ = &( theApp.m_pComm->m_pEQPool->m_EQArray[i] ) ;
//增加一个项目到列表框
m_ctrlList.InsertItem(i,pEQ->strName) ;
m_ctrlList.SetItemText(i,1,pEQ->strIDAddr) ;
SetCommState(i,pEQ->unCommState) ;//显示通讯状态
strTemp.Format("%d",pEQ->nTimeOut) ;
m_ctrlList.SetItemText(i,3,strTemp) ;
if( pEQ->nModel == 1 )
m_ctrlList.SetItemText(i,4,"COM") ;
else
m_ctrlList.SetItemText(i,4,"TCP") ;
SetEQState(i,5,pEQ->unEQState) ;//显示设备状态
}
}
//##ModelId=44B6F886034E
void CDebugDlg::SetCommState(UINT nIndex , UINT nState)
{
CString strTemp ;
switch(nState)
{
case 0 :
strTemp = "断开" ;
break ;
case 1 :
strTemp = "空闲" ;
break ;
case 2 :
strTemp = "通讯" ;
break ;
case 3 :
strTemp = "异常" ;
break ;
default :
strTemp = "未知" ;
break ;
}
m_ctrlList.SetItemText(nIndex,2,strTemp) ;
}
//##ModelId=44B6F8860342
void CDebugDlg::SetEQState(UINT nIndex, UINT nColumn, UINT nState)
{
CString strTemp ;
switch(nState)
{
case 0 :
strTemp = "正常" ;
break ;
case 1:
strTemp = "告警" ;
break ;
case 2:
strTemp = "异常" ;
break ;
case 3 :
strTemp = "故障" ;
break ;
default :
strTemp = "未知" ;
break;
}
m_ctrlList.SetItemText(nIndex,nColumn,strTemp) ;
}
//##ModelId=44B6F886033E
void CDebugDlg::AddTimeOut(UINT nIndex , UINT nColumn , int nAddNum)
{
CString strTemp ;
m_nTimeOut++ ;
strTemp.Format("%d",nAddNum) ;
m_ctrlList.SetItemText(nIndex , nColumn , strTemp ) ;
strTemp.Format("%d条",m_nTimeOut) ;
SetDlgItemText(IDC_TIMEOUT , strTemp) ;
}
//##ModelId=44B6F886033C
UCHAR CDebugDlg::GetBoxCmd(int i)
{
UCHAR ucCmd ;
switch(i)
{
case 0 :
ucCmd = 0x60 ;//初始化监测模块
break ;
case 1 :
ucCmd = 0x44 ;//获取告警状态
break ;
case 2 :
ucCmd = 0x4D ;//获取监测模块时间
break ;
case 3:
ucCmd = 0x4E ;//设定监测模块时间
break ;
case 4 :
ucCmd = 0x4F ;//获取通讯协议版本
break ;
case 5 :
ucCmd = 0x50 ;//获取设备地址
break ;
case 6 :
ucCmd = 0x51 ;//获取设备厂家信息
break ;
case 7:
ucCmd = 0x58 ;
break ;
case 8:
ucCmd = 0xF1 ;//初始化监测模块响应包
break ;
case 9:
ucCmd = 0xF2 ;//监测模块告警响应包
break ;
default:
ucCmd = 0x00 ;//置为错误命令
break ;
}
return ucCmd ;
}
//##ModelId=44B6F8870030
void CDebugDlg::OnGsmcheck()
{
// TODO: Add your control notification handler code here
if(((CButton*)GetDlgItem(IDC_GSMCHECK))->GetCheck())
{
if(theApp.m_pComm->m_pCommPool->m_GSM.InitGSM(theApp.m_pComm->m_pCommPool->m_unGSMPort)==0)
{
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) ;
}
else
ShowMsg("GSM 短信中心启动失败 端口COM2 关闭 ;\r\n\r\n") ;
}
else
{
theApp.m_pComm->m_pCommPool->m_GSM.CloseCom() ;
theApp.m_pComm->m_bIsMsgOpen = FALSE ;
theApp.m_pComm->m_bIsVoiceOpen = FALSE ;
GetDlgItem(IDC_EPNUM)->EnableWindow(FALSE) ;
//GetDlgItem(IDC_EMINDEX)->EnableWindow(FALSE) ;
//GetDlgItem(IDC_CHECKALL)->EnableWindow(FALSE) ;
GetDlgItem(IDC_BCALL)->EnableWindow(FALSE) ;
GetDlgItem(IDC_BSENDMSG)->EnableWindow(FALSE) ;
//GetDlgItem(IDC_BDELMSG)->EnableWindow(FALSE) ;
GetDlgItem(IDC_EMSG)->EnableWindow(FALSE) ;
ShowMsg("\r\nGSM 短信中心关闭 端口COM2 关闭 ;\r\n\r\n") ;
}
}
//发送短信
//##ModelId=44B6F8870032
void CDebugDlg::OnBSendMsg()
{
// TODO: Add your control notification handler code here
int i,nCount,nRet ;
char* pSrc ;
char* pDst ;
SM_PARAM SmParam;
//WCHAR wchar[1024];
CString strSend,strNumber,strSmsc,strATCmd,strUnicode,strTemp,strTip;
GetDlgItemText(IDC_EPNUM,strNumber) ;
GetDlgItemText(IDC_EMSG,strSend) ;
strSmsc = theApp.m_pComm->m_pCommPool->m_GSM.m_strMsgCenter ;
nCount = strSend.GetLength() ;
if(nCount == 0 )
{
AfxMessageBox("请输入消息内容!");
return;
}
pSrc = strSend.GetBuffer(0) ;
BOOL nContinue = FALSE ;
for(i=0 ; nCount > 0 ; i++)
{
memset(&SmParam, 0, sizeof(SM_PARAM));
pDst = SmParam.TP_UD ;
if(nContinue)
{
strcpy(pDst,"<续>") ;
pDst += 4 ;
}
if( nCount > MSG_LEN )
{
nRet = MsgCopy(pSrc,pDst,MSG_LEN) ;
pSrc += nRet ;
}
else
nRet = MsgCopy(pSrc,pDst,nCount) ;
nCount -= nRet ;
if( nCount > 0 )
nContinue = TRUE ;
// 去掉号码前的"+"
if(strSmsc[0] == '+') strSmsc = strSmsc.Mid(1);
if(strNumber[0] == '+') strNumber = strNumber.Mid(1);
// 在号码前加"86"
if(strSmsc.Left(2) != "86") strSmsc = "86" + strSmsc;
if(strNumber.Left(2) != "86") strNumber = "86" + strNumber;
// 填充短消息结构
strcpy(SmParam.SCA, strSmsc.GetBuffer(0));
strcpy(SmParam.TPA, strNumber.GetBuffer(0));
SmParam.TP_PID = 0 ;
SmParam.TP_DCS = 8 ; //GSM_UCS2
theApp.m_pComm->m_pCommPool->m_GSM.GsmSendMessage(&SmParam,strNumber,strNumber,strSend,NULL,MSG_TYPE_EQ) ;
Sleep(200) ;
}
if( i > 1 )
{
strTip.Format("消息内容分为 %d 条发送!",i) ;
AfxMessageBox(strTip) ;
}
}
//##ModelId=44B6F887003E
void CDebugDlg::OnBCall()
{
// TODO: Add your control notification handler code here
static int flag = 0 ;
CString strNumber ;
if( theApp.m_pComm->m_pCommPool->m_GSM.nState == 1 ) //MSG_RUN
{
AfxMessageBox("短信发送中,请等待其完成") ;
return ;
}
if( flag == 0 )
{
GetDlgItemText(IDC_EPNUM,strNumber) ;
flag = 1 ;
if( strNumber.GetLength() < 6 )
return ;
theApp.m_pComm->m_pCommPool->m_GSM.Dail(strNumber) ;
SetDlgItemText(IDC_BCALL,"挂断电话") ;
GetDlgItem(IDC_BSENDMSG)->EnableWindow(FALSE) ;
}
else
{
flag = 0 ;
SetDlgItemText(IDC_BCALL,"拨打电话") ;
theApp.m_pComm->m_pCommPool->m_GSM.HangUp() ;
GetDlgItem(IDC_BSENDMSG)->EnableWindow(TRUE) ;
}
}
//##ModelId=44B6F8870040
LRESULT CDebugDlg::OnMM_WOM_OPEN(UINT wParam, LONG lParam)
{
return theApp.m_pMedia->OnOpen() ;
}
//##ModelId=44B6F887004F
LRESULT CDebugDlg::OnMM_WOM_DONE(UINT wParam, LONG lParam)
{
return theApp.m_pMedia->OnClose() ;
}
//##ModelId=44B6F8870053
LRESULT CDebugDlg::OnMM_WOM_CLOSE(UINT wParam, LONG lParam)
{
theApp.m_pMedia->OnClose() ;
SetDlgItemText(IDC_BVOICE,"开始播放") ;
bVoice = TRUE ;
return(-1);
}
//##ModelId=44B6F8870060
void CDebugDlg::OnVoice()
{
// TODO: Add your control notification handler code here
theApp.m_pMedia->AlarmVoice() ;
/*
if( bVoice )
{
SetDlgItemText(IDC_BVOICE,"停止播放") ;
theApp.m_pMedia->SetVoice("01",33,this->m_hWnd) ;
theApp.m_pMedia->AlarmVoice() ;
bVoice = FALSE ;
}
else
{
SetDlgItemText(IDC_BVOICE,"开始播放") ;
theApp.m_pMedia->CloseVoice() ;
bVoice = TRUE ;
}
*/
}
//##ModelId=44B6F8870062
LRESULT CDebugDlg::GsmVoice(WPARAM wParam,LPARAM lParam)
{
OnVoice() ;
return(-1);
}
//##ModelId=44B6F886039A
BOOL CDebugDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
m_bOpen = FALSE ;
return CDialog::DestroyWindow();
}
//##ModelId=44B6F886032E
int CDebugDlg::AddRecv()
{
CString strTemp ;
if( !m_bOpen )
return -1 ;
m_iRecv++ ;
strTemp.Format("%d条",m_iRecv) ;
SetDlgItemText(IDC_RECVNUM,strTemp) ;
return 0 ;
}
//##ModelId=44B6F8870070
void CDebugDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CAPortDlg PortDlg ;
POSITION pos = m_ctrlList.GetFirstSelectedItemPosition();
if( pos == NULL )
return ;
int nHitItem = m_ctrlList.GetNextSelectedItem(pos);
PortDlg.m_pEQ = &(theApp.m_pComm->m_pEQPool->m_EQArray[nHitItem]) ;
PortDlg.DoModal() ;
*pResult = 0;
}
//##ModelId=44B6F886032D
void CDebugDlg::AddAlarm()
{
CString strTemp ;
m_nAlarm++ ;
strTemp.Format("%d条",m_nAlarm) ;
SetDlgItemText(IDC_ALARM,strTemp) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -