You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.8 KiB

  1. #include "XNetSDKTest.h"
  2. #include "AlarmInfo.h"
  3. #include "XNetSDKSyn.h"
  4. #include "Detect_MotionDetect.h"
  5. USE_NS_NETSDK_CFG
  6. int TestDevAlarmCallback()
  7. {
  8. printf("%s\r\n", __FUNCTION__);
  9. char c = 0;
  10. do
  11. {
  12. switch(c)
  13. {
  14. //////设置移动侦测报警
  15. case 'a':
  16. {
  17. char szOutBuffer[40960] = {0};
  18. int nInOutSize = sizeof(szOutBuffer);
  19. int nResult = XSDK_DevGetChnConfigSyn(g_hDevice, 0, JK_Detect_MotionDetect, szOutBuffer, &nInOutSize, 4000, EXCMD_CONFIG_GET);
  20. if(nResult >= 0)
  21. {
  22. Detect_MotionDetect cfg;
  23. cfg.SetName("Detect.MotionDetect.[0]");
  24. cfg.Parse(szOutBuffer);
  25. cfg.Enable.SetValue(true);
  26. const char *pCfg = cfg.ToString();
  27. int nRet = XSDK_DevSetChnConfig(g_hDevice, 0, JK_Detect_MotionDetect, pCfg, strlen(pCfg), 1, 5000, EXCMD_CONFIG_SET);
  28. if(nRet >= 0)
  29. {
  30. printf("Set Success!\r\n");
  31. }
  32. }
  33. }
  34. break;
  35. //////开启报警监听(开启后触发移动侦测报警有相关返回)
  36. case 's':
  37. {
  38. XSDK_DevSetAlarmListener(g_hDevice, true);
  39. }
  40. break;
  41. //////关闭报警监听
  42. case 't':
  43. {
  44. XSDK_DevSetAlarmListener(g_hDevice, false);
  45. }
  46. break;
  47. }
  48. }while((c = getchar()) != 'q');
  49. return 0;
  50. }
  51. /////触发报警后的返回
  52. void OnDevAlarmCallback(XSDK_HANDLE hDevice, const char *szAlarm)
  53. {
  54. AlarmInfo alarmInfo;
  55. if(0 == alarmInfo.Parse(szAlarm))
  56. {
  57. const char * buf = alarmInfo.Event.ToString();
  58. printf("OnDevAlarmCallback[Dev:%d]\r\n\Event:[%s]\r\n\Channel:[%d]\r\n\StartTime:[%s]\r\n\Status:[%s]\r\n\ExtInfo:[%s]\r\n\r\n",
  59. hDevice, alarmInfo.Event.Value(), alarmInfo.Channel.Value(), alarmInfo.StartTime.Value(), alarmInfo.Status.Value(), alarmInfo.ExtInfo.Value());
  60. }
  61. else
  62. {
  63. printf("OnDevAlarmCallback[Dev:%ld][%s]\r\n", hDevice, szAlarm);
  64. }
  65. }