1. V1.0.0.0版本完成
This commit is contained in:
commit
2c646bcbcb
68
CMakeLists.txt
Normal file
68
CMakeLists.txt
Normal file
@ -0,0 +1,68 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# 设置交叉编译器
|
||||
#set(CMAKE_CXX_COMPILER /tmp/g++)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
|
||||
project(HDSDK LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_subdirectory(Protocol)
|
||||
|
||||
set(ENABLE_DEMO OFF)
|
||||
if(ENABLE_DEMO)
|
||||
add_executable(sendXml demo/sendXml.cpp)
|
||||
target_include_directories(sendXml PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Protocol
|
||||
)
|
||||
target_link_libraries(sendXml PRIVATE HDSDK)
|
||||
|
||||
add_executable(sendFile demo/sendFile.cpp)
|
||||
target_include_directories(sendFile PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Protocol
|
||||
)
|
||||
target_link_libraries(sendFile PRIVATE HDSDK)
|
||||
|
||||
add_executable(lightInfo demo/lightInfo.cpp)
|
||||
target_include_directories(lightInfo PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Protocol
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SDK
|
||||
)
|
||||
target_link_libraries(lightInfo PRIVATE HDSDK)
|
||||
|
||||
add_executable(systemVolume demo/systemVolume.cpp)
|
||||
target_include_directories(systemVolume PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Protocol
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SDK
|
||||
)
|
||||
target_link_libraries(systemVolume PRIVATE HDSDK)
|
||||
|
||||
add_executable(tcpServer demo/tcpServer.cpp)
|
||||
target_include_directories(tcpServer PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Protocol
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SDK
|
||||
)
|
||||
target_link_libraries(tcpServer PRIVATE HDSDK)
|
||||
|
||||
add_executable(time demo/time.cpp)
|
||||
target_include_directories(time PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Protocol
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SDK
|
||||
)
|
||||
target_link_libraries(time PRIVATE HDSDK)
|
||||
|
||||
add_executable(eth demo/eth.cpp)
|
||||
target_include_directories(eth PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Protocol
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SDK
|
||||
)
|
||||
target_link_libraries(eth PRIVATE HDSDK)
|
||||
endif()
|
||||
38
Protocol/CMakeLists.txt
Normal file
38
Protocol/CMakeLists.txt
Normal file
@ -0,0 +1,38 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(HDSDK LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
set(ENABLE_SDK ON)
|
||||
if (ENABLE_SDK)
|
||||
list(APPEND SDK_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/tinyxml2.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/HXml.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/SDKInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HSDKInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HEthernetInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HGeneralInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HLightInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HOTherInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HScreenFunctionInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HSDKInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HSensorInfo.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HTimeInfo.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(HDSDK SHARED
|
||||
HDSDK.cpp
|
||||
${SDK_FILES}
|
||||
)
|
||||
|
||||
if (ENABLE_SDK)
|
||||
target_include_directories(HDSDK PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../SDK)
|
||||
target_include_directories(HDSDK PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data)
|
||||
endif()
|
||||
|
||||
target_include_directories(HDSDK PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(HDSDK PRIVATE -static-libgcc -static-libstdc++)
|
||||
set_target_properties(HDSDK PROPERTIES LINK_FLAGS "-nodefaultlibs")
|
||||
add_definitions(-DUSE_HD_LIB)
|
||||
843
Protocol/HDSDK.cpp
Normal file
843
Protocol/HDSDK.cpp
Normal file
@ -0,0 +1,843 @@
|
||||
|
||||
|
||||
#include "HDSDK.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
|
||||
#define MD5_LENGHT (32)
|
||||
#define XML_MAX (9200)
|
||||
#define LOCAL_TCP_VERSION (0x1000009)
|
||||
#define LOCAL_UDP_VERSION (0x1000009)
|
||||
|
||||
|
||||
typedef unsigned long long huint64;
|
||||
typedef unsigned int huint32;
|
||||
typedef unsigned short huint16;
|
||||
typedef unsigned char huint8;
|
||||
|
||||
typedef long long hint64;
|
||||
typedef int hint32;
|
||||
typedef short hint16;
|
||||
typedef char hint8;
|
||||
typedef float hfloat;
|
||||
typedef double hdouble;
|
||||
|
||||
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
||||
enum eHCmdType
|
||||
{
|
||||
kTcpHeartbeatAsk = 0x005f, ///< TCP心跳包请求
|
||||
kTcpHeartbeatAnswer = 0x0060, ///< TCP心跳包反馈
|
||||
kSearchDeviceAsk = 0x1001, ///< 搜索设备请求
|
||||
kSearchDeviceAnswer = 0x1002, ///< 搜索设备应答
|
||||
kErrorAnswer = 0x2000, ///< 出错反馈
|
||||
|
||||
kSDKServiceAsk = 0x2001, ///< 版本协商请求
|
||||
kSDKServiceAnswer = 0x2002, ///< 版本协商应答
|
||||
kSDKCmdAsk = 0x2003, ///< sdk命令请求
|
||||
kSDKCmdAnswer = 0x2004, ///< sdk命令反馈
|
||||
kFileStartAsk = 0x8001, ///< 文件开始传输请求
|
||||
kFileStartAnswer = 0x8002, ///< 文件开始传输应答
|
||||
kFileContentAsk = 0x8003, ///< 携带文件内容的请求
|
||||
kFileContentAnswer = 0x8004, ///< 写文件内容的应答
|
||||
kFileEndAsk = 0x8005, ///< 文件结束传输请求
|
||||
kFileEndAnswer = 0x8006, ///< 文件结束传输应答
|
||||
kReadFileAsk = 0x8007, ///< 回读文件请求
|
||||
kReadFileAnswer = 0x8008, ///< 回读文件应答
|
||||
};
|
||||
|
||||
|
||||
template <typename _Func>
|
||||
class HCallBack
|
||||
{
|
||||
public:
|
||||
HCallBack()
|
||||
: userData_(nullptr)
|
||||
{}
|
||||
|
||||
void Bind(const std::function<_Func> &func) {
|
||||
callBack_ = func;
|
||||
}
|
||||
|
||||
void ClearFunc() { callBack_ = std::function<_Func>();}
|
||||
|
||||
void SetUserData(void *userData) {
|
||||
userData_ = userData;
|
||||
}
|
||||
|
||||
template <typename ..._Args>
|
||||
#if __cplusplus >= 201402L
|
||||
decltype(auto)
|
||||
#else
|
||||
typename std::result_of<std::function<_Func>(_Args..., void *)>::type
|
||||
#endif
|
||||
Emit(_Args &&...args) {
|
||||
auto func(callBack_);
|
||||
return func(std::forward<_Args>(args)..., userData_);
|
||||
}
|
||||
|
||||
template <typename ..._Args>
|
||||
#if __cplusplus >= 201402L
|
||||
decltype(auto)
|
||||
#else
|
||||
typename std::result_of<std::function<_Func>(_Args..., void *)>::type
|
||||
#endif
|
||||
operator()(_Args &&...args) {
|
||||
return this->Emit(std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
bool IsCanUse() const { return bool(callBack_); }
|
||||
|
||||
private:
|
||||
std::function<_Func> callBack_;
|
||||
void *userData_;
|
||||
};
|
||||
|
||||
|
||||
class HAny
|
||||
{
|
||||
private:
|
||||
struct DataBase;
|
||||
using DataBasePtrType = std::shared_ptr<DataBase>;
|
||||
struct DataBase{
|
||||
virtual ~DataBase() {}
|
||||
virtual DataBasePtrType Clone() const = 0;
|
||||
virtual const std::type_info &Type() const = 0;
|
||||
};
|
||||
|
||||
template<typename _T>
|
||||
struct Data : public DataBase
|
||||
{
|
||||
template<typename...Args>
|
||||
Data(Args&&...args) : data(std::forward<Args>(args)...){ }
|
||||
|
||||
virtual DataBasePtrType Clone() const override { return DataBasePtrType(new Data(data)); }
|
||||
virtual const std::type_info &Type() const override { return typeid(_T); }
|
||||
|
||||
_T data;
|
||||
};
|
||||
|
||||
DataBasePtrType Clone() const {
|
||||
if (data_) {
|
||||
return data_->Clone();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
public:
|
||||
HAny() {}
|
||||
HAny(const HAny &other) : data_(other.data_) {}
|
||||
template <typename _T, typename = typename std::enable_if<!std::is_same<typename std::decay<_T>::type, HAny>::value, _T>::type>
|
||||
HAny(_T &&t) : data_(new Data<typename std::decay<_T>::type>(std::forward<_T>(t))) {}
|
||||
|
||||
const std::type_info &Type() const { return data_ ? data_->Type() : typeid(void); }
|
||||
|
||||
template <typename _T>
|
||||
bool IsType() const { return Type() == typeid(_T); }
|
||||
|
||||
template <typename _T>
|
||||
_T& Cast() const {
|
||||
Detach();
|
||||
auto p = static_cast<Data<typename std::decay<_T>::type>*>(this->data_.get());
|
||||
return p->data;
|
||||
}
|
||||
|
||||
private:
|
||||
void Detach() const {
|
||||
if (!data_ || data_.unique()) {
|
||||
return ;
|
||||
}
|
||||
|
||||
data_ = data_->Clone();
|
||||
}
|
||||
|
||||
private:
|
||||
mutable DataBasePtrType data_;
|
||||
};
|
||||
|
||||
|
||||
template <typename _T>
|
||||
std::string IconvStr(_T value) {
|
||||
std::string ret;
|
||||
for (std::size_t i = 0; i < sizeof(_T); ++i) {
|
||||
ret.push_back(char(value & 0xff));
|
||||
value = value >> 8;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename _T>
|
||||
_T StrIconv(const char *value, std::size_t len = std::numeric_limits<std::size_t>::max()) {
|
||||
_T ret = _T();
|
||||
for (std::size_t i = 0; i < sizeof(typename std::remove_cv<_T>::type) && i < len; ++i) {
|
||||
ret = ret | ((value[i] & 0xff) << (8 * i));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename _T>
|
||||
_T StrIconv(const std::string &value) { return StrIconv<_T>(value.data(), value.size()); }
|
||||
|
||||
|
||||
static std::list<std::string> SplitSdkData(const std::string &xml)
|
||||
{
|
||||
std::list<std::string> queue;
|
||||
int size = static_cast<int>(xml.size());
|
||||
huint32 index = 0;
|
||||
|
||||
for (; size > XML_MAX; size -= XML_MAX, index += XML_MAX){
|
||||
std::string data = IconvStr<huint16>(12 + XML_MAX);
|
||||
data.append(IconvStr<huint16>(kSDKCmdAsk));
|
||||
data.append(IconvStr<huint32>(xml.size()));
|
||||
data.append(IconvStr<huint32>(index));
|
||||
data.append(xml.data() + index, XML_MAX);
|
||||
|
||||
queue.emplace_back(std::move(data));
|
||||
}
|
||||
|
||||
if (size > 0){
|
||||
std::string data = IconvStr<huint16>(12 + static_cast<huint16>(size));
|
||||
data.append(IconvStr<huint16>(kSDKCmdAsk));
|
||||
data.append(IconvStr<huint32>(xml.size()));
|
||||
data.append(IconvStr<huint32>(index));
|
||||
data.append(xml.data() + index, size);
|
||||
|
||||
queue.emplace_back(std::move(data));
|
||||
}
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
static std::list<std::string> SplitFileData(const char *fileData, int size)
|
||||
{
|
||||
std::list<std::string> queue;
|
||||
huint32 index = 0;
|
||||
|
||||
for (; size > XML_MAX; size -= XML_MAX, index += XML_MAX){
|
||||
std::string data = IconvStr<huint16>(4 + XML_MAX);
|
||||
data.append(IconvStr<huint16>(kFileContentAsk));
|
||||
data.append(fileData + index, XML_MAX);
|
||||
|
||||
queue.emplace_back(std::move(data));
|
||||
}
|
||||
|
||||
if (size > 0){
|
||||
std::string data = IconvStr<huint16>(4 + static_cast<huint16>(size));
|
||||
data.append(IconvStr<huint16>(kFileContentAsk));
|
||||
data.append(fileData + index, size);
|
||||
|
||||
queue.emplace_back(std::move(data));
|
||||
}
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
|
||||
static std::string &Remove(std::string &buff, std::size_t index, std::size_t num = std::string::npos) {
|
||||
if (index > buff.size()) {
|
||||
index = buff.size();
|
||||
}
|
||||
|
||||
return buff.erase(index, num);
|
||||
}
|
||||
|
||||
static std::string Mid(const std::string &buff, std::size_t index, std::size_t len = std::string::npos) {
|
||||
if (index >= buff.size()) {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
if (len > buff.size()) {
|
||||
len = buff.size();
|
||||
}
|
||||
|
||||
if (len > buff.size() - index) {
|
||||
len = buff.size() - index;
|
||||
}
|
||||
|
||||
if (index == 0 && len == buff.size()) {
|
||||
return buff;
|
||||
}
|
||||
|
||||
return buff.substr(index, len);
|
||||
}
|
||||
|
||||
|
||||
static std::string GetXmlAttribute(const std::string &xml, const std::string &node, const std::string &attributeName) {
|
||||
std::string nodeName = "<" + node;
|
||||
std::string::size_type pos = xml.find(nodeName);
|
||||
if (pos == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
|
||||
pos = xml.find(attributeName, pos + nodeName.size());
|
||||
if (pos == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
|
||||
pos = xml.find('"', pos + attributeName.size());
|
||||
if (pos == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
|
||||
++pos;
|
||||
std::string::size_type posEnd = xml.find('"', pos);
|
||||
if (posEnd == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return xml.substr(pos, posEnd - pos);
|
||||
}
|
||||
|
||||
static std::string SetXmlAttribute(const std::string &xml, const std::string &node, const std::string &attributeName, const std::string &attributeValue) {
|
||||
std::string nodeName = "<" + node;
|
||||
std::string::size_type pos = xml.find(nodeName);
|
||||
if (pos == std::string::npos) {
|
||||
return xml;
|
||||
}
|
||||
|
||||
pos = xml.find(attributeName, pos + nodeName.size());
|
||||
if (pos == std::string::npos) {
|
||||
return xml;
|
||||
}
|
||||
|
||||
pos = xml.find('"', pos + attributeName.size());
|
||||
if (pos == std::string::npos) {
|
||||
return xml;
|
||||
}
|
||||
|
||||
++pos;
|
||||
std::string::size_type posEnd = xml.find('"', pos);
|
||||
if (posEnd == std::string::npos) {
|
||||
return xml;
|
||||
}
|
||||
|
||||
std::string result = xml;
|
||||
return result.replace(pos, posEnd - pos, attributeValue);
|
||||
}
|
||||
|
||||
|
||||
struct DelaySend {
|
||||
int cmd;
|
||||
std::string data;
|
||||
detail::HAny userData;
|
||||
DelaySend()
|
||||
: cmd(0)
|
||||
{}
|
||||
|
||||
DelaySend(int c, const std::string &d, const detail::HAny &u)
|
||||
: cmd(c)
|
||||
, data(d)
|
||||
, userData(u)
|
||||
{}
|
||||
DelaySend(int c, std::string &&d, detail::HAny &&u)
|
||||
: cmd(c)
|
||||
, data(std::move(d))
|
||||
, userData(std::move(u))
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
struct SendFileInfo {
|
||||
hint64 index;
|
||||
hint64 size;
|
||||
hint16 type;
|
||||
std::string md5;
|
||||
std::string name;
|
||||
std::function<int(hint64 index, hint64 size, int status, char *buff, int buffSize, void *userData)> call;
|
||||
void *userData;
|
||||
|
||||
SendFileInfo()
|
||||
: index(0)
|
||||
, size(0)
|
||||
, type(0)
|
||||
, userData(nullptr)
|
||||
{}
|
||||
|
||||
void Clear() {
|
||||
index = 0;
|
||||
size = 0;
|
||||
type = 0;
|
||||
md5.clear();
|
||||
name.clear();
|
||||
call = std::function<int(hint64, hint64, int, char *, int, void *)>();
|
||||
userData = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
///< 绑定成员函数的回调
|
||||
template <typename _Ret, typename _Obj, typename... _Args>
|
||||
std::function<_Ret(_Args...)> BindMember(_Obj *obj, _Ret(_Obj::*func)(_Args...))
|
||||
{
|
||||
return [&](_Args &&...args) {
|
||||
return (obj->*func)(std::forward<_Args>(args)...);
|
||||
};
|
||||
}
|
||||
|
||||
///< 绑定普通函数的回调
|
||||
template <typename _Ret, typename... _Args>
|
||||
std::function<_Ret(_Args...)> BindFunc(_Ret(*func)(_Args...))
|
||||
{
|
||||
return [&](_Args &&...args) {
|
||||
return func(std::forward<_Args>(args)...);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace hd
|
||||
{
|
||||
|
||||
|
||||
///< SDK私有数据类, 用于保留接口一致
|
||||
class HDSDKPrivate
|
||||
{
|
||||
public:
|
||||
detail::HCallBack<void(const char *xml, int len, int errorCode, void *userData)> NotifyReadXml;
|
||||
detail::HCallBack<bool(const char *data, int len, void *userData)> NotifySendData;
|
||||
detail::HCallBack<int(hint64 index, hint64 size, int status, char *buff, int buffSize, void *userData)> NotifySendFile;
|
||||
|
||||
public:
|
||||
enum eCmd {
|
||||
kInitRun, ///< 初始化协商
|
||||
kReadData, ///< 读取数据
|
||||
kSendSDK, ///< 发送xml
|
||||
kSendFile, ///< 发送文件
|
||||
};
|
||||
|
||||
public:
|
||||
HDSDKPrivate() { Init(); }
|
||||
|
||||
void Init();
|
||||
bool Dispose(int cmd, const std::string &data, const detail::HAny &userData = detail::HAny());
|
||||
|
||||
private:
|
||||
bool ParseReadData(const std::string &data);
|
||||
bool ParseNegotiate(int num);
|
||||
bool ParseSDKCmdAnswer(std::string &&data);
|
||||
bool ParseSendSDK(int cmd, const std::string &data, const detail::HAny &userData);
|
||||
bool ParseFileStartAnswer(std::string &&buff);
|
||||
bool SendFileEnd();
|
||||
bool DelaySend();
|
||||
|
||||
///< 通知回调接口处理任务
|
||||
bool SendData(const std::string &data) { return SendData(data.c_str(), data.size()); }
|
||||
bool SendData(const char *data, int len);
|
||||
void ReadXml(const std::string &xml, int errorCode);
|
||||
int SendFile(hint64 index, hint64 size, int status, char *buff, int buffSize);
|
||||
|
||||
private:
|
||||
friend class HDSDK;
|
||||
std::string guid_; ///< 通信的guid
|
||||
std::string sdkBuff_; ///< sdk xml缓存
|
||||
std::string readBuff_; ///< 总数据缓存
|
||||
std::list<detail::DelaySend> delaySendList_; ///< 延迟发送队列
|
||||
detail::SendFileInfo fileInfo_; ///< 发送文件信息
|
||||
bool negotiate_; ///< 协商状态
|
||||
bool processing_; ///< 发送文件中独占
|
||||
};
|
||||
|
||||
void HDSDKPrivate::Init()
|
||||
{
|
||||
guid_.clear();
|
||||
negotiate_ = false;
|
||||
processing_ = false;
|
||||
delaySendList_.clear();
|
||||
std::string().swap(sdkBuff_);
|
||||
std::string().swap(readBuff_);
|
||||
}
|
||||
|
||||
bool HDSDKPrivate::Dispose(int cmd, const std::string &data, const detail::HAny &userData)
|
||||
{
|
||||
switch (cmd) {
|
||||
case kInitRun: {
|
||||
return ParseNegotiate(0);
|
||||
} break;
|
||||
case kReadData: {
|
||||
return ParseReadData(data);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (processing_) {
|
||||
delaySendList_.emplace_back(detail::DelaySend(cmd, data, userData));
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case kSendSDK: {
|
||||
return ParseSendSDK(cmd, data, userData);
|
||||
} break;
|
||||
case kSendFile: {
|
||||
if (negotiate_ == false) {
|
||||
delaySendList_.emplace_back(detail::DelaySend(cmd, data, userData));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (userData.IsType<detail::SendFileInfo>() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fileInfo_ = userData.Cast<detail::SendFileInfo>();
|
||||
if (fileInfo_.size <= 0 || fileInfo_.md5.empty() || fileInfo_.name.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fileInfo_.md5.size() < MD5_LENGHT) {
|
||||
fileInfo_.md5.append(MD5_LENGHT - fileInfo_.md5.size(), '\0');
|
||||
}
|
||||
|
||||
NotifySendFile.Bind(fileInfo_.call);
|
||||
NotifySendFile.SetUserData(fileInfo_.userData);
|
||||
|
||||
std::string sendData = detail::IconvStr<huint16>(47 + fileInfo_.name.size() + 1);
|
||||
sendData.append(detail::IconvStr<huint16>(detail::kFileStartAsk));
|
||||
sendData.append(fileInfo_.md5);
|
||||
sendData.append(1, '\0');
|
||||
sendData.append(detail::IconvStr<huint64>(fileInfo_.size));
|
||||
sendData.append(detail::IconvStr<hint16>(fileInfo_.type));
|
||||
sendData.append(fileInfo_.name);
|
||||
sendData.append(1, '\0');
|
||||
if (SendData(sendData) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
processing_ = true;
|
||||
return true;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HDSDKPrivate::ParseReadData(const std::string &data)
|
||||
{
|
||||
if (data.empty() == false) {
|
||||
readBuff_.append(data);
|
||||
}
|
||||
|
||||
if (readBuff_.size() < 4) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::size_t len = detail::StrIconv<huint16>(readBuff_.c_str(), readBuff_.size());
|
||||
int cmd = detail::StrIconv<huint16>(readBuff_.c_str() + 2, readBuff_.size() - 2);
|
||||
if (len > readBuff_.size()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string buff = detail::Mid(data, 0, len);
|
||||
detail::Remove(readBuff_, 0, len);
|
||||
|
||||
bool result = true;
|
||||
switch (cmd) {
|
||||
case detail::kTcpHeartbeatAsk:
|
||||
case detail::kTcpHeartbeatAnswer: {
|
||||
std::string sendData = detail::IconvStr<huint16>(4);
|
||||
sendData.append(detail::IconvStr<huint16>(detail::kTcpHeartbeatAsk));
|
||||
result = SendData(sendData);
|
||||
} break;
|
||||
case detail::kSDKServiceAnswer: {
|
||||
result = ParseNegotiate(1);
|
||||
} break;
|
||||
case detail::kSDKCmdAnswer: {
|
||||
result = ParseSDKCmdAnswer(std::move(buff));
|
||||
} break;
|
||||
case detail::kErrorAnswer: {
|
||||
if (buff.size() < 6) {
|
||||
return false;
|
||||
}
|
||||
ReadXml("", detail::StrIconv<huint16>(buff.c_str() + 4, buff.size() - 4));
|
||||
} break;
|
||||
case detail::kFileStartAnswer: {
|
||||
result = ParseFileStartAnswer(std::move(buff));
|
||||
} break;
|
||||
case detail::kFileContentAnswer:
|
||||
break;
|
||||
case detail::kFileEndAnswer: {
|
||||
SendFile(fileInfo_.index, fileInfo_.size, 0, nullptr, 0);
|
||||
processing_ = false;
|
||||
result = DelaySend();
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (result && readBuff_.empty() == false) {
|
||||
return ParseReadData("");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool HDSDKPrivate::ParseNegotiate(int num)
|
||||
{
|
||||
std::string data;
|
||||
if (num == 0) {
|
||||
data.append(detail::IconvStr<huint16>(8));
|
||||
data.append(detail::IconvStr<huint16>(detail::kSDKServiceAsk));
|
||||
data.append(detail::IconvStr<huint32>(LOCAL_TCP_VERSION));
|
||||
} else {
|
||||
std::string xml(R"(<?xml version="1.0" encoding="utf-8"?>
|
||||
<sdk guid="##GUID">
|
||||
<in method="GetIFVersion">
|
||||
<version value="1000000"/>
|
||||
</in>
|
||||
</sdk>)");
|
||||
|
||||
data = detail::SplitSdkData(xml).front();
|
||||
}
|
||||
|
||||
return SendData(data);
|
||||
}
|
||||
|
||||
bool HDSDKPrivate::ParseSDKCmdAnswer(std::string &&data)
|
||||
{
|
||||
if (data.size() < 12) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// int len = detail::StrIconv<huint16>(data.c_str());
|
||||
// int cmd = detail::StrIconv<huint16>(data.c_str() + 2, data.size() - 2);
|
||||
huint32 total = detail::StrIconv<huint32>(data.c_str() + 4, data.size() - 4);
|
||||
// int index = detail::StrIconv<huint32>(data.c_str() + 8, data.size() - 8);
|
||||
detail::Remove(data, 0, 12);
|
||||
|
||||
if (negotiate_ == false) {
|
||||
guid_ = detail::GetXmlAttribute(data, "sdk", "guid");
|
||||
negotiate_ = true;
|
||||
return DelaySend();
|
||||
}
|
||||
|
||||
if (data.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
sdkBuff_.append(data);
|
||||
if (total <= sdkBuff_.size()) {
|
||||
std::string buff(std::move(sdkBuff_));
|
||||
sdkBuff_.clear();
|
||||
ReadXml(buff, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HDSDKPrivate::ParseSendSDK(int cmd, const std::string &data, const detail::HAny &userData)
|
||||
{
|
||||
if (negotiate_ == false) {
|
||||
delaySendList_.emplace_back(detail::DelaySend(cmd, data, userData));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (data.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string xml = detail::SetXmlAttribute(data, "sdk", "guid", guid_);
|
||||
auto xmlList = detail::SplitSdkData(xml);
|
||||
for (const auto &i : xmlList) {
|
||||
if (SendData(i) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HDSDKPrivate::ParseFileStartAnswer(std::string &&buff)
|
||||
{
|
||||
if (buff.size() < 14) {
|
||||
return false;
|
||||
}
|
||||
|
||||
processing_ = true;
|
||||
huint16 status = detail::StrIconv<huint16>(buff.c_str() + 4, buff.size() - 4);
|
||||
fileInfo_.index = detail::StrIconv<hint64>(buff.c_str() + 6, buff.size() - 6);
|
||||
if (status != 0) {
|
||||
SendFile(fileInfo_.index, fileInfo_.size, status, nullptr, 0);
|
||||
processing_ = false;
|
||||
return DelaySend();
|
||||
}
|
||||
|
||||
std::vector<char> sendBuff(XML_MAX, '\0');
|
||||
while (fileInfo_.index < fileInfo_.size) {
|
||||
int len = SendFile(fileInfo_.index, fileInfo_.size, status, sendBuff.data(), sendBuff.size());
|
||||
if (len <= 0) {
|
||||
processing_ = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
fileInfo_.index += len;
|
||||
auto sendList = detail::SplitFileData(sendBuff.data(), len);
|
||||
for (const auto &i : sendList) {
|
||||
if (SendData(i) == false) {
|
||||
processing_ = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return SendFileEnd();
|
||||
}
|
||||
|
||||
bool HDSDKPrivate::SendFileEnd()
|
||||
{
|
||||
std::string data = detail::IconvStr<huint16>(4);
|
||||
data.append(detail::IconvStr<huint16>(detail::kFileEndAsk));
|
||||
return SendData(data);
|
||||
}
|
||||
|
||||
bool HDSDKPrivate::DelaySend()
|
||||
{
|
||||
std::list<detail::DelaySend> sendList;
|
||||
sendList.swap(delaySendList_);
|
||||
while (sendList.empty() == false) {
|
||||
if (processing_) {
|
||||
delaySendList_.splice(delaySendList_.begin(), std::move(sendList));
|
||||
break;
|
||||
}
|
||||
|
||||
detail::DelaySend i = std::move(sendList.front());
|
||||
sendList.pop_front();
|
||||
if (Dispose(i.cmd, i.data, i.userData) == false) {
|
||||
delaySendList_.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HDSDKPrivate::SendData(const char *data, int len)
|
||||
{
|
||||
if (NotifySendData.IsCanUse() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return NotifySendData(data, len);
|
||||
}
|
||||
|
||||
void HDSDKPrivate::ReadXml(const std::string &xml, int errorCode)
|
||||
{
|
||||
if (NotifyReadXml.IsCanUse() == false) {
|
||||
return ;
|
||||
}
|
||||
NotifyReadXml(xml.c_str(), xml.size(), errorCode);
|
||||
}
|
||||
|
||||
int HDSDKPrivate::SendFile(hint64 index, hint64 size, int status, char *buff, int buffSize)
|
||||
{
|
||||
if (NotifySendFile.IsCanUse() == false) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return NotifySendFile(index, size, status, buff, buffSize);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
IHDProtocol CreateProtocol()
|
||||
{
|
||||
return new hd::HDSDKPrivate();
|
||||
}
|
||||
|
||||
void FreeProtocol(IHDProtocol protocol)
|
||||
{
|
||||
delete protocol;
|
||||
}
|
||||
|
||||
HBool SetProtocolFunc(IHDProtocol protocol, int func, void *data)
|
||||
{
|
||||
if (protocol == nullptr) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
switch (func) {
|
||||
case kSetReadXml: {
|
||||
if (data) {
|
||||
protocol->NotifyReadXml.Bind(reinterpret_cast<void(*)(const char *xml, int len, int errorCode, void *userData)>(data));
|
||||
} else {
|
||||
protocol->NotifyReadXml.ClearFunc();
|
||||
}
|
||||
} break;
|
||||
case kSetReadXmlData: {
|
||||
protocol->NotifyReadXml.SetUserData(data);
|
||||
} break;
|
||||
case kSetSendFunc: {
|
||||
if (data) {
|
||||
protocol->NotifySendData.Bind(reinterpret_cast<bool(*)(const char *data, int len, void *userData)>(data));
|
||||
} else {
|
||||
protocol->NotifySendData.ClearFunc();
|
||||
}
|
||||
} break;
|
||||
case kSetSendFuncData: {
|
||||
protocol->NotifySendData.SetUserData(data);
|
||||
} break;
|
||||
default:
|
||||
return HFalse;
|
||||
break;
|
||||
}
|
||||
|
||||
return HTrue;
|
||||
}
|
||||
|
||||
void InitProtocol(hd::IHDProtocol protocol)
|
||||
{
|
||||
protocol->Init();
|
||||
}
|
||||
|
||||
HBool RunProtocol(hd::IHDProtocol protocol)
|
||||
{
|
||||
return protocol->Dispose(hd::HDSDKPrivate::kInitRun, "") ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
HBool UpdateReadData(hd::IHDProtocol protocol, const char *data, int len)
|
||||
{
|
||||
return protocol->Dispose(hd::HDSDKPrivate::kReadData, std::string(data, len)) ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
HBool SendXml(hd::IHDProtocol protocol, const char *xml, int len)
|
||||
{
|
||||
return protocol->Dispose(hd::HDSDKPrivate::kSendSDK, std::string(xml, len)) ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
HBool SendFile(hd::IHDProtocol protocol, const char *fileName, int fileNameLen, const char *md5, int type, hint64 size, int (*callFun)(hint64, hint64, int, char *, int, void *), void *userData)
|
||||
{
|
||||
detail::SendFileInfo info;
|
||||
info.size = size;
|
||||
info.type = type;
|
||||
info.md5.assign(md5);
|
||||
info.name.assign(fileName, fileNameLen);
|
||||
info.call = callFun;
|
||||
info.userData = userData;
|
||||
|
||||
if (info.md5.empty() || info.md5.size() != MD5_LENGHT) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
if (info.name.empty()) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
return protocol->Dispose(hd::HDSDKPrivate::kSendFile, "", info) ? HTrue : HFalse;
|
||||
}
|
||||
193
Protocol/HDSDK.h
Normal file
193
Protocol/HDSDK.h
Normal file
@ -0,0 +1,193 @@
|
||||
|
||||
|
||||
#ifndef __HDSDK_H__
|
||||
#define __HDSDK_H__
|
||||
|
||||
|
||||
#if defined(_MSC_VER) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
|
||||
# define H_DECL_EXPORT __declspec(dllexport)
|
||||
# define H_DECL_IMPORT __declspec(dllimport)
|
||||
# define DLL_CALL __cdecl
|
||||
# define H_WIN
|
||||
#else
|
||||
# define H_DECL_EXPORT __attribute__((visibility("default")))
|
||||
# define H_DECL_IMPORT __attribute__((visibility("default")))
|
||||
# define DLL_CALL
|
||||
// __attribute__((__cdecl__))
|
||||
# define H_LINUX
|
||||
#endif
|
||||
|
||||
#ifdef STATIC_IMPORT
|
||||
#ifdef H_DECL_IMPORT
|
||||
#undef H_DECL_IMPORT
|
||||
#define H_DECL_IMPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_HD_LIB)
|
||||
# define HD_API H_DECL_EXPORT
|
||||
#else
|
||||
# define HD_API H_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
|
||||
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(HCAT_NOEXCEPTION)
|
||||
#define CAT_THROW(exception) throw exception
|
||||
#define CAT_TRY try
|
||||
#define CAT_CATCH(exception) catch(exception)
|
||||
#define CAT_INTERNAL_CATCH(exception) catch(exception)
|
||||
#else
|
||||
#include <cstdlib>
|
||||
#define CAT_THROW(exception) std::abort()
|
||||
#define CAT_TRY if(true)
|
||||
#define CAT_CATCH(exception) if(false)
|
||||
#define CAT_INTERNAL_CATCH(exception) if(false)
|
||||
#endif
|
||||
|
||||
|
||||
// override exception macros
|
||||
#if defined(CAT_THROW_USER)
|
||||
#undef CAT_THROW
|
||||
#define CAT_THROW CAT_THROW_USER
|
||||
#endif
|
||||
#if defined(CAT_TRY_USER)
|
||||
#undef CAT_TRY
|
||||
#define CAT_TRY CAT_TRY_USER
|
||||
#endif
|
||||
#if defined(CAT_CATCH_USER)
|
||||
#undef CAT_CATCH
|
||||
#define CAT_CATCH CAT_CATCH_USER
|
||||
#undef CAT_INTERNAL_CATCH
|
||||
#define CAT_INTERNAL_CATCH CAT_CATCH_USER
|
||||
#endif
|
||||
#if defined(CAT_INTERNAL_CATCH_USER)
|
||||
#undef CAT_INTERNAL_CATCH
|
||||
#define CAT_INTERNAL_CATCH CAT_INTERNAL_CATCH_USER
|
||||
#endif
|
||||
|
||||
|
||||
#define HBool int
|
||||
#define HTrue 1
|
||||
#define HFalse 0
|
||||
|
||||
typedef unsigned long long huint64;
|
||||
typedef unsigned int huint32;
|
||||
typedef unsigned short huint16;
|
||||
typedef unsigned char huint8;
|
||||
|
||||
typedef long long hint64;
|
||||
typedef int hint32;
|
||||
typedef short hint16;
|
||||
typedef char hint8;
|
||||
|
||||
|
||||
#ifdef USE_HD_LIB
|
||||
namespace hd {
|
||||
typedef class HDSDKPrivate* IHDProtocol;
|
||||
}
|
||||
using hd::IHDProtocol;
|
||||
#else
|
||||
typedef void* IHDProtocol;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum {
|
||||
/**
|
||||
* void readXml(const char *xml, int len, int errorCode, void *userData)
|
||||
* @param xml Xml data
|
||||
* @param len Xml len
|
||||
* @param errorCode Error code, normally 0
|
||||
* @param userData kSetReadXmlData value
|
||||
*/
|
||||
kSetReadXml = 0x0001,
|
||||
kSetReadXmlData = 0x0002,
|
||||
|
||||
/**
|
||||
* HBool sendDataToNet(const char *data, int len, void *userData)
|
||||
* @param data Send data
|
||||
* @param len Send data len
|
||||
* @param userData kSetSendFuncData value
|
||||
* @return 0 <= return. Stop the protocol, which requires a protocol reset
|
||||
*/
|
||||
kSetSendFunc = 0x0003,
|
||||
kSetSendFuncData = 0x0004
|
||||
|
||||
} eHDFunc ;
|
||||
|
||||
|
||||
/**
|
||||
* @brief CreateProtocol Create protocol. default init.
|
||||
* @return IHDProtocol
|
||||
*/
|
||||
HD_API IHDProtocol DLL_CALL CreateProtocol();
|
||||
|
||||
/**
|
||||
* @brief FreeProtocol free protocol
|
||||
* @param protocol IHDProtocol
|
||||
*/
|
||||
HD_API void DLL_CALL FreeProtocol(IHDProtocol protocol);
|
||||
|
||||
/**
|
||||
* @brief SetProtocolFunc Set protocol function
|
||||
* @param protocol IHDProtocol
|
||||
* @param func eHDFunc
|
||||
* @param data data
|
||||
* @return 1 or 0 (1 = true; 0 = false)
|
||||
*/
|
||||
HD_API HBool DLL_CALL SetProtocolFunc(IHDProtocol protocol, int func, void *data);
|
||||
|
||||
/**
|
||||
* @brief InitProtocol init protocol. Required when the same protocol body needs to be reused
|
||||
* @param protocol IHDProtocol
|
||||
*/
|
||||
HD_API void DLL_CALL InitProtocol(IHDProtocol protocol);
|
||||
|
||||
/**
|
||||
* @brief RunProtocol Start negotiating the protocol
|
||||
* @param protocol IHDProtocol
|
||||
* @return 1 or 0 (1 = true; 0 = false)
|
||||
*/
|
||||
HD_API HBool RunProtocol(IHDProtocol protocol);
|
||||
|
||||
/**
|
||||
* @brief UpdateReadData The core, the read data is passed in
|
||||
* @param protocol IHDProtocol
|
||||
* @param data Read data
|
||||
* @param len Read data len
|
||||
* @return 1 or 0 (1 = true; 0 = false)
|
||||
*/
|
||||
HD_API HBool UpdateReadData(IHDProtocol protocol, const char *data, int len);
|
||||
|
||||
/**
|
||||
* @brief SendXml Send xml data
|
||||
* @param protocol IHDProtocol
|
||||
* @param xml Xml data
|
||||
* @param len Xml len
|
||||
* @return 1 or 0 (1 = true; 0 = false)
|
||||
*/
|
||||
HD_API HBool DLL_CALL SendXml(IHDProtocol protocol, const char *xml, int len);
|
||||
|
||||
/**
|
||||
* @brief SendFile Send file
|
||||
* @param protocol IHDProtocol
|
||||
* @param fileName device save file name
|
||||
* @param fileNameLen Send file name len
|
||||
* @param md5 md5(32byte)
|
||||
* @param type 0(image), 1(video), 2(font), 3(firmware), 128(temp image file), 129(temp video file)
|
||||
* @param size Send file Size
|
||||
* @param callFun Send file data { int(hint64 index, hint64 size, int status, char *buff, int buffSize, void *userData) }
|
||||
* @param userData callFun userData
|
||||
* @return 1 or 0 (1 = true; 0 = false)
|
||||
*/
|
||||
HD_API HBool DLL_CALL SendFile(IHDProtocol protocol, const char *fileName, int fileNameLen, const char *md5, int type, hint64 size, int(*callFun)(hint64, hint64, int, char *, int, void *), void *userData);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __HDSDK_H__
|
||||
124
SDK/Data/HEthernetInfo.cpp
Normal file
124
SDK/Data/HEthernetInfo.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
|
||||
|
||||
#include <Data/HEthernetInfo.h>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, Eth0Info &node)
|
||||
{
|
||||
node.dhcp = xml.at("eth").at("dhcp").GetAttribute("auto") == "true";
|
||||
node.ip = xml.at("eth").at("address").GetAttribute("ip");
|
||||
node.netmask = xml.at("eth").at("address").GetAttribute("netmask");
|
||||
node.gateway = xml.at("eth").at("address").GetAttribute("gateway");
|
||||
node.dns = xml.at("eth").at("address").GetAttribute("dns");
|
||||
}
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const Eth0Info &node)
|
||||
{
|
||||
xml["eth"] = {"valid", "true"};
|
||||
xml["eth"]["enable"] = {"value", "true"};
|
||||
xml["eth"]["dhcp"] = {"auto", node.dhcp};
|
||||
xml["eth"]["address"] = {{"ip", node.ip},
|
||||
{"netmask", node.netmask},
|
||||
{"gateway", node.gateway},
|
||||
{"dns", node.dns}};
|
||||
}
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, WifiInfo &node)
|
||||
{
|
||||
node.mode = xml.at("mode").GetAttribute("value");
|
||||
node.ap.ssid = xml.at("ap").at("ssid").GetAttribute("value");
|
||||
node.ap.password = xml.at("ap").at("passwd").GetAttribute("value");
|
||||
node.ap.ipAddress = xml.at("ap").at("address").GetAttribute("ip");
|
||||
if (xml.at("ap").ContainsNodes("channel")) {
|
||||
node.ap.channel = xml.at("ap").at("channel").GetAttribute("value").ToInt();
|
||||
}
|
||||
|
||||
node.stationIndex = xml.at("station").at("current").GetAttribute("index").ToInt();
|
||||
|
||||
node.station.clear();
|
||||
for (const auto &i : xml.at("station").at("list").at("item")) {
|
||||
WifiInfo::StationConfig info;
|
||||
info.ssid = i.at("ssid").GetAttribute("value");
|
||||
info.password = i.at("passwd").GetAttribute("value");
|
||||
info.dhcp = i.at("dhcp").GetAttribute("auto") != "false";
|
||||
info.ip = i.at("address").GetAttribute("ip");
|
||||
info.mask = i.at("address").GetAttribute("netmask");
|
||||
info.gateway = i.at("address").GetAttribute("gateway");
|
||||
info.dns = i.at("address").GetAttribute("dns");
|
||||
node.station.emplace_back(std::move(info));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const WifiInfo &node)
|
||||
{
|
||||
xml["mode"] = {"value", node.mode.GetConstString()};
|
||||
xml["ap"]["ssid"] = {"value", node.ap.ssid.GetConstString()};
|
||||
xml["ap"]["passwd"] = {"value", node.ap.password.GetConstString()};
|
||||
xml["ap"]["channel"] = {"value", node.ap.channel};
|
||||
xml["ap"]["encryption"] = {"value", "WPA-PSK"};
|
||||
xml["ap"]["dhcp"] = {"auto", "true"};
|
||||
xml["ap"]["address"] = {{"ip", node.ap.ipAddress.GetConstString()},
|
||||
{"netmask", ""},
|
||||
{"gateway", ""},
|
||||
{"dns", ""}};
|
||||
|
||||
xml["station"]["current"] = {"index", node.stationIndex};
|
||||
for (const auto &i : node.station) {
|
||||
HXml &item = xml["station"]["list"].NewChild("item");
|
||||
item["ssid"] = {"value", i.ssid};
|
||||
item["passwd"] = {"value", i.password};
|
||||
item["signal"] = {"value", 0};
|
||||
item["apmac"] = {"value", i.mac};
|
||||
item["dhcp"] = {"auto", i.dhcp ? "true" : "false"};
|
||||
item["address"] = {{"ip", i.ip},
|
||||
{"netmask", i.mask},
|
||||
{"gateway", i.gateway},
|
||||
{"dns", i.dns}};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, PppoeInfo &node)
|
||||
{
|
||||
node.vaild = xml.at("pppoe").GetAttribute("valid") == "true";
|
||||
node.enable = xml.at("pppoe").at("enable").GetAttribute("value") == "true";
|
||||
node.apn = xml.at("pppoe").at("apn").GetAttribute("value");
|
||||
node.manufacturer = xml.at("pppoe").at("manufacturer").GetAttribute("value");
|
||||
node.version = xml.at("pppoe").at("version").GetAttribute("value");
|
||||
node.model = xml.at("pppoe").at("model").GetAttribute("value");
|
||||
node.imei = xml.at("pppoe").at("imei").GetAttribute("value");
|
||||
node.number = xml.at("pppoe").at("number").GetAttribute("value");
|
||||
node.operators = xml.at("pppoe").at("operators").GetAttribute("value");
|
||||
node.signal = xml.at("pppoe").at("signal").GetAttribute("value").ToInt();
|
||||
node.dbm = xml.at("pppoe").at("dbm").GetAttribute("value").ToInt();
|
||||
node.insert = xml.at("pppoe").at("insert").GetAttribute("value") == "true";
|
||||
node.status = xml.at("pppoe").at("status").GetAttribute("value");
|
||||
node.network = xml.at("pppoe").at("network").GetAttribute("value");
|
||||
node.code = xml.at("pppoe").at("code").GetAttribute("value");
|
||||
}
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const PppoeInfo &node)
|
||||
{
|
||||
xml["apn"] = {"value", node.apn};
|
||||
}
|
||||
|
||||
const WifiInfo::StationConfig &WifiInfo::GetCurrentStation()
|
||||
{
|
||||
if (stationIndex < 0 || stationIndex >= static_cast<int>(station.size())) {
|
||||
stationIndex = 0;
|
||||
station.clear();
|
||||
station.emplace_back(StationConfig());
|
||||
}
|
||||
return station.front();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
114
SDK/Data/HEthernetInfo.h
Normal file
114
SDK/Data/HEthernetInfo.h
Normal file
@ -0,0 +1,114 @@
|
||||
|
||||
|
||||
#ifndef __HETHERNETINFO_H__
|
||||
#define __HETHERNETINFO_H__
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <HXml.h>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
///< Eth0
|
||||
struct Eth0Info
|
||||
{
|
||||
bool dhcp; ///< "true"(dhcp获取ip地址), "false"(静态ip地址)
|
||||
cat::HCatBuffer ip;
|
||||
cat::HCatBuffer netmask;
|
||||
cat::HCatBuffer gateway;
|
||||
cat::HCatBuffer dns;
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetEth0Info"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetEth0Info"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetEth0Info"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetEth0Info"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, Eth0Info &node);
|
||||
void to_xml(HXml &xml, const Eth0Info &node);
|
||||
|
||||
|
||||
struct WifiInfo
|
||||
{
|
||||
struct ApConfig
|
||||
{
|
||||
cat::HCatBuffer ssid; ///< 热点名称
|
||||
cat::HCatBuffer password; ///< 热点密码
|
||||
cat::HCatBuffer ipAddress; ///< ip地址
|
||||
int channel; ///< ap通道
|
||||
ApConfig() : channel(0) { }
|
||||
};
|
||||
|
||||
struct StationConfig
|
||||
{
|
||||
cat::HCatBuffer ssid; ///< wifi名称
|
||||
cat::HCatBuffer password; ///< wifi密码(仅设置)
|
||||
bool dhcp; ///< 是否开启dhcp(默认开)
|
||||
cat::HCatBuffer mac; ///< mac地址(只读)
|
||||
cat::HCatBuffer ip;
|
||||
cat::HCatBuffer mask;
|
||||
cat::HCatBuffer gateway;
|
||||
cat::HCatBuffer dns;
|
||||
StationConfig() : dhcp(true) {}
|
||||
};
|
||||
|
||||
cat::HCatBuffer mode; ///< 模式(ap|station)
|
||||
ApConfig ap; ///< ap设置
|
||||
int stationIndex; ///< station索引
|
||||
std::list<StationConfig> station; ///< station设置
|
||||
|
||||
WifiInfo() : stationIndex(0) {}
|
||||
|
||||
const StationConfig & GetCurrentStation();
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetWifiInfo"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetWifiInfo"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetWifiInfo"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetWifiInfo"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, WifiInfo &node);
|
||||
void to_xml(HXml &xml, const WifiInfo &node);
|
||||
|
||||
|
||||
struct PppoeInfo
|
||||
{
|
||||
bool vaild; ///< 是否有接入 {"true"(有3/4G模块接入), "false"(无3/4G模块接入)}
|
||||
bool enable; ///< {"true"(有3/4G网络接入), "false"(无3/4G网络接入)}
|
||||
cat::HCatBuffer apn; ///< apn值
|
||||
cat::HCatBuffer manufacturer; ///< 模块生产商
|
||||
cat::HCatBuffer version; ///< 模块版本
|
||||
cat::HCatBuffer model; ///< 模块型号
|
||||
cat::HCatBuffer imei; ///< 模块IMEI
|
||||
cat::HCatBuffer number; ///< sim卡电话号码
|
||||
cat::HCatBuffer operators; ///< 运营商
|
||||
int signal; ///< 信号强度, 取值范围[1, 5]; 1表示信号强度最差; 5表示信号强度最好
|
||||
int dbm; ///< 信号强度(单位dbm)
|
||||
bool insert; ///< SIM卡是否插入, 取值范围{"true"(有SIM卡插入), "false"(无SIM卡插入)}
|
||||
cat::HCatBuffer status; ///< 网络注册状态, 取值范围 {"unregister"(未注册), "register local"(已注册, 本地网络), "searching"(搜索中), "reject"(拒绝注册), "unknow"(未知错误), "register roaming"(已注册, 漫游网络), "init"(初始化状态)}
|
||||
cat::HCatBuffer network; ///< 网络制式, 取值范围 {"init"(初始化状态), "unknow"(未知网络), "2G"(2G), "2.5G"(2.5G), "3GPP"(3GPP家族), "3G TD"(移动3G), "3.5G HSDPA", "3.5G HSUPA", "3.5G HSPAPlus", "4G LTE", "4G TDD", "4G FDD"}
|
||||
cat::HCatBuffer code; ///< 错误码(保留)
|
||||
|
||||
PppoeInfo()
|
||||
: vaild(false)
|
||||
, enable(false)
|
||||
, signal(0)
|
||||
, dbm(0)
|
||||
, insert(false)
|
||||
{}
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetPppoeInfo"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetApn"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetPppoeInfo"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetApn"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, PppoeInfo &node);
|
||||
void to_xml(HXml &xml, const PppoeInfo &node);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // __HETHERNETINFO_H__
|
||||
94
SDK/Data/HGeneralInfo.cpp
Normal file
94
SDK/Data/HGeneralInfo.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <Data/HGeneralInfo.h>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const SystemVolumeInfo &data)
|
||||
{
|
||||
xml["mode"] = HXml{"value", data.mode != SystemVolumeInfo::kDefault ? "ploys" : "default"};
|
||||
xml["volume"] = HXml{"percent", data.volume};
|
||||
for (const auto &i : data.ploys) {
|
||||
xml["ploy"].emplace_back("item", {{"percent", i.volume},
|
||||
{"enable", i.enable},
|
||||
{"start", i.time}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, SystemVolumeInfo &data)
|
||||
{
|
||||
data.mode = xml.at("mode").GetAttribute("value") == "ploys" ? SystemVolumeInfo::kPloys : SystemVolumeInfo::kDefault;
|
||||
data.volume = xml.at("volume").GetAttribute("percent");
|
||||
data.ploys.clear();
|
||||
if (xml.ContainsNodes("ploy", "item")) {
|
||||
for (const auto &i : xml.at("ploy").at("item")) {
|
||||
SystemVolumeInfo::Ploy item;
|
||||
item.enable = DataToType<bool>(i.GetAttribute("enable"));
|
||||
item.volume = i.GetAttribute("percent").ToInt();
|
||||
item.time = i.GetAttribute("start");
|
||||
data.ploys.emplace_back(std::move(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const DeviceNameInfo &data)
|
||||
{
|
||||
xml["name"] = {"value", data.name};
|
||||
}
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, DeviceNameInfo &data)
|
||||
{
|
||||
data.name = xml.at("name").GetAttribute("value");
|
||||
}
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const SDKTcpServerInfo &data)
|
||||
{
|
||||
xml["server"] = {{"port", data.port},
|
||||
{"host", data.host}};
|
||||
}
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, SDKTcpServerInfo &data)
|
||||
{
|
||||
data.port = xml.at("server").GetAttribute("port").ToInt();
|
||||
data.host = xml.at("server").GetAttribute("host");
|
||||
}
|
||||
|
||||
void from_xml(const HXml &xml, DeviceInfo &data)
|
||||
{
|
||||
data.device.cpu = xml.at("device").GetAttribute("cpu");
|
||||
data.device.id = xml.at("device").GetAttribute("id");
|
||||
data.device.model = xml.at("device").GetAttribute("model");
|
||||
data.device.name = xml.at("device").GetAttribute("name");
|
||||
|
||||
data.version.kernel = xml.at("version").GetAttribute("kernel");
|
||||
data.version.hardware = xml.at("version").GetAttribute("hardware");
|
||||
data.version.app = xml.at("version").GetAttribute("app");
|
||||
data.version.fpga = xml.at("version").GetAttribute("fpga");
|
||||
|
||||
data.screen.rotation = xml.at("screen").GetAttribute("rotation").ToInt();
|
||||
data.screen.width = xml.at("screen").GetAttribute("width").ToInt();
|
||||
data.screen.height = xml.at("screen").GetAttribute("height").ToInt();
|
||||
}
|
||||
|
||||
void to_xml(HXml &xml, const ScreenShot2 &data)
|
||||
{
|
||||
xml["image"] = {{"width", data.width},
|
||||
{"height", data.height}};
|
||||
}
|
||||
|
||||
void from_xml(const HXml &xml, ScreenShot2 &data)
|
||||
{
|
||||
data.rawData = cat::HCatBuffer::FromBase64(xml.at("image").GetAttribute("data"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
137
SDK/Data/HGeneralInfo.h
Normal file
137
SDK/Data/HGeneralInfo.h
Normal file
@ -0,0 +1,137 @@
|
||||
|
||||
|
||||
#ifndef __HGENERALINFO_H__
|
||||
#define __HGENERALINFO_H__
|
||||
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <HXml.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
///< 系统音量
|
||||
struct SystemVolumeInfo
|
||||
{
|
||||
enum eMode {
|
||||
kDefault,
|
||||
kPloys,
|
||||
};
|
||||
struct Ploy {
|
||||
bool enable; ///< 是否启用时间段
|
||||
cat::HCatBuffer time; ///< 开始时间 "HH:mm:ss"
|
||||
int volume; ///< 0-100
|
||||
Ploy() : enable(false), volume(0) {}
|
||||
};
|
||||
|
||||
int mode;
|
||||
cat::HCatBuffer volume; ///< 0-100
|
||||
std::vector<Ploy> ploys; ///< 分时音量
|
||||
|
||||
SystemVolumeInfo()
|
||||
: mode(kDefault)
|
||||
{}
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetSystemVolume"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetSystemVolume"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetSystemVolume"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetSystemVolume"; }
|
||||
};
|
||||
void to_xml(HXml &xml, const SystemVolumeInfo &data);
|
||||
void from_xml(const HXml &xml, SystemVolumeInfo &data);
|
||||
|
||||
|
||||
///< 设备名
|
||||
struct DeviceNameInfo
|
||||
{
|
||||
cat::HCatBuffer name; ///< 设备名
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetDeviceName"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetDeviceName"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetDeviceName"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetDeviceName"; }
|
||||
};
|
||||
void to_xml(HXml &xml, const DeviceNameInfo &data);
|
||||
void from_xml(const HXml &xml, DeviceNameInfo &data);
|
||||
|
||||
|
||||
///< tcp服务器
|
||||
struct SDKTcpServerInfo
|
||||
{
|
||||
cat::HCatBuffer host; ///< 主机地址
|
||||
huint16 port; ///< 端口
|
||||
|
||||
SDKTcpServerInfo() : port(0) {}
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetSDKTcpServer"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetSDKTcpServer"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetSDKTcpServer"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetSDKTcpServer"; }
|
||||
};
|
||||
void to_xml(HXml &xml, const SDKTcpServerInfo &data);
|
||||
void from_xml(const HXml &xml, SDKTcpServerInfo &data);
|
||||
|
||||
|
||||
///< 设备信息
|
||||
struct DeviceInfo
|
||||
{
|
||||
struct Device {
|
||||
cat::HCatBuffer cpu; ///< cpu信息
|
||||
cat::HCatBuffer id; ///< 设备id
|
||||
cat::HCatBuffer model; ///< 设备类型
|
||||
cat::HCatBuffer name; ///< 设备名
|
||||
};
|
||||
struct Version {
|
||||
cat::HCatBuffer kernel; ///< 内核版本
|
||||
cat::HCatBuffer hardware; ///< 硬件版本
|
||||
cat::HCatBuffer app; ///< 应用版本
|
||||
cat::HCatBuffer fpga; ///< fpga版本
|
||||
};
|
||||
struct Screen {
|
||||
int rotation; ///< 旋转
|
||||
int width; ///< 屏幕宽度
|
||||
int height; ///< 屏幕高度
|
||||
Screen()
|
||||
: rotation(0)
|
||||
, width(0)
|
||||
, height(0)
|
||||
{}
|
||||
};
|
||||
|
||||
Device device;
|
||||
Version version;
|
||||
Screen screen;
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetDeviceInfo"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetDeviceInfo"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, DeviceInfo &data);
|
||||
|
||||
|
||||
///< 屏幕截图
|
||||
struct ScreenShot2
|
||||
{
|
||||
int width; ///< 截图宽
|
||||
int height; ///< 截图高
|
||||
cat::HCatBuffer rawData; ///< 图片base64数据
|
||||
|
||||
ScreenShot2()
|
||||
: width(0)
|
||||
, height(0)
|
||||
{}
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetScreenshot2"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetScreenshot2"; }
|
||||
};
|
||||
void to_xml(HXml &xml, const ScreenShot2 &data);
|
||||
void from_xml(const HXml &xml, ScreenShot2 &data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // __HGENERALINFO_H__
|
||||
67
SDK/Data/HLightInfo.cpp
Normal file
67
SDK/Data/HLightInfo.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <Data/HLightInfo.h>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, LightInfo &node)
|
||||
{
|
||||
|
||||
cat::HCatBuffer mode = xml.at("mode").GetAttribute("value");
|
||||
if (mode == "ploys") {
|
||||
node.mode = LightInfo::kPloys;
|
||||
} else if (mode == "sensor") {
|
||||
node.mode = LightInfo::kSensor;
|
||||
} else {
|
||||
node.mode = LightInfo::kDefault;
|
||||
}
|
||||
|
||||
node.defaultValue = xml.at("default").GetAttribute("value");
|
||||
node.sensor.min = xml.at("sensor").GetAttribute("min").ToInt();
|
||||
node.sensor.max = xml.at("sensor").GetAttribute("max").ToInt();
|
||||
node.sensor.time = xml.at("sensor").GetAttribute("time").ToInt();
|
||||
|
||||
node.ployList.clear();
|
||||
if (xml.ContainsNodes("ploy") && xml.at("ploy").ContainsNodes("item")) {
|
||||
for (const auto &i : xml.at("ploy").at("item")) {
|
||||
LightInfo::Ploy item;
|
||||
item.enable = i.GetAttribute("enable") == "true";
|
||||
item.start = i.GetAttribute("start");
|
||||
item.percent = i.GetAttribute("percent").ToInt();
|
||||
node.ployList.emplace_back(std::move(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const LightInfo &node)
|
||||
{
|
||||
|
||||
switch (node.mode) {
|
||||
case LightInfo::kDefault: xml["mode"] = {"value", "default"}; break;
|
||||
case LightInfo::kPloys: xml["mode"] = {"value", "ploys"}; break;
|
||||
case LightInfo::kSensor: xml["mode"] = {"value", "sensor"}; break;
|
||||
default:
|
||||
xml["mode"] = {"value", "default"};
|
||||
break;
|
||||
}
|
||||
|
||||
xml["default"] = {"value", node.defaultValue};
|
||||
xml["sensor"] = {{"min", node.sensor.min},
|
||||
{"max", node.sensor.max},
|
||||
{"time", node.sensor.time}};
|
||||
for (const auto &i : node.ployList) {
|
||||
xml["ploy"].emplace_back("item", {{"enable", i.enable},
|
||||
{"start", i.start},
|
||||
{"percent", i.percent}});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
60
SDK/Data/HLightInfo.h
Normal file
60
SDK/Data/HLightInfo.h
Normal file
@ -0,0 +1,60 @@
|
||||
|
||||
|
||||
#ifndef __HLIGHTINFO_H__
|
||||
#define __HLIGHTINFO_H__
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <HXml.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
///< 亮度
|
||||
struct LightInfo
|
||||
{
|
||||
enum eMode {
|
||||
kDefault, ///< 默认
|
||||
kPloys, ///< 自定义模式
|
||||
kSensor, ///< 传感器模式
|
||||
};
|
||||
struct Sensor {
|
||||
hint16 min; ///< 最小亮度等级
|
||||
hint16 max; ///< 最大亮度等级
|
||||
hint16 time; ///< 亮度调整间隔时间
|
||||
|
||||
Sensor() : min(1), max(100), time(5) {}
|
||||
};
|
||||
struct Ploy {
|
||||
bool enable; ///< 使能
|
||||
cat::HCatBuffer start; ///< 开始时间 hh:mm:ss
|
||||
hint16 percent; ///< 亮度等级
|
||||
|
||||
Ploy() : enable(false), percent(0) {}
|
||||
};
|
||||
|
||||
eMode mode; ///< 模式
|
||||
cat::HCatBuffer defaultValue; ///< 默认模式的值[1, 100]
|
||||
Sensor sensor; ///< 传感器模式
|
||||
std::vector<Ploy> ployList; ///< 自定义模式
|
||||
|
||||
LightInfo()
|
||||
: mode(kDefault)
|
||||
{}
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetLuminancePloy"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetLuminancePloy"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetLuminancePloy"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetLuminancePloy"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, LightInfo &node);
|
||||
void to_xml(HXml &xml, const LightInfo &node);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // __HLIGHTINFO_H__
|
||||
36
SDK/Data/HOTherInfo.cpp
Normal file
36
SDK/Data/HOTherInfo.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
|
||||
|
||||
#include <Data/HOTherInfo.h>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, MulScreenSyncInfo &node)
|
||||
{
|
||||
node.enable = xml.at("enable").GetAttribute("value") == "true";
|
||||
}
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const MulScreenSyncInfo &node)
|
||||
{
|
||||
xml["enable"] = {"value", node.enable ? "true" : "false"};
|
||||
}
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, GpsRespondInfo &node)
|
||||
{
|
||||
node.enable = xml.at("gps").GetAttribute("enable") == "true";
|
||||
node.delay = xml.at("gps").GetAttribute("delay").ToInt();
|
||||
}
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const GpsRespondInfo &node)
|
||||
{
|
||||
xml["gps"] = {{"enable", node.enable ? "true" : "false"},
|
||||
{"delay", node.delay}};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
51
SDK/Data/HOTherInfo.h
Normal file
51
SDK/Data/HOTherInfo.h
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
|
||||
#ifndef __HOTHERINFO_H__
|
||||
#define __HOTHERINFO_H__
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <HXml.h>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
///< 多屏同步
|
||||
struct MulScreenSyncInfo
|
||||
{
|
||||
bool enable; ///< 使能
|
||||
|
||||
MulScreenSyncInfo() : enable(false) {}
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetMulScreenSync"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetMulScreenSync"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetMulScreenSync"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetMulScreenSync"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, MulScreenSyncInfo &node);
|
||||
void to_xml(HXml &xml, const MulScreenSyncInfo &node);
|
||||
|
||||
|
||||
///< gps数据上报
|
||||
struct GpsRespondInfo
|
||||
{
|
||||
bool enable;
|
||||
hint16 delay;
|
||||
|
||||
GpsRespondInfo() : enable(false), delay(0) {}
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetGpsRespondEnable"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetGpsRespondEnable"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetGpsRespondEnable"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetGpsRespondEnable"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, GpsRespondInfo &node);
|
||||
void to_xml(HXml &xml, const GpsRespondInfo &node);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // __HOTHERINFO_H__
|
||||
69
SDK/Data/HSDKInfo.cpp
Normal file
69
SDK/Data/HSDKInfo.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
|
||||
|
||||
#include <Data/HSDKInfo.h>
|
||||
#include <HCatBuffer.h>
|
||||
#include <HXml.h>
|
||||
|
||||
|
||||
using namespace sdk;
|
||||
|
||||
|
||||
template <typename _T,
|
||||
bool(*)(const cat::HCatBuffer &) = &_T::MatchGet,
|
||||
bool(*)(const cat::HCatBuffer &) = &_T::MatchSet>
|
||||
bool UpdateNode(_T &obj, const cat::HCatBuffer &method, const HXml &xml) {
|
||||
if (_T::MatchSet(method)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_T::MatchGet(method) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return xml.get_to(obj);
|
||||
}
|
||||
template <typename _T,
|
||||
bool(*)(const cat::HCatBuffer &) = &_T::MatchGet>
|
||||
bool UpdateGetNode(_T &obj, const cat::HCatBuffer &method, const HXml &xml) {
|
||||
if (_T::MatchGet(method) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return xml.get_to(obj);
|
||||
}
|
||||
|
||||
|
||||
int HSDKInfo::ParseInfo(tinyxml2::XMLElement *outNode, const cat::HCatBuffer &method)
|
||||
{
|
||||
if (outNode == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
HXml xml(outNode);
|
||||
|
||||
#define UPDATE_NODE(obj) \
|
||||
if (UpdateNode(obj, method, xml)) { ++result; }
|
||||
#define UPDATE_GET_NODE(obj) \
|
||||
if (UpdateGetNode(obj, method, xml)) { ++result; }
|
||||
|
||||
UPDATE_NODE(lightInfo);
|
||||
UPDATE_NODE(systemVolumeInfo);
|
||||
UPDATE_NODE(tcpSercerInfo);
|
||||
UPDATE_NODE(timeInfo);
|
||||
UPDATE_NODE(ethInfo);
|
||||
UPDATE_NODE(wifiInfo);
|
||||
UPDATE_NODE(pppoeInfo);
|
||||
UPDATE_NODE(deviceNameInfo);
|
||||
UPDATE_NODE(switchTimeInfo);
|
||||
UPDATE_NODE(relayInfo);
|
||||
|
||||
UPDATE_GET_NODE(deviceInfo);
|
||||
UPDATE_GET_NODE(screenShot2);
|
||||
UPDATE_GET_NODE(sensorInfo);
|
||||
UPDATE_GET_NODE(gpsInfo);
|
||||
|
||||
return result;
|
||||
#undef UPDATE_GET_NODE
|
||||
#undef UPDATE_NODE
|
||||
}
|
||||
51
SDK/Data/HSDKInfo.h
Normal file
51
SDK/Data/HSDKInfo.h
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
|
||||
#ifndef __HSDKINFO_H__
|
||||
#define __HSDKINFO_H__
|
||||
|
||||
|
||||
#include <Data/HEthernetInfo.h>
|
||||
#include <Data/HGeneralInfo.h>
|
||||
#include <Data/HLightInfo.h>
|
||||
#include <Data/HOTherInfo.h>
|
||||
#include <Data/HScreenFunctionInfo.h>
|
||||
#include <Data/HSensorInfo.h>
|
||||
#include <Data/HTimeInfo.h>
|
||||
#include <tinyxml2.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
struct HSDKInfo
|
||||
{
|
||||
Eth0Info ethInfo; ///< 有线
|
||||
WifiInfo wifiInfo; ///< wifi
|
||||
PppoeInfo pppoeInfo; ///< pppoe
|
||||
SystemVolumeInfo systemVolumeInfo; ///< 系统音量
|
||||
DeviceNameInfo deviceNameInfo; ///< 设备名
|
||||
SDKTcpServerInfo tcpSercerInfo; ///< tcp服务器
|
||||
LightInfo lightInfo; ///< 亮度
|
||||
MulScreenSyncInfo mulScreenSyncInfo; ///< 多屏同步
|
||||
GpsRespondInfo gpsResondInfo; ///< gps数据上报
|
||||
SwitchTimeInfo switchTimeInfo; ///< 开关机
|
||||
RelayInfo relayInfo; ///< 继电器
|
||||
TimeInfo timeInfo; ///< 时间
|
||||
|
||||
///< 下面是只有获取项的
|
||||
DeviceInfo deviceInfo; ///< 设备信息
|
||||
ScreenShot2 screenShot2; ///< 截图数据
|
||||
SensorInfo sensorInfo; ///< 传感器状态
|
||||
GpsInfo gpsInfo; ///< gps信息
|
||||
|
||||
|
||||
int ParseInfo(tinyxml2::XMLElement *outNode, const cat::HCatBuffer &method);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // __HSDKINFO_H__
|
||||
127
SDK/Data/HScreenFunctionInfo.cpp
Normal file
127
SDK/Data/HScreenFunctionInfo.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
|
||||
|
||||
#include <Data/HScreenFunctionInfo.h>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, SwitchTimeInfo &node)
|
||||
{
|
||||
node.ploys.clear();
|
||||
node.weekPloys.clear();
|
||||
node.open = xml.at("open").GetAttribute("enable") == "true";
|
||||
node.ployEnable = xml.at("ploy").GetAttribute("enable") == "true";
|
||||
node.mode = xml.at("ploy").GetAttribute("mode").ToInt();
|
||||
do {
|
||||
if (xml.at("ploy").ContainsNodes("item") == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (const auto &i : xml.at("ploy").at("item")) {
|
||||
SwitchTimeInfo::ployItem item;
|
||||
item.enable = i.GetAttribute("enable") == "true";
|
||||
item.start = i.GetAttribute("start");
|
||||
item.end = i.GetAttribute("end");
|
||||
node.ploys.emplace_back(std::move(item));
|
||||
}
|
||||
} while (false);
|
||||
|
||||
do {
|
||||
if (xml.at("ploy").ContainsNodes("weekItem") == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (const auto &i : xml.at("ploy").at("weekItem")) {
|
||||
SwitchTimeInfo::weekPloyItem item;
|
||||
item.openAllDay = i.GetAttribute("openAllDay").ToInt();
|
||||
item.week = i.GetAttribute("week").ToInt();
|
||||
|
||||
if (i.ContainsNodes("item")) {
|
||||
for (const auto &j : i.at("item")) {
|
||||
SwitchTimeInfo::weekItem itemTime;
|
||||
itemTime.start = j.GetAttribute("start");
|
||||
itemTime.end = j.GetAttribute("end");
|
||||
item.ploys.emplace_back(std::move(itemTime));
|
||||
}
|
||||
}
|
||||
|
||||
node.weekPloys.emplace_back(std::move(item));
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const SwitchTimeInfo &node)
|
||||
{
|
||||
xml["open"] = {"enable", node.ployEnable ? "true" : "false"};
|
||||
xml["ploy"] = {{"mode", node.mode},
|
||||
{"enbale", node.ployEnable}};
|
||||
|
||||
for (const auto &i : node.ploys) {
|
||||
xml["ploy"].emplace_back("item", {{"enable", i.enable},
|
||||
{"start", i.start},
|
||||
{"end", i.end}});
|
||||
}
|
||||
|
||||
for (const auto &i : node.weekPloys) {
|
||||
HXml &item = xml["ploy"].NewChild("weekItem");
|
||||
item = {{"openAllDay", i.openAllDay ? 1 : 0},
|
||||
{"week", i.week}};
|
||||
|
||||
|
||||
for (const auto &j : i.ploys) {
|
||||
item.emplace_back("item", {{"start", j.start},
|
||||
{"end", j.end}});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SwitchTimeInfo::InitWeekPloys()
|
||||
{
|
||||
std::size_t week = 0;
|
||||
const std::size_t weekNum = GetWeekMax();
|
||||
for (auto i = weekPloys.begin(); i != weekPloys.end();) {
|
||||
if (week & (1 << i->week)) {
|
||||
i = weekPloys.erase(i);
|
||||
continue;
|
||||
}
|
||||
week |= 1 << i->week;
|
||||
++i;
|
||||
}
|
||||
|
||||
while (weekPloys.size() < weekNum) {
|
||||
weekPloyItem item;
|
||||
for (std::size_t i = 0; i < weekNum; ++i) {
|
||||
if (week & (1 << i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
week |= 1 << i;
|
||||
item.week = i;
|
||||
}
|
||||
weekPloys.emplace_back(std::move(item));
|
||||
}
|
||||
}
|
||||
|
||||
SwitchTimeInfo::weekPloyItem &SwitchTimeInfo::GetWeekItem(int week)
|
||||
{
|
||||
if (weekPloys.size() < GetWeekMax()) {
|
||||
InitWeekPloys();
|
||||
}
|
||||
|
||||
for (auto &i : weekPloys) {
|
||||
if (i.week == week) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return weekPloys.front();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
64
SDK/Data/HScreenFunctionInfo.h
Normal file
64
SDK/Data/HScreenFunctionInfo.h
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
|
||||
#ifndef __HSCREENFUNCTIONINFO_H__
|
||||
#define __HSCREENFUNCTIONINFO_H__
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <HXml.h>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
///< 开关机
|
||||
struct SwitchTimeInfo
|
||||
{
|
||||
struct ployItem {
|
||||
bool enable; ///< 该项是否使能, 取值范围{"true"(使能), "false"(不使能)}
|
||||
cat::HCatBuffer start; ///< 开屏时刻, 格式hh:mm:ss
|
||||
cat::HCatBuffer end; ///< 关屏时刻, 格式hh:mm:ss
|
||||
};
|
||||
|
||||
struct weekItem {
|
||||
cat::HCatBuffer start; ///< 格式hh:mm:ss
|
||||
cat::HCatBuffer end; ///< 格式hh:mm:ss
|
||||
};
|
||||
|
||||
struct weekPloyItem {
|
||||
int week; ///< 星期数[0-6]
|
||||
bool openAllDay; ///< 全天开机
|
||||
std::vector<weekItem> ploys; ///< 时间项
|
||||
weekPloyItem()
|
||||
: week(0)
|
||||
, openAllDay(true)
|
||||
{}
|
||||
};
|
||||
|
||||
bool open; ///< 当前屏幕状态
|
||||
bool ployEnable; ///< 是否启用定时开关屏
|
||||
int mode; ///< 开关屏模式 0: 每天, 1:每星期
|
||||
std::vector<ployItem> ploys; ///< 开关屏时间段列表
|
||||
std::vector<weekPloyItem> weekPloys; ///< 按星期开关屏时间表
|
||||
|
||||
void InitWeekPloys();
|
||||
static std::size_t GetWeekMax() { return 7; }
|
||||
weekPloyItem &GetWeekItem(int week);
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetSwitchTime"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetSwitchTime"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetSwitchTime"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetSwitchTime"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, SwitchTimeInfo &node);
|
||||
void to_xml(HXml &xml, const SwitchTimeInfo &node);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // HSCREENFUNCTIONINFO_H
|
||||
132
SDK/Data/HSensorInfo.cpp
Normal file
132
SDK/Data/HSensorInfo.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
|
||||
|
||||
#include <Data/HSensorInfo.h>
|
||||
|
||||
|
||||
// 外置继电器最大是6个, 常规系列那边第七个是内置继电器
|
||||
#define MAX_RELAY_NUM (6)
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, SensorInfo &node)
|
||||
{
|
||||
node.luminance = xml.at("luminance").GetAttribute("connect") == "true";
|
||||
node.temp1 = xml.at("temp1").GetAttribute("connect") == "true";
|
||||
node.humidity = xml.at("humidity").GetAttribute("connect") == "true";
|
||||
node.temp2 = xml.at("temp2").GetAttribute("connect") == "true";
|
||||
node.telecontroller = xml.at("telecontroller").GetAttribute("connect") == "true";
|
||||
node.gps = xml.at("gps").GetAttribute("connect") == "true";
|
||||
node.windSpeed = xml.at("windSpeed").GetAttribute("connect") == "true";
|
||||
node.windDirection = xml.at("windDirection").GetAttribute("connect") == "true";
|
||||
node.noise = xml.at("noise").GetAttribute("connect") == "true";
|
||||
node.pressure = xml.at("pressure").GetAttribute("connect") == "true";
|
||||
node.lightIntensity = xml.at("lightIntensity").GetAttribute("connect") == "true";
|
||||
node.rainfall = xml.at("rainfall").GetAttribute("connect") == "true";
|
||||
node.co2 = xml.at("co2").GetAttribute("connect") == "true";
|
||||
node.pm2d5 = xml.at("pm2d5").GetAttribute("connect") == "true";
|
||||
node.pm10 = xml.at("pm10").GetAttribute("connect") == "true";
|
||||
}
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, GpsInfo &node)
|
||||
{
|
||||
node.east = xml.at("gps").GetAttribute("east") == "true";
|
||||
node.north = xml.at("gps").GetAttribute("north") == "true";
|
||||
node.longitude = xml.at("gps").GetAttribute("longitude").ToFloat();
|
||||
node.latitude = xml.at("gps").GetAttribute("latitude ").ToFloat();
|
||||
node.counts = xml.at("gps").GetAttribute("counts").ToInt();
|
||||
node.speed = xml.at("gps").GetAttribute("speed ").ToFloat();
|
||||
node.direction = xml.at("gps").GetAttribute("direction").ToFloat();
|
||||
}
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, RelayInfo &node)
|
||||
{
|
||||
node.relayList.clear();
|
||||
node.internal.ploys.clear();
|
||||
|
||||
for (const auto &i : xml.at("item")) {
|
||||
RelayInfo::realyItem item;
|
||||
item.name = i.GetAttribute("name");
|
||||
item.relayStatus = i.GetAttribute("relayStatus").ToInt();
|
||||
item.useSwitch = DataToType<bool>(i.GetAttribute("useSwitch"));
|
||||
if (i.ContainsNodes("time") == false) {
|
||||
node.relayList.emplace_back(std::move(item));
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const auto &j : i.at("time")) {
|
||||
RelayInfo::ployItem timeItem;
|
||||
timeItem.start = j.GetAttribute("start");
|
||||
timeItem.end = j.GetAttribute("end");
|
||||
item.ploys.emplace_back(std::move(timeItem));
|
||||
}
|
||||
node.relayList.emplace_back(std::move(item));
|
||||
}
|
||||
|
||||
do {
|
||||
if (xml.ContainsNodes("internal") == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
node.internal.name = xml.at("internal").GetAttribute("name");
|
||||
node.internal.relayStatus = xml.at("internal").GetAttribute("relayStatus").ToInt();
|
||||
node.internal.useSwitch = DataToType<bool>(xml.at("internal").GetAttribute("useSwitch"));
|
||||
if (xml.at("internal").ContainsNodes("time") == false) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (const auto &i : xml.at("internal").at("time")) {
|
||||
RelayInfo::ployItem timeItem;
|
||||
timeItem.start = i.GetAttribute("start");
|
||||
timeItem.end = i.GetAttribute("end");
|
||||
node.internal.ploys.emplace_back(std::move(timeItem));
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const RelayInfo &node)
|
||||
{
|
||||
for (const auto &i : node.relayList) {
|
||||
HXml &item = xml.NewChild("item");
|
||||
item = {{"relayStatus", i.relayStatus},
|
||||
{"name", i.name},
|
||||
{"useSwitch", i.useSwitch ? 1 : 0}};
|
||||
|
||||
for (const auto &j : i.ploys) {
|
||||
item.NewChild("time") = {{"start", j.start},
|
||||
{"end", j.end}};
|
||||
}
|
||||
}
|
||||
|
||||
for (auto i = node.relayList.size(); i < MAX_RELAY_NUM; ++i) {
|
||||
xml.NewChild("item") = {{"relayStatus", "0"},
|
||||
{"name", ""},
|
||||
{"useSwitch", "0"}};
|
||||
}
|
||||
|
||||
xml["internal"] = {{"relayStatus", node.internal.relayStatus},
|
||||
{"name", node.internal.name},
|
||||
{"useSwitch", node.internal.useSwitch ? 1 : 0}};
|
||||
|
||||
for (const auto &i : node.internal.ploys) {
|
||||
xml["internal"].NewChild("time") = {{"start", i.start},
|
||||
{"end", i.end}};
|
||||
}
|
||||
}
|
||||
|
||||
void RelayInfo::InitRelayList()
|
||||
{
|
||||
while (relayList.size() < MAX_RELAY_NUM) {
|
||||
relayList.emplace_back(realyItem());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
119
SDK/Data/HSensorInfo.h
Normal file
119
SDK/Data/HSensorInfo.h
Normal file
@ -0,0 +1,119 @@
|
||||
|
||||
|
||||
#ifndef __HSENSORINFO_H__
|
||||
#define __HSENSORINFO_H__
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <HXml.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
///< 传感器状态
|
||||
struct SensorInfo
|
||||
{
|
||||
bool luminance; ///< 是否接入亮度传感器
|
||||
bool temp1; ///< 是否接入温度传感器1
|
||||
bool humidity; ///< 是否接入湿度传感器
|
||||
bool temp2; ///< 是否接入温度传感器2
|
||||
bool telecontroller; ///< 是否接入遥控器
|
||||
bool gps; ///< 是否接入gps
|
||||
bool windSpeed; ///< 是否接入风速传感器
|
||||
bool windDirection; ///< 是否接入风向传感器
|
||||
bool noise; ///< 是否接入噪音传感器
|
||||
bool pressure; ///< 是否接入压力传感器
|
||||
bool lightIntensity; ///< 是否接入光照强度传感器
|
||||
bool rainfall; ///< 是否接入降雨量传感器
|
||||
bool co2; ///< 是否接入二氧化碳传感器
|
||||
bool pm2d5; ///< 是否接入PM2.5传感器
|
||||
bool pm10; ///< 是否接入PM10传感器
|
||||
|
||||
SensorInfo()
|
||||
: luminance(false)
|
||||
, temp1(false)
|
||||
, humidity(false)
|
||||
, temp2(false)
|
||||
, telecontroller(false)
|
||||
, gps(false)
|
||||
, windSpeed(false)
|
||||
, windDirection(false)
|
||||
, noise(false)
|
||||
, pressure(false)
|
||||
, lightIntensity(false)
|
||||
, rainfall(false)
|
||||
, co2(false)
|
||||
, pm2d5(false)
|
||||
, pm10(false)
|
||||
{}
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetSensorInfo"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetSensorInfo"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, SensorInfo &node);
|
||||
|
||||
|
||||
///< gps
|
||||
struct GpsInfo
|
||||
{
|
||||
bool east; ///< 东方
|
||||
bool north; ///< 北方
|
||||
double longitude; ///< 经度
|
||||
double latitude; ///< 纬度
|
||||
int counts; ///< 计数
|
||||
float speed; ///< 速度
|
||||
float direction; ///< 方向
|
||||
|
||||
GpsInfo()
|
||||
: east(false)
|
||||
, north(false)
|
||||
, longitude(0.0)
|
||||
, latitude(0.0)
|
||||
, counts(0)
|
||||
, speed(0.0)
|
||||
, direction(0.0)
|
||||
{}
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetGPSInfo"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetGPSInfo"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, GpsInfo &node);
|
||||
|
||||
|
||||
///< 继电器
|
||||
struct RelayInfo
|
||||
{
|
||||
struct ployItem {
|
||||
cat::HCatBuffer start; ///< 格式 hh:mm:ss
|
||||
cat::HCatBuffer end; ///< 格式 hh:mm:ss
|
||||
};
|
||||
|
||||
struct realyItem {
|
||||
int relayStatus; ///< 继电器状态{0: 未知 1:继电器开启 2:继电器关闭}
|
||||
cat::HCatBuffer name; ///< 继电器名称
|
||||
bool useSwitch; ///< 关联显示屏状态 {1:true 0:false}
|
||||
std::vector<ployItem> ploys; ///< 时间项
|
||||
realyItem() : relayStatus(0), useSwitch(false) {}
|
||||
};
|
||||
|
||||
std::vector<realyItem> relayList; ///< 开关配置列表
|
||||
realyItem internal; ///< 板载继电器
|
||||
|
||||
void InitRelayList();
|
||||
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetRelayInfo"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetRelayInfo"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetRelayInfo"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetRelayInfo"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, RelayInfo &node);
|
||||
void to_xml(HXml &xml, const RelayInfo &node);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // HSENSORINFO_H
|
||||
37
SDK/Data/HTimeInfo.cpp
Normal file
37
SDK/Data/HTimeInfo.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <Data/HTimeInfo.h>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
void from_xml(const HXml &xml, TimeInfo &node)
|
||||
{
|
||||
node.timeZone = xml.at("timezone").GetAttribute("value");
|
||||
node.summer = xml.at("summer").GetAttribute("enable") == "true";
|
||||
node.sync = xml.at("sync").GetAttribute("value");
|
||||
node.currTime = xml.at("time").GetAttribute("value");
|
||||
node.serverList.Clear();
|
||||
if (xml.ContainsNodes("server")) {
|
||||
node.serverList = xml.at("server").GetAttribute("list");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void to_xml(HXml &xml, const TimeInfo &node)
|
||||
{
|
||||
xml["timezone"] = {"value", node.timeZone};
|
||||
xml["summer"] = {{"enable", node.summer}};
|
||||
xml["sync"] = {"value", node.sync.Empty() ? "none" : node.sync};
|
||||
xml["time"] = {"value", node.currTime};
|
||||
xml["server"] = {"list", node.serverList};
|
||||
xml["rf"]["enable"] = {"value", node.rf.enable};
|
||||
xml["rf"]["master"] = {"value", node.rf.master};
|
||||
xml["rf"]["channel"] = {"value", node.rf.channel};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
50
SDK/Data/HTimeInfo.h
Normal file
50
SDK/Data/HTimeInfo.h
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
|
||||
#ifndef __HTIMEINFO_H__
|
||||
#define __HTIMEINFO_H__
|
||||
|
||||
|
||||
#include <HCatBuffer.h>
|
||||
#include <HXml.h>
|
||||
|
||||
|
||||
namespace sdk
|
||||
{
|
||||
|
||||
|
||||
///< 时间
|
||||
struct TimeInfo
|
||||
{
|
||||
struct Rf {
|
||||
bool enable; ///< rf同步是否使能
|
||||
bool master; ///< 主设备
|
||||
int channel; ///< 通道
|
||||
Rf()
|
||||
: enable(false)
|
||||
, master(false)
|
||||
, channel(0)
|
||||
{};
|
||||
};
|
||||
|
||||
cat::HCatBuffer timeZone; ///< 时区字符串
|
||||
bool summer; ///< 是否开启夏令时
|
||||
cat::HCatBuffer sync; ///< 时间同步模式
|
||||
cat::HCatBuffer currTime; ///< 当前控制卡时间 yyyy-mm-dd hh:MM:ss
|
||||
cat::HCatBuffer serverList; ///< 服务器列表, 逗号分隔
|
||||
Rf rf; ///< rf模块
|
||||
|
||||
TimeInfo()
|
||||
: summer(false)
|
||||
{}
|
||||
static bool MatchGet(const cat::HCatBuffer &item) { return item == "GetTimeInfo"; }
|
||||
static bool MatchSet(const cat::HCatBuffer &item) { return item == "SetTimeInfo"; }
|
||||
static cat::HCatBuffer GetMethod() { return "GetTimeInfo"; }
|
||||
static cat::HCatBuffer SetMethod() { return "SetTimeInfo"; }
|
||||
};
|
||||
void from_xml(const HXml &xml, TimeInfo &node);
|
||||
void to_xml(HXml &xml, const TimeInfo &node);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // __HTIMEINFO_H__
|
||||
588
SDK/HCatBuffer.h
Normal file
588
SDK/HCatBuffer.h
Normal file
@ -0,0 +1,588 @@
|
||||
|
||||
|
||||
#ifndef __HCATBUFFER_H__
|
||||
#define __HCATBUFFER_H__
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace cat
|
||||
{
|
||||
|
||||
|
||||
class HCatBuffer
|
||||
{
|
||||
public:
|
||||
typedef typename std::string::difference_type difference_type;
|
||||
typedef HCatBuffer value_type;
|
||||
typedef HCatBuffer * pointer;
|
||||
typedef HCatBuffer & reference;
|
||||
typedef typename std::string::iterator::iterator_category iterator_category;
|
||||
|
||||
public:
|
||||
HCatBuffer() : buff_(new std::string()) {}
|
||||
explicit HCatBuffer(std::size_t len) : buff_(new std::string(len, '\0')) {}
|
||||
HCatBuffer(std::size_t len, char c) : buff_(new std::string(len, c)) {}
|
||||
HCatBuffer(const char *buff, std::size_t len) : buff_(new std::string(buff, len)) {}
|
||||
HCatBuffer(const char *buff) : buff_(new std::string(buff ? buff : "")) {}
|
||||
HCatBuffer(const std::string &buff) : buff_(new std::string(buff)) {}
|
||||
HCatBuffer(std::string &&buff) : buff_(new std::string(std::move(buff))) {}
|
||||
HCatBuffer(const HCatBuffer &buff) : buff_(buff.buff_) {}
|
||||
|
||||
std::string::iterator begin() { Detach(); return buff_->begin(); }
|
||||
std::string::const_iterator begin() const { return buff_->begin(); }
|
||||
std::string::iterator end() { Detach(); return buff_->end(); }
|
||||
std::string::const_iterator end() const { return buff_->end(); }
|
||||
|
||||
static bool isUpperCaseAscii(char c) { return c >= 'A' && c <= 'Z'; }
|
||||
static bool isLowerCaseAscii(char c) { return c >= 'a' && c <= 'z'; }
|
||||
bool isUpper() const { return !std::any_of(buff_->begin(), buff_->end(), isLowerCaseAscii); }
|
||||
bool isLower() const { return !std::any_of(buff_->begin(), buff_->end(), isUpperCaseAscii); }
|
||||
|
||||
static unsigned char asciiUpper(unsigned char c) { return c >= 'a' && c <= 'z' ? c & ~0x20 : c; }
|
||||
static unsigned char asciiLower(unsigned char c) { return c >= 'A' && c <= 'Z' ? c | 0x20 : c; }
|
||||
HCatBuffer toLower() const {
|
||||
HCatBuffer result(*this);
|
||||
std::transform(buff_->begin(), buff_->end(), result.begin(), asciiLower);
|
||||
return result;
|
||||
}
|
||||
HCatBuffer toUpper() const {
|
||||
HCatBuffer result(*this);
|
||||
std::transform(buff_->begin(), buff_->end(), result.begin(), asciiUpper);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string GetString() const { return *buff_; }
|
||||
std::string GetString(std::size_t len) const { return buff_->substr(0, len); }
|
||||
const std::string &GetConstString() const { return *buff_; }
|
||||
std::string &GetRefString() { Detach(); return *buff_; }
|
||||
|
||||
std::string::pointer Data() { Detach(); return &buff_->front(); }
|
||||
std::string::const_pointer Data() const { return &buff_->front(); }
|
||||
std::string::const_pointer ConstData() const { return buff_->data(); }
|
||||
std::size_t Size() const { return buff_->size(); }
|
||||
HCatBuffer &Swap(HCatBuffer &buff) { Detach(); buff_.swap(buff.buff_); return *this; }
|
||||
std::string::reference At(std::size_t index) { Detach(); return buff_->at(index); }
|
||||
std::string::const_reference At(std::size_t index) const { return buff_->at(index); }
|
||||
bool Empty() const { return buff_->empty(); }
|
||||
HCatBuffer &Clear() { Detach(); std::string().swap(*buff_); return *this; }
|
||||
|
||||
std::string::reference operator [](std::size_t index) { Detach(); return buff_->at(index); }
|
||||
std::string::const_reference operator [](std::size_t index) const { return buff_->at(index); }
|
||||
|
||||
HCatBuffer &Insert(const char *buff, std::size_t index) { Detach(); buff_->insert(index, buff); return *this; }
|
||||
HCatBuffer &Insert(const char *buff, std::size_t index, std::size_t len) { Detach(); buff_->insert(index, buff, len); return *this; }
|
||||
HCatBuffer &Insert(const std::string &buff, std::size_t index) { Detach(); buff_->insert(index, buff); return *this; }
|
||||
HCatBuffer &Insert(const HCatBuffer &buff, std::size_t index) { Detach(); buff_->insert(index, *buff.buff_); return *this; }
|
||||
|
||||
HCatBuffer &Remove(std::size_t index, std::size_t num = std::string::npos) {
|
||||
if (index > buff_->size()) {
|
||||
index = buff_->size();
|
||||
}
|
||||
Detach();
|
||||
buff_->erase(index, num);
|
||||
return *this;
|
||||
}
|
||||
|
||||
HCatBuffer Mid(std::size_t index, std::size_t len = std::string::npos) const {
|
||||
if (index >= buff_->size()) {
|
||||
return HCatBuffer();
|
||||
}
|
||||
if (len > buff_->size()) {
|
||||
len = buff_->size();
|
||||
}
|
||||
if (len > buff_->size() - index) {
|
||||
len = buff_->size() - index;
|
||||
}
|
||||
if (index == 0 && len == buff_->size()) {
|
||||
return *this;
|
||||
}
|
||||
return HCatBuffer(buff_->substr(index, len));
|
||||
}
|
||||
|
||||
std::string::size_type Find(char value, std::size_t pos = 0) const { return buff_->find(value, pos); }
|
||||
std::string::size_type Find(const char *value, std::size_t pos = 0) const { return buff_->find(value, pos); }
|
||||
std::string::size_type Find(const std::string &value, std::size_t pos = 0) const { return buff_->find(value, pos); }
|
||||
std::string::size_type IndexOf(char value, std::size_t pos = 0) const { return Find(value, pos); }
|
||||
std::string::size_type IndexOf(const char *value, std::size_t pos = 0) const { return Find(value, pos); }
|
||||
std::string::size_type IndexOf(const std::string &value, std::size_t pos = 0) const { return Find(value, pos); }
|
||||
|
||||
std::string::size_type Rfind(char value, std::size_t pos = std::string::npos) const { return buff_->rfind(value, pos); }
|
||||
std::string::size_type Rfind(const char *value, std::size_t pos = std::string::npos) const { return buff_->rfind(value, pos); }
|
||||
std::string::size_type Rfind(const std::string &value, std::size_t pos = std::string::npos) const { return buff_->rfind(value, pos); }
|
||||
std::string::size_type LastIndexOf(char value, std::size_t pos = std::string::npos) const { return Rfind(value, pos); }
|
||||
std::string::size_type LastIndexOf(const char *value, std::size_t pos = std::string::npos) const { return Rfind(value, pos); }
|
||||
std::string::size_type LastIndexOf(const std::string &value, std::size_t pos = std::string::npos) const { return Rfind(value, pos); }
|
||||
|
||||
bool Contains(char c) const { return IndexOf(c) != std::string::npos; }
|
||||
bool Contains(const char *c) const { return IndexOf(c) != std::string::npos; }
|
||||
bool Contains(const std::string &c) const { return IndexOf(c) != std::string::npos; }
|
||||
|
||||
HCatBuffer &Append(const std::string &buff) { Detach(); buff_->append(buff); return *this; }
|
||||
HCatBuffer &Append(std::string &&buff) { Detach(); buff_->append(std::move(buff)); return *this; }
|
||||
HCatBuffer &Append(const HCatBuffer &buff) { Detach(); buff_->append(*buff.buff_); return *this; }
|
||||
HCatBuffer &Append(HCatBuffer &&buff) { Detach(); buff_->append(std::move(*buff.buff_)); return *this; }
|
||||
HCatBuffer &Append(const char *buff) { if (buff == nullptr) { return *this; } Detach(); buff_->append(buff); return *this; }
|
||||
HCatBuffer &Append(const char *buff, std::size_t size) { Detach(); buff_->append(buff, size); return *this; }
|
||||
HCatBuffer &Append(const unsigned char *buff) { Detach(); buff_->append(reinterpret_cast<const char *>(buff)); return *this; }
|
||||
HCatBuffer &Append(const unsigned char *buff, std::size_t size) { Detach(); buff_->append(reinterpret_cast<const char *>(buff), size); return *this; }
|
||||
HCatBuffer &Append(const char buff) { Detach(); buff_->push_back(buff); return *this; }
|
||||
HCatBuffer &Append(int len, const char buff) { Detach(); buff_->append(len, buff); return *this; }
|
||||
HCatBuffer &Append(const unsigned char buff) { Detach(); buff_->push_back(static_cast<char>(buff)); return *this; }
|
||||
HCatBuffer &Append(int len, const unsigned char buff) { Detach(); buff_->append(len, static_cast<char>(buff)); return *this; }
|
||||
|
||||
HCatBuffer &Replace(const std::string &src, const std::string &dest) {
|
||||
std::string::size_type pos = buff_->find(src);
|
||||
if (pos == std::string::npos) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Detach();
|
||||
buff_->replace(pos, src.size(), dest);
|
||||
return *this;
|
||||
}
|
||||
|
||||
HCatBuffer Left(std::size_t len) const {
|
||||
if (len >= buff_->size()) {
|
||||
return *this;
|
||||
}
|
||||
return HCatBuffer(buff_->data(), len);
|
||||
}
|
||||
HCatBuffer Right(std::size_t len) const {
|
||||
if (len >= buff_->size()) {
|
||||
return *this;
|
||||
}
|
||||
return HCatBuffer((&(*buff_->end())) - len, len);
|
||||
}
|
||||
|
||||
bool StartsWith(const cat::HCatBuffer &other) const {
|
||||
if (Size() < other.Size()) {
|
||||
return false;
|
||||
}
|
||||
if (buff_ == other.buff_ || other.Size() == 0) {
|
||||
return true;
|
||||
}
|
||||
return memcmp(ConstData(), other.ConstData(), other.Size()) == 0;
|
||||
}
|
||||
bool EndsWith(const cat::HCatBuffer &other) const {
|
||||
if (Size() < other.Size()) {
|
||||
return false;
|
||||
}
|
||||
if (buff_ == other.buff_ || other.Size() == 0) {
|
||||
return true;
|
||||
}
|
||||
return memcmp((ConstData() + Size() - other.Size()), other.ConstData(), other.Size()) == 0;
|
||||
}
|
||||
|
||||
std::vector<HCatBuffer> Split(const std::string &sep, bool keepEmpty = true) const {
|
||||
std::vector<HCatBuffer> result;
|
||||
std::size_t startPos = 0;
|
||||
std::size_t endPos = 0;
|
||||
std::size_t extra = 0;
|
||||
while ((endPos = buff_->find(sep, startPos + extra)) != std::string::npos) {
|
||||
result.emplace_back(Mid(startPos, endPos - startPos));
|
||||
startPos = endPos + sep.size();
|
||||
extra = sep.size() == 0 ? 1 : 0;
|
||||
}
|
||||
if (startPos != buff_->size() || keepEmpty) {
|
||||
result.emplace_back(Mid(startPos));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
std::vector<HCatBuffer> Split(char sep, bool keepEmpty = true) const { return Split(std::string(1, sep), keepEmpty); }
|
||||
static HCatBuffer Join(const std::vector<HCatBuffer> &that, const cat::HCatBuffer &sep) {
|
||||
std::size_t totalLen = 0;
|
||||
const std::size_t size = that.size();
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
totalLen += that.at(i).Size();
|
||||
}
|
||||
if (size > 0) {
|
||||
totalLen += sep.Size() * (size - 1);
|
||||
}
|
||||
|
||||
HCatBuffer result;
|
||||
if (totalLen) {
|
||||
result.buff_->reserve(totalLen);
|
||||
}
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
if (i) {
|
||||
result.Append(sep);
|
||||
}
|
||||
result.Append(that.at(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
static HCatBuffer Join(const std::vector<HCatBuffer> &that, char sep) { return Join(that, HCatBuffer(1, sep)); }
|
||||
|
||||
HCatBuffer Simplified() const {
|
||||
if (buff_->empty()) {
|
||||
return *this;
|
||||
}
|
||||
const char *srcPos = ConstData();
|
||||
const char *endPos = ConstData() + Size();
|
||||
cat::HCatBuffer result(Size());
|
||||
char *dst = result.Data();
|
||||
char *ptr = dst;
|
||||
for (;;) {
|
||||
while (srcPos != endPos && std::isspace(static_cast<unsigned char>(*srcPos))) {
|
||||
++srcPos;
|
||||
}
|
||||
while (srcPos != endPos && !std::isspace(static_cast<unsigned char>(*srcPos))) {
|
||||
*ptr++ = *srcPos++;
|
||||
}
|
||||
if (srcPos == endPos) {
|
||||
break;
|
||||
}
|
||||
*ptr++ = ' ';
|
||||
}
|
||||
if (ptr != dst && std::isspace(static_cast<unsigned char>(ptr[-1]))) {
|
||||
--ptr;
|
||||
}
|
||||
|
||||
std::size_t newLen = ptr - dst;
|
||||
result.buff_->resize(newLen);
|
||||
return result;
|
||||
}
|
||||
|
||||
static char ToHexLower(int value) noexcept { return "0123456789abcdef"[value & 0xF]; }
|
||||
static char toHexUpper(int value) noexcept { return "0123456789ABCDEF"[value & 0xF]; }
|
||||
HCatBuffer ToHex(char separator, bool upper = false) const {
|
||||
if (buff_->empty()) {
|
||||
return HCatBuffer();
|
||||
}
|
||||
|
||||
const std::size_t length = separator ? (buff_->size() * 3 - 1) : (buff_->size() * 2);
|
||||
HCatBuffer hex(length);
|
||||
char *hexData = hex.Data();
|
||||
const unsigned char *data = reinterpret_cast<const unsigned char *>(this->ConstData());
|
||||
for (std::size_t i = 0, o = 0; i < buff_->size(); ++i) {
|
||||
if (upper) {
|
||||
hexData[o++] = toHexUpper(data[i] >> 4);
|
||||
hexData[o++] = toHexUpper(data[i] & 0xf);
|
||||
} else {
|
||||
hexData[o++] = ToHexLower(data[i] >> 4);
|
||||
hexData[o++] = ToHexLower(data[i] & 0xf);
|
||||
}
|
||||
|
||||
if ((separator) && (o < length))
|
||||
hexData[o++] = separator;
|
||||
}
|
||||
|
||||
return hex;
|
||||
}
|
||||
|
||||
static int FromHex(int c) {
|
||||
return ((c >= '0') && (c <= '9')) ? int(c - '0') :
|
||||
((c >= 'A') && (c <= 'F')) ? int(c - 'A' + 10) :
|
||||
((c >= 'a') && (c <= 'f')) ? int(c - 'a' + 10) :
|
||||
/* otherwise */ -1;
|
||||
}
|
||||
static HCatBuffer FromHex(const HCatBuffer &hexEncoded) {
|
||||
HCatBuffer res((hexEncoded.Size() + 1) / 2);
|
||||
unsigned char *result = reinterpret_cast<unsigned char *>(res.Data() + res.Size());
|
||||
|
||||
bool odd_digit = true;
|
||||
for (long i = hexEncoded.Size() - 1; i >= 0; --i) {
|
||||
unsigned char ch = static_cast<unsigned char>(hexEncoded.At(i));
|
||||
int tmp = FromHex(ch);
|
||||
if (tmp == -1)
|
||||
continue;
|
||||
if (odd_digit) {
|
||||
--result;
|
||||
*result = tmp;
|
||||
odd_digit = false;
|
||||
} else {
|
||||
*result |= tmp << 4;
|
||||
odd_digit = true;
|
||||
}
|
||||
}
|
||||
|
||||
res.Remove(0, result - reinterpret_cast<const unsigned char *>(res.ConstData()));
|
||||
return res;
|
||||
}
|
||||
|
||||
HCatBuffer ToBase64() const {
|
||||
if (this->Empty()) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
const char alphabet_base64[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef"
|
||||
"ghijklmn" "opqrstuv" "wxyz0123" "456789+/";
|
||||
const char *const alphabet = alphabet_base64;
|
||||
const char padchar = '=';
|
||||
int padlen = 0;
|
||||
const std::size_t sz = Size();
|
||||
HCatBuffer tmp((sz + 2) / 3 * 4);
|
||||
|
||||
std::size_t i = 0;
|
||||
char *out = tmp.Data();
|
||||
while (i < sz) {
|
||||
int chunk = 0;
|
||||
chunk |= int(static_cast<unsigned char>(ConstData()[i++])) << 16;
|
||||
if (i == sz) {
|
||||
padlen = 2;
|
||||
} else {
|
||||
chunk |= int(static_cast<unsigned char>(ConstData()[i++])) << 8;
|
||||
if (i == sz) {
|
||||
padlen = 1;
|
||||
} else {
|
||||
chunk |= int(static_cast<unsigned char>(ConstData()[i++]));
|
||||
}
|
||||
}
|
||||
|
||||
int j = (chunk & 0x00fc0000) >> 18;
|
||||
int k = (chunk & 0x0003f000) >> 12;
|
||||
int l = (chunk & 0x00000fc0) >> 6;
|
||||
int m = (chunk & 0x0000003f);
|
||||
*out++ = alphabet[j];
|
||||
*out++ = alphabet[k];
|
||||
|
||||
if (padlen > 1) {
|
||||
*out++ = padchar;
|
||||
} else {
|
||||
*out++ = alphabet[l];
|
||||
}
|
||||
if (padlen > 0) {
|
||||
*out++ = padchar;
|
||||
} else {
|
||||
*out++ = alphabet[m];
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t diffSize = out - tmp.ConstData();
|
||||
if (diffSize < tmp.Size()) {
|
||||
tmp.buff_->resize(diffSize);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static HCatBuffer FromBase64(const HCatBuffer &base64) {
|
||||
if (base64.Empty()) {
|
||||
return base64;
|
||||
}
|
||||
const auto inputSize = base64.Size();
|
||||
HCatBuffer result((inputSize * 3) / 4);
|
||||
enum Base64Option {
|
||||
Base64Encoding = 0,
|
||||
Base64UrlEncoding = 1,
|
||||
IgnoreBase64DecodingErrors = 0,
|
||||
AbortOnBase64DecodingErrors = 4,
|
||||
};
|
||||
Base64Option options = Base64Encoding;
|
||||
|
||||
const char *input = base64.ConstData();
|
||||
char *output = result.Data();
|
||||
unsigned int buf = 0;
|
||||
int nbits = 0;
|
||||
|
||||
std::size_t offset = 0;
|
||||
for (std::size_t i = 0; i < inputSize; ++i) {
|
||||
int ch = input[i];
|
||||
int d;
|
||||
|
||||
if (ch >= 'A' && ch <= 'Z') {
|
||||
d = ch - 'A';
|
||||
} else if (ch >= 'a' && ch <= 'z') {
|
||||
d = ch - 'a' + 26;
|
||||
} else if (ch >= '0' && ch <= '9') {
|
||||
d = ch - '0' + 52;
|
||||
} else if (ch == '+' && (options & Base64UrlEncoding) == 0) {
|
||||
d = 62;
|
||||
} else if (ch == '-' && (options & Base64UrlEncoding) != 0) {
|
||||
d = 62;
|
||||
} else if (ch == '/' && (options & Base64UrlEncoding) == 0) {
|
||||
d = 63;
|
||||
} else if (ch == '_' && (options & Base64UrlEncoding) != 0) {
|
||||
d = 63;
|
||||
} else {
|
||||
if (options & AbortOnBase64DecodingErrors) {
|
||||
if (ch == '=') {
|
||||
// can have 1 or 2 '=' signs, in both cases padding base64Size to
|
||||
// a multiple of 4. Any other case is illegal.
|
||||
if ((inputSize % 4) != 0) {
|
||||
result.Clear();
|
||||
return result;
|
||||
} else if ((i == inputSize - 1) ||
|
||||
(i == inputSize - 2 && input[++i] == '=')) {
|
||||
d = -1; // ... and exit the loop, normally
|
||||
} else {
|
||||
result.Clear();
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
result.Clear();
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
d = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (d != -1) {
|
||||
buf = (buf << 6) | d;
|
||||
nbits += 6;
|
||||
if (nbits >= 8) {
|
||||
nbits -= 8;
|
||||
if (offset >= i) {
|
||||
result.Clear();
|
||||
return result;
|
||||
}
|
||||
output[offset++] = buf >> nbits;
|
||||
buf &= (1 << nbits) - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (offset < result.Size()) {
|
||||
result.buff_->resize(offset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int ToInt(int base = 10) const {
|
||||
if (buff_->empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
try {
|
||||
#if __cplusplus >= 201402L
|
||||
result = std::stoi(buff_->data(), nullptr, base);
|
||||
#else
|
||||
result = strtol(buff_->data(), nullptr, base);
|
||||
#endif
|
||||
} catch(...) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
long long ToLongLong(int base = 10) const {
|
||||
if (buff_->empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
long long result = 0;
|
||||
try {
|
||||
#if __cplusplus >= 201402L
|
||||
result = std::stoll(buff_->data(), nullptr, base);
|
||||
#else
|
||||
result = strtoll(buff_->data(), nullptr, base);
|
||||
#endif
|
||||
} catch(...) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
float ToFloat() const {
|
||||
if (buff_->empty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float result = 0.0;
|
||||
try {
|
||||
#if __cplusplus >= 201402L
|
||||
result = std::stof(buff_->data());
|
||||
#else
|
||||
result = strtof(buff_->data(), nullptr);
|
||||
#endif
|
||||
} catch(...) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
HCatBuffer &SetNum(long long n, int base = 10) {
|
||||
// big enough for MAX_ULLONG in base 2
|
||||
const int buffsize = 66;
|
||||
char buff[buffsize];
|
||||
char *p = nullptr;
|
||||
if (n < 0) {
|
||||
p = LToS(buff + buffsize, static_cast<unsigned long long>(-(1 + n) + 1), base);
|
||||
*--p = '-';
|
||||
} else {
|
||||
p = LToS(buff + buffsize, static_cast<unsigned long long>(n), base);
|
||||
}
|
||||
Clear();
|
||||
return Append(p, buffsize - (p - buff));
|
||||
}
|
||||
HCatBuffer &SetNum(unsigned long long n, int base = 10) {
|
||||
// big enough for MAX_ULLONG in base 2
|
||||
const int buffsize = 66;
|
||||
char buff[buffsize];
|
||||
char *p = LToS(buff + buffsize, n, base);
|
||||
Clear();
|
||||
return Append(p, buffsize - (p - buff));
|
||||
}
|
||||
|
||||
static HCatBuffer Number(int value, int base = 10) { HCatBuffer result; return result.SetNum(static_cast<unsigned long long>(value), base); }
|
||||
static HCatBuffer Number(long long value, int base = 10) { HCatBuffer result; return result.SetNum(value, base); }
|
||||
|
||||
|
||||
HCatBuffer operator +(const HCatBuffer &buff) const { return *buff_ + *buff.buff_; }
|
||||
HCatBuffer operator +(const std::string &buff) const { return *buff_ + buff; }
|
||||
HCatBuffer operator +(const char *buff) const { return *buff_ + buff; }
|
||||
HCatBuffer operator +(const char buff) const { return *buff_ + buff; }
|
||||
|
||||
HCatBuffer &operator +=(const HCatBuffer &buff) { return Append(buff); }
|
||||
HCatBuffer &operator +=(const std::string &buff) { return Append(buff); }
|
||||
HCatBuffer &operator +=(const char *buff) { return Append(buff); }
|
||||
HCatBuffer &operator +=(const char buff) { return Append(buff); }
|
||||
|
||||
HCatBuffer &operator =(const HCatBuffer &buff) { Detach(); buff_->assign(*buff.buff_); return *this; }
|
||||
HCatBuffer &operator =(const std::string &buff) { Detach(); buff_->assign(buff); return *this; }
|
||||
HCatBuffer &operator =(std::string &&buff) { Detach(); buff_->assign(std::move(buff)); return *this; }
|
||||
HCatBuffer &operator =(const char *buff) { if (buff == nullptr) { return *this; } Detach(); buff_->assign(buff); return *this; }
|
||||
|
||||
bool operator==(const HCatBuffer &buff) const { return *buff_ == *buff.buff_; }
|
||||
bool operator==(const std::string &buff) const { return *buff_ == buff; }
|
||||
bool operator==(const char *buff) const { return *buff_ == buff; }
|
||||
|
||||
bool operator!=(const HCatBuffer &buff) const { return *buff_ != *buff.buff_; }
|
||||
bool operator!=(const std::string &buff) const { return *buff_ != buff; }
|
||||
bool operator!=(const char *buff) const { return *buff_ != buff; }
|
||||
|
||||
bool operator<(const HCatBuffer &buff) const { return *buff_ < *buff.buff_; }
|
||||
bool operator<=(const HCatBuffer &buff) const { return *buff_ < *buff.buff_; }
|
||||
bool operator>(const HCatBuffer &buff) const { return *buff_ > *buff.buff_; }
|
||||
bool operator>=(const HCatBuffer &buff) const { return *buff_ > *buff.buff_; }
|
||||
|
||||
private:
|
||||
void Detach() {
|
||||
if (buff_.use_count() <= 1) {
|
||||
return ;
|
||||
}
|
||||
|
||||
buff_.reset(new std::string(*buff_));
|
||||
}
|
||||
|
||||
// Convert number to string
|
||||
static char *LToS(char *p , unsigned long long n, int base) {
|
||||
if (base < 2 || base > 36) {
|
||||
base = 10;
|
||||
}
|
||||
const char b = 'a' - 10;
|
||||
do {
|
||||
const int c = n % base;
|
||||
n /= base;
|
||||
*--p = c + (c < 10 ? '0' : b);
|
||||
} while (n);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::string> buff_;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // __HCATBUFFER_H__
|
||||
350
SDK/HXml.cpp
Normal file
350
SDK/HXml.cpp
Normal file
@ -0,0 +1,350 @@
|
||||
|
||||
|
||||
#include <HXml.h>
|
||||
#include <exception>
|
||||
#include <HDSDK.h>
|
||||
|
||||
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
||||
HXmlHelper::HXmlHelper(bool declaration)
|
||||
{
|
||||
if (declaration) {
|
||||
doc_.InsertFirstChild(doc_.NewDeclaration());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HXml &HXmlHelper::FindElement(HXml &parent, const char *nodeName)
|
||||
{
|
||||
// 当前自身是空节点, 是root节点
|
||||
if (parent.node_ == nullptr) {
|
||||
parent.node_ = doc_.NewElement(nodeName);
|
||||
doc_.InsertEndChild(parent.node_);
|
||||
return AddElement(parent.node_);
|
||||
}
|
||||
|
||||
// 检查是否是根自身节点, 这里由于上面创建的新节点是给root节点
|
||||
// 这导致一个问题, root节点无法创建同名的子节点, 但子节点可以创建同名的孙子节点
|
||||
if (strcmp(parent.node_->Value(), nodeName) == 0) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
// 查找下一个节点
|
||||
tinyxml2::XMLElement *next = parent.node_->FirstChildElement(nodeName);
|
||||
if (next == nullptr) {
|
||||
next = parent.node_->InsertNewChildElement(nodeName);
|
||||
}
|
||||
|
||||
return AddElement(next);
|
||||
}
|
||||
|
||||
|
||||
const HXml &HXmlHelper::FindElement(const HXml &parent, const char *nodeName) const
|
||||
{
|
||||
if (parent.node_ == nullptr) {
|
||||
CAT_THROW(HXmlException(nodeName));
|
||||
}
|
||||
|
||||
if (parent.node_ == doc_.RootElement()) {
|
||||
if (strcmp(parent.node_->Value(), nodeName) == 0) {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
// 查找下一个节点
|
||||
tinyxml2::XMLElement *next = parent.node_->FirstChildElement(nodeName);
|
||||
if (next == nullptr) {
|
||||
CAT_THROW(HXmlException(nodeName));
|
||||
}
|
||||
for (const auto &i : node_){
|
||||
if (i->node_ == next) {
|
||||
return *i;
|
||||
}
|
||||
}
|
||||
CAT_THROW(HXmlException(nodeName));
|
||||
}
|
||||
|
||||
|
||||
HXml &HXmlHelper::AddElement(tinyxml2::XMLElement *next)
|
||||
{
|
||||
for (const auto &i : node_){
|
||||
if (i->node_ == next) {
|
||||
return *i;
|
||||
}
|
||||
}
|
||||
|
||||
node_.emplace_back(std::shared_ptr<HXml>(new HXml(this, next)));
|
||||
return *node_.back();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
tinyxml2::XMLElement *HXml::InitResultDoc(tinyxml2::XMLDocument &doc, const std::string &guid)
|
||||
{
|
||||
tinyxml2::XMLDeclaration* declaration = doc.NewDeclaration();
|
||||
doc.InsertFirstChild(declaration);
|
||||
tinyxml2::XMLElement* root = doc.NewElement("sdk");
|
||||
root->SetAttribute("guid", guid.data());
|
||||
doc.InsertEndChild(root);
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HXml::HXml()
|
||||
: p_(new detail::HXmlHelper())
|
||||
, node_(nullptr)
|
||||
, type_(kRoot)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
HXml::HXml(tinyxml2::XMLElement *element, bool scan)
|
||||
: HXml()
|
||||
{
|
||||
if (element == nullptr) {
|
||||
return ;
|
||||
}
|
||||
|
||||
p_->doc_.InsertEndChild(element->DeepClone(&p_->doc_));
|
||||
node_ = p_->doc_.RootElement();
|
||||
|
||||
if (scan) {
|
||||
Scan();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HXml::~HXml()
|
||||
{
|
||||
if (p_ && (type_ == kRoot || type_ == kObj)) {
|
||||
delete p_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string HXml::Dump() const
|
||||
{
|
||||
tinyxml2::XMLDocument *doc = nullptr;
|
||||
switch (type_) {
|
||||
case kRoot: {
|
||||
if (!p_) {
|
||||
return "";
|
||||
}
|
||||
doc = &p_->doc_;
|
||||
} break;
|
||||
default:
|
||||
if (node_ == nullptr) {
|
||||
return "";
|
||||
}
|
||||
doc = node_->GetDocument();
|
||||
break;
|
||||
}
|
||||
|
||||
if (doc == nullptr) {
|
||||
return "";
|
||||
}
|
||||
|
||||
tinyxml2::XMLPrinter xmlStr;
|
||||
doc->Print(&xmlStr);
|
||||
return xmlStr.CStr();
|
||||
}
|
||||
|
||||
|
||||
bool HXml::ContainsNodes(const tinyxml2::XMLElement *node, const char *name)
|
||||
{
|
||||
if (node == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return node->FirstChildElement(name) != nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool HXml::ContainsAttribute(const tinyxml2::XMLElement *node, const char *name)
|
||||
{
|
||||
if (node == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return node->FindAttribute(name) != nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
cat::HCatBuffer HXml::GetAttribute(const char *key, const char *defaultValue) const
|
||||
{
|
||||
if (node_ == nullptr) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
if (node_->FindAttribute(key) == nullptr) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return node_->Attribute(key);
|
||||
}
|
||||
|
||||
|
||||
HXml &HXml::operator[](const char *nodeName)
|
||||
{
|
||||
return p_->FindElement(*this, nodeName);
|
||||
}
|
||||
|
||||
|
||||
const HXml &HXml::at(const char *nodeName) const
|
||||
{
|
||||
return p_->FindElement(*this, nodeName);
|
||||
}
|
||||
|
||||
|
||||
void HXml::Scan()
|
||||
{
|
||||
if (p_ == nullptr) {
|
||||
return ;
|
||||
}
|
||||
|
||||
auto *root = p_->doc_.RootElement();
|
||||
Scan(root);
|
||||
}
|
||||
|
||||
|
||||
HXml &HXml::emplace_back(const cat::HCatBuffer &node, HXml &&sibling)
|
||||
{
|
||||
tinyxml2::XMLElement *brother = p_->doc_.NewElement(node.ConstData());
|
||||
node_->InsertEndChild(brother);
|
||||
return (p_->AddElement(brother) = sibling);
|
||||
}
|
||||
|
||||
|
||||
HXml &HXml::push_back(const cat::HCatBuffer &node, const HXml &sibling)
|
||||
{
|
||||
tinyxml2::XMLElement *brother = p_->doc_.NewElement(node.ConstData());
|
||||
node_->InsertEndChild(brother);
|
||||
return (p_->AddElement(brother) = sibling);
|
||||
}
|
||||
|
||||
|
||||
HXml &HXml::NewChild(const cat::HCatBuffer &node)
|
||||
{
|
||||
tinyxml2::XMLElement *brother = p_->doc_.NewElement(node.ConstData());
|
||||
node_->InsertEndChild(brother);
|
||||
return p_->AddElement(brother);
|
||||
}
|
||||
|
||||
|
||||
HXml &HXml::operator=(const HXml &value)
|
||||
{
|
||||
switch (type_) {
|
||||
case kObj:
|
||||
// 这里是对象节点,
|
||||
break;
|
||||
case kRoot: {
|
||||
// p_指针为空时说明追加对象只有属性
|
||||
if (value.p_ == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
// root节点追加对象节点, 对象节点和root节点的node都是空, 比较检查p_指针就行
|
||||
if (value.type_ == kObj) {
|
||||
if (p_ == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 检查对象节点有需要追加的数据吗
|
||||
tinyxml2::XMLElement *root = value.p_->doc_.RootElement();
|
||||
if (!root) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 当前根节点是空节点的话直接复制对象节点数据
|
||||
if (p_->doc_.RootElement() == nullptr) {
|
||||
value.p_->doc_.DeepCopy(&p_->doc_);
|
||||
break;
|
||||
}
|
||||
|
||||
// 插入到根节点数据
|
||||
p_->doc_.RootElement()->InsertEndChild(root->DeepClone(&p_->doc_));
|
||||
break;
|
||||
}
|
||||
|
||||
// 这里追加子节点 [""] = {{}}
|
||||
tinyxml2::XMLElement *root = value.p_->doc_.RootElement();
|
||||
if (root) {
|
||||
node_->InsertEndChild(root->DeepClone(&p_->doc_));
|
||||
}
|
||||
} break;
|
||||
case kChild: {
|
||||
// 子节点追加对象时需要追加对象节点的所有节点 to_xml()时
|
||||
if (value.type_ != kObj) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 这里追加类型转换出来的对象节点 [""] = class()
|
||||
tinyxml2::XMLElement * root = value.p_->doc_.RootElement();
|
||||
if (root) {
|
||||
node_->InsertEndChild(root->DeepClone(&p_->doc_));
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// 当前无节点, 将属性保存到当前属性节点
|
||||
if (node_ == nullptr) {
|
||||
attr_.insert(attr_.end(), value.attr_.begin(), value.attr_.end());
|
||||
return *this;
|
||||
}
|
||||
|
||||
// 将属性集合点的属性追加到这里
|
||||
for (const auto &i : value.attr_) {
|
||||
if (i.first.Empty()) {
|
||||
continue;
|
||||
}
|
||||
node_->SetAttribute(i.first.ConstData(), i.second.ConstData());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HXml::HXml(detail::HXmlHelper *p, tinyxml2::XMLElement *node)
|
||||
: p_(p)
|
||||
, node_(node)
|
||||
, type_(kChild)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void HXml::Scan(tinyxml2::XMLElement *node)
|
||||
{
|
||||
if (p_ == nullptr || node == nullptr) {
|
||||
return ;
|
||||
}
|
||||
|
||||
for (auto *next = node->FirstChildElement(); next; next = next->NextSiblingElement()) {
|
||||
p_->AddElement(next);
|
||||
Scan(next);
|
||||
}
|
||||
}
|
||||
|
||||
void HXmlIterator::operator++() const
|
||||
{
|
||||
if (xml_ == nullptr || xml_->node_ == nullptr) {
|
||||
return ;
|
||||
}
|
||||
|
||||
auto *p = xml_->node_->NextSiblingElement(xml_->node_->Value());
|
||||
if (p) {
|
||||
xml_ = &xml_->p_->AddElement(p);
|
||||
} else {
|
||||
xml_ = nullptr;
|
||||
}
|
||||
}
|
||||
452
SDK/HXml.h
Normal file
452
SDK/HXml.h
Normal file
@ -0,0 +1,452 @@
|
||||
|
||||
|
||||
#ifndef __HXML_H__
|
||||
#define __HXML_H__
|
||||
|
||||
#include <HDSDK.h>
|
||||
#include <tinyxml2.h>
|
||||
#include <exception>
|
||||
#include <initializer_list>
|
||||
#include <HCatBuffer.h>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <list>
|
||||
|
||||
|
||||
|
||||
template <typename _Ret, typename _Value>
|
||||
_Ret DataToType(const _Value &value) {
|
||||
std::stringstream ss;
|
||||
ss << value;
|
||||
_Ret result;
|
||||
ss >> result;
|
||||
return result;
|
||||
}
|
||||
template <>
|
||||
inline std::string DataToType(const cat::HCatBuffer &value) {
|
||||
return value.GetString();
|
||||
}
|
||||
template <>
|
||||
inline std::string DataToType(const std::string &value) {
|
||||
return value;
|
||||
}
|
||||
template <>
|
||||
inline std::string DataToType(const bool &value) {
|
||||
return value ? "true" : "false";
|
||||
}
|
||||
template <>
|
||||
inline bool DataToType(const std::string &value) {
|
||||
return value == "true" ? true : value == "1" ? true : false;
|
||||
}
|
||||
template <>
|
||||
inline bool DataToType(const cat::HCatBuffer &value) {
|
||||
return DataToType<bool>(value.GetConstString());
|
||||
}
|
||||
|
||||
|
||||
class HXml;
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct static_const { static constexpr T value{}; };
|
||||
|
||||
template <typename T>
|
||||
constexpr T static_const<T>::value;
|
||||
|
||||
template<unsigned N> struct priority_tag : priority_tag <N - 1> {};
|
||||
template<> struct priority_tag<0> {};
|
||||
|
||||
struct to_xml_fn
|
||||
{
|
||||
template<typename BasicXmlType, typename T>
|
||||
auto operator()(BasicXmlType& j, T&& val) const
|
||||
noexcept(noexcept(to_xml(j, std::forward<T>(val))))
|
||||
-> decltype(to_xml(j, std::forward<T>(val)), void())
|
||||
{
|
||||
return call(j, std::forward<T>(val), priority_tag<1>{});
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename BasicXmlType, typename T>
|
||||
auto call(BasicXmlType& j, T&& val, priority_tag<1>) const
|
||||
noexcept(noexcept(to_xml(j, std::forward<T>(val))))
|
||||
-> decltype(to_xml(j, std::forward<T>(val)), void())
|
||||
{
|
||||
return to_xml(j, std::forward<T>(val));
|
||||
}
|
||||
|
||||
template<typename BasicXmlType, typename T>
|
||||
void call(BasicXmlType&, T&&, priority_tag<0>) const noexcept
|
||||
{
|
||||
static_assert(sizeof(BasicXmlType) == 0, "could not find to_xml() method in T's namespace");
|
||||
}
|
||||
};
|
||||
struct from_xml_fn
|
||||
{
|
||||
public:
|
||||
template<typename BasicXmlType, typename T>
|
||||
auto operator()(const BasicXmlType& j, T&& val) const
|
||||
noexcept(noexcept(from_xml(j, std::forward<T>(val))))
|
||||
-> decltype(from_xml(j, std::forward<T>(val)), void())
|
||||
{
|
||||
return call(j, std::forward<T>(val), priority_tag<1>{});
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename BasicXmlType, typename T>
|
||||
auto call(const BasicXmlType& j, T&& val, priority_tag<1>) const
|
||||
noexcept(noexcept(from_xml(j, std::forward<T>(val))))
|
||||
-> decltype(from_xml(j, std::forward<T>(val)), void())
|
||||
{
|
||||
return from_xml(j, std::forward<T>(val));
|
||||
}
|
||||
template<typename BasicXmlType, typename T>
|
||||
void call(BasicXmlType&, T&&, priority_tag<0>) const noexcept
|
||||
{
|
||||
static_assert(sizeof(BasicXmlType) == 0, "could not find from_xml() method in T's namespace");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class HXmlHelper
|
||||
{
|
||||
public:
|
||||
explicit HXmlHelper(bool declaration = true);
|
||||
|
||||
HXml &FindElement(HXml &parent, const char *nodeName);
|
||||
const HXml &FindElement(const HXml &parent, const char *nodeName) const;
|
||||
HXml &AddElement(tinyxml2::XMLElement *next);
|
||||
|
||||
private:
|
||||
friend class ::HXml;
|
||||
tinyxml2::XMLDocument doc_;
|
||||
std::list<std::shared_ptr<HXml>> node_;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
||||
constexpr const auto& to_xml = detail::static_const<detail::to_xml_fn>::value;
|
||||
constexpr const auto& from_xml = detail::static_const<detail::from_xml_fn>::value;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///< HXml的异常
|
||||
class HXmlException : std::exception
|
||||
{
|
||||
public:
|
||||
explicit HXmlException(std::string &&e) : error(std::move(e)) {}
|
||||
virtual const char* what() const noexcept override { return error.data(); }
|
||||
|
||||
const std::string error;
|
||||
};
|
||||
|
||||
|
||||
class HXmlIterator
|
||||
{
|
||||
public:
|
||||
explicit HXmlIterator(const HXml *xml) : xml_(xml) {}
|
||||
|
||||
bool operator!=(const HXmlIterator &iterator) const { return iterator.xml_ != xml_; }
|
||||
const HXml &operator*() { return *xml_; }
|
||||
void operator++() const;
|
||||
|
||||
|
||||
private:
|
||||
mutable const HXml *xml_;
|
||||
};
|
||||
|
||||
|
||||
class HXml
|
||||
{
|
||||
public:
|
||||
///< 生成sdk返回的xml, 返回in节点
|
||||
static tinyxml2::XMLElement *InitResultDoc(tinyxml2::XMLDocument &doc, const std::string &guid);
|
||||
|
||||
HXml();
|
||||
|
||||
///< 将xml数据转换
|
||||
explicit HXml(tinyxml2::XMLElement *element, bool scan = true);
|
||||
|
||||
HXml(HXml &&other)
|
||||
: p_(other.p_)
|
||||
, node_(other.node_)
|
||||
, attr_(std::move(other.attr_))
|
||||
, type_(other.type_)
|
||||
{
|
||||
other.p_ = nullptr;
|
||||
}
|
||||
|
||||
///< 这个用来追加xml节点, 请注意, xml需要root节点存在, to_xml实现会导致, 如果只是向节点追加子节点, 使用ToXml
|
||||
template <typename _T, typename = typename std::enable_if<
|
||||
!std::is_same<typename std::decay<_T>::type, const char *>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, char *>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, std::string>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, cat::HCatBuffer>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, HXml>::value, _T>::type>
|
||||
HXml(_T &&value)
|
||||
: p_(new detail::HXmlHelper())
|
||||
, node_(nullptr)
|
||||
, type_(kObj)
|
||||
{
|
||||
to_xml(*this, std::forward<_T>(value));
|
||||
}
|
||||
|
||||
///< 这个用于追加子节点
|
||||
template <typename _T, typename = typename std::enable_if<
|
||||
!std::is_same<typename std::decay<_T>::type, const char *>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, char *>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, std::string>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, cat::HCatBuffer>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, HXml>::value, _T>::type>
|
||||
HXml &ToXml(_T &&value) {
|
||||
to_xml(*this, std::forward<_T>(value));
|
||||
return *this;
|
||||
}
|
||||
|
||||
///< 单个属性值生成 HXml
|
||||
template <typename _T>
|
||||
HXml(const char *key, _T &&value) : HXml(cat::HCatBuffer(key), std::forward<_T>(value)){}
|
||||
template <typename _T>
|
||||
HXml(const std::string &key, _T &&value) : HXml(cat::HCatBuffer(key), std::forward<_T>(value)){}
|
||||
template <typename _T, typename = typename std::enable_if<
|
||||
!std::is_same<typename std::decay<_T>::type, const char *>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, char *>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, std::string>::value &&
|
||||
!std::is_same<typename std::decay<_T>::type, cat::HCatBuffer>::value, _T>::type>
|
||||
HXml(const cat::HCatBuffer &key, const _T &value) : HXml(key, cat::HCatBuffer(DataToType<std::string>(value))) {}
|
||||
HXml(const cat::HCatBuffer &key, const cat::HCatBuffer &value)
|
||||
: p_(nullptr)
|
||||
, node_(nullptr)
|
||||
, attr_{{key, value}}
|
||||
, type_(kChild)
|
||||
{}
|
||||
|
||||
///< 生成属性列表
|
||||
HXml(std::initializer_list<HXml> &&value)
|
||||
: p_(nullptr)
|
||||
, node_(nullptr)
|
||||
, type_(kChild)
|
||||
{
|
||||
for (const auto &i : value) {
|
||||
attr_.insert(attr_.end(), i.attr_.begin(), i.attr_.end());
|
||||
}
|
||||
}
|
||||
|
||||
~HXml();
|
||||
|
||||
///< 获取xml文本
|
||||
std::string Dump() const;
|
||||
|
||||
///< 获取对应的结构数据, 需自行实现 对于的 from_xml(const HXml &xml, class &userClass)
|
||||
template <typename _T>
|
||||
bool get_to(_T &value) const {
|
||||
CAT_TRY {
|
||||
from_xml(*this, value);
|
||||
} CAT_CATCH (const HXmlException &e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///< 递归检查当前节点的子节点是否存在该名 如当前节点node 一级节点 a 二级节点 b ContainsNodes("a", "b") 都存在返回true, 反之返回false
|
||||
static bool ContainsNodes(const tinyxml2::XMLElement *node) { return node != nullptr; }
|
||||
static bool ContainsNodes(const tinyxml2::XMLElement *node, const char *name);
|
||||
template <typename ..._Args>
|
||||
bool ContainsNodes(const tinyxml2::XMLElement *node, const char *nodeName, _Args &&...args) const {
|
||||
if (node == nullptr) {
|
||||
return false;
|
||||
}
|
||||
const tinyxml2::XMLElement *next = node->FirstChildElement(nodeName);
|
||||
return next != nullptr && ContainsNodes(next, std::forward<_Args>(args)...);
|
||||
}
|
||||
template <typename ..._Args>
|
||||
bool ContainsNodes(const char *nodeName, _Args &&...args) const { return ContainsNodes(node_, nodeName, std::forward<_Args>(args)...); }
|
||||
|
||||
///< 检查是否包含该属性
|
||||
static bool ContainsAttribute(const tinyxml2::XMLElement *node) { return node != nullptr; }
|
||||
static bool ContainsAttribute(const tinyxml2::XMLElement *node, const char *name);
|
||||
template <typename ..._Args>
|
||||
bool ContainsAttribute(const char *nodeName, _Args &&...args) const {
|
||||
return ContainsAttribute(node_, nodeName) && ContainsAttribute(node_, std::forward<_Args>(args)...);
|
||||
}
|
||||
|
||||
///< 获取属性
|
||||
cat::HCatBuffer GetAttribute(const char *key, const char *defaultValue = nullptr) const;
|
||||
cat::HCatBuffer GetNodeName() const { if (node_ == nullptr) { return ""; } return node_->Value(); }
|
||||
cat::HCatBuffer GetFirstChildNodeName() const { if (node_ == nullptr) { return ""; } auto node = node_->FirstChildElement(); return node ? node->Value() : ""; }
|
||||
|
||||
///< 设置文本
|
||||
HXml &SetText(const cat::HCatBuffer &text) { if (node_ == nullptr) { return *this; } node_->SetText(text.ConstData()); return *this; }
|
||||
cat::HCatBuffer GetText() const { if (node_ == nullptr) { return ""; } return node_->GetText(); }
|
||||
|
||||
///< 获取节点名
|
||||
cat::HCatBuffer GetName() const { return node_ ? node_->Name() : ""; }
|
||||
|
||||
///< 获取子节点, 如不存在则创建
|
||||
///< 无root节点会先创建root节点, 其余节点都在root节点下面
|
||||
///< 如存在根节点后xml["root"] xml["root"]["sdk"] 和 xml["sdk"]是一样的
|
||||
HXml &operator[](const char *nodeName);
|
||||
|
||||
///< 获取子节点, 不存在则抛 HXmlException 异常
|
||||
const HXml &at(const char *nodeName) const;
|
||||
|
||||
///< 扫描节点, 生成所有对应的节点
|
||||
void Scan();
|
||||
|
||||
///< 设置属性
|
||||
template <typename _T>
|
||||
HXml &operator=(const std::pair<const char *, _T> &value) {
|
||||
if (value.first == nullptr) {
|
||||
return *this;
|
||||
}
|
||||
node_->SetAttribute(value.first, value.second);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
///< HXml追加属性
|
||||
HXml &operator=(const HXml &value);
|
||||
|
||||
///< 追加兄弟节点
|
||||
HXml &emplace_back(const cat::HCatBuffer &node, HXml &&sibling);
|
||||
HXml &push_back(const cat::HCatBuffer &node, const HXml &sibling);
|
||||
HXml &NewChild(const cat::HCatBuffer &node);
|
||||
|
||||
///< 为了支持迭代兄弟节点, 但实际不存在HXml时将会创建
|
||||
HXmlIterator begin() const { return HXmlIterator(this); }
|
||||
HXmlIterator end() const { return HXmlIterator(nullptr); }
|
||||
|
||||
tinyxml2::XMLElement *GetNode() const { return node_; }
|
||||
|
||||
private:
|
||||
friend class detail::HXmlHelper;
|
||||
friend class HXmlIterator;
|
||||
|
||||
HXml(detail::HXmlHelper *p, tinyxml2::XMLElement *node);
|
||||
|
||||
///< 递归扫描所有节点
|
||||
void Scan(tinyxml2::XMLElement *node);
|
||||
|
||||
private:
|
||||
detail::HXmlHelper *p_;
|
||||
tinyxml2::XMLElement *node_;
|
||||
std::list<std::pair<cat::HCatBuffer, cat::HCatBuffer>> attr_;
|
||||
enum {
|
||||
kRoot,
|
||||
kObj,
|
||||
kChild,
|
||||
} type_;
|
||||
};
|
||||
|
||||
|
||||
#define CREATE_TAG_P(_doc, _parent, _node, _tagName) \
|
||||
_node = (_doc)->NewElement(_tagName); \
|
||||
if (_node == nullptr) { \
|
||||
code = cat::HErrorCode::kMemoryFailed; \
|
||||
break; \
|
||||
} else { \
|
||||
(_parent)->InsertEndChild(_node); \
|
||||
}
|
||||
|
||||
|
||||
#define CREATE_TAG_ATTR(_doc, _node, _tagName, _attrName, _attrValue) \
|
||||
_node = (_doc)->NewElement(_tagName); \
|
||||
if (_node == nullptr) { \
|
||||
code = cat::HErrorCode::kMemoryFailed; \
|
||||
break; \
|
||||
} else { \
|
||||
_node->SetAttribute(_attrName, _attrValue); \
|
||||
}
|
||||
|
||||
|
||||
#define CREATE_TAG_ATTR_P(_doc, _parent, _node, _tagName, _attrName, _attrValue)\
|
||||
_node = (_doc)->NewElement(_tagName); \
|
||||
if (_node == nullptr) { \
|
||||
code = cat::HErrorCode::kMemoryFailed; \
|
||||
break; \
|
||||
} else { \
|
||||
_node->SetAttribute(_attrName, _attrValue); \
|
||||
(_parent)->InsertEndChild(_node); \
|
||||
}
|
||||
|
||||
#define PARSE_TAG_ATTR_P(_parent, _node, _tagName, _attrName, _attrValue) \
|
||||
_node = (_parent)->FirstChildElement(_tagName); \
|
||||
if (_node == nullptr) { \
|
||||
code = cat::HErrorCode::kParseXmlFailed; \
|
||||
break; \
|
||||
} else if (_node->FindAttribute(_attrName) == nullptr) { \
|
||||
code = cat::HErrorCode::kParseXmlFailed; \
|
||||
break; \
|
||||
} else { \
|
||||
_attrValue = _node->Attribute(_attrName); \
|
||||
}
|
||||
|
||||
#define PARSE_TAG_ATTR_P_TYPE(_parent, _node, _tagName, _attrName, _attrValue, _type) \
|
||||
_node = (_parent)->FirstChildElement(_tagName); \
|
||||
if (_node == nullptr) { \
|
||||
code = cat::HErrorCode::kParseXmlFailed; \
|
||||
break; \
|
||||
} else if (_node->FindAttribute(_attrName) == nullptr) { \
|
||||
code = cat::HErrorCode::kParseXmlFailed; \
|
||||
break; \
|
||||
} else { \
|
||||
_attrValue = DataToType<_type>(_node->Attribute(_attrName)); \
|
||||
}
|
||||
|
||||
|
||||
#define PARSE_TAG_ATTR_P_NULL(_parent, _node, _tagName, _attrName, _attrValue) \
|
||||
_node = (_parent)->FirstChildElement(_tagName); \
|
||||
if (_node == nullptr) { \
|
||||
_attrValue = _type(); \
|
||||
} else if (_node->FindAttribute(_attrName) == nullptr) { \
|
||||
code = cat::HErrorCode::kParseXmlFailed; \
|
||||
break; \
|
||||
} else { \
|
||||
_attrValue = _node->Attribute(_attrName); \
|
||||
}
|
||||
|
||||
|
||||
#define PARSE_TAG_ATTR_P_NULL_TYPE(_parent, _node, _tagName, _attrName, _attrValue, _type) \
|
||||
_node = (_parent)->FirstChildElement(_tagName); \
|
||||
if (_node == nullptr) { \
|
||||
_attrValue = _type(); \
|
||||
} else if (_node->FindAttribute(_attrName) == nullptr) { \
|
||||
code = cat::HErrorCode::kParseXmlFailed; \
|
||||
break; \
|
||||
} else { \
|
||||
_attrValue = DataToType<_type>(_node->Attribute(_attrName)); \
|
||||
}
|
||||
|
||||
|
||||
#define PARSE_TAG_ATTR(_node, _tagName, _attrName, _attrValue) \
|
||||
if (_node->FindAttribute(_attrName) == nullptr) { \
|
||||
code = cat::HErrorCode::kParseXmlFailed; \
|
||||
break; \
|
||||
} else { \
|
||||
_attrValue = _node->Attribute(_attrName); \
|
||||
}
|
||||
|
||||
#define PARSE_TAG_ATTR_TYPE(_node, _tagName, _attrName, _attrValue, _type) \
|
||||
if (_node->FindAttribute(_attrName) == nullptr) { \
|
||||
code = cat::HErrorCode::kParseXmlFailed; \
|
||||
break; \
|
||||
} else { \
|
||||
_attrValue = DataToType<_type>(_node->Attribute(_attrName)); \
|
||||
}
|
||||
|
||||
#endif // HXML_H
|
||||
833
SDK/SDKInfo.cpp
Normal file
833
SDK/SDKInfo.cpp
Normal file
@ -0,0 +1,833 @@
|
||||
|
||||
|
||||
#include "HDSDK.h"
|
||||
#include "HScreenFunctionInfo.h"
|
||||
#include "HSensorInfo.h"
|
||||
#include <SDKInfo.h>
|
||||
#include <string>
|
||||
#include <HCatBuffer.h>
|
||||
#include <tinyxml2.h>
|
||||
#include <HXml.h>
|
||||
#include <Data/HSDKInfo.h>
|
||||
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
||||
template <typename _T>
|
||||
cat::HCatBuffer GetNode(const _T &) { return _T::GetMethod(); }
|
||||
template <typename _T>
|
||||
cat::HCatBuffer SetNode(const _T &) { return _T::SetMethod(); }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
ISDKInfo DLL_CALL CreateSDKInfo()
|
||||
{
|
||||
return new sdk::HSDKInfo();
|
||||
}
|
||||
|
||||
void DLL_CALL FreeSDKInfo(sdk::ISDKInfo info)
|
||||
{
|
||||
delete info;
|
||||
}
|
||||
|
||||
|
||||
HBool DLL_CALL ParseXml(const char *xml, int len, ISDKInfo info)
|
||||
{
|
||||
if (xml == nullptr || info == nullptr || len <= 0) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xml, len);
|
||||
if (doc.Error()) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement *sdk = doc.FirstChildElement("sdk");
|
||||
if (!sdk) {
|
||||
printf("read xml error, sdk tag not found\n");
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement *node = sdk->FirstChildElement("out");
|
||||
if (!node) {
|
||||
printf("read xml error, out tag not found\n");
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
while (node) {
|
||||
cat::HCatBuffer method(node->Attribute("method"));
|
||||
if (info->ParseInfo(node, method) == 0) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
node = node->NextSiblingElement("out");
|
||||
}
|
||||
|
||||
return HTrue;
|
||||
}
|
||||
|
||||
HBool UpdateItem(IHDProtocol protocol, ISDKInfo info, int updateItem)
|
||||
{
|
||||
if (protocol == nullptr || info == nullptr) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
HXml xml;
|
||||
xml["sdk"] = {"guid", "##GUID"};
|
||||
|
||||
// 存在配置信息的Get项
|
||||
#define GET_DATA_ITEM(item, obj) \
|
||||
case item: { \
|
||||
xml["sdk"]["in"] = {"method", detail::GetNode(obj)}; \
|
||||
xml["sdk"]["in"].ToXml(obj); \
|
||||
} break;
|
||||
|
||||
// 常规Get项
|
||||
#define GET_ITEM(item, obj) \
|
||||
case item: { \
|
||||
xml["sdk"]["in"] = {"method", detail::GetNode(obj)}; \
|
||||
} break;
|
||||
|
||||
// 常规Set项
|
||||
#define SET_ITEM(item, obj) \
|
||||
case item: { \
|
||||
xml["sdk"]["in"] = {"method", detail::SetNode(obj)}; \
|
||||
xml["sdk"]["in"].ToXml(obj); \
|
||||
} break;
|
||||
|
||||
// 多处理常规Set和Get系列
|
||||
#define GET_SET_ITEM(getItem, setItem, obj) \
|
||||
GET_ITEM(getItem, obj); \
|
||||
SET_ITEM(setItem, obj);
|
||||
|
||||
|
||||
switch (updateItem) {
|
||||
GET_SET_ITEM(kGetLightInfo, kSetLightInfo, info->lightInfo);
|
||||
GET_SET_ITEM(kGetSystemVolumeInfo, kSetSystemVolumeInfo, info->systemVolumeInfo);
|
||||
GET_SET_ITEM(kGetTcpServerInfo, kSetTcpServerInfo, info->tcpSercerInfo);
|
||||
GET_SET_ITEM(kGetTimeInfo, kSetTimeInfo, info->timeInfo);
|
||||
GET_SET_ITEM(kGetEthInfo, kSetEthInfo, info->ethInfo);
|
||||
GET_SET_ITEM(kGetWifiInfo, kSetWifiInfo, info->wifiInfo);
|
||||
GET_SET_ITEM(kGetPppoeInfo, kSetPppoeInfo, info->pppoeInfo);
|
||||
GET_SET_ITEM(kGetDeviceNameInfo, kSetDeviceNameInfo, info->deviceNameInfo);
|
||||
GET_SET_ITEM(kGetSwitchTimeInfo, kSetSwitchTimeInfo, info->switchTimeInfo);
|
||||
GET_SET_ITEM(kGetRelayInfo, kSetRelayInfo, info->relayInfo);
|
||||
|
||||
GET_ITEM(kGetDeviceInfo, info->deviceInfo);
|
||||
GET_DATA_ITEM(kGetScreenShot, info->screenShot2);
|
||||
default:
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
std::string buff = xml.Dump();
|
||||
return SendXml(protocol, buff.c_str(), buff.size()) ? HTrue : HFalse;
|
||||
|
||||
#undef GET_DATA_ITEM
|
||||
#undef GET_ITEM
|
||||
#undef SET_ITEM
|
||||
#undef SET_ITEM_INFO
|
||||
#undef GET_SET_ITEM
|
||||
}
|
||||
|
||||
void SetLightInfo(ISDKInfo info, int mode, int defaultModeLight)
|
||||
{
|
||||
info->lightInfo.mode = static_cast<sdk::LightInfo::eMode>(mode);
|
||||
info->lightInfo.defaultValue = cat::HCatBuffer::Number(defaultModeLight);
|
||||
}
|
||||
|
||||
void SetLightInfoSensor(ISDKInfo info, int min, int max, int time)
|
||||
{
|
||||
info->lightInfo.sensor.min = std::max(1, min);
|
||||
info->lightInfo.sensor.max = std::min(max, 100);
|
||||
info->lightInfo.sensor.time = std::max(5, std::min(15, time));
|
||||
}
|
||||
|
||||
void AddLightInfoPloy(ISDKInfo info, HBool enable, const char *startTime, int percent)
|
||||
{
|
||||
sdk::LightInfo::Ploy item;
|
||||
item.enable = enable;
|
||||
item.percent = percent;
|
||||
item.start = cat::HCatBuffer(startTime);
|
||||
|
||||
info->lightInfo.ployList.emplace_back(std::move(item));
|
||||
}
|
||||
|
||||
void SetLightInfoPloy(ISDKInfo info, int index, HBool enable, const char *startTime, int percent)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->lightInfo.ployList.size())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
info->lightInfo.ployList[index].enable = enable != HFalse;
|
||||
info->lightInfo.ployList[index].start = cat::HCatBuffer(startTime);
|
||||
info->lightInfo.ployList[index].percent = percent;
|
||||
}
|
||||
|
||||
void ClearLightInfoPloy(ISDKInfo info)
|
||||
{
|
||||
info->lightInfo.ployList.clear();
|
||||
}
|
||||
|
||||
int GetLightInfoMode(ISDKInfo info)
|
||||
{
|
||||
return info->lightInfo.mode;
|
||||
}
|
||||
|
||||
int GetLightInfoDefaultLight(ISDKInfo info)
|
||||
{
|
||||
return info->lightInfo.defaultValue.ToInt();
|
||||
}
|
||||
|
||||
int GetLightInfoPloySize(ISDKInfo info)
|
||||
{
|
||||
return info->lightInfo.ployList.size();
|
||||
}
|
||||
|
||||
int GetLightInfoPloyEnable(ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->lightInfo.ployList.size())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return info->lightInfo.ployList.at(index).enable;
|
||||
}
|
||||
|
||||
int GetLightInfoPloyPercent(ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->lightInfo.ployList.size())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return info->lightInfo.ployList.at(index).percent;
|
||||
}
|
||||
|
||||
const char *GetLightInfoPloyStart(ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->lightInfo.ployList.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return info->lightInfo.ployList.at(index).start.ConstData();
|
||||
}
|
||||
|
||||
int GetLightInfoSensorMax(ISDKInfo info)
|
||||
{
|
||||
return info->lightInfo.sensor.max;
|
||||
}
|
||||
|
||||
int GetLightInfoSensorMin(ISDKInfo info)
|
||||
{
|
||||
return info->lightInfo.sensor.min;
|
||||
}
|
||||
|
||||
int GetLightInfoSensorTime(ISDKInfo info)
|
||||
{
|
||||
return info->lightInfo.sensor.time;
|
||||
}
|
||||
|
||||
void SetSystemVolumeInfo(ISDKInfo info, int mode, int volume)
|
||||
{
|
||||
info->systemVolumeInfo.mode = mode;
|
||||
info->systemVolumeInfo.volume = cat::HCatBuffer::Number(std::min(100, std::max(volume, 0)));
|
||||
}
|
||||
|
||||
void AddSystemVolumeInfoPloy(ISDKInfo info, int enable, const char *time, int volume)
|
||||
{
|
||||
sdk::SystemVolumeInfo::Ploy item;
|
||||
item.enable = enable;
|
||||
item.volume = std::min(100, std::max(volume, 0));
|
||||
item.time = cat::HCatBuffer(time);
|
||||
info->systemVolumeInfo.ploys.emplace_back(std::move(item));
|
||||
}
|
||||
|
||||
void ClearSystemVolumeInfoPloy(ISDKInfo info)
|
||||
{
|
||||
info->systemVolumeInfo.ploys.clear();
|
||||
}
|
||||
|
||||
int GetSystemVolumeInfoMode(ISDKInfo info)
|
||||
{
|
||||
return info->systemVolumeInfo.mode;
|
||||
}
|
||||
|
||||
int GetSystemVolumeInfoVolume(ISDKInfo info)
|
||||
{
|
||||
return info->systemVolumeInfo.volume.ToInt();
|
||||
}
|
||||
|
||||
int GetSystemVolumeInfoPloySize(ISDKInfo info)
|
||||
{
|
||||
return info->systemVolumeInfo.ploys.size();
|
||||
}
|
||||
|
||||
int GetSystemVolumeInfoPloyEnable(ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->systemVolumeInfo.ploys.size())) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
return info->systemVolumeInfo.ploys.at(index).enable ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
const char *GetSystemVolumeInfoPloyTime(ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->systemVolumeInfo.ploys.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return info->systemVolumeInfo.ploys.at(index).time.ConstData();
|
||||
}
|
||||
|
||||
int GetSystemVolumeInfoPloyVolume(ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->systemVolumeInfo.ploys.size())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return info->systemVolumeInfo.ploys.at(index).volume;
|
||||
}
|
||||
|
||||
void SetTcpServerInfo(ISDKInfo info, const char *ip, huint16 port)
|
||||
{
|
||||
info->tcpSercerInfo.host = cat::HCatBuffer(ip);
|
||||
info->tcpSercerInfo.port = port;
|
||||
}
|
||||
|
||||
const char *GetTcpServerInfoIp(ISDKInfo info)
|
||||
{
|
||||
return info->tcpSercerInfo.host.ConstData();
|
||||
}
|
||||
|
||||
huint16 GetTcpServerInfoPort(ISDKInfo info)
|
||||
{
|
||||
return info->tcpSercerInfo.port;
|
||||
}
|
||||
|
||||
void SetTimeInfo(ISDKInfo info, const char *timeZone, int summer, const char *sync, const char *currTime, const char *serverList)
|
||||
{
|
||||
info->timeInfo.timeZone = cat::HCatBuffer(timeZone);
|
||||
info->timeInfo.summer = summer == HTrue;
|
||||
info->timeInfo.sync = cat::HCatBuffer(sync);
|
||||
info->timeInfo.currTime = cat::HCatBuffer(currTime);
|
||||
info->timeInfo.serverList = cat::HCatBuffer(serverList);
|
||||
}
|
||||
|
||||
const char *GetTimeInfoTimeZone(ISDKInfo info)
|
||||
{
|
||||
return info->timeInfo.timeZone.ConstData();
|
||||
}
|
||||
|
||||
int GetTimeInfoSummer(ISDKInfo info)
|
||||
{
|
||||
return info->timeInfo.summer ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
const char *GetTimeInfoSync(ISDKInfo info)
|
||||
{
|
||||
return info->timeInfo.sync.ConstData();
|
||||
}
|
||||
|
||||
const char *GetTimeInfoCurrTime(ISDKInfo info)
|
||||
{
|
||||
return info->timeInfo.currTime.ConstData();
|
||||
}
|
||||
|
||||
const char *GetTimeInfoServerList(ISDKInfo info)
|
||||
{
|
||||
return info->timeInfo.serverList.ConstData();
|
||||
}
|
||||
|
||||
void SetEthInfo(sdk::ISDKInfo info, HBool dhcp, const char *ip, const char *netmask, const char *gateway, const char *dns)
|
||||
{
|
||||
info->ethInfo.dhcp = dhcp != HFalse;
|
||||
info->ethInfo.ip = cat::HCatBuffer(ip);
|
||||
info->ethInfo.netmask = cat::HCatBuffer(netmask);
|
||||
info->ethInfo.gateway = cat::HCatBuffer(gateway);
|
||||
info->ethInfo.dns = cat::HCatBuffer(dns);
|
||||
}
|
||||
|
||||
HBool GetEhtInfoDhcp(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->ethInfo.dhcp ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
const char *GetEhtInfoIp(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->ethInfo.ip.ConstData();
|
||||
}
|
||||
|
||||
const char *GetEhtInfoNetmask(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->ethInfo.netmask.ConstData();
|
||||
}
|
||||
|
||||
const char *GetEhtInfoGateway(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->ethInfo.gateway.ConstData();
|
||||
}
|
||||
|
||||
const char *GetEhtInfoDns(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->ethInfo.dns.ConstData();
|
||||
}
|
||||
|
||||
void SetWifiInfo(sdk::ISDKInfo info, int mode)
|
||||
{
|
||||
if (mode == 1) {
|
||||
info->wifiInfo.mode = "station";
|
||||
} else {
|
||||
info->wifiInfo.mode = "ap";
|
||||
}
|
||||
}
|
||||
|
||||
void SetWifiInfoAp(sdk::ISDKInfo info, const char *ssid, const char *password, const char *ip)
|
||||
{
|
||||
info->wifiInfo.ap.ssid = cat::HCatBuffer(ssid);
|
||||
info->wifiInfo.ap.password = cat::HCatBuffer(password);
|
||||
info->wifiInfo.ap.ipAddress = cat::HCatBuffer(ip);
|
||||
info->wifiInfo.ap.channel = 0;
|
||||
}
|
||||
|
||||
void SetWifiInfoStation(sdk::ISDKInfo info, const char *ssid, const char *password, int dhcp)
|
||||
{
|
||||
info->wifiInfo.stationIndex = 0;
|
||||
if (info->wifiInfo.station.size() > 1) {
|
||||
info->wifiInfo.station.clear();
|
||||
}
|
||||
if (info->wifiInfo.station.empty()) {
|
||||
info->wifiInfo.station.emplace_back(sdk::WifiInfo::StationConfig());
|
||||
}
|
||||
|
||||
info->wifiInfo.station.front().dhcp = dhcp != HFalse;
|
||||
info->wifiInfo.station.front().ssid = cat::HCatBuffer(ssid);
|
||||
info->wifiInfo.station.front().password = cat::HCatBuffer(password);
|
||||
}
|
||||
|
||||
void SetWifiInfoStationNet(sdk::ISDKInfo info, const char *ip, const char *mask, const char *gateway, const char *dns)
|
||||
{
|
||||
info->wifiInfo.stationIndex = 0;
|
||||
if (info->wifiInfo.station.size() > 1) {
|
||||
info->wifiInfo.station.clear();
|
||||
}
|
||||
if (info->wifiInfo.station.empty()) {
|
||||
info->wifiInfo.station.emplace_back(sdk::WifiInfo::StationConfig());
|
||||
}
|
||||
|
||||
info->wifiInfo.station.front().ip = cat::HCatBuffer(ip);
|
||||
info->wifiInfo.station.front().mask = cat::HCatBuffer(mask);
|
||||
info->wifiInfo.station.front().gateway = cat::HCatBuffer(gateway);
|
||||
info->wifiInfo.station.front().dns = cat::HCatBuffer(dns);
|
||||
}
|
||||
|
||||
int GetWifiInfoMode(sdk::ISDKInfo info)
|
||||
{
|
||||
if (info->wifiInfo.mode == "station") {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *GetWifiInfoApSsid(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->wifiInfo.ap.ssid.ConstData();
|
||||
}
|
||||
|
||||
const char *GetWifiInfoApPassword(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->wifiInfo.ap.password.ConstData();
|
||||
}
|
||||
|
||||
const char *GetWifiInfoApIp(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->wifiInfo.ap.ipAddress.ConstData();
|
||||
}
|
||||
|
||||
const char *GetWifiInfoStationSsid(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->wifiInfo.GetCurrentStation().ssid.ConstData();
|
||||
}
|
||||
|
||||
HBool GetWifiInfoStationDhcp(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->wifiInfo.GetCurrentStation().dhcp ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
const char *GetWifiInfoStationIp(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->wifiInfo.GetCurrentStation().ip.ConstData();
|
||||
}
|
||||
|
||||
const char *GetWifiInfoStationMask(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->wifiInfo.GetCurrentStation().mask.ConstData();
|
||||
}
|
||||
|
||||
const char *GetWifiInfoStationGateway(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->wifiInfo.GetCurrentStation().gateway.ConstData();
|
||||
}
|
||||
|
||||
const char *GetWifiInfoStationDns(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->wifiInfo.GetCurrentStation().dns.ConstData();
|
||||
}
|
||||
|
||||
void SetPppoeInfoApn(sdk::ISDKInfo info, const char *apn)
|
||||
{
|
||||
info->pppoeInfo.apn = cat::HCatBuffer(apn);
|
||||
}
|
||||
|
||||
HBool GetPppoeInfoVaild(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->pppoeInfo.vaild ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
const char *GetPppoeInfoApn(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->pppoeInfo.apn.ConstData();
|
||||
}
|
||||
|
||||
void SetDeviceNameInfo(sdk::ISDKInfo info, const char *name)
|
||||
{
|
||||
info->deviceNameInfo.name = cat::HCatBuffer(name);
|
||||
}
|
||||
|
||||
const char *GetDeviceNameInfo(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->deviceNameInfo.name.ConstData();
|
||||
}
|
||||
|
||||
void SetSwitchTimeInfo(sdk::ISDKInfo info, int mode, int enable)
|
||||
{
|
||||
info->switchTimeInfo.mode = mode;
|
||||
info->switchTimeInfo.ployEnable = enable != HFalse;
|
||||
}
|
||||
|
||||
void AddSwitchTimeInfoItem(sdk::ISDKInfo info, HBool enable, const char *start, const char *end)
|
||||
{
|
||||
sdk::SwitchTimeInfo::ployItem item;
|
||||
item.enable = enable != HFalse;
|
||||
item.start = cat::HCatBuffer(start);
|
||||
item.end = cat::HCatBuffer(end);
|
||||
info->switchTimeInfo.ploys.emplace_back(std::move(item));
|
||||
}
|
||||
|
||||
void ClearSwitchTimeInfoItem(sdk::ISDKInfo info)
|
||||
{
|
||||
info->switchTimeInfo.ploys.clear();
|
||||
}
|
||||
|
||||
HBool SetSwitchTimeInfoItem(sdk::ISDKInfo info, int index, HBool enable, const char *start, const char *end)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->switchTimeInfo.ploys.size())) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
info->switchTimeInfo.ploys[index].enable = enable != HFalse;
|
||||
info->switchTimeInfo.ploys[index].start = cat::HCatBuffer(start);
|
||||
info->switchTimeInfo.ploys[index].end = cat::HCatBuffer(end);
|
||||
return HTrue;
|
||||
}
|
||||
|
||||
void AddSwitchTimeInfoWeekItem(sdk::ISDKInfo info, int week, HBool openAllDay, const char *start, const char *end)
|
||||
{
|
||||
if (week < 0 || week >= static_cast<int>(sdk::SwitchTimeInfo::GetWeekMax())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
sdk::SwitchTimeInfo::weekItem item;
|
||||
item.start = cat::HCatBuffer(start);
|
||||
item.end = cat::HCatBuffer(end);
|
||||
info->switchTimeInfo.GetWeekItem(week).openAllDay = openAllDay != HFalse;
|
||||
info->switchTimeInfo.GetWeekItem(week).ploys.emplace_back(std::move(item));
|
||||
}
|
||||
|
||||
void ClearSwitchTimeInfoWeekItem(sdk::ISDKInfo info, int week)
|
||||
{
|
||||
if (week < 0 || week >= static_cast<int>(sdk::SwitchTimeInfo::GetWeekMax())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
info->switchTimeInfo.GetWeekItem(week).ploys.clear();
|
||||
}
|
||||
|
||||
void SetSwitchTimeInfoWeekItem(sdk::ISDKInfo info, int week, int index, HBool openAllDay, const char *start, const char *end)
|
||||
{
|
||||
if (week < 0 || week >= static_cast<int>(sdk::SwitchTimeInfo::GetWeekMax())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
if (index < 0 || index >= static_cast<int>(info->switchTimeInfo.weekPloys.size())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
info->switchTimeInfo.GetWeekItem(week).openAllDay = openAllDay != HFalse;
|
||||
info->switchTimeInfo.GetWeekItem(week).ploys[index].start = cat::HCatBuffer(start);
|
||||
info->switchTimeInfo.GetWeekItem(week).ploys[index].end = cat::HCatBuffer(end);
|
||||
}
|
||||
|
||||
int GetSwitchTimeInfoItemSize(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->switchTimeInfo.ploys.size();
|
||||
}
|
||||
|
||||
int GetSwitchTimeInfoWeekItemSize(sdk::ISDKInfo info, int week)
|
||||
{
|
||||
if (week < 0 || week >= static_cast<int>(sdk::SwitchTimeInfo::GetWeekMax())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return info->switchTimeInfo.GetWeekItem(week).ploys.size();
|
||||
}
|
||||
|
||||
HBool GetSwitchTimeInfoEnable(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->switchTimeInfo.ployEnable ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
HBool GetSwitchTimeInfoItemEnable(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->switchTimeInfo.ploys.size())) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
return info->switchTimeInfo.ploys.at(index).enable ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
const char *GetSwitchTimeInfoItemStart(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->switchTimeInfo.ploys.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return info->switchTimeInfo.ploys.at(index).start.ConstData();
|
||||
}
|
||||
|
||||
const char *GetSwitchTimeInfoItemEnd(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->switchTimeInfo.ploys.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return info->switchTimeInfo.ploys.at(index).end.ConstData();
|
||||
}
|
||||
|
||||
void SetRelayInfoItem(sdk::ISDKInfo info, int index, const char *name, HBool useSwitch)
|
||||
{
|
||||
info->relayInfo.InitRelayList();
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
info->relayInfo.relayList[index].name = cat::HCatBuffer(name);
|
||||
info->relayInfo.relayList[index].useSwitch = useSwitch != HFalse;
|
||||
}
|
||||
|
||||
void AddRelayInfoItemPloy(sdk::ISDKInfo info, int index, const char *start, const char *end)
|
||||
{
|
||||
info->relayInfo.InitRelayList();
|
||||
if (index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
sdk::RelayInfo::ployItem item;
|
||||
item.start = cat::HCatBuffer(start);
|
||||
item.end = cat::HCatBuffer(end);
|
||||
info->relayInfo.relayList[index].ploys.emplace_back(std::move(item));
|
||||
}
|
||||
|
||||
void ClearRelayInfoItemPloy(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
info->relayInfo.InitRelayList();
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
info->relayInfo.relayList[index].ploys.clear();
|
||||
}
|
||||
|
||||
void SetRelayInfoItemPloyItem(sdk::ISDKInfo info, int index, int itemIndex, const char *start, const char *end)
|
||||
{
|
||||
info->relayInfo.InitRelayList();
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
if (itemIndex < 0 || itemIndex >= static_cast<int>(info->relayInfo.relayList.at(index).ploys.size())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
info->relayInfo.relayList[index].ploys[itemIndex].start = cat::HCatBuffer(start);
|
||||
info->relayInfo.relayList[index].ploys[itemIndex].end = cat::HCatBuffer(end);
|
||||
}
|
||||
|
||||
void SetRelayInfoInternal(sdk::ISDKInfo info, const char *name, HBool useSwitch)
|
||||
{
|
||||
info->relayInfo.internal.name = cat::HCatBuffer(name);
|
||||
info->relayInfo.internal.useSwitch = useSwitch != HFalse;
|
||||
}
|
||||
|
||||
void AddRelayInfoInternalPloy(sdk::ISDKInfo info, const char *start, const char *end)
|
||||
{
|
||||
sdk::RelayInfo::ployItem item;
|
||||
item.start = cat::HCatBuffer(start);
|
||||
item.end = cat::HCatBuffer(end);
|
||||
info->relayInfo.internal.ploys.emplace_back(std::move(item));
|
||||
}
|
||||
|
||||
void ClearRelayInfoInternalPloy(sdk::ISDKInfo info)
|
||||
{
|
||||
info->relayInfo.internal.ploys.clear();
|
||||
}
|
||||
|
||||
void SetRelayInfoInternalPloyItem(sdk::ISDKInfo info, int index, const char *start, const char *end)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.internal.ploys.size())) {
|
||||
return ;
|
||||
}
|
||||
|
||||
info->relayInfo.internal.ploys[index].start = cat::HCatBuffer(start);
|
||||
info->relayInfo.internal.ploys[index].end = cat::HCatBuffer(end);
|
||||
}
|
||||
|
||||
int GetRelayInfoStatus(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return info->relayInfo.relayList.at(index).relayStatus;
|
||||
}
|
||||
|
||||
const char *GetRelayInfoName(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return info->relayInfo.relayList.at(index).name.ConstData();
|
||||
}
|
||||
|
||||
HBool GetRelayInfoUseSwitch(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return HFalse;
|
||||
}
|
||||
|
||||
return info->relayInfo.relayList.at(index).useSwitch ? HTrue : HFalse;
|
||||
}
|
||||
|
||||
int GetRelayInfoItemPloySize(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return info->relayInfo.relayList.at(index).ploys.size();
|
||||
}
|
||||
|
||||
const char *GetRelayInfoItemPloyStart(sdk::ISDKInfo info, int index, int itemIndex)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (itemIndex < 0 || itemIndex >= static_cast<int>(info->relayInfo.relayList.at(index).ploys.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return info->relayInfo.relayList.at(index).ploys.at(itemIndex).start.ConstData();
|
||||
}
|
||||
|
||||
const char *GetRelayInfoItemPloyEnd(sdk::ISDKInfo info, int index, int itemIndex)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.relayList.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (itemIndex < 0 || itemIndex >= static_cast<int>(info->relayInfo.relayList.at(index).ploys.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return info->relayInfo.relayList.at(index).ploys.at(itemIndex).end.ConstData();
|
||||
}
|
||||
|
||||
int GetRelayInfoInternalPloySize(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->relayInfo.internal.ploys.size();
|
||||
}
|
||||
|
||||
const char *GetRelayInfoInternalPloyStart(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.internal.ploys.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return info->relayInfo.internal.ploys.at(index).start.ConstData();
|
||||
}
|
||||
|
||||
const char *GetRelayInfoInternalPloyEnd(sdk::ISDKInfo info, int index)
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(info->relayInfo.internal.ploys.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return info->relayInfo.internal.ploys.at(index).end.ConstData();
|
||||
}
|
||||
|
||||
const char *GetDevceInfoId(ISDKInfo info)
|
||||
{
|
||||
return info->deviceInfo.device.id.ConstData();
|
||||
}
|
||||
|
||||
const char *GetDevceInfoName(ISDKInfo info)
|
||||
{
|
||||
return info->deviceInfo.device.name.ConstData();
|
||||
}
|
||||
|
||||
const char *GetDevceInfoAppVersion(ISDKInfo info)
|
||||
{
|
||||
return info->deviceInfo.version.app.ConstData();
|
||||
}
|
||||
|
||||
const char *GetDevceInfoFpgaVersion(ISDKInfo info)
|
||||
{
|
||||
return info->deviceInfo.version.fpga.ConstData();
|
||||
}
|
||||
|
||||
int GetDevceInfoScreenRotation(ISDKInfo info)
|
||||
{
|
||||
return info->deviceInfo.screen.rotation;
|
||||
}
|
||||
|
||||
int GetDevceInfoScreenWidth(ISDKInfo info)
|
||||
{
|
||||
return info->deviceInfo.screen.width;
|
||||
}
|
||||
|
||||
int GetDevceInfoScreenHeight(ISDKInfo info)
|
||||
{
|
||||
return info->deviceInfo.screen.height;
|
||||
}
|
||||
|
||||
void SetScreenShot(ISDKInfo info, int width, int height)
|
||||
{
|
||||
info->screenShot2.width = width;
|
||||
info->screenShot2.height = height;
|
||||
}
|
||||
|
||||
const char *GetScreenShot(ISDKInfo info)
|
||||
{
|
||||
return info->screenShot2.rawData.ConstData();
|
||||
}
|
||||
|
||||
int GetScreenShotSize(sdk::ISDKInfo info)
|
||||
{
|
||||
return info->screenShot2.rawData.Size();
|
||||
}
|
||||
267
SDK/SDKInfo.h
Normal file
267
SDK/SDKInfo.h
Normal file
@ -0,0 +1,267 @@
|
||||
|
||||
|
||||
#ifndef __ISDKINFO_H__
|
||||
#define __ISDKINFO_H__
|
||||
|
||||
|
||||
#include <HDSDK.h>
|
||||
|
||||
#ifdef USE_HD_LIB
|
||||
namespace sdk{
|
||||
typedef struct HSDKInfo* ISDKInfo;
|
||||
}
|
||||
using sdk::ISDKInfo;
|
||||
#else
|
||||
typedef void* ISDKInfo;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
///< 创建信息体
|
||||
HD_API ISDKInfo DLL_CALL CreateSDKInfo();
|
||||
///< 释放信息体
|
||||
HD_API void DLL_CALL FreeSDKInfo(ISDKInfo info);
|
||||
///< 解析xml生成对应数据信息
|
||||
HD_API HBool DLL_CALL ParseXml(const char *xml, int len, ISDKInfo info);
|
||||
|
||||
enum eUpdateItem {
|
||||
kGetLightInfo = 0x1000, ///< 获取亮度信息
|
||||
kSetLightInfo = 0x1001, ///< 设置亮度信息
|
||||
kGetSystemVolumeInfo = 0x1002, ///< 获取系统音量
|
||||
kSetSystemVolumeInfo = 0x1003, ///< 设置系统音量
|
||||
kGetTcpServerInfo = 0x1004, ///< 获取tcp服务器
|
||||
kSetTcpServerInfo = 0x1005, ///< 设置tcp服务器
|
||||
kGetTimeInfo = 0x1006, ///< 获取时间信息
|
||||
kSetTimeInfo = 0x1007, ///< 设置时间信息
|
||||
kGetEthInfo = 0x1008, ///< 获取有线信息
|
||||
kSetEthInfo = 0x1009, ///< 设置有线信息
|
||||
kGetWifiInfo = 0x1010, ///< 获取Wifi信息
|
||||
kSetWifiInfo = 0x1011, ///< 设置Wifi信息
|
||||
kGetPppoeInfo = 0x1012, ///< 获取pppoe信息
|
||||
kSetPppoeInfo = 0x1013, ///< 设置pppoe信息
|
||||
kGetDeviceNameInfo = 0x1014, ///< 获取设备名信息
|
||||
kSetDeviceNameInfo = 0x1015, ///< 设置设备名信息
|
||||
kGetSwitchTimeInfo = 0x1016, ///< 获取开关机信息
|
||||
kSetSwitchTimeInfo = 0x1017, ///< 设置开关机信息
|
||||
kGetRelayInfo = 0x1018, ///< 获取继电器信息
|
||||
kSetRelayInfo = 0x1019, ///< 设置继电器信息
|
||||
|
||||
///< 没有设置项, 只有获取项
|
||||
kGetDeviceInfo = 0x2000, ///< 获取设备信息
|
||||
kGetScreenShot = 0x2001, ///< 获取截图数据
|
||||
};
|
||||
///< 更新对应项, 需要参数会话, 信息体, 对应项
|
||||
HD_API HBool DLL_CALL UpdateItem(IHDProtocol protocol, ISDKInfo info, int updateItem);
|
||||
|
||||
/**
|
||||
* @brief SetLightInfo 设置亮度信息
|
||||
* @param info 信息体
|
||||
* @param mode 亮度模式 {0(默认), 1(自定义模式), 2(传感器模式)}
|
||||
* @param defaultModeLight 默认模式下的亮度
|
||||
*/
|
||||
HD_API void DLL_CALL SetLightInfo(ISDKInfo info, int mode, int defaultModeLight);
|
||||
HD_API void DLL_CALL SetLightInfoSensor(ISDKInfo info, int min, int max, int time);
|
||||
// startTime格式 HH:mm:ss
|
||||
HD_API void DLL_CALL AddLightInfoPloy(ISDKInfo info, HBool enable, const char *startTime, int percent);
|
||||
HD_API void DLL_CALL SetLightInfoPloy(ISDKInfo info, int index, HBool enable, const char *startTime, int percent);
|
||||
HD_API void DLL_CALL ClearLightInfoPloy(ISDKInfo info);
|
||||
|
||||
///< 亮度获取系列
|
||||
HD_API int DLL_CALL GetLightInfoMode(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetLightInfoDefaultLight(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetLightInfoPloySize(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetLightInfoPloyEnable(ISDKInfo info, int index);
|
||||
HD_API int DLL_CALL GetLightInfoPloyPercent(ISDKInfo info, int index);
|
||||
HD_API const char * DLL_CALL GetLightInfoPloyStart(ISDKInfo info, int index);
|
||||
HD_API int DLL_CALL GetLightInfoSensorMax(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetLightInfoSensorMin(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetLightInfoSensorTime(ISDKInfo info);
|
||||
|
||||
/**
|
||||
* @brief SetSystemVolume 设置系统音量
|
||||
* @param info 信息体
|
||||
* @param mode 音量模式{0(默认), 1(分时)}
|
||||
* @param volume 默认模式下的音量
|
||||
*/
|
||||
HD_API void DLL_CALL SetSystemVolumeInfo(ISDKInfo info, int mode, int volume);
|
||||
// time格式HH:mm:ss
|
||||
HD_API void DLL_CALL AddSystemVolumeInfoPloy(ISDKInfo info, HBool enable, const char *time, int volume);
|
||||
HD_API void DLL_CALL ClearSystemVolumeInfoPloy(ISDKInfo info);
|
||||
|
||||
///< 系统音量获取系列
|
||||
HD_API int DLL_CALL GetSystemVolumeInfoMode(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetSystemVolumeInfoVolume(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetSystemVolumeInfoPloySize(ISDKInfo info);
|
||||
HD_API HBool DLL_CALL GetSystemVolumeInfoPloyEnable(ISDKInfo info, int index);
|
||||
HD_API const char * DLL_CALL GetSystemVolumeInfoPloyTime(ISDKInfo info, int index);
|
||||
HD_API int DLL_CALL GetSystemVolumeInfoPloyVolume(ISDKInfo info, int index);
|
||||
|
||||
/**
|
||||
* @brief SetTcpServerInfo 设置tcp服务器
|
||||
* @param info 信息体
|
||||
* @param ip 服务器地址
|
||||
* @param port 端口
|
||||
*/
|
||||
HD_API void DLL_CALL SetTcpServerInfo(ISDKInfo info, const char *ip, huint16 port);
|
||||
|
||||
///< tcp服务器获取系列
|
||||
HD_API const char * DLL_CALL GetTcpServerInfoIp(ISDKInfo info);
|
||||
HD_API huint16 DLL_CALL GetTcpServerInfoPort(ISDKInfo info);
|
||||
|
||||
|
||||
/**
|
||||
* @brief SetTimeInfo 设置时间
|
||||
* @param info 信息体
|
||||
* @param timeZone 时区, 格式"(UTC+08:00)Beijing,Chongqing,HongKong,Urumchi"
|
||||
* @param summer 是否开启夏令时
|
||||
* @param sync 是否开启时间同步 {"none"(不开启自动同步), "gps"(gps校时), "network"(网络校时), "auto"(自动校时)}
|
||||
* @param currTime 时间 格式"yyyy-MM-dd hh:mm:ss"
|
||||
* @param ntp服务器列表, 以逗号分隔
|
||||
*/
|
||||
HD_API void DLL_CALL SetTimeInfo(ISDKInfo info, const char *timeZone, HBool summer, const char *sync, const char *currTime, const char *serverList);
|
||||
|
||||
///< 时间信息获取系列
|
||||
HD_API const char * DLL_CALL GetTimeInfoTimeZone(ISDKInfo info);
|
||||
HD_API HBool DLL_CALL GetTimeInfoSummer(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetTimeInfoSync(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetTimeInfoCurrTime(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetTimeInfoServerList(ISDKInfo info);
|
||||
|
||||
|
||||
/**
|
||||
* @brief SetEthInfo 设置以太网信息
|
||||
* @param info 信息体
|
||||
* @param dhcp dhcp
|
||||
* @param ip ip
|
||||
* @param netmask 网络掩码
|
||||
* @param gateway 网关
|
||||
* @param dns dns
|
||||
*/
|
||||
HD_API void DLL_CALL SetEthInfo(ISDKInfo info, HBool dhcp, const char *ip, const char *netmask, const char *gateway, const char *dns);
|
||||
|
||||
///< 以太网信息获取系列
|
||||
HD_API HBool DLL_CALL GetEhtInfoDhcp(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetEhtInfoIp(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetEhtInfoNetmask(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetEhtInfoGateway(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetEhtInfoDns(ISDKInfo info);
|
||||
|
||||
|
||||
/**
|
||||
* @brief SetWifiInfo 设置wifi信息
|
||||
* @param info 信息体
|
||||
* @param mode {0: ap模式, 1: station模式}
|
||||
*/
|
||||
HD_API void DLL_CALL SetWifiInfo(ISDKInfo info, int mode);
|
||||
HD_API void DLL_CALL SetWifiInfoAp(ISDKInfo info, const char *ssid, const char *password, const char *ip);
|
||||
HD_API void DLL_CALL SetWifiInfoStation(ISDKInfo info, const char *ssid, const char *password, HBool dhcp);
|
||||
HD_API void DLL_CALL SetWifiInfoStationNet(ISDKInfo info, const char *ip, const char *mask, const char *gateway, const char *dns);
|
||||
|
||||
HD_API int DLL_CALL GetWifiInfoMode(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetWifiInfoApSsid(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetWifiInfoApPassword(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetWifiInfoApIp(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetWifiInfoStationSsid(ISDKInfo info);
|
||||
HD_API HBool DLL_CALL GetWifiInfoStationDhcp(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetWifiInfoStationIp(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetWifiInfoStationMask(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetWifiInfoStationGateway(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetWifiInfoStationDns(ISDKInfo info);
|
||||
|
||||
|
||||
/**
|
||||
* @brief SetPppoeInfoApn 设置pppoe apn
|
||||
* @param info 信息体
|
||||
* @param apn apn
|
||||
*/
|
||||
HD_API void DLL_CALL SetPppoeInfoApn(ISDKInfo info, const char *apn);
|
||||
|
||||
HD_API HBool DLL_CALL GetPppoeInfoVaild(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetPppoeInfoApn(ISDKInfo info);
|
||||
|
||||
|
||||
/**
|
||||
* @brief SetDeviceNameInfo 设置设备名
|
||||
* @param info 信息体
|
||||
* @param name 设备名
|
||||
**/
|
||||
HD_API void DLL_CALL SetDeviceNameInfo(ISDKInfo info, const char *name);
|
||||
HD_API const char * DLL_CALL GetDeviceNameInfo(ISDKInfo info);
|
||||
|
||||
|
||||
/**
|
||||
* @brief SetSwitchTimeInfo 设置定时开关机
|
||||
* @param info 信息体
|
||||
* @param name 模式
|
||||
* @param enable 是否开启定时开关机
|
||||
**/
|
||||
HD_API void DLL_CALL SetSwitchTimeInfo(ISDKInfo info, int mode, HBool enable);
|
||||
// start和end 格式 hh:mm:ss
|
||||
HD_API void DLL_CALL AddSwitchTimeInfoItem(ISDKInfo info, HBool enable, const char *start, const char *end);
|
||||
HD_API void DLL_CALL ClearSwitchTimeInfoItem(ISDKInfo info);
|
||||
HD_API HBool DLL_CALL SetSwitchTimeInfoItem(ISDKInfo info, int index, HBool enable, const char *start, const char *end);
|
||||
// start和end 格式 hh:mm:ss
|
||||
HD_API void DLL_CALL AddSwitchTimeInfoWeekItem(ISDKInfo info, int week, HBool openAllDay, const char *start, const char *end);
|
||||
HD_API void DLL_CALL ClearSwitchTimeInfoWeekItem(ISDKInfo info, int week);
|
||||
HD_API void DLL_CALL SetSwitchTimeInfoWeekItem(ISDKInfo info, int week, int index, HBool openAllDay, const char *start, const char *end);
|
||||
|
||||
HD_API int DLL_CALL GetSwitchTimeInfoItemSize(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetSwitchTimeInfoWeekItemSize(ISDKInfo info, int week);
|
||||
HD_API HBool DLL_CALL GetSwitchTimeInfoEnable(ISDKInfo info);
|
||||
HD_API HBool DLL_CALL GetSwitchTimeInfoItemEnable(ISDKInfo info, int index);
|
||||
HD_API const char * DLL_CALL GetSwitchTimeInfoItemStart(ISDKInfo info, int index);
|
||||
HD_API const char * DLL_CALL GetSwitchTimeInfoItemEnd(ISDKInfo info, int index);
|
||||
|
||||
|
||||
/**
|
||||
* @brief SetRelayInfoItem 设置继电器项
|
||||
* @param info 信息体
|
||||
* @param index 继电器索引
|
||||
* @param name 继电器名
|
||||
* @param useSwitch 关联显示屏状态
|
||||
**/
|
||||
HD_API void DLL_CALL SetRelayInfoItem(ISDKInfo info, int index, const char *name, HBool useSwitch);
|
||||
HD_API void DLL_CALL AddRelayInfoItemPloy(ISDKInfo info, int index, const char *start, const char *end);
|
||||
HD_API void DLL_CALL ClearRelayInfoItemPloy(ISDKInfo info, int index);
|
||||
HD_API void DLL_CALL SetRelayInfoItemPloyItem(ISDKInfo info, int index, int itemIndex, const char *start, const char *end);
|
||||
HD_API void DLL_CALL SetRelayInfoInternal(ISDKInfo info, const char *name, HBool useSwitch);
|
||||
HD_API void DLL_CALL AddRelayInfoInternalPloy(ISDKInfo info, const char *start, const char *end);
|
||||
HD_API void DLL_CALL ClearRelayInfoInternalPloy(ISDKInfo info);
|
||||
HD_API void DLL_CALL SetRelayInfoInternalPloyItem(ISDKInfo info, int index, const char *start, const char *end);
|
||||
|
||||
HD_API int DLL_CALL GetRelayInfoStatus(ISDKInfo info, int index);
|
||||
HD_API const char * DLL_CALL GetRelayInfoName(ISDKInfo info, int index);
|
||||
HD_API HBool DLL_CALL GetRelayInfoUseSwitch(ISDKInfo info, int index);
|
||||
HD_API int DLL_CALL GetRelayInfoItemPloySize(ISDKInfo info, int index);
|
||||
HD_API const char * DLL_CALL GetRelayInfoItemPloyStart(ISDKInfo info, int index, int itemIndex);
|
||||
HD_API const char * DLL_CALL GetRelayInfoItemPloyEnd(ISDKInfo info, int index, int itemIndex);
|
||||
HD_API int DLL_CALL GetRelayInfoInternalPloySize(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetRelayInfoInternalPloyStart(ISDKInfo info, int index);
|
||||
HD_API const char * DLL_CALL GetRelayInfoInternalPloyEnd(ISDKInfo info, int index);
|
||||
|
||||
|
||||
|
||||
///< 下面是获取
|
||||
|
||||
///< 获取设备信息系列
|
||||
HD_API const char * DLL_CALL GetDevceInfoId(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetDevceInfoName(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetDevceInfoAppVersion(ISDKInfo info);
|
||||
HD_API const char * DLL_CALL GetDevceInfoFpgaVersion(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetDevceInfoScreenRotation(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetDevceInfoScreenWidth(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetDevceInfoScreenHeight(ISDKInfo info);
|
||||
|
||||
///< 获取屏幕截图系列
|
||||
HD_API void DLL_CALL SetScreenShot(ISDKInfo info, int width, int height);
|
||||
HD_API const char * DLL_CALL GetScreenShot(ISDKInfo info);
|
||||
HD_API int DLL_CALL GetScreenShotSize(ISDKInfo info);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ISDKINFO_H
|
||||
2994
SDK/tinyxml2.cpp
Normal file
2994
SDK/tinyxml2.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2380
SDK/tinyxml2.h
Normal file
2380
SDK/tinyxml2.h
Normal file
File diff suppressed because it is too large
Load Diff
111
demo/eth.cpp
Normal file
111
demo/eth.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "../SDK/SDKInfo.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
struct Proto
|
||||
{
|
||||
IHDProtocol proto;
|
||||
ISDKInfo info;
|
||||
};
|
||||
|
||||
int IsRead = 0;
|
||||
|
||||
|
||||
static bool SendData(const char *data, int len, void *userData) {
|
||||
int fd = (int)(intptr_t)userData;
|
||||
return write(fd, data, len) > 0;
|
||||
}
|
||||
|
||||
static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
||||
Proto *info = (Proto *)userData;
|
||||
++IsRead;
|
||||
if (errorCode != 0) {
|
||||
printf("error code[%d]\n", errorCode);
|
||||
return ;
|
||||
}
|
||||
ParseXml(xml, len, info->info);
|
||||
|
||||
std::cout << "dhcp:" << GetEhtInfoDhcp(info->info) << "\n"
|
||||
<< "ip:" << GetEhtInfoIp(info->info) << "\n"
|
||||
<< "netmask:" << GetEhtInfoNetmask(info->info) << "\n"
|
||||
<< "gateway:" << GetEhtInfoGateway(info->info) << "\n"
|
||||
<< "dns:" << GetEhtInfoDns(info->info) << "\n"
|
||||
<< std::endl;
|
||||
|
||||
if (IsRead == 1) {
|
||||
// UpdateItem(info->proto, info->info, kSetEthInfo);
|
||||
}
|
||||
UpdateItem(info->proto, info->info, kGetEthInfo);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("a.out ip\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("create socket faild");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct sockaddr_in addrSrv;
|
||||
memset(&addrSrv, 0, sizeof(addrSrv));
|
||||
addrSrv.sin_family = AF_INET;
|
||||
addrSrv.sin_port = htons(10001);
|
||||
addrSrv.sin_addr.s_addr = inet_addr(argv[1]);
|
||||
|
||||
int result = connect(fd, reinterpret_cast<struct sockaddr *>(&addrSrv), sizeof(addrSrv));
|
||||
if (result < 0) {
|
||||
close(fd);
|
||||
perror("Not connect client");
|
||||
return 2;
|
||||
}
|
||||
|
||||
ISDKInfo sdkInfo = CreateSDKInfo();
|
||||
IHDProtocol proto = CreateProtocol();
|
||||
Proto a;
|
||||
a.proto = proto;
|
||||
a.info = sdkInfo;
|
||||
SetProtocolFunc(proto, kSetSendFunc, (void *)SendData);
|
||||
SetProtocolFunc(proto, kSetSendFuncData, (void *)(intptr_t)(fd));
|
||||
SetProtocolFunc(proto, kSetReadXml, (void *)ReadXml);
|
||||
SetProtocolFunc(proto, kSetReadXmlData, (void *)&a);
|
||||
|
||||
RunProtocol(proto);
|
||||
|
||||
UpdateItem(proto, sdkInfo, kGetEthInfo);
|
||||
|
||||
char buff[1024];
|
||||
for (;;) {
|
||||
int len = read(fd, buff, sizeof(buff));
|
||||
if (len <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateReadData(proto, buff, len);
|
||||
if (IsRead > 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FreeSDKInfo(sdkInfo);
|
||||
FreeProtocol(proto);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
122
demo/lightInfo.cpp
Normal file
122
demo/lightInfo.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "../SDK/SDKInfo.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
struct Proto
|
||||
{
|
||||
IHDProtocol proto;
|
||||
ISDKInfo info;
|
||||
};
|
||||
|
||||
int IsRead = 0;
|
||||
|
||||
|
||||
static bool SendData(const char *data, int len, void *userData) {
|
||||
int fd = (int)(intptr_t)userData;
|
||||
return write(fd, data, len) > 0;
|
||||
}
|
||||
|
||||
static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
||||
Proto *info = (Proto *)userData;
|
||||
++IsRead;
|
||||
if (errorCode != 0) {
|
||||
printf("error code[%d]\n", errorCode);
|
||||
return ;
|
||||
}
|
||||
ParseXml(xml, len, info->info);
|
||||
|
||||
std::cout << "mode:" << GetLightInfoMode(info->info) << "\n"
|
||||
<< "defaultLight:" << GetLightInfoDefaultLight(info->info) << "\n"
|
||||
<< "ploySize:" << GetLightInfoPloySize(info->info) << "\n"
|
||||
<< "ployEnable:" << GetLightInfoPloyEnable(info->info, 0) << "\n"
|
||||
<< "ployPercent:" << GetLightInfoPloyPercent(info->info, 0) << "\n"
|
||||
<< "ployStart:" << GetLightInfoPloyStart(info->info, 0) << "\n"
|
||||
<< "sensorMax:" << GetLightInfoSensorMax(info->info) << "\n"
|
||||
<< "sensorMin:" << GetLightInfoSensorMin(info->info) << "\n"
|
||||
<< "sensorTime:" << GetLightInfoSensorTime(info->info) << "\n"
|
||||
<< std::endl;
|
||||
|
||||
ClearLightInfoPloy(info->info);
|
||||
std::cout << GetLightInfoPloySize(info->info) << std::endl;
|
||||
if (IsRead == 1) {
|
||||
SetLightInfo(info->info, 0, 100);
|
||||
SetLightInfoSensor(info->info, 0, 100, 5);
|
||||
AddLightInfoPloy(info->info, HFalse, "12:12:12", 50);
|
||||
SetLightInfoPloy(info->info, 0, HFalse, "11:11:11", 50);
|
||||
UpdateItem(info->proto, info->info, kSetLightInfo);
|
||||
} else {
|
||||
UpdateItem(info->proto, info->info, kGetLightInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("a.out ip\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("create socket faild");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct sockaddr_in addrSrv;
|
||||
memset(&addrSrv, 0, sizeof(addrSrv));
|
||||
addrSrv.sin_family = AF_INET;
|
||||
addrSrv.sin_port = htons(10001);
|
||||
addrSrv.sin_addr.s_addr = inet_addr(argv[1]);
|
||||
|
||||
int result = connect(fd, reinterpret_cast<struct sockaddr *>(&addrSrv), sizeof(addrSrv));
|
||||
if (result < 0) {
|
||||
close(fd);
|
||||
perror("Not connect client");
|
||||
return 2;
|
||||
}
|
||||
|
||||
ISDKInfo sdkInfo = CreateSDKInfo();
|
||||
IHDProtocol proto = CreateProtocol();
|
||||
Proto a;
|
||||
a.proto = proto;
|
||||
a.info = sdkInfo;
|
||||
SetProtocolFunc(proto, kSetSendFunc, (void *)SendData);
|
||||
SetProtocolFunc(proto, kSetSendFuncData, (void *)(intptr_t)(fd));
|
||||
SetProtocolFunc(proto, kSetReadXml, (void *)ReadXml);
|
||||
SetProtocolFunc(proto, kSetReadXmlData, (void *)&a);
|
||||
|
||||
RunProtocol(proto);
|
||||
|
||||
UpdateItem(proto, sdkInfo, kGetLightInfo);
|
||||
|
||||
char buff[1024];
|
||||
for (;;) {
|
||||
int len = read(fd, buff, sizeof(buff));
|
||||
if (len <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateReadData(proto, buff, len);
|
||||
if (IsRead > 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FreeSDKInfo(sdkInfo);
|
||||
FreeProtocol(proto);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
129
demo/sendFile.cpp
Normal file
129
demo/sendFile.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "HDSDK.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int IsRead = 0;
|
||||
|
||||
|
||||
static bool SendData(const char *data, int len, void *userData) {
|
||||
int fd = (int)(intptr_t)userData;
|
||||
return write(fd, data, len) > 0;
|
||||
}
|
||||
|
||||
static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
||||
(void)len;
|
||||
(void)userData;
|
||||
++IsRead;
|
||||
if (errorCode != 0) {
|
||||
printf("error code[%d]\n", errorCode);
|
||||
return ;
|
||||
}
|
||||
printf("====[%s]===\n", xml);
|
||||
}
|
||||
|
||||
static int SendPngFile(hint64 index, hint64 size, int status, char *buff, int buffSize, void *userData) {
|
||||
if (status != 0) {
|
||||
printf("send file faild[%d]\n", status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("[%lld][%lld][%f]\r", index, size, 1.0f * index / size);
|
||||
if (index == size) {
|
||||
++IsRead;
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = (int)(intptr_t)userData;
|
||||
if (lseek(fd, 0, SEEK_CUR) != index) {
|
||||
lseek(fd, index, SEEK_SET);
|
||||
}
|
||||
int len = read(fd, buff, buffSize);
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("a.out ip\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fileFd = open("./1.png", O_RDONLY);
|
||||
if (fileFd == -1) {
|
||||
perror("not open file[1.png]");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("create socket faild");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct sockaddr_in addrSrv;
|
||||
memset(&addrSrv, 0, sizeof(addrSrv));
|
||||
addrSrv.sin_family = AF_INET;
|
||||
addrSrv.sin_port = htons(10001);
|
||||
addrSrv.sin_addr.s_addr = inet_addr(argv[1]);
|
||||
|
||||
int result = connect(fd, reinterpret_cast<struct sockaddr *>(&addrSrv), sizeof(addrSrv));
|
||||
if (result < 0) {
|
||||
close(fd);
|
||||
perror("Not connect client");
|
||||
return 2;
|
||||
}
|
||||
|
||||
IHDProtocol proto = CreateProtocol();
|
||||
SetProtocolFunc(proto, kSetSendFunc, (void *)SendData);
|
||||
SetProtocolFunc(proto, kSetSendFuncData, (void *)(intptr_t)(fd));
|
||||
SetProtocolFunc(proto, kSetReadXml, (void *)ReadXml);
|
||||
|
||||
RunProtocol(proto);
|
||||
|
||||
const char *xml = R"(<?xml version='1.0' encoding='utf-8'?>
|
||||
<sdk guid="##GUID">
|
||||
<in method="GetDeviceInfo"/>
|
||||
</sdk>)";
|
||||
|
||||
const char *getFiles = R"(<?xml version='1.0' encoding='utf-8'?>
|
||||
<sdk guid="##GUID">
|
||||
<in method="GetFiles"/>
|
||||
</sdk>
|
||||
)";
|
||||
|
||||
SendXml(proto, xml, strlen(xml));
|
||||
const char *fileName = "test.png";
|
||||
SendFile(proto, fileName, strlen(fileName), "6070a9ea174fdae68e8fe89bc5ec7403", 0, 21060215, SendPngFile, (void *)(intptr_t)fileFd);
|
||||
SendXml(proto, getFiles, strlen(getFiles));
|
||||
|
||||
char buff[1024];
|
||||
for (;;) {
|
||||
int len = read(fd, buff, sizeof(buff));
|
||||
if (len <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateReadData(proto, buff, len);
|
||||
if (IsRead > 4) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FreeProtocol(proto);
|
||||
close(fileFd);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
102
demo/sendXml.cpp
Normal file
102
demo/sendXml.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "HDSDK.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int IsRead = 0;
|
||||
|
||||
|
||||
static bool SendData(const char *data, int len, void *userData) {
|
||||
int fd = (int)(intptr_t)userData;
|
||||
return write(fd, data, len) > 0;
|
||||
}
|
||||
|
||||
static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
||||
(void)len;
|
||||
(void)userData;
|
||||
++IsRead;
|
||||
if (errorCode != 0) {
|
||||
printf("error code[%d]\n", errorCode);
|
||||
return ;
|
||||
}
|
||||
printf("====[%s]===\n", xml);
|
||||
|
||||
char **p = (char **)(userData);
|
||||
free(*p);
|
||||
*p = (char *)malloc(len);
|
||||
memcpy(*p, xml, len);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("a.out ip\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("create socket faild");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct sockaddr_in addrSrv;
|
||||
memset(&addrSrv, 0, sizeof(addrSrv));
|
||||
addrSrv.sin_family = AF_INET;
|
||||
addrSrv.sin_port = htons(10001);
|
||||
addrSrv.sin_addr.s_addr = inet_addr(argv[1]);
|
||||
|
||||
int result = connect(fd, reinterpret_cast<struct sockaddr *>(&addrSrv), sizeof(addrSrv));
|
||||
if (result < 0) {
|
||||
close(fd);
|
||||
perror("Not connect client");
|
||||
return 2;
|
||||
}
|
||||
|
||||
char *p_buff = NULL;
|
||||
|
||||
IHDProtocol proto = CreateProtocol();
|
||||
SetProtocolFunc(proto, kSetSendFunc, (void *)SendData);
|
||||
SetProtocolFunc(proto, kSetSendFuncData, (void *)(intptr_t)(fd));
|
||||
SetProtocolFunc(proto, kSetReadXml, (void *)ReadXml);
|
||||
SetProtocolFunc(proto, kSetReadXmlData, &p_buff);
|
||||
|
||||
RunProtocol(proto);
|
||||
|
||||
const char *xml = R"(<?xml version='1.0' encoding='utf-8'?>
|
||||
<sdk guid="##GUID">
|
||||
<in method="GetDeviceInfo"/>
|
||||
</sdk>)";
|
||||
|
||||
SendXml(proto, xml, strlen(xml));
|
||||
SendXml(proto, xml, strlen(xml));
|
||||
|
||||
char buff[1024];
|
||||
for (;;) {
|
||||
int len = read(fd, buff, sizeof(buff));
|
||||
if (len <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateReadData(proto, buff, len);
|
||||
if (IsRead > 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("read xml[\n%s]\n", p_buff);
|
||||
free(p_buff);
|
||||
FreeProtocol(proto);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
118
demo/systemVolume.cpp
Normal file
118
demo/systemVolume.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "../SDK/SDKInfo.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
struct Proto
|
||||
{
|
||||
IHDProtocol proto;
|
||||
ISDKInfo info;
|
||||
};
|
||||
|
||||
int IsRead = 0;
|
||||
|
||||
|
||||
static bool SendData(const char *data, int len, void *userData) {
|
||||
int fd = (int)(intptr_t)userData;
|
||||
return write(fd, data, len) > 0;
|
||||
}
|
||||
|
||||
static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
||||
Proto *info = (Proto *)userData;
|
||||
++IsRead;
|
||||
if (errorCode != 0) {
|
||||
printf("error code[%d]\n", errorCode);
|
||||
return ;
|
||||
}
|
||||
ParseXml(xml, len, info->info);
|
||||
|
||||
std::cout << "mode:" << GetSystemVolumeInfoMode(info->info) << "\n"
|
||||
<< "volume:" << GetSystemVolumeInfoVolume(info->info) << "\n"
|
||||
<< "ploySize:" << GetSystemVolumeInfoPloySize(info->info) << "\n"
|
||||
<< "ployEnable:" << GetSystemVolumeInfoPloyEnable(info->info, 0) << "\n"
|
||||
<< "ployTime:" << GetSystemVolumeInfoPloyTime(info->info, 0) << "\n"
|
||||
<< "ployVolume:" << GetSystemVolumeInfoPloyVolume(info->info, 0) << "\n"
|
||||
<< std::endl;
|
||||
|
||||
if (IsRead == 1) {
|
||||
SetSystemVolumeInfo(info->info, 0, 100);
|
||||
AddSystemVolumeInfoPloy(info->info, HFalse, "11:11:11", 100);
|
||||
ClearSystemVolumeInfoPloy(info->info);
|
||||
AddSystemVolumeInfoPloy(info->info, HFalse, "12:12:12", 100);
|
||||
|
||||
UpdateItem(info->proto, info->info, kSetSystemVolumeInfo);
|
||||
} else {
|
||||
UpdateItem(info->proto, info->info, kGetSystemVolumeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("a.out ip\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("create socket faild");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct sockaddr_in addrSrv;
|
||||
memset(&addrSrv, 0, sizeof(addrSrv));
|
||||
addrSrv.sin_family = AF_INET;
|
||||
addrSrv.sin_port = htons(10001);
|
||||
addrSrv.sin_addr.s_addr = inet_addr(argv[1]);
|
||||
|
||||
int result = connect(fd, reinterpret_cast<struct sockaddr *>(&addrSrv), sizeof(addrSrv));
|
||||
if (result < 0) {
|
||||
close(fd);
|
||||
perror("Not connect client");
|
||||
return 2;
|
||||
}
|
||||
|
||||
ISDKInfo sdkInfo = CreateSDKInfo();
|
||||
IHDProtocol proto = CreateProtocol();
|
||||
Proto a;
|
||||
a.proto = proto;
|
||||
a.info = sdkInfo;
|
||||
SetProtocolFunc(proto, kSetSendFunc, (void *)SendData);
|
||||
SetProtocolFunc(proto, kSetSendFuncData, (void *)(intptr_t)(fd));
|
||||
SetProtocolFunc(proto, kSetReadXml, (void *)ReadXml);
|
||||
SetProtocolFunc(proto, kSetReadXmlData, (void *)&a);
|
||||
|
||||
RunProtocol(proto);
|
||||
|
||||
UpdateItem(proto, sdkInfo, kGetSystemVolumeInfo);
|
||||
|
||||
char buff[1024];
|
||||
for (;;) {
|
||||
int len = read(fd, buff, sizeof(buff));
|
||||
if (len <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateReadData(proto, buff, len);
|
||||
if (IsRead > 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FreeSDKInfo(sdkInfo);
|
||||
FreeProtocol(proto);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
108
demo/tcpServer.cpp
Normal file
108
demo/tcpServer.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "../SDK/SDKInfo.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
struct Proto
|
||||
{
|
||||
IHDProtocol proto;
|
||||
ISDKInfo info;
|
||||
};
|
||||
|
||||
int IsRead = 0;
|
||||
|
||||
|
||||
static bool SendData(const char *data, int len, void *userData) {
|
||||
int fd = (int)(intptr_t)userData;
|
||||
return write(fd, data, len) > 0;
|
||||
}
|
||||
|
||||
static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
||||
Proto *info = (Proto *)userData;
|
||||
++IsRead;
|
||||
if (errorCode != 0) {
|
||||
printf("error code[%d]\n", errorCode);
|
||||
return ;
|
||||
}
|
||||
ParseXml(xml, len, info->info);
|
||||
|
||||
std::cout << "ip:" << GetTcpServerInfoIp(info->info) << "\n"
|
||||
<< "port:" << GetTcpServerInfoPort(info->info) << "\n"
|
||||
<< std::endl;
|
||||
|
||||
if (IsRead == 1) {
|
||||
// UpdateItem(info->proto, info->info, kSetTcpServerInfo);
|
||||
}
|
||||
UpdateItem(info->proto, info->info, kGetTcpServerInfo);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("a.out ip\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("create socket faild");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct sockaddr_in addrSrv;
|
||||
memset(&addrSrv, 0, sizeof(addrSrv));
|
||||
addrSrv.sin_family = AF_INET;
|
||||
addrSrv.sin_port = htons(10001);
|
||||
addrSrv.sin_addr.s_addr = inet_addr(argv[1]);
|
||||
|
||||
int result = connect(fd, reinterpret_cast<struct sockaddr *>(&addrSrv), sizeof(addrSrv));
|
||||
if (result < 0) {
|
||||
close(fd);
|
||||
perror("Not connect client");
|
||||
return 2;
|
||||
}
|
||||
|
||||
ISDKInfo sdkInfo = CreateSDKInfo();
|
||||
IHDProtocol proto = CreateProtocol();
|
||||
Proto a;
|
||||
a.proto = proto;
|
||||
a.info = sdkInfo;
|
||||
SetProtocolFunc(proto, kSetSendFunc, (void *)SendData);
|
||||
SetProtocolFunc(proto, kSetSendFuncData, (void *)(intptr_t)(fd));
|
||||
SetProtocolFunc(proto, kSetReadXml, (void *)ReadXml);
|
||||
SetProtocolFunc(proto, kSetReadXmlData, (void *)&a);
|
||||
|
||||
RunProtocol(proto);
|
||||
|
||||
UpdateItem(proto, sdkInfo, kGetTcpServerInfo);
|
||||
|
||||
char buff[1024];
|
||||
for (;;) {
|
||||
int len = read(fd, buff, sizeof(buff));
|
||||
if (len <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateReadData(proto, buff, len);
|
||||
if (IsRead > 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FreeSDKInfo(sdkInfo);
|
||||
FreeProtocol(proto);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
114
demo/time.cpp
Normal file
114
demo/time.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "../SDK/SDKInfo.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
struct Proto
|
||||
{
|
||||
IHDProtocol proto;
|
||||
ISDKInfo info;
|
||||
};
|
||||
|
||||
int IsRead = 0;
|
||||
|
||||
|
||||
static bool SendData(const char *data, int len, void *userData) {
|
||||
int fd = (int)(intptr_t)userData;
|
||||
return write(fd, data, len) > 0;
|
||||
}
|
||||
|
||||
static void ReadXml(const char *xml, int len, int errorCode, void *userData) {
|
||||
Proto *info = (Proto *)userData;
|
||||
++IsRead;
|
||||
if (errorCode != 0) {
|
||||
printf("error code[%d]\n", errorCode);
|
||||
return ;
|
||||
}
|
||||
ParseXml(xml, len, info->info);
|
||||
|
||||
std::cout << "timeZone:" << GetTimeInfoTimeZone(info->info) << "\n"
|
||||
<< "summer:" << GetTimeInfoSummer(info->info) << "\n"
|
||||
<< "sync:" << GetTimeInfoSync(info->info) << "\n"
|
||||
<< "currentTime:" << GetTimeInfoCurrTime(info->info) << "\n"
|
||||
<< "serverList:" << GetTimeInfoServerList(info->info) << "\n"
|
||||
<< std::endl;
|
||||
|
||||
if (IsRead == 1) {
|
||||
SetTimeInfo(info->info, GetTimeInfoTimeZone(info->info), GetTimeInfoSummer(info->info), "network", "2000-01-01 11:11:11", GetTimeInfoServerList(info->info));
|
||||
|
||||
UpdateItem(info->proto, info->info, kSetTimeInfo);
|
||||
} else {
|
||||
UpdateItem(info->proto, info->info, kGetTimeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
printf("a.out ip\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0) {
|
||||
perror("create socket faild");
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct sockaddr_in addrSrv;
|
||||
memset(&addrSrv, 0, sizeof(addrSrv));
|
||||
addrSrv.sin_family = AF_INET;
|
||||
addrSrv.sin_port = htons(10001);
|
||||
addrSrv.sin_addr.s_addr = inet_addr(argv[1]);
|
||||
|
||||
int result = connect(fd, reinterpret_cast<struct sockaddr *>(&addrSrv), sizeof(addrSrv));
|
||||
if (result < 0) {
|
||||
close(fd);
|
||||
perror("Not connect client");
|
||||
return 2;
|
||||
}
|
||||
|
||||
ISDKInfo sdkInfo = CreateSDKInfo();
|
||||
IHDProtocol proto = CreateProtocol();
|
||||
Proto a;
|
||||
a.proto = proto;
|
||||
a.info = sdkInfo;
|
||||
SetProtocolFunc(proto, kSetSendFunc, (void *)SendData);
|
||||
SetProtocolFunc(proto, kSetSendFuncData, (void *)(intptr_t)(fd));
|
||||
SetProtocolFunc(proto, kSetReadXml, (void *)ReadXml);
|
||||
SetProtocolFunc(proto, kSetReadXmlData, (void *)&a);
|
||||
|
||||
RunProtocol(proto);
|
||||
|
||||
UpdateItem(proto, sdkInfo, kGetTimeInfo);
|
||||
|
||||
char buff[1024];
|
||||
for (;;) {
|
||||
int len = read(fd, buff, sizeof(buff));
|
||||
if (len <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
UpdateReadData(proto, buff, len);
|
||||
if (IsRead > 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FreeSDKInfo(sdkInfo);
|
||||
FreeProtocol(proto);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user