nep-cli 0.2.0 → 0.2.1
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/index.js +150 -144
- package/package.json +2 -2
- package/bin/image4.html +0 -57
package/bin/index.js
CHANGED
|
@@ -18,49 +18,47 @@ const fs = require('fs');
|
|
|
18
18
|
const zmqc = require("zeromq/v5-compat");
|
|
19
19
|
|
|
20
20
|
const PORT_MASTER_INFO = 50001; // Default port for master info
|
|
21
|
-
const PORT_IMAGES =
|
|
22
|
-
|
|
23
|
-
PORT_IMAGES.push(i);
|
|
24
|
-
}
|
|
21
|
+
const PORT_IMAGES = 50060;
|
|
22
|
+
const PORT_JSON = 50080;
|
|
25
23
|
|
|
26
24
|
|
|
27
25
|
program
|
|
28
|
-
.version(version)
|
|
29
|
-
.description('NEP-CLI')
|
|
26
|
+
.version(version)
|
|
27
|
+
.description('NEP-CLI')
|
|
30
28
|
|
|
31
29
|
program
|
|
32
|
-
.command('ip')
|
|
33
|
-
.description('Display current Wi-Fi and Ethernet IP addresses of this computer')
|
|
34
|
-
.action(() => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
.command('ip')
|
|
31
|
+
.description('Display current Wi-Fi and Ethernet IP addresses of this computer')
|
|
32
|
+
.action(() => {
|
|
33
|
+
try {
|
|
34
|
+
// subsitude by interfaces = nep.getNetworkInterfaces --> {"wifi":wifiInterfaces, "eth":ethernetInterface}
|
|
35
|
+
const platform = os.platform();
|
|
36
|
+
let wifiInterfaces, ethernetInterface;
|
|
37
|
+
|
|
38
|
+
if (platform === 'linux') {
|
|
39
|
+
wifiInterfaces = Object.keys(os.networkInterfaces()).filter(ifname => /^(wlan|wlp|wl|en)\d*$/i.test(ifname));
|
|
40
|
+
ethernetInterface = Object.keys(os.networkInterfaces()).find(ifname => /^(eth|enp|eno)\d*$/i.test(ifname));
|
|
41
|
+
} else if (platform === 'win32') {
|
|
42
|
+
wifiInterfaces = Object.keys(os.networkInterfaces()).filter(ifname => /^(Wireless|Wi-Fi)/i.test(ifname));
|
|
43
|
+
ethernetInterface = Object.keys(os.networkInterfaces()).find(ifname => /^Ethernet/i.test(ifname));
|
|
44
|
+
} else if (platform === 'darwin') {
|
|
45
|
+
wifiInterfaces = Object.keys(os.networkInterfaces()).filter(ifname => /^en\d*$/i.test(ifname));
|
|
46
|
+
ethernetInterface = Object.keys(os.networkInterfaces()).find(ifname => /^en\d*$/i.test(ifname));
|
|
47
|
+
} else {
|
|
48
|
+
console.log('Unsupported operating system.');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
wifiInterfaces.forEach(wifiInterface => {
|
|
53
|
+
const ipAddress = nep.getIPAddress(wifiInterface);
|
|
54
|
+
nep.printIPAddress(`Wi-Fi (${wifiInterface})`, ipAddress);
|
|
55
|
+
});
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
57
|
+
nep.printIPAddress('Ethernet', nep.getIPAddress(ethernetInterface));
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error('An error occurred:', error.message);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
64
62
|
|
|
65
63
|
|
|
66
64
|
|
|
@@ -277,7 +275,7 @@ const processMsg = (json_msg, nodes_register, topic_register) => {
|
|
|
277
275
|
|
|
278
276
|
// Update node info
|
|
279
277
|
nodes_register[node] = pid;
|
|
280
|
-
|
|
278
|
+
|
|
281
279
|
// Check topic status
|
|
282
280
|
const topicStr = String(topic);
|
|
283
281
|
if (topicStr in topic_register) {
|
|
@@ -293,6 +291,78 @@ const processMsg = (json_msg, nodes_register, topic_register) => {
|
|
|
293
291
|
}
|
|
294
292
|
};
|
|
295
293
|
|
|
294
|
+
function startShowServer(port, topic, ip) {
|
|
295
|
+
const app = express();
|
|
296
|
+
const server = http.createServer(app);
|
|
297
|
+
const io = socketIo(server);
|
|
298
|
+
const path = require('path');
|
|
299
|
+
|
|
300
|
+
const node = new nep.Node("nep-cli-sub");
|
|
301
|
+
const config = node.hybrid(ip)
|
|
302
|
+
|
|
303
|
+
function getImage(msg) {
|
|
304
|
+
// Send the received image data as-is to connected clients
|
|
305
|
+
io.sockets.emit('image', { image: msg });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const sub = node.new_sub(topic, "images", getImage, config);
|
|
309
|
+
|
|
310
|
+
app.get('/', (req, res) => {
|
|
311
|
+
res.sendFile(path.join(__dirname, './image.html')); // Serve your HTML file
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
server.listen(port, () => {
|
|
315
|
+
console.log(`Server is running on http://localhost:${port}`);
|
|
316
|
+
}).on('error', err => {
|
|
317
|
+
console.error(`Error starting server: ${err}`);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
io.on('connection', (socket) => {
|
|
321
|
+
const frameRate = 30; // Desired frame rate
|
|
322
|
+
const interval = 1000 / frameRate; // Interval between frames
|
|
323
|
+
}).on('error', err => {
|
|
324
|
+
console.error(`Error with socket connection: ${err}`);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function startJsonServer(port, topic, ip, msg_type = "json") {
|
|
329
|
+
const app = express();
|
|
330
|
+
const server = http.createServer(app);
|
|
331
|
+
const io = socketIo(server);
|
|
332
|
+
const path = require('path');
|
|
333
|
+
|
|
334
|
+
const node = new nep.Node("nep-cli-sub");
|
|
335
|
+
const config = node.hybrid(ip)
|
|
336
|
+
|
|
337
|
+
function getJSON(msg) {
|
|
338
|
+
try {
|
|
339
|
+
|
|
340
|
+
io.sockets.emit('json_data', msg);
|
|
341
|
+
} catch (error) {
|
|
342
|
+
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const sub = node.new_sub(topic, msg_type, getJSON, config);
|
|
347
|
+
|
|
348
|
+
app.get('/', (req, res) => {
|
|
349
|
+
res.sendFile(path.join(__dirname, './json.html')); // Serve your HTML file
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
server.listen(port, () => {
|
|
353
|
+
console.log(`Server is running on http://localhost:${port}`);
|
|
354
|
+
}).on('error', err => {
|
|
355
|
+
console.error(`Error starting server: ${err}`);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
io.on('connection', (socket) => {
|
|
359
|
+
const frameRate = 30; // Desired frame rate
|
|
360
|
+
const interval = 1000 / frameRate; // Interval between frames
|
|
361
|
+
}).on('error', err => {
|
|
362
|
+
console.error(`Error with socket connection: ${err}`);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
296
366
|
|
|
297
367
|
program
|
|
298
368
|
.command('app')
|
|
@@ -369,7 +439,7 @@ program
|
|
|
369
439
|
var node = new nep.Node("nep-cli");
|
|
370
440
|
console.log("Starting NEP master in terminal")
|
|
371
441
|
var master = new MasterLocal();
|
|
372
|
-
var info = new nep.MasterInfoServer(IP = '0.0.0.0', topics = topic_register, port_=PORT_MASTER_INFO);
|
|
442
|
+
var info = new nep.MasterInfoServer(IP = '0.0.0.0', topics = topic_register, port_ = PORT_MASTER_INFO);
|
|
373
443
|
} catch (error) {
|
|
374
444
|
if (error.message.includes('EADDRINUSE')) {
|
|
375
445
|
console.error("Error: Address already in use. Another instance of NEP master might be running.");
|
|
@@ -433,65 +503,45 @@ program
|
|
|
433
503
|
await getTopics(); // Call the function to get topics
|
|
434
504
|
});
|
|
435
505
|
|
|
506
|
+
program
|
|
507
|
+
.command('show <topic> <msg_type> [index]')
|
|
508
|
+
.description('Show images published to a NEP+ topic in the default browser')
|
|
509
|
+
.action(async (topic, msg_type, index = 0) => {
|
|
510
|
+
const ip = "127.0.0.1";
|
|
511
|
+
const topicid = `${topic}`;
|
|
512
|
+
const port = PORT_IMAGES + parseInt(index);
|
|
513
|
+
|
|
514
|
+
const allowedFormats = ["json", "images", "dictionary"];
|
|
515
|
+
if (!allowedFormats.includes(msg_type)) {
|
|
516
|
+
console.error(`Format '${msg_type}' no allowed. Allowed formats are: ${allowedFormats.join(', ')}`);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
436
519
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
console.log(dateString);
|
|
448
|
-
|
|
449
|
-
if (msg.length > 10000) {
|
|
450
|
-
console.log("the message is too long to be displayed");
|
|
451
|
-
} else {
|
|
452
|
-
console.log(msg);
|
|
453
|
-
}
|
|
454
|
-
};
|
|
520
|
+
if(msg_type === "images"){
|
|
521
|
+
open(`http://localhost:${port}/?port=${port}&topic=${encodeURIComponent(topicid)}`);
|
|
522
|
+
startShowServer(port, topic, ip);
|
|
523
|
+
}
|
|
524
|
+
else if (msg_type === "json" || msg_type === "dictionary")
|
|
525
|
+
{
|
|
526
|
+
open(`http://localhost:${port}/?port=${port}&topic=${encodeURIComponent(topicid)}`);
|
|
527
|
+
startJsonServer(port, topic, ip, msg_type);
|
|
528
|
+
}
|
|
529
|
+
});
|
|
455
530
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
531
|
+
program
|
|
532
|
+
.command('echo <topic> <msg_type>')
|
|
533
|
+
.description('Subscribe to a NEP+ topic and display raw string messages')
|
|
534
|
+
.action(async (topic, msg_type) => {
|
|
460
535
|
|
|
461
|
-
var master_ip = "127.0.0.1";
|
|
462
|
-
async function run() {
|
|
463
|
-
var requester = new zmq.Request();
|
|
464
|
-
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
465
536
|
|
|
466
|
-
let msg = { "input": "topics" };
|
|
467
|
-
var message = JSON.stringify(msg);
|
|
468
|
-
await requester.send(message);
|
|
469
|
-
const [result] = await requester.receive();
|
|
470
|
-
var results = JSON.parse(result.toString());
|
|
471
537
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (results["input"].includes(topic)) {
|
|
477
|
-
opensub(master_ip);
|
|
478
|
-
} else {
|
|
479
|
-
console.log("Topic is not registered");
|
|
480
|
-
}
|
|
481
|
-
}
|
|
538
|
+
const allowedFormats = ["json", "msgpack", "bytes", "images", "dictionary", "string"];
|
|
539
|
+
if (!allowedFormats.includes(msg_type)) {
|
|
540
|
+
console.error(`Format '${msg_type}' no allowed. Allowed formats are: ${allowedFormats.join(', ')}`);
|
|
541
|
+
return;
|
|
482
542
|
}
|
|
483
543
|
|
|
484
|
-
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
program
|
|
489
|
-
.command('echo <topic>')
|
|
490
|
-
.description('Subscribe to a NEP+ topic and display raw string messages')
|
|
491
|
-
.action(async (topic) => {
|
|
492
|
-
const interfaces = os.networkInterfaces();
|
|
493
|
-
|
|
494
|
-
var opensub = function (master_ip = "127.0.0.1") {
|
|
544
|
+
var opensub = function (master_ip = "127.0.0.1", msg_type) {
|
|
495
545
|
var callback = function (msg) {
|
|
496
546
|
var date = new Date();
|
|
497
547
|
var dateString = date.toISOString();
|
|
@@ -506,9 +556,10 @@ program
|
|
|
506
556
|
|
|
507
557
|
var node = new nep.Node("nep-cli-sub");
|
|
508
558
|
var conf = node.hybrid(master_ip);
|
|
509
|
-
sub = node.new_sub(topic,
|
|
559
|
+
sub = node.new_sub(topic, msg_type, callback, conf);
|
|
510
560
|
};
|
|
511
561
|
|
|
562
|
+
|
|
512
563
|
var master_ip = "127.0.0.1";
|
|
513
564
|
async function run() {
|
|
514
565
|
var requester = new zmq.Request();
|
|
@@ -525,7 +576,7 @@ program
|
|
|
525
576
|
} else {
|
|
526
577
|
console.log("");
|
|
527
578
|
if (results["input"].includes(topic)) {
|
|
528
|
-
opensub(master_ip);
|
|
579
|
+
opensub(master_ip, msg_type);
|
|
529
580
|
} else {
|
|
530
581
|
console.log("Topic is not registered");
|
|
531
582
|
}
|
|
@@ -535,54 +586,6 @@ program
|
|
|
535
586
|
run();
|
|
536
587
|
});
|
|
537
588
|
|
|
538
|
-
|
|
539
|
-
program
|
|
540
|
-
.command('publish <topic> <message>')
|
|
541
|
-
.description('Publish a message to a NEP+ topic')
|
|
542
|
-
.action((topic, message) => {
|
|
543
|
-
|
|
544
|
-
var openpub = function (master_ip = "127.0.0.1") {
|
|
545
|
-
|
|
546
|
-
var pubFunction = function () {
|
|
547
|
-
|
|
548
|
-
var msg = message.replace(/'/g, '"')
|
|
549
|
-
console.log(JSON.parse(msg))
|
|
550
|
-
pub.publish(JSON.parse(msg))
|
|
551
|
-
console.log("Message published")
|
|
552
|
-
|
|
553
|
-
process.exit(1)
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
var node = new nep.Node("nep-cli-pub")
|
|
558
|
-
var pub = node.new_pub(topic, "json")
|
|
559
|
-
setTimeout(pubFunction, 1000)
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
async function run() {
|
|
563
|
-
var requester = new zmq.Request;
|
|
564
|
-
var master_ip = "127.0.0.1"
|
|
565
|
-
|
|
566
|
-
requester.connect("tcp://" + master_ip + ":" + PORT_MASTER_INFO);
|
|
567
|
-
|
|
568
|
-
let msg = { "input": "topics" }
|
|
569
|
-
var message = JSON.stringify(msg);
|
|
570
|
-
await requester.send(message)
|
|
571
|
-
const [result] = await requester.receive()
|
|
572
|
-
var results = JSON.parse(result.toString())
|
|
573
|
-
//console.log(results);
|
|
574
|
-
if (results["input"].includes(topic)) {
|
|
575
|
-
console.log("")
|
|
576
|
-
openpub(master_ip)
|
|
577
|
-
}
|
|
578
|
-
else {
|
|
579
|
-
console.log("Topic is not registered");
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
run()
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
|
|
586
589
|
program
|
|
587
590
|
.command('hz <topic> <msg_type>')
|
|
588
591
|
.description('Monitor the publishing rate of a NEP+ topic in localhost')
|
|
@@ -606,15 +609,18 @@ program
|
|
|
606
609
|
}
|
|
607
610
|
};
|
|
608
611
|
|
|
609
|
-
const allowedFormats = ["json", "msgpack", "bytes", "images", "
|
|
610
|
-
|
|
612
|
+
const allowedFormats = ["json", "msgpack", "bytes", "images", "dictionary", "string"];
|
|
613
|
+
if (!allowedFormats.includes(msg_type)) {
|
|
614
|
+
console.error(`Format '${msg_type}' no allowed. Allowed formats are: ${allowedFormats.join(', ')}`);
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
611
617
|
const node = new nep.Node("nep-cli-sub");
|
|
612
618
|
const conf = node.hybrid(master_ip);
|
|
613
619
|
|
|
614
620
|
console.log("Topic:", topic)
|
|
615
|
-
console.log("Message type:",
|
|
621
|
+
console.log("Message type:", msg_type)
|
|
616
622
|
|
|
617
|
-
const sub = node.new_sub(topic,
|
|
623
|
+
const sub = node.new_sub(topic, msg_type, callback, conf);
|
|
618
624
|
console.log("");
|
|
619
625
|
|
|
620
626
|
setInterval(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nep-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"main": "./lib/nep.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"nep": "./bin/index.js"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"express": "^4.18.2",
|
|
15
15
|
"fix-path": "^2.1.0",
|
|
16
16
|
"inquirer": "^9.2.10",
|
|
17
|
-
"nep-js": "0.3.
|
|
17
|
+
"nep-js": "0.3.8",
|
|
18
18
|
"open": "7.4.2",
|
|
19
19
|
"socket.io": "^4.7.2",
|
|
20
20
|
"zeromq": "6.0.0-beta.19"
|
package/bin/image4.html
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<title>NEP+ Image</title>
|
|
8
|
-
<!-- Include Vue 2 and Vuetify 2 from CDN -->
|
|
9
|
-
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.6.3/dist/vuetify.min.css" rel="stylesheet">
|
|
10
|
-
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
|
|
11
|
-
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.6.3/dist/vuetify.js"></script>
|
|
12
|
-
</head>
|
|
13
|
-
|
|
14
|
-
<body>
|
|
15
|
-
<div id="app">
|
|
16
|
-
<v-app>
|
|
17
|
-
<v-container>
|
|
18
|
-
<v-toolbar dense color="transparent">
|
|
19
|
-
<v-toolbar-title>Camera USB</v-toolbar-title>
|
|
20
|
-
<v-spacer></v-spacer>
|
|
21
|
-
|
|
22
|
-
</v-toolbar>
|
|
23
|
-
<v-row>
|
|
24
|
-
<v-col>
|
|
25
|
-
<v-card color="#1A1A1A">
|
|
26
|
-
<v-img :src="imageSrc" alt="Streamed Image" contain></v-img>
|
|
27
|
-
</v-card>
|
|
28
|
-
</v-col>
|
|
29
|
-
</v-row>
|
|
30
|
-
</v-container>
|
|
31
|
-
</v-app>
|
|
32
|
-
</div>
|
|
33
|
-
<script src="/socket.io/socket.io.js"></script> <!-- Include the Socket.IO client library -->
|
|
34
|
-
<script>
|
|
35
|
-
// Initialize Vue and Vuetify
|
|
36
|
-
new Vue({
|
|
37
|
-
el: '#app',
|
|
38
|
-
vuetify: new Vuetify(),
|
|
39
|
-
data() {
|
|
40
|
-
return {
|
|
41
|
-
imageSrc: '', // Initialize the image source as empty
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
mounted() {
|
|
45
|
-
const image = document.getElementById('image');
|
|
46
|
-
const socket = io.connect('http://localhost:3000'); // Connect to your server
|
|
47
|
-
|
|
48
|
-
socket.on('image', (data) => {
|
|
49
|
-
// Set the received image data as the image source
|
|
50
|
-
this.imageSrc = `data:image/jpeg;base64,${data.image}`;
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
</script>
|
|
55
|
-
</body>
|
|
56
|
-
|
|
57
|
-
</html>
|