nep-cli 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/image.html +29 -8
- package/bin/image4.html +57 -0
- package/bin/index.js +677 -317
- package/bin/json.html +172 -0
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -267,7 +267,7 @@ program
|
|
|
267
267
|
|
|
268
268
|
program
|
|
269
269
|
.command('ip')
|
|
270
|
-
.description('Display current Wi-Fi and Ethernet IP addresses')
|
|
270
|
+
.description('Display current Wi-Fi and Ethernet IP addresses of this computer')
|
|
271
271
|
.action(() => {
|
|
272
272
|
const interfaces = os.networkInterfaces();
|
|
273
273
|
|
|
@@ -324,7 +324,7 @@ program
|
|
|
324
324
|
|
|
325
325
|
program
|
|
326
326
|
.command('open [programName]')
|
|
327
|
-
.description('Open NEP+ GUI')
|
|
327
|
+
.description('Open a NEP+ GUI')
|
|
328
328
|
.action(async (programName) => {
|
|
329
329
|
const programs = ['cameras', 'hxri'];
|
|
330
330
|
|
|
@@ -366,10 +366,9 @@ program
|
|
|
366
366
|
|
|
367
367
|
|
|
368
368
|
|
|
369
|
-
|
|
370
369
|
program
|
|
371
370
|
.command('master')
|
|
372
|
-
.description('Start NEP master in
|
|
371
|
+
.description('Start NEP master in localhost')
|
|
373
372
|
.action(async () => {
|
|
374
373
|
try {
|
|
375
374
|
var node = new nep.Node("nep-cli");
|
|
@@ -386,22 +385,40 @@ program
|
|
|
386
385
|
});
|
|
387
386
|
|
|
388
387
|
program
|
|
389
|
-
.command('master-
|
|
390
|
-
.description('Start NEP master in
|
|
391
|
-
.action(async (
|
|
388
|
+
.command('master-wifi')
|
|
389
|
+
.description('Start NEP master in Wi-Fi network')
|
|
390
|
+
.action(async () => {
|
|
392
391
|
|
|
392
|
+
const interfaces = os.networkInterfaces();
|
|
393
393
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
394
|
+
// Find Wi-Fi interface
|
|
395
|
+
const wifiInterface = interfaces['Wi-Fi'] || interfaces['Wi-Fi 2'] || interfaces['wlan0'] || interfaces['wlo1'];
|
|
396
|
+
if (wifiInterface) {
|
|
397
|
+
const wifiIPv4 = wifiInterface.find(iface => iface.family === 'IPv4');
|
|
398
|
+
if (wifiIPv4) {
|
|
399
|
+
console.log(`Wi-Fi IP Address: ${wifiIPv4.address}`);
|
|
400
|
+
try {
|
|
401
|
+
var node = new nep.Node("nep-cli");
|
|
402
|
+
nep_configuration["IP"] = wifiIPv4.address;
|
|
403
|
+
var master = new MasterLocal(IP = wifiIPv4.address);
|
|
404
|
+
var info = new nep.MasterInfoServer(IP = wifiIPv4.address, topics = topic_register);
|
|
405
|
+
} catch (error) {
|
|
406
|
+
if (error.message.includes('EADDRINUSE')) {
|
|
407
|
+
console.error("Error: Address already in use. Another instance of NEP master might be running.");
|
|
408
|
+
} else {
|
|
409
|
+
console.error("An error occurred:", error.message);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
399
412
|
|
|
413
|
+
} else {
|
|
414
|
+
console.log('No Wi-Fi IPv4 address found.');
|
|
415
|
+
}
|
|
416
|
+
} else {
|
|
417
|
+
console.log('Wi-Fi interface not found.');
|
|
418
|
+
}
|
|
400
419
|
});
|
|
401
|
-
|
|
402
|
-
|
|
403
420
|
program
|
|
404
|
-
.command('eth')
|
|
421
|
+
.command('master-eth')
|
|
405
422
|
.description('Start NEP master in Ethernet network')
|
|
406
423
|
.action(async () => {
|
|
407
424
|
|
|
@@ -426,39 +443,20 @@ program
|
|
|
426
443
|
|
|
427
444
|
|
|
428
445
|
program
|
|
429
|
-
.command('
|
|
430
|
-
.description('Start NEP master in
|
|
431
|
-
.action(async () => {
|
|
446
|
+
.command('master-ip <ip>')
|
|
447
|
+
.description('Start NEP master in some specific IP')
|
|
448
|
+
.action(async (ip) => {
|
|
432
449
|
|
|
433
|
-
const interfaces = os.networkInterfaces();
|
|
434
450
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
console.log(`Wi-Fi IP Address: ${wifiIPv4.address}`);
|
|
441
|
-
try {
|
|
442
|
-
var node = new nep.Node("nep-cli");
|
|
443
|
-
nep_configuration["IP"] = wifiIPv4.address;
|
|
444
|
-
var master = new MasterLocal(IP = wifiIPv4.address);
|
|
445
|
-
var info = new nep.MasterInfoServer(IP = wifiIPv4.address, topics = topic_register);
|
|
446
|
-
} catch (error) {
|
|
447
|
-
if (error.message.includes('EADDRINUSE')) {
|
|
448
|
-
console.error("Error: Address already in use. Another instance of NEP master might be running.");
|
|
449
|
-
} else {
|
|
450
|
-
console.error("An error occurred:", error.message);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
451
|
+
console.log(`IP Address: ${ip}`);
|
|
452
|
+
var node = new nep.Node("nep-cli");
|
|
453
|
+
nep_configuration["IP"] = ip;
|
|
454
|
+
var master = new MasterLocal(IP = ip);
|
|
455
|
+
var info = new nep.MasterInfoServer(IP = ip, topics = topic_register);
|
|
453
456
|
|
|
454
|
-
} else {
|
|
455
|
-
console.log('No Wi-Fi IPv4 address found.');
|
|
456
|
-
}
|
|
457
|
-
} else {
|
|
458
|
-
console.log('Wi-Fi interface not found.');
|
|
459
|
-
}
|
|
460
457
|
});
|
|
461
458
|
|
|
459
|
+
|
|
462
460
|
program
|
|
463
461
|
.command('topics')
|
|
464
462
|
.description('Get list of NEP+ topics')
|
|
@@ -513,7 +511,7 @@ program
|
|
|
513
511
|
});
|
|
514
512
|
|
|
515
513
|
program
|
|
516
|
-
.command('eth
|
|
514
|
+
.command('topics-eth')
|
|
517
515
|
.description('Get list of NEP+ topics over Ethernet')
|
|
518
516
|
.action(async () => {
|
|
519
517
|
const interfaces = os.networkInterfaces();
|
|
@@ -536,7 +534,7 @@ program
|
|
|
536
534
|
|
|
537
535
|
|
|
538
536
|
program
|
|
539
|
-
.command('wifi
|
|
537
|
+
.command('topics-wifi')
|
|
540
538
|
.description('Get list of NEP+ topics over Wi-Fi')
|
|
541
539
|
.action(async () => {
|
|
542
540
|
const interfaces = os.networkInterfaces();
|
|
@@ -601,104 +599,102 @@ program
|
|
|
601
599
|
|
|
602
600
|
|
|
603
601
|
program
|
|
604
|
-
.command('
|
|
605
|
-
.description('
|
|
606
|
-
.action((topic
|
|
607
|
-
|
|
608
|
-
var openpub = function (master_ip = "127.0.0.1") {
|
|
609
|
-
|
|
610
|
-
var pubFunction = function () {
|
|
611
|
-
|
|
612
|
-
var msg = message.replace(/'/g, '"')
|
|
613
|
-
console.log(JSON.parse(msg))
|
|
614
|
-
pub.publish(JSON.parse(msg))
|
|
615
|
-
console.log("Message published")
|
|
602
|
+
.command('listen <topic>')
|
|
603
|
+
.description('Subscribe to a NEP+ topic and display JSON messages')
|
|
604
|
+
.action(async (topic) => {
|
|
605
|
+
const interfaces = os.networkInterfaces();
|
|
616
606
|
|
|
617
|
-
|
|
618
|
-
|
|
607
|
+
var opensub = function (master_ip = "127.0.0.1") {
|
|
608
|
+
var callback = function (msg) {
|
|
609
|
+
var date = new Date();
|
|
610
|
+
var dateString = date.toISOString();
|
|
611
|
+
console.log(dateString);
|
|
619
612
|
|
|
613
|
+
if (msg.length > 10000) {
|
|
614
|
+
console.log("the message is too long to be displayed");
|
|
615
|
+
} else {
|
|
616
|
+
console.log(msg);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
620
619
|
|
|
621
|
-
var node = new nep.Node("nep-cli-
|
|
622
|
-
var
|
|
623
|
-
|
|
624
|
-
}
|
|
620
|
+
var node = new nep.Node("nep-cli-sub");
|
|
621
|
+
var conf = node.hybrid(master_ip);
|
|
622
|
+
sub = node.new_sub(topic, "json", callback, conf);
|
|
623
|
+
};
|
|
625
624
|
|
|
625
|
+
var master_ip = "127.0.0.1";
|
|
626
626
|
async function run() {
|
|
627
|
-
var requester = new zmq.Request;
|
|
628
|
-
var master_ip = "127.0.0.1"
|
|
629
|
-
|
|
627
|
+
var requester = new zmq.Request();
|
|
630
628
|
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
631
629
|
|
|
632
|
-
let msg = { "input": "topics" }
|
|
630
|
+
let msg = { "input": "topics" };
|
|
633
631
|
var message = JSON.stringify(msg);
|
|
634
|
-
await requester.send(message)
|
|
635
|
-
const [result] = await requester.receive()
|
|
636
|
-
var results = JSON.parse(result.toString())
|
|
637
|
-
|
|
638
|
-
if (results["
|
|
639
|
-
console.log("")
|
|
640
|
-
openpub(master_ip)
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
632
|
+
await requester.send(message);
|
|
633
|
+
const [result] = await requester.receive();
|
|
634
|
+
var results = JSON.parse(result.toString());
|
|
635
|
+
|
|
636
|
+
if (results["state"] === "failure") {
|
|
643
637
|
console.log("Topic is not registered");
|
|
638
|
+
} else {
|
|
639
|
+
console.log("");
|
|
640
|
+
if (results["input"].includes(topic)) {
|
|
641
|
+
opensub(master_ip);
|
|
642
|
+
} else {
|
|
643
|
+
console.log("Topic is not registered");
|
|
644
|
+
}
|
|
644
645
|
}
|
|
645
646
|
}
|
|
646
|
-
run()
|
|
647
|
-
});
|
|
648
|
-
|
|
649
647
|
|
|
648
|
+
run();
|
|
649
|
+
});
|
|
650
650
|
|
|
651
651
|
program
|
|
652
|
-
.command('eth
|
|
653
|
-
.description('
|
|
654
|
-
.action((topic
|
|
655
|
-
|
|
652
|
+
.command('listen-eth <topic>')
|
|
653
|
+
.description('Subscribe to a NEP+ topic over Ethernet and display JSON messages')
|
|
654
|
+
.action(async (topic) => {
|
|
656
655
|
const interfaces = os.networkInterfaces();
|
|
657
656
|
|
|
658
|
-
var
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
console.log(JSON.parse(msg))
|
|
664
|
-
pub.publish(JSON.parse(msg))
|
|
665
|
-
console.log("Message published")
|
|
666
|
-
|
|
667
|
-
process.exit(1)
|
|
668
|
-
}
|
|
657
|
+
var opensub = function (master_ip = "127.0.0.1") {
|
|
658
|
+
var callback = function (msg) {
|
|
659
|
+
var date = new Date();
|
|
660
|
+
var dateString = date.toISOString();
|
|
661
|
+
console.log(dateString);
|
|
669
662
|
|
|
663
|
+
if (msg.length > 10000) {
|
|
664
|
+
console.log("the message is too long to be displayed");
|
|
665
|
+
} else {
|
|
666
|
+
console.log(msg);
|
|
667
|
+
}
|
|
668
|
+
};
|
|
670
669
|
|
|
671
|
-
var node = new nep.Node("nep-cli-
|
|
672
|
-
var
|
|
673
|
-
|
|
674
|
-
}
|
|
670
|
+
var node = new nep.Node("nep-cli-sub");
|
|
671
|
+
var conf = node.hybrid(master_ip);
|
|
672
|
+
sub = node.new_sub(topic, "json", callback, conf);
|
|
673
|
+
};
|
|
675
674
|
|
|
676
675
|
async function run(master_ip) {
|
|
677
676
|
var requester = new zmq.Request();
|
|
678
|
-
requester.connect(
|
|
677
|
+
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
679
678
|
|
|
680
679
|
let msg = { "input": "topics" };
|
|
681
680
|
var message = JSON.stringify(msg);
|
|
681
|
+
await requester.send(message);
|
|
682
|
+
const [result] = await requester.receive();
|
|
683
|
+
var results = JSON.parse(result.toString());
|
|
682
684
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
var results = JSON.parse(result.toString());
|
|
688
|
-
|
|
685
|
+
if (results["state"] === "failure") {
|
|
686
|
+
console.log("Topic is not registered");
|
|
687
|
+
} else {
|
|
688
|
+
console.log("");
|
|
689
689
|
if (results["input"].includes(topic)) {
|
|
690
|
-
|
|
691
|
-
openpub(master_ip);
|
|
690
|
+
opensub(master_ip);
|
|
692
691
|
} else {
|
|
693
692
|
console.log("Topic is not registered");
|
|
694
693
|
}
|
|
695
|
-
} catch (error) {
|
|
696
|
-
console.error("Error:", error.message);
|
|
697
|
-
} finally {
|
|
698
|
-
process.exit(1)
|
|
699
694
|
}
|
|
700
695
|
}
|
|
701
696
|
|
|
697
|
+
// Find Ethernet interface
|
|
702
698
|
const ethernetInterface = interfaces['Ethernet'] || interfaces['Ethernet 2'] || interfaces['eth0'] || interfaces['イーサネット'] || interfaces['enp0s10'];
|
|
703
699
|
if (ethernetInterface) {
|
|
704
700
|
const ethernetIPv4 = ethernetInterface.find(iface => iface.family === 'IPv4');
|
|
@@ -714,61 +710,56 @@ program
|
|
|
714
710
|
});
|
|
715
711
|
|
|
716
712
|
program
|
|
717
|
-
.command('wifi
|
|
718
|
-
.description('
|
|
719
|
-
.action((topic
|
|
720
|
-
|
|
713
|
+
.command('listen-wifi <topic>')
|
|
714
|
+
.description('Subscribe to a NEP+ topic over Wi-Fi and display JSON messages')
|
|
715
|
+
.action(async (topic) => {
|
|
721
716
|
const interfaces = os.networkInterfaces();
|
|
722
717
|
|
|
723
|
-
var
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
console.log(JSON.parse(msg))
|
|
729
|
-
pub.publish(JSON.parse(msg))
|
|
730
|
-
console.log("Message published")
|
|
731
|
-
|
|
732
|
-
process.exit(1)
|
|
733
|
-
}
|
|
718
|
+
var opensub = function (master_ip = "127.0.0.1") {
|
|
719
|
+
var callback = function (msg) {
|
|
720
|
+
var date = new Date();
|
|
721
|
+
var dateString = date.toISOString();
|
|
722
|
+
console.log(dateString);
|
|
734
723
|
|
|
724
|
+
if (msg.length > 10000) {
|
|
725
|
+
console.log("the message is too long to be displayed");
|
|
726
|
+
} else {
|
|
727
|
+
console.log(msg);
|
|
728
|
+
}
|
|
729
|
+
};
|
|
735
730
|
|
|
736
|
-
var node = new nep.Node("nep-cli-
|
|
737
|
-
var
|
|
738
|
-
|
|
739
|
-
}
|
|
731
|
+
var node = new nep.Node("nep-cli-sub");
|
|
732
|
+
var conf = node.hybrid(master_ip);
|
|
733
|
+
sub = node.new_sub(topic, "json", callback, conf);
|
|
734
|
+
};
|
|
740
735
|
|
|
741
736
|
async function run(master_ip) {
|
|
742
737
|
var requester = new zmq.Request();
|
|
743
|
-
requester.connect(
|
|
738
|
+
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
744
739
|
|
|
745
740
|
let msg = { "input": "topics" };
|
|
746
741
|
var message = JSON.stringify(msg);
|
|
742
|
+
await requester.send(message);
|
|
743
|
+
const [result] = await requester.receive();
|
|
744
|
+
var results = JSON.parse(result.toString());
|
|
747
745
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
var results = JSON.parse(result.toString());
|
|
753
|
-
|
|
746
|
+
if (results["state"] === "failure") {
|
|
747
|
+
console.log("Topic is not registered");
|
|
748
|
+
} else {
|
|
749
|
+
console.log("");
|
|
754
750
|
if (results["input"].includes(topic)) {
|
|
755
|
-
|
|
756
|
-
openpub(master_ip);
|
|
751
|
+
opensub(master_ip);
|
|
757
752
|
} else {
|
|
758
753
|
console.log("Topic is not registered");
|
|
759
754
|
}
|
|
760
|
-
} catch (error) {
|
|
761
|
-
console.error("Error:", error.message);
|
|
762
|
-
} finally {
|
|
763
|
-
process.exit(1)
|
|
764
755
|
}
|
|
765
756
|
}
|
|
757
|
+
|
|
766
758
|
const wifiInterface = interfaces['Wi-Fi'] || interfaces['Wi-Fi 2'] || interfaces['wlan0'] || interfaces['wlo1'];
|
|
767
759
|
if (wifiInterface) {
|
|
768
760
|
const wifiIPv4 = wifiInterface.find(iface => iface.family === 'IPv4');
|
|
769
761
|
if (wifiIPv4) {
|
|
770
|
-
|
|
771
|
-
run(wifiIPv4.address)
|
|
762
|
+
run(wifiIPv4.address);
|
|
772
763
|
} else {
|
|
773
764
|
console.log('No Wi-Fi IPv4 address found.');
|
|
774
765
|
}
|
|
@@ -779,8 +770,8 @@ program
|
|
|
779
770
|
|
|
780
771
|
|
|
781
772
|
program
|
|
782
|
-
.command('
|
|
783
|
-
.description('Subscribe to a NEP+ topic')
|
|
773
|
+
.command('echo <topic>')
|
|
774
|
+
.description('Subscribe to a NEP+ topic and display raw string messages')
|
|
784
775
|
.action(async (topic) => {
|
|
785
776
|
const interfaces = os.networkInterfaces();
|
|
786
777
|
|
|
@@ -799,28 +790,421 @@ program
|
|
|
799
790
|
|
|
800
791
|
var node = new nep.Node("nep-cli-sub");
|
|
801
792
|
var conf = node.hybrid(master_ip);
|
|
802
|
-
sub = node.new_sub(topic, "
|
|
793
|
+
sub = node.new_sub(topic, "string", callback, conf);
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
var master_ip = "127.0.0.1";
|
|
797
|
+
async function run() {
|
|
798
|
+
var requester = new zmq.Request();
|
|
799
|
+
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
800
|
+
|
|
801
|
+
let msg = { "input": "topics" };
|
|
802
|
+
var message = JSON.stringify(msg);
|
|
803
|
+
await requester.send(message);
|
|
804
|
+
const [result] = await requester.receive();
|
|
805
|
+
var results = JSON.parse(result.toString());
|
|
806
|
+
|
|
807
|
+
if (results["state"] === "failure") {
|
|
808
|
+
console.log("Topic is not registered");
|
|
809
|
+
} else {
|
|
810
|
+
console.log("");
|
|
811
|
+
if (results["input"].includes(topic)) {
|
|
812
|
+
opensub(master_ip);
|
|
813
|
+
} else {
|
|
814
|
+
console.log("Topic is not registered");
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
run();
|
|
820
|
+
});
|
|
821
|
+
|
|
822
|
+
program
|
|
823
|
+
.command('echo-eth <topic>')
|
|
824
|
+
.description('Subscribe to a NEP+ topic over Ethernet and display raw string messages')
|
|
825
|
+
.action(async (topic) => {
|
|
826
|
+
const interfaces = os.networkInterfaces();
|
|
827
|
+
|
|
828
|
+
var opensub = function (master_ip = "127.0.0.1") {
|
|
829
|
+
var callback = function (msg) {
|
|
830
|
+
var date = new Date();
|
|
831
|
+
var dateString = date.toISOString();
|
|
832
|
+
console.log(dateString);
|
|
833
|
+
|
|
834
|
+
if (msg.length > 10000) {
|
|
835
|
+
console.log("the message is too long to be displayed");
|
|
836
|
+
} else {
|
|
837
|
+
console.log(msg);
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
var node = new nep.Node("nep-cli-sub");
|
|
842
|
+
var conf = node.hybrid(master_ip);
|
|
843
|
+
sub = node.new_sub(topic, "string", callback, conf);
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
async function run(master_ip) {
|
|
847
|
+
var requester = new zmq.Request();
|
|
848
|
+
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
849
|
+
|
|
850
|
+
let msg = { "input": "topics" };
|
|
851
|
+
var message = JSON.stringify(msg);
|
|
852
|
+
await requester.send(message);
|
|
853
|
+
const [result] = await requester.receive();
|
|
854
|
+
var results = JSON.parse(result.toString());
|
|
855
|
+
|
|
856
|
+
if (results["state"] === "failure") {
|
|
857
|
+
console.log("Topic is not registered");
|
|
858
|
+
} else {
|
|
859
|
+
console.log("");
|
|
860
|
+
if (results["input"].includes(topic)) {
|
|
861
|
+
opensub(master_ip);
|
|
862
|
+
} else {
|
|
863
|
+
console.log("Topic is not registered");
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// Find Ethernet interface
|
|
869
|
+
const ethernetInterface = interfaces['Ethernet'] || interfaces['Ethernet 2'] || interfaces['eth0'] || interfaces['イーサネット'] || interfaces['enp0s10'];
|
|
870
|
+
if (ethernetInterface) {
|
|
871
|
+
const ethernetIPv4 = ethernetInterface.find(iface => iface.family === 'IPv4');
|
|
872
|
+
if (ethernetIPv4) {
|
|
873
|
+
console.log(`Ethernet IP Address: ${ethernetIPv4.address}`);
|
|
874
|
+
run(ethernetIPv4.address)
|
|
875
|
+
} else {
|
|
876
|
+
console.log('No Ethernet IPv4 address found.');
|
|
877
|
+
}
|
|
878
|
+
} else {
|
|
879
|
+
console.log('Ethernet interface not found.');
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
program
|
|
884
|
+
.command('echo-wifi <topic>')
|
|
885
|
+
.description('Subscribe to a NEP+ topic over Wi-Fi and display raw string messages')
|
|
886
|
+
.action(async (topic) => {
|
|
887
|
+
const interfaces = os.networkInterfaces();
|
|
888
|
+
|
|
889
|
+
var opensub = function (master_ip = "127.0.0.1") {
|
|
890
|
+
var callback = function (msg) {
|
|
891
|
+
var date = new Date();
|
|
892
|
+
var dateString = date.toISOString();
|
|
893
|
+
console.log(dateString);
|
|
894
|
+
|
|
895
|
+
if (msg.length > 10000) {
|
|
896
|
+
console.log("the message is too long to be displayed");
|
|
897
|
+
} else {
|
|
898
|
+
console.log(msg);
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
|
|
902
|
+
var node = new nep.Node("nep-cli-sub");
|
|
903
|
+
var conf = node.hybrid(master_ip);
|
|
904
|
+
sub = node.new_sub(topic, "string", callback, conf);
|
|
905
|
+
};
|
|
906
|
+
|
|
907
|
+
async function run(master_ip) {
|
|
908
|
+
var requester = new zmq.Request();
|
|
909
|
+
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
910
|
+
|
|
911
|
+
let msg = { "input": "topics" };
|
|
912
|
+
var message = JSON.stringify(msg);
|
|
913
|
+
await requester.send(message);
|
|
914
|
+
const [result] = await requester.receive();
|
|
915
|
+
var results = JSON.parse(result.toString());
|
|
916
|
+
|
|
917
|
+
if (results["state"] === "failure") {
|
|
918
|
+
console.log("Topic is not registered");
|
|
919
|
+
} else {
|
|
920
|
+
console.log("");
|
|
921
|
+
if (results["input"].includes(topic)) {
|
|
922
|
+
opensub(master_ip);
|
|
923
|
+
} else {
|
|
924
|
+
console.log("Topic is not registered");
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
const wifiInterface = interfaces['Wi-Fi'] || interfaces['Wi-Fi 2'] || interfaces['wlan0'] || interfaces['wlo1'];
|
|
930
|
+
if (wifiInterface) {
|
|
931
|
+
const wifiIPv4 = wifiInterface.find(iface => iface.family === 'IPv4');
|
|
932
|
+
if (wifiIPv4) {
|
|
933
|
+
run(wifiIPv4.address);
|
|
934
|
+
} else {
|
|
935
|
+
console.log('No Wi-Fi IPv4 address found.');
|
|
936
|
+
}
|
|
937
|
+
} else {
|
|
938
|
+
console.log('Wi-Fi interface not found.');
|
|
939
|
+
}
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
program
|
|
943
|
+
.command('publish <topic> <message>')
|
|
944
|
+
.description('Publish a message to a NEP+ topic')
|
|
945
|
+
.action((topic, message) => {
|
|
946
|
+
|
|
947
|
+
var openpub = function (master_ip = "127.0.0.1") {
|
|
948
|
+
|
|
949
|
+
var pubFunction = function () {
|
|
950
|
+
|
|
951
|
+
var msg = message.replace(/'/g, '"')
|
|
952
|
+
console.log(JSON.parse(msg))
|
|
953
|
+
pub.publish(JSON.parse(msg))
|
|
954
|
+
console.log("Message published")
|
|
955
|
+
|
|
956
|
+
process.exit(1)
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
|
|
960
|
+
var node = new nep.Node("nep-cli-pub")
|
|
961
|
+
var pub = node.new_pub(topic, "json")
|
|
962
|
+
setTimeout(pubFunction, 1000)
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
async function run() {
|
|
966
|
+
var requester = new zmq.Request;
|
|
967
|
+
var master_ip = "127.0.0.1"
|
|
968
|
+
|
|
969
|
+
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
970
|
+
|
|
971
|
+
let msg = { "input": "topics" }
|
|
972
|
+
var message = JSON.stringify(msg);
|
|
973
|
+
await requester.send(message)
|
|
974
|
+
const [result] = await requester.receive()
|
|
975
|
+
var results = JSON.parse(result.toString())
|
|
976
|
+
//console.log(results);
|
|
977
|
+
if (results["input"].includes(topic)) {
|
|
978
|
+
console.log("")
|
|
979
|
+
openpub(master_ip)
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
console.log("Topic is not registered");
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
run()
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
program
|
|
989
|
+
.command('publish-eth <topic> <message>')
|
|
990
|
+
.description('Publish a JSON message to a NEP+ topic over Ethernet')
|
|
991
|
+
.action((topic, message) => {
|
|
992
|
+
|
|
993
|
+
const interfaces = os.networkInterfaces();
|
|
994
|
+
|
|
995
|
+
var openpub = function (master_ip = "127.0.0.1") {
|
|
996
|
+
|
|
997
|
+
var pubFunction = function () {
|
|
998
|
+
|
|
999
|
+
var msg = message.replace(/'/g, '"')
|
|
1000
|
+
console.log(JSON.parse(msg))
|
|
1001
|
+
pub.publish(JSON.parse(msg))
|
|
1002
|
+
console.log("Message published")
|
|
1003
|
+
|
|
1004
|
+
process.exit(1)
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
var node = new nep.Node("nep-cli-pub")
|
|
1009
|
+
var pub = node.new_pub(topic, "json")
|
|
1010
|
+
setTimeout(pubFunction, 1000)
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
async function run(master_ip) {
|
|
1014
|
+
var requester = new zmq.Request();
|
|
1015
|
+
requester.connect(`tcp://${master_ip}:${PORT_MASTER_INFO}`);
|
|
1016
|
+
|
|
1017
|
+
let msg = { "input": "topics" };
|
|
1018
|
+
var message = JSON.stringify(msg);
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
try {
|
|
1022
|
+
await requester.send(message);
|
|
1023
|
+
const [result] = await Promise.race([requester.receive(), timeoutPromise(5000)]); // Timeout of 5 seconds
|
|
1024
|
+
var results = JSON.parse(result.toString());
|
|
1025
|
+
|
|
1026
|
+
if (results["input"].includes(topic)) {
|
|
1027
|
+
console.log("");
|
|
1028
|
+
openpub(master_ip);
|
|
1029
|
+
} else {
|
|
1030
|
+
console.log("Topic is not registered");
|
|
1031
|
+
}
|
|
1032
|
+
} catch (error) {
|
|
1033
|
+
console.error("Error:", error.message);
|
|
1034
|
+
} finally {
|
|
1035
|
+
process.exit(1)
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
const ethernetInterface = interfaces['Ethernet'] || interfaces['Ethernet 2'] || interfaces['eth0'] || interfaces['イーサネット'] || interfaces['enp0s10'];
|
|
1040
|
+
if (ethernetInterface) {
|
|
1041
|
+
const ethernetIPv4 = ethernetInterface.find(iface => iface.family === 'IPv4');
|
|
1042
|
+
if (ethernetIPv4) {
|
|
1043
|
+
console.log(`Ethernet IP Address: ${ethernetIPv4.address}`);
|
|
1044
|
+
run(ethernetIPv4.address)
|
|
1045
|
+
} else {
|
|
1046
|
+
console.log('No Ethernet IPv4 address found.');
|
|
1047
|
+
}
|
|
1048
|
+
} else {
|
|
1049
|
+
console.log('Ethernet interface not found.');
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
|
|
1053
|
+
program
|
|
1054
|
+
.command('publish-wifi <topic> <message>')
|
|
1055
|
+
.description('Publish a JSON message to a NEP+ topic over Wi-Fi')
|
|
1056
|
+
.action((topic, message) => {
|
|
1057
|
+
|
|
1058
|
+
const interfaces = os.networkInterfaces();
|
|
1059
|
+
|
|
1060
|
+
var openpub = function (master_ip = "127.0.0.1") {
|
|
1061
|
+
|
|
1062
|
+
var pubFunction = function () {
|
|
1063
|
+
|
|
1064
|
+
var msg = message.replace(/'/g, '"')
|
|
1065
|
+
console.log(JSON.parse(msg))
|
|
1066
|
+
pub.publish(JSON.parse(msg))
|
|
1067
|
+
console.log("Message published")
|
|
1068
|
+
|
|
1069
|
+
process.exit(1)
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
var node = new nep.Node("nep-cli-pub")
|
|
1074
|
+
var pub = node.new_pub(topic, "json")
|
|
1075
|
+
setTimeout(pubFunction, 1000)
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
async function run(master_ip) {
|
|
1079
|
+
var requester = new zmq.Request();
|
|
1080
|
+
requester.connect(`tcp://${master_ip}:${PORT_MASTER_INFO}`);
|
|
1081
|
+
|
|
1082
|
+
let msg = { "input": "topics" };
|
|
1083
|
+
var message = JSON.stringify(msg);
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
try {
|
|
1087
|
+
await requester.send(message);
|
|
1088
|
+
const [result] = await Promise.race([requester.receive(), timeoutPromise(5000)]); // Timeout of 5 seconds
|
|
1089
|
+
var results = JSON.parse(result.toString());
|
|
1090
|
+
|
|
1091
|
+
if (results["input"].includes(topic)) {
|
|
1092
|
+
console.log("");
|
|
1093
|
+
openpub(master_ip);
|
|
1094
|
+
} else {
|
|
1095
|
+
console.log("Topic is not registered");
|
|
1096
|
+
}
|
|
1097
|
+
} catch (error) {
|
|
1098
|
+
console.error("Error:", error.message);
|
|
1099
|
+
} finally {
|
|
1100
|
+
process.exit(1)
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
const wifiInterface = interfaces['Wi-Fi'] || interfaces['Wi-Fi 2'] || interfaces['wlan0'] || interfaces['wlo1'];
|
|
1104
|
+
if (wifiInterface) {
|
|
1105
|
+
const wifiIPv4 = wifiInterface.find(iface => iface.family === 'IPv4');
|
|
1106
|
+
if (wifiIPv4) {
|
|
1107
|
+
console.log(`Wi-Fi IP Address: ${wifiIPv4.address}`);
|
|
1108
|
+
run(wifiIPv4.address)
|
|
1109
|
+
} else {
|
|
1110
|
+
console.log('No Wi-Fi IPv4 address found.');
|
|
1111
|
+
}
|
|
1112
|
+
} else {
|
|
1113
|
+
console.log('Wi-Fi interface not found.');
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
program
|
|
1119
|
+
.command('hz <topic>')
|
|
1120
|
+
.description('Monitor the publishing rate of a NEP+ topic in localhost')
|
|
1121
|
+
.action(async (topic) => {
|
|
1122
|
+
const interfaces = os.networkInterfaces();
|
|
1123
|
+
const master_ip = "127.0.0.1"; // Change to the appropriate master IP
|
|
1124
|
+
|
|
1125
|
+
const opensub = function () {
|
|
1126
|
+
const timestamps = []; // To store message timestamps
|
|
1127
|
+
|
|
1128
|
+
const callback = function (msg) {
|
|
1129
|
+
const date = new Date();
|
|
1130
|
+
const timestamp = date.getTime();
|
|
1131
|
+
|
|
1132
|
+
timestamps.push(timestamp);
|
|
1133
|
+
|
|
1134
|
+
// Remove timestamps older than ten seconds
|
|
1135
|
+
const tenSecondsAgo = timestamp - 10000;
|
|
1136
|
+
while (timestamps[0] < tenSecondsAgo) {
|
|
1137
|
+
timestamps.shift();
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
|
|
1141
|
+
const messageFormat = topic.endsWith("/image") ? "string" : "string";
|
|
1142
|
+
const node = new nep.Node("nep-cli-sub");
|
|
1143
|
+
const conf = node.hybrid(master_ip);
|
|
1144
|
+
const sub = node.new_sub(topic, messageFormat, callback, conf);
|
|
1145
|
+
|
|
1146
|
+
setInterval(() => {
|
|
1147
|
+
// Calculate statistics for the last 10 seconds
|
|
1148
|
+
const now = Date.now();
|
|
1149
|
+
const tenSecondsAgo = now - 10000;
|
|
1150
|
+
const recentTimestamps = timestamps.filter((ts) => ts > tenSecondsAgo);
|
|
1151
|
+
const rate = recentTimestamps.length / 10; // Messages per second for a 10-second window
|
|
1152
|
+
|
|
1153
|
+
console.log("Average rate:", rate.toFixed(2), "Hz");
|
|
1154
|
+
console.log("Min:", (10 / Math.max(rate, 0.1)).toFixed(2), "s");
|
|
1155
|
+
console.log("Max:", (10 / Math.min(rate, 10)).toFixed(2), "s");
|
|
1156
|
+
console.log("Std dev:", calculateStdDev(recentTimestamps, now).toFixed(2), "s");
|
|
1157
|
+
console.log("Window:", recentTimestamps.length);
|
|
1158
|
+
console.log("");
|
|
1159
|
+
}, 1000);
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
const calculateStdDev = (timestamps) => {
|
|
1163
|
+
if (timestamps.length < 2) {
|
|
1164
|
+
return 0; // Standard deviation is not meaningful with less than two timestamps
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
// Calculate the time intervals between consecutive timestamps
|
|
1168
|
+
const timeIntervals = [];
|
|
1169
|
+
for (let i = 1; i < timestamps.length; i++) {
|
|
1170
|
+
const interval = timestamps[i] - timestamps[i - 1];
|
|
1171
|
+
timeIntervals.push(interval);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
// Calculate the mean (average) of the time intervals
|
|
1175
|
+
const mean = timeIntervals.reduce((acc, val) => acc + val, 0) / timeIntervals.length;
|
|
1176
|
+
|
|
1177
|
+
// Calculate the squared differences from the mean
|
|
1178
|
+
const squaredDifferences = timeIntervals.map((interval) => Math.pow(interval - mean, 2));
|
|
1179
|
+
|
|
1180
|
+
// Calculate the mean of the squared differences
|
|
1181
|
+
const meanSquaredDifference = squaredDifferences.reduce((acc, val) => acc + val, 0) / squaredDifferences.length;
|
|
1182
|
+
|
|
1183
|
+
// Calculate the square root of the mean squared difference
|
|
1184
|
+
const stdDeviation = Math.sqrt(meanSquaredDifference);
|
|
1185
|
+
|
|
1186
|
+
return stdDeviation;
|
|
803
1187
|
};
|
|
804
1188
|
|
|
805
|
-
|
|
1189
|
+
|
|
806
1190
|
async function run() {
|
|
807
|
-
|
|
808
|
-
requester.connect(
|
|
1191
|
+
const requester = new zmq.Request();
|
|
1192
|
+
requester.connect(`tcp://${master_ip}:${PORT_MASTER_INFO}`);
|
|
809
1193
|
|
|
810
|
-
|
|
811
|
-
|
|
1194
|
+
const msg = { "input": "topics" };
|
|
1195
|
+
const message = JSON.stringify(msg);
|
|
812
1196
|
await requester.send(message);
|
|
813
1197
|
const [result] = await requester.receive();
|
|
814
|
-
|
|
1198
|
+
const results = JSON.parse(result.toString());
|
|
815
1199
|
|
|
816
1200
|
if (results["state"] === "failure") {
|
|
817
|
-
console.log("Topic is not registered");
|
|
1201
|
+
console.log("Topic is not registered, use *nep topics* to see the list of avaliable topics");
|
|
818
1202
|
} else {
|
|
819
1203
|
console.log("");
|
|
820
1204
|
if (results["input"].includes(topic)) {
|
|
821
|
-
opensub(
|
|
1205
|
+
opensub();
|
|
822
1206
|
} else {
|
|
823
|
-
console.log("Topic is not registered");
|
|
1207
|
+
console.log("Topic is not registered, use *nep topics* to see the list of avaliable topics");
|
|
824
1208
|
}
|
|
825
1209
|
}
|
|
826
1210
|
}
|
|
@@ -828,14 +1212,15 @@ program
|
|
|
828
1212
|
run();
|
|
829
1213
|
});
|
|
830
1214
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
.
|
|
1215
|
+
|
|
1216
|
+
program
|
|
1217
|
+
.command('hz-wifi <topic>')
|
|
1218
|
+
.description('Monitor the publishing rate of a NEP+ topic over Wi-Fi')
|
|
834
1219
|
.action(async (topic) => {
|
|
835
1220
|
const interfaces = os.networkInterfaces();
|
|
836
|
-
const master_ip = "127.0.0.1"; // Change to the appropriate master IP
|
|
837
1221
|
|
|
838
|
-
|
|
1222
|
+
|
|
1223
|
+
const opensub = function (master_ip) {
|
|
839
1224
|
const timestamps = []; // To store message timestamps
|
|
840
1225
|
|
|
841
1226
|
const callback = function (msg) {
|
|
@@ -876,31 +1261,31 @@ program
|
|
|
876
1261
|
if (timestamps.length < 2) {
|
|
877
1262
|
return 0; // Standard deviation is not meaningful with less than two timestamps
|
|
878
1263
|
}
|
|
879
|
-
|
|
1264
|
+
|
|
880
1265
|
// Calculate the time intervals between consecutive timestamps
|
|
881
1266
|
const timeIntervals = [];
|
|
882
1267
|
for (let i = 1; i < timestamps.length; i++) {
|
|
883
1268
|
const interval = timestamps[i] - timestamps[i - 1];
|
|
884
1269
|
timeIntervals.push(interval);
|
|
885
1270
|
}
|
|
886
|
-
|
|
1271
|
+
|
|
887
1272
|
// Calculate the mean (average) of the time intervals
|
|
888
1273
|
const mean = timeIntervals.reduce((acc, val) => acc + val, 0) / timeIntervals.length;
|
|
889
|
-
|
|
1274
|
+
|
|
890
1275
|
// Calculate the squared differences from the mean
|
|
891
1276
|
const squaredDifferences = timeIntervals.map((interval) => Math.pow(interval - mean, 2));
|
|
892
|
-
|
|
1277
|
+
|
|
893
1278
|
// Calculate the mean of the squared differences
|
|
894
1279
|
const meanSquaredDifference = squaredDifferences.reduce((acc, val) => acc + val, 0) / squaredDifferences.length;
|
|
895
|
-
|
|
1280
|
+
|
|
896
1281
|
// Calculate the square root of the mean squared difference
|
|
897
1282
|
const stdDeviation = Math.sqrt(meanSquaredDifference);
|
|
898
|
-
|
|
1283
|
+
|
|
899
1284
|
return stdDeviation;
|
|
900
1285
|
};
|
|
901
|
-
|
|
902
1286
|
|
|
903
|
-
|
|
1287
|
+
|
|
1288
|
+
async function run(master_ip) {
|
|
904
1289
|
const requester = new zmq.Request();
|
|
905
1290
|
requester.connect(`tcp://${master_ip}:${PORT_MASTER_INFO}`);
|
|
906
1291
|
|
|
@@ -915,136 +1300,136 @@ program
|
|
|
915
1300
|
} else {
|
|
916
1301
|
console.log("");
|
|
917
1302
|
if (results["input"].includes(topic)) {
|
|
918
|
-
opensub();
|
|
1303
|
+
opensub(master_ip);
|
|
919
1304
|
} else {
|
|
920
1305
|
console.log("Topic is not registered, use *nep topics* to see the list of avaliable topics");
|
|
921
1306
|
}
|
|
922
1307
|
}
|
|
923
1308
|
}
|
|
924
1309
|
|
|
925
|
-
|
|
1310
|
+
const wifiInterface = interfaces['Wi-Fi'] || interfaces['Wi-Fi 2'] || interfaces['wlan0'] || interfaces['wlo1'];
|
|
1311
|
+
if (wifiInterface) {
|
|
1312
|
+
const wifiIPv4 = wifiInterface.find(iface => iface.family === 'IPv4');
|
|
1313
|
+
if (wifiIPv4) {
|
|
1314
|
+
console.log(`Wi-Fi IP Address: ${wifiIPv4.address}`);
|
|
1315
|
+
run(wifiIPv4.address)
|
|
1316
|
+
} else {
|
|
1317
|
+
console.log('No Wi-Fi IPv4 address found.');
|
|
1318
|
+
}
|
|
1319
|
+
} else {
|
|
1320
|
+
console.log('Wi-Fi interface not found.');
|
|
1321
|
+
}
|
|
926
1322
|
});
|
|
927
1323
|
|
|
928
1324
|
program
|
|
929
|
-
.command('eth
|
|
930
|
-
.description('
|
|
1325
|
+
.command('hz-eth <topic>')
|
|
1326
|
+
.description('Monitor the publishing rate of a NEP+ topic over Ethernet')
|
|
931
1327
|
.action(async (topic) => {
|
|
932
1328
|
const interfaces = os.networkInterfaces();
|
|
933
1329
|
|
|
934
|
-
var opensub = function (master_ip = "127.0.0.1") {
|
|
935
|
-
var callback = function (msg) {
|
|
936
|
-
var date = new Date();
|
|
937
|
-
var dateString = date.toISOString();
|
|
938
|
-
console.log(dateString);
|
|
939
1330
|
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1331
|
+
const opensub = function (master_ip) {
|
|
1332
|
+
const timestamps = []; // To store message timestamps
|
|
1333
|
+
|
|
1334
|
+
const callback = function (msg) {
|
|
1335
|
+
const date = new Date();
|
|
1336
|
+
const timestamp = date.getTime();
|
|
1337
|
+
|
|
1338
|
+
timestamps.push(timestamp);
|
|
1339
|
+
|
|
1340
|
+
// Remove timestamps older than ten seconds
|
|
1341
|
+
const tenSecondsAgo = timestamp - 10000;
|
|
1342
|
+
while (timestamps[0] < tenSecondsAgo) {
|
|
1343
|
+
timestamps.shift();
|
|
944
1344
|
}
|
|
945
1345
|
};
|
|
946
1346
|
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
async function run(master_ip) {
|
|
953
|
-
var requester = new zmq.Request();
|
|
954
|
-
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
1347
|
+
const messageFormat = topic.endsWith("/image") ? "string" : "string";
|
|
1348
|
+
const node = new nep.Node("nep-cli-sub");
|
|
1349
|
+
const conf = node.hybrid(master_ip);
|
|
1350
|
+
const sub = node.new_sub(topic, messageFormat, callback, conf);
|
|
955
1351
|
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1352
|
+
setInterval(() => {
|
|
1353
|
+
// Calculate statistics for the last 10 seconds
|
|
1354
|
+
const now = Date.now();
|
|
1355
|
+
const tenSecondsAgo = now - 10000;
|
|
1356
|
+
const recentTimestamps = timestamps.filter((ts) => ts > tenSecondsAgo);
|
|
1357
|
+
const rate = recentTimestamps.length / 10; // Messages per second for a 10-second window
|
|
961
1358
|
|
|
962
|
-
|
|
963
|
-
console.log("
|
|
964
|
-
|
|
1359
|
+
console.log("Average rate:", rate.toFixed(2), "Hz");
|
|
1360
|
+
console.log("Min:", (10 / Math.max(rate, 0.1)).toFixed(2), "s");
|
|
1361
|
+
console.log("Max:", (10 / Math.min(rate, 10)).toFixed(2), "s");
|
|
1362
|
+
console.log("Std dev:", calculateStdDev(recentTimestamps, now).toFixed(2), "s");
|
|
1363
|
+
console.log("Window:", recentTimestamps.length);
|
|
965
1364
|
console.log("");
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1365
|
+
}, 1000);
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1368
|
+
const calculateStdDev = (timestamps) => {
|
|
1369
|
+
if (timestamps.length < 2) {
|
|
1370
|
+
return 0; // Standard deviation is not meaningful with less than two timestamps
|
|
971
1371
|
}
|
|
972
|
-
}
|
|
973
1372
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
console.log(`Ethernet IP Address: ${ethernetIPv4.address}`);
|
|
980
|
-
run(ethernetIPv4.address)
|
|
981
|
-
} else {
|
|
982
|
-
console.log('No Ethernet IPv4 address found.');
|
|
1373
|
+
// Calculate the time intervals between consecutive timestamps
|
|
1374
|
+
const timeIntervals = [];
|
|
1375
|
+
for (let i = 1; i < timestamps.length; i++) {
|
|
1376
|
+
const interval = timestamps[i] - timestamps[i - 1];
|
|
1377
|
+
timeIntervals.push(interval);
|
|
983
1378
|
}
|
|
984
|
-
} else {
|
|
985
|
-
console.log('Ethernet interface not found.');
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
1379
|
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
.description('Subscribe to a NEP+ topic over Wi-Fi')
|
|
992
|
-
.action(async (topic) => {
|
|
993
|
-
const interfaces = os.networkInterfaces();
|
|
1380
|
+
// Calculate the mean (average) of the time intervals
|
|
1381
|
+
const mean = timeIntervals.reduce((acc, val) => acc + val, 0) / timeIntervals.length;
|
|
994
1382
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
var date = new Date();
|
|
998
|
-
var dateString = date.toISOString();
|
|
999
|
-
console.log(dateString);
|
|
1383
|
+
// Calculate the squared differences from the mean
|
|
1384
|
+
const squaredDifferences = timeIntervals.map((interval) => Math.pow(interval - mean, 2));
|
|
1000
1385
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
} else {
|
|
1004
|
-
console.log(msg);
|
|
1005
|
-
}
|
|
1006
|
-
};
|
|
1386
|
+
// Calculate the mean of the squared differences
|
|
1387
|
+
const meanSquaredDifference = squaredDifferences.reduce((acc, val) => acc + val, 0) / squaredDifferences.length;
|
|
1007
1388
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1389
|
+
// Calculate the square root of the mean squared difference
|
|
1390
|
+
const stdDeviation = Math.sqrt(meanSquaredDifference);
|
|
1391
|
+
|
|
1392
|
+
return stdDeviation;
|
|
1011
1393
|
};
|
|
1012
1394
|
|
|
1395
|
+
|
|
1013
1396
|
async function run(master_ip) {
|
|
1014
|
-
|
|
1015
|
-
requester.connect(
|
|
1397
|
+
const requester = new zmq.Request();
|
|
1398
|
+
requester.connect(`tcp://${master_ip}:${PORT_MASTER_INFO}`);
|
|
1016
1399
|
|
|
1017
|
-
|
|
1018
|
-
|
|
1400
|
+
const msg = { "input": "topics" };
|
|
1401
|
+
const message = JSON.stringify(msg);
|
|
1019
1402
|
await requester.send(message);
|
|
1020
1403
|
const [result] = await requester.receive();
|
|
1021
|
-
|
|
1404
|
+
const results = JSON.parse(result.toString());
|
|
1022
1405
|
|
|
1023
1406
|
if (results["state"] === "failure") {
|
|
1024
|
-
console.log("Topic is not registered");
|
|
1407
|
+
console.log("Topic is not registered, use *nep topics* to see the list of avaliable topics");
|
|
1025
1408
|
} else {
|
|
1026
1409
|
console.log("");
|
|
1027
1410
|
if (results["input"].includes(topic)) {
|
|
1028
1411
|
opensub(master_ip);
|
|
1029
1412
|
} else {
|
|
1030
|
-
console.log("Topic is not registered");
|
|
1413
|
+
console.log("Topic is not registered, use *nep topics* to see the list of avaliable topics");
|
|
1031
1414
|
}
|
|
1032
1415
|
}
|
|
1033
1416
|
}
|
|
1034
1417
|
|
|
1035
|
-
const
|
|
1036
|
-
if (
|
|
1037
|
-
const
|
|
1038
|
-
if (
|
|
1039
|
-
|
|
1418
|
+
const ethernetInterface = interfaces['Ethernet'] || interfaces['Ethernet 2'] || interfaces['eth0'] || interfaces['イーサネット'] || interfaces['enp0s10'];
|
|
1419
|
+
if (ethernetInterface) {
|
|
1420
|
+
const ethernetIPv4 = ethernetInterface.find(iface => iface.family === 'IPv4');
|
|
1421
|
+
if (ethernetIPv4) {
|
|
1422
|
+
console.log(`Ethernet IP Address: ${ethernetIPv4.address}`);
|
|
1423
|
+
run(ethernetIPv4.address)
|
|
1040
1424
|
} else {
|
|
1041
|
-
console.log('No
|
|
1425
|
+
console.log('No Ethernet IPv4 address found.');
|
|
1042
1426
|
}
|
|
1043
1427
|
} else {
|
|
1044
|
-
console.log('
|
|
1428
|
+
console.log('Ethernet interface not found.');
|
|
1045
1429
|
}
|
|
1046
1430
|
});
|
|
1047
1431
|
|
|
1432
|
+
|
|
1048
1433
|
program
|
|
1049
1434
|
.command('docs')
|
|
1050
1435
|
.description('Open the NEP+ documentation in the default browser')
|
|
@@ -1067,6 +1452,14 @@ function timeoutPromise(ms) {
|
|
|
1067
1452
|
});
|
|
1068
1453
|
}
|
|
1069
1454
|
|
|
1455
|
+
function timeoutPromise(ms) {
|
|
1456
|
+
return new Promise((resolve, reject) => {
|
|
1457
|
+
setTimeout(() => {
|
|
1458
|
+
reject(new Error("Request timed out"));
|
|
1459
|
+
}, ms);
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1070
1463
|
async function getAndDisplayTopics(master_ip) {
|
|
1071
1464
|
const TIMEOUT_DURATION = 5000;
|
|
1072
1465
|
|
|
@@ -1086,7 +1479,7 @@ async function getAndDisplayTopics(master_ip) {
|
|
|
1086
1479
|
|
|
1087
1480
|
const timeoutPromise = new Promise((resolve, reject) => {
|
|
1088
1481
|
setTimeout(() => {
|
|
1089
|
-
reject(new Error("Timed out, NEP master over
|
|
1482
|
+
reject(new Error("Timed out, NEP master over Wi-Fi was not found"));
|
|
1090
1483
|
}, TIMEOUT_DURATION);
|
|
1091
1484
|
});
|
|
1092
1485
|
|
|
@@ -1108,84 +1501,51 @@ async function getAndDisplayTopics(master_ip) {
|
|
|
1108
1501
|
}
|
|
1109
1502
|
}
|
|
1110
1503
|
|
|
1111
|
-
program
|
|
1112
|
-
.command('image <topic>')
|
|
1113
|
-
.description('Start image server')
|
|
1114
|
-
.action((topic, options) => {
|
|
1115
|
-
async function run() {
|
|
1116
|
-
var requester = new zmq.Request;
|
|
1117
|
-
var master_ip = "127.0.0.1"
|
|
1118
|
-
var port = PORT_IMAGE
|
|
1119
|
-
|
|
1120
1504
|
|
|
1121
1505
|
|
|
1122
|
-
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
1123
1506
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
await requester.send(message)
|
|
1127
|
-
const [result] = await requester.receive()
|
|
1128
|
-
var results = JSON.parse(result.toString())
|
|
1129
|
-
//console.log(results);
|
|
1507
|
+
async function getAndDisplayTopics(master_ip) {
|
|
1508
|
+
const TIMEOUT_DURATION = 5000;
|
|
1130
1509
|
|
|
1510
|
+
var requester = new zmq.Request();
|
|
1511
|
+
requester.connect(`tcp://${master_ip}:${PORT_MASTER_INFO}`);
|
|
1131
1512
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1513
|
+
let msg = { "input": "topics" };
|
|
1514
|
+
var message = JSON.stringify(msg);
|
|
1134
1515
|
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
} else if (!filteredList.includes(topic)) {
|
|
1143
|
-
const autoComplete = new AutoComplete({
|
|
1144
|
-
name: 'program',
|
|
1145
|
-
message: 'Invalid program name. Select a valid program:',
|
|
1146
|
-
choices: filteredList,
|
|
1147
|
-
});
|
|
1148
|
-
topic = await autoComplete.run();
|
|
1149
|
-
}
|
|
1516
|
+
try {
|
|
1517
|
+
const responsePromise = new Promise(async (resolve, reject) => {
|
|
1518
|
+
await requester.send(message);
|
|
1519
|
+
const [result] = await requester.receive();
|
|
1520
|
+
var results = JSON.parse(result.toString());
|
|
1521
|
+
resolve(results);
|
|
1522
|
+
});
|
|
1150
1523
|
|
|
1524
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
|
1525
|
+
setTimeout(() => {
|
|
1526
|
+
reject(new Error("Timed out, NEP master over Ethernet was not found"));
|
|
1527
|
+
}, TIMEOUT_DURATION);
|
|
1528
|
+
});
|
|
1151
1529
|
|
|
1152
|
-
|
|
1153
|
-
open(`http://localhost:${port}`);
|
|
1530
|
+
const results = await Promise.race([responsePromise, timeoutPromise]);
|
|
1154
1531
|
|
|
1532
|
+
if (results["state"] === "success") {
|
|
1533
|
+
availableTopics = results["input"];
|
|
1534
|
+
console.log("");
|
|
1535
|
+
results["input"].forEach(element => {
|
|
1536
|
+
console.log(element);
|
|
1537
|
+
});
|
|
1538
|
+
} else {
|
|
1539
|
+
console.log("No topics yet");
|
|
1155
1540
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
// Function to start the server
|
|
1161
|
-
function startServer(port, topic) {
|
|
1162
|
-
const app = express();
|
|
1163
|
-
const server = http.createServer(app);
|
|
1164
|
-
const io = socketIo(server);
|
|
1165
|
-
|
|
1166
|
-
var node = new nep.Node("nep-cli");
|
|
1167
|
-
|
|
1168
|
-
function getImage(msg) {
|
|
1169
|
-
// Send the received image data as-is to connected clients
|
|
1170
|
-
io.sockets.emit('image', { image: msg });
|
|
1541
|
+
} catch (error) {
|
|
1542
|
+
console.error("Error:", error.message);
|
|
1543
|
+
} finally {
|
|
1544
|
+
process.exit();
|
|
1171
1545
|
}
|
|
1172
|
-
|
|
1173
|
-
var sub = node.new_sub(topic, "image", getImage);
|
|
1174
|
-
|
|
1175
|
-
app.get('/', (req, res) => {
|
|
1176
|
-
res.sendFile(__dirname + '/image.html'); // Serve your HTML file
|
|
1177
|
-
});
|
|
1178
|
-
|
|
1179
|
-
server.listen(port, () => {
|
|
1180
|
-
console.log(`Server is running on http://localhost:${port}`);
|
|
1181
|
-
});
|
|
1182
|
-
|
|
1183
|
-
io.on('connection', (socket) => {
|
|
1184
|
-
const frameRate = 30; // Desired frame rate
|
|
1185
|
-
const interval = 1000 / frameRate; // Interval between frames
|
|
1186
|
-
});
|
|
1187
1546
|
}
|
|
1188
1547
|
|
|
1548
|
+
|
|
1189
1549
|
program.parse(process.argv);
|
|
1190
1550
|
|
|
1191
1551
|
|