diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..78a530a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "app_protocols/transmit_disfection_protocol"] + path = app_protocols/transmit_disfection_protocol + url = zwsd@192.168.1.3:p_transmit_disinfection_v3/transmit_disfection_protocol.git +[submodule "app_protocols/zscanprotocol"] + path = app_protocols/zscanprotocol + url = zwsd@192.168.1.3:zprotocols/zscanprotocol.git diff --git a/CMakeLists.txt b/CMakeLists.txt index c0eb681..edcf3bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,9 +40,17 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") message("CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") message("PROJECT_NAME: ${PROJECT_NAME}") -file(GLOB_RECURSE APP_SRC # - src/*.cpp # - src/*.c # +file( + GLOB_RECURSE + APP_SRC # + src/*.cpp # + src/*.c # + src/*.hpp # + src/*.h # + app_protocols/*.cpp # + app_protocols/*.c # + app_protocols/*.hpp # + app_protocols/*.h # ) zadd_executable( diff --git a/app_protocols/apperrorcode/apperrorcode.hpp b/app_protocols/apperrorcode/apperrorcode.hpp new file mode 100644 index 0000000..aef5f04 --- /dev/null +++ b/app_protocols/apperrorcode/apperrorcode.hpp @@ -0,0 +1,26 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace iflytop { +using namespace std; + +typedef enum { + ksucc = 0, + + kappe_disinfectant_insufficient = 1, // 消毒液不足 + kappe_the_bottom_of_the_device_has_water = 2, // 设备底部有水 + kappe_the_evaporation_bin_has_water = 3, // 蒸发仓有水 + kappe_the_sensor_is_prehearting = 4, // 传感器正在预热 + +} apperror_t; + +} // namespace iflytop \ No newline at end of file diff --git a/app_protocols/appexception/zexception.hpp b/app_protocols/appexception/zexception.hpp new file mode 100644 index 0000000..e73cc7d --- /dev/null +++ b/app_protocols/appexception/zexception.hpp @@ -0,0 +1,45 @@ +// +// Created by zhaohe on 19-5-21. +// + +#pragma once +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace iflytop { +using namespace std; + +class app_exception : public std::exception { + public: + string description; + string whatstr; + int32_t ecode; + + app_exception(int32_t ecode, const char *fmt, ...) { + va_list args; + va_start(args, fmt); + char buffer[1024]; + vsnprintf(buffer, sizeof(buffer), fmt, args); + + this->description = buffer; + + this->description = description; + this->ecode = ecode; + + this->whatstr = buffer; + } + virtual ~app_exception() {} + const char *what() const _GLIBCXX_USE_NOEXCEPT { return whatstr.c_str(); } +}; +} // namespace iflytop \ No newline at end of file diff --git a/app_protocols/transmit_disfection_protocol b/app_protocols/transmit_disfection_protocol new file mode 160000 index 0000000..9836b9c --- /dev/null +++ b/app_protocols/transmit_disfection_protocol @@ -0,0 +1 @@ +Subproject commit 9836b9c4356e8cf635be9ab8394d75c8fb301dfe diff --git a/app_protocols/zscanprotocol b/app_protocols/zscanprotocol new file mode 160000 index 0000000..94c49f6 --- /dev/null +++ b/app_protocols/zscanprotocol @@ -0,0 +1 @@ +Subproject commit 94c49f650f508e64b9e30e733dbb161c72ae2559 diff --git a/src/app/app_components/app_errorcode_mgr.cpp b/src/app/app_components/app_errorcode_mgr.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/app/app_components/app_errorcode_mgr.hpp b/src/app/app_components/app_errorcode_mgr.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/components/simple_udp/simple_udp.cpp b/src/components/simple_udp/simple_udp.cpp new file mode 100644 index 0000000..a64ed23 --- /dev/null +++ b/src/components/simple_udp/simple_udp.cpp @@ -0,0 +1,56 @@ +#include "simple_udp.hpp" + +#include +#include +#include +using namespace std; +using namespace iflytop; +using namespace core; + +void SimpleUDP::initialize(int port) { + // 建立一个UDP的socket + m_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + + if (m_socket == -1) { + logger->error("socket failed"); + return; + } + // 绑定地址信息 + + struct sockaddr_in servaddr; + memset(&servaddr, 0, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(port); + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + + if (bind(m_socket, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { + logger->error("bind {} failed,", port); + return; + } + logger->info("bind {} success", port); + + m_thread.reset(new Thread("udpThread", [this]() { // + struct sockaddr_in peeraddr; + socklen_t peerlen; + while (true) { + memset(m_rxbuf, 0, sizeof(m_rxbuf)); + + memset(&peeraddr, 0, sizeof(sockaddr_in)); + peerlen = sizeof(sockaddr_in); + + int ret = recvfrom(m_socket, m_rxbuf, sizeof(m_rxbuf), 0, (struct sockaddr *)&peeraddr, &peerlen); + logger->debug("Recv msg {} from IP:{} Port:{}\n", m_rxbuf, inet_ntoa(peeraddr.sin_addr), ntohs(peeraddr.sin_port)); + // int wret = ::sendto(m_socket, "Hello World!", strlen("Hello World!"), 0, (sockaddr *)&peeraddr, peerlen); + // logger->debug("sendto ret:{}", wret); + // perror("sendto"); + if (ret < 0) { + logger->error("recvfrom failed, {}", strerror(errno)); + continue; + } + if (m_on_recv) { + m_on_recv(&peeraddr, m_rxbuf, ret); + } + } + })); + return; +}; \ No newline at end of file diff --git a/src/components/simple_udp/simple_udp.hpp b/src/components/simple_udp/simple_udp.hpp new file mode 100644 index 0000000..c8c9978 --- /dev/null +++ b/src/components/simple_udp/simple_udp.hpp @@ -0,0 +1,58 @@ +// +// Created by zwsd +// + +#pragma once +#include +#include +#include +#include +#include +#include +#include /* See NOTES */ +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "iflytop/core/core.hpp" +/** + * @brief + * + * service: SimpleUDP + * + * 监听事件: + * 依赖状态: + * 依赖服务: + * 作用: + * + */ + +namespace iflytop { +using namespace std; +using namespace core; +class SimpleUDP : public enable_shared_from_this { + ENABLE_LOGGER(SimpleUDP); + int m_socket = -1; + unique_ptr m_thread; + char m_rxbuf[1024]; + + typedef function on_recv_t; + + on_recv_t m_on_recv; + + public: + SimpleUDP(){}; + void initialize(int port); + void set_on_recv(on_recv_t on_recv) { m_on_recv = on_recv; } + void sendto(struct sockaddr_in* from, const char* data, size_t len) { ::sendto(m_socket, data, len, 0, (struct sockaddr*)from, sizeof(struct sockaddr_in)); } +}; +} // namespace iflytop \ No newline at end of file diff --git a/src/components/sqlite_orm/README.md b/src/components/sqlite_orm/README.md new file mode 100644 index 0000000..22e3ec7 --- /dev/null +++ b/src/components/sqlite_orm/README.md @@ -0,0 +1,2 @@ +v1.8.2 +https://github.com/fnc12/sqlite_orm diff --git a/src/components/sqlite_orm/sqlite_orm.hpp b/src/components/sqlite_orm/sqlite_orm.hpp new file mode 100644 index 0000000..18abc89 --- /dev/null +++ b/src/components/sqlite_orm/sqlite_orm.hpp @@ -0,0 +1,18253 @@ +#pragma once + +#if defined(_MSC_VER) +__pragma(push_macro("min")) +#undef min + __pragma(push_macro("max")) +#undef max +#endif // defined(_MSC_VER) +#pragma once + +// #include "cxx_universal.h" + +/* + * This header makes central C++ functionality on which sqlite_orm depends universally available: + * - alternative operator representations + * - ::size_t, ::ptrdiff_t, ::nullptr_t + * - C++ core language feature macros + * - macros for dealing with compiler quirks + */ + +#include // alternative operator representations + +#include // sqlite_orm is using size_t, ptrdiff_t, nullptr_t everywhere, pull it in early + + // earlier clang versions didn't make nullptr_t available in the global namespace via stddef.h, + // though it should have according to C++ documentation (see https://en.cppreference.com/w/cpp/types/nullptr_t#Notes). + // actually it should be available when including stddef.h + using std::nullptr_t; + +// #include "cxx_core_features.h" + +/* + * This header detects core C++ language features on which sqlite_orm depends. + * May be updated/overwritten by cxx_compiler_quirks.h + */ + +#ifdef __has_cpp_attribute +#define SQLITE_ORM_HAS_CPP_ATTRIBUTE(attr) __has_cpp_attribute(attr) +#else +#define SQLITE_ORM_HAS_CPP_ATTRIBUTE(attr) 0L +#endif + +#ifdef __has_include +#define SQLITE_ORM_HAS_INCLUDE(file) __has_include(file) +#else +#define SQLITE_ORM_HAS_INCLUDE(file) 0L +#endif + +#if __cpp_aggregate_nsdmi >= 201304L +#define SQLITE_ORM_AGGREGATE_NSDMI_SUPPORTED +#endif + +#if __cpp_constexpr >= 201304L +#define SQLITE_ORM_RELAXED_CONSTEXPR_SUPPORTED +#endif + +#if __cpp_noexcept_function_type >= 201510L +#define SQLITE_ORM_NOTHROW_ALIASES_SUPPORTED +#endif + +#if __cpp_aggregate_bases >= 201603L +#define SQLITE_ORM_AGGREGATE_BASES_SUPPORTED +#endif + +#if __cpp_fold_expressions >= 201603L +#define SQLITE_ORM_FOLD_EXPRESSIONS_SUPPORTED +#endif + +#if __cpp_inline_variables >= 201606L +#define SQLITE_ORM_INLINE_VARIABLES_SUPPORTED +#endif + +#if __cpp_if_constexpr >= 201606L +#define SQLITE_ORM_IF_CONSTEXPR_SUPPORTED +#endif + +#if __cpp_inline_variables >= 201606L +#define SQLITE_ORM_INLINE_VARIABLES_SUPPORTED +#endif + +#if __cpp_generic_lambdas >= 201707L +#define SQLITE_ORM_EXPLICIT_GENERIC_LAMBDA_SUPPORTED +#else +#endif + +#if __cpp_consteval >= 201811L +#define SQLITE_ORM_CONSTEVAL_SUPPORTED +#endif + +#if __cpp_aggregate_paren_init >= 201902L +#define SQLITE_ORM_AGGREGATE_PAREN_INIT_SUPPORTED +#endif + +#if __cpp_concepts >= 201907L +#define SQLITE_ORM_CONCEPTS_SUPPORTED +#endif + +// #include "cxx_compiler_quirks.h" + +/* + * This header defines macros for circumventing compiler quirks on which sqlite_orm depends. + * May amend cxx_core_features.h + */ + +#ifdef __clang__ +#define SQLITE_ORM_DO_PRAGMA(...) _Pragma(#__VA_ARGS__) +#endif + +#ifdef __clang__ +#define SQLITE_ORM_CLANG_SUPPRESS(warnoption, ...) \ + SQLITE_ORM_DO_PRAGMA(clang diagnostic push) \ + SQLITE_ORM_DO_PRAGMA(clang diagnostic ignored warnoption) \ + __VA_ARGS__ \ + SQLITE_ORM_DO_PRAGMA(clang diagnostic pop) + +#else +#define SQLITE_ORM_CLANG_SUPPRESS(warnoption, ...) __VA_ARGS__ +#endif + +// clang has the bad habit of diagnosing missing brace-init-lists when constructing aggregates with base classes. +// This is a false positive, since the C++ standard is quite clear that braces for nested or base objects may be omitted, +// see https://en.cppreference.com/w/cpp/language/aggregate_initialization: +// "The braces around the nested initializer lists may be elided (omitted), +// in which case as many initializer clauses as necessary are used to initialize every member or element of the corresponding subaggregate, +// and the subsequent initializer clauses are used to initialize the following members of the object." +// In this sense clang should only warn about missing field initializers. +// Because we know what we are doing, we suppress the diagnostic message +#define SQLITE_ORM_CLANG_SUPPRESS_MISSING_BRACES(...) SQLITE_ORM_CLANG_SUPPRESS("-Wmissing-braces", __VA_ARGS__) + +#if defined(_MSC_VER) && (_MSC_VER < 1920) +#define SQLITE_ORM_BROKEN_VARIADIC_PACK_EXPANSION +#endif + +// clang 10 chokes on concepts that don't depend on template parameters; +// when it tries to instantiate an expression in a requires expression, which results in an error, +// the compiler reports an error instead of dismissing the templated function. +#if defined(SQLITE_ORM_CONCEPTS_SUPPORTED) && (defined(__clang__) && (__clang_major__ == 10)) +#define SQLITE_ORM_BROKEN_NONTEMPLATE_CONCEPTS +#endif + +#ifdef SQLITE_ORM_INLINE_VARIABLES_SUPPORTED +#define SQLITE_ORM_INLINE_VAR inline +#else +#define SQLITE_ORM_INLINE_VAR +#endif + +#if SQLITE_ORM_HAS_CPP_ATTRIBUTE(no_unique_address) >= 201803L +#define SQLITE_ORM_NOUNIQUEADDRESS [[no_unique_address]] +#else +#define SQLITE_ORM_NOUNIQUEADDRESS +#endif + +#ifdef SQLITE_ORM_CONSTEVAL_SUPPORTED +#define SQLITE_ORM_CONSTEVAL consteval +#else +#define SQLITE_ORM_CONSTEVAL constexpr +#endif +#pragma once + +#include // std::enable_if, std::is_same + +// #include "functional/cxx_type_traits_polyfill.h" + +#include + +// #include "cxx_universal.h" + +namespace sqlite_orm { +namespace internal { +namespace polyfill { +#if __cpp_lib_void_t >= 201411L +using std::void_t; +#else +template +using void_t = void; +#endif + +#if __cpp_lib_bool_constant >= 201505L +using std::bool_constant; +#else +template +using bool_constant = std::integral_constant; +#endif + +#if __cpp_lib_logical_traits >= 201510L && __cpp_lib_type_trait_variable_templates >= 201510L +using std::conjunction; +using std::conjunction_v; +using std::disjunction; +using std::disjunction_v; +using std::negation; +using std::negation_v; +#else +template +struct conjunction : std::true_type {}; +template +struct conjunction : B1 {}; +template +struct conjunction : std::conditional_t, B1> {}; +template +SQLITE_ORM_INLINE_VAR constexpr bool conjunction_v = conjunction::value; + +template +struct disjunction : std::false_type {}; +template +struct disjunction : B1 {}; +template +struct disjunction : std::conditional_t> {}; +template +SQLITE_ORM_INLINE_VAR constexpr bool disjunction_v = disjunction::value; + +template +struct negation : bool_constant {}; +template +SQLITE_ORM_INLINE_VAR constexpr bool negation_v = negation::value; +#endif + +#if __cpp_lib_remove_cvref >= 201711L +using std::remove_cvref, std::remove_cvref_t; +#else +template +struct remove_cvref : std::remove_cv> {}; + +template +using remove_cvref_t = typename remove_cvref::type; +#endif + +#if __cpp_lib_type_identity >= 201806L +using std::type_identity, std::type_identity_t; +#else +template +struct type_identity { + using type = T; +}; + +template +using type_identity_t = typename type_identity::type; +#endif + +#if 0 // __cpp_lib_detect >= 0L // library fundamentals TS v2, [meta.detect] + using std::nonesuch; + using std::detector; + using std::is_detected, std::is_detected_v; + using std::detected, std::detected_t; + using std::detected_or, std::detected_or_t; +#else +struct nonesuch { + ~nonesuch() = delete; + nonesuch(const nonesuch&) = delete; + void operator=(const nonesuch&) = delete; +}; + +template class Op, class... Args> +struct detector { + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> { + using value_t = std::true_type; + using type = Op; +}; + +template