Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //============================================================================
- // Name : main.cpp
- // Author : Huy Do (huydo1@gmail.com)
- // Version : 2017-04-22
- // Description : Net Alarm Test for DAHUA NVR
- //============================================================================
- #include <iostream>
- #include <unistd.h> // for sleep
- #include <string>
- #include "dhnetsdk.h"
- using namespace std;
- LLONG m_lLoginHandle;
- void CALLBACK DisConnectFunc(LLONG lLoginID, char *pchDVRIP, LONG nDVRPort, LDWORD dwUser)
- {
- cout << "Callback DisConnect" << endl;
- return;
- }
- void init()
- {
- cout << "init" << endl;
- bool success = CLIENT_Init(DisConnectFunc, (LDWORD) 0);
- if (success)
- {
- cout << "init ok" << endl;
- }
- else
- {
- cout << "init failed" << endl;
- }
- }
- void login()
- {
- cout << "login" << endl;
- int error = 0;
- long port = 37777;
- string destip = "192.168.2.108";
- string username = "alarm";
- string password = "alarm";
- NET_DEVICEINFO deviceInfo = {0};
- m_lLoginHandle = CLIENT_Login(destip.c_str(), port, username.c_str(), password.c_str(), &deviceInfo, &error);
- if(m_lLoginHandle == 0)
- {
- if(error != 255)
- {
- cout << "login failed with code " << error << endl;
- }
- else
- {
- cout << "login also failed" << endl;
- }
- }
- else
- {
- cout << "login ok" << endl;
- }
- }
- void logout()
- {
- cout << "logout" << endl;
- bool success = CLIENT_Logout(m_lLoginHandle);
- if(success)
- {
- cout << "logout ok" << endl;
- }
- else
- {
- cout << "logout failed" << endl;
- }
- }
- void alarmInStart()
- {
- cout << "alarm start" << endl;
- if(0 != m_lLoginHandle)
- {
- ALARMCTRL_PARAM alarmParam = {0};
- alarmParam.dwSize = sizeof(ALARMCTRL_PARAM);
- alarmParam.nAction = 1;
- alarmParam.nAlarmNo = 0;
- BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_TRIGGER_ALARM_IN, &alarmParam);
- if(bSuccess)
- {
- cout << "ok" << endl;
- }
- else
- {
- cout << "failed" << endl;
- }
- }
- else
- {
- cout << "invalid login" << endl;
- }
- }
- void alarmInStop()
- {
- cout << "alarm stop" << endl;
- if(0 != m_lLoginHandle)
- {
- ALARMCTRL_PARAM alarmParam = {0};
- alarmParam.dwSize = sizeof(ALARMCTRL_PARAM);
- alarmParam.nAction = 0;
- alarmParam.nAlarmNo = 0;
- BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_TRIGGER_ALARM_IN, &alarmParam);
- if(bSuccess)
- {
- cout << "ok" << endl;
- }
- else
- {
- cout << "failed" << endl;
- }
- }
- else
- {
- cout << "invalid login" << endl;
- }
- }
- int main() {
- cout << "Dahua Net Alarm Test" << endl;
- init();
- login();
- alarmInStart();
- sleep(2);
- alarmInStop();
- logout();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement