⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monitor.cpp

📁 MDF监控源码2
💻 CPP
📖 第 1 页 / 共 3 页
字号:

				//TRACE0(strAnwser);
			}
			else
				TRACE0("结果分析错误...");
		
			
			delete m_ptcWeb;
			return(0);
		}else
			return(-1);


	}
	catch(_com_error e)
	{
		strTip.Format("与WEB通信发生错误:%d:%s",e.Error,e.Description);
		theApp.WriteTxtLog(strTip);
	}
	return 0;
}

// 初始化短信组件
//##ModelId=465286A00080
BOOL CMonitor::IniGsmInfo(void)
{
	BOOL bResult = FALSE; 
	m_Gsm = new CGsmComm();
	bResult = m_Gsm->InitGSM(theApp.m_Baseinfo.GSMPort);
	if (!bResult)
	{
		theApp.WriteTxtLog(_T("GSM MODEM起动失败..."));
		theApp.m_Baseinfo.SMSOpen = FALSE;
		theApp.m_Baseinfo.VoiceOpen = FALSE;
		return FALSE;
	}
	bResult = m_Gsm->SetServiceNum(theApp.m_Baseinfo.SMSCenter);

	if(bResult)
	{
		theApp.WriteTxtLog(_T("GSM MODEM起动..."));
		theApp.m_Baseinfo.SMSOpen = TRUE;
	}else
	{
		theApp.WriteTxtLog(_T("GSM MODEM起动失败..."));
		theApp.m_Baseinfo.SMSOpen = FALSE;
		theApp.m_Baseinfo.VoiceOpen = FALSE;
	}
	return bResult;
}


//##ModelId=4652869F0237
LRESULT CMonitor::onSendSMSInfo(WPARAM wParam, LPARAM lParam)
{
	//Send message to mobile phone
	CString strNo,strMsg,strTip;
	strNo  = (LPCTSTR)wParam;
	strMsg = (LPCTSTR)lParam;
	
	if (strNo.Compare("00") != 0 )
	{
		int iResult = m_Gsm->GsmAddMsg(strMsg,strNo,_T("远程短信"),NULL,1);
		if (iResult == 0 )
		{
			//CString strTip;
			strTip = "SM|00";
			m_udpServer[0]->SendTo(strTip,theApp.m_Baseinfo.WebIP,theApp.m_Baseinfo.WebPort);
		}else
		{
			strTip = "SM|FF|GSM BUSY";
			m_udpServer[0]->SendTo(strTip,theApp.m_Baseinfo.WebIP,theApp.m_Baseinfo.WebPort);
		}

	}else
	{
		m_udpServer[0]->SendTo(strMsg,theApp.m_Baseinfo.WebIP,theApp.m_Baseinfo.WebPort);
	}

	return  LRESULT();
}

// 关闭GSMMODEM
//##ModelId=465286A0009D
BOOL CMonitor::ClsoeGSM(void)
{
	try 
	{
		m_Gsm->bExitRead = TRUE;
		m_Gsm->CloseGsm();
		delete m_Gsm;
		return TRUE;
	}
	catch(_com_error e) 
	{
		return FALSE;	
	}
}


//打开音频播放器
//##ModelId=44B6F8850149
LRESULT CMonitor::onSoundOpen(UINT wParam, LONG lParam)
{
	TRACE0("程序:调用 CMDFDlg::OnMM_WOM_OPEN()") ;
	m_pMedia.OnOpen();
	
	return 0;
}

//结束音频播放器
//##ModelId=44B6F885014D
LRESULT CMonitor::onSoundDone(UINT wParam, LONG lParam)
{
	TRACE0("程序:调用 CMDFDlg::OnMM_WOM_DONE()") ;
	m_pMedia.OnClose();
	return 0; 
}

//关闭音频播放器
//##ModelId=44B6F885015A
LRESULT CMonitor::onSoundClose(UINT wParam, LONG lParam)
{
	TRACE0("程序:调用 CMDFDlg::OnMM_WOM_CLOSE()") ;
	m_pMedia.Free() ;

	return 0; //theApp.
}

//##ModelId=44B6F8850168
LRESULT CMonitor::GsmVoice(WPARAM wParam,LPARAM lParam)
{
	m_pMedia.AlarmVoice();	
	return 0;
}

//##ModelId=44B6F885016C
LRESULT CMonitor::GsmVoiceClose(WPARAM wParam,LPARAM lParam)
{
	TRACE0("程序:调用 CMDFDlg::GsmVoiceClose()") ;
	//if (m_pMedia.m_bPlay)
	//{
		m_pMedia.CloseVoice();
	//}
	return 0;	
}
//##ModelId=465286A000AC
void CMonitor::OnCmSound()
{
	// TODO: 在此添加命令处理程序代码
	CString strTip;
	strTip = "33962181";
	m_Gsm->Dail(strTip);

	//m_pMedia.SetVoice(_T("1"),1,m_hWnd);
	//m_pMedia.AlarmVoice();

}


