14 #include <condition_variable> 19 using namespace TCLAP;
21 #define WAIT_FOR_DEVICE_TIMEOUT 10 25 std::vector<uint8_t> rv;
30 rv.resize(file.tellg());
32 file.seekg(0, std::ios::beg);
33 file.read((
char*)rv.data(), rv.size());
42 std::map<rs2_camera_info, std::string> camera_info;
61 throw rs2::error(
"firmware file must be selected");
66 if (fw_image.size() == 0)
68 throw rs2::error(
"failed to read firmware file");
77 std::cout << std::endl <<
"firmware update started"<< std::endl << std::endl;
81 printf(
"\rfirmware update progress: %d[%%]", (
int)(progress * 100));
83 std::cout << std::endl << std::endl <<
"firmware update done" << std::endl;
91 std::cout << std::endl <<
"there are no connected devices" << std::endl;
95 std::cout << std::endl <<
"connected devices:" << std::endl;
106 int main(
int argc,
char** argv)
try 108 #ifdef BUILD_EASYLOGGINGPP 114 std::condition_variable
cv;
125 SwitchArg list_devices_arg(
"l",
"list_devices",
"List all available devices");
126 SwitchArg recover_arg(
"r",
"recover",
"Recover all connected devices which are in recovery mode");
127 SwitchArg unsigned_arg(
"u",
"unsigned",
"Update unsigned firmware, available only for unlocked cameras");
128 ValueArg<std::string> backup_arg(
"b",
"backup",
"Create a backup to the camera flash and saved it to the given path",
false,
"",
"string");
130 ValueArg<std::string> serial_number_arg(
"s",
"serial_number",
"The serial number of the device to be update, this is mandetory if more than one device is connected",
false,
"",
"string");
132 cmd.
add(list_devices_arg);
133 cmd.
add(recover_arg);
134 cmd.
add(unsigned_arg);
136 cmd.
add(serial_number_arg);
139 cmd.
parse(argc, argv);
141 bool recovery_request = recover_arg.
getValue();
143 if (list_devices_arg.
isSet())
151 std::cout << std::endl <<
"nothing to do, run again with -h for help" << std::endl;
155 if (serial_number_arg.
isSet())
157 selected_serial_number = serial_number_arg.
getValue();
158 std::cout << std::endl <<
"search for device with serial number: " << selected_serial_number << std::endl;
164 bool recovery_executed =
false;
165 if (recover_arg.
isSet() )
171 for (
auto&&
d : devs)
177 std::cout << std::endl <<
"recovering device: " << std::endl;
180 recovery_executed =
true;
184 std::cout << std::endl <<
"failed to recover device" << std::endl;
187 if (recovery_executed)
189 std::cout << std::endl <<
"recovery done" << std::endl;
205 std::lock_guard<std::mutex> lk(mutex);
207 new_fw_update_device =
d;
211 if(new_fw_update_device || new_device)
217 if (!serial_number_arg.
isSet() && devs.size() > 1)
219 std::cout << std::endl <<
"more than one device is connected, serial number must be selected" << std::endl << std::endl;
223 bool device_found =
false;
225 for (
auto&&
d : devs)
233 if (usb_type.find(
"2.") != std::string::npos) {
234 std::cout << std::endl <<
"Warning! the camera is connected via USB 2 port, in case the process fails, connect the camera to a USB 3 port and try again" << std::endl;
241 if (sn != selected_serial_number && devs.size() != 1)
246 if (backup_arg.
isSet())
248 std::cout << std::endl <<
"backing-up device flash: " << std::endl;
252 printf(
"\rflash backup progress: %d[%%]", (
int)(progress * 100));
257 file.write((
const char*)flash.data(), flash.size());
260 if (!file_arg.
isSet())
265 std::cout << std::endl <<
"updating device: " << std::endl;
268 if (unsigned_arg.
isSet())
270 std::cout << std::endl <<
"firmware update started" << std::endl << std::endl;
274 printf(
"\rfirmware update progress: %d[%%]", (
int)(progress * 100));
276 std::cout << std::endl << std::endl <<
"firmware update done" << std::endl;
282 std::unique_lock<std::mutex> lk(mutex);
285 std::cout << std::endl <<
"failed to locate a device in FW update mode" << std::endl;
289 update(new_fw_update_device, fw_image);
297 if(serial_number_arg.
isSet())
298 std::cout << std::endl <<
"couldn't find the requested serial number" << std::endl;
299 else if (devs.size() == 1)
301 std::cout << std::endl <<
"nothing to do, run again with -h for help" << std::endl;
306 std::unique_lock<std::mutex> lk(mutex);
312 for (
auto&&
d : devs)
315 if (serial_number_arg.
isSet() && sn != selected_serial_number)
319 std::cout << std::endl <<
"device " << sn <<
" successfully updated to FW: " << fw << std::endl;
std::vector< uint8_t > read_fw_file(std::string file_path)
rs2_camera_info
Read-only strings that can be queried from the device. Not all information attributes are available o...
int main(int argc, char **argv)
#define WAIT_FOR_DEVICE_TIMEOUT
std::vector< uint8_t > read_firmware_data(bool is_set, const std::string &file_path)
device_list query_devices() const
GLsizei const GLchar *const * string
void print_device_info(rs2::device d)
static const textual_icon usb_type
def info(name, value, persistent=False)
const std::string & get_failed_args() const
void update(rs2::update_device fwu_dev, std::vector< uint8_t > fw_image)
void update(const std::vector< uint8_t > &fw_image) const
const char * get_info(rs2_camera_info info) const
static std::condition_variable cv
bool supports(rs2_camera_info info) const
#define RS2_PRODUCT_LINE_DEPTH
void log_to_console(rs2_log_severity min_severity)
void list_devices(rs2::context ctx)
void parse(int argc, const char *const *argv)
const GLuint GLenum const void * binary
#define RS2_API_VERSION_STR
void set_devices_changed_callback(T callback)
const std::string & get_failed_function() const