joulescope_driver 0.0.0 → 1.5.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/README.md +45 -43
- package/binding.gyp +103 -103
- package/{examples → example}/samples.js +66 -66
- package/{examples → example}/statistics.js +63 -63
- package/index.js +99 -99
- package/package.json +36 -36
- package/prebuilds/darwin-arm64/joulescope_driver.node +0 -0
- package/prebuilds/linux-x64/joulescope_driver.node +0 -0
- package/prebuilds/win32-x64/joulescope_driver.node +0 -0
- package/src/addon.cc +25 -25
- package/src/joulescope_driver.cc +412 -412
- package/src/joulescope_driver.h +39 -39
- package/test/test_binding.js +31 -31
package/README.md
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
# Copyright 2023-2024 Jetperch LLC
|
|
3
|
-
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
15
|
-
-->
|
|
16
|
-
|
|
17
|
-
# Node.js Node-API bindings for Joulescope Driver
|
|
18
|
-
|
|
19
|
-
Welcome to the Joulescope™ Driver project.
|
|
20
|
-
[Joulescope](https://www.joulescope.com) is an affordable, precision DC energy
|
|
21
|
-
analyzer that enables you to build better products.
|
|
22
|
-
|
|
23
|
-
This node.js package contains the Javascript bindings for the Joulescope driver.
|
|
24
|
-
See the [source code](https://github.com/jetperch/joulescope_driver)
|
|
25
|
-
and the main [README](https://github.com/jetperch/joulescope_driver/README.md).
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
* https://nodejs.
|
|
1
|
+
<!--
|
|
2
|
+
# Copyright 2023-2024 Jetperch LLC
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
-->
|
|
16
|
+
|
|
17
|
+
# Node.js Node-API bindings for Joulescope Driver
|
|
18
|
+
|
|
19
|
+
Welcome to the Joulescope™ Driver project.
|
|
20
|
+
[Joulescope](https://www.joulescope.com) is an affordable, precision DC energy
|
|
21
|
+
analyzer that enables you to build better products.
|
|
22
|
+
|
|
23
|
+
This node.js package contains the Javascript bindings for the Joulescope driver.
|
|
24
|
+
See the [source code](https://github.com/jetperch/joulescope_driver)
|
|
25
|
+
and the main [README](https://github.com/jetperch/joulescope_driver/README.md).
|
|
26
|
+
|
|
27
|
+
See the "example" subdirectory for examples of how to use this package.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Building
|
|
31
|
+
|
|
32
|
+
Install node.js and npm. See [instructions](https://nodejs.github.io/node-addon-examples/getting-started/tools).
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
npm install
|
|
36
|
+
npm test
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## References
|
|
42
|
+
|
|
43
|
+
* https://nodejs.github.io/node-addon-examples/
|
|
44
|
+
* https://github.com/nodejs/node-addon-examples
|
|
45
|
+
* https://nodejs.org/api/n-api.html
|
package/binding.gyp
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
{
|
|
2
|
-
'targets': [
|
|
3
|
-
{
|
|
4
|
-
'target_name': 'joulescope_driver_native',
|
|
5
|
-
'sources': [
|
|
6
|
-
'src/addon.cc',
|
|
7
|
-
'src/joulescope_driver.cc',
|
|
8
|
-
'../src/buffer.c',
|
|
9
|
-
'../src/buffer_signal.c',
|
|
10
|
-
'../src/cstr.c',
|
|
11
|
-
'../src/devices.c',
|
|
12
|
-
'../src/downsample.c',
|
|
13
|
-
'../src/error_code.c',
|
|
14
|
-
'../src/js110_cal.c',
|
|
15
|
-
'../src/js110_sample_processor.c',
|
|
16
|
-
'../src/js110_stats.c',
|
|
17
|
-
'../src/js110_usb.c',
|
|
18
|
-
'../src/js220_i128.c',
|
|
19
|
-
'../src/js220_params.c',
|
|
20
|
-
'../src/js220_usb.c',
|
|
21
|
-
'../src/js220_stats.c',
|
|
22
|
-
'../src/jsdrv.c',
|
|
23
|
-
'../src/json.c',
|
|
24
|
-
'../src/log.c',
|
|
25
|
-
'../src/pubsub.c',
|
|
26
|
-
'../src/meta.c',
|
|
27
|
-
'../src/sample_buffer_f32.c',
|
|
28
|
-
'../src/statistics.c',
|
|
29
|
-
'../src/time.c',
|
|
30
|
-
'../src/time_map_filter.c',
|
|
31
|
-
'../src/topic.c',
|
|
32
|
-
'../src/union.c',
|
|
33
|
-
'../src/version.c',
|
|
34
|
-
'../third-party/tinyprintf/tinyprintf.c'
|
|
35
|
-
],
|
|
36
|
-
'conditions': [
|
|
37
|
-
["OS=='win'", {
|
|
38
|
-
'sources': [
|
|
39
|
-
'../src/backend/winusb/backend.c',
|
|
40
|
-
'../src/backend/winusb/device_change_notifier.c',
|
|
41
|
-
'../src/backend/winusb/msg_queue.c',
|
|
42
|
-
'../src/backend/windows.c'
|
|
43
|
-
],
|
|
44
|
-
'libraries': ['Setupapi', 'Winusb', 'user32', 'winmm']
|
|
45
|
-
}],
|
|
46
|
-
["OS!='win'", {
|
|
47
|
-
'sources': [
|
|
48
|
-
'../src/backend/posix.c',
|
|
49
|
-
'../src/backend/libusb/backend.c',
|
|
50
|
-
'../src/backend/libusb/msg_queue.c',
|
|
51
|
-
'../third-party/libusb/libusb/core.c',
|
|
52
|
-
'../third-party/libusb/libusb/descriptor.c',
|
|
53
|
-
'../third-party/libusb/libusb/hotplug.c',
|
|
54
|
-
'../third-party/libusb/libusb/io.c',
|
|
55
|
-
'../third-party/libusb/libusb/strerror.c',
|
|
56
|
-
'../third-party/libusb/libusb/sync.c',
|
|
57
|
-
'../third-party/libusb/libusb/os/events_posix.c',
|
|
58
|
-
'../third-party/libusb/libusb/os/threads_posix.c'
|
|
59
|
-
],
|
|
60
|
-
'libraries': [],
|
|
61
|
-
"conditions": [
|
|
62
|
-
["OS=='mac'", {
|
|
63
|
-
'sources': [
|
|
64
|
-
'../third-party/libusb/libusb/os/darwin_usb.c'
|
|
65
|
-
],
|
|
66
|
-
'include_dirs': [
|
|
67
|
-
'../third-party/libusb/libusb',
|
|
68
|
-
'../third-party/libusb/include/macos'
|
|
69
|
-
]
|
|
70
|
-
}],
|
|
71
|
-
["OS=='linux'", {
|
|
72
|
-
"sources": [
|
|
73
|
-
'../third-party/libusb/libusb/os/linux_udev.c',
|
|
74
|
-
'../third-party/libusb/libusb/os/linux_usbfs.c',
|
|
75
|
-
],
|
|
76
|
-
'include_dirs': [
|
|
77
|
-
'../third-party/libusb/libusb',
|
|
78
|
-
'../third-party/libusb/include/linux'
|
|
79
|
-
],
|
|
80
|
-
'libraries': []
|
|
81
|
-
}]
|
|
82
|
-
]
|
|
83
|
-
}]
|
|
84
|
-
],
|
|
85
|
-
'include_dirs': [
|
|
86
|
-
"<!@(node -p \"require('node-addon-api').include\")",
|
|
87
|
-
"../include",
|
|
88
|
-
"../include_private",
|
|
89
|
-
"../third-party/tinyprintf"
|
|
90
|
-
],
|
|
91
|
-
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
|
|
92
|
-
'cflags!': [ '-fno-exceptions' ],
|
|
93
|
-
'cflags_cc!': [ '-fno-exceptions' ],
|
|
94
|
-
'xcode_settings': {
|
|
95
|
-
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
|
96
|
-
'CLANG_CXX_LIBRARY': 'libc++',
|
|
97
|
-
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
98
|
-
},
|
|
99
|
-
'msvs_settings': {
|
|
100
|
-
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
]
|
|
1
|
+
{
|
|
2
|
+
'targets': [
|
|
3
|
+
{
|
|
4
|
+
'target_name': 'joulescope_driver_native',
|
|
5
|
+
'sources': [
|
|
6
|
+
'src/addon.cc',
|
|
7
|
+
'src/joulescope_driver.cc',
|
|
8
|
+
'../src/buffer.c',
|
|
9
|
+
'../src/buffer_signal.c',
|
|
10
|
+
'../src/cstr.c',
|
|
11
|
+
'../src/devices.c',
|
|
12
|
+
'../src/downsample.c',
|
|
13
|
+
'../src/error_code.c',
|
|
14
|
+
'../src/js110_cal.c',
|
|
15
|
+
'../src/js110_sample_processor.c',
|
|
16
|
+
'../src/js110_stats.c',
|
|
17
|
+
'../src/js110_usb.c',
|
|
18
|
+
'../src/js220_i128.c',
|
|
19
|
+
'../src/js220_params.c',
|
|
20
|
+
'../src/js220_usb.c',
|
|
21
|
+
'../src/js220_stats.c',
|
|
22
|
+
'../src/jsdrv.c',
|
|
23
|
+
'../src/json.c',
|
|
24
|
+
'../src/log.c',
|
|
25
|
+
'../src/pubsub.c',
|
|
26
|
+
'../src/meta.c',
|
|
27
|
+
'../src/sample_buffer_f32.c',
|
|
28
|
+
'../src/statistics.c',
|
|
29
|
+
'../src/time.c',
|
|
30
|
+
'../src/time_map_filter.c',
|
|
31
|
+
'../src/topic.c',
|
|
32
|
+
'../src/union.c',
|
|
33
|
+
'../src/version.c',
|
|
34
|
+
'../third-party/tinyprintf/tinyprintf.c'
|
|
35
|
+
],
|
|
36
|
+
'conditions': [
|
|
37
|
+
["OS=='win'", {
|
|
38
|
+
'sources': [
|
|
39
|
+
'../src/backend/winusb/backend.c',
|
|
40
|
+
'../src/backend/winusb/device_change_notifier.c',
|
|
41
|
+
'../src/backend/winusb/msg_queue.c',
|
|
42
|
+
'../src/backend/windows.c'
|
|
43
|
+
],
|
|
44
|
+
'libraries': ['Setupapi', 'Winusb', 'user32', 'winmm']
|
|
45
|
+
}],
|
|
46
|
+
["OS!='win'", {
|
|
47
|
+
'sources': [
|
|
48
|
+
'../src/backend/posix.c',
|
|
49
|
+
'../src/backend/libusb/backend.c',
|
|
50
|
+
'../src/backend/libusb/msg_queue.c',
|
|
51
|
+
'../third-party/libusb/libusb/core.c',
|
|
52
|
+
'../third-party/libusb/libusb/descriptor.c',
|
|
53
|
+
'../third-party/libusb/libusb/hotplug.c',
|
|
54
|
+
'../third-party/libusb/libusb/io.c',
|
|
55
|
+
'../third-party/libusb/libusb/strerror.c',
|
|
56
|
+
'../third-party/libusb/libusb/sync.c',
|
|
57
|
+
'../third-party/libusb/libusb/os/events_posix.c',
|
|
58
|
+
'../third-party/libusb/libusb/os/threads_posix.c'
|
|
59
|
+
],
|
|
60
|
+
'libraries': [],
|
|
61
|
+
"conditions": [
|
|
62
|
+
["OS=='mac'", {
|
|
63
|
+
'sources': [
|
|
64
|
+
'../third-party/libusb/libusb/os/darwin_usb.c'
|
|
65
|
+
],
|
|
66
|
+
'include_dirs': [
|
|
67
|
+
'../third-party/libusb/libusb',
|
|
68
|
+
'../third-party/libusb/include/macos'
|
|
69
|
+
]
|
|
70
|
+
}],
|
|
71
|
+
["OS=='linux'", {
|
|
72
|
+
"sources": [
|
|
73
|
+
'../third-party/libusb/libusb/os/linux_udev.c',
|
|
74
|
+
'../third-party/libusb/libusb/os/linux_usbfs.c',
|
|
75
|
+
],
|
|
76
|
+
'include_dirs': [
|
|
77
|
+
'../third-party/libusb/libusb',
|
|
78
|
+
'../third-party/libusb/include/linux'
|
|
79
|
+
],
|
|
80
|
+
'libraries': []
|
|
81
|
+
}]
|
|
82
|
+
]
|
|
83
|
+
}]
|
|
84
|
+
],
|
|
85
|
+
'include_dirs': [
|
|
86
|
+
"<!@(node -p \"require('node-addon-api').include\")",
|
|
87
|
+
"../include",
|
|
88
|
+
"../include_private",
|
|
89
|
+
"../third-party/tinyprintf"
|
|
90
|
+
],
|
|
91
|
+
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
|
|
92
|
+
'cflags!': [ '-fno-exceptions' ],
|
|
93
|
+
'cflags_cc!': [ '-fno-exceptions' ],
|
|
94
|
+
'xcode_settings': {
|
|
95
|
+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
|
96
|
+
'CLANG_CXX_LIBRARY': 'libc++',
|
|
97
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
98
|
+
},
|
|
99
|
+
'msvs_settings': {
|
|
100
|
+
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
104
|
}
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Jetperch LLC
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
const JoulescopeDriver = require("..");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function initialize(){
|
|
21
|
-
const drv = new JoulescopeDriver();
|
|
22
|
-
const device_paths = drv.device_paths();
|
|
23
|
-
console.log('device_paths: ' + device_paths);
|
|
24
|
-
if (0 == device_paths.length) {
|
|
25
|
-
drv.finalize()
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
let unsubs = [];
|
|
29
|
-
|
|
30
|
-
device_paths.forEach((device_path) => {
|
|
31
|
-
drv.open(device_path);
|
|
32
|
-
|
|
33
|
-
var sample_cbk = (topic, value) => {
|
|
34
|
-
// Modify this code to do whatever you want with the data
|
|
35
|
-
const avg = value['data'].reduce((accumulator, currentValue) =>
|
|
36
|
-
accumulator + currentValue, 0) / value['data'].length;
|
|
37
|
-
console.log(topic + ' : ' + avg);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (device_path.includes("/js110/")) {
|
|
41
|
-
drv.publish(device_path.concat("/s/i/range/select"), "auto");
|
|
42
|
-
drv.publish(device_path.concat("/s/v/range/select"), "15 V");
|
|
43
|
-
} else {
|
|
44
|
-
drv.publish(device_path.concat("/s/i/range/mode"), "auto");
|
|
45
|
-
drv.publish(device_path.concat("/s/v/range/mode"), "auto");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
unsubs.push(drv.subscribe(device_path.concat("/s/i/!data"), 2, sample_cbk));
|
|
49
|
-
unsubs.push(drv.subscribe(device_path.concat("/s/v/!data"), 2, sample_cbk));
|
|
50
|
-
drv.publish(device_path.concat("/s/i/ctrl"), 1, 0);
|
|
51
|
-
drv.publish(device_path.concat("/s/v/ctrl"), 1, 0);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
return () => {
|
|
55
|
-
unsubs.forEach((unsub) => unsub());
|
|
56
|
-
device_paths.forEach((device_path) => {
|
|
57
|
-
drv.publish(device_path.concat('/s/i/ctrl'), 0, 0);
|
|
58
|
-
drv.publish(device_path.concat('/s/v/ctrl'), 0);
|
|
59
|
-
drv.close(device_path);
|
|
60
|
-
})
|
|
61
|
-
drv.finalize();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
finalize_cbk = initialize();
|
|
66
|
-
process.on('SIGINT', finalize_cbk);
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Jetperch LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const JoulescopeDriver = require("..");
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function initialize(){
|
|
21
|
+
const drv = new JoulescopeDriver();
|
|
22
|
+
const device_paths = drv.device_paths();
|
|
23
|
+
console.log('device_paths: ' + device_paths);
|
|
24
|
+
if (0 == device_paths.length) {
|
|
25
|
+
drv.finalize()
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
let unsubs = [];
|
|
29
|
+
|
|
30
|
+
device_paths.forEach((device_path) => {
|
|
31
|
+
drv.open(device_path);
|
|
32
|
+
|
|
33
|
+
var sample_cbk = (topic, value) => {
|
|
34
|
+
// Modify this code to do whatever you want with the data
|
|
35
|
+
const avg = value['data'].reduce((accumulator, currentValue) =>
|
|
36
|
+
accumulator + currentValue, 0) / value['data'].length;
|
|
37
|
+
console.log(topic + ' : ' + avg);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (device_path.includes("/js110/")) {
|
|
41
|
+
drv.publish(device_path.concat("/s/i/range/select"), "auto");
|
|
42
|
+
drv.publish(device_path.concat("/s/v/range/select"), "15 V");
|
|
43
|
+
} else {
|
|
44
|
+
drv.publish(device_path.concat("/s/i/range/mode"), "auto");
|
|
45
|
+
drv.publish(device_path.concat("/s/v/range/mode"), "auto");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
unsubs.push(drv.subscribe(device_path.concat("/s/i/!data"), 2, sample_cbk));
|
|
49
|
+
unsubs.push(drv.subscribe(device_path.concat("/s/v/!data"), 2, sample_cbk));
|
|
50
|
+
drv.publish(device_path.concat("/s/i/ctrl"), 1, 0);
|
|
51
|
+
drv.publish(device_path.concat("/s/v/ctrl"), 1, 0);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return () => {
|
|
55
|
+
unsubs.forEach((unsub) => unsub());
|
|
56
|
+
device_paths.forEach((device_path) => {
|
|
57
|
+
drv.publish(device_path.concat('/s/i/ctrl'), 0, 0);
|
|
58
|
+
drv.publish(device_path.concat('/s/v/ctrl'), 0);
|
|
59
|
+
drv.close(device_path);
|
|
60
|
+
})
|
|
61
|
+
drv.finalize();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
finalize_cbk = initialize();
|
|
66
|
+
process.on('SIGINT', finalize_cbk);
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Jetperch LLC
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
const JoulescopeDriver = require("joulescope_driver");
|
|
18
|
-
|
|
19
|
-
function initialize(){
|
|
20
|
-
const drv = new JoulescopeDriver();
|
|
21
|
-
const device_paths = drv.device_paths();
|
|
22
|
-
console.log('device_paths: ' + device_paths);
|
|
23
|
-
if (0 == device_paths.length) {
|
|
24
|
-
drv.finalize()
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
let unsubs = [];
|
|
28
|
-
|
|
29
|
-
device_paths.forEach((device_path) => {
|
|
30
|
-
drv.open(device_path);
|
|
31
|
-
|
|
32
|
-
var stats_cbk = (topic, value) => {
|
|
33
|
-
topic_parts = topic.split('/');
|
|
34
|
-
console.log(topic_parts[1] + '-' + topic_parts[2]
|
|
35
|
-
+ ',' + value['signals']['current']['avg']['value']
|
|
36
|
-
+ ',' + value['signals']['voltage']['avg']['value']
|
|
37
|
-
+ ',' + value['signals']['power']['avg']['value']
|
|
38
|
-
+ ',' + value['accumulators']['energy']['value']);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (device_path.includes("/js110/")) {
|
|
42
|
-
drv.publish(device_path.concat("/s/i/range/select"), "auto");
|
|
43
|
-
unsubs.push(drv.subscribe(device_path.concat("/s/sstats/value"), 2, stats_cbk));
|
|
44
|
-
} else {
|
|
45
|
-
drv.publish(device_path.concat("/s/i/range/mode"), "auto");
|
|
46
|
-
drv.publish(device_path.concat("/s/v/range/mode"), "auto");
|
|
47
|
-
unsubs.push(drv.subscribe(device_path.concat("/s/stats/value"), 2, stats_cbk));
|
|
48
|
-
drv.publish(device_path.concat('/s/stats/ctrl'), 1, 0);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return () => {
|
|
53
|
-
unsubs.forEach((unsub) => unsub());
|
|
54
|
-
device_paths.forEach((device_path) => {
|
|
55
|
-
drv.publish(device_path.concat('/s/stats/ctrl'), 0, 0);
|
|
56
|
-
drv.close(device_path);
|
|
57
|
-
})
|
|
58
|
-
drv.finalize();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
finalize_cbk = initialize();
|
|
63
|
-
process.on('SIGINT', finalize_cbk);
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Jetperch LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const JoulescopeDriver = require("joulescope_driver");
|
|
18
|
+
|
|
19
|
+
function initialize(){
|
|
20
|
+
const drv = new JoulescopeDriver();
|
|
21
|
+
const device_paths = drv.device_paths();
|
|
22
|
+
console.log('device_paths: ' + device_paths);
|
|
23
|
+
if (0 == device_paths.length) {
|
|
24
|
+
drv.finalize()
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
let unsubs = [];
|
|
28
|
+
|
|
29
|
+
device_paths.forEach((device_path) => {
|
|
30
|
+
drv.open(device_path);
|
|
31
|
+
|
|
32
|
+
var stats_cbk = (topic, value) => {
|
|
33
|
+
topic_parts = topic.split('/');
|
|
34
|
+
console.log(topic_parts[1] + '-' + topic_parts[2]
|
|
35
|
+
+ ',' + value['signals']['current']['avg']['value']
|
|
36
|
+
+ ',' + value['signals']['voltage']['avg']['value']
|
|
37
|
+
+ ',' + value['signals']['power']['avg']['value']
|
|
38
|
+
+ ',' + value['accumulators']['energy']['value']);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (device_path.includes("/js110/")) {
|
|
42
|
+
drv.publish(device_path.concat("/s/i/range/select"), "auto");
|
|
43
|
+
unsubs.push(drv.subscribe(device_path.concat("/s/sstats/value"), 2, stats_cbk));
|
|
44
|
+
} else {
|
|
45
|
+
drv.publish(device_path.concat("/s/i/range/mode"), "auto");
|
|
46
|
+
drv.publish(device_path.concat("/s/v/range/mode"), "auto");
|
|
47
|
+
unsubs.push(drv.subscribe(device_path.concat("/s/stats/value"), 2, stats_cbk));
|
|
48
|
+
drv.publish(device_path.concat('/s/stats/ctrl'), 1, 0);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
unsubs.forEach((unsub) => unsub());
|
|
54
|
+
device_paths.forEach((device_path) => {
|
|
55
|
+
drv.publish(device_path.concat('/s/stats/ctrl'), 0, 0);
|
|
56
|
+
drv.close(device_path);
|
|
57
|
+
})
|
|
58
|
+
drv.finalize();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
finalize_cbk = initialize();
|
|
63
|
+
process.on('SIGINT', finalize_cbk);
|