// 数据分析线程函数,队列中有数据时处理数据包,如果无数据时,自动退出线程。
UINT CMonitor::DataAnalyseThd(LPVOID lpWnd)
{
	CMonitor* pMonitor = (CMonitor*)lpWnd;
	CInfoFrame *m_infobody;
	while(pMonitor->m_ListInfo->GetCount() > 0  &&  !pMonitor->m_AskingClose)
	{
		pMonitor->m_thdAnalyseStatus = TRUE;	
		m_infobody = pMonitor->m_ListInfo->GetInfobodyHead();
		pMonitor->DataAnalyse(*m_infobody);
	}
	pMonitor->m_thdAnalyseStatus = FALSE;
	pMonitor->m_AskingClose = FALSE;
	return 0;
}

// 起动数据包分析线程
BOOL CMonitor::StartAnalyseing(void)
{
	if (m_thdAnalyseStatus)
		return(true);
	m_AskingClose =FALSE;
	m_thdAnalyseStatus = FALSE;
	m_pAnalyseThread = AfxBeginThread(DataAnalyseThd,(LPVOID) this);
	return 0;
}

// 停止数据分析线程
BOOL CMonitor::StopAnalyseing(void)
{
	m_thdAnalyseClose = TRUE;
	return 0;
}

// 停止轮训线程
BOOL CMonitor::StopAsking(void)
{
	m_AskingClose = TRUE;
	return 0;
}

// 初始设备状态
int CMonitor::IniEquipmentStatus(int iType)
{
	//初始设备状态
	m_pEQPool->IniMDFArray(m_EquipState); 
	m_pEQPool->IniCircleArray(m_CircleList);
	m_pEQPool->IniCableArray(m_CableList); 
	m_pEQPool->IniPowerDCArray(m_PowerDCList); 
	return 0;
}

// 播放告警声音
int CMonitor::PlayAlarmSound(long lDevid, UCHAR ucTypeNum)
{
	CString strPath;
	char cPath[MAX_PATH];
	int nlen = GetCurrentDirectory(MAX_PATH,cPath);
	//=========================================
	//可以根据设备急告警内容增加多个语音文件
	strPath.Format("%s\\wav\\设备.wav",cPath); 
	
	//strPath = cPath;
	//strPath += "\\wav\\warn.wav";
	m_pMedia.AddFile(strPath); 
	//录制了不同设备的语音后增加各种设备语音
	switch(ucTypeNum )
	{
	case EQU_CODE_MDF:				//MDF智能告警器
		break;	
	case EQU_CODE_CABLE:			//电缆检测单元
		break;
	case EQU_CODE_INDUCTCIRCLE:		//强电入侵监测模块(工频环)
		break;
	case EQU_CODE_ACPOWERCABINET:	//交流电源分配柜
		break;	
	case EQU_CODE_DCPOWERCABINET:	//直流电源分配柜
		break;
	case EQU_CODE_ACPOWERBOX:		//交流电源分配箱
		break;	
	case EQU_CODE_DCPOWERBOX:		//直流电源分配箱
		break;
	case EQU_CODE_AMBIENT:			//环境检测模块
		break;
	}
	//增加设备ID号
	m_pMedia.AddVoice(lDevid);
	strPath.Format("%s\\wav\\发生.wav",cPath); 
	
	m_pMedia.AddFile(strPath);
	strPath.Format("%s\\wav\\告警.wav",cPath);

	m_pMedia.AddFile(strPath);
	strPath.Format("%s\\wav\\WARN.wav",cPath);
	m_pMedia.AddFile(strPath);

	//=========================================

	m_pMedia.StartVoice(this->m_hWnd); 
	return 0;
}

// 送出告警信息到维护人员的手机
int CMonitor::SendAlarmInfoToPhone(long lDevid, CString strInfo)
{
	if (lDevid<=0)
		return(-1);
	if (strInfo.GetLength() == 0 )
		return(-1);
	CString sSql,strTip,strPhone;
	_RecordsetPtr m_pRst;
	sSql.Format("Select * From %s Where monitorEquID = %d","VW_PepolePhone",lDevid); 
	if (m_Gsm->m_bMsgIsOpen)
	{
		m_pRst.CreateInstance(__uuidof(Recordset));
		p_adodb->ReadDB(sSql,m_pRst,strTip);
		while (! m_pRst->adoEOF)
		{
			p_adodb->GetFieldValue("peoplePhone",m_pRst,strPhone ); 
			if (strPhone.GetLength()>0 )
				m_Gsm->SendMsgTo(strPhone,strInfo);
			m_pRst->MoveNext(); 
		}
		m_pRst.Release(); 
	}
	return 0;
}

