Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. //============================================================================
  2. // Name : main.cpp
  3. // Author : Huy Do (huydo1@gmail.com)
  4. // Version : 2017-04-22
  5. // Description : Net Alarm Test for DAHUA NVR
  6. //============================================================================
  7.  
  8. #include <iostream>
  9. #include <unistd.h> // for sleep
  10. #include <string>
  11. #include "dhnetsdk.h"
  12. using namespace std;
  13.  
  14. LLONG m_lLoginHandle;
  15.  
  16. void CALLBACK DisConnectFunc(LLONG lLoginID, char *pchDVRIP, LONG nDVRPort, LDWORD dwUser)
  17. {
  18. cout << "Callback DisConnect" << endl;
  19. return;
  20. }
  21.  
  22. void init()
  23. {
  24. cout << "init" << endl;
  25. bool success = CLIENT_Init(DisConnectFunc, (LDWORD) 0);
  26. if (success)
  27. {
  28. cout << "init ok" << endl;
  29. }
  30. else
  31. {
  32. cout << "init failed" << endl;
  33. }
  34. }
  35.  
  36.  
  37. void login()
  38. {
  39. cout << "login" << endl;
  40. int error = 0;
  41. long port = 37777;
  42. string destip = "192.168.2.108";
  43. string username = "alarm";
  44. string password = "alarm";
  45. NET_DEVICEINFO deviceInfo = {0};
  46.  
  47.  
  48. m_lLoginHandle = CLIENT_Login(destip.c_str(), port, username.c_str(), password.c_str(), &deviceInfo, &error);
  49. if(m_lLoginHandle == 0)
  50. {
  51. if(error != 255)
  52. {
  53. cout << "login failed with code " << error << endl;
  54. }
  55. else
  56. {
  57. cout << "login also failed" << endl;
  58. }
  59.  
  60. }
  61. else
  62. {
  63. cout << "login ok" << endl;
  64. }
  65.  
  66. }
  67.  
  68. void logout()
  69. {
  70. cout << "logout" << endl;
  71. bool success = CLIENT_Logout(m_lLoginHandle);
  72. if(success)
  73. {
  74. cout << "logout ok" << endl;
  75. }
  76. else
  77. {
  78. cout << "logout failed" << endl;
  79. }
  80. }
  81.  
  82. void alarmInStart()
  83. {
  84. cout << "alarm start" << endl;
  85. if(0 != m_lLoginHandle)
  86. {
  87. ALARMCTRL_PARAM alarmParam = {0};
  88. alarmParam.dwSize = sizeof(ALARMCTRL_PARAM);
  89. alarmParam.nAction = 1;
  90. alarmParam.nAlarmNo = 0;
  91.  
  92. BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_TRIGGER_ALARM_IN, &alarmParam);
  93. if(bSuccess)
  94. {
  95. cout << "ok" << endl;
  96. }
  97. else
  98. {
  99. cout << "failed" << endl;
  100. }
  101. }
  102. else
  103. {
  104. cout << "invalid login" << endl;
  105. }
  106. }
  107.  
  108. void alarmInStop()
  109. {
  110. cout << "alarm stop" << endl;
  111. if(0 != m_lLoginHandle)
  112. {
  113. ALARMCTRL_PARAM alarmParam = {0};
  114. alarmParam.dwSize = sizeof(ALARMCTRL_PARAM);
  115. alarmParam.nAction = 0;
  116. alarmParam.nAlarmNo = 0;
  117.  
  118. BOOL bSuccess = CLIENT_ControlDevice(m_lLoginHandle, DH_TRIGGER_ALARM_IN, &alarmParam);
  119. if(bSuccess)
  120. {
  121. cout << "ok" << endl;
  122. }
  123. else
  124. {
  125. cout << "failed" << endl;
  126. }
  127. }
  128. else
  129. {
  130. cout << "invalid login" << endl;
  131. }
  132. }
  133.  
  134. int main() {
  135. cout << "Dahua Net Alarm Test" << endl;
  136. init();
  137. login();
  138. alarmInStart();
  139. sleep(2);
  140. alarmInStop();
  141. logout();
  142. return 0;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement