@science-corporation/synapse 0.9.0

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.
Files changed (123) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +57 -0
  3. package/dist/api/api.d.ts +3973 -0
  4. package/dist/api/api.d.ts.map +1 -0
  5. package/dist/api/api.js +9368 -0
  6. package/dist/api/api.js.map +1 -0
  7. package/dist/api/proto.json +747 -0
  8. package/dist/channel_mask.d.ts +7 -0
  9. package/dist/channel_mask.d.ts.map +1 -0
  10. package/dist/channel_mask.js +14 -0
  11. package/dist/channel_mask.js.map +1 -0
  12. package/dist/config.d.ts +16 -0
  13. package/dist/config.d.ts.map +1 -0
  14. package/dist/config.js +103 -0
  15. package/dist/config.js.map +1 -0
  16. package/dist/demo.d.ts +2 -0
  17. package/dist/demo.d.ts.map +1 -0
  18. package/dist/demo.js +269 -0
  19. package/dist/demo.js.map +1 -0
  20. package/dist/device.d.ts +17 -0
  21. package/dist/device.d.ts.map +1 -0
  22. package/dist/device.js +112 -0
  23. package/dist/device.js.map +1 -0
  24. package/dist/index.d.ts +5 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +28 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/node.d.ts +10 -0
  29. package/dist/node.d.ts.map +1 -0
  30. package/dist/node.js +14 -0
  31. package/dist/node.js.map +1 -0
  32. package/dist/nodes/electrical_broadband.d.ts +11 -0
  33. package/dist/nodes/electrical_broadband.d.ts.map +1 -0
  34. package/dist/nodes/electrical_broadband.js +28 -0
  35. package/dist/nodes/electrical_broadband.js.map +1 -0
  36. package/dist/nodes/electrical_stimulation.d.ts +11 -0
  37. package/dist/nodes/electrical_stimulation.d.ts.map +1 -0
  38. package/dist/nodes/electrical_stimulation.js +28 -0
  39. package/dist/nodes/electrical_stimulation.js.map +1 -0
  40. package/dist/nodes/index.d.ts +9 -0
  41. package/dist/nodes/index.d.ts.map +1 -0
  42. package/dist/nodes/index.js +23 -0
  43. package/dist/nodes/index.js.map +1 -0
  44. package/dist/nodes/optical_broadband.d.ts +11 -0
  45. package/dist/nodes/optical_broadband.d.ts.map +1 -0
  46. package/dist/nodes/optical_broadband.js +28 -0
  47. package/dist/nodes/optical_broadband.js.map +1 -0
  48. package/dist/nodes/optical_stimulation.d.ts +11 -0
  49. package/dist/nodes/optical_stimulation.d.ts.map +1 -0
  50. package/dist/nodes/optical_stimulation.js +28 -0
  51. package/dist/nodes/optical_stimulation.js.map +1 -0
  52. package/dist/nodes/spectral_filter.d.ts +11 -0
  53. package/dist/nodes/spectral_filter.d.ts.map +1 -0
  54. package/dist/nodes/spectral_filter.js +28 -0
  55. package/dist/nodes/spectral_filter.js.map +1 -0
  56. package/dist/nodes/spike_detect.d.ts +11 -0
  57. package/dist/nodes/spike_detect.d.ts.map +1 -0
  58. package/dist/nodes/spike_detect.js +28 -0
  59. package/dist/nodes/spike_detect.js.map +1 -0
  60. package/dist/nodes/stream_in.d.ts +19 -0
  61. package/dist/nodes/stream_in.d.ts.map +1 -0
  62. package/dist/nodes/stream_in.js +66 -0
  63. package/dist/nodes/stream_in.js.map +1 -0
  64. package/dist/nodes/stream_out.d.ts +16 -0
  65. package/dist/nodes/stream_out.d.ts.map +1 -0
  66. package/dist/nodes/stream_out.js +87 -0
  67. package/dist/nodes/stream_out.js.map +1 -0
  68. package/dist/utils/client.d.ts +3 -0
  69. package/dist/utils/client.d.ts.map +1 -0
  70. package/dist/utils/client.js +25 -0
  71. package/dist/utils/client.js.map +1 -0
  72. package/dist/utils/discover.d.ts +15 -0
  73. package/dist/utils/discover.d.ts.map +1 -0
  74. package/dist/utils/discover.js +64 -0
  75. package/dist/utils/discover.js.map +1 -0
  76. package/dist/utils/enum.d.ts +2 -0
  77. package/dist/utils/enum.d.ts.map +1 -0
  78. package/dist/utils/enum.js +13 -0
  79. package/dist/utils/enum.js.map +1 -0
  80. package/dist/utils/index.d.ts +2 -0
  81. package/dist/utils/index.d.ts.map +1 -0
  82. package/dist/utils/index.js +3 -0
  83. package/dist/utils/index.js.map +1 -0
  84. package/package.json +42 -0
  85. package/scripts/build.sh +11 -0
  86. package/scripts/generate.sh +25 -0
  87. package/src/api/api.d.ts +3973 -0
  88. package/src/api/api.js +9991 -0
  89. package/src/api/proto.json +747 -0
  90. package/src/config.ts +110 -0
  91. package/src/demo.ts +303 -0
  92. package/src/device.ts +94 -0
  93. package/src/index.ts +4 -0
  94. package/src/node.ts +18 -0
  95. package/src/nodes/electrical_broadband.ts +30 -0
  96. package/src/nodes/electrical_stimulation.ts +30 -0
  97. package/src/nodes/index.ts +8 -0
  98. package/src/nodes/optical_broadband.ts +30 -0
  99. package/src/nodes/optical_stimulation.ts +30 -0
  100. package/src/nodes/spectral_filter.ts +30 -0
  101. package/src/nodes/spike_detect.ts +30 -0
  102. package/src/nodes/stream_in.ts +83 -0
  103. package/src/nodes/stream_out.ts +92 -0
  104. package/src/utils/client.ts +20 -0
  105. package/src/utils/discover.ts +82 -0
  106. package/src/utils/enum.ts +8 -0
  107. package/src/utils/index.ts +1 -0
  108. package/synapse-api/README.md +15 -0
  109. package/synapse-api/api/channel.proto +9 -0
  110. package/synapse-api/api/datatype.proto +12 -0
  111. package/synapse-api/api/files.proto +46 -0
  112. package/synapse-api/api/node.proto +54 -0
  113. package/synapse-api/api/nodes/electrical_broadband.proto +15 -0
  114. package/synapse-api/api/nodes/electrical_stimulation.proto +13 -0
  115. package/synapse-api/api/nodes/optical_broadband.proto +11 -0
  116. package/synapse-api/api/nodes/optical_stimulation.proto +11 -0
  117. package/synapse-api/api/nodes/spectral_filter.proto +17 -0
  118. package/synapse-api/api/nodes/spike_detect.proto +16 -0
  119. package/synapse-api/api/nodes/stream_in.proto +9 -0
  120. package/synapse-api/api/nodes/stream_out.proto +8 -0
  121. package/synapse-api/api/query.proto +46 -0
  122. package/synapse-api/api/status.proto +42 -0
  123. package/synapse-api/api/synapse.proto +51 -0
package/src/config.ts ADDED
@@ -0,0 +1,110 @@
1
+ import Node from "./node";
2
+ import { synapse } from "./api/api";
3
+ import ElectricalBroadband from "./nodes/electrical_broadband";
4
+ import ElectricalStimulation from "./nodes/electrical_stimulation";
5
+ import OpticalBroadband from "./nodes/optical_broadband";
6
+ import OpticalStimulation from "./nodes/optical_stimulation";
7
+ import SpectralFilter from "./nodes/spectral_filter";
8
+ import SpikeDetect from "./nodes/spike_detect";
9
+ import StreamIn from "./nodes/stream_in";
10
+ import StreamOut from "./nodes/stream_out";
11
+
12
+ type Connection = [number, number];
13
+ const kNodeTypeObjectMap = {
14
+ [synapse.NodeType.kElectricalBroadband]: ElectricalBroadband,
15
+ [synapse.NodeType.kElectricalStimulation]: ElectricalStimulation,
16
+ [synapse.NodeType.kOpticalBroadband]: OpticalBroadband,
17
+ [synapse.NodeType.kOpticalStimulation]: OpticalStimulation,
18
+ [synapse.NodeType.kSpectralFilter]: SpectralFilter,
19
+ [synapse.NodeType.kSpikeDetect]: SpikeDetect,
20
+ [synapse.NodeType.kStreamIn]: StreamIn,
21
+ [synapse.NodeType.kStreamOut]: StreamOut,
22
+ };
23
+
24
+ class Config {
25
+ connections: Connection[] = [];
26
+ nodes: Node[] = [];
27
+
28
+ _genNodeId(): number {
29
+ return this.nodes.length + 1;
30
+ }
31
+
32
+ add(nodes: Node[]) {
33
+ for (const node of nodes) {
34
+ if (!this.addNode(node)) {
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ }
40
+
41
+ connect(fromNode: Node, toNode: Node): boolean {
42
+ if (fromNode.id === null || toNode.id === null) {
43
+ return false;
44
+ }
45
+ this.connections.push([fromNode.id, toNode.id]);
46
+ return true;
47
+ }
48
+
49
+ addNode(node: Node): boolean {
50
+ if (!!node.id) {
51
+ return false;
52
+ }
53
+ node.id = this._genNodeId();
54
+ this.nodes.push(node);
55
+ return true;
56
+ }
57
+
58
+ setDevice(device): boolean {
59
+ for (const node of this.nodes) {
60
+ node.device = device;
61
+ }
62
+ return true;
63
+ }
64
+
65
+ static fromProto(proto: synapse.IDeviceConfiguration): Config {
66
+ const { nodes = [], connections = [] } = proto;
67
+ const config = new Config();
68
+
69
+ for (const nodeProto of nodes) {
70
+ const { type } = nodeProto;
71
+ const NodeType = kNodeTypeObjectMap[type];
72
+ if (!NodeType) {
73
+ continue;
74
+ }
75
+
76
+ const node = NodeType.fromProto(nodeProto);
77
+ if (!!nodeProto.id) {
78
+ node.id = nodeProto.id;
79
+ config.nodes.push(node);
80
+ } else {
81
+ config.addNode(node);
82
+ }
83
+ }
84
+
85
+ for (const connection of connections) {
86
+ const from = config.nodes.find((node) => node.id === connection.srcNodeId);
87
+ const to = config.nodes.find((node) => node.id === connection.dstNodeId);
88
+ if (!from || !to) {
89
+ continue;
90
+ }
91
+ config.connect(from, to);
92
+ }
93
+
94
+ return config;
95
+ }
96
+
97
+ toProto(): synapse.DeviceConfiguration {
98
+ return new synapse.DeviceConfiguration({
99
+ nodes: this.nodes.map((node) => node.toProto()),
100
+ connections: this.connections.map((connection) => {
101
+ return {
102
+ srcNodeId: connection[0],
103
+ dstNodeId: connection[1],
104
+ };
105
+ }),
106
+ });
107
+ }
108
+ }
109
+
110
+ export default Config;
package/src/demo.ts ADDED
@@ -0,0 +1,303 @@
1
+ import fs from "fs";
2
+ import yargs from "yargs";
3
+ import { hideBin } from "yargs/helpers";
4
+
5
+ import { synapse } from "./api/api";
6
+ import Config from "./config";
7
+ import Device from "./device";
8
+ import ElectricalBroadband from "./nodes/electrical_broadband";
9
+ import OpticalStimulation from "./nodes/optical_stimulation";
10
+ import StreamIn from "./nodes/stream_in";
11
+ import StreamOut from "./nodes/stream_out";
12
+ import { discover } from "./utils/discover";
13
+ import { getName } from "./utils/enum";
14
+
15
+ const cli = yargs(hideBin(process.argv))
16
+ .help()
17
+ .command("discover", "Discover synapse devices")
18
+ .command("read", "Read from StreamOut node", {
19
+ "multicast-group": {
20
+ alias: "m",
21
+ type: "string",
22
+ description: "Multicast group",
23
+ },
24
+ output: {
25
+ alias: "o",
26
+ type: "string",
27
+ description: "Output file",
28
+ },
29
+ uri: {
30
+ alias: "u",
31
+ type: "string",
32
+ demandOption: true,
33
+ },
34
+ })
35
+ .command("write", "Write to StreamIn node", {
36
+ input: {
37
+ alias: "i",
38
+ type: "string",
39
+ description: "Input file",
40
+ },
41
+ uri: {
42
+ alias: "u",
43
+ type: "string",
44
+ demandOption: true,
45
+ },
46
+ });
47
+
48
+ const info = async (device: Device) => {
49
+ console.log("Info()");
50
+
51
+ const info = await device.info();
52
+ const { serial, name, status, synapseVersion, firmwareVersion, peripherals, configuration } = info;
53
+
54
+ console.log(` - serial: ${serial}`);
55
+ console.log(` - name: ${name}`);
56
+ console.log(` - synapse version: ${synapseVersion || "<unknown>"}`);
57
+ console.log(` - firmware version: ${firmwareVersion || "<unknown>"}`);
58
+
59
+ console.log(
60
+ ` - status: ${status.code} (${getName(synapse.StatusCode, status.code)})${
61
+ status.message ? `: "${status.message}"` : ""
62
+ }`
63
+ );
64
+ console.log(` - state: ${getName(synapse.DeviceState, status.state)}`);
65
+
66
+ console.log(` - sockets: ${status.sockets?.length || 0}`);
67
+ status.sockets?.forEach(({ nodeId, bind }) => {
68
+ console.log(` - node [${nodeId}] ${bind}`);
69
+ });
70
+
71
+ console.log(` - peripherals: ${peripherals?.length || 0}`);
72
+ peripherals?.forEach(({ name, peripheralId: id, vendor }) => {
73
+ console.log(` - [${id}] ${name} (${vendor})`);
74
+ });
75
+
76
+ if (configuration) {
77
+ const { nodes } = configuration;
78
+ console.log(` - configuration:`);
79
+ console.log(` - nodes: ${nodes?.length || 0}`);
80
+ nodes?.forEach(({ id, type }) => {
81
+ console.log(` - [${id}] (${getName(synapse.NodeType, type)})`);
82
+ });
83
+ }
84
+
85
+ return true;
86
+ };
87
+
88
+ const read = async (device: Device, argv: any) => {
89
+ console.log("Reading from device's StreamOut node...");
90
+
91
+ const { multicastGroup, output } = argv;
92
+ let ok = true;
93
+ let stream = null;
94
+ if (output) {
95
+ console.log(`Writing to file: ${output}`);
96
+ stream = fs.createWriteStream(output);
97
+ }
98
+
99
+ const onMessage = (msg: Buffer) => {
100
+ const value = msg.readUInt32BE();
101
+ console.log(`StreamOut | recv: ${value}`);
102
+ if (stream) {
103
+ stream.write(msg);
104
+ }
105
+ };
106
+
107
+ const config = new Config();
108
+ const nodeEphys = new ElectricalBroadband({
109
+ peripheralId: 3,
110
+ channels: [{ id: 0, referenceId: 0, electrodeId: 1 }],
111
+ bitWidth: 12,
112
+ sampleRate: 16000,
113
+ });
114
+ const nodeStreamOut = new StreamOut(
115
+ {
116
+ multicastGroup,
117
+ },
118
+ onMessage
119
+ );
120
+
121
+ ok = config.add([nodeEphys, nodeStreamOut]);
122
+ ok = config.connect(nodeEphys, nodeStreamOut);
123
+ if (!ok) {
124
+ console.error("Failed to connect nodes");
125
+ return;
126
+ }
127
+
128
+ console.log("Configuring device...");
129
+ try {
130
+ ok = await device.configure(config);
131
+ } catch (e) {
132
+ console.error(e);
133
+ return;
134
+ }
135
+
136
+ console.log("Starting device...");
137
+ try {
138
+ ok = await device.start();
139
+ } catch (e) {
140
+ console.error(e);
141
+ return;
142
+ }
143
+
144
+ nodeStreamOut.start();
145
+
146
+ let running = true;
147
+ process.on("SIGINT", function () {
148
+ if (!running) {
149
+ return;
150
+ }
151
+
152
+ running = false;
153
+ nodeStreamOut.stop();
154
+ device.stop();
155
+ });
156
+ };
157
+
158
+ const write = async (device: Device, argv: any) => {
159
+ const { input } = argv;
160
+
161
+ if (input && !fs.existsSync(input)) {
162
+ console.error(`File not found: ${input}`);
163
+ return;
164
+ }
165
+
166
+ console.log("Writing to device's StreamOut node...");
167
+ let ok = true;
168
+
169
+ const config = new Config();
170
+ const nodeStreamIn = new StreamIn({
171
+ dataType: synapse.DataType.kBroadband,
172
+ });
173
+ const nodeOptical = new OpticalStimulation();
174
+
175
+ ok = config.add([nodeStreamIn, nodeOptical]);
176
+ ok = config.connect(nodeStreamIn, nodeOptical);
177
+ if (!ok) {
178
+ console.error("Failed to connect nodes");
179
+ return;
180
+ }
181
+
182
+ console.log("Configuring device...");
183
+ try {
184
+ ok = await device.configure(config);
185
+ } catch (e) {
186
+ console.error(e);
187
+ return;
188
+ }
189
+
190
+ console.log("Starting device...");
191
+ try {
192
+ ok = await device.start();
193
+ } catch (e) {
194
+ console.error(e);
195
+ return;
196
+ }
197
+
198
+ let running = true;
199
+ process.on("SIGINT", function () {
200
+ console.log("SIGINT", running);
201
+ if (!running) return;
202
+ console.log("stopping...");
203
+
204
+ running = false;
205
+ device.stop();
206
+
207
+ process.exit();
208
+ });
209
+
210
+ if (input) {
211
+ console.log(`Reading from file: ${input}`);
212
+ fs.open(input, "r", (err, fd) => {
213
+ console.log("Opened file");
214
+ const kBufSize = 4;
215
+ const buffer = Buffer.alloc(kBufSize);
216
+
217
+ if (err) {
218
+ console.error(err);
219
+ return;
220
+ }
221
+
222
+ const read = () => {
223
+ if (!running) {
224
+ fs.close(fd, () => {});
225
+ return;
226
+ }
227
+
228
+ fs.read(fd, buffer, 0, kBufSize, null, (err, n) => {
229
+ if (err) {
230
+ console.error(err);
231
+ return;
232
+ }
233
+
234
+ if (n === 0) {
235
+ return;
236
+ }
237
+
238
+ console.log(`StreamIn | send: ${buffer.readUInt32BE()}`);
239
+ nodeStreamIn.write(buffer.slice(0, n));
240
+ read();
241
+ });
242
+ };
243
+
244
+ read();
245
+ });
246
+
247
+ return;
248
+ }
249
+
250
+ let i = 0;
251
+ const kInterval = 1;
252
+ const buffer = Buffer.alloc(4);
253
+ const write = () => {
254
+ if (!running) {
255
+ device.stop();
256
+ return;
257
+ }
258
+
259
+ buffer.writeUInt32BE(i++);
260
+ nodeStreamIn.write(buffer);
261
+
262
+ setTimeout(write, kInterval);
263
+ };
264
+ setTimeout(write, kInterval);
265
+ };
266
+
267
+ const main = async () => {
268
+ const argv = cli.parseSync();
269
+
270
+ if (argv._.includes("discover")) {
271
+ const devices = await discover();
272
+ for (const device of devices) {
273
+ console.log(`${device.host}:${device.port} ${device.capability} ${device.name} (${device.serial})`);
274
+ }
275
+ return;
276
+ }
277
+
278
+ const { uri } = argv;
279
+ if (!uri) {
280
+ console.error("Missing URI");
281
+ return;
282
+ }
283
+
284
+ console.log(`Connecting to device @ ${uri}`);
285
+ const device = new Device(uri as string);
286
+
287
+ try {
288
+ await info(device);
289
+ } catch (e) {
290
+ console.error(e);
291
+ return;
292
+ }
293
+
294
+ if (argv._.includes("read")) {
295
+ return read(device, argv);
296
+ }
297
+
298
+ if (argv._.includes("write")) {
299
+ return write(device, argv);
300
+ }
301
+ };
302
+
303
+ main();
package/src/device.ts ADDED
@@ -0,0 +1,94 @@
1
+ import { Channel, credentials } from "@grpc/grpc-js";
2
+
3
+ import { synapse } from "./api/api";
4
+ import Config from "./config";
5
+ import { create } from "./utils/client";
6
+ import { getName } from "./utils/enum";
7
+
8
+ class Device {
9
+ rpc: any | null = null;
10
+ channel: Channel | null = null;
11
+ sockets: synapse.INodeSocket[] = [];
12
+
13
+ constructor(public uri: string) {
14
+ this.rpc = create(uri, credentials.createInsecure());
15
+ if (!this.rpc) {
16
+ throw new Error(`Failed to create client for ${uri}`);
17
+ }
18
+ }
19
+
20
+ async configure(config: Config): Promise<boolean> {
21
+ return new Promise((resolve, reject) => {
22
+ config.setDevice(this);
23
+
24
+ const proto = config.toProto();
25
+ this.rpc.configure(proto, (err, res) => {
26
+ if (err) {
27
+ reject(err);
28
+ } else {
29
+ if (this._handleStatusResponse(res!)) {
30
+ resolve(true);
31
+ } else {
32
+ reject(`Error configuring device: (code: ${getName(synapse.StatusCode, res.code)}) ${res.message}`);
33
+ }
34
+ }
35
+ });
36
+ });
37
+ }
38
+
39
+ async info(): Promise<synapse.DeviceInfo> {
40
+ return new Promise((resolve, reject) => {
41
+ this.rpc.info({}, (err, res) => {
42
+ if (err) {
43
+ reject(err);
44
+ } else {
45
+ resolve(res!);
46
+ }
47
+ });
48
+ });
49
+ }
50
+
51
+ async start(): Promise<boolean> {
52
+ return new Promise((resolve, reject) => {
53
+ this.rpc.start({}, (err, res) => {
54
+ if (err) {
55
+ reject(err);
56
+ } else {
57
+ if (this._handleStatusResponse(res!)) {
58
+ resolve(true);
59
+ } else {
60
+ reject(`Error starting device: (code: ${getName(synapse.StatusCode, res.code)}) ${res.message}`);
61
+ }
62
+ }
63
+ });
64
+ });
65
+ }
66
+
67
+ async stop(): Promise<boolean> {
68
+ return new Promise((resolve, reject) => {
69
+ this.rpc.stop({}, (err, res) => {
70
+ if (err) {
71
+ reject(err);
72
+ } else {
73
+ if (this._handleStatusResponse(res!)) {
74
+ resolve(true);
75
+ } else {
76
+ reject(`Error stopping device: (code: ${getName(synapse.StatusCode, res.code)}) ${res.message}`);
77
+ }
78
+ }
79
+ });
80
+ });
81
+ }
82
+
83
+ _handleStatusResponse(status: synapse.Status): boolean {
84
+ const { code, sockets } = status;
85
+ if (code && (code as any) !== synapse.StatusCode.kOk) {
86
+ return false;
87
+ } else {
88
+ this.sockets = sockets || [];
89
+ return true;
90
+ }
91
+ }
92
+ }
93
+
94
+ export default Device;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { default as Config } from "./config";
2
+ export { default as Device } from "./device";
3
+ export * from "./nodes";
4
+ export { synapse } from "./api/api";
package/src/node.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { synapse } from "./api/api";
2
+ import Device from "./device";
3
+
4
+ class Node {
5
+ id?: number;
6
+ type: synapse.NodeType = synapse.NodeType.kNodeTypeUnknown;
7
+ device: Device | null = null;
8
+
9
+ toProto(config: synapse.INodeConfig = {}): synapse.NodeConfig {
10
+ return new synapse.NodeConfig({
11
+ ...config,
12
+ id: this.id,
13
+ type: this.type,
14
+ });
15
+ }
16
+ }
17
+
18
+ export default Node;
@@ -0,0 +1,30 @@
1
+ import { synapse } from "../api/api";
2
+ import Node from "../node";
3
+
4
+ class ElectricalBroadband extends Node {
5
+ type = synapse.NodeType.kElectricalBroadband;
6
+ config: synapse.IElectricalBroadbandConfig;
7
+
8
+ constructor(config: synapse.IElectricalBroadbandConfig = {}) {
9
+ super();
10
+
11
+ this.config = config;
12
+ }
13
+
14
+ toProto(): synapse.NodeConfig {
15
+ return super.toProto({
16
+ electricalBroadband: this.config,
17
+ });
18
+ }
19
+
20
+ static fromProto(proto: synapse.NodeConfig): ElectricalBroadband {
21
+ const { electricalBroadband } = proto;
22
+ if (!electricalBroadband) {
23
+ throw new Error("Invalid config, missing electricalBroadband");
24
+ }
25
+
26
+ return new ElectricalBroadband(proto.electricalBroadband);
27
+ }
28
+ }
29
+
30
+ export default ElectricalBroadband;
@@ -0,0 +1,30 @@
1
+ import { synapse } from "../api/api";
2
+ import Node from "../node";
3
+
4
+ class ElectricalStimulation extends Node {
5
+ type = synapse.NodeType.kElectricalStimulation;
6
+ config: synapse.IElectricalStimulationConfig;
7
+
8
+ constructor(config: synapse.IElectricalStimulationConfig = {}) {
9
+ super();
10
+
11
+ this.config = config;
12
+ }
13
+
14
+ toProto(): synapse.NodeConfig {
15
+ return super.toProto({
16
+ electricalStimulation: this.config,
17
+ });
18
+ }
19
+
20
+ static fromProto(proto: synapse.INodeConfig): ElectricalStimulation {
21
+ const { electricalStimulation } = proto;
22
+ if (!electricalStimulation) {
23
+ throw new Error("Invalid config, missing electricalStimulation");
24
+ }
25
+
26
+ return new ElectricalStimulation(proto.electricalStimulation);
27
+ }
28
+ }
29
+
30
+ export default ElectricalStimulation;
@@ -0,0 +1,8 @@
1
+ export { default as ElectricalBroadband } from "./electrical_broadband";
2
+ export { default as ElectricalStimulation } from "./electrical_stimulation";
3
+ export { default as OpticalBroadband } from "./optical_broadband";
4
+ export { default as OpticalStimulation } from "./optical_stimulation";
5
+ export { default as SpectralFilter } from "./spectral_filter";
6
+ export { default as SpikeDetect } from "./spike_detect";
7
+ export { default as StreamIn } from "./stream_in";
8
+ export { default as StreamOut } from "./stream_out";
@@ -0,0 +1,30 @@
1
+ import { synapse } from "../api/api";
2
+ import Node from "../node";
3
+
4
+ class OpticalBroadband extends Node {
5
+ type = synapse.NodeType.kOpticalBroadband;
6
+ config: synapse.IOpticalBroadbandConfig;
7
+
8
+ constructor(config: synapse.IOpticalBroadbandConfig = {}) {
9
+ super();
10
+
11
+ this.config = config;
12
+ }
13
+
14
+ toProto(): synapse.NodeConfig {
15
+ return super.toProto({
16
+ opticalBroadband: this.config,
17
+ });
18
+ }
19
+
20
+ static fromProto(proto: synapse.INodeConfig): OpticalBroadband {
21
+ const { opticalBroadband } = proto;
22
+ if (!opticalBroadband) {
23
+ throw new Error("Invalid config, missing opticalBroadband");
24
+ }
25
+
26
+ return new OpticalBroadband(proto.opticalBroadband);
27
+ }
28
+ }
29
+
30
+ export default OpticalBroadband;
@@ -0,0 +1,30 @@
1
+ import { synapse } from "../api/api";
2
+ import Node from "../node";
3
+
4
+ class OpticalStimulation extends Node {
5
+ type = synapse.NodeType.kOpticalStimulation;
6
+ config: synapse.IOpticalStimulationConfig;
7
+
8
+ constructor(config: synapse.IOpticalStimulationConfig = {}) {
9
+ super();
10
+
11
+ this.config = config;
12
+ }
13
+
14
+ toProto(): synapse.NodeConfig {
15
+ return super.toProto({
16
+ opticalStimulation: this.config,
17
+ });
18
+ }
19
+
20
+ static fromProto(proto: synapse.INodeConfig): OpticalStimulation {
21
+ const { opticalStimulation } = proto;
22
+ if (!opticalStimulation) {
23
+ throw new Error("Invalid config, missing opticalStimulation");
24
+ }
25
+
26
+ return new OpticalStimulation(proto.opticalStimulation);
27
+ }
28
+ }
29
+
30
+ export default OpticalStimulation;
@@ -0,0 +1,30 @@
1
+ import { synapse } from "../api/api";
2
+ import Node from "../node";
3
+
4
+ class SpectralFilter extends Node {
5
+ type = synapse.NodeType.kSpectralFilter;
6
+ config: synapse.ISpectralFilterConfig;
7
+
8
+ constructor(config: synapse.ISpectralFilterConfig = {}) {
9
+ super();
10
+
11
+ this.config = config;
12
+ }
13
+
14
+ toProto(): synapse.NodeConfig {
15
+ return super.toProto({
16
+ spectralFilter: this.config,
17
+ });
18
+ }
19
+
20
+ static fromProto(proto: synapse.INodeConfig): SpectralFilter {
21
+ const { spectralFilter } = proto;
22
+ if (!spectralFilter) {
23
+ throw new Error("Invalid config, missing spectralFilter");
24
+ }
25
+
26
+ return new SpectralFilter(proto.spectralFilter);
27
+ }
28
+ }
29
+
30
+ export default SpectralFilter;