#include "usg_common.h"
|
#include <stdio.h>
|
#include <iostream>
|
#include "HCNetSDK.h"
|
using namespace std;
|
int saveRecordFile(int userId, char * srcfile, char * destfile)
|
{
|
printf("destfile=%s\n", destfile);
|
int bRes = 1;
|
int hPlayback = 0;
|
//按文件名下载录像
|
if ( (hPlayback = NET_DVR_GetFileByName(userId, srcfile, destfile)) < 0 )
|
{
|
printf( "GetFileByName failed. error[%d]\n", NET_DVR_GetLastError());
|
bRes = -1;
|
return bRes;
|
}
|
//开始下载
|
if (!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_PLAYSTART, NULL, 0, NULL, NULL))
|
{
|
printf("play back control failed [%d]\n", NET_DVR_GetLastError());
|
bRes = -1;
|
return bRes;
|
}
|
int nPos = 0;
|
for (nPos = 0; nPos < 100 && nPos >= 0; nPos = NET_DVR_GetDownloadPos(hPlayback))
|
{
|
printf("Be downloading...%d %%\n", nPos);
|
sleep(1);
|
//下载进度
|
//millisecond
|
}
|
printf("have got %d\n", nPos);
|
//停止下载
|
if (!NET_DVR_StopGetFile(hPlayback))
|
{
|
printf("failed to stop get file [%d]\n", NET_DVR_GetLastError());
|
bRes = -1;
|
return bRes;
|
}
|
printf("%s\n", srcfile);
|
if (nPos < 0 || nPos > 100)
|
{
|
printf("download err [%d]\n", NET_DVR_GetLastError());
|
bRes = -1;
|
return bRes;
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
|
int main()
|
{
|
char *libPath = "../hclib/";
|
// char cryptoPath[2048] = {0};
|
// sprintf(cryptoPath, "%slibcrypto.so", libPath);
|
// printf("cryptoPath:%s\n", cryptoPath);
|
// NET_DVR_SetSDKInitCfg(NET_SDK_INIT_CFG_LIBEAY_PATH, cryptoPath);
|
|
// char sslPath[2048] = {0};
|
// sprintf(sslPath, "%slibssl.so", libPath);
|
// NET_DVR_SetSDKInitCfg(NET_SDK_INIT_CFG_SSLEAY_PATH, sslPath);
|
|
NET_DVR_LOCAL_SDK_PATH struComPath = {0};
|
sprintf(struComPath.sPath, "%s", libPath); //HCNetSDKCom文件夹所在的路径
|
NET_DVR_SetSDKInitCfg(NET_SDK_INIT_CFG_SDK_PATH, &struComPath);
|
//---------------------------------------
|
// 初始化
|
NET_DVR_Init();
|
//设置连接时间与重连时间
|
NET_DVR_SetConnectTime(2000, 1);
|
NET_DVR_SetReconnect(10000, true);
|
//---------------------------------------
|
//登录参数,包括设备地址、登录用户、密码等
|
NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
|
struLoginInfo.bUseAsynLogin = 0; //同步登录方式
|
strcpy(struLoginInfo.sDeviceAddress, "192.168.20.11"); //设备IP地址
|
struLoginInfo.wPort = 8000; //设备服务端口
|
strcpy(struLoginInfo.sUserName, "admin"); //设备登录用户名
|
strcpy(struLoginInfo.sPassword, "a1234567"); //设备登录密码
|
|
// 注册设备
|
LONG lUserID;
|
NET_DVR_DEVICEINFO_V40 struDeviceInfo = {0};
|
//lUserID = 0;
|
lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfo);
|
if (lUserID < 0)
|
{
|
printf("Login error, %d\n", NET_DVR_GetLastError());
|
NET_DVR_Cleanup();
|
return 1;
|
}
|
printf("lUserID = %ld\n", lUserID);
|
NET_DVR_FILECOND_V40 struFileCond = {0};
|
struFileCond.dwFileType = 0xFF;
|
|
//通道号
|
struFileCond.lChannel = 1;
|
struFileCond.dwIsLocked = 0xFF;
|
struFileCond.dwUseCardNo = 0;
|
struFileCond.struStartTime.dwYear = 2020; //开始时间
|
struFileCond.struStartTime.dwMonth = 4;
|
struFileCond.struStartTime.dwDay = 10;
|
struFileCond.struStartTime.dwHour = 14;
|
struFileCond.struStartTime.dwMinute = 9;
|
struFileCond.struStartTime.dwSecond = 0;
|
struFileCond.struStopTime.dwYear = 2020; //结束时间
|
struFileCond.struStopTime.dwMonth = 4;
|
struFileCond.struStopTime.dwDay = 10;
|
struFileCond.struStopTime.dwHour = 15;
|
struFileCond.struStopTime.dwMinute = 22;
|
struFileCond.struStopTime.dwSecond = 0;
|
|
|
//---------------------------------------
|
//查找录像文件
|
int lFindHandle = NET_DVR_FindFile_V40(lUserID, &struFileCond);
|
if (lFindHandle < 0)
|
{
|
printf("find file fail,last error %d\n", NET_DVR_GetLastError());
|
return 1;
|
}
|
NET_DVR_FINDDATA_V40 struFileData;
|
while (true)
|
{
|
//逐个获取查找到的文件信息
|
int result = NET_DVR_FindNextFile_V40(lFindHandle, &struFileData);
|
if (result == NET_DVR_ISFINDING)
|
{
|
continue;
|
}
|
else if (result == NET_DVR_FILE_SUCCESS) //获取文件信息成功
|
{
|
char strFileName[256] = {0};
|
sprintf(strFileName, "./%s", struFileData.sFileName);
|
saveRecordFile(lUserID, struFileData.sFileName, strFileName);
|
break;
|
}
|
else if (result == NET_DVR_FILE_NOFIND || result == NET_DVR_NOMOREFILE) //未查找到文件或者查找结束
|
{
|
break;
|
}
|
else
|
{
|
printf("find file fail for illegal get file state");
|
break;
|
}
|
}
|
//停止查找
|
if (lFindHandle >= 0)
|
{
|
NET_DVR_FindClose_V30(lFindHandle);
|
}
|
//注销用户
|
NET_DVR_Logout(lUserID);
|
//释放 SDK 资源
|
NET_DVR_Cleanup();
|
return 1;
|
}
|