Skip to content

Instantly share code, notes, and snippets.

@hdo
Created April 22, 2017 17:55
Show Gist options
  • Save hdo/598f56a23d360164c3fbf60012902a88 to your computer and use it in GitHub Desktop.
Save hdo/598f56a23d360164c3fbf60012902a88 to your computer and use it in GitHub Desktop.
Minimal program to send Net Alarm to Dahua NVR
//============================================================================
// Name : main.cpp
// Author : Huy Do ([email protected])
// 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;
}
@hdo
Copy link
Author

hdo commented Apr 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment