pans
2016-12-15 87e3ee273b2f84081ac45926be9d8e5be3166eaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "exceptionparams.h"
#include "ui_exceptionparams.h"
#include <stdio.h>
 
ExceptionParams::ExceptionParams(QWidget *parent) :
    QWidget(parent),
    m_ui(new Ui::ExceptionParams)
{
    m_ui->setupUi(this);
 
     for(int i = 0; i < MAX_ALARMOUT_V30; i++ ) //NULL
     {
           checkboxAlarmOut[i] = NULL;
     }
 
    connect(m_ui->btnrefresh, SIGNAL(clicked()), this, SLOT(RefreshParams()));
    connect(m_ui->btnsave, SIGNAL(clicked()), this, SLOT(SaveParams()));
    connect(m_ui->comboBoxExceptionType, SIGNAL(currentIndexChanged(int )), this, SLOT(changeType(int )));
    connect(m_ui->checkBoxInvokeAlarmOut, SIGNAL(stateChanged(int )), this, SLOT(changeState(int )));
 
    QStringList strings;
    strings <<"HDD full"<<"HDD error"<<"Network error"<<"IP conflict"<<"Illegal access"<<"Input/Output video standard not match"<<"Video signal abnormality";
    m_ui->comboBoxExceptionType->addItems(strings);
    m_ui->comboBoxExceptionType->setCurrentIndex(0);
}
 
ExceptionParams::~ExceptionParams()
{
    delete m_ui;
}
 
void ExceptionParams::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
 
void ExceptionParams::RefreshParams()
{
    DWORD dwReturned;
    int i;
    memset(&m_struIPAlarmOutCfg, 0, sizeof(m_struIPAlarmOutCfg));
    memset(&m_struDeviceInfo,0,sizeof(m_struDeviceInfo));
    NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_DEVICECFG, 0, &m_struDeviceInfo, sizeof(m_struDeviceInfo), &dwReturned);
    dwAlarmOutNum = m_struDeviceInfo.byAlarmOutPortNum;
    memset(&m_struExceptionInfo,0,sizeof(m_struExceptionInfo));
 
    NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_IPALARMOUTCFG, 0, &m_struIPAlarmOutCfg, sizeof(NET_DVR_IPALARMOUTCFG), &dwReturned);
   if(!NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_EXCEPTIONCFG_V30, 0, &m_struExceptionInfo, sizeof(NET_DVR_EXCEPTION_V30), &dwReturned))
    {
       //QMessageBox::information(this, tr("Error"),tr("NET_DVR_GET_EXCEPTIONCFG_V30 failed"));
       return;
    }
   else
   {
       m_iExceptionType = m_ui->comboBoxExceptionType->currentIndex();
       if(m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].dwHandleType &0x01 == 1)
       {
           m_ui->checkBoxMontiorAlarm->setCheckState(Qt::Checked);
       }
       else
       {
            m_ui->checkBoxMontiorAlarm->setCheckState(Qt::Unchecked);
       }
       if((m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].dwHandleType >> 1) &0x01 == 1)
       {
           m_ui->checkBoxSoundAlarm->setCheckState(Qt::Checked);
       }
       else
       {
           m_ui->checkBoxSoundAlarm->setCheckState(Qt::Unchecked);
       }
       if((m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].dwHandleType >> 2) &0x01 == 1)
       {
           m_ui->checkBoxCenterAlarm->setCheckState(Qt::Checked);
       }
       else
       {
           m_ui->checkBoxCenterAlarm->setCheckState(Qt::Unchecked);
       }
       if((m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].dwHandleType >> 3) &0x01 == 1)
       {
           m_ui->checkBoxInvokeAlarmOut->setCheckState(Qt::Checked);
           char strTemp[100];
            for(i = 0; i < MAX_ALARMOUT_V30; i++ ) //NULL
            {
                if(checkboxAlarmOut[i] != NULL)
                {
                    delete checkboxAlarmOut[i];
                }
                checkboxAlarmOut[i] = NULL;
 
                if (i<(int)dwAlarmOutNum || (i>=MAX_ANALOG_ALARMIN && m_struIPAlarmOutCfg.struIPAlarmOutInfo[i-MAX_ANALOG_ALARMOUT].byIPID > 0))
                {
                     if (i<(int)dwAlarmOutNum)
                     {
                        sprintf(strTemp,"AlarmOut%d",(i+1));
                     }
                     else if (i>=MAX_ANALOG_ALARMOUT)
                     {
                        sprintf(strTemp,"IPAlarmOut%d",(i+1-MAX_ANALOG_ALARMOUT));
                     }
                     checkboxAlarmOut[i] = new QCheckBox(strTemp);
                     m_ui->verticalLayoutAlarmOut->addWidget( checkboxAlarmOut[i]);
                     if(m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].byRelAlarmOut[i] == 1)
                     {
                        checkboxAlarmOut[i]->setCheckState(Qt::Checked);
                     }
                }
            }
       }
       else
       {
           m_ui->checkBoxInvokeAlarmOut->setCheckState(Qt::Unchecked);
       }
    }
}
int ExceptionParams::setUserID(long lUserID)
 {
     if(lUserID >= 0)
     {
         m_lUserID = lUserID;
         return 1;
     }
     else
     {
         return 0;
     }
 }
 
