31
31
32
32
using rsutils::json;
33
33
34
+ std::condition_variable cv;
35
+ std::mutex mutex;
36
+ std::string selected_serial_number;
37
+
38
+ rs2::device new_device;
39
+ rs2::update_device new_fw_update_device;
40
+
41
+ bool done = false ;
34
42
35
43
std::vector<uint8_t > read_fw_file (std::string file_path)
36
44
{
@@ -139,7 +147,30 @@ void list_devices( rs2::context ctx )
139
147
}
140
148
}
141
149
142
- int write_fw_to_mipi_device ( const rs2::device & dev, const std::vector< uint8_t > & fw_image )
150
+
151
+ void waiting_for_device_to_reconnect (rs2::context& ctx, rs2::cli::value<std::string>& serial_number_arg)
152
+ {
153
+ std::cout << std::endl << " Waiting for device to reconnect..." << std::endl;
154
+ std::unique_lock<std::mutex> lk (mutex);
155
+ cv.wait_for (lk, std::chrono::seconds (WAIT_FOR_DEVICE_TIMEOUT), [&] { return !done || new_device; });
156
+
157
+ if (done)
158
+ {
159
+ auto devs = ctx.query_devices ();
160
+ for (auto && d : devs)
161
+ {
162
+ auto sn = d.supports (RS2_CAMERA_INFO_SERIAL_NUMBER) ? d.get_info (RS2_CAMERA_INFO_SERIAL_NUMBER) : " unknown" ;
163
+ if (serial_number_arg.isSet () && sn != selected_serial_number)
164
+ continue ;
165
+
166
+ auto fw = d.supports (RS2_CAMERA_INFO_FIRMWARE_VERSION) ? d.get_info (RS2_CAMERA_INFO_FIRMWARE_VERSION) : " unknown" ;
167
+ std::cout << std::endl << " Device " << sn << " successfully updated to FW: " << fw << std::endl;
168
+ }
169
+ }
170
+
171
+ }
172
+
173
+ int write_fw_to_mipi_device ( rs2::context& ctx, rs2::cli::value<std::string>& serial_number_arg, const rs2::device & dev, const std::vector< uint8_t > & fw_image )
143
174
{
144
175
// Write firmware to appropriate file descriptor
145
176
std::cout << std::endl << " Update can take up to 2 minutes" << std::endl;
@@ -186,6 +217,10 @@ int write_fw_to_mipi_device( const rs2::device & dev, const std::vector< uint8_t
186
217
return EXIT_FAILURE;
187
218
}
188
219
std::cout << std::endl << " Firmware update done" << std::endl;
220
+
221
+ done = true ;
222
+
223
+ waiting_for_device_to_reconnect (ctx, serial_number_arg);
189
224
190
225
return EXIT_SUCCESS;
191
226
}
@@ -205,15 +240,6 @@ bool is_mipi_device( const rs2::device & dev )
205
240
int main ( int argc, char ** argv )
206
241
try
207
242
{
208
- std::condition_variable cv;
209
- std::mutex mutex;
210
- std::string selected_serial_number;
211
-
212
- rs2::device new_device;
213
- rs2::update_device new_fw_update_device;
214
-
215
- bool done = false ;
216
-
217
243
using rs2::cli;
218
244
cli cmd ( " librealsense rs-fw-update tool" );
219
245
@@ -477,25 +503,28 @@ try
477
503
// return EXIT_FAILURE;
478
504
// }
479
505
480
- return write_fw_to_mipi_device ( d, fw_image );
506
+ return write_fw_to_mipi_device (ctx, serial_number_arg, d, fw_image );
481
507
}
482
508
483
509
if ( unsigned_arg.isSet () )
484
510
{
485
- std::cout << std::endl << " Firmware update started. Please don't disconnect device!" << std::endl << std::endl;
511
+
512
+ std::cout << std::endl << " Unsigned Firmware update started. Please don't disconnect device!" << std::endl << std::endl;
486
513
487
514
if ( ISATTY ( FILENO ( stdout ) ) )
488
515
{
489
516
d.as <rs2::updatable>().update_unsigned ( fw_image, [&]( const float progress )
490
517
{
491
- printf ( " \r Firmware update progress: %d[%%]" , (int )( progress * 100 ) );
518
+ printf ( " \r Unsigned Firmware update progress: %d[%%]" , (int )( progress * 100 ) );
492
519
std::cout.flush ();
493
520
} );
494
521
}
495
522
else
496
523
d.as <rs2::updatable>().update_unsigned ( fw_image, [&]( const float progress ) {} );
497
524
498
- std::cout << std::endl << std::endl << " Firmware update done" << std::endl;
525
+ std::cout << std::endl << std::endl << " Unsigned Firmware update done" << std::endl;
526
+
527
+ done = true ;
499
528
}
500
529
else
501
530
{
547
576
return EXIT_FAILURE;
548
577
}
549
578
550
- std::cout << std::endl << " Waiting for device to reconnect..." << std::endl;
551
- std::unique_lock<std::mutex> lk (mutex);
552
- cv.wait_for (lk, std::chrono::seconds (WAIT_FOR_DEVICE_TIMEOUT), [&] { return !done || new_device; });
553
-
554
- if (done)
555
- {
556
- auto devs = ctx.query_devices ();
557
- for (auto && d : devs)
558
- {
559
- auto sn = d.supports (RS2_CAMERA_INFO_SERIAL_NUMBER) ? d.get_info (RS2_CAMERA_INFO_SERIAL_NUMBER) : " unknown" ;
560
- if (serial_number_arg.isSet () && sn != selected_serial_number)
561
- continue ;
562
-
563
- auto fw = d.supports (RS2_CAMERA_INFO_FIRMWARE_VERSION) ? d.get_info (RS2_CAMERA_INFO_FIRMWARE_VERSION) : " unknown" ;
564
- std::cout << std::endl << " Device " << sn << " successfully updated to FW: " << fw << std::endl;
565
- }
566
- }
579
+ waiting_for_device_to_reconnect (ctx, serial_number_arg);
567
580
568
581
return EXIT_SUCCESS;
569
582
}
0 commit comments