From bad3a4eb676832a1bddfc3cee7064ef44f7ce15c Mon Sep 17 00:00:00 2001 From: Yaroslav Svitlytskyi Date: Mon, 8 Apr 2024 01:08:43 +0200 Subject: [PATCH] fix: fixed bugs --- .../Proto/Generated/Content/settings.h | 312 ++++++++++++++---- Core/External/Proto/Helper/proto_helper.cpp | 52 ++- Core/External/Proto/Helper/proto_helper.h | 90 +++++ .../Scheduler/Handler/scheduler_handler.cpp | 50 ++- Core/External/Tools/Indicator/indicator.cpp | 16 - Core/External/Tools/Indicator/indicator.h | 10 - .../Proto/Container/Content/settings.proto | 20 +- Scripts/cli/src/proto/Content/settings_pb2.py | 18 +- .../cli/src/proto/Content/settings_pb2.pyi | 40 ++- 9 files changed, 485 insertions(+), 123 deletions(-) diff --git a/Core/External/Proto/Generated/Content/settings.h b/Core/External/Proto/Generated/Content/settings.h index 15f054f..ce9fa87 100644 --- a/Core/External/Proto/Generated/Content/settings.h +++ b/Core/External/Proto/Generated/Content/settings.h @@ -31,6 +31,26 @@ enum class SettingsType : uint32_t SetIntegralTime = 3 }; +enum class SetGrainSettingType : uint32_t +{ + SetGrainSettingNone = 0, + Low = 1, + Medium = 2, + High = 3, + Max = 4 +}; + +enum class SetIntegralTimeSettingType : uint32_t +{ + SetIntegralTimeSettingNone = 0, + First = 1, + Second = 2, + Third = 3, + Forth = 4, + Fifth = 5, + Sixth = 6 +}; + class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface { public: @@ -38,13 +58,24 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface SettingsBusRequestContent(const SettingsBusRequestContent& rhs ) { set_settingsType(rhs.get_settingsType()); - if(rhs.has_value()) + if(rhs.get_which_value() != which_value_) { - set_value(rhs.get_value()); + // First delete the old object in the oneof. + clear_value(); } - else + + switch(rhs.get_which_value()) { - clear_value(); + case FieldNumber::SETGAINVALUE: + set_setGainValue(rhs.get_setGainValue()); + break; + + case FieldNumber::SETINTEGRALTIMEVALUE: + set_setIntegralTimeValue(rhs.get_setIntegralTimeValue()); + break; + + default: + break; } } @@ -52,13 +83,24 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface SettingsBusRequestContent(const SettingsBusRequestContent&& rhs ) noexcept { set_settingsType(rhs.get_settingsType()); - if(rhs.has_value()) + if(rhs.get_which_value() != which_value_) { - set_value(rhs.get_value()); + // First delete the old object in the oneof. + clear_value(); } - else + + switch(rhs.get_which_value()) { - clear_value(); + case FieldNumber::SETGAINVALUE: + set_setGainValue(rhs.get_setGainValue()); + break; + + case FieldNumber::SETINTEGRALTIMEVALUE: + set_setIntegralTimeValue(rhs.get_setIntegralTimeValue()); + break; + + default: + break; } } @@ -69,19 +111,31 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface { NOT_SET = 0, SETTINGSTYPE = 1, - VALUE = 2 + SETGAINVALUE = 2, + SETINTEGRALTIMEVALUE = 3 }; SettingsBusRequestContent& operator=(const SettingsBusRequestContent& rhs) { set_settingsType(rhs.get_settingsType()); - if(rhs.has_value()) + if(rhs.get_which_value() != which_value_) { - set_value(rhs.get_value()); + // First delete the old object in the oneof. + clear_value(); } - else + + switch(rhs.get_which_value()) { - clear_value(); + case FieldNumber::SETGAINVALUE: + set_setGainValue(rhs.get_setGainValue()); + break; + + case FieldNumber::SETINTEGRALTIMEVALUE: + set_setIntegralTimeValue(rhs.get_setIntegralTimeValue()); + break; + + default: + break; } return *this; @@ -90,15 +144,26 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface SettingsBusRequestContent& operator=(const SettingsBusRequestContent&& rhs) noexcept { set_settingsType(rhs.get_settingsType()); - if(rhs.has_value()) + if(rhs.get_which_value() != which_value_) { - set_value(rhs.get_value()); + // First delete the old object in the oneof. + clear_value(); } - else + + switch(rhs.get_which_value()) { - clear_value(); + case FieldNumber::SETGAINVALUE: + set_setGainValue(rhs.get_setGainValue()); + break; + + case FieldNumber::SETINTEGRALTIMEVALUE: + set_setIntegralTimeValue(rhs.get_setIntegralTimeValue()); + break; + + default: + break; } - + return *this; } @@ -109,33 +174,71 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface inline const SettingsType& get_settingsType() const { return settingsType_.get(); } inline SettingsType settingsType() const { return settingsType_.get(); } - static constexpr char const* VALUE_NAME = "value"; - inline bool has_value() const + FieldNumber get_which_value() const { return which_value_; } + + static constexpr char const* SETGAINVALUE_NAME = "setGainValue"; + inline bool has_setGainValue() const + { + return FieldNumber::SETGAINVALUE == which_value_; + } + inline void clear_setGainValue() + { + if(FieldNumber::SETGAINVALUE == which_value_) + { + which_value_ = FieldNumber::NOT_SET; + value_.setGainValue_.clear(); + } + } + inline void set_setGainValue(const SetGrainSettingType& value) + { + if(FieldNumber::SETGAINVALUE != which_value_) + { + init_value(FieldNumber::SETGAINVALUE); + } + value_.setGainValue_ = value; + } + inline void set_setGainValue(const SetGrainSettingType&& value) { - return 0 != (presence::mask(presence::fields::VALUE) & presence_[presence::index(presence::fields::VALUE)]); + if(FieldNumber::SETGAINVALUE != which_value_) + { + init_value(FieldNumber::SETGAINVALUE); + } + value_.setGainValue_ = value; } - inline void clear_value() + inline const SetGrainSettingType& get_setGainValue() const { return value_.setGainValue_.get(); } + inline SetGrainSettingType setGainValue() const { return value_.setGainValue_.get(); } + + static constexpr char const* SETINTEGRALTIMEVALUE_NAME = "setIntegralTimeValue"; + inline bool has_setIntegralTimeValue() const { - presence_[presence::index(presence::fields::VALUE)] &= ~(presence::mask(presence::fields::VALUE)); - value_.clear(); + return FieldNumber::SETINTEGRALTIMEVALUE == which_value_; } - inline void set_value(const int32_t& value) + inline void clear_setIntegralTimeValue() { - presence_[presence::index(presence::fields::VALUE)] |= presence::mask(presence::fields::VALUE); - value_ = value; + if(FieldNumber::SETINTEGRALTIMEVALUE == which_value_) + { + which_value_ = FieldNumber::NOT_SET; + value_.setIntegralTimeValue_.clear(); + } } - inline void set_value(const int32_t&& value) + inline void set_setIntegralTimeValue(const SetIntegralTimeSettingType& value) { - presence_[presence::index(presence::fields::VALUE)] |= presence::mask(presence::fields::VALUE); - value_ = value; + if(FieldNumber::SETINTEGRALTIMEVALUE != which_value_) + { + init_value(FieldNumber::SETINTEGRALTIMEVALUE); + } + value_.setIntegralTimeValue_ = value; } - inline int32_t& mutable_value() + inline void set_setIntegralTimeValue(const SetIntegralTimeSettingType&& value) { - presence_[presence::index(presence::fields::VALUE)] |= presence::mask(presence::fields::VALUE); - return value_.get(); + if(FieldNumber::SETINTEGRALTIMEVALUE != which_value_) + { + init_value(FieldNumber::SETINTEGRALTIMEVALUE); + } + value_.setIntegralTimeValue_ = value; } - inline const int32_t& get_value() const { return value_.get(); } - inline int32_t value() const { return value_.get(); } + inline const SetIntegralTimeSettingType& get_setIntegralTimeValue() const { return value_.setIntegralTimeValue_.get(); } + inline SetIntegralTimeSettingType setIntegralTimeValue() const { return value_.setIntegralTimeValue_.get(); } ::EmbeddedProto::Error serialize(::EmbeddedProto::WriteBufferInterface& buffer) const override @@ -147,9 +250,24 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface return_value = settingsType_.serialize_with_id(static_cast(FieldNumber::SETTINGSTYPE), buffer, false); } - if(has_value() && (::EmbeddedProto::Error::NO_ERRORS == return_value)) + switch(which_value_) { - return_value = value_.serialize_with_id(static_cast(FieldNumber::VALUE), buffer, true); + case FieldNumber::SETGAINVALUE: + if(has_setGainValue() && (::EmbeddedProto::Error::NO_ERRORS == return_value)) + { + return_value = value_.setGainValue_.serialize_with_id(static_cast(FieldNumber::SETGAINVALUE), buffer, true); + } + break; + + case FieldNumber::SETINTEGRALTIMEVALUE: + if(has_setIntegralTimeValue() && (::EmbeddedProto::Error::NO_ERRORS == return_value)) + { + return_value = value_.setIntegralTimeValue_.serialize_with_id(static_cast(FieldNumber::SETINTEGRALTIMEVALUE), buffer, true); + } + break; + + default: + break; } return return_value; @@ -172,9 +290,9 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface return_value = settingsType_.deserialize_check_type(buffer, wire_type); break; - case FieldNumber::VALUE: - presence_[presence::index(presence::fields::VALUE)] |= presence::mask(presence::fields::VALUE); - return_value = value_.deserialize_check_type(buffer, wire_type); + case FieldNumber::SETGAINVALUE: + case FieldNumber::SETINTEGRALTIMEVALUE: + return_value = deserialize_value(id_tag, buffer, wire_type); break; case FieldNumber::NOT_SET: @@ -219,8 +337,11 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface case FieldNumber::SETTINGSTYPE: name = SETTINGSTYPE_NAME; break; - case FieldNumber::VALUE: - name = VALUE_NAME; + case FieldNumber::SETGAINVALUE: + name = SETGAINVALUE_NAME; + break; + case FieldNumber::SETINTEGRALTIMEVALUE: + name = SETINTEGRALTIMEVALUE_NAME; break; default: name = "Invalid FieldNumber"; @@ -283,7 +404,7 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface } left_chars = settingsType_.to_string(left_chars, indent_level + 2, SETTINGSTYPE_NAME, true); - left_chars = value_.to_string(left_chars, indent_level + 2, VALUE_NAME, false); + left_chars = to_string_value(left_chars, indent_level + 2, false); if( 0 == indent_level) { @@ -307,44 +428,97 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface private: - // Define constants for tracking the presence of fields. - // Use a struct to scope the variables from user fields as namespaces are not allowed within classes. - struct presence + + EmbeddedProto::enumeration settingsType_ = static_cast(0); + + FieldNumber which_value_ = FieldNumber::NOT_SET; + union value { - // An enumeration with all the fields for which presence has to be tracked. - enum class fields : uint32_t - { - VALUE - }; + value() {} + ~value() {} + EmbeddedProto::enumeration setGainValue_; + EmbeddedProto::enumeration setIntegralTimeValue_; + }; + value value_; - // The number of fields for which presence has to be tracked. - static constexpr uint32_t N_FIELDS = 1; + void init_value(const FieldNumber field_id) + { + if(FieldNumber::NOT_SET != which_value_) + { + // First delete the old object in the oneof. + clear_value(); + } - // Which type are we using to track presence. - using TYPE = uint32_t; + which_value_ = field_id; + } - // How many bits are there in the presence type. - static constexpr uint32_t N_BITS = std::numeric_limits::digits; + void clear_value() + { + switch(which_value_) + { + case FieldNumber::SETGAINVALUE: + value_.setGainValue_ = static_cast(0); + break; + case FieldNumber::SETINTEGRALTIMEVALUE: + value_.setIntegralTimeValue_ = static_cast(0); + break; + default: + break; + } + which_value_ = FieldNumber::NOT_SET; + } - // How many variables of TYPE do we need to bit mask all presence fields. - static constexpr uint32_t SIZE = (N_FIELDS / N_BITS) + ((N_FIELDS % N_BITS) > 0 ? 1 : 0); + ::EmbeddedProto::Error deserialize_value(const FieldNumber field_id, + ::EmbeddedProto::ReadBufferInterface& buffer, + const ::EmbeddedProto::WireFormatter::WireType wire_type) + { + ::EmbeddedProto::Error return_value = ::EmbeddedProto::Error::NO_ERRORS; + + if(field_id != which_value_) + { + init_value(field_id); + } - // Obtain the index of a given field in the presence array. - static constexpr uint32_t index(const fields& field) { return static_cast(field) / N_BITS; } + switch(which_value_) + { + case FieldNumber::SETGAINVALUE: + return_value = value_.setGainValue_.deserialize_check_type(buffer, wire_type); + break; + case FieldNumber::SETINTEGRALTIMEVALUE: + return_value = value_.setIntegralTimeValue_.deserialize_check_type(buffer, wire_type); + break; + default: + break; + } - // Obtain the bit mask for the given field assuming we are at the correct index in the presence array. - static constexpr TYPE mask(const fields& field) + if(::EmbeddedProto::Error::NO_ERRORS != return_value) { - return static_cast(0x01) << (static_cast(field) % N_BITS); + clear_value(); } - }; + return return_value; + } - // Create an array in which the presence flags are stored. - typename presence::TYPE presence_[presence::SIZE] = {0}; +#ifdef MSG_TO_STRING + ::EmbeddedProto::string_view to_string_value(::EmbeddedProto::string_view& str, const uint32_t indent_level, const bool first_field) const + { + ::EmbeddedProto::string_view left_chars = str; - EmbeddedProto::enumeration settingsType_ = static_cast(0); - EmbeddedProto::int32 value_ = 0; + switch(which_value_) + { + case FieldNumber::SETGAINVALUE: + left_chars = value_.setGainValue_.to_string(left_chars, indent_level, SETGAINVALUE_NAME, first_field); + break; + case FieldNumber::SETINTEGRALTIMEVALUE: + left_chars = value_.setIntegralTimeValue_.to_string(left_chars, indent_level, SETINTEGRALTIMEVALUE_NAME, first_field); + break; + default: + break; + } + return left_chars; + } + +#endif // End of MSG_TO_STRING }; class SettingsBusResponseContent final: public ::EmbeddedProto::MessageInterface diff --git a/Core/External/Proto/Helper/proto_helper.cpp b/Core/External/Proto/Helper/proto_helper.cpp index 000755c..b8ef510 100644 --- a/Core/External/Proto/Helper/proto_helper.cpp +++ b/Core/External/Proto/Helper/proto_helper.cpp @@ -75,7 +75,57 @@ bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type( return content.settingsType() == light_detector::SettingsType::SetGain; } +bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_low_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setGainValue() == light_detector::SetGrainSettingType::Low; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_medium_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setGainValue() == light_detector::SetGrainSettingType::Medium; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_high_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setGainValue() == light_detector::SetGrainSettingType::High; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_max_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setGainValue() == light_detector::SetGrainSettingType::Max; +} + bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type( const light_detector::SettingsBusRequestContent &content) { return content.settingsType() == light_detector::SettingsType::SetIntegralTime; -} \ No newline at end of file +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_first_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::First; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_second_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Second; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_third_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Third; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_forth_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Forth; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_fifth_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Fifth; +} + +bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_sixth_type( + const light_detector::SettingsBusRequestContent &content) { + return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Sixth; +} diff --git a/Core/External/Proto/Helper/proto_helper.h b/Core/External/Proto/Helper/proto_helper.h index d0605c1..c8fb74b 100644 --- a/Core/External/Proto/Helper/proto_helper.h +++ b/Core/External/Proto/Helper/proto_helper.h @@ -148,6 +148,42 @@ class ProtoHelper { static bool is_settings_bus_request_content_of_set_gain_settings_type( const light_detector::SettingsBusRequestContent &content); + /** + * Checks if the given settings bus request content of set gain settings type of low type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_gain_settings_type_of_low_type( + const light_detector::SettingsBusRequestContent &content); + + /** + * Checks if the given settings bus request content of set gain settings type of medium type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_gain_settings_type_of_medium_type( + const light_detector::SettingsBusRequestContent &content); + + /** + * Checks if the given settings bus request content of set gain settings type of high type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_gain_settings_type_of_high_type( + const light_detector::SettingsBusRequestContent &content); + + /** + * Checks if the given settings bus request content of set gain settings type of max type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_gain_settings_type_of_max_type( + const light_detector::SettingsBusRequestContent &content); + /** * Checks if the given settings bus request content of set integral time settings type. * @@ -156,6 +192,60 @@ class ProtoHelper { */ static bool is_settings_bus_request_content_of_set_integral_time_settings_type( const light_detector::SettingsBusRequestContent &content); + + /** + * Checks if the given settings bus request content set integral time of settings type of first type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_first_type( + const light_detector::SettingsBusRequestContent &content); + + /** + * Checks if the given settings bus request content set integral time of settings type of second type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_second_type( + const light_detector::SettingsBusRequestContent &content); + + /** + * Checks if the given settings bus request content set integral time of settings type of third type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_third_type( + const light_detector::SettingsBusRequestContent &content); + + /** + * Checks if the given settings bus request content set integral time of settings type of forth type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_forth_type( + const light_detector::SettingsBusRequestContent &content); + + /** + * Checks if the given settings bus request content set integral time of settings type of fifth type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_fifth_type( + const light_detector::SettingsBusRequestContent &content); + + /** + * Checks if the given settings bus request content set integral time of settings type of sixth type. + * + * @param content - given settings bus request content. + * @return result of the check. + */ + static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_sixth_type( + const light_detector::SettingsBusRequestContent &content); }; #endif //LIGHT_DETECTOR_PROTO_HELPER_H diff --git a/Core/External/Scheduler/Handler/scheduler_handler.cpp b/Core/External/Scheduler/Handler/scheduler_handler.cpp index 7949ecf..91a3e0b 100644 --- a/Core/External/Scheduler/Handler/scheduler_handler.cpp +++ b/Core/External/Scheduler/Handler/scheduler_handler.cpp @@ -340,18 +340,26 @@ int SchedulerHandler::process_settings_bus_request_content_response( if (ProtoHelper::is_settings_bus_request_content_of_reset_settings_type( settings_bus_request_content)) { - return SchedulerHandler::process_settings_bus_request_content_of_reset_settings_type_response(); + if (SchedulerHandler::process_settings_bus_request_content_of_reset_settings_type_response() != EXIT_SUCCESS) { + return EXIT_FAILURE; + } } else if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type( settings_bus_request_content)) { - return SchedulerHandler::process_settings_bus_request_content_of_set_gain_settings_type_response(content); + if (SchedulerHandler::process_settings_bus_request_content_of_set_gain_settings_type_response(content) != EXIT_SUCCESS) { + return EXIT_FAILURE; + } } else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type( settings_bus_request_content)) { - return SchedulerHandler::process_settings_bus_request_content_of_set_integral_time_settings_type_response( - content); + if (SchedulerHandler::process_settings_bus_request_content_of_set_integral_time_settings_type_response( + content) != EXIT_SUCCESS) { + return EXIT_FAILURE; + } } + Indicator::toggle_action_success(); + return EXIT_SUCCESS; } @@ -392,7 +400,19 @@ int SchedulerHandler::process_settings_bus_request_content_of_set_gain_settings_ if (TSL2591X::is_available()) { settings_bus_response_content.set_deviceId(TSL2591X::get_device_id()); - TSL2591X::set_gain(content.get_settingsBus().get_value()); + if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_low_type( + content.settingsBus())) { + TSL2591X::set_gain(LOW_AGAIN); + } else if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_medium_type( + content.settingsBus())) { + TSL2591X::set_gain(MEDIUM_AGAIN); + } else if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_high_type( + content.settingsBus())) { + TSL2591X::set_gain(HIGH_AGAIN); + } else if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_max_type( + content.settingsBus())) { + TSL2591X::set_gain(MAX_AGAIN); + } settings_bus_response_content.set_result(true); } else { @@ -419,7 +439,25 @@ int SchedulerHandler::process_settings_bus_request_content_of_set_integral_time_ if (TSL2591X::is_available()) { settings_bus_response_content.set_deviceId(TSL2591X::get_device_id()); - TSL2591X::set_integral_time(content.get_settingsBus().get_value()); + if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_first_type( + content.settingsBus())) { + TSL2591X::set_integral_time(ATIME_100MS); + } else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_second_type( + content.settingsBus())) { + TSL2591X::set_integral_time(ATIME_200MS); + } else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_third_type( + content.settingsBus())) { + TSL2591X::set_integral_time(ATIME_300MS); + } else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_forth_type( + content.settingsBus())) { + TSL2591X::set_integral_time(ATIME_400MS); + } else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_fifth_type( + content.settingsBus())) { + TSL2591X::set_integral_time(ATIME_500MS); + } else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_sixth_type( + content.settingsBus())) { + TSL2591X::set_integral_time(ATIME_600MS); + } settings_bus_response_content.set_result(true); } else { diff --git a/Core/External/Tools/Indicator/indicator.cpp b/Core/External/Tools/Indicator/indicator.cpp index 1749287..36a4fa1 100644 --- a/Core/External/Tools/Indicator/indicator.cpp +++ b/Core/External/Tools/Indicator/indicator.cpp @@ -27,15 +27,6 @@ void Indicator::toggle_action_success() { HAL_Delay(2000); }; -void Indicator::toggle_action_failure() { - for (int i = 0; i < 4; i++) { - HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); - HAL_Delay(200); - } - - HAL_Delay(1000); -}; - void Indicator::toggle_invalid_request() { for (int i = 0; i < 2; i++) { HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); @@ -53,10 +44,3 @@ void Indicator::toggle_invalid_response() { HAL_Delay(2000); } - -void Indicator::toggle_n(uint8_t n) { - for (int i = 0; i < n; i++) { - HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); - HAL_Delay(200); - } -} diff --git a/Core/External/Tools/Indicator/indicator.h b/Core/External/Tools/Indicator/indicator.h index e964be6..2a6c9bc 100644 --- a/Core/External/Tools/Indicator/indicator.h +++ b/Core/External/Tools/Indicator/indicator.h @@ -13,11 +13,6 @@ class Indicator { */ static void toggle_initialization_success(); - /** - * Indicated initialization process success. - */ - static void toggle_n(uint8_t n); - /** * Indicated initialization process failure. */ @@ -28,11 +23,6 @@ class Indicator { */ static void toggle_action_success(); - /** - * Indicated operation action failure. - */ - static void toggle_action_failure(); - /** * Indicated invalid incoming request. */ diff --git a/Resources/Proto/Container/Content/settings.proto b/Resources/Proto/Container/Content/settings.proto index 4f3cefe..80cae14 100644 --- a/Resources/Proto/Container/Content/settings.proto +++ b/Resources/Proto/Container/Content/settings.proto @@ -15,21 +15,21 @@ enum SettingsType { // Represents all the available set grain value presets, which can be used with settings bus. enum SetGrainSettingType { SetGrainSettingNone = 0; // Stub enum to handle serialization. - LOW = 1; - MEDIUM = 2; - HIGH = 3; - MAX = 4; + Low = 1; + Medium = 2; + High = 3; + Max = 4; } // Represents all the available set integral time value presets, which can be used with settings bus. enum SetIntegralTimeSettingType { SetIntegralTimeSettingNone = 0; // Stub enum to handle serialization. - 100MS = 1; - 200MS = 2; - 300MS = 3; - 400MS = 4; - 500MS = 5; - 600MS = 6; + First = 1; + Second = 2; + Third = 3; + Forth = 4; + Fifth = 5; + Sixth = 6; } // Represents settings bus request content send from the client to the board. diff --git a/Scripts/cli/src/proto/Content/settings_pb2.py b/Scripts/cli/src/proto/Content/settings_pb2.py index 640766e..da0e49b 100644 --- a/Scripts/cli/src/proto/Content/settings_pb2.py +++ b/Scripts/cli/src/proto/Content/settings_pb2.py @@ -14,17 +14,21 @@ -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x16\x43ontent/settings.proto\x12\x0elight_detector\"m\n\x19SettingsBusRequestContent\x12\x32\n\x0csettingsType\x18\x01 \x01(\x0e\x32\x1c.light_detector.SettingsType\x12\x12\n\x05value\x18\x02 \x01(\x05H\x00\x88\x01\x01\x42\x08\n\x06_value\"\x81\x01\n\x1aSettingsBusResponseContent\x12\x10\n\x08\x64\x65viceId\x18\x01 \x01(\r\x12\x32\n\x0csettingsType\x18\x02 \x01(\x0e\x32\x1c.light_detector.SettingsType\x12\x0e\n\x06result\x18\x03 \x01(\x08\x12\r\n\x05nonce\x18\x04 \x01(\r*M\n\x0cSettingsType\x12\x10\n\x0cSettingsNone\x10\x00\x12\t\n\x05Reset\x10\x01\x12\x0b\n\x07SetGain\x10\x02\x12\x13\n\x0fSetIntegralTime\x10\x03\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x16\x43ontent/settings.proto\x12\x0elight_detector\"\xe1\x01\n\x19SettingsBusRequestContent\x12\x32\n\x0csettingsType\x18\x01 \x01(\x0e\x32\x1c.light_detector.SettingsType\x12;\n\x0csetGainValue\x18\x02 \x01(\x0e\x32#.light_detector.SetGrainSettingTypeH\x00\x12J\n\x14setIntegralTimeValue\x18\x03 \x01(\x0e\x32*.light_detector.SetIntegralTimeSettingTypeH\x00\x42\x07\n\x05value\"\x81\x01\n\x1aSettingsBusResponseContent\x12\x10\n\x08\x64\x65viceId\x18\x01 \x01(\r\x12\x32\n\x0csettingsType\x18\x02 \x01(\x0e\x32\x1c.light_detector.SettingsType\x12\x0e\n\x06result\x18\x03 \x01(\x08\x12\r\n\x05nonce\x18\x04 \x01(\r*M\n\x0cSettingsType\x12\x10\n\x0cSettingsNone\x10\x00\x12\t\n\x05Reset\x10\x01\x12\x0b\n\x07SetGain\x10\x02\x12\x13\n\x0fSetIntegralTime\x10\x03*V\n\x13SetGrainSettingType\x12\x17\n\x13SetGrainSettingNone\x10\x00\x12\x07\n\x03Low\x10\x01\x12\n\n\x06Medium\x10\x02\x12\x08\n\x04High\x10\x03\x12\x07\n\x03Max\x10\x04*\x7f\n\x1aSetIntegralTimeSettingType\x12\x1e\n\x1aSetIntegralTimeSettingNone\x10\x00\x12\t\n\x05\x46irst\x10\x01\x12\n\n\x06Second\x10\x02\x12\t\n\x05Third\x10\x03\x12\t\n\x05\x46orth\x10\x04\x12\t\n\x05\x46ifth\x10\x05\x12\t\n\x05Sixth\x10\x06\x62\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'Content.settings_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None - _globals['_SETTINGSTYPE']._serialized_start=285 - _globals['_SETTINGSTYPE']._serialized_end=362 - _globals['_SETTINGSBUSREQUESTCONTENT']._serialized_start=42 - _globals['_SETTINGSBUSREQUESTCONTENT']._serialized_end=151 - _globals['_SETTINGSBUSRESPONSECONTENT']._serialized_start=154 - _globals['_SETTINGSBUSRESPONSECONTENT']._serialized_end=283 + _globals['_SETTINGSTYPE']._serialized_start=402 + _globals['_SETTINGSTYPE']._serialized_end=479 + _globals['_SETGRAINSETTINGTYPE']._serialized_start=481 + _globals['_SETGRAINSETTINGTYPE']._serialized_end=567 + _globals['_SETINTEGRALTIMESETTINGTYPE']._serialized_start=569 + _globals['_SETINTEGRALTIMESETTINGTYPE']._serialized_end=696 + _globals['_SETTINGSBUSREQUESTCONTENT']._serialized_start=43 + _globals['_SETTINGSBUSREQUESTCONTENT']._serialized_end=268 + _globals['_SETTINGSBUSRESPONSECONTENT']._serialized_start=271 + _globals['_SETTINGSBUSRESPONSECONTENT']._serialized_end=400 # @@protoc_insertion_point(module_scope) diff --git a/Scripts/cli/src/proto/Content/settings_pb2.pyi b/Scripts/cli/src/proto/Content/settings_pb2.pyi index 255395c..9132f4d 100644 --- a/Scripts/cli/src/proto/Content/settings_pb2.pyi +++ b/Scripts/cli/src/proto/Content/settings_pb2.pyi @@ -11,18 +11,50 @@ class SettingsType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): Reset: _ClassVar[SettingsType] SetGain: _ClassVar[SettingsType] SetIntegralTime: _ClassVar[SettingsType] + +class SetGrainSettingType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): + __slots__ = () + SetGrainSettingNone: _ClassVar[SetGrainSettingType] + Low: _ClassVar[SetGrainSettingType] + Medium: _ClassVar[SetGrainSettingType] + High: _ClassVar[SetGrainSettingType] + Max: _ClassVar[SetGrainSettingType] + +class SetIntegralTimeSettingType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper): + __slots__ = () + SetIntegralTimeSettingNone: _ClassVar[SetIntegralTimeSettingType] + First: _ClassVar[SetIntegralTimeSettingType] + Second: _ClassVar[SetIntegralTimeSettingType] + Third: _ClassVar[SetIntegralTimeSettingType] + Forth: _ClassVar[SetIntegralTimeSettingType] + Fifth: _ClassVar[SetIntegralTimeSettingType] + Sixth: _ClassVar[SetIntegralTimeSettingType] SettingsNone: SettingsType Reset: SettingsType SetGain: SettingsType SetIntegralTime: SettingsType +SetGrainSettingNone: SetGrainSettingType +Low: SetGrainSettingType +Medium: SetGrainSettingType +High: SetGrainSettingType +Max: SetGrainSettingType +SetIntegralTimeSettingNone: SetIntegralTimeSettingType +First: SetIntegralTimeSettingType +Second: SetIntegralTimeSettingType +Third: SetIntegralTimeSettingType +Forth: SetIntegralTimeSettingType +Fifth: SetIntegralTimeSettingType +Sixth: SetIntegralTimeSettingType class SettingsBusRequestContent(_message.Message): - __slots__ = ("settingsType", "value") + __slots__ = ("settingsType", "setGainValue", "setIntegralTimeValue") SETTINGSTYPE_FIELD_NUMBER: _ClassVar[int] - VALUE_FIELD_NUMBER: _ClassVar[int] + SETGAINVALUE_FIELD_NUMBER: _ClassVar[int] + SETINTEGRALTIMEVALUE_FIELD_NUMBER: _ClassVar[int] settingsType: SettingsType - value: int - def __init__(self, settingsType: _Optional[_Union[SettingsType, str]] = ..., value: _Optional[int] = ...) -> None: ... + setGainValue: SetGrainSettingType + setIntegralTimeValue: SetIntegralTimeSettingType + def __init__(self, settingsType: _Optional[_Union[SettingsType, str]] = ..., setGainValue: _Optional[_Union[SetGrainSettingType, str]] = ..., setIntegralTimeValue: _Optional[_Union[SetIntegralTimeSettingType, str]] = ...) -> None: ... class SettingsBusResponseContent(_message.Message): __slots__ = ("deviceId", "settingsType", "result", "nonce")