Skip to content

Commit

Permalink
PR #9339 from Nir: support for recovery device in online update flow
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel authored Jul 6, 2021
2 parents c777ea6 + bb3f4f4 commit 604e7ed
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 59 deletions.
65 changes: 35 additions & 30 deletions common/sw-update/dev-updates-profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ namespace rs2

std::string dev_name = (dev.supports(RS2_CAMERA_INFO_NAME)) ? dev.get_info(RS2_CAMERA_INFO_NAME) : "Unknown";
std::string serial = (dev.supports(RS2_CAMERA_INFO_SERIAL_NUMBER)) ? dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) : "Unknown";

std::string fw_update_id = "Unknown";

if (dev.supports(RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID))
{
fw_update_id = dev.get_info(RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID);
}

std::string firmware_ver = (dev.supports(RS2_CAMERA_INFO_FIRMWARE_VERSION)) ? dev.get_info(RS2_CAMERA_INFO_FIRMWARE_VERSION) : "0.0.0";

_update_profile.software_version = sw_update::version(RS2_API_FULL_VERSION_STR);
Expand All @@ -25,6 +33,7 @@ namespace rs2

_update_profile.device_name = dev_name;
_update_profile.serial_number = serial;
_update_profile.fw_update_id = fw_update_id;
}

bool dev_updates_profile::retrieve_updates(component_part_type comp, bool& fail_access_db)
Expand All @@ -38,47 +47,43 @@ namespace rs2

bool update_available(false);

// We expect to get here in recovery mode (on firmware update flow) and therefore do not want to throw...
if (_update_profile.device_name.find("Recovery") == std::string::npos)
{
auto &versions_vec((comp == FIRMWARE) ?
_update_profile.firmware_versions : _update_profile.software_versions);
auto &versions_vec((comp == FIRMWARE) ?
_update_profile.firmware_versions : _update_profile.software_versions);

version& current_version((comp == FIRMWARE) ? _update_profile.firmware_version : _update_profile.software_version);
version& current_version((comp == FIRMWARE) ? _update_profile.firmware_version : _update_profile.software_version);
{
version_info experimental_update;
auto parse_update_stts = try_parse_update(_versions_db, _update_profile.device_name, EXPERIMENTAL, comp, experimental_update);
if ( parse_update_stts == VERSION_FOUND)
{
version_info experimental_update;
auto parse_update_stts = try_parse_update(_versions_db, _update_profile.device_name, EXPERIMENTAL, comp, experimental_update);
if ( parse_update_stts == VERSION_FOUND)
if (current_version < experimental_update.ver)
{
if (current_version < experimental_update.ver)
{
versions_vec[experimental_update.ver] = experimental_update;
update_available = true;
}
versions_vec[experimental_update.ver] = experimental_update;
update_available = true;
}
}

version_info recommened_update;
if (try_parse_update(_versions_db, _update_profile.device_name, RECOMMENDED, comp, recommened_update) == VERSION_FOUND)
version_info recommened_update;
if (try_parse_update(_versions_db, _update_profile.device_name, RECOMMENDED, comp, recommened_update) == VERSION_FOUND)
{
if (current_version < recommened_update.ver)
{
if (current_version < recommened_update.ver)
{
versions_vec[recommened_update.ver] = recommened_update;
update_available = true;
}
versions_vec[recommened_update.ver] = recommened_update;
update_available = true;
}
}

version_info required_update;
if (try_parse_update(_versions_db, _update_profile.device_name, ESSENTIAL, comp, required_update) == VERSION_FOUND)
version_info required_update;
if (try_parse_update(_versions_db, _update_profile.device_name, ESSENTIAL, comp, required_update) == VERSION_FOUND)
{
if (current_version < required_update.ver)
{
if (current_version < required_update.ver)
{
versions_vec[required_update.ver] = required_update;
update_available = true;
}
versions_vec[required_update.ver] = required_update;
update_available = true;
}

fail_access_db = (parse_update_stts == DB_LOAD_FAILURE);
}

fail_access_db = (parse_update_stts == DB_LOAD_FAILURE);
}
return update_available;
}
Expand Down
1 change: 1 addition & 0 deletions common/sw-update/dev-updates-profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace rs2
{
std::string device_name;
std::string serial_number;
std::string fw_update_id;

sw_update::version software_version;
sw_update::version firmware_version;
Expand Down
61 changes: 42 additions & 19 deletions common/updates-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ void updates_model::draw(std::shared_ptr<notifications_model> not_model, ux_wind

bool sw_update_needed(false), fw_update_needed(false);

// Verify Device Exists
if (update.profile.dev_active || _fw_update_state == fw_update_states::started)
bool fw_update_in_process = _fw_update_state == fw_update_states::started
|| _fw_update_state == fw_update_states::failed_updating
|| _fw_update_state == fw_update_states::failed_downloading;

// Verify Device Exists or a FW update process
if (update.profile.dev_active || fw_update_in_process)
{
// ===========================================================================
// Draw Software update Pane
Expand All @@ -84,20 +88,29 @@ void updates_model::draw(std::shared_ptr<notifications_model> not_model, ux_wind
// Draw Firmware update Pane
// ===========================================================================
fw_update_needed = draw_firmware_section(not_model, window_name, update, positions, window, error_message);

}
else
{
ImGui::PushFont(window.get_large_font());
{ // Indicate device disconnected to the user
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::SetCursorPos({ positions.orig_pos.x, positions.y0 - 100 });
ImGui::SetWindowFontScale(1.5);
ImGui::Text("%s","THE DEVICE HAS BEEN DISCONNECTED,");
ImGui::SetCursorPos({ positions.orig_pos.x - 100, positions.y0 - 70 });
ImGui::Text("%s", "PLEASE RECONNECT IT OR CLOSE THE UPDATES WINDOW.");
ImGui::PopFont();
ImGui::SetCursorPos({ positions.orig_pos.x + 230, positions.y0 });
std::string disconnected_text = "THE DEVICE HAS BEEN DISCONNECTED,";
auto disconnected_text_size = ImGui::CalcTextSize(disconnected_text.c_str());
auto disconnected_text_x_pixel = positions.w / 2 - disconnected_text_size.x / 2; // Align 2 center
auto vertical_padding = 100.f;
ImGui::SetCursorPos({ disconnected_text_x_pixel, vertical_padding });
ImGui::Text("%s", disconnected_text.c_str());

std::string reconnect_text = "PLEASE RECONNECT IT OR CLOSE THE UPDATES WINDOW.";
auto reconnect_text_size = ImGui::CalcTextSize(reconnect_text.c_str());
auto reconnect_text_x_pixel = positions.w / 2 - reconnect_text_size.x / 2; // Align 2 center
ImGui::SetCursorPosX(reconnect_text_x_pixel);
ImGui::Text("%s", reconnect_text.c_str());

ImGui::SetWindowFontScale(3.);

auto disconnect_icon_size = ImGui::CalcTextSize(textual_icons::lock);
auto disconnect_icon_x_pixel = (positions.w / 2.f) - (disconnect_icon_size.x / 2); // Align 2 center
ImGui::SetCursorPosX( disconnect_icon_x_pixel );
ImGui::Text("%s", static_cast<const char *>(textual_icons::lock));
ImGui::SetWindowFontScale(1.);
ImGui::PopStyleColor();
Expand Down Expand Up @@ -500,7 +513,9 @@ bool updates_model::draw_firmware_section(std::shared_ptr<notifications_model> n

}

ImVec2 fw_text_pos(pos.orig_pos.x + 10, pos.mid_y + 15);
auto left_padding = 10;
auto top_padding = 15;
ImVec2 fw_text_pos(pos.orig_pos.x + left_padding, pos.mid_y + top_padding);
ImGui::SetCursorScreenPos(fw_text_pos);

ImGui::PushFont(window.get_large_font());
Expand Down Expand Up @@ -558,7 +573,15 @@ bool updates_model::draw_firmware_section(std::shared_ptr<notifications_model> n
ImGui::Text("%s", "Current FW version:");
ImGui::SameLine();
ImGui::PopStyleColor();
auto current_fw_ver_str = std::string(selected_profile.profile.firmware_version);

// During FW update do not take the version from the device because a recovery device version is 0.0.0.0.
// Instead display an update in progress label
std::string current_fw_ver_str;
if (_fw_update_state != fw_update_states::started)
current_fw_ver_str = std::string(selected_profile.profile.firmware_version);
else
current_fw_ver_str = "Update in progress..";

ImGui::Text("%s", current_fw_ver_str.c_str());


Expand Down Expand Up @@ -711,8 +734,8 @@ bool updates_model::draw_firmware_section(std::shared_ptr<notifications_model> n
}
else if (_fw_update_state == fw_update_states::downloading)
{
ImGui::SetCursorScreenPos({ pos.orig_pos.x + 150, pos.orig_pos.y + pos.h - 95 });
_progress.draw(window, static_cast<int>(pos.w) - 170, _fw_download_progress / 3);
ImGui::SetCursorScreenPos({ pos.orig_pos.x + left_padding, pos.orig_pos.y + pos.h - 95 });
_progress.draw(window, static_cast<int>(pos.w) - 170 - left_padding, _fw_download_progress / 3);
if (_fw_download_progress == 100 && !_fw_image.empty())
{
_fw_download_progress = 0;
Expand All @@ -727,8 +750,8 @@ bool updates_model::draw_firmware_section(std::shared_ptr<notifications_model> n
}
else if (_fw_update_state == fw_update_states::started)
{
ImGui::SetCursorScreenPos({ pos.orig_pos.x + 150, pos.orig_pos.y + pos.h - 95 });
_progress.draw(window, static_cast<int>(pos.w) - 170, static_cast<int>(_update_manager->get_progress() * 0.66 + 33));
ImGui::SetCursorScreenPos({ pos.orig_pos.x + left_padding, pos.orig_pos.y + pos.h - 95 });
_progress.draw(window, static_cast<int>(pos.w) - 170 - left_padding, static_cast<int>(_update_manager->get_progress() * 0.66 + 33));
if (_update_manager->done()) {
_fw_update_state = fw_update_states::completed;
_fw_image.clear();
Expand All @@ -750,12 +773,12 @@ bool updates_model::draw_firmware_section(std::shared_ptr<notifications_model> n
else if (_fw_update_state == fw_update_states::failed_downloading ||
_fw_update_state == fw_update_states::failed_updating)
{
ImGui::SetCursorScreenPos({ pos.orig_pos.x + 150, pos.orig_pos.y + pos.h - 95 });
ImGui::SetCursorScreenPos({ pos.orig_pos.x + left_padding, pos.orig_pos.y + pos.h - 95 });
ImGui::PushStyleColor(ImGuiCol_Text, white);
std::string text = _fw_update_state == fw_update_states::failed_downloading ?
"Firmware download failed, check connection and press to retry" :
"Firmware update process failed, press to retry";
if (ImGui::Button(text.c_str(), ImVec2(pos.w - 170, 25)))
if (ImGui::Button(text.c_str(), ImVec2(pos.w - 170 - left_padding, 25)))
{
_fw_update_state = fw_update_states::ready;
_update_manager.reset();
Expand Down
8 changes: 4 additions & 4 deletions common/updates-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace rs2
{
std::lock_guard<std::mutex> lock(_lock);
auto it = std::find_if(_updates.begin(), _updates.end(), [&](update_profile_model& p) {
return (p.profile.device_name == update.profile.device_name && p.profile.serial_number == update.profile.serial_number);
return (p.profile.fw_update_id == update.profile.fw_update_id);
});
if (it == _updates.end())
_updates.push_back(update);
Expand All @@ -45,7 +45,7 @@ namespace rs2
{
std::lock_guard<std::mutex> lock(_lock);
auto it = std::find_if(_updates.begin(), _updates.end(), [&](update_profile_model& p) {
return (p.profile.device_name == update.profile.device_name && p.profile.serial_number == update.profile.serial_number);
return (p.profile.fw_update_id == update.profile.fw_update_id);
});
if (it != _updates.end())
{
Expand All @@ -56,7 +56,7 @@ namespace rs2
{
std::lock_guard<std::mutex> lock(_lock);
auto it = std::find_if(_updates.begin(), _updates.end(), [&](update_profile_model& p) {
return (p.profile.device_name == update.device_name && p.profile.serial_number == update.serial_number);
return (p.profile.fw_update_id == update.fw_update_id);
});
if (it != _updates.end())
_updates.erase(it);
Expand All @@ -69,7 +69,7 @@ namespace rs2
{
std::lock_guard<std::mutex> lock(_lock);
auto it = std::find_if(_updates.begin(), _updates.end(), [&](update_profile_model& p) {
return (p.profile.device_name == update.device_name && p.profile.serial_number == update.serial_number);
return (p.profile.fw_update_id == update.fw_update_id);
});
if (it != _updates.end())
it->profile.dev_active = active;
Expand Down
11 changes: 6 additions & 5 deletions common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2902,6 +2902,12 @@ namespace rs2
if (ImGui::RadioButton("Custom Server", !official_url))
{
official_url = false;
temp_cfg.set(configurations::update::sw_updates_official_server, false);

// Load last saved custom URL
url_str = custom_url;
temp_cfg.set(configurations::update::sw_updates_url, url_str);

}
if (ImGui::IsItemHovered())
{
Expand All @@ -2913,12 +2919,7 @@ namespace rs2
if (ImGui::InputText("##custom_server_url", custom_url, 255))
{
url_str = custom_url;
}
ImGui::SameLine();
if (ImGui::Button("Update URL", ImVec2(80, 20)))
{
temp_cfg.set(configurations::update::sw_updates_url, url_str);
temp_cfg.set(configurations::update::sw_updates_official_server, false);
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion unit-tests/py/rspy/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def has_expired(self):

# Force time expiration
def set_expired(self):
self._sw.reset(time.perf_counter() - (self._delta + 0.00001));
self._sw.reset(time.perf_counter() - (self._delta + 0.00001))


0 comments on commit 604e7ed

Please sign in to comment.