diff --git a/CMakeLists.txt b/CMakeLists.txt index 43cde37..08bfe5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,4 +69,12 @@ if(ENABLE_DEMO) ${CMAKE_CURRENT_SOURCE_DIR}/SDK ) target_link_libraries(eth PRIVATE HDSDK) + + add_executable(sendProgram demo/sendProgram.cpp) + target_include_directories(sendProgram PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/Protocol + ${CMAKE_CURRENT_SOURCE_DIR}/SDK + ) + target_link_libraries(sendProgram PRIVATE HDSDK) endif() diff --git a/Protocol/CMakeLists.txt b/Protocol/CMakeLists.txt index c1a3024..b9427ad 100644 --- a/Protocol/CMakeLists.txt +++ b/Protocol/CMakeLists.txt @@ -19,6 +19,7 @@ if (ENABLE_SDK) ${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HSDKInfo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HSensorInfo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HTimeInfo.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/../SDK/Data/HProgramInfo.cpp ) endif() diff --git a/SDK/Data/HProgramInfo.cpp b/SDK/Data/HProgramInfo.cpp new file mode 100644 index 0000000..d8bef2b --- /dev/null +++ b/SDK/Data/HProgramInfo.cpp @@ -0,0 +1,235 @@ + + +#include "HXml.h" +#include + +void to_xml(HXml &xml, const EffectInfo &node) +{ + xml["effect"] = { + {"inSpeed", node.inSpeed}, + {"outSpeed", node.outSpeed}, + {"in", node.in}, + {"out", node.out}, + {"duration", node.duration}, + }; +} +void from_xml(const HXml &xml, EffectInfo &node) +{ + node.inSpeed = xml.at("effect").GetAttribute("inSpeed").ToInt(); + node.outSpeed = xml.at("effect").GetAttribute("outSpeed").ToInt(); + node.in = xml.at("effect").GetAttribute("in").ToInt(); + node.out = xml.at("effect").GetAttribute("out").ToInt(); + node.duration = xml.at("effect").GetAttribute("duration").ToInt(); +} + +void to_xml(HXml &xml, const FileInfo &node) +{ + xml["file"] = { + {"name", node.name}, + {"md5", node.md5}, + {"size", node.size}, + }; +} + +void from_xml(const HXml &xml, FileInfo &node) +{ + node.name = xml.at("file").GetAttribute("name"); + node.md5 = xml.at("file").GetAttribute("md5"); + node.size = xml.at("file").GetAttribute("size").ToInt(); +} + +void to_xml(HXml &xml, const TextInfo &node) +{ + xml = { + {"guid", node.guid}, + {"background", node.background}, + }; + xml["string"].SetText(node.text); + xml["style"] = { + {"valign", node.style.valign}, + {"align", node.style.align}, + }; + xml["font"] = { + {"name", node.font.name}, + {"color", node.font.color}, + {"italic", node.font.italic}, + {"bold", node.font.bold}, + {"underline", node.font.underline}, + {"size", node.font.size}, + }; + xml.ToXml(node.effect); +} + +void from_xml(const HXml &xml, TextInfo &node) +{ + node.guid = xml.GetAttribute("guid"); + node.background = xml.GetAttribute("background"); + node.text.Clear(); + if (xml.ContainsNodes("string")) { + node.text = xml.at("string").GetText(); + } + + node.style.valign = xml.at("style").GetAttribute("valign"); + node.style.align = xml.at("style").GetAttribute("align"); + node.font.name = xml.at("font").GetAttribute("name"); + node.font.color = xml.at("font").GetAttribute("color"); + + if (xml.at("font").ContainsAttribute("italic")) { + node.font.italic = xml.at("font").GetAttribute("italic") == "true"; + } + + if (xml.at("font").ContainsAttribute("bold")) { + node.font.bold = xml.at("font").GetAttribute("bold") == "true"; + } + + if (xml.at("font").ContainsAttribute("underline")) { + node.font.underline = xml.at("font").GetAttribute("underline") == "true"; + } + + node.font.size = xml.at("font").GetAttribute("size").ToInt(); + xml.get_to(node.effect); +} + +void to_xml(HXml &xml, const PhotoInfo &node) +{ + xml = { + {"guid",node.guid}, + {"fit", node.fit}, + }; + xml.ToXml(node.file); + xml.ToXml(node.effect); +} + +void from_xml(const HXml &xml, PhotoInfo &node) +{ + node.guid = xml.GetAttribute("guid"); + if (xml.ContainsAttribute("fit")) { + node.fit = xml.GetAttribute("fit"); + } + + xml.get_to(node.file); + xml.get_to(node.effect); +} + +void to_xml(HXml &xml, const VideoInfo &node) +{ + xml = { + {"guid", node.guid}, + {"aspectRatio", node.aspectRatio ? "true" : "false"}, + }; + xml["playParams"] = { + {"duration", node.playParams.duration}, + }; + xml.ToXml(node.file); +} + +void from_xml(const HXml &xml, VideoInfo &node) +{ + node.guid = xml.GetAttribute("guid"); + if (xml.ContainsAttribute("aspectRatio")) { + node.aspectRatio = xml.GetAttribute("aspectRatio") == "true"; + } + + xml.get_to(node.file); + if (xml.ContainsNodes("playParams")) { + node.playParams.duration = xml.at("playParams").GetAttribute("duration").ToInt(); + } +} + +void to_xml(HXml &xml, const ResourcesInfo &node) +{ + for (const auto &i : node.nodeList) { + i->ToXml(xml); + } +} + +void from_xml(const HXml &xml, ResourcesInfo &node) +{ + node.nodeList.clear(); + for (const auto &i : xml.at("resources")) { + std::shared_ptr item; + if (i.GetNodeName() == "text") { + item.reset(new TextInfo()); + } else if (i.GetNodeName() == "image") { + item.reset(new PhotoInfo()); + } else if (i.GetNodeName() == "video") { + item.reset(new VideoInfo()); + } else { + continue; + } + + item->FromXml(i); + node.nodeList.emplace_back(item); + } +} + +void to_xml(HXml &xml, const AreaNodeInfo &node) +{ + xml = { + {"guid", node.guid}, + {"alpha", node.alpha}, + }; + xml["rectangle"] = { + {"x", node.rect.x}, + {"y", node.rect.y}, + {"width", node.rect.width}, + {"height", node.rect.height}, + }; + xml["resources"].ToXml(node.resource); +} + +void from_xml(const HXml &xml, AreaNodeInfo &node) +{ + node.guid = xml.GetAttribute("guid"); + node.alpha = xml.GetAttribute("alpha").ToInt(); + node.rect.x = xml.at("rectangle").GetAttribute("x").ToInt(); + node.rect.y = xml.at("rectangle").GetAttribute("y").ToInt(); + node.rect.width = xml.at("rectangle").GetAttribute("width").ToInt(); + node.rect.height = xml.at("rectangle").GetAttribute("height").ToInt(); + xml.at("resource").get_to(node.resource); +} + +void to_xml(HXml &xml, const ProgramNodeInfo &node) +{ + xml = { + {"guid", node.guid}, + }; + for (const auto &i : node.areaList) { + xml.NewChild("area").ToXml(i); + } +} + +void from_xml(const HXml &xml, ProgramNodeInfo &node) { + node.guid = xml.at("program").GetAttribute("guid"); + for (const auto &i : xml.at("program").at("area")) { + AreaNodeInfo item; + if (i.get_to(item) == false) { + continue; + } + + node.areaList.emplace_back(std::move(item)); + } +} + +void to_xml(HXml &xml, const ScreenNodeInfo &node) { + xml["screen"] = { + {"timeStamps", node.timeStamps}, + }; + + for (const auto &i : node.programList) { + xml["screen"].NewChild("program").ToXml(i); + } +} + +void from_xml(const HXml &xml, ScreenNodeInfo &node) { + node.timeStamps = xml.at("screen").GetAttribute("timeStamps").ToInt(); + for (const auto &i : xml.at("screen").at("program")) { + ProgramNodeInfo item; + if (i.get_to(item) == false) { + continue; + } + + node.programList.emplace_back(std::move(item)); + } +} + diff --git a/SDK/Data/HProgramInfo.h b/SDK/Data/HProgramInfo.h new file mode 100644 index 0000000..caf763d --- /dev/null +++ b/SDK/Data/HProgramInfo.h @@ -0,0 +1,196 @@ + + +#ifndef HSENSORINFO_H +#define HSENSORINFO_H + +#include +#include +#include + + +class IProgramNode +{ +public: + virtual ~IProgramNode() {} + + virtual void ToXml(HXml &xml) = 0; + virtual bool FromXml(const HXml &xml) = 0; + virtual cat::HCatBuffer GetType() const = 0; +}; + +struct EffectInfo +{ + int inSpeed; ///< 播放速度 + int outSpeed; ///< 播放速度 + int in; ///< 进入特效 + int out; ///< 退出特效 + int duration; ///< 播放时长, 0.1s + + EffectInfo() : inSpeed(5), outSpeed(5), in(0), out(0), duration(50) {} +}; +void to_xml(HXml &xml, const EffectInfo &node); +void from_xml(const HXml &xml, EffectInfo &node); + +struct FileInfo { + cat::HCatBuffer name; + cat::HCatBuffer md5; + int size; + + FileInfo() : size(0) {} +}; +void to_xml(HXml &xml, const FileInfo &node); +void from_xml(const HXml &xml, FileInfo &node); + +/** + * + *