📄 utility.c
字号:
#include "Utility.h"
#include "mainprofile_error.h"
int HandleBasicArgument(int argc, char* argv[], TSERVER_INFO *ptServerInfo)
{
int nCnt;
memset(ptServerInfo, 0, sizeof(TSERVER_INFO));
ptServerInfo->dwFtpPort = 0;
ptServerInfo->dwHttpPort = 0;
for (nCnt = 1; nCnt < argc; nCnt++)
{
if (strncmp(argv[nCnt], "-I", 2) == 0 && strlen(argv[nCnt]) > 2)
{
strncpy(ptServerInfo->chHostName, &argv[nCnt][2], sizeof(ptServerInfo->chHostName));
}
else if (strncmp(argv[nCnt], "-H", 2) == 0 && strlen(argv[nCnt]) > 2)
{
ptServerInfo->dwHttpPort = atoi(&argv[nCnt][2]);
}
else if (strncmp(argv[nCnt], "-F", 2) == 0 && strlen(argv[nCnt]) > 2)
{
ptServerInfo->dwFtpPort = atoi(&argv[nCnt][2]);
}
else if (strncmp(argv[nCnt], "-U", 2) == 0 && strlen(argv[nCnt]) > 2)
{
strncpy(ptServerInfo->chUserName, &argv[nCnt][2], sizeof(ptServerInfo->chUserName));
}
else if (strncmp(argv[nCnt], "-P", 2) == 0 && strlen(argv[nCnt]) > 2)
{
strncpy(ptServerInfo->chPassWord, & argv[nCnt][2], sizeof(ptServerInfo->chPassWord));
}
else if (strncmp(argv[nCnt], "-T", 2) == 0 && strlen(argv[nCnt]) > 2)
{
strncpy(ptServerInfo->chServerType, &argv[nCnt][2], sizeof(ptServerInfo->chServerType));
}
}
if (strlen(ptServerInfo->chHostName) == 0)
{
printf("please input IP address\n");
return -1;
}
return 0;
}
SCODE ServerUtlInit(HANDLE *phServerUtl, HANDLE *phDevice, char *lpszModelName, TSERVER_INFO tServerInfo)
{
TSERVERUTL_DEV_PROPERTY tDevProperty;
SCODE scRet;
memset(&tDevProperty, 0, sizeof(tDevProperty));
tDevProperty.lpszHost = tServerInfo.chHostName;
tDevProperty.lpszPassword = tServerInfo.chPassWord;
tDevProperty.lpszUserName = tServerInfo.chUserName;
tDevProperty.dwTimeout = 30000;
tDevProperty.dwHttpPort = tServerInfo.dwHttpPort;
scRet = ServerUtl_Initial(phServerUtl, SERVERUTL_VERSION);
if (scRet != S_OK)
{
printf("ServerUtl_Initial fail %X\n", scRet);
return scRet;
}
scRet = ServerUtl_CreateDevice(*phServerUtl, phDevice);
if (scRet != S_OK)
{
printf("ServerUtl_CreateDevice fail %X\n", scRet);
scRet = ServerUtl_Release(phServerUtl);
if (scRet != S_OK)
printf("Server_Release fail %X(%p)\n", scRet, *phServerUtl);
return scRet;
}
scRet = ServerUtl_SetDeviceProperty(*phDevice, tDevProperty, FALSE);
if (scRet != S_OK)
{
printf("ServerUtl_SetDeviceProperty fail %X\n", scRet);
if (scRet == SERVUTL_E_AUTH)
printf("User Name or Password incorrect\n");
else
printf("Can't connect to server\n");
ServerUtlRelease(phServerUtl, phDevice);
return scRet;
}
lpszModelName[0] = 0;
scRet = ServerUtl_GetDeviceModel(*phDevice, lpszModelName);
if (scRet != S_OK)
{
printf("ServerUtl_GetDeviceModel failed %X\n", scRet);
ServerUtlRelease(phServerUtl, phDevice);
return scRet;
}
scRet = ServerUtl_OpenDevice(*phDevice, lpszModelName);
if (scRet != S_OK)
{
printf("ServerUtl_OpenDevice failed %X\n", scRet);
ServerUtlRelease(phServerUtl, phDevice);
return scRet;
}
return S_OK;
}
SCODE ServerUtlRelease(HANDLE *phServerUtl, HANDLE *phDevice)
{
SCODE scRet;
scRet = ServerUtl_DeleteDevice(*phDevice);
if (scRet != S_OK)
{
printf("Server device error: %X (%p)\n", scRet, *phDevice);
return scRet;
}
scRet = ServerUtl_Release(phServerUtl);
if (scRet != S_OK)
{
printf("ServerUtl release error: %X (%p)\n", scRet, *phServerUtl);
return scRet;
}
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -