📄 ~dlgalarm.~cpp
字号:
// DlgAlarm.cpp : implementation file
//
#include "stdafx.h"
#include "..\dvrmanager.h"
#include "DlgAlarm.h"
#include "../utils/custom_msgs.h"
#include "../utils/common.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgAlarm dialog
#define TYPE(x) ((x)/16)
#define CHANNEL(x) ((x)%16)
#define CHECK_VISIBLE if(!is_visible(this)) return
CDlgAlarm::CDlgAlarm(CWnd* pParent /* = NULL */)
: baseclass(CDlgAlarm::IDD, pParent), hidden(false), alarming(false)
{
//{{AFX_DATA_INIT(CDlgAlarm)
m_remote = 0;
//}}AFX_DATA_INIT
}
#define DDX(x) DDX_Control(pDX, ID_##x, m_led[TYPE(x-1)][CHANNEL(x-1)])
void CDlgAlarm::DoDataExchange(CDataExchange* pDX)
{
baseclass::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgAlarm)
DDX(1); DDX(2); DDX(3); DDX(4);
DDX(5); DDX(6); DDX(7); DDX(8);
DDX(9); DDX(10);DDX(11);DDX(12);
DDX(13);DDX(14);DDX(15);DDX(16);
DDX(17);DDX(18);DDX(19);DDX(20);
DDX(21);DDX(22);DDX(23);DDX(24);
DDX(25);DDX(26);DDX(27);DDX(28);
DDX(29);DDX(30);DDX(31);DDX(32);
DDX(33);DDX(34);DDX(35);DDX(36);
DDX(37);DDX(38);DDX(39);DDX(40);
DDX(41);DDX(42);DDX(43);DDX(44);
DDX(45);DDX(46);DDX(47);DDX(48);
DDX_Control(pDX, IDCB_REMOTE, m_cbremote);
DDX_CBIndex(pDX, IDCB_REMOTE, m_remote);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgAlarm, baseclass)
//{{AFX_MSG_MAP(CDlgAlarm)
ON_WM_TIMER()
ON_WM_SYSCOMMAND()
ON_CBN_SELCHANGE(IDCB_REMOTE, OnSelChangeRemote)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgAlarm message handlers
void CDlgAlarm::OnCancel()
{
OnOK();
}
void CDlgAlarm::OnOK()
{
hide_alarm(true);
hide();
update_status();
AfxGetMainWnd()->SendMessage(WM_HIDE_ALARM, TRUE);
}
BOOL CDlgAlarm::OnInitDialog()
{
baseclass::OnInitDialog();
// alarm(VIDEO_LOST, 16);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
#define MAKEDWORD(hi,low) (((USHORT)hi<<16) | ( (USHORT)low &0xffff) )
#define HSHORT(dw) ((SHORT)(dw>>16))
#define LSHORT(dw) ((SHORT)(dw&0xffff))
#define IS_BIT_SET(x, y) (((x) & (1<<(y))) == (1<<(y)))
/*
* masks: 位标识, 从低位到高位, 若某位置位则该路有警报
*/
void CDlgAlarm::add_alarm(ULONG _ip, USHORT _port, LPCTSTR alias, const DWORD* masks)
{
/*
* 检查该主机是否已在列表中
* 是则更新
*/
for( int i=0; i<al.size(); i++ )
{
alarm_data& ref = al[i];
if( ref.ip == _ip &&
ref.port == _port )
{
ref.set_alarm(masks);
break;
}
}
// 否则添加
if( i == al.size() )
{
al.push_back(alarm_data(_ip, _port, alias, masks));
}
// 决定是否弹出本对话框
if( !hidden )
if( !is_visible(this) )
{
if( alarms_present() )
show(AfxGetMainWnd());
}
// 更新状态
update_status();
}
void CDlgAlarm::remove_alarm(ULONG _ip, USHORT _port)
{
for( int i=0; i<al.size(); i++ )
{
alarm_data& ref = al[i];
if( ref.ip == _ip &&
ref.port == _port )
{
al.erase(al.begin()+i);
}
}
update_status();
}
void CDlgAlarm::restore_status()
{
int i=0;
if( is_visible(this) )
for( i=0; i<tl.size(); i++ )
{
KillTimer(tl[i]);
}
tl.clear();
alarming = false;
CHECK_VISIBLE;
for( i=0; i<LEDS; i++ )
{
CLed& led = m_led[TYPE(i)][CHANNEL(i)];
if(led.GetLedColor() != CLed::LED_COLOR_GREEN)
led.SetLed(CLed::LED_COLOR_GREEN, CLed::LED_OFF, CLed::LED_ROUND);
}
}
void CDlgAlarm::set_timer(UINT timer)
{
CHECK_VISIBLE;
tl.push_back(timer);
SetTimer(timer, 500, NULL);
}
void CDlgAlarm::check_alarms(const DWORD* alarms)
{
for( int type=0; type<3; type++ )
{
for( int i=0; i<32; i++ )
{
if( IS_BIT_SET(alarms[type], i) )
{
UINT timer = MAKEDWORD(type, i);
set_timer(timer);
alarming = true;
}
}
}
}
void CDlgAlarm::update_combo()
{
/*
* 刷新主机列表
*/
CString x;
m_cbremote.GetWindowText(x);
m_cbremote.ResetContent();
for( int i=0; i<al.size(); i++ )
{
alarm_data& ref = al[i];
int idx = m_cbremote.AddString(ref.alias);
m_cbremote.SetItemData(idx, ref.ip);
}
if( m_cbremote.GetCount() != 0 )
{
int idx = m_cbremote.FindString(-1, x);
if( idx != -1 )
{
m_remote = idx;
}
m_remote = m_cbremote.GetCount()-1;
UpdateData(FALSE);
}
}
void CDlgAlarm::update_status()
{
CHECK_VISIBLE;
restore_status();
// update_combo();
/*
* 刷新警报列表
*/
ULONG ip = m_cbremote.GetItemData(m_remote);
for( int i=0; i<al.size(); i++ )
{
alarm_data& x = al[i];
if( x.ip == ip )
{
check_alarms(x.alarms);
break;
}
}
if( alarms_present() )
ds.Play(0, TRUE);
else
ds.Stop();
}
void CDlgAlarm::clear_alarm()
{
if( al.empty() )
return;
al.clear();
restore_status();
update_status();
}
bool CDlgAlarm::alarms_present() const
{
for( int i=0; i<al.size(); i++ )
{
const alarm_data& ref = al[i];
for( int j=0; j<3; j++ )
{
if( ref.alarms[j] )
return true;
}
}
return false;
}
void CDlgAlarm::OnTimer(UINT nIDEvent)
{
CHECK_VISIBLE;
if( HSHORT(nIDEvent) >= 3 ||
LSHORT(nIDEvent) >= 16 )
return;
CLed& led = m_led[HSHORT(nIDEvent)][LSHORT(nIDEvent)];
if(led.GetLedMode() == CLed::LED_ON)
led.SetLed(CLed::LED_COLOR_RED, CLed::LED_OFF, CLed::LED_ROUND);
else
led.SetLed(CLed::LED_COLOR_RED, CLed::LED_ON, CLed::LED_ROUND);
baseclass::OnTimer(nIDEvent);
}
void CDlgAlarm::OnSysCommand(UINT nID, LPARAM lParam)
{
if( nID == SC_CLOSE )
{
OnOK();
return;
}
baseclass::OnSysCommand(nID, lParam);
}
void CDlgAlarm::show(CWnd* parent /* = NULL */)
{
baseclass::show(parent);
if( !ds.IsValid() )
ds.Create(IDR_ALARM, this);
update_combo();
update_status();
}
void CDlgAlarm::hide()
{
ds.Stop();
baseclass::hide();
}
void CDlgAlarm::hide_alarm(bool h/* =true */)
{
hidden = h;
}
void CDlgAlarm::OnSelChangeRemote()
{
UpdateData();
update_status();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -