add main
This commit is contained in:
parent
3f50c8dd9a
commit
a4708d0c00
|
@ -60,6 +60,8 @@
|
||||||
"unordered_map": "cpp",
|
"unordered_map": "cpp",
|
||||||
"variant": "cpp",
|
"variant": "cpp",
|
||||||
"vector": "cpp",
|
"vector": "cpp",
|
||||||
"algorithm": "cpp"
|
"algorithm": "cpp",
|
||||||
|
"__tree": "cpp",
|
||||||
|
"map": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
105
HkStreamer.cpp
105
HkStreamer.cpp
|
@ -2,23 +2,25 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
#include "HCNetSDK.h"
|
#include "HCNetSDK.h"
|
||||||
#include "HkStreamer.h"
|
#include "HkStreamer.h"
|
||||||
|
|
||||||
|
void CALLBACK fPlayDataCallBack(LONG lPlayHandle, DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize, void* dwUser)
|
||||||
void CALLBACK fPlayDataCallBack(LONG lPlayHandle, DWORD dwDataType, BYTE *pBuffer,DWORD dwBufSize,DWORD dwUser)
|
|
||||||
{
|
{
|
||||||
if(dwBufSize>0){
|
if (dwBufSize > 0)
|
||||||
char pb[dwBufSize] = {0};
|
{
|
||||||
memcpy(pb, pBuffer, dwBufSize);
|
char pb[dwBufSize] = {0};
|
||||||
std::cout.write(pb, dwBufSize);
|
memcpy(pb, pBuffer, dwBufSize);
|
||||||
}
|
|
||||||
int pos = NET_DVR_GetDownloadPos(lPlayHandle);
|
std::cout.write(pb, dwBufSize);
|
||||||
if (pos > 98)
|
std::cout.flush();
|
||||||
{
|
}
|
||||||
fprintf(stderr, "pyd---Current Time:%d, data size:%d\n", time(NULL), dwBufSize);
|
int pos = NET_DVR_GetDownloadPos(lPlayHandle);
|
||||||
printf("Play over!%d\n", pos);
|
if (pos > 98)
|
||||||
}
|
{
|
||||||
|
fprintf(stderr, "pyd---Current Time:%d, data size:%d\n", time(NULL), dwBufSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int login(LPLoginInfo loginInfo)
|
int login(LPLoginInfo loginInfo)
|
||||||
|
@ -27,16 +29,19 @@ int login(LPLoginInfo loginInfo)
|
||||||
long lUserID;
|
long lUserID;
|
||||||
// login
|
// login
|
||||||
NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
|
NET_DVR_USER_LOGIN_INFO struLoginInfo = {0};
|
||||||
|
NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0};
|
||||||
struLoginInfo.bUseAsynLogin = false;
|
struLoginInfo.bUseAsynLogin = false;
|
||||||
|
|
||||||
struLoginInfo.wPort = 8000;
|
struLoginInfo.wPort = 8000;
|
||||||
memcpy(struLoginInfo.sDeviceAddress, loginInfo->sDeviceAddress, NET_DVR_DEV_ADDRESS_MAX_LEN);
|
memcpy(struLoginInfo.sDeviceAddress, loginInfo->sDeviceAddress, NET_DVR_DEV_ADDRESS_MAX_LEN);
|
||||||
memcpy(struLoginInfo.sUserName, loginInfo->sUserName, NAME_LEN);
|
memcpy(struLoginInfo.sUserName, loginInfo->sUserName, NAME_LEN);
|
||||||
memcpy(struLoginInfo.sPassword, loginInfo->sPassword, NAME_LEN);
|
memcpy(struLoginInfo.sPassword, loginInfo->sPassword, NAME_LEN);
|
||||||
lUserID = NET_DVR_Login_V40(&struLoginInfo, nullptr);
|
std::cerr << struLoginInfo.sDeviceAddress << " " << struLoginInfo.sUserName << " " << struLoginInfo.sPassword << std::endl;
|
||||||
|
lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40);
|
||||||
return lUserID;
|
return lUserID;
|
||||||
}
|
}
|
||||||
void cpTime(NET_DVR_TIME *nvrTime, StreamDate date){
|
void cpTime(NET_DVR_TIME *nvrTime, StreamDate date)
|
||||||
|
{
|
||||||
nvrTime->dwYear = date.dwYear;
|
nvrTime->dwYear = date.dwYear;
|
||||||
nvrTime->dwMonth = date.dwMonth;
|
nvrTime->dwMonth = date.dwMonth;
|
||||||
nvrTime->dwDay = date.dwDay;
|
nvrTime->dwDay = date.dwDay;
|
||||||
|
@ -49,47 +54,55 @@ int playback(LPLoginInfo loginInfo, LPStream stream)
|
||||||
long lUserID = login(loginInfo);
|
long lUserID = login(loginInfo);
|
||||||
if (lUserID < 0)
|
if (lUserID < 0)
|
||||||
{
|
{
|
||||||
printf("pyd1---Login error, %d\n", NET_DVR_GetLastError());
|
std::cerr << "pyd1---Login error" << NET_DVR_GetLastError() << std::endl;
|
||||||
return HPR_ERROR;
|
return HPR_ERROR;
|
||||||
}
|
}
|
||||||
NET_DVR_VOD_PARA struVodPara = {0};
|
NET_DVR_VOD_PARA struVodPara = {0};
|
||||||
StreamDate start = stream->start;
|
StreamDate start = stream->start;
|
||||||
|
struVodPara.struIDInfo.dwChannel = stream->lChannel;
|
||||||
cpTime(&struVodPara.struBeginTime, start);
|
cpTime(&struVodPara.struBeginTime, start);
|
||||||
cpTime(&struVodPara.struEndTime, stream->end);
|
cpTime(&struVodPara.struEndTime, stream->end);
|
||||||
int hPlayback = NET_DVR_PlayBackByTime_V40(lUserID, &struVodPara);
|
int hPlayback = NET_DVR_PlayBackByTime_V40(lUserID, &struVodPara);
|
||||||
if (hPlayback < 0)
|
if (hPlayback < 0)
|
||||||
{
|
{
|
||||||
printf("pyd1---PlayBack error, %d\n", NET_DVR_GetLastError());
|
std::cerr << "pyd1---PlayBack error: " << NET_DVR_GetLastError() << std::endl;
|
||||||
return HPR_ERROR;
|
return HPR_ERROR;
|
||||||
}
|
}
|
||||||
|
char usrInfo[200];
|
||||||
if (!NET_DVR_SetPlayDataCallBack(hPlayback, fPlayDataCallBack, 1))
|
if (!NET_DVR_SetPlayDataCallBack_V40(hPlayback, fPlayDataCallBack, usrInfo))
|
||||||
{
|
{
|
||||||
printf("NET_DVR_SetPlayDataCallBack fail!\n");
|
std::cerr << "NET_DVR_SetPlayDataCallBack fail!\n"
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NET_DVR_PlayBackControl(hPlayback, NET_DVR_PLAYSTART, 0, NULL))
|
time_t lstart = time(NULL);
|
||||||
|
if (!NET_DVR_PlayBackControl_V40(hPlayback, NET_DVR_PLAYSTART,NULL, 0, NULL, NULL))
|
||||||
{
|
{
|
||||||
printf("play back control failed [%d]\n", NET_DVR_GetLastError());
|
std::cerr << "play back control failed : " << NET_DVR_GetLastError() << std::endl;
|
||||||
return HPR_ERROR;
|
return HPR_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (pos = 0; pos < 100 && pos >= 0; pos = NET_DVR_GetDownloadPos(hPlayback))
|
for (pos = 0; pos < 100 && pos >= 0; pos = NET_DVR_GetDownloadPos(hPlayback))
|
||||||
{
|
{
|
||||||
sleep(10);
|
std::cerr<<"Pos:"<<pos<<std::endl;
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
printf("have got %d\n", pos);
|
std::cerr << "have got: " << pos << std::endl;
|
||||||
if (!NET_DVR_StopGetFile(hPlayback))
|
if (!NET_DVR_StopGetFile(hPlayback))
|
||||||
{
|
{
|
||||||
printf("failed to stop get file [%d]\n", NET_DVR_GetLastError());
|
std::cerr << "failed to stop get file: " << NET_DVR_GetLastError() << std::endl;
|
||||||
return HPR_ERROR;
|
return HPR_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("StopGetFile\n");
|
time_t lend = time(NULL);
|
||||||
|
std::cerr << "StopGetFile\n"
|
||||||
|
<< "Use:"
|
||||||
|
<< lend - lstart
|
||||||
|
<< std::endl;
|
||||||
if (pos < 0 || pos > 100)
|
if (pos < 0 || pos > 100)
|
||||||
{
|
{
|
||||||
printf("download err [%d]\n", NET_DVR_GetLastError());
|
std::cerr << "download err:" << NET_DVR_GetLastError() << std::endl;
|
||||||
return HPR_ERROR;
|
return HPR_ERROR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -104,6 +117,42 @@ int playback(LPLoginInfo loginInfo, LPStream stream)
|
||||||
|
|
||||||
return HPR_OK;
|
return HPR_OK;
|
||||||
}
|
}
|
||||||
int main()
|
int getCfg(LPLoginInfo loginInfo)
|
||||||
{
|
{
|
||||||
|
long lUserID = login(loginInfo);
|
||||||
|
if (lUserID < 0)
|
||||||
|
{
|
||||||
|
std::cerr << "pyd1---Login error" << NET_DVR_GetLastError() << std::endl;
|
||||||
|
return HPR_ERROR;
|
||||||
|
}
|
||||||
|
NET_DVR_IPPARACFG_V40 ipcfg;
|
||||||
|
DWORD bytesReturned = 0;
|
||||||
|
ipcfg.dwSize = sizeof(NET_DVR_IPPARACFG_V40);
|
||||||
|
int iGroupNO = 0;
|
||||||
|
bool resCode = NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_IPPARACFG_V40, iGroupNO, &ipcfg, sizeof(NET_DVR_IPPARACFG_V40), &bytesReturned);
|
||||||
|
if (!resCode)
|
||||||
|
{
|
||||||
|
DWORD code = NET_DVR_GetLastError();
|
||||||
|
std::cout << "NET_DVR_GetDVRConfig failed " << NET_DVR_GetErrorMsg((LONG *)(&code)) << std::endl;
|
||||||
|
NET_DVR_Logout(lUserID);
|
||||||
|
NET_DVR_Cleanup();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
std::cout << "设备组 " << ipcfg.dwGroupNum << " 数字通道个数 " << ipcfg.dwDChanNum << " 起始通道 " << ipcfg.dwStartDChan << std::endl
|
||||||
|
<< std::endl;
|
||||||
|
for (int i = 0; i < ipcfg.dwDChanNum; i++)
|
||||||
|
{
|
||||||
|
NET_DVR_PICCFG_V30 channelInfo;
|
||||||
|
bytesReturned = 0;
|
||||||
|
channelInfo.dwSize = sizeof(NET_DVR_PICCFG_V30);
|
||||||
|
int channelNum = i + ipcfg.dwStartDChan;
|
||||||
|
NET_DVR_GetDVRConfig(lUserID, NET_DVR_GET_PICCFG_V30, channelNum, &channelInfo, sizeof(NET_DVR_PICCFG_V30), &bytesReturned);
|
||||||
|
std::cout << "通道号 " << channelNum << "\t通道名称 " << channelInfo.sChanName;
|
||||||
|
std::cout << "\t用户名 " << ipcfg.struIPDevInfo[i].sUserName << "\t密码 " << ipcfg.struIPDevInfo[i].sPassword;
|
||||||
|
std::cout << "\t设备ID " << (long)ipcfg.struIPDevInfo[i].szDeviceID;
|
||||||
|
std::cout << "\tip地址 " << ipcfg.struIPDevInfo[i].struIP.sIpV4 << "\t端口 " << ipcfg.struIPDevInfo[i].wDVRPort << std::endl;
|
||||||
|
}
|
||||||
|
NET_DVR_Logout(lUserID);
|
||||||
|
NET_DVR_Cleanup();
|
||||||
|
return 0;
|
||||||
}
|
}
|
Binary file not shown.
|
@ -0,0 +1,19 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
/*
|
||||||
|
#
|
||||||
|
#include "include/HkStreamer.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
// type HkLoginInfo C.LoginInfo
|
||||||
|
// type StreamDate C.StreamDate
|
||||||
|
// type StreamCon C.StreamCon
|
||||||
|
|
||||||
|
func makeLoginInfo(deviceAddr string, user string, password string) C.LoginInfo {
|
||||||
|
ret := C.LoginInfo{}
|
||||||
|
ret.sDeviceAddress = C.CString(deviceAddr)
|
||||||
|
ret.sUser = C.CString(user)
|
||||||
|
ret.sPassword = C.CString(password)
|
||||||
|
return ret
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,199 @@
|
||||||
|
/* automatically generated by rust-bindgen 0.64.0 */
|
||||||
|
|
||||||
|
pub const HPR_OK: u32 = 0;
|
||||||
|
pub const HPR_ERROR: i32 = -1;
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct LoginInfo {
|
||||||
|
pub sDeviceAddress: [::std::os::raw::c_char; 129usize],
|
||||||
|
pub sUserName: [::std::os::raw::c_char; 64usize],
|
||||||
|
pub sPassword: [::std::os::raw::c_char; 64usize],
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_LoginInfo() {
|
||||||
|
const UNINIT: ::std::mem::MaybeUninit<LoginInfo> = ::std::mem::MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::size_of::<LoginInfo>(),
|
||||||
|
257usize,
|
||||||
|
concat!("Size of: ", stringify!(LoginInfo))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::align_of::<LoginInfo>(),
|
||||||
|
1usize,
|
||||||
|
concat!("Alignment of ", stringify!(LoginInfo))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).sDeviceAddress) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(LoginInfo),
|
||||||
|
"::",
|
||||||
|
stringify!(sDeviceAddress)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).sUserName) as usize - ptr as usize },
|
||||||
|
129usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(LoginInfo),
|
||||||
|
"::",
|
||||||
|
stringify!(sUserName)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).sPassword) as usize - ptr as usize },
|
||||||
|
193usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(LoginInfo),
|
||||||
|
"::",
|
||||||
|
stringify!(sPassword)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pub type LPLoginInfo = *mut LoginInfo;
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct StreamDate {
|
||||||
|
pub dwYear: ::std::os::raw::c_ulong,
|
||||||
|
pub dwMonth: ::std::os::raw::c_ulong,
|
||||||
|
pub dwDay: ::std::os::raw::c_ulong,
|
||||||
|
pub dwHour: ::std::os::raw::c_ulong,
|
||||||
|
pub dwMinute: ::std::os::raw::c_ulong,
|
||||||
|
pub dwSecond: ::std::os::raw::c_ulong,
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_StreamDate() {
|
||||||
|
const UNINIT: ::std::mem::MaybeUninit<StreamDate> = ::std::mem::MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::size_of::<StreamDate>(),
|
||||||
|
48usize,
|
||||||
|
concat!("Size of: ", stringify!(StreamDate))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::align_of::<StreamDate>(),
|
||||||
|
8usize,
|
||||||
|
concat!("Alignment of ", stringify!(StreamDate))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).dwYear) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(StreamDate),
|
||||||
|
"::",
|
||||||
|
stringify!(dwYear)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).dwMonth) as usize - ptr as usize },
|
||||||
|
8usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(StreamDate),
|
||||||
|
"::",
|
||||||
|
stringify!(dwMonth)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).dwDay) as usize - ptr as usize },
|
||||||
|
16usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(StreamDate),
|
||||||
|
"::",
|
||||||
|
stringify!(dwDay)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).dwHour) as usize - ptr as usize },
|
||||||
|
24usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(StreamDate),
|
||||||
|
"::",
|
||||||
|
stringify!(dwHour)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).dwMinute) as usize - ptr as usize },
|
||||||
|
32usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(StreamDate),
|
||||||
|
"::",
|
||||||
|
stringify!(dwMinute)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).dwSecond) as usize - ptr as usize },
|
||||||
|
40usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(StreamDate),
|
||||||
|
"::",
|
||||||
|
stringify!(dwSecond)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pub type LStreamDate = *mut StreamDate;
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct StreamCon {
|
||||||
|
pub lChannel: ::std::os::raw::c_ulong,
|
||||||
|
pub start: StreamDate,
|
||||||
|
pub end: StreamDate,
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_StreamCon() {
|
||||||
|
const UNINIT: ::std::mem::MaybeUninit<StreamCon> = ::std::mem::MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::size_of::<StreamCon>(),
|
||||||
|
104usize,
|
||||||
|
concat!("Size of: ", stringify!(StreamCon))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::align_of::<StreamCon>(),
|
||||||
|
8usize,
|
||||||
|
concat!("Alignment of ", stringify!(StreamCon))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).lChannel) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(StreamCon),
|
||||||
|
"::",
|
||||||
|
stringify!(lChannel)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).start) as usize - ptr as usize },
|
||||||
|
8usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(StreamCon),
|
||||||
|
"::",
|
||||||
|
stringify!(start)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize },
|
||||||
|
56usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(StreamCon),
|
||||||
|
"::",
|
||||||
|
stringify!(end)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
pub type LPStream = *mut StreamCon;
|
||||||
|
extern "C" {
|
||||||
|
pub fn playback(loginInfo: LPLoginInfo, stream: LPStream) -> ::std::os::raw::c_int;
|
||||||
|
}
|
|
@ -10,29 +10,39 @@
|
||||||
// typedef unsigned long ULONG;
|
// typedef unsigned long ULONG;
|
||||||
// typedef unsigned long unsigned long ;
|
// typedef unsigned long unsigned long ;
|
||||||
// // #endif //#ifdef __LINUX__
|
// // #endif //#ifdef __LINUX__
|
||||||
|
#ifdef __cplusplus
|
||||||
typedef struct {
|
extern "C"
|
||||||
char sDeviceAddress[129];
|
|
||||||
char sUserName[64];
|
|
||||||
char sPassword[64];
|
|
||||||
} LoginInfo, *LPLoginInfo;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
{
|
||||||
unsigned long dwYear; //年
|
#endif
|
||||||
unsigned long dwMonth; //月
|
typedef struct
|
||||||
unsigned long dwDay; //日
|
{
|
||||||
unsigned long dwHour; //时
|
char sDeviceAddress[129];
|
||||||
unsigned long dwMinute; //分
|
char sUserName[64];
|
||||||
unsigned long dwSecond; //秒
|
char sPassword[64];
|
||||||
} StreamDate, *LStreamDate;
|
} LoginInfo, *LPLoginInfo;
|
||||||
typedef struct {
|
|
||||||
unsigned long lChannel;
|
typedef struct
|
||||||
StreamDate start;
|
{
|
||||||
StreamDate end;
|
unsigned long dwYear; // 年
|
||||||
} StreamCon, *LPStream;
|
unsigned long dwMonth; // 月
|
||||||
|
unsigned long dwDay; // 日
|
||||||
|
unsigned long dwHour; // 时
|
||||||
|
unsigned long dwMinute; // 分
|
||||||
|
unsigned long dwSecond; // 秒
|
||||||
|
} StreamDate, *LStreamDate;
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned long lChannel;
|
||||||
|
StreamDate start;
|
||||||
|
StreamDate end;
|
||||||
|
} StreamCon, *LPStream;
|
||||||
|
|
||||||
|
#define HPR_OK 0
|
||||||
|
#define HPR_ERROR -1
|
||||||
|
int playback(LPLoginInfo loginInfo, LPStream stream);
|
||||||
|
int getCfg(LPLoginInfo loginInfo);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#define HPR_OK 0
|
|
||||||
#define HPR_ERROR -1
|
|
||||||
int playback(LPLoginInfo loginInfo, LPStream stream);
|
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,117 @@
|
||||||
|
#include "HkStreamer.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstring>
|
||||||
|
#include <map>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <time.h>
|
||||||
|
using namespace std;
|
||||||
|
bool check_key(std::map<std::string, std::string> *m, string key)
|
||||||
|
{
|
||||||
|
// Key is not present
|
||||||
|
if (m->find(key) == m->end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void parseTime(string timeStr,struct tm *timeOut){
|
||||||
|
strptime(timeStr.c_str(), "%Y%m%dT%H%M%S",timeOut);
|
||||||
|
}
|
||||||
|
void parseArgs(int argc, char *argv[], std::map<std::string, std::string> *paramMap)
|
||||||
|
{
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{"cnd", required_argument, NULL, 'c'},
|
||||||
|
{"url", required_argument, NULL, 'i'},
|
||||||
|
{"user", required_argument, NULL, 'u'},
|
||||||
|
{"passwd", required_argument, NULL, 'p'},
|
||||||
|
{"device", required_argument, NULL, 'd'},
|
||||||
|
{"channel", required_argument, NULL, 'c'},
|
||||||
|
{"start", required_argument, NULL, 's'},
|
||||||
|
{"end", required_argument, NULL, 'e'},
|
||||||
|
};
|
||||||
|
int c;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
int opt_index = 0;
|
||||||
|
c = getopt_long(argc, argv, "c:u:p:", long_options, &opt_index);
|
||||||
|
if (c == -1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string paraName(1, char(c));
|
||||||
|
|
||||||
|
std::cout << "paraName:" << paraName << std::endl;
|
||||||
|
std::string paraValue = optarg;
|
||||||
|
|
||||||
|
(*paramMap)[paraName] = paraValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void error(string msg)
|
||||||
|
{
|
||||||
|
cerr << msg << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
std::map<std::string, std::string> pMap;
|
||||||
|
parseArgs(argc, argv, &pMap);
|
||||||
|
std::string cmd = pMap.at("cmd");
|
||||||
|
if (!check_key(&pMap, "u"))
|
||||||
|
{
|
||||||
|
error("Must set user");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!check_key(&pMap, "d"))
|
||||||
|
{
|
||||||
|
error("Must set device address");
|
||||||
|
}
|
||||||
|
LoginInfo loginInfo = {0};
|
||||||
|
strcpy(loginInfo.sDeviceAddress, pMap.at("d").c_str());
|
||||||
|
strcpy(loginInfo.sUserName, pMap.at("u").c_str());
|
||||||
|
strcpy(loginInfo.sPassword, pMap.at("p").c_str());
|
||||||
|
if (cmd == "playback")
|
||||||
|
{
|
||||||
|
if (!check_key(&pMap, "c"))
|
||||||
|
{
|
||||||
|
error("Muset set channel");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!check_key(&pMap, "s"))
|
||||||
|
{
|
||||||
|
error("Must set start time");
|
||||||
|
}
|
||||||
|
if (!check_key(&pMap, "e"))
|
||||||
|
{
|
||||||
|
error("Must set end time");
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamCon stream = {0};
|
||||||
|
|
||||||
|
stream.lChannel = stol(pMap.at("c"));
|
||||||
|
string startStr = pMap.at("s");
|
||||||
|
struct tm start;
|
||||||
|
parseTime(startStr, &start);
|
||||||
|
stream.start.dwYear = start.tm_year;
|
||||||
|
stream.start.dwMonth = start.tm_mon;
|
||||||
|
stream.start.dwDay = start.tm_mday;
|
||||||
|
stream.start.dwHour = start.tm_hour;
|
||||||
|
stream.start.dwMinute = start.tm_min;
|
||||||
|
stream.start.dwSecond = start.tm_sec;
|
||||||
|
string endStr = pMap.at("e");
|
||||||
|
struct tm end;
|
||||||
|
parseTime(endStr, &end);
|
||||||
|
stream.end.dwYear = end.tm_year;
|
||||||
|
stream.end.dwMonth = end.tm_mon;
|
||||||
|
stream.end.dwDay = end.tm_mday;
|
||||||
|
stream.end.dwHour = end.tm_hour;
|
||||||
|
stream.end.dwMinute = end.tm_min;
|
||||||
|
stream.end.dwSecond = end.tm_sec;
|
||||||
|
playback(&loginInfo, &stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
// getCfg(&loginInfo);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue