Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online updates - Enhancements #9008

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 58 additions & 17 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3708,7 +3708,7 @@ namespace rs2
_updates->set_device_status(*_updates_profile, false);
}

void device_model::check_for_bundled_fw_update(const rs2::context &ctx, std::shared_ptr<notifications_model> not_model)
bool device_model::check_for_bundled_fw_update(const rs2::context &ctx, std::shared_ptr<notifications_model> not_model , bool reset_delay )
{
if( dev.supports( RS2_CAMERA_INFO_FIRMWARE_VERSION )
&& dev.supports( RS2_CAMERA_INFO_RECOMMENDED_FIRMWARE_VERSION )
Expand Down Expand Up @@ -3758,15 +3758,20 @@ namespace rs2
auto n = std::make_shared< fw_update_notification_model >( msg.str(),
manager,
false );
n->delay_id = "dfu." + dev_name.second;
n->delay_id = "fw_update_alert." + recommended + "." + dev_name.second;
maloel marked this conversation as resolved.
Show resolved Hide resolved
n->enable_complex_dismiss = true;

if( reset_delay ) n->reset_delay();

if( ! n->is_delayed() )
{
not_model->add_notification( n );
related_notifications.push_back( n );
return true;
}
}
}
return false;
}

void device_model::refresh_notifications(viewer_model& viewer)
Expand Down Expand Up @@ -4876,7 +4881,7 @@ namespace rs2
error_message = e.what();
}
}
void device_model::check_for_device_updates(viewer_model& viewer)
void device_model::check_for_device_updates(viewer_model& viewer, bool activated_by_user )
{
std::weak_ptr< updates_model > updates_model_protected( viewer.updates );
std::weak_ptr< dev_updates_profile::update_profile > update_profile_protected(
Expand All @@ -4887,7 +4892,8 @@ namespace rs2
updates_model_protected,
notification_model_protected,
this,
update_profile_protected]() {
update_profile_protected,
activated_by_user]() {
try
{
bool need_to_check_bundle = true;
Expand All @@ -4905,9 +4911,10 @@ namespace rs2
}
sw_update::dev_updates_profile updates_profile( dev, server_url, use_local_file );

bool sw_online_update_available = updates_profile.retrieve_updates( sw_update::LIBREALSENSE );
bool fw_online_update_available = updates_profile.retrieve_updates( sw_update::FIRMWARE );

bool fail_access_db = false;
bool sw_online_update_available = updates_profile.retrieve_updates( sw_update::LIBREALSENSE, fail_access_db);
bool fw_online_update_available = updates_profile.retrieve_updates( sw_update::FIRMWARE, fail_access_db);
bool fw_bundled_update_available = false;
if (sw_online_update_available || fw_online_update_available)
{
if (auto update_profile = update_profile_protected.lock())
Expand Down Expand Up @@ -4942,14 +4949,14 @@ namespace rs2
{
if (auto nm = notification_model_protected.lock())
{
handle_online_sw_update( nm, update_profile );
handle_online_sw_update( nm, update_profile, activated_by_user);
}
}
if (fw_online_update_available)
{
if (auto nm = notification_model_protected.lock())
{
need_to_check_bundle = !handle_online_fw_update( ctx, nm, update_profile );
need_to_check_bundle = !handle_online_fw_update( ctx, nm, update_profile , activated_by_user);
}
}
}
Expand All @@ -4964,7 +4971,12 @@ namespace rs2
}
else if( auto nm = notification_model_protected.lock() )
{
nm->add_log( "No online SW / FW updates available" );
if ( activated_by_user && fail_access_db )
nm->add_notification( { to_string() << textual_icons::wifi << " Unable to access versions database!\n",
RS2_LOG_SEVERITY_INFO,
RS2_NOTIFICATION_CATEGORY_UNKNOWN_ERROR } );
else
nm->add_log( "No online SW / FW updates available" );
}

// If no on-line updates notification, offer bundled FW update if needed
Expand All @@ -4973,7 +4985,23 @@ namespace rs2
{
if( auto nm = notification_model_protected.lock() )
{
check_for_bundled_fw_update( ctx, nm );
fw_bundled_update_available = check_for_bundled_fw_update( ctx, nm , activated_by_user);
}
}

// When no updates available (on-line + bundled), add a notification to indicate "all up to date"
if( activated_by_user && ! fail_access_db && ! sw_online_update_available
&& ! fw_online_update_available && ! fw_bundled_update_available )
{
auto n = std::make_shared< sw_update_up_to_date_model >();
auto name = get_device_name(dev);
n->delay_id = "no_updates_alert." + name.second;
n->enable_complex_dismiss = true; // allow advanced dismiss menu
maloel marked this conversation as resolved.
Show resolved Hide resolved

if (auto nm = notification_model_protected.lock())
{
nm->add_notification(n);
related_notifications.push_back(n);
}
}
}
Expand Down Expand Up @@ -5274,7 +5302,7 @@ namespace rs2
n->dismiss( false ); // No need for snooze, if needed a new notification will be popped
}

check_for_device_updates( viewer );
check_for_device_updates( viewer , true);
}
}

Expand Down Expand Up @@ -5574,26 +5602,36 @@ namespace rs2
}
}

void rs2::device_model::handle_online_sw_update(std::shared_ptr < notifications_model > nm , std::shared_ptr < dev_updates_profile::update_profile >update_profile )
void rs2::device_model::handle_online_sw_update(
std::shared_ptr< notifications_model > nm,
std::shared_ptr< dev_updates_profile::update_profile > update_profile,
bool reset_delay )
{
dev_updates_profile::version_info recommended_sw_update_info;
update_profile->get_sw_update(sw_update::RECOMMENDED, recommended_sw_update_info);
auto n = std::make_shared< sw_recommended_update_alert_model >(
RS2_API_FULL_VERSION_STR,
recommended_sw_update_info.ver,
recommended_sw_update_info.download_link);
auto name = get_device_name(dev);
n->delay_id = "update_alert." + name.second;

auto dev_name = get_device_name(dev);
n->delay_id = "sw_update_alert." + std::string(recommended_sw_update_info.ver) + "." + dev_name.second;
n->enable_complex_dismiss = true; // allow advanced dismiss menu

if ( reset_delay ) n->reset_delay();

if (!n->is_delayed())
{
nm->add_notification(n);
related_notifications.push_back(n);
}
}

bool rs2::device_model::handle_online_fw_update( const context& ctx, std::shared_ptr < notifications_model > nm, std::shared_ptr< dev_updates_profile::update_profile> update_profile )
bool rs2::device_model::handle_online_fw_update(
const context & ctx,
std::shared_ptr< notifications_model > nm,
std::shared_ptr< dev_updates_profile::update_profile > update_profile,
bool reset_delay )
{
bool fw_update_notification_raised = false;
std::shared_ptr< firmware_update_manager > manager = nullptr;
Expand Down Expand Up @@ -5640,8 +5678,11 @@ namespace rs2
msg.str(),
manager,
false);
n->delay_id = "dfu." + dev_name.second;
n->delay_id = "fw_update_alert." + std::string(recommended_fw_update_info.ver) + "." + dev_name.second;
n->enable_complex_dismiss = true;

if ( reset_delay ) n->reset_delay();

if (!n->is_delayed())
{
nm->add_notification(n);
Expand Down
15 changes: 10 additions & 5 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ namespace rs2
static const textual_icon mail { u8"\uF01C" };
static const textual_icon cube { u8"\uf1b2" };
static const textual_icon measure { u8"\uf545" };
static const textual_icon wifi { u8"\uf1eb" };
}

class subdevice_model;
Expand Down Expand Up @@ -767,7 +768,9 @@ namespace rs2
void resume_record();

void refresh_notifications(viewer_model& viewer);
void check_for_bundled_fw_update(const rs2::context& ctx, std::shared_ptr<notifications_model> not_model);
bool check_for_bundled_fw_update( const rs2::context & ctx,
std::shared_ptr< notifications_model > not_model,
bool reset_delay = false );

int draw_playback_panel(ux_window& window, ImFont* font, viewer_model& view);
bool draw_advanced_controls(viewer_model& view, ux_window& window, std::string& error_message);
Expand All @@ -784,7 +787,7 @@ namespace rs2
void begin_update(std::vector<uint8_t> data,
viewer_model& viewer, std::string& error_message);
void begin_update_unsigned(viewer_model& viewer, std::string& error_message);
void check_for_device_updates(viewer_model& viewer);
void check_for_device_updates(viewer_model& viewer, bool activated_by_user = false);


std::shared_ptr< atomic_objects_in_frame > get_detected_objects() const { return _detected_objects; }
Expand Down Expand Up @@ -844,13 +847,15 @@ namespace rs2
void load_viewer_configurations(const std::string& json_str);
void save_viewer_configurations(std::ofstream& outfile, nlohmann::json& j);
void handle_online_sw_update(
std::shared_ptr < notifications_model > nm,
std::shared_ptr< sw_update::dev_updates_profile::update_profile > update_profile );
std::shared_ptr< notifications_model > nm,
std::shared_ptr< sw_update::dev_updates_profile::update_profile > update_profile,
bool reset_delay = false );

bool handle_online_fw_update(
const context & ctx,
std::shared_ptr< notifications_model > nm,
std::shared_ptr< sw_update::dev_updates_profile::update_profile > update_profile );
std::shared_ptr< sw_update::dev_updates_profile::update_profile > update_profile,
bool reset_delay = false );

std::shared_ptr<recorder> _recorder;
std::vector<std::shared_ptr<subdevice_model>> live_subdevices;
Expand Down
59 changes: 59 additions & 0 deletions common/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,14 @@ namespace rs2
std::string str = to_string() << "notifications." << delay_id << ".next";
config_file::instance().set(str.c_str(), (long long)(rawtime + days * 60 * 60 * 24));
}
void notification_model::reset_delay()
{
if( is_delayed() )
{
std::string str = to_string() << "notifications." << delay_id << ".next";
config_file::instance().remove( str.c_str());
}
}

sw_recommended_update_alert_model::sw_recommended_update_alert_model(const std::string& current_version, const std::string& recommended_version, const std::string& recommended_version_link)
: notification_model(), _current_version(current_version), _recommended_version(recommended_version), _recommended_version_link(recommended_version_link)
Expand Down Expand Up @@ -1092,4 +1100,55 @@ namespace rs2
}
ImGui::PopStyleColor(2);
}

sw_update_up_to_date_model::sw_update_up_to_date_model()
: notification_model()
{
enable_expand = false;
enable_dismiss = false;
pinned = false;
forced = true;
severity = RS2_LOG_SEVERITY_INFO;
message = "SW/FW versions up to date";
}

void sw_update_up_to_date_model::set_color_scheme(float t) const
{
notification_model::set_color_scheme(t);
ImGui::PopStyleColor();

ImVec4 c;
c = alpha(saturate(light_blue, 0.7f), 1 - t);
ImGui::PushStyleColor(ImGuiCol_WindowBg, c);
}


void sw_update_up_to_date_model::draw_content(ux_window& win, int x, int y, float t, std::string& error_message)
{
using namespace std;
using namespace chrono;

ImGui::SetCursorScreenPos({ float(x + 9), float(y + 4) });

ImVec4 shadow{ 1.f, 1.f, 1.f, 0.1f };
ImGui::GetWindowDrawList()->AddRectFilled({ float(x), float(y) },
{ float(x + width), float(y + 25) }, ImColor(shadow));

ImGui::Text("Updates Status");

ImGui::SetCursorScreenPos({ float(x + 10), float(y + 35) });
ImGui::PushFont(win.get_large_font());
std::string txt = to_string() << textual_icons::throphy;
ImGui::Text("%s", txt.c_str());
ImGui::PopFont();

ImGui::SetCursorScreenPos({ float(x + 40), float(y + 35) });
ImGui::Text("SW/FW Versions All Up To Date");

ImGui::SetCursorScreenPos({ float(x + 5), float(y + height - 25) });

const auto bar_width = width - 115;
maloel marked this conversation as resolved.
Show resolved Hide resolved

}

}
12 changes: 11 additions & 1 deletion common/notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace rs2

bool is_delayed() const;
void delay(int days);
void reset_delay();

float last_x, last_y;
bool animating = false;
Expand Down Expand Up @@ -230,7 +231,6 @@ namespace rs2
void draw_content(
ux_window & win, int x, int y, float t, std::string & error_message ) override;
int calc_height() override { return 150; }
int get_max_lifetime_ms() const override { return 10000; }
const std::string _current_version;
const std::string _recommended_version;
const std::string _recommended_version_link;
Expand All @@ -246,6 +246,16 @@ namespace rs2
return{ v.x, v.y, v.z, a };
}

struct sw_update_up_to_date_model : public notification_model
{
sw_update_up_to_date_model();

void set_color_scheme(float t) const override;
void draw_content(
ux_window& win, int x, int y, float t, std::string& error_message) override;
int calc_height() override { return 65; }
};

class export_manager : public process_manager
{
public:
Expand Down
6 changes: 6 additions & 0 deletions common/rs-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ void config_file::set_default(const char* key, const char* calculate)
_defaults[key] = calculate;
}

void config_file::remove(const char* key)
{
_values.erase(key);
save();
}

void config_file::reset()
{
_values.clear();
Expand Down
2 changes: 2 additions & 0 deletions common/rs-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ namespace rs2

void reset();

void remove(const char* key);

static config_file& instance();

private:
Expand Down
Loading