usb 2.17.0 → 3.0.0-alpha.2
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/LICENSE +18 -4
- package/README.md +25 -516
- package/dist/index.d.ts +67 -13
- package/dist/index.js +333 -64
- package/index.d.ts +89 -0
- package/index.js +583 -0
- package/package.json +53 -33
- package/CHANGELOG.md +0 -294
- package/binding.gyp +0 -128
- package/dist/index.js.map +0 -1
- package/dist/usb/bindings.d.ts +0 -266
- package/dist/usb/bindings.js +0 -10
- package/dist/usb/bindings.js.map +0 -1
- package/dist/usb/capability.d.ts +0 -13
- package/dist/usb/capability.js +0 -17
- package/dist/usb/capability.js.map +0 -1
- package/dist/usb/descriptors.d.ts +0 -128
- package/dist/usb/descriptors.js +0 -3
- package/dist/usb/descriptors.js.map +0 -1
- package/dist/usb/device.d.ts +0 -100
- package/dist/usb/device.js +0 -297
- package/dist/usb/device.js.map +0 -1
- package/dist/usb/endpoint.d.ts +0 -94
- package/dist/usb/endpoint.js +0 -219
- package/dist/usb/endpoint.js.map +0 -1
- package/dist/usb/index.d.ts +0 -31
- package/dist/usb/index.js +0 -116
- package/dist/usb/index.js.map +0 -1
- package/dist/usb/interface.d.ts +0 -80
- package/dist/usb/interface.js +0 -133
- package/dist/usb/interface.js.map +0 -1
- package/dist/webusb/index.d.ts +0 -64
- package/dist/webusb/index.js +0 -295
- package/dist/webusb/index.js.map +0 -1
- package/dist/webusb/webusb-device.d.ts +0 -54
- package/dist/webusb/webusb-device.js +0 -434
- package/dist/webusb/webusb-device.js.map +0 -1
- package/libusb/.clang-tidy +0 -34
- package/libusb/.codespellrc +0 -3
- package/libusb/.private/README.txt +0 -5
- package/libusb/.private/appveyor_build.sh +0 -26
- package/libusb/.private/bm.sh +0 -54
- package/libusb/.private/ci-build.sh +0 -92
- package/libusb/.private/ci-container-build.sh +0 -67
- package/libusb/.private/post-rewrite.sh +0 -32
- package/libusb/.private/pre-commit.sh +0 -52
- package/libusb/.private/wbs.txt +0 -43
- package/libusb/.travis.yml +0 -58
- package/libusb/AUTHORS +0 -231
- package/libusb/COPYING +0 -504
- package/libusb/ChangeLog +0 -365
- package/libusb/HACKING +0 -25
- package/libusb/INSTALL_WIN.txt +0 -52
- package/libusb/KEYS +0 -123
- package/libusb/Makefile.am +0 -50
- package/libusb/NEWS +0 -2
- package/libusb/PORTING +0 -94
- package/libusb/README +0 -29
- package/libusb/README.git +0 -41
- package/libusb/TODO +0 -2
- package/libusb/Xcode/common.xcconfig +0 -92
- package/libusb/Xcode/config.h +0 -31
- package/libusb/Xcode/debug.xcconfig +0 -32
- package/libusb/Xcode/libusb.xcconfig +0 -21
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +0 -1391
- package/libusb/Xcode/libusb_debug.xcconfig +0 -21
- package/libusb/Xcode/libusb_release.xcconfig +0 -21
- package/libusb/Xcode/release.xcconfig +0 -30
- package/libusb/android/README +0 -152
- package/libusb/android/config.h +0 -55
- package/libusb/android/examples/unrooted_android.c +0 -301
- package/libusb/android/examples/unrooted_android.h +0 -36
- package/libusb/android/jni/Android.mk +0 -23
- package/libusb/android/jni/Application.mk +0 -40
- package/libusb/android/jni/examples.mk +0 -168
- package/libusb/android/jni/libusb.mk +0 -60
- package/libusb/android/jni/tests.mk +0 -45
- package/libusb/appveyor.yml +0 -108
- package/libusb/autogen.sh +0 -10
- package/libusb/bootstrap.sh +0 -10
- package/libusb/configure.ac +0 -450
- package/libusb/doc/Makefile.in +0 -22
- package/libusb/doc/doxygen.cfg.in +0 -2571
- package/libusb/doc/libusb.png +0 -0
- package/libusb/examples/Makefile.am +0 -12
- package/libusb/examples/dpfp.c +0 -711
- package/libusb/examples/ezusb.c +0 -846
- package/libusb/examples/ezusb.h +0 -109
- package/libusb/examples/fxload.c +0 -310
- package/libusb/examples/hotplugtest.c +0 -147
- package/libusb/examples/listdevs.c +0 -73
- package/libusb/examples/sam3u_benchmark.c +0 -228
- package/libusb/examples/testlibusb.c +0 -312
- package/libusb/examples/xusb.c +0 -1254
- package/libusb/libusb/Makefile.am +0 -98
- package/libusb/libusb/Makefile.am.extra +0 -26
- package/libusb/libusb/core.c +0 -2925
- package/libusb/libusb/descriptor.c +0 -1558
- package/libusb/libusb/hotplug.c +0 -489
- package/libusb/libusb/io.c +0 -2865
- package/libusb/libusb/libusb-1.0.def +0 -199
- package/libusb/libusb/libusb-1.0.rc +0 -53
- package/libusb/libusb/libusb.h +0 -2421
- package/libusb/libusb/libusbi.h +0 -1535
- package/libusb/libusb/os/darwin_usb.c +0 -2977
- package/libusb/libusb/os/darwin_usb.h +0 -156
- package/libusb/libusb/os/emscripten_webusb.cpp +0 -875
- package/libusb/libusb/os/events_posix.c +0 -340
- package/libusb/libusb/os/events_posix.h +0 -62
- package/libusb/libusb/os/events_windows.c +0 -214
- package/libusb/libusb/os/events_windows.h +0 -46
- package/libusb/libusb/os/haiku_pollfs.cpp +0 -372
- package/libusb/libusb/os/haiku_usb.h +0 -113
- package/libusb/libusb/os/haiku_usb_backend.cpp +0 -532
- package/libusb/libusb/os/haiku_usb_raw.cpp +0 -231
- package/libusb/libusb/os/haiku_usb_raw.h +0 -188
- package/libusb/libusb/os/linux_netlink.c +0 -401
- package/libusb/libusb/os/linux_udev.c +0 -321
- package/libusb/libusb/os/linux_usbfs.c +0 -2829
- package/libusb/libusb/os/linux_usbfs.h +0 -221
- package/libusb/libusb/os/netbsd_usb.c +0 -617
- package/libusb/libusb/os/null_usb.c +0 -111
- package/libusb/libusb/os/openbsd_usb.c +0 -700
- package/libusb/libusb/os/sunos_usb.c +0 -1619
- package/libusb/libusb/os/sunos_usb.h +0 -79
- package/libusb/libusb/os/threads_posix.c +0 -126
- package/libusb/libusb/os/threads_posix.h +0 -98
- package/libusb/libusb/os/threads_windows.c +0 -40
- package/libusb/libusb/os/threads_windows.h +0 -113
- package/libusb/libusb/os/windows_common.c +0 -923
- package/libusb/libusb/os/windows_common.h +0 -424
- package/libusb/libusb/os/windows_usbdk.c +0 -724
- package/libusb/libusb/os/windows_usbdk.h +0 -106
- package/libusb/libusb/os/windows_winusb.c +0 -4766
- package/libusb/libusb/os/windows_winusb.h +0 -787
- package/libusb/libusb/strerror.c +0 -223
- package/libusb/libusb/sync.c +0 -342
- package/libusb/libusb/version.h +0 -18
- package/libusb/libusb/version_nano.h +0 -1
- package/libusb/libusb-1.0.pc.in +0 -11
- package/libusb/msvc/Base.props +0 -60
- package/libusb/msvc/Configuration.Application.props +0 -7
- package/libusb/msvc/Configuration.Base.props +0 -47
- package/libusb/msvc/Configuration.DynamicLibrary.props +0 -21
- package/libusb/msvc/Configuration.StaticLibrary.props +0 -7
- package/libusb/msvc/ProjectConfigurations.Base.props +0 -69
- package/libusb/msvc/build_all.ps1 +0 -17
- package/libusb/msvc/config.h +0 -58
- package/libusb/msvc/dpfp.vcxproj +0 -33
- package/libusb/msvc/dpfp_threaded.vcxproj +0 -38
- package/libusb/msvc/fxload.vcxproj +0 -46
- package/libusb/msvc/getopt/getopt.c +0 -1060
- package/libusb/msvc/getopt/getopt.h +0 -180
- package/libusb/msvc/getopt/getopt1.c +0 -188
- package/libusb/msvc/getopt.vcxproj +0 -33
- package/libusb/msvc/hotplugtest.vcxproj +0 -32
- package/libusb/msvc/init_context.vcxproj +0 -35
- package/libusb/msvc/libusb.sln +0 -542
- package/libusb/msvc/libusb_dll.vcxproj +0 -61
- package/libusb/msvc/libusb_static.vcxproj +0 -49
- package/libusb/msvc/listdevs.vcxproj +0 -32
- package/libusb/msvc/sam3u_benchmark.vcxproj +0 -33
- package/libusb/msvc/set_option.vcxproj +0 -35
- package/libusb/msvc/stress.vcxproj +0 -35
- package/libusb/msvc/stress_mt.vcxproj +0 -33
- package/libusb/msvc/testlibusb.vcxproj +0 -32
- package/libusb/msvc/xusb.vcxproj +0 -38
- package/libusb/tests/Makefile.am +0 -40
- package/libusb/tests/init_context.c +0 -153
- package/libusb/tests/libusb_testlib.h +0 -76
- package/libusb/tests/macos.c +0 -130
- package/libusb/tests/set_option.c +0 -253
- package/libusb/tests/stress.c +0 -172
- package/libusb/tests/stress_mt.c +0 -267
- package/libusb/tests/testlib.c +0 -184
- package/libusb/tests/umockdev.c +0 -1175
- package/libusb/tests/webusb-test-shim/index.js +0 -12
- package/libusb/tests/webusb-test-shim/package-lock.json +0 -50
- package/libusb/tests/webusb-test-shim/package.json +0 -10
- package/libusb.gypi +0 -154
- package/libusb_config/config.h +0 -1
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-arm64/node.napi.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +0 -439
- package/src/helpers.h +0 -64
- package/src/hotplug/hotplug.h +0 -22
- package/src/hotplug/libusb.cc +0 -90
- package/src/hotplug/windows.cc +0 -168
- package/src/node_usb.cc +0 -314
- package/src/node_usb.h +0 -131
- package/src/thread_name.cc +0 -79
- package/src/thread_name.h +0 -11
- package/src/transfer.cc +0 -143
- package/src/uv_async_queue.h +0 -41
- package/test/usb.coffee +0 -250
- package/test/webusb.coffee +0 -227
- package/test/worker.cjs +0 -13
package/src/transfer.cc
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
#include "node_usb.h"
|
|
2
|
-
|
|
3
|
-
extern "C" void LIBUSB_CALL usbCompletionCb(libusb_transfer *transfer);
|
|
4
|
-
|
|
5
|
-
Transfer::Transfer(const Napi::CallbackInfo& info)
|
|
6
|
-
: Napi::ObjectWrap<Transfer>(info) {
|
|
7
|
-
transfer = libusb_alloc_transfer(0);
|
|
8
|
-
transfer->callback = usbCompletionCb;
|
|
9
|
-
transfer->user_data = this;
|
|
10
|
-
DEBUG_LOG("Created Transfer %p", this);
|
|
11
|
-
Constructor(info);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
Transfer::~Transfer(){
|
|
15
|
-
DEBUG_LOG("Freed Transfer %p", this);
|
|
16
|
-
v8callback.Reset();
|
|
17
|
-
libusb_free_transfer(transfer);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// new Transfer(device, endpointAddr, type, timeout)
|
|
21
|
-
Napi::Value Transfer::Constructor(const Napi::CallbackInfo& info) {
|
|
22
|
-
Napi::Env env = info.Env();
|
|
23
|
-
ENTER_CONSTRUCTOR(5);
|
|
24
|
-
UNWRAP_ARG(Device, device, 0);
|
|
25
|
-
int endpoint, type, timeout;
|
|
26
|
-
INT_ARG(endpoint, 1);
|
|
27
|
-
INT_ARG(type, 2);
|
|
28
|
-
INT_ARG(timeout, 3);
|
|
29
|
-
CALLBACK_ARG(4);
|
|
30
|
-
|
|
31
|
-
info.This().As<Napi::Object>().DefineProperty(Napi::PropertyDescriptor::Value(std::string("device"), info[0], CONST_PROP));
|
|
32
|
-
auto self = this;
|
|
33
|
-
self->device = device;
|
|
34
|
-
self->transfer->endpoint = endpoint;
|
|
35
|
-
self->transfer->type = type;
|
|
36
|
-
self->transfer->timeout = timeout;
|
|
37
|
-
|
|
38
|
-
self->v8callback.Reset(callback, 1);
|
|
39
|
-
|
|
40
|
-
return info.This();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Transfer.submit(buffer, callback)
|
|
44
|
-
Napi::Value Transfer::Submit(const Napi::CallbackInfo& info) {
|
|
45
|
-
ENTER_METHOD(Transfer, 1);
|
|
46
|
-
|
|
47
|
-
if (self->transfer->buffer){
|
|
48
|
-
THROW_ERROR("Transfer is already active")
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (!info[0].IsBuffer()){
|
|
52
|
-
THROW_BAD_ARGS("Buffer arg [0] must be Buffer");
|
|
53
|
-
}
|
|
54
|
-
Napi::Buffer<unsigned char> buffer_obj = info[0].As<Napi::Buffer<unsigned char>>();
|
|
55
|
-
if (!self->device->device_handle){
|
|
56
|
-
THROW_ERROR("Device is not open");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Can't be cached in constructor as device could be closed and re-opened
|
|
60
|
-
self->transfer->dev_handle = self->device->device_handle;
|
|
61
|
-
|
|
62
|
-
self->v8buffer.Reset(buffer_obj, 1);
|
|
63
|
-
self->transfer->buffer = (unsigned char*) buffer_obj.Data();
|
|
64
|
-
self->transfer->length = buffer_obj.ByteLength();
|
|
65
|
-
|
|
66
|
-
DEBUG_LOG("Submitting, %p %p %x %i %i %i %p",
|
|
67
|
-
self,
|
|
68
|
-
self->transfer->dev_handle,
|
|
69
|
-
self->transfer->endpoint,
|
|
70
|
-
self->transfer->type,
|
|
71
|
-
self->transfer->timeout,
|
|
72
|
-
self->transfer->length,
|
|
73
|
-
self->transfer->buffer
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
CHECK_USB(libusb_submit_transfer(self->transfer));
|
|
77
|
-
self->ref();
|
|
78
|
-
self->device->ref();
|
|
79
|
-
|
|
80
|
-
return info.This();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
extern "C" void LIBUSB_CALL usbCompletionCb(libusb_transfer *transfer){
|
|
84
|
-
Transfer* t = static_cast<Transfer*>(transfer->user_data);
|
|
85
|
-
DEBUG_LOG("Completion callback %p", t);
|
|
86
|
-
assert(t != NULL);
|
|
87
|
-
t->device->completionQueue.post(t);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
void handleCompletion(Transfer* self){
|
|
91
|
-
Napi::Env env = self->Env();
|
|
92
|
-
Napi::HandleScope scope(env);
|
|
93
|
-
DEBUG_LOG("HandleCompletion %p", self);
|
|
94
|
-
|
|
95
|
-
self->device->unref();
|
|
96
|
-
|
|
97
|
-
// The callback may resubmit and overwrite these, so need to clear the
|
|
98
|
-
// persistent first.
|
|
99
|
-
Napi::Object buffer = self->v8buffer.Value();
|
|
100
|
-
self->v8buffer.Reset();
|
|
101
|
-
self->transfer->buffer = NULL;
|
|
102
|
-
|
|
103
|
-
if (!self->v8callback.IsEmpty()) {
|
|
104
|
-
Napi::Value error = env.Undefined();
|
|
105
|
-
if (self->transfer->status != 0){
|
|
106
|
-
error = libusbException(env, self->transfer->status).Value();
|
|
107
|
-
}
|
|
108
|
-
try {
|
|
109
|
-
self->v8callback.MakeCallback(self->Value(), { error, buffer,
|
|
110
|
-
Napi::Number::New(env, (uint32_t)self->transfer->actual_length) });
|
|
111
|
-
}
|
|
112
|
-
catch (const Napi::Error& e) {
|
|
113
|
-
e.ThrowAsJavaScriptException();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
self->unref();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
Napi::Value Transfer::Cancel(const Napi::CallbackInfo& info){
|
|
121
|
-
ENTER_METHOD(Transfer, 0);
|
|
122
|
-
DEBUG_LOG("Cancel %p %i", self, !!self->transfer->buffer);
|
|
123
|
-
int r = libusb_cancel_transfer(self->transfer);
|
|
124
|
-
if (r == LIBUSB_ERROR_NOT_FOUND){
|
|
125
|
-
// Not useful to throw an error for this case
|
|
126
|
-
return Napi::Boolean::New(env, false);
|
|
127
|
-
} else {
|
|
128
|
-
CHECK_USB(r);
|
|
129
|
-
return Napi::Boolean::New(env, true);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
Napi::Object Transfer::Init(Napi::Env env, Napi::Object exports) {
|
|
134
|
-
exports.Set("Transfer", Transfer::DefineClass(
|
|
135
|
-
env,
|
|
136
|
-
"Transfer",
|
|
137
|
-
{
|
|
138
|
-
Transfer::InstanceMethod("submit", &Transfer::Submit),
|
|
139
|
-
Transfer::InstanceMethod("cancel", &Transfer::Cancel),
|
|
140
|
-
}));
|
|
141
|
-
|
|
142
|
-
return exports;
|
|
143
|
-
}
|
package/src/uv_async_queue.h
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
#ifndef SRC_UV_ASYNC_QUEUE_H
|
|
2
|
-
#define SRC_UV_ASYNC_QUEUE_H
|
|
3
|
-
|
|
4
|
-
template <class T>
|
|
5
|
-
class UVQueue{
|
|
6
|
-
public:
|
|
7
|
-
typedef void (*fptr)(T);
|
|
8
|
-
|
|
9
|
-
Napi::ThreadSafeFunction tsfn;
|
|
10
|
-
|
|
11
|
-
UVQueue(fptr cb): callback(cb) {}
|
|
12
|
-
|
|
13
|
-
void start(Napi::Env env) {
|
|
14
|
-
Napi::Function empty_func = Napi::Function::New(env, [](const Napi::CallbackInfo& cb) {});
|
|
15
|
-
tsfn = Napi::ThreadSafeFunction::New(env, empty_func, "libusb", 0, 1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
void stop() {
|
|
19
|
-
tsfn.Release();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
void ref(Napi::Env env) {
|
|
23
|
-
tsfn.Ref(env);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
void unref(Napi::Env env) {
|
|
27
|
-
tsfn.Unref(env);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
void post(T value){
|
|
31
|
-
auto cb = callback;
|
|
32
|
-
tsfn.BlockingCall( value, [cb](Napi::Env _env, Napi::Function _jsCallback, T val) {
|
|
33
|
-
cb(val);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private:
|
|
38
|
-
fptr callback;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
#endif
|
package/test/usb.coffee
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
assert = require('assert')
|
|
2
|
-
util = require('util')
|
|
3
|
-
usb = require('../').usb
|
|
4
|
-
getDeviceList = require('../').getDeviceList
|
|
5
|
-
findByIds = require('../').findByIds
|
|
6
|
-
findBySerialNumber = require('../').findBySerialNumber
|
|
7
|
-
Worker = require('worker_threads').Worker
|
|
8
|
-
|
|
9
|
-
if typeof gc is 'function'
|
|
10
|
-
# running with --expose-gc, do a sweep between tests so valgrind blames the right one
|
|
11
|
-
afterEach -> gc()
|
|
12
|
-
|
|
13
|
-
describe 'USB Module', ->
|
|
14
|
-
it 'should describe basic constants', ->
|
|
15
|
-
assert.notEqual(usb, undefined, "usb must be undefined")
|
|
16
|
-
assert.ok((usb.LIBUSB_CLASS_PER_INTERFACE != undefined), "Constants must be described")
|
|
17
|
-
assert.ok((usb.LIBUSB_ENDPOINT_IN == 128))
|
|
18
|
-
|
|
19
|
-
it 'should handle abuse without crashing', ->
|
|
20
|
-
assert.throws -> new usb.Device()
|
|
21
|
-
assert.throws -> usb.Device()
|
|
22
|
-
assert.throws -> usb.Device.prototype.open.call({})
|
|
23
|
-
|
|
24
|
-
describe 'setDebugLevel', ->
|
|
25
|
-
it 'should throw when passed invalid args', ->
|
|
26
|
-
assert.throws((-> usb.setDebugLevel()), TypeError)
|
|
27
|
-
assert.throws((-> usb.setDebugLevel(-1)), TypeError)
|
|
28
|
-
assert.throws((-> usb.setDebugLevel(5)), TypeError)
|
|
29
|
-
|
|
30
|
-
it 'should succeed with good args', ->
|
|
31
|
-
assert.doesNotThrow(-> usb.setDebugLevel(0))
|
|
32
|
-
|
|
33
|
-
describe 'getDeviceList', ->
|
|
34
|
-
it 'should return at least one device', ->
|
|
35
|
-
l = getDeviceList()
|
|
36
|
-
assert.ok((l.length > 0))
|
|
37
|
-
|
|
38
|
-
describe 'findByIds', ->
|
|
39
|
-
it 'should return an array with length > 0', ->
|
|
40
|
-
dev = findByIds(0x59e3, 0x0a23)
|
|
41
|
-
assert.ok(dev, "Demo device is not attached")
|
|
42
|
-
|
|
43
|
-
describe 'findBySerialNumber', ->
|
|
44
|
-
it 'should return a single device', ->
|
|
45
|
-
dev = findBySerialNumber('TEST_DEVICE')
|
|
46
|
-
assert.ok(dev, "Demo device is not attached")
|
|
47
|
-
|
|
48
|
-
describe 'Hotplug', ->
|
|
49
|
-
it 'should detect detach', (done) ->
|
|
50
|
-
usb.once 'detach', (d) ->
|
|
51
|
-
assert.equal(d.deviceDescriptor.idVendor, 0x59e3)
|
|
52
|
-
assert.equal(d.deviceDescriptor.idProduct, 0x0a23)
|
|
53
|
-
done()
|
|
54
|
-
console.log('\n--- DISCONNECT DEVICE ---\n')
|
|
55
|
-
|
|
56
|
-
it 'should detect attach', (done) ->
|
|
57
|
-
usb.once 'attach', (d) ->
|
|
58
|
-
assert.equal(d.deviceDescriptor.idVendor, 0x59e3)
|
|
59
|
-
assert.equal(d.deviceDescriptor.idProduct, 0x0a23)
|
|
60
|
-
done()
|
|
61
|
-
console.log('\n--- CONNECT DEVICE ---\n')
|
|
62
|
-
|
|
63
|
-
describe 'Device', ->
|
|
64
|
-
device = null
|
|
65
|
-
before ->
|
|
66
|
-
device = findByIds(0x59e3, 0x0a23)
|
|
67
|
-
|
|
68
|
-
it 'should have sane properties', ->
|
|
69
|
-
assert.ok((device.busNumber > 0), "busNumber must be larger than 0")
|
|
70
|
-
assert.ok((device.deviceAddress > 0), "deviceAddress must be larger than 0")
|
|
71
|
-
if process.platform != 'darwin' || process.arch != 'arm64'
|
|
72
|
-
assert.ok((util.isArray(device.portNumbers)), "portNumbers must be an array")
|
|
73
|
-
|
|
74
|
-
it 'should have a deviceDescriptor property', ->
|
|
75
|
-
assert.ok(((deviceDesc = device.deviceDescriptor) != undefined))
|
|
76
|
-
|
|
77
|
-
it 'should have a configDescriptor property', ->
|
|
78
|
-
assert.ok(device.configDescriptor != undefined)
|
|
79
|
-
|
|
80
|
-
it 'should open', ->
|
|
81
|
-
device.open()
|
|
82
|
-
|
|
83
|
-
it 'gets string descriptors', (done) ->
|
|
84
|
-
device.getStringDescriptor device.deviceDescriptor.iManufacturer, (e, s) ->
|
|
85
|
-
assert.ok(e == undefined, e)
|
|
86
|
-
assert.equal(s, 'Nonolith Labs')
|
|
87
|
-
done()
|
|
88
|
-
|
|
89
|
-
it 'supports null string descriptors', (done) ->
|
|
90
|
-
device.getStringDescriptor device.configDescriptor.iConfiguration, (e, s) ->
|
|
91
|
-
assert.ok(e == undefined, e)
|
|
92
|
-
assert.equal(s, undefined)
|
|
93
|
-
done()
|
|
94
|
-
|
|
95
|
-
describe 'control transfer', ->
|
|
96
|
-
b = Buffer.from([0x30...0x40])
|
|
97
|
-
it 'should OUT transfer when the IN bit is not set', (done) ->
|
|
98
|
-
device.controlTransfer 0x40, 0x81, 0, 0, b, (e) ->
|
|
99
|
-
assert.ok(e == undefined, e)
|
|
100
|
-
done()
|
|
101
|
-
|
|
102
|
-
it 'should fail when bmRequestType doesn\'t match buffer / length', ->
|
|
103
|
-
assert.throws(-> device.controlTransfer(0x40, 0x81, 0, 0, 64))
|
|
104
|
-
|
|
105
|
-
it 'should IN transfer when the IN bit is set', (done) ->
|
|
106
|
-
device.controlTransfer 0xc0, 0x81, 0, 0, 128, (e, d) ->
|
|
107
|
-
#console.log("ControlTransferIn", d, e)
|
|
108
|
-
assert.ok(e == undefined, e)
|
|
109
|
-
assert.equal(d.toString(), b.toString())
|
|
110
|
-
done()
|
|
111
|
-
|
|
112
|
-
it 'should signal errors', (done) ->
|
|
113
|
-
device.controlTransfer 0xc0, 0xff, 0, 0, 64, (e, d) ->
|
|
114
|
-
assert.equal e.errno, usb.LIBUSB_TRANSFER_STALL
|
|
115
|
-
done()
|
|
116
|
-
|
|
117
|
-
describe 'Interface', ->
|
|
118
|
-
iface = null
|
|
119
|
-
before ->
|
|
120
|
-
iface = device.interfaces[0]
|
|
121
|
-
iface.claim()
|
|
122
|
-
|
|
123
|
-
it 'should have one interface', ->
|
|
124
|
-
assert.notEqual(iface, undefined)
|
|
125
|
-
|
|
126
|
-
it 'should be the same as the interfaceNo 0', ->
|
|
127
|
-
assert.strictEqual iface, device.interface(0)
|
|
128
|
-
|
|
129
|
-
if process.platform == 'linux'
|
|
130
|
-
it "shouldn't have a kernel driver", ->
|
|
131
|
-
assert.equal iface.isKernelDriverActive(), false
|
|
132
|
-
|
|
133
|
-
it "should fail to detach the kernel driver", ->
|
|
134
|
-
assert.throws -> iface.detachKernelDriver()
|
|
135
|
-
|
|
136
|
-
it "should fail to attach the kernel driver", ->
|
|
137
|
-
assert.throws -> iface.attachKernelDriver()
|
|
138
|
-
|
|
139
|
-
describe 'IN endpoint', ->
|
|
140
|
-
inEndpoint = null
|
|
141
|
-
before ->
|
|
142
|
-
inEndpoint = iface.endpoints[0]
|
|
143
|
-
|
|
144
|
-
it 'should be able to get the endpoint', ->
|
|
145
|
-
assert.ok inEndpoint?
|
|
146
|
-
|
|
147
|
-
it 'should be able to get the endpoint by address', ->
|
|
148
|
-
assert.equal(inEndpoint, iface.endpoint(0x81))
|
|
149
|
-
|
|
150
|
-
it 'should have the IN direction flag', ->
|
|
151
|
-
assert.equal(inEndpoint.direction, 'in')
|
|
152
|
-
|
|
153
|
-
it 'should have a descriptor', ->
|
|
154
|
-
assert.equal(inEndpoint.descriptor.bEndpointAddress, 0x81)
|
|
155
|
-
assert.equal(inEndpoint.descriptor.wMaxPacketSize, 64)
|
|
156
|
-
|
|
157
|
-
it 'should fail to write', ->
|
|
158
|
-
assert.throws -> inEndpoint.transfer(b)
|
|
159
|
-
|
|
160
|
-
it 'should support read', (done) ->
|
|
161
|
-
inEndpoint.transfer 64, (e, d) ->
|
|
162
|
-
assert.ok(e == undefined, e)
|
|
163
|
-
assert.ok(d.length == 64)
|
|
164
|
-
done()
|
|
165
|
-
|
|
166
|
-
it 'times out', (done) ->
|
|
167
|
-
iface.endpoints[2].timeout = 20
|
|
168
|
-
iface.endpoints[2].transfer 64, (e, d) ->
|
|
169
|
-
assert.equal e.errno, usb.LIBUSB_TRANSFER_TIMED_OUT
|
|
170
|
-
done()
|
|
171
|
-
|
|
172
|
-
it 'polls the device using events', (done) ->
|
|
173
|
-
pkts = 0
|
|
174
|
-
|
|
175
|
-
inEndpoint.startPoll 8, 64
|
|
176
|
-
inEndpoint.on 'data', (d) ->
|
|
177
|
-
assert.equal d.length, 64
|
|
178
|
-
pkts++
|
|
179
|
-
|
|
180
|
-
if pkts == 100
|
|
181
|
-
inEndpoint.stopPoll()
|
|
182
|
-
|
|
183
|
-
inEndpoint.once 'error', (e) ->
|
|
184
|
-
throw e
|
|
185
|
-
|
|
186
|
-
inEndpoint.once 'end', ->
|
|
187
|
-
done()
|
|
188
|
-
|
|
189
|
-
it 'polls the device using a callback', (done) ->
|
|
190
|
-
pkts = 0
|
|
191
|
-
|
|
192
|
-
inEndpoint.startPoll 8, 64, (e, b, a, c) ->
|
|
193
|
-
assert.equal(c, true)
|
|
194
|
-
assert.ok(e == undefined, e)
|
|
195
|
-
assert.equal(pkts, 100)
|
|
196
|
-
done()
|
|
197
|
-
|
|
198
|
-
inEndpoint.on 'data', (d) ->
|
|
199
|
-
assert.equal d.length, 64
|
|
200
|
-
pkts++
|
|
201
|
-
|
|
202
|
-
if pkts == 100
|
|
203
|
-
inEndpoint.stopPoll()
|
|
204
|
-
|
|
205
|
-
inEndpoint.once 'error', (e) ->
|
|
206
|
-
throw e
|
|
207
|
-
|
|
208
|
-
inEndpoint.once 'end', ->
|
|
209
|
-
assert.equal(pkts, 100)
|
|
210
|
-
|
|
211
|
-
describe 'OUT endpoint', ->
|
|
212
|
-
outEndpoint = null
|
|
213
|
-
before ->
|
|
214
|
-
outEndpoint = iface.endpoints[1]
|
|
215
|
-
|
|
216
|
-
it 'should be able to get the endpoint', ->
|
|
217
|
-
assert.ok outEndpoint?
|
|
218
|
-
|
|
219
|
-
it 'should be able to get the endpoint by address', ->
|
|
220
|
-
assert.equal(outEndpoint, iface.endpoint(0x02))
|
|
221
|
-
|
|
222
|
-
it 'should have the OUT direction flag', ->
|
|
223
|
-
assert.equal(outEndpoint.direction, 'out')
|
|
224
|
-
|
|
225
|
-
it 'should support write', (done) ->
|
|
226
|
-
outEndpoint.transfer [1,2,3,4], (e) ->
|
|
227
|
-
assert.ok(e == undefined, e)
|
|
228
|
-
done()
|
|
229
|
-
|
|
230
|
-
it 'times out', (done) ->
|
|
231
|
-
iface.endpoints[3].timeout = 20
|
|
232
|
-
iface.endpoints[3].transfer [1,2,3,4], (e) ->
|
|
233
|
-
assert.equal e.errno, usb.LIBUSB_TRANSFER_TIMED_OUT
|
|
234
|
-
done()
|
|
235
|
-
|
|
236
|
-
after (cb) ->
|
|
237
|
-
iface.release(cb)
|
|
238
|
-
|
|
239
|
-
after ->
|
|
240
|
-
device.close()
|
|
241
|
-
|
|
242
|
-
if process.platform != 'win32'
|
|
243
|
-
describe 'Context Aware', ->
|
|
244
|
-
it 'should handle opening the same device from different contexts', ->
|
|
245
|
-
for n in [1..5]
|
|
246
|
-
worker = new Worker('./test/worker.cjs')
|
|
247
|
-
worker.on 'message', (serial) ->
|
|
248
|
-
assert.equal(serial, 'TEST_DEVICE')
|
|
249
|
-
worker.on 'exit', (code) ->
|
|
250
|
-
assert.equal(code, 0)
|
package/test/webusb.coffee
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
assert = require('assert')
|
|
2
|
-
util = require('util')
|
|
3
|
-
webusb = require('../').webusb
|
|
4
|
-
WebUSB = require('../').WebUSB
|
|
5
|
-
|
|
6
|
-
if typeof gc is 'function'
|
|
7
|
-
# running with --expose-gc, do a sweep between tests so valgrind blames the right one
|
|
8
|
-
afterEach -> gc()
|
|
9
|
-
|
|
10
|
-
describe 'WebUSB Module', ->
|
|
11
|
-
it 'should describe basic constants', ->
|
|
12
|
-
assert.notEqual(webusb, undefined, "webusb must be undefined")
|
|
13
|
-
|
|
14
|
-
describe 'allowedDevices', ->
|
|
15
|
-
it 'should not list any devices by default', ->
|
|
16
|
-
l = await webusb.getDevices()
|
|
17
|
-
assert.equal(l.length, 0)
|
|
18
|
-
|
|
19
|
-
it 'should list allowed devices', ->
|
|
20
|
-
customWebusb = new WebUSB({ allowedDevices: [{ vendorId: 0x59e3 }] })
|
|
21
|
-
l = await customWebusb.getDevices()
|
|
22
|
-
assert.equal(l.length, 1)
|
|
23
|
-
assert.notEqual(l[0], undefined)
|
|
24
|
-
|
|
25
|
-
describe 'requestDevice', ->
|
|
26
|
-
it 'should return a device', ->
|
|
27
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
28
|
-
assert.notEqual(device, undefined)
|
|
29
|
-
|
|
30
|
-
describe 'getDevices', ->
|
|
31
|
-
it 'should return one device', ->
|
|
32
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
33
|
-
l = await webusb.getDevices()
|
|
34
|
-
assert.equal(l.length, 1)
|
|
35
|
-
assert.notEqual(l[0], undefined)
|
|
36
|
-
assert.deepEqual(l[0], device)
|
|
37
|
-
|
|
38
|
-
describe 'WebUSB Hotplug', ->
|
|
39
|
-
it 'should detect disconnect', (done) ->
|
|
40
|
-
fn = (e) ->
|
|
41
|
-
assert.equal(e.device.serialNumber, "TEST_DEVICE")
|
|
42
|
-
webusb.removeEventListener 'disconnect', fn
|
|
43
|
-
done()
|
|
44
|
-
webusb.addEventListener 'disconnect', fn
|
|
45
|
-
console.log('\n--- DISCONNECT DEVICE ---\n')
|
|
46
|
-
|
|
47
|
-
it 'should detect connect', (done) ->
|
|
48
|
-
fn = (e) ->
|
|
49
|
-
assert.equal(e.device.serialNumber, "TEST_DEVICE")
|
|
50
|
-
webusb.removeEventListener 'connect', fn
|
|
51
|
-
done()
|
|
52
|
-
webusb.addEventListener 'connect', fn
|
|
53
|
-
console.log('\n--- CONNECT DEVICE ---\n')
|
|
54
|
-
|
|
55
|
-
describe 'Device properties', ->
|
|
56
|
-
device = null
|
|
57
|
-
before ->
|
|
58
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
59
|
-
|
|
60
|
-
it 'should have usb version properties', ->
|
|
61
|
-
assert.equal(device.usbVersionMajor, 1)
|
|
62
|
-
assert.equal(device.usbVersionMinor, 1)
|
|
63
|
-
assert.equal(device.usbVersionSubminor, 0)
|
|
64
|
-
|
|
65
|
-
it 'should have device version properties', ->
|
|
66
|
-
assert.equal(device.deviceVersionMajor, 1)
|
|
67
|
-
assert.equal(device.deviceVersionMinor, 1)
|
|
68
|
-
assert.equal(device.deviceVersionSubminor, 0)
|
|
69
|
-
|
|
70
|
-
it 'should have class properties', ->
|
|
71
|
-
assert.equal(device.deviceClass, 0)
|
|
72
|
-
assert.equal(device.deviceSubclass, 0)
|
|
73
|
-
|
|
74
|
-
it 'should have protocol property', ->
|
|
75
|
-
assert.equal(device.deviceProtocol, 0)
|
|
76
|
-
|
|
77
|
-
it 'should have vid/pid properties', ->
|
|
78
|
-
assert.equal(device.vendorId, 0x59e3)
|
|
79
|
-
assert.equal(device.productId, 0x0a23)
|
|
80
|
-
|
|
81
|
-
it 'should have a single configuration', ->
|
|
82
|
-
assert.equal(device.configurations.length, 1)
|
|
83
|
-
assert.equal(device.configurations[0].configurationValue, 1)
|
|
84
|
-
|
|
85
|
-
it 'should have a configuration property', ->
|
|
86
|
-
assert.notEqual(device.configuration, undefined)
|
|
87
|
-
|
|
88
|
-
it 'should have a single interface', ->
|
|
89
|
-
assert.equal(device.configuration.interfaces.length, 1)
|
|
90
|
-
assert.equal(device.configuration.interfaces[0].interfaceNumber, 0)
|
|
91
|
-
|
|
92
|
-
it 'should have a single alternate', ->
|
|
93
|
-
assert.equal(device.configuration.interfaces[0].alternates.length, 1)
|
|
94
|
-
assert.equal(device.configuration.interfaces[0].alternates[0].alternateSetting, 0)
|
|
95
|
-
|
|
96
|
-
describe 'String descriptors', ->
|
|
97
|
-
device = null
|
|
98
|
-
before ->
|
|
99
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
100
|
-
|
|
101
|
-
it 'gets serialNumber string', ->
|
|
102
|
-
assert.equal(device.serialNumber, "TEST_DEVICE")
|
|
103
|
-
|
|
104
|
-
it 'gets manufacturerName string', ->
|
|
105
|
-
assert.equal(device.manufacturerName, "Nonolith Labs")
|
|
106
|
-
|
|
107
|
-
it 'gets productName string', ->
|
|
108
|
-
assert.equal(device.productName, "STM32F103 Test Device")
|
|
109
|
-
|
|
110
|
-
describe 'Device access', ->
|
|
111
|
-
device = null
|
|
112
|
-
before ->
|
|
113
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
114
|
-
|
|
115
|
-
it 'is not open', ->
|
|
116
|
-
assert.equal(device.opened, false)
|
|
117
|
-
|
|
118
|
-
it 'is opens and closes', ->
|
|
119
|
-
assert.equal(device.opened, false)
|
|
120
|
-
await device.open()
|
|
121
|
-
assert.equal(device.opened, true)
|
|
122
|
-
await device.close()
|
|
123
|
-
assert.equal(device.opened, false)
|
|
124
|
-
|
|
125
|
-
describe 'Configurations', ->
|
|
126
|
-
device = null
|
|
127
|
-
before ->
|
|
128
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
129
|
-
await device.open()
|
|
130
|
-
|
|
131
|
-
it 'selects existing configuration', ->
|
|
132
|
-
assert.doesNotReject(device.selectConfiguration(1))
|
|
133
|
-
|
|
134
|
-
it 'fails to select missing configuration', ->
|
|
135
|
-
assert.rejects(device.selectConfiguration(99))
|
|
136
|
-
|
|
137
|
-
after ->
|
|
138
|
-
device.close()
|
|
139
|
-
|
|
140
|
-
describe 'Interfaces', ->
|
|
141
|
-
device = null
|
|
142
|
-
before ->
|
|
143
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
144
|
-
await device.open()
|
|
145
|
-
|
|
146
|
-
it 'claims existing interface', ->
|
|
147
|
-
assert.doesNotReject(device.claimInterface(0))
|
|
148
|
-
|
|
149
|
-
it 'fails to claim missing interface', ->
|
|
150
|
-
assert.rejects(device.claimInterface(99))
|
|
151
|
-
|
|
152
|
-
it 'releases existing interface', ->
|
|
153
|
-
assert.doesNotReject(device.releaseInterface(0))
|
|
154
|
-
|
|
155
|
-
it 'fails to release missing interface', ->
|
|
156
|
-
assert.rejects(device.releaseInterface(99))
|
|
157
|
-
|
|
158
|
-
after ->
|
|
159
|
-
device.close()
|
|
160
|
-
|
|
161
|
-
describe 'Alternates', ->
|
|
162
|
-
device = null
|
|
163
|
-
before ->
|
|
164
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
165
|
-
await device.open()
|
|
166
|
-
await device.claimInterface(0)
|
|
167
|
-
|
|
168
|
-
it 'selects existing alternate', ->
|
|
169
|
-
assert.doesNotReject(device.selectAlternateInterface(0, 0))
|
|
170
|
-
|
|
171
|
-
after ->
|
|
172
|
-
device.close()
|
|
173
|
-
|
|
174
|
-
describe 'Throwing Transfers', ->
|
|
175
|
-
device = null
|
|
176
|
-
|
|
177
|
-
before ->
|
|
178
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
179
|
-
|
|
180
|
-
it 'should fail transfer unless opened', ->
|
|
181
|
-
assert.rejects(device.transferIn(1, 64), 'The device must be opened first')
|
|
182
|
-
|
|
183
|
-
describe 'Transfers', ->
|
|
184
|
-
device = null
|
|
185
|
-
b = Uint8Array.from([0x30...0x40]).buffer
|
|
186
|
-
|
|
187
|
-
before ->
|
|
188
|
-
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|
|
189
|
-
await device.open()
|
|
190
|
-
await device.claimInterface(0)
|
|
191
|
-
|
|
192
|
-
it 'should control transfer OUT', ->
|
|
193
|
-
transferResult = await device.controlTransferOut({
|
|
194
|
-
requestType: 'device',
|
|
195
|
-
recipient: 'vendor',
|
|
196
|
-
request: 0x81,
|
|
197
|
-
value: 0,
|
|
198
|
-
index: 0
|
|
199
|
-
}, b)
|
|
200
|
-
|
|
201
|
-
assert.equal(transferResult.status, 'ok')
|
|
202
|
-
assert.equal(transferResult.bytesWritten, b.byteLength)
|
|
203
|
-
|
|
204
|
-
it 'should control transfer IN', ->
|
|
205
|
-
transferResult = await device.controlTransferIn({
|
|
206
|
-
requestType: 'device',
|
|
207
|
-
recipient: 'vendor',
|
|
208
|
-
request: 0x81,
|
|
209
|
-
value: 0,
|
|
210
|
-
index: 0
|
|
211
|
-
}, 128)
|
|
212
|
-
|
|
213
|
-
assert.equal(transferResult.status, 'ok')
|
|
214
|
-
assert.equal(transferResult.data.buffer.toString(), b.toString())
|
|
215
|
-
|
|
216
|
-
it 'should transfer OUT', ->
|
|
217
|
-
transferResult = await device.transferOut(2, b)
|
|
218
|
-
assert.equal(transferResult.status, 'ok')
|
|
219
|
-
assert.equal(transferResult.bytesWritten, b.byteLength)
|
|
220
|
-
|
|
221
|
-
it 'should transfer IN', ->
|
|
222
|
-
transferResult = await device.transferIn(1, 64)
|
|
223
|
-
assert.equal(transferResult.status, 'ok')
|
|
224
|
-
assert.equal(transferResult.data.byteLength, 64)
|
|
225
|
-
|
|
226
|
-
after ->
|
|
227
|
-
device.close()
|
package/test/worker.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const parentPort = require('worker_threads').parentPort
|
|
2
|
-
const findByIds = require('../dist').findByIds;
|
|
3
|
-
|
|
4
|
-
const device = findByIds(0x59e3, 0x0a23);
|
|
5
|
-
if (!device) {
|
|
6
|
-
console.error('No test device connected, tests require this device to be present');
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
device.open();
|
|
10
|
-
device.getStringDescriptor(device.deviceDescriptor.iSerialNumber, (_, serial) => {
|
|
11
|
-
parentPort?.postMessage(serial);
|
|
12
|
-
device.close();
|
|
13
|
-
});
|