// 按照设备ID获得设备的当前状态
LPVOID CMonitor::GetDevStateByID(long lDevid, UCHAR ucTypeNum)
{
	LPVOID lp;
	lp = NULL;
	switch(ucTypeNum) 
	{
		case EQU_CODE_MDF:				//MDF智能告警器
			for(int i=0;i<m_EquipState.GetCount();i++ )
			{
				if(((CEquipmentPort)(m_EquipState.GetAt(i))).MonitorEquID == lDevid)
				{
					lp  = &(CEquipmentPort)(m_EquipState.GetAt(i));
					break;
				}
			}
			break;	
		case EQU_CODE_CABLE:			//电缆检测单元
			for(int i=0;i<m_CableList.GetCount();i++ )
			{
				if(((tyCable)(m_CableList.GetAt(i))).MonitorEquID == lDevid)
				{
					lp  = &(tyCable)(m_CableList.GetAt(i));
					break;
				}
			}

			break;
		case EQU_CODE_INDUCTCIRCLE:		//强电入侵监测模块(工频环)
			for(int i=0;i<m_CircleList.GetCount();i++ )
			{
				if(((tyCircle)(m_CircleList.GetAt(i))).MonitorEquID == lDevid)
				{
					lp  = &(tyCircle)(m_CircleList.GetAt(i));
					break;
				}
			}
			break;
		case EQU_CODE_ACPOWERCABINET:	//交流电源分配柜
			break;	
		case EQU_CODE_DCPOWERCABINET:	//直流电源分配柜
			for(int i=0;i<m_PowerDCList.GetCount();i++ )
			{
				if(((tyPowerDC)(m_PowerDCList.GetAt(i))).MonitorEquID == lDevid)
				{
					lp  = &(tyPowerDC)(m_PowerDCList.GetAt(i));
					break;
				}
			}
			break;
		case EQU_CODE_ACPOWERBOX:		//交流电源分配箱

			break;	
		case EQU_CODE_DCPOWERBOX:		//直流电源分配箱
			break;
		case EQU_CODE_AMBIENT:			//环境检测模块
			break;		
	}
	return LPVOID();
}

// 获得硬件设备使用协议版本号
int CMonitor::GetProtocolVer(long lDevid)
{
	return 0;
}

// 获得设备地址码
int CMonitor::GetDeviceAddr(long lDevid)
{
	return 0;
}

// 获取设备制造厂家信息
int CMonitor::GetDeviceMaker(void)
{
	return 0;
}

// 初始设备
int CMonitor::IniDevice(long lDevid)
{
	return 0;
}

// 设置新的地址编码
int CMonitor::SetDeviceAddr(long lDevid, UCHAR ucnewAddr)
{
	return 0;
}

// 获取设备时间
int CMonitor::GetDeviceTime(long lDevid, CString & strTime)
{
	return 0;
}

// 设置设备时间
int CMonitor::SetDeviceTime(long lDevid, CString strTime)
{
	return 0;
}

// 获取告警字符内容
CString CMonitor::GetAlarmString(long lDevid, UCHAR ucTypeNum)
{
	CString strTemp;
	strTemp.AllocSysString(); 
	switch(ucTypeNum )
	{
	case EQU_CODE_MDF:				//MDF智能告警器
		if (m_EquipState.GetCount()>0 )
		{
			for(int i=1;m_EquipState.GetCount();i++ )
			{
				if(((CEquipmentPort)m_EquipState.GetAt(i)).MonitorEquID == lDevid )
				{
					strTemp = ((CEquipmentPort)m_EquipState.GetAt(i)).strComment;
					break;
				}
			}
		}
		break;	
	case EQU_CODE_CABLE:			//电缆检测单元
		if (m_CableList.GetCount()>0 )
		{
			for(int i=1;m_CableList.GetCount();i++ )
			{
				if(((tyCable)m_CableList.GetAt(i)).MonitorEquID == lDevid )
				{
					strTemp = ((tyCable)m_CableList.GetAt(i)).strComment;
					break;
				}
			}
		}

		break;
	case EQU_CODE_INDUCTCIRCLE:		//强电入侵监测模块(工频环)
		if (m_CircleList.GetCount()>0 )
		{
			for(int i=1;m_CircleList.GetCount();i++ )
			{
				if(((tyCircle)m_CircleList.GetAt(i)).MonitorEquID == lDevid )
				{
					strTemp = ((tyCircle)m_CircleList.GetAt(i)).strComment;
					break;
				}
			}
		}

		break;
	case EQU_CODE_ACPOWERCABINET:	//交流电源分配柜
		if (m_PowerACList.GetCount()>0 )
		{
			for(int i=1;m_PowerACList.GetCount();i++ )
			{
				if(((tyPowerAC)m_PowerACList.GetAt(i)).MonitorEquID == lDevid )
				{
					strTemp = ((tyPowerAC)m_PowerACList.GetAt(i)).strComment;
					break;
				}
			}
		}

		break;	
	case EQU_CODE_DCPOWERCABINET:	//直流电源分配柜
		if (m_PowerDCList.GetCount()>0 )
		{
			for(int i=1;m_PowerDCList.GetCount();i++ )
			{
				if(((tyPowerDC)m_PowerDCList.GetAt(i)).MonitorEquID == lDevid )
				{
					strTemp = ((tyPowerDC)m_PowerDCList.GetAt(i)).strComment;
					break;
				}
			}
		}

		break;
	case EQU_CODE_ACPOWERBOX:		//交流电源分配箱
		break;	
	case EQU_CODE_DCPOWERBOX:		//直流电源分配箱
		break;
	case EQU_CODE_AMBIENT:			//环境检测模块
		break;
	}
	

	return strTemp;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -