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

Viewer - Alert user on recovery device bundled update #9575

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
93 changes: 52 additions & 41 deletions common/fw-update-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,68 +45,79 @@ namespace rs2
RS2_FWU_STATE_FAILED = 3,
};

bool is_recommended_fw_available(const std::string& product_line, const std::string& PID)
bool is_recommended_fw_available(const std::string& product_line, const std::string& pid)
{
auto pl = parse_product_line(product_line);
auto fv = get_available_firmware_version(pl, PID);
auto fv = get_available_firmware_version(pl, pid);
return !(fv == "");
}

int parse_product_line(const std::string& id)
int parse_product_line(const std::string& product_line)
{
if (id == "D400") return RS2_PRODUCT_LINE_D400;
else if (id == "SR300") return RS2_PRODUCT_LINE_SR300;
else if (id == "L500") return RS2_PRODUCT_LINE_L500;
if (product_line == "D400") return RS2_PRODUCT_LINE_D400;
else if (product_line == "SR300") return RS2_PRODUCT_LINE_SR300;
else if (product_line == "L500") return RS2_PRODUCT_LINE_L500;
else return -1;
}

std::string get_available_firmware_version(int product_line, const std::string& PID)
std::string get_available_firmware_version(int product_line, const std::string& pid)
{
if (product_line == RS2_PRODUCT_LINE_D400) return FW_D4XX_FW_IMAGE_VERSION;
//else if (product_line == RS2_PRODUCT_LINE_SR300) return FW_SR3XX_FW_IMAGE_VERSION;
else if (product_line == RS2_PRODUCT_LINE_L500 && PID == "0B64") return FW_L51X_FW_IMAGE_VERSION;
else if (product_line == RS2_PRODUCT_LINE_L500 && PID == "0B68") return FW_L53X_FW_IMAGE_VERSION;
else if (product_line == RS2_PRODUCT_LINE_L500 && pid == "0B68") return FW_L53X_FW_IMAGE_VERSION;
else if (product_line == RS2_PRODUCT_LINE_L500) return FW_L51X_FW_IMAGE_VERSION;
else return "";
}

std::map<std::pair<int, std::string>, std::vector<uint8_t>> create_default_fw_table()
std::vector< uint8_t > get_default_fw_image( int product_line, const std::string & pid )
{
bool allow_rc_firmware = config_file::instance().get_or_default(configurations::update::allow_rc_firmware, false);
std::vector< uint8_t > image;

std::map<std::pair<int, std::string>, std::vector<uint8_t>> rv;

if (strlen(FW_D4XX_FW_IMAGE_VERSION) && !allow_rc_firmware)
{
int size = 0;
auto hex = fw_get_D4XX_FW_Image(size);
auto vec = std::vector<uint8_t>(hex, hex + size);
rv[{RS2_PRODUCT_LINE_D400, ""}] = vec;
}

if (strlen(FW_SR3XX_FW_IMAGE_VERSION))
switch( product_line )
{
int size = 0;
auto hex = fw_get_SR3XX_FW_Image(size);
auto vec = std::vector<uint8_t>(hex, hex + size);
rv[{RS2_PRODUCT_LINE_SR300, ""}] = vec;
}

if (strlen(FW_L51X_FW_IMAGE_VERSION))
case RS2_PRODUCT_LINE_D400:
{
int size = 0;
auto hex = fw_get_L51X_FW_Image(size);
auto vec = std::vector<uint8_t>(hex, hex + size);
rv[{RS2_PRODUCT_LINE_L500, "0B64"}] = vec;
bool allow_rc_firmware = config_file::instance().get_or_default( configurations::update::allow_rc_firmware, false );
if( strlen( FW_D4XX_FW_IMAGE_VERSION ) && ! allow_rc_firmware )
{
int size = 0;
auto hex = fw_get_D4XX_FW_Image( size );
image = std::vector< uint8_t >( hex, hex + size );
}
}
if (strlen(FW_L53X_FW_IMAGE_VERSION))
{
int size = 0;
auto hex = fw_get_L53X_FW_Image(size);
auto vec = std::vector<uint8_t>(hex, hex + size);
rv[{RS2_PRODUCT_LINE_L500, "0B68"}] = vec;
break;
case RS2_PRODUCT_LINE_SR300:
if( strlen( FW_SR3XX_FW_IMAGE_VERSION ) )
{
int size = 0;
auto hex = fw_get_SR3XX_FW_Image( size );
image = std::vector< uint8_t >( hex, hex + size );
}
break;
case RS2_PRODUCT_LINE_L500:
if( pid == "0B68" || pid == "0B72" ) // L535 || L535 Recovery
{
if( strlen( FW_L53X_FW_IMAGE_VERSION ) )
{
int size = 0;
auto hex = fw_get_L53X_FW_Image( size );
image = std::vector< uint8_t >( hex, hex + size );
}
}
else
{ // default for all L515 use cases (include recovery usb2 old pid)
if( strlen( FW_L51X_FW_IMAGE_VERSION ) )
{
int size = 0;
auto hex = fw_get_L51X_FW_Image( size );
image = std::vector< uint8_t >( hex, hex + size );
}
}
break;
default:
break;
}

return rv;
return image;
}

std::vector<int> parse_fw_version(const std::string& fw)
Expand Down
10 changes: 4 additions & 6 deletions common/fw-update-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ namespace rs2
{
class viewer_model;

int parse_product_line(const std::string& id);
std::string get_available_firmware_version(int product_line, const std::string& PID);
int parse_product_line(const std::string& product_line);
std::string get_available_firmware_version(int product_line, const std::string& pid);

// product line + PID to FW image data
// if PID doesn't make any difference (ds5, sr300) its will be ""
std::map<std::pair<int, std::string>, std::vector<uint8_t>> create_default_fw_table();
std::vector<uint8_t> get_default_fw_image(int product_line, const std::string& pid);
std::vector<int> parse_fw_version(const std::string& fw);
bool is_upgradeable(const std::string& curr, const std::string& available);
bool is_recommended_fw_available(const std::string& product_line, const std::string& PID);
bool is_recommended_fw_available(const std::string& product_line, const std::string& pid);

class firmware_update_manager : public process_manager
{
Expand Down
87 changes: 55 additions & 32 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3853,40 +3853,50 @@ namespace rs2
// it). Lacking an available version, we try to let the user choose a "recommended"
// version for download. The recommended version is defined by the device (and comes
// from a #define).
if( dev.supports( RS2_CAMERA_INFO_FIRMWARE_VERSION )
&& dev.supports( RS2_CAMERA_INFO_RECOMMENDED_FIRMWARE_VERSION )
&& dev.supports( RS2_CAMERA_INFO_PRODUCT_LINE ) )

// 'notification_type_is_displayed()' is used to detect if fw_update notification is on to avoid displaying it during FW update process when
// the device enters recovery mode
if( ! not_model->notification_type_is_displayed< fw_update_notification_model >()
&& ( dev.is< updatable >() || dev.is< update_device >() ) )
{
std::string fw = dev.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION );
std::string recommended_fw_ver
= dev.get_info( RS2_CAMERA_INFO_RECOMMENDED_FIRMWARE_VERSION );
std::string fw;
std::string recommended_fw_ver;
int product_line = 0;

// Override with device info if info is available
if (dev.is<updatable>())
{
fw = dev.supports( RS2_CAMERA_INFO_FIRMWARE_VERSION )
? dev.get_info( RS2_CAMERA_INFO_FIRMWARE_VERSION )
: "";

int product_line
= parse_product_line( dev.get_info( RS2_CAMERA_INFO_PRODUCT_LINE ) );
recommended_fw_ver = dev.supports(RS2_CAMERA_INFO_RECOMMENDED_FIRMWARE_VERSION)
? dev.get_info(RS2_CAMERA_INFO_RECOMMENDED_FIRMWARE_VERSION)
: "";
}

product_line = dev.supports(RS2_CAMERA_INFO_PRODUCT_LINE)
? parse_product_line(dev.get_info(RS2_CAMERA_INFO_PRODUCT_LINE))
: -1; // invalid product line, will be handled later on

bool allow_rc_firmware = config_file::instance().get_or_default(
configurations::update::allow_rc_firmware,
false );
bool is_rc = ( product_line == RS2_PRODUCT_LINE_D400 ) && allow_rc_firmware;
std::string PID = dev.get_info(RS2_CAMERA_INFO_PRODUCT_ID);

std::string available_fw_ver = get_available_firmware_version( product_line, PID);

bool is_rc = ( product_line == RS2_PRODUCT_LINE_D400 ) && allow_rc_firmware;
std::string pid = dev.get_info(RS2_CAMERA_INFO_PRODUCT_ID);
std::string available_fw_ver = get_available_firmware_version( product_line, pid);
std::shared_ptr< firmware_update_manager > manager = nullptr;


if( is_upgradeable( fw, available_fw_ver) )
if( dev.is<update_device>() || is_upgradeable( fw, available_fw_ver) )
{
recommended_fw_ver = available_fw_ver;

static auto table = create_default_fw_table();

std::vector<uint8_t> image;

if (table.find({ product_line, PID }) != table.end())
image = table[{product_line, PID}];
else
image = table[{product_line, ""}];
auto image = get_default_fw_image(product_line, pid);
if (image.empty())
{
not_model->add_log("could not detect a bundled FW version for the connected device", RS2_LOG_SEVERITY_WARN);
return false;
}

manager = std::make_shared< firmware_update_manager >( not_model,
*this,
Expand All @@ -3897,13 +3907,22 @@ namespace rs2
}

auto dev_name = get_device_name(dev);
if( is_upgradeable( fw, recommended_fw_ver) )

if( dev.is<update_device>() || is_upgradeable( fw, recommended_fw_ver) )
{
std::stringstream msg;
msg << dev_name.first << " (S/N " << dev_name.second << ")\n"
<< "Current Version: " << fw << "\n";

if( is_rc )
if (dev.is<update_device>())
{
msg << dev_name.first << "\n(S/N " << dev.get_info(RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID) << ")\n";
}
else
{
msg << dev_name.first << " (S/N " << dev_name.second << ")\n"
<< "Current Version: " << fw << "\n";
}

if (is_rc)
msg << "Release Candidate: " << recommended_fw_ver << " Pre-Release";
else
msg << "Recommended Version: " << recommended_fw_ver;
Expand All @@ -3916,6 +3935,7 @@ namespace rs2
n->delay_id = "fw_update_alert." + recommended_fw_ver + "." + dev_name.second;
n->enable_complex_dismiss = true;

// If a delay request received in the past, reset it.
if( reset_delay ) n->reset_delay();

if( ! n->is_delayed() )
Expand All @@ -3927,12 +3947,15 @@ namespace rs2
}
else
{
std::stringstream msg;
msg << "Current FW >= Bundled FW for: " << dev_name.first << " (S/N " << dev_name.second << ")\n"
<< "Current Version: " << fw << "\n"
<< "Recommended Version: " << recommended_fw_ver;
if( ! fw.empty() && ! recommended_fw_ver.empty() )
{
std::stringstream msg;
msg << "Current FW >= Bundled FW for: " << dev_name.first << " (S/N " << dev_name.second << ")\n"
<< "Current Version: " << fw << "\n"
<< "Recommended Version: " << recommended_fw_ver;

not_model->add_log(msg.str(), RS2_LOG_SEVERITY_DEBUG);
not_model->add_log(msg.str(), RS2_LOG_SEVERITY_DEBUG);
}
}
}
return false;
Expand Down
8 changes: 8 additions & 0 deletions common/notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ namespace rs2
std::function<void()> custom_action,
bool use_custom_action = true);
void add_notification(std::shared_ptr<notification_model> model);

// Check of a notification of type T is currently on the display queue.
template <typename T>
bool notification_type_is_displayed()
{
std::lock_guard<std::recursive_mutex> lock(m);
return std::any_of(pending_notifications.cbegin(), pending_notifications.cend(), [](const std::shared_ptr<notification_model>& nm) {return nm->is<T>(); });
}
bool draw(ux_window& win, int w, int h, std::string& error_message);

notifications_model() {}
Expand Down
4 changes: 3 additions & 1 deletion src/fw-update/fw-update-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace librealsense
}

update_device::update_device(const std::shared_ptr<context>& ctx, bool register_device_notifications, std::shared_ptr<platform::usb_device> usb_device)
: _context(ctx), _usb_device(usb_device), _physical_port( usb_device->get_info().id )
: _context(ctx), _usb_device(usb_device), _physical_port( usb_device->get_info().id), _pid(hexify(usb_device->get_info().pid))
{
if (auto messenger = _usb_device->open(FW_UPDATE_INTERFACE_NUMBER))
{
Expand Down Expand Up @@ -277,6 +277,7 @@ namespace librealsense
case RS2_CAMERA_INFO_NAME: return get_name();
case RS2_CAMERA_INFO_PRODUCT_LINE: return get_product_line();
case RS2_CAMERA_INFO_PHYSICAL_PORT: return _physical_port;
case RS2_CAMERA_INFO_PRODUCT_ID: return _pid;
default:
throw std::runtime_error("update_device does not support " + std::string(rs2_camera_info_to_string(info)));
}
Expand All @@ -290,6 +291,7 @@ namespace librealsense
case RS2_CAMERA_INFO_NAME:
case RS2_CAMERA_INFO_PRODUCT_LINE:
case RS2_CAMERA_INFO_PHYSICAL_PORT:
case RS2_CAMERA_INFO_PRODUCT_ID:
return true;

default:
Expand Down
1 change: 1 addition & 0 deletions src/fw-update/fw-update-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ namespace librealsense
std::string _highest_fw_version;
std::string _last_fw_version;
std::string _physical_port;
std::string _pid;
bool _is_dfu_locked = false;
};
}