#include "cipparams.h" #include "publicfuc.h" #include CIPParams::CIPParams(QWidget *parent) : QWidget(parent) { ui.setupUi(this); m_lUserID = -1; m_iIPParamIndex = -1; m_iCurrentRow = -1; ui.hLayout->addWidget(ui.widgetCamora); ui.widgetCamora->hide(); ui.btnSave->hide(); //click table connect(ui.tableChannelInfo, SIGNAL(cellClicked(int,int)), this, SLOT(clickTabChannel(int))); } CIPParams::~CIPParams() { } int CIPParams::setUserID(long lUserID) { if(lUserID < 0) { return HPR_ERROR; } m_lUserID = lUserID; return HPR_OK; } //»ñȡͨµÀÐÅÏ¢£¬Ð´Èë±í¸ñÖÐ int CIPParams::getIPInfo() { if(m_lUserID < 0) { return HPR_ERROR; } //»ñÈ¡É豸µÄIP½ÓÈëÐÅÏ¢ NET_DVR_IPPARACFG struIPParams; memset(&struIPParams, 0 , sizeof(NET_DVR_IPPARACFG)); if(getIPConInfo(&struIPParams) < 0) { return HPR_ERROR; } //ÏÈÇåÀí±í¸ñ int iRow; ui.tableChannelInfo->clear(); for(iRow = 0; iRow < ui.tableChannelInfo->rowCount(); iRow++) { ui.tableChannelInfo->removeRow(iRow); } //»ñÈ¡×î´óÊý×ÖͨµÀºÍÄ£ÄâͨµÀÊý NET_DVR_DEVICECFG struDeviceInfo; memset(&struDeviceInfo, 0 , sizeof(NET_DVR_DEVICECFG)); if(getDeviceInfo(&struDeviceInfo) < 0) { return HPR_ERROR; } //ÉèÖÃÐÐÊý£¬ÁÐÊý£¬Í· ui.tableChannelInfo->setRowCount(struDeviceInfo.byChanNum + struDeviceInfo.byIPChanNum); ui.tableChannelInfo->setColumnCount(5); //ÉèÖÃÍ·²¿ QStringList list; list<<"Channel No."<<"IP address"<<"Port"<<"IP channel No."<<"Whether online"; ui.tableChannelInfo->setHorizontalHeaderLabels(list); //ÉèÖóߴç×ÔÊÊÓ¦ ui.tableChannelInfo->horizontalHeader()->setResizeMode(QHeaderView::Stretch); ui.tableChannelInfo->setSelectionBehavior(QAbstractItemView::SelectRows); //ÉèÖÃÕûÐÐÑ¡ÖÐ //ui.tableChannelInfo->setSelectionMode(QAbstractItemView::SingleSelection); //ÉèÖõ±ÐÐÑ¡ÖÐ //¼ÓÈëÄÚÈÝ int i; int dwIPChanIndex; int dwID; iRow = 0; char strChannelName[100] = {0}; for(i = 0; i < MAX_CHANNUM_V30; i++) { //Ä£ÄâͨµÀ if(i < struDeviceInfo.byChanNum ) { memset(strChannelName, 0, 100); sprintf(strChannelName,"Camora%d", i + struDeviceInfo.byStartChan); ui.tableChannelInfo->setItem(iRow, 0, new QTableWidgetItem(strChannelName)); ui.tableChannelInfo->setItem(iRow, 1, new QTableWidgetItem("Local")); ui.tableChannelInfo->setItem(iRow, 2, new QTableWidgetItem("0")); ui.tableChannelInfo->setItem(iRow, 3, new QTableWidgetItem("0")); if(struIPParams.byAnalogChanEnable[i]) { ui.tableChannelInfo->setItem(iRow, 4, new QTableWidgetItem("Yes")); } else { ui.tableChannelInfo->setItem(iRow, 4, new QTableWidgetItem("No")); } iRow++; } //Êý×ÖͨµÀ if((i >= MAX_ANALOG_CHANNUM) && (i < MAX_ANALOG_CHANNUM + struDeviceInfo.byIPChanNum)) { dwIPChanIndex = i - MAX_ANALOG_CHANNUM; memset(strChannelName, 0, 100); sprintf(strChannelName,"IPCamora%d", dwIPChanIndex + struDeviceInfo.byStartChan); ui.tableChannelInfo->setItem(iRow, 0, new QTableWidgetItem(strChannelName)); dwID = struIPParams.struIPChanInfo[dwIPChanIndex].byIPID; if(struIPParams.struIPChanInfo[dwIPChanIndex].byIPID != 0) { //IP ui.tableChannelInfo->setItem(iRow, 1, new QTableWidgetItem(struIPParams.struIPDevInfo[dwID-1].struIP.sIpV4)); //¶Ë¿Ú memset(strChannelName, 0, 100); sprintf(strChannelName, "%d", struIPParams.struIPDevInfo[dwID-1].wDVRPort); ui.tableChannelInfo->setItem(iRow, 2, new QTableWidgetItem(strChannelName)); //IPͨµÀºÅ memset(strChannelName, 0, 100); sprintf(strChannelName, "%d", struIPParams.struIPChanInfo[dwIPChanIndex].byChannel); ui.tableChannelInfo->setItem(iRow, 3, new QTableWidgetItem(strChannelName)); //ÊÇ·ñÔÚÏß if (struIPParams.struIPChanInfo[dwIPChanIndex].byEnable) { ui.tableChannelInfo->setItem(iRow, 4, new QTableWidgetItem("online")); } else { ui.tableChannelInfo->setItem(iRow, 4, new QTableWidgetItem("offline")); } } else { ui.tableChannelInfo->setItem(iRow, 1, new QTableWidgetItem("0.0.0.0")); ui.tableChannelInfo->setItem(iRow, 2, new QTableWidgetItem("0")); ui.tableChannelInfo->setItem(iRow, 3, new QTableWidgetItem("0")); ui.tableChannelInfo->setItem(iRow, 4, new QTableWidgetItem("no")); } iRow++; } } //table²»¿ÉÒÔ±»±à¼­ ui.tableChannelInfo->setEditTriggers(QAbstractItemView::NoEditTriggers); return HPR_OK; } //´Ó±í¸ñÖеõ½Êý¾Ý£¬Ð´ÈëÉ豸 int CIPParams::saveIPInfo() { return HPR_OK; } //±í¸ñ×ó¼üµ¥»÷ʼþ int CIPParams::clickTabChannel(int iRow) { m_iIPParamIndex = -1; //ͨ¹ýÐÐÖеÄcamoraXXÐÅÏ¢£¬»ñȡȥIDÐÅÏ¢ int iChannelIndex = 0; if(getIPChannnelIndex(iRow, &iChannelIndex) < 0) { return HPR_ERROR; } //ÉèÖÃÐ޸ĿؼþÖеÄÖµ NET_DVR_IPPARACFG struIPParams; memset(&struIPParams, 0 , sizeof(NET_DVR_IPPARACFG)); //»ñÈ¡É豸ÖеÄIP½ÓÈëÐÅÏ¢ if(getIPConInfo(&struIPParams) < 0) { return HPR_ERROR; } m_iIPParamIndex = iChannelIndex; //¼Ç¼Ïµ±Ç°µÄͨµÀÐòºÅ if(iChannelIndex < MAX_ANALOG_CHANNUM)//Ä£ÄâͨµÀ { ui.widgetIPCamora->hide(); ui.widgetCamora->show(); if(struIPParams.byAnalogChanEnable[iChannelIndex]) { ui.btnEnable->setEnabled(FALSE); ui.btnDisenable->setEnabled(TRUE); } else { ui.btnEnable->setEnabled(TRUE); ui.btnDisenable->setEnabled(FALSE); } } else//Êý×ÖͨµÀ { int iIPChannelIndex; iIPChannelIndex = iChannelIndex - MAX_ANALOG_CHANNUM; ui.widgetIPCamora->show(); ui.widgetCamora->hide(); if(struIPParams.struIPChanInfo[iIPChannelIndex].byIPID > 0)//ÓжÔÓ¦µÄIPÉ豸ID { int iIPID; iIPID = struIPParams.struIPChanInfo[iIPChannelIndex].byIPID -1; ui.btnEdit->setText("ÐÞ¸Ä"); ui.btnDelete->setEnabled(TRUE); //ÉèÖÿؼþµÄÖµ ui.editIP->setText(struIPParams.struIPDevInfo[iIPID].struIP.sIpV4); ui.editUsername->setText((char *)struIPParams.struIPDevInfo[iIPID].sUserName); ui.editPassword->setText((char *)struIPParams.struIPDevInfo[iIPID].sPassword); unsigned int uiPort; uiPort = struIPParams.struIPDevInfo[iIPID].wDVRPort; KIT_unintToEdit(ui.editPort, uiPort); unsigned int uiChannelNO; uiChannelNO = struIPParams.struIPChanInfo[iIPChannelIndex].byChannel; KIT_unintToEdit(ui.editChannelNO, uiChannelNO); } else//ûÓжÔÓ¦µÄIPÉ豸ID { ui.btnEdit->setText("Ìí¼Ó"); ui.btnDelete->setEnabled(FALSE); } } m_iCurrentRow = iRow; //QMessageBox::information(this, "Please check!", tr("The error is \"%1\"").arg(iChannelIndex)); return HPR_OK; } //µ¥»÷IPCÇøÓòµÄ"±à¼­"°´Å¥ void CIPParams::on_btnEdit_clicked() { //»ñÈ¡µ±Ç°½¹µãÐÅÏ¢ if(m_iIPParamIndex >= MAX_ANALOG_CHANNUM) { int iIPChannelIndex; int iTemp; NET_DVR_IPPARACFG struIPParams; //= {0}; memset(&struIPParams, 0, sizeof(NET_DVR_IPPARACFG)); //»ñÈ¡É豸ÖеÄIP½ÓÈëÐÅÏ¢ if(getIPConInfo(&struIPParams) < 0) { return; } iIPChannelIndex = m_iIPParamIndex - MAX_ANALOG_CHANNUM; int iIPID = 0; if(struIPParams.struIPChanInfo[iIPChannelIndex].byIPID <= 0)//ÐÂÌí¼ÓÉ豸 { //ÕÒÒ»¸ö¿ÉÓÃIPÉ豸IDºÅ int i; for(i = 0; i< MAX_IP_DEVICE; i++) { if (!struIPParams.struIPDevInfo[i].dwEnable) { iIPID = i+1;//find the first empty node break; } } //ÐÞ¸ÄIPͨµÀÐÅÏ¢ KIT_editToInt(ui.editChannelNO, &iTemp); struIPParams.struIPChanInfo[iIPChannelIndex].byChannel = (BYTE)iTemp; struIPParams.struIPChanInfo[iIPChannelIndex].byIPID = (BYTE)iIPID; //ÐÞ¸ÄiIPID¶ÔÓ¦µÄÉ豸 KIT_editToIP(ui.editIP, (BYTE *)(struIPParams.struIPDevInfo[iIPID-1].struIP.sIpV4), IP_LEN); struIPParams.struIPDevInfo[iIPID-1].dwEnable = TRUE; KIT_editToInt(ui.editPort, &iTemp); struIPParams.struIPDevInfo[iIPID-1].wDVRPort = iTemp;//port KIT_editToStr(ui.editUsername, struIPParams.struIPDevInfo[iIPID-1].sUserName, NAME_LEN); KIT_editToStr(ui.editPassword, struIPParams.struIPDevInfo[iIPID-1].sPassword, PASSWD_LEN); } else //ÐÞ¸ÄIPͨµÀÐÅÏ¢ { iIPID = struIPParams.struIPChanInfo[iIPChannelIndex].byIPID; KIT_editToInt(ui.editChannelNO, &iTemp); struIPParams.struIPChanInfo[iIPChannelIndex].byChannel = (BYTE)iTemp; //ÐÞ¸ÄiIPID¶ÔÓ¦µÄÉ豸 KIT_editToIP(ui.editIP, (BYTE *)(struIPParams.struIPDevInfo[iIPID-1].struIP.sIpV4), IP_LEN); KIT_editToInt(ui.editPort, &iTemp); struIPParams.struIPDevInfo[iIPID-1].wDVRPort = iTemp;//port KIT_editToStr(ui.editUsername, struIPParams.struIPDevInfo[iIPID-1].sUserName, NAME_LEN); KIT_editToStr(ui.editPassword, struIPParams.struIPDevInfo[iIPID-1].sPassword, PASSWD_LEN); } //ÍùÉ豸·¢ËͲÎÊýÉèÖÃÐÅÏ¢, ±£´æµ½É豸 int iRet = NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_IPPARACFG, -1, &struIPParams, sizeof(NET_DVR_IPPARACFG)); if(0 == iRet) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Set User parameters error! \"%1\"").arg(iRet)); return ; } }//IPͨµÀ²ÎÊýÐ޸ĻòÌí¼Ó½áÊø if(m_iIPParamIndex < 0) { QMessageBox::information(this, tr("Please check!"), tr("Please choose a row of table!")); } getIPInfo(); //Ë¢ÐÂTable if(m_iCurrentRow >= 0) { ui.tableChannelInfo->setCurrentCell(m_iCurrentRow, 0); clickTabChannel(m_iCurrentRow); } } //ɾ³ýIPͨµÀÅäÖÃÐÅÏ¢ void CIPParams::on_btnDelete_clicked() { //»ñÈ¡µ±Ç°TableÖеÄÄÄÒ»Ðб»Ñ¡ÖУ¬m_iIPParamIndex±íʾ±»Ñ¡ÖÐÄÇÒ»ÐеÄͨµÀ±àºÅ(start no.µ½×î´óͨµÀºÅ) if(m_iIPParamIndex >= MAX_ANALOG_CHANNUM) { int iIPChannelIndex; NET_DVR_IPPARACFG struIPParams; //= {0}; memset(&struIPParams, 0, sizeof(NET_DVR_IPPARACFG)); //»ñÈ¡É豸ÖеÄIP½ÓÈëÐÅÏ¢ if(getIPConInfo(&struIPParams) < 0) { return; } iIPChannelIndex = m_iIPParamIndex - MAX_ANALOG_CHANNUM;//IP²ÎÊýÊý×éÐòºÅ int iIPID = 0; //»ñÈ¡IPÉ豸Êý×éÐòºÅ iIPID = struIPParams.struIPChanInfo[iIPChannelIndex].byIPID; if (iIPID <= 0) //ÎÞЧIPÉ豸ÐòºÅ£¬É¾³ýʧ°Ü£¬Ö±½Ó·µ»Ø { QMessageBox::information(this, tr("Please check!"), tr("Please ip device ID is error!")); return; } //ÅжÏÒ»ÏÂÊÇ·ñÓÐIPͨµÀÔÚÉèÓøÃÉ豸 int i; bool bDeleteDev = TRUE; for (i = 0; i < MAX_IP_CHANNEL; i++) { if (iIPChannelIndex != i) { if (iIPID == struIPParams.struIPChanInfo[i].byIPID) { //ÒÑÓÐIPͨµÀʹÓøÃÉ豸, //QMessageBox::information(this, tr("Please check!"), tr("Some IP channel has used this Device!")); bDeleteDev = FALSE; break; } } } //Çå¿ÕipÉ豸µÄÐÅÏ¢/clear current ip device if (bDeleteDev) { memset(&(struIPParams.struIPDevInfo[iIPID-1]), 0, sizeof(NET_DVR_IPDEVINFO)); } //Çå¿Õµ±Ç°ipͨµÀµÄÐÅÏ¢/clear current ip chan memset(&(struIPParams.struIPChanInfo[iIPChannelIndex]), 0, sizeof(NET_DVR_IPCHANINFO)); //ÍùÉ豸·¢ËͲÎÊýÉèÖÃÐÅÏ¢, ±£´æµ½É豸 int iRet = NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_IPPARACFG, -1, &struIPParams, sizeof(NET_DVR_IPPARACFG)); if(0 == iRet) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Set User parameters error! \"%1\"").arg(iRet)); return ; } } if(m_iIPParamIndex < 0) { QMessageBox::information(this, tr("Please check!"), tr("Please choose a row of table!")); } getIPInfo(); //Ë¢ÐÂTable if(m_iCurrentRow >= 0) { ui.tableChannelInfo->setCurrentCell(m_iCurrentRow, 0); clickTabChannel(m_iCurrentRow); } } //ÆôÓÃÄ£ÄâͨµÀ void CIPParams::on_btnEnable_clicked() { if(m_iIPParamIndex < 0) { QMessageBox::information(this, tr("Please check!"), tr("Please choose a row of table!")); return; } if(m_iIPParamIndex < MAX_ANALOG_CHANNUM)//Ä£ÄâͨµÀ { NET_DVR_IPPARACFG struIPParams; //= {0}; memset(&struIPParams, 0, sizeof(NET_DVR_IPPARACFG)); //»ñÈ¡É豸ÖеÄIP½ÓÈëÐÅÏ¢ if(getIPConInfo(&struIPParams) < 0) { return; } struIPParams.byAnalogChanEnable[m_iIPParamIndex] = TRUE;//Ä£ÄâͨµÀ²ÎÊýÊý×éÐòºÅ //ÍùÉ豸·¢ËͲÎÊýÉèÖÃÐÅÏ¢, ±£´æµ½É豸 int iRet = NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_IPPARACFG, -1, &struIPParams, sizeof(NET_DVR_IPPARACFG)); if(!iRet) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Set User parameters error! \"%1\"").arg(iRet)); return ; } ui.btnEnable->setEnabled(FALSE); ui.btnDisenable->setEnabled(TRUE); if(getIPInfo() == HPR_OK) //Ë¢ÐÂTable { } } } //½ûÓÃÄ£ÄâͨµÀ void CIPParams::on_btnDisenable_clicked() { if(m_iIPParamIndex < 0) { QMessageBox::information(this, tr("Please check!"), tr("Please choose a row of table!")); return; } if(m_iIPParamIndex < MAX_ANALOG_CHANNUM)//Ä£ÄâͨµÀ { NET_DVR_IPPARACFG struIPParams; //= {0}; memset(&struIPParams, 0, sizeof(NET_DVR_IPPARACFG)); //»ñÈ¡É豸ÖеÄIP½ÓÈëÐÅÏ¢ if(getIPConInfo(&struIPParams) < 0) { return; } struIPParams.byAnalogChanEnable[m_iIPParamIndex] = FALSE;//Ä£ÄâͨµÀ²ÎÊýÊý×éÐòºÅ //ÍùÉ豸·¢ËͲÎÊýÉèÖÃÐÅÏ¢, ±£´æµ½É豸 int iRet = NET_DVR_SetDVRConfig(m_lUserID, NET_DVR_SET_IPPARACFG, -1, &struIPParams, sizeof(NET_DVR_IPPARACFG)); if(!iRet) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, tr("Please check!"), tr("Set User parameters error! \"%1\"").arg(iRet)); return ; } ui.btnEnable->setEnabled(TRUE); ui.btnDisenable->setEnabled(FALSE); getIPInfo(); //Ë¢ÐÂTable } } //»ñÈ¡É豸ÐÅÏ¢: ÆðʼͨµÀºÅ£¬±ãÓÚÔÚtableÖÐÏÔʾÓà int CIPParams::getDeviceInfo(LPNET_DVR_DEVICECFG pDeviceInfo) { if(m_lUserID < 0 && pDeviceInfo ==NULL) { return HPR_ERROR; } int iRet; DWORD uiReturnLen; iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_DEVICECFG, 0, pDeviceInfo, sizeof(NET_DVR_DEVICECFG), &uiReturnLen); if(0 == iRet) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, "Please check!", tr("The error is \"%1\"").arg(iRet)); return HPR_ERROR; } return HPR_OK; } //»ñÈ¡IP½ÓÈëÐÅÏ¢ int CIPParams::getIPConInfo(LPNET_DVR_IPPARACFG pIPConInfo) { if(m_lUserID < 0 && pIPConInfo ==NULL) { return HPR_ERROR; } int iRet; DWORD uiReturnLen; iRet = NET_DVR_GetDVRConfig(m_lUserID, NET_DVR_GET_IPPARACFG, 0, pIPConInfo, sizeof(NET_DVR_IPPARACFG), &uiReturnLen); if(0 == iRet) { iRet = NET_DVR_GetLastError(); QMessageBox::information(this, "Please check!", tr("The error is \"%1\"").arg(iRet)); return HPR_ERROR; } return HPR_OK; } //¸ù¾ÝÐкţ¬»ñȡͨµÀÐòºÅ int CIPParams::getIPChannnelIndex(int iRow, int *piChannelIndex) { if(NULL == piChannelIndex) { return HPR_ERROR; } //ÏÈ»ñÈ¡±í¸ñÖеÄÔªËØ QTableWidgetItem *pChannelName = NULL; pChannelName = ui.tableChannelInfo->item(iRow, 0); //È¡µÃÔªËØÖеÄtext if(NULL ==pChannelName) { return HPR_ERROR; } char strChannelName[20] = {0}; QString qstrChannelName; qstrChannelName = pChannelName->text(); KIT_qstringToStr(&qstrChannelName, (BYTE *)strChannelName, 20); //»ñÈ¡É豸ÐÅÏ¢ NET_DVR_DEVICECFG struDeviceInfo; memset(&struDeviceInfo, 0, sizeof(NET_DVR_DEVICECFG)); if(getDeviceInfo(&struDeviceInfo) < 0) { return HPR_ERROR; } //´¦Àí int iIndex = 0; if('C' == strChannelName[0])//Ä£ÄâͨµÀÃû³Æ { iIndex = atoi(&(strChannelName[6])); } if('I' == strChannelName[0])//IPͨµÀ { iIndex = atoi(&(strChannelName[8])); iIndex += MAX_ANALOG_CHANNUM; } iIndex -= struDeviceInfo.byStartChan; *piChannelIndex = iIndex; return HPR_OK; } void CIPParams::showEvent ( QShowEvent * event ) { if(event == NULL) { } getIPInfo(); }