-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdkclient.cpp
171 lines (155 loc) · 4.76 KB
/
sdkclient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <stdio.h>
#include <memory.h>
#include <unistd.h>
#include <iostream>
#include <arpa/inet.h>
#include "netsdk.h"
using namespace std;
long g_LoginID=0;
char hostname[64]="";
char username[NET_NAME_PASSWORD_LEN]="";
char password[NET_NAME_PASSWORD_LEN]="";
char action[64];
char param1[32];
char param2[32];
int error=0;
DWORD dwRetLen = 0;
int nWaitTime = 10000;
bool isValidIpAddress(char *ipAddress)
{
struct sockaddr_in sa;
int result = inet_pton(AF_INET, ipAddress, &(sa.sin_addr));
return result != 0;
}
int main(int argc, char* argv[])
{
if(argc<4) {
printf("\nUsage: %s [IP|CloudID] [username] [password] [action]\n Possible actions: debugcamera,format,password,localsearch\n\n",argv[0]);
return 0;
}
strcpy (hostname, argv[1]);
strcpy (username, argv[2]);
strcpy (password, argv[3]);
sprintf (action, argv[4]);
sprintf (param1, argv[5]);
sprintf (param2, argv[6]);
H264_DVR_Init(NULL,NULL);
H264_DVR_SetConnectTime(3000,1);
//printf("Hostname: %s, Username: %s, Password: \"%s\"\n", hostname,username,password);
H264_DVR_DEVICEINFO lpDeviceInfo;
memset(&lpDeviceInfo,0,sizeof(lpDeviceInfo));
if (isValidIpAddress(hostname)) {
g_LoginID = H264_DVR_Login((char*)hostname, 34567, (char*)username,(char*)password,(LPH264_DVR_DEVICEINFO)(&lpDeviceInfo),&error);
}
else{
g_LoginID = H264_DVR_Login_Cloud((char*)hostname, 34567, (char*)username,(char*)password,(LPH264_DVR_DEVICEINFO)(&lpDeviceInfo),&error,NULL);
}
printf("g_LoginID=%lui,nError:%d\n",g_LoginID,error);
if ( g_LoginID <= 0 )
{
string strErr;
switch (error)
{
case H264_DVR_PASSWORD_NOT_VALID:
strErr = printf("Error.PwdErr");
break;
case H264_DVR_NOPOWER:
strErr = printf("Error.NoPower");
break;
case H264_DVR_LOGIN_USER_NOEXIST:
strErr = printf("Error.UserNotExisted");
break;
case H264_DVR_USER_LOCKED:
strErr = printf("Login.Locked");
break;
case H264_DVR_USER_IN_BLACKLIST:
strErr = printf("Error.InBlackList");
break;
case H264_DVR_USER_HAS_USED:
strErr = printf("Error.HasLogined");
break;
case H264_DVR_CONNECT_DEVICE_ERROR:
strErr = printf("Error.NotFound");
break;
case H264_DVR_CLOUD_LOGIN_ERR:
strErr = printf("Log.Error") + lpDeviceInfo.sCloudErrCode;
break;
default:
{
char ch[10];
strErr = printf("Log.Error") + ch;
}
break;
}
printf("error?");
}
BOOL bSuccess = H264_DVR_GetDevConfig(g_LoginID,E_SDK_CONFIG_SYSINFO,0,(char *)&lpDeviceInfo,sizeof(H264_DVR_DEVICEINFO),&dwRetLen,nWaitTime);
//printf("bSuccess=%i,RetLen:%lui\n",bSuccess,dwRetLen);
if (bSuccess && dwRetLen == sizeof (H264_DVR_DEVICEINFO))
{
printf("Hardware : %s\n",lpDeviceInfo.sHardWare);
printf("Software : %s\n",lpDeviceInfo.sSoftWareVersion);
printf("SerialNumber: %s\n",lpDeviceInfo.sSerialNumber);
}
if (!strcmp(action,"debugcamera")) {
printf("DebugCamera\n");
}
if (!strcmp(action,"format")) {
printf("Formatting disk...");
SDK_StorageDeviceControl pStorageCtl;
memset(&pStorageCtl,0,sizeof(pStorageCtl));
pStorageCtl.iAction = SDK_STORAGE_DEVICE_CONTROL_CLEAR;
pStorageCtl.iPartNo = 0;
pStorageCtl.iSerialNo = 0;
pStorageCtl.iType = SDK_STORAGE_DEVICE_CLEAR_DATA;
int nRet = H264_DVR_SetDevConfig(g_LoginID,E_SDK_CONFIG_DISK_MANAGER,0,(char *)&pStorageCtl,sizeof(pStorageCtl),nWaitTime);
if (nRet >=0 ){
printf("success");
}
}
if (!strcmp(action,"password")) {
printf("Change password...");
char szMD5[100] = {0};
//H264_DVR_Encryptsword((char *)szMD5, param1);
_CONF_MODIFY_PSW psw;
strcpy (psw.sUserName, "admin");
strcpy (psw.Password, password);
strcpy (psw.NewPassword, (char *)szMD5);
int nRet = H264_DVR_SetDevConfig(g_LoginID, E_SDK_CONFIG_MODIFY_PSW, 0, (char *)&psw, sizeof(_CONF_MODIFY_PSW));
if (nRet >=0 ){
printf("success");
}
}
if (!strcmp(action,"localsearch")) {
printf("Searching...");
unsigned long lRetLen=0;
SDK_NetDevList m_Devlist;
memset( &m_Devlist,0,sizeof(m_Devlist));
int nRet = H264_DVR_GetDevConfig(g_LoginID, E_SDK_CFG_NET_LOCALSEARCH, -1, (char*)&m_Devlist,sizeof(m_Devlist),&lRetLen,15000);
if (nRet >=0 ){
for (int i= 0; i<m_Devlist.vNetDevNum;i++)
{
printf ("Found: %i %d.%d.%d.%d %s %s \n",i,\
m_Devlist.vNetDevList[i].HostIP.c[0], \
m_Devlist.vNetDevList[i].HostIP.c[1], \
m_Devlist.vNetDevList[i].HostIP.c[2], \
m_Devlist.vNetDevList[i].HostIP.c[3], \
m_Devlist.vNetDevList[i].sMac, \
m_Devlist.vNetDevList[i].sSn);
}
}
}
if(g_LoginID>0){
printf("\nLogin ok\n");
}
else {
printf("Error\n");
}
if(g_LoginID>0)
{
H264_DVR_Logout(g_LoginID);
printf("Logout...\n");
}
H264_DVR_Cleanup();
return 0;
}