#include "XNetSDKTest.h" #include "AlarmInfo.h" #include "XNetSDKSyn.h" #include "Detect_MotionDetect.h" USE_NS_NETSDK_CFG int TestDevAlarmCallback() { printf("%s\r\n", __FUNCTION__); char c = 0; do { switch(c) { //////设置移动侦测报警 case 'a': { char szOutBuffer[40960] = {0}; int nInOutSize = sizeof(szOutBuffer); int nResult = XSDK_DevGetChnConfigSyn(g_hDevice, 0, JK_Detect_MotionDetect, szOutBuffer, &nInOutSize, 4000, EXCMD_CONFIG_GET); if(nResult >= 0) { Detect_MotionDetect cfg; cfg.SetName("Detect.MotionDetect.[0]"); cfg.Parse(szOutBuffer); cfg.Enable.SetValue(true); const char *pCfg = cfg.ToString(); int nRet = XSDK_DevSetChnConfig(g_hDevice, 0, JK_Detect_MotionDetect, pCfg, strlen(pCfg), 1, 5000, EXCMD_CONFIG_SET); if(nRet >= 0) { printf("Set Success!\r\n"); } } } break; //////开启报警监听(开启后触发移动侦测报警有相关返回) case 's': { XSDK_DevSetAlarmListener(g_hDevice, true); } break; //////关闭报警监听 case 't': { XSDK_DevSetAlarmListener(g_hDevice, false); } break; } }while((c = getchar()) != 'q'); return 0; } /////触发报警后的返回 void OnDevAlarmCallback(XSDK_HANDLE hDevice, const char *szAlarm) { AlarmInfo alarmInfo; if(0 == alarmInfo.Parse(szAlarm)) { const char * buf = alarmInfo.Event.ToString(); 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", hDevice, alarmInfo.Event.Value(), alarmInfo.Channel.Value(), alarmInfo.StartTime.Value(), alarmInfo.Status.Value(), alarmInfo.ExtInfo.Value()); } else { printf("OnDevAlarmCallback[Dev:%ld][%s]\r\n", hDevice, szAlarm); } }