void ExceptionParams::changeType(int index)
{
      RefreshParams();
}
 
void ExceptionParams::SaveParams()
{
    m_iExceptionType = m_ui->comboBoxExceptionType->currentIndex();
 
    m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].dwHandleType = 0;
    m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].dwHandleType |= (m_ui->checkBoxMontiorAlarm->isChecked())<<0;
    m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].dwHandleType |= (m_ui->checkBoxSoundAlarm->isChecked())<<1;
    m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].dwHandleType |= (m_ui->checkBoxCenterAlarm->isChecked())<<2;
    m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].dwHandleType |= (m_ui->checkBoxInvokeAlarmOut->isChecked())<<3;
 
    for(int i=0; i < MAX_ALARMOUT_V30; i++)
    {
        if (i<(int)dwAlarmOutNum || (i>=MAX_ANALOG_ALARMIN && m_struIPAlarmOutCfg.struIPAlarmOutInfo[i-MAX_ANALOG_ALARMOUT].byIPID > 0))
        {
            m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].byRelAlarmOut[i] = checkboxAlarmOut[i]->isChecked();
        }
    }
 
    if(NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_EXCEPTIONCFG_V30, 0, &m_struExceptionInfo, sizeof(NET_DVR_EXCEPTION_V30)))
    {
        QMessageBox::information(this, tr("Succ"),tr("NET_DVR_SET_EXCEPTIONCFG_V30 succ"));
    }
}
 
void ExceptionParams::changeState(int state)
{
    if(state == 0)
    {
        for(int i=0; i < MAX_ALARMOUT_V30; i++)
        {
            if(checkboxAlarmOut[i] != NULL)
            {
                checkboxAlarmOut[i]->setEnabled(FALSE);
            }
        }
    }
    else if(state == 2)
    {
       char strTemp[100];
       for(int i = 0; i < MAX_ALARMOUT_V30; i++ ) //NULL
       {
           if(checkboxAlarmOut[i] != NULL)
           {
               delete checkboxAlarmOut[i];
           }
           checkboxAlarmOut[i] = NULL;
 
           if (i<(int)dwAlarmOutNum || (i>=MAX_ANALOG_ALARMIN && m_struIPAlarmOutCfg.struIPAlarmOutInfo[i-MAX_ANALOG_ALARMOUT].byIPID > 0))
           {
                if (i<(int)dwAlarmOutNum)
                {
                    sprintf(strTemp,"AlarmOut%d",(i+1));
                }
                else if (i>=MAX_ANALOG_ALARMOUT)
                {
                    sprintf(strTemp,"IPAlarmOut%d",(i+1-MAX_ANALOG_ALARMOUT));
                }
                checkboxAlarmOut[i] = new QCheckBox(strTemp);
                m_ui->verticalLayoutAlarmOut->addWidget( checkboxAlarmOut[i]);
                if(m_struExceptionInfo.struExceptionHandleType[m_iExceptionType].byRelAlarmOut[i] == 1)
                {
                    checkboxAlarmOut[i]->setCheckState(Qt::Checked);
                }
           }
       }
    }
}