-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall-mirror.js
executable file
·50 lines (44 loc) · 1.97 KB
/
all-mirror.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
// mirror to all ports
'use strict'; //find bugs easier
//const assert = require('assert').strict; //https://nodejs.org/api/assert.html; CAUTION: SLOW
const {my_exports} = require("yalp/incl/utils");
//const {TODO} = require("yalp21/incl/msgout");
const {model, grid, mapall, shmslice, ZZ, flip} = require("yalp/models");
//const {NUM_PORTS} = require("yalp");
//const {UNIV_LEN} = require("yalp21/yalp").yalp;
///////////////////////////////////////////////////////////////////////////////
////
/// Custom model: all
//
//all nodes of all ports:
//layout will assign 1 port#
//any node output will be replicated across all ports
my_exports({all_mirror});
function all_mirror(opts)
{
// const = (typeof opts == "object")? opts.NUM_PORTS: opts;
const {NUM_PORTS, UNIV_LEN} = opts.ctlr || opts;
if (all_mirror.singleton) return all_mirror.singleton; //CAUTION: ignores opts
//fill single port then wedge out() to copy to all other ports:
// const oneport = nullpx(yalp.UNIV_LEN);
const oneport = model(Object.assign({name: `all px[${NUM_PORTS} x ${UNIV_LEN}]: ALL`}, mapall(grid(UNIV_LEN))));
oneport.firstpx = 0; //start at first node
oneport.svout = oneport.out;
oneport.out = function(...args)
{
const retval = this.svout(...args);
const [frbuf,] = args;
if (this.firstpx || this.numpx != UNIV_LEN) warn("all: only %'d..%d of %'d nodes mapped", this.firstpx, this.firstpx + this.numpx, UNIV_LEN);
for (let p = 0; p < NUM_PORTS; ++p)
if (p != this.portnum)
frbuf.wsnodes[p].set(frbuf.wsnodes[this.portnum]);
return retval;
};
// model({name: "all ports", numpx, nodes2D});
// return all.singleton = model({name: "all ports", numpx, nodes2D});
return all_mirror.singleton = oneport;
}
if (!module.parent) setImmediate(() => all_mirror().csv()); //unit-test; run after inline init
//if (!module.parent) setImmediate(() => minidev().dump()); //unit-test; run after inline init
//eof