Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Apr 1, 2024
1 parent 428490f commit 874c39d
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Core/External/Proto/Generated/Content/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace light_detector {

enum class InfoType : uint32_t
{
GetGain = 0,
GetIntegralTime = 1
Gain = 0,
IntegralTime = 1
};

class InfoBusRequestContent final: public ::EmbeddedProto::MessageInterface
Expand Down
117 changes: 116 additions & 1 deletion Core/External/Proto/Generated/Content/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,67 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface
SettingsBusRequestContent(const SettingsBusRequestContent& rhs )
{
set_settingsType(rhs.get_settingsType());
if(rhs.has_value())
{
set_value(rhs.get_value());
}
else
{
clear_value();
}

}

SettingsBusRequestContent(const SettingsBusRequestContent&& rhs ) noexcept
{
set_settingsType(rhs.get_settingsType());
if(rhs.has_value())
{
set_value(rhs.get_value());
}
else
{
clear_value();
}

}

~SettingsBusRequestContent() override = default;

enum class FieldNumber : uint32_t
{
NOT_SET = 0,
SETTINGSTYPE = 1
SETTINGSTYPE = 1,
VALUE = 2
};

SettingsBusRequestContent& operator=(const SettingsBusRequestContent& rhs)
{
set_settingsType(rhs.get_settingsType());
if(rhs.has_value())
{
set_value(rhs.get_value());
}
else
{
clear_value();
}

return *this;
}

SettingsBusRequestContent& operator=(const SettingsBusRequestContent&& rhs) noexcept
{
set_settingsType(rhs.get_settingsType());
if(rhs.has_value())
{
set_value(rhs.get_value());
}
else
{
clear_value();
}

return *this;
}

Expand All @@ -73,6 +110,34 @@ 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
{
return 0 != (presence::mask(presence::fields::VALUE) & presence_[presence::index(presence::fields::VALUE)]);
}
inline void clear_value()
{
presence_[presence::index(presence::fields::VALUE)] &= ~(presence::mask(presence::fields::VALUE));
value_.clear();
}
inline void set_value(const int32_t& value)
{
presence_[presence::index(presence::fields::VALUE)] |= presence::mask(presence::fields::VALUE);
value_ = value;
}
inline void set_value(const int32_t&& value)
{
presence_[presence::index(presence::fields::VALUE)] |= presence::mask(presence::fields::VALUE);
value_ = value;
}
inline int32_t& mutable_value()
{
presence_[presence::index(presence::fields::VALUE)] |= presence::mask(presence::fields::VALUE);
return value_.get();
}
inline const int32_t& get_value() const { return value_.get(); }
inline int32_t value() const { return value_.get(); }


::EmbeddedProto::Error serialize(::EmbeddedProto::WriteBufferInterface& buffer) const override
{
Expand All @@ -83,6 +148,11 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface
return_value = settingsType_.serialize_with_id(static_cast<uint32_t>(FieldNumber::SETTINGSTYPE), buffer, false);
}

if(has_value() && (::EmbeddedProto::Error::NO_ERRORS == return_value))
{
return_value = value_.serialize_with_id(static_cast<uint32_t>(FieldNumber::VALUE), buffer, true);
}

return return_value;
};

Expand All @@ -103,6 +173,11 @@ 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);
break;

case FieldNumber::NOT_SET:
return_value = ::EmbeddedProto::Error::INVALID_FIELD_ID;
break;
Expand Down Expand Up @@ -133,6 +208,7 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface
void clear() override
{
clear_settingsType();
clear_value();

}

Expand All @@ -144,6 +220,9 @@ class SettingsBusRequestContent final: public ::EmbeddedProto::MessageInterface
case FieldNumber::SETTINGSTYPE:
name = SETTINGSTYPE_NAME;
break;
case FieldNumber::VALUE:
name = VALUE_NAME;
break;
default:
name = "Invalid FieldNumber";
break;
Expand Down Expand Up @@ -205,6 +284,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);

if( 0 == indent_level)
{
Expand All @@ -228,8 +308,43 @@ 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
{
// An enumeration with all the fields for which presence has to be tracked.
enum class fields : uint32_t
{
VALUE
};

// The number of fields for which presence has to be tracked.
static constexpr uint32_t N_FIELDS = 1;

// Which type are we using to track presence.
using TYPE = uint32_t;

// How many bits are there in the presence type.
static constexpr uint32_t N_BITS = std::numeric_limits<TYPE>::digits;

// 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);

// Obtain the index of a given field in the presence array.
static constexpr uint32_t index(const fields& field) { return static_cast<uint32_t>(field) / N_BITS; }

// 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)
{
return static_cast<uint32_t>(0x01) << (static_cast<uint32_t>(field) % N_BITS);
}
};

// Create an array in which the presence flags are stored.
typename presence::TYPE presence_[presence::SIZE] = {0};

EmbeddedProto::enumeration<SettingsType> settingsType_ = static_cast<SettingsType>(0);
EmbeddedProto::int32 value_ = 0;

};

Expand Down
47 changes: 38 additions & 9 deletions Core/External/Scheduler/Handler/scheduler_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int SchedulerHandler::try_process_request_container() {
}

int SchedulerHandler::process_data_bus_request_content_response(
const light_detector::RequestContainer& content) {
const light_detector::RequestContainer &content) {
auto data_bus_request_content =
ProtoHelper::extract_data_bus_request_content(content);

Expand Down Expand Up @@ -149,35 +149,64 @@ int SchedulerHandler::process_data_bus_request_content_of_visible_data_type_resp
}

int SchedulerHandler::process_info_bus_request_content_response(
const light_detector::RequestContainer& content) {
const light_detector::RequestContainer &content) {
auto info_bus_request_content =
ProtoHelper::extract_info_bus_request_content(content);

if (ProtoHelper::is_info_bus_request_content_of_gain_info_type(info_bus_request_content)) {

return process_info_bus_request_content_of_gain_info_type_response(content);
} else if (ProtoHelper::is_info_bus_request_content_of_integral_time_info_type(info_bus_request_content)) {

return process_info_bus_request_content_of_integral_time_info_type_response(content);
}

return EXIT_SUCCESS;
}

int SchedulerHandler::process_info_bus_request_content_of_gain_info_type_response(
const light_detector::RequestContainer &content) {
light_detector::ResponseContainer response_container;

response_container.set_msgId(content.get_msgId());

light_detector::InfoBusResponseContent info_bus_response_content;

info_bus_response_content.set_deviceId(TSL2591X::get_device_id());
info_bus_response_content.set_infoType(light_detector::InfoType::GetGain);
info_bus_response_content.set_infoType(light_detector::InfoType::Gain);

uint8_t value = TSL2591X::get_gain();

// uint32_t value = TSL2591X::read_visible();
//
// data_bus_response_content.set_value(value);
// data_bus_response_content.set_nonce(State::get_current_response_nonce());
info_bus_response_content.set_value(value);
info_bus_response_content.set_nonce(State::get_current_response_nonce());

response_container.set_infoBus(info_bus_response_content);

return ProtoCodec::encode_response_container(response_container);
}
};

int SchedulerHandler::process_info_bus_request_content_of_integral_time_info_type_response(
const light_detector::RequestContainer &content) {
light_detector::ResponseContainer response_container;

response_container.set_msgId(content.get_msgId());

light_detector::InfoBusResponseContent info_bus_response_content;

info_bus_response_content.set_deviceId(TSL2591X::get_device_id());
info_bus_response_content.set_infoType(light_detector::InfoType::IntegralTime);

uint8_t value = TSL2591X::get_integral_time();

info_bus_response_content.set_value(value);
info_bus_response_content.set_nonce(State::get_current_response_nonce());

response_container.set_infoBus(info_bus_response_content);

return ProtoCodec::encode_response_container(response_container);
};

int SchedulerHandler::process_settings_bus_request_content_response(
const light_detector::RequestContainer& content) {
const light_detector::RequestContainer &content) {

}
18 changes: 18 additions & 0 deletions Core/External/Scheduler/Handler/scheduler_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ class SchedulerHandler {
*/
static int process_info_bus_request_content_response(const light_detector::RequestContainer& content);

/**
* Attempts to process info bus request content of gain info type response.
*
* @param content - given info bus request content.
* @return status of the info bus request content response processing.
*/
static int process_info_bus_request_content_of_gain_info_type_response(
const light_detector::RequestContainer& content);

/**
* Attempts to process info bus request content of integral time info type response.
*
* @param content - given info bus request content.
* @return status of the info bus request content response processing.
*/
static int process_info_bus_request_content_of_integral_time_info_type_response(
const light_detector::RequestContainer& content);

/**
* Attempts to process settings bus request content response.
*
Expand Down
28 changes: 14 additions & 14 deletions Core/External/Sensor/tsl2591x.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ class TSL2591X {
*/
static void invoke_lux_interrupt(uint16_t low, uint16_t high);

/**
* Retrieves integral time option from the sensor.
*
* @return read value.
*/
static uint8_t get_integral_time();

/**
* Retrieves the value of gain option from the sensor.
*
* @return retrieved value.
*/
static uint8_t get_gain();

private:
/**
* Indicated that the device has already been initialized.
Expand All @@ -171,27 +185,13 @@ class TSL2591X {
*/
static uint16_t read_channel1();

/**
* Retrieves integral time option from the sensor.
*
* @return read value.
*/
static uint8_t get_integral_time();

/**
* Sets integral time option to the sensor.
*
* @param src - given value to be set.
*/
static void set_integral_time(uint8_t src);

/**
* Retrieves the value of gain option from the sensor.
*
* @return retrieved value.
*/
static uint8_t get_gain();

/**
* Sets the value of gain option to the sensor.
*
Expand Down
1 change: 1 addition & 0 deletions Resources/Proto/Container/Content/settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum SettingsType {
// Represents settings bus request content send from the client to the board.
message SettingsBusRequestContent {
SettingsType settingsType = 1;
optional int32 value = 2;
}

// Represents settings bus response content send to the client from the board.
Expand Down
4 changes: 2 additions & 2 deletions Scripts/graph/proto/Content/info_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 874c39d

Please sign in to comment.