1. 增加文档
This commit is contained in:
parent
d74bfa4b7a
commit
93620d6def
103
README.md
Normal file
103
README.md
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
# README
|
||||||
|
|
||||||
|
## SDK协议接口详解 HDSDK.h
|
||||||
|
|
||||||
|
> 详情请看 HDSDK.h 头文件
|
||||||
|
|
||||||
|
1. SDK协议封装了协议部分, 网络部分由用户自己实现, 只需给协议提供发送数据的回调和读取xml数据的回调接口即可. 接下来只需要将网络读取的数据传入协议即可.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// 创建协议通信
|
||||||
|
IHDProtocol sdk = CreateProtocol();
|
||||||
|
|
||||||
|
// 设置协议
|
||||||
|
// kSetReadXml = 0x0001
|
||||||
|
// kSetReadXmlData = 0x0002
|
||||||
|
// void readXml(const char *xml, int len, int errorCode, void *userData)
|
||||||
|
SetProtocolFunc(sdk, kSetReadXml, func);
|
||||||
|
|
||||||
|
// 设置这个回调, 这个回调就是需要write的发送数据的地方
|
||||||
|
// kSetSendFunc = 0x0003
|
||||||
|
// kSetSendFuncData = 0x0004
|
||||||
|
// int sendDataToNet(const char *data, int len, void *userData), 返回0或1, 1成功 0失败
|
||||||
|
SetProtocolFunc(sdk, kSetReadXml, func);
|
||||||
|
|
||||||
|
// 开始执行协议协商
|
||||||
|
RunProtocol(sdk);
|
||||||
|
|
||||||
|
// 发送xml数据通信sdk
|
||||||
|
SendXml(sdk, xml, xmlLen);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
// 将所有读取到的数据都推入UpdateReadData
|
||||||
|
data = read();
|
||||||
|
UpdateReadData(sdk, data, data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 释放协议体
|
||||||
|
FreeProtocol(sdk);
|
||||||
|
```
|
||||||
|
|
||||||
|
## 使用SDK信息体构建xml SDKInfo.h
|
||||||
|
|
||||||
|
> 详情请看 SDKInfo.h 头文件
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
static void readXml(const char *xml, int len, int errorCode, void *userData)
|
||||||
|
{
|
||||||
|
if (errorCode != 0) {
|
||||||
|
printf("error code[%d]\n", errorCode);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 解析xml
|
||||||
|
ISDKInfo info = (ISDKInfo)userData;
|
||||||
|
ParseXml(info, xml, len);
|
||||||
|
|
||||||
|
printf("模式[%d]\n", GetLightInfoMode(info));
|
||||||
|
printf("亮度值[%d]\n", GetLightInfoDefaultLight(info));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建xml信息体
|
||||||
|
ISDKInfo sdkInfo = CreateSDKInfo();
|
||||||
|
|
||||||
|
// 创建协议通信
|
||||||
|
IHDProtocol sdk = CreateProtocol();
|
||||||
|
|
||||||
|
// 设置协议
|
||||||
|
// kSetReadXml = 0x0001
|
||||||
|
// kSetReadXmlData = 0x0002
|
||||||
|
// void readXml(const char *xml, int len, int errorCode, void *userData)
|
||||||
|
SetProtocolFunc(sdk, kSetReadXml, func);
|
||||||
|
|
||||||
|
// 设置这个回调, 这个回调就是需要write的发送数据的地方
|
||||||
|
// kSetSendFunc = 0x0003
|
||||||
|
// kSetSendFuncData = 0x0004
|
||||||
|
// int sendDataToNet(const char *data, int len, void *userData), 返回0或1, 1成功 0失败
|
||||||
|
SetProtocolFunc(sdk, kSetReadXml, readXml);
|
||||||
|
SetProtocolFunc(sdk, kSetSendFuncData, sdkInfo);
|
||||||
|
|
||||||
|
// 开始执行协议协商
|
||||||
|
RunProtocol(sdk);
|
||||||
|
|
||||||
|
// 发送获取亮度请求
|
||||||
|
// kGetLightInfo = 0x1000
|
||||||
|
UpdateItem(sdk, sdkInfo, kGetLightInfo);
|
||||||
|
|
||||||
|
// 设置亮度信息体, 模式, 亮度值
|
||||||
|
SetLightInfo(sdkInfo, 0, 100);
|
||||||
|
|
||||||
|
// 发送设置亮度请求
|
||||||
|
// kSetLightInfo = 0x1001
|
||||||
|
UpdateItem(sdk, sdkInfo, kSetLightInfo);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
// 将所有读取到的数据都推入UpdateReadData
|
||||||
|
data = read();
|
||||||
|
UpdateReadData(sdk, data, data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeSDKInfo(sdkInfo);
|
||||||
|
FreeProtocol(sdk);
|
||||||
|
```
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ void DLL_CALL FreeSDKInfo(sdk::ISDKInfo info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HBool DLL_CALL ParseXml(const char *xml, int len, ISDKInfo info)
|
HBool DLL_CALL ParseXml(ISDKInfo info, const char *xml, int len)
|
||||||
{
|
{
|
||||||
if (xml == nullptr || info == nullptr || len <= 0) {
|
if (xml == nullptr || info == nullptr || len <= 0) {
|
||||||
return HFalse;
|
return HFalse;
|
||||||
|
|||||||
@ -24,7 +24,7 @@ HD_API ISDKInfo DLL_CALL CreateSDKInfo();
|
|||||||
///< 释放信息体
|
///< 释放信息体
|
||||||
HD_API void DLL_CALL FreeSDKInfo(ISDKInfo info);
|
HD_API void DLL_CALL FreeSDKInfo(ISDKInfo info);
|
||||||
///< 解析xml生成对应数据信息
|
///< 解析xml生成对应数据信息
|
||||||
HD_API HBool DLL_CALL ParseXml(const char *xml, int len, ISDKInfo info);
|
HD_API HBool DLL_CALL ParseXml(ISDKInfo info, const char *xml, int len);
|
||||||
|
|
||||||
enum eUpdateItem {
|
enum eUpdateItem {
|
||||||
kGetLightInfo = 0x1000, ///< 获取亮度信息
|
kGetLightInfo = 0x1000, ///< 获取亮度信息
|
||||||
|
|||||||
@ -35,7 +35,7 @@ static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
|||||||
printf("error code[%d]\n", errorCode);
|
printf("error code[%d]\n", errorCode);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
ParseXml(xml, len, info->info);
|
ParseXml(info->info, xml, len);
|
||||||
|
|
||||||
std::cout << "dhcp:" << GetEhtInfoDhcp(info->info) << "\n"
|
std::cout << "dhcp:" << GetEhtInfoDhcp(info->info) << "\n"
|
||||||
<< "ip:" << GetEhtInfoIp(info->info) << "\n"
|
<< "ip:" << GetEhtInfoIp(info->info) << "\n"
|
||||||
|
|||||||
@ -35,7 +35,7 @@ static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
|||||||
printf("error code[%d]\n", errorCode);
|
printf("error code[%d]\n", errorCode);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
ParseXml(xml, len, info->info);
|
ParseXml(info->info, xml, len);
|
||||||
|
|
||||||
std::cout << "mode:" << GetLightInfoMode(info->info) << "\n"
|
std::cout << "mode:" << GetLightInfoMode(info->info) << "\n"
|
||||||
<< "defaultLight:" << GetLightInfoDefaultLight(info->info) << "\n"
|
<< "defaultLight:" << GetLightInfoDefaultLight(info->info) << "\n"
|
||||||
|
|||||||
@ -35,7 +35,7 @@ static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
|||||||
printf("error code[%d]\n", errorCode);
|
printf("error code[%d]\n", errorCode);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
ParseXml(xml, len, info->info);
|
ParseXml(info->info, xml, len);
|
||||||
|
|
||||||
std::cout << "mode:" << GetSystemVolumeInfoMode(info->info) << "\n"
|
std::cout << "mode:" << GetSystemVolumeInfoMode(info->info) << "\n"
|
||||||
<< "volume:" << GetSystemVolumeInfoVolume(info->info) << "\n"
|
<< "volume:" << GetSystemVolumeInfoVolume(info->info) << "\n"
|
||||||
|
|||||||
@ -35,7 +35,7 @@ static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
|||||||
printf("error code[%d]\n", errorCode);
|
printf("error code[%d]\n", errorCode);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
ParseXml(xml, len, info->info);
|
ParseXml(info->info, xml, len);
|
||||||
|
|
||||||
std::cout << "ip:" << GetTcpServerInfoIp(info->info) << "\n"
|
std::cout << "ip:" << GetTcpServerInfoIp(info->info) << "\n"
|
||||||
<< "port:" << GetTcpServerInfoPort(info->info) << "\n"
|
<< "port:" << GetTcpServerInfoPort(info->info) << "\n"
|
||||||
|
|||||||
@ -35,7 +35,7 @@ static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
|||||||
printf("error code[%d]\n", errorCode);
|
printf("error code[%d]\n", errorCode);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
ParseXml(xml, len, info->info);
|
ParseXml(info->info, xml, len);
|
||||||
|
|
||||||
std::cout << "timeZone:" << GetTimeInfoTimeZone(info->info) << "\n"
|
std::cout << "timeZone:" << GetTimeInfoTimeZone(info->info) << "\n"
|
||||||
<< "summer:" << GetTimeInfoSummer(info->info) << "\n"
|
<< "summer:" << GetTimeInfoSummer(info->info) << "\n"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user