@@ -402,6 +402,21 @@ json list_dfu_interfaces(void) {
402
402
int index = 0 ;
403
403
404
404
for (pdfu = dfu_root; pdfu != NULL ; pdfu = pdfu->next ) {
405
+
406
+ if (!(pdfu->flags & DFU_IFF_DFU)) {
407
+ // decide what to do with DFU runtime objects
408
+ // for the time being, ignore them
409
+ continue ;
410
+ }
411
+
412
+ for (int i = 0 ; i < index; i++) {
413
+ // allow only one object
414
+ if (j[" ports" ][i][" address" ] == get_path (pdfu->dev )) {
415
+ index = i;
416
+ break ;
417
+ }
418
+ }
419
+
405
420
j[" ports" ][index][" address" ] = get_path (pdfu->dev );
406
421
j[" ports" ][index][" label" ] = pdfu->alt_name ;
407
422
j[" ports" ][index][" protocol" ] = " dfu" ;
@@ -459,12 +474,48 @@ void print_list() {
459
474
std::cout << j.dump (2 ) << std::endl;
460
475
}
461
476
477
+
478
+
479
+
462
480
json previous_list;
463
481
void print_event () {
464
482
auto j = list_dfu_interfaces ();
465
483
auto diff = json::diff (previous_list, j);
484
+
485
+ json diff_discovery;
486
+ // diff_discovery["eventType"] = "remove";
487
+
466
488
if (diff.size () > 0 ) {
467
- std::cout << diff.dump (2 ) << std::endl;
489
+ for (auto & new_port : j[" ports" ].items ()) {
490
+ bool found = false ;
491
+ for (auto & old_port : previous_list[" ports" ].items ()) {
492
+ if (new_port.value ()[" address" ] == old_port.value ()[" address" ]) {
493
+ found = true ;
494
+ break ;
495
+ }
496
+ }
497
+ if (!found) {
498
+ diff_discovery[" eventType" ] = " add" ;
499
+ diff_discovery[" port" ] = new_port.value ();
500
+ std::cout << diff_discovery.dump (2 ) << std::endl;
501
+ }
502
+ }
503
+
504
+ for (auto & new_port : previous_list[" ports" ].items ()) {
505
+ bool found = false ;
506
+ for (auto & old_port : j[" ports" ].items ()) {
507
+ if (new_port.value ()[" address" ] == old_port.value ()[" address" ]) {
508
+ found = true ;
509
+ break ;
510
+ }
511
+ }
512
+ if (!found) {
513
+ diff_discovery[" eventType" ] = " remove" ;
514
+ diff_discovery[" port" ] = new_port.value ();
515
+ std::cout << diff_discovery.dump (2 ) << std::endl;
516
+ }
517
+ }
518
+ // std::cout << diff.dump(2) << std::endl;
468
519
}
469
520
previous_list = j;
470
521
}
0 commit comments