brilliantsole 0.0.26 → 0.0.28
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 +16 -10
- package/assets/3d/anchor.glb +0 -0
- package/assets/3d/coin.glb +0 -0
- package/assets/3d/glasses.glb +0 -0
- package/assets/3d/rightHand.glb +0 -0
- package/assets/audio/bounceMedium.wav +0 -0
- package/assets/audio/bounceStrong.wav +0 -0
- package/assets/audio/bounceWeak.wav +0 -0
- package/assets/audio/coin.wav +0 -0
- package/assets/audio/getUp.wav +0 -0
- package/assets/audio/grab.wav +0 -0
- package/assets/audio/kick.wav +0 -0
- package/assets/audio/platterFadeIn old.wav +0 -0
- package/assets/audio/platterFadeIn.wav +0 -0
- package/assets/audio/platterFadeOut.wav +0 -0
- package/assets/audio/punch.wav +0 -0
- package/assets/audio/punchSqueak.wav +0 -0
- package/assets/audio/purr.wav +0 -0
- package/assets/audio/purrFadeOut.wav +0 -0
- package/assets/audio/release.wav +0 -0
- package/assets/audio/splat.wav +0 -0
- package/assets/audio/stomp.wav +0 -0
- package/assets/images/ukaton-pressure-0.svg +9 -0
- package/assets/images/ukaton-pressure-1.svg +9 -0
- package/assets/images/ukaton-pressure-10.svg +9 -0
- package/assets/images/ukaton-pressure-11.svg +9 -0
- package/assets/images/ukaton-pressure-12.svg +9 -0
- package/assets/images/ukaton-pressure-13.svg +9 -0
- package/assets/images/ukaton-pressure-14.svg +9 -0
- package/assets/images/ukaton-pressure-15.svg +9 -0
- package/assets/images/ukaton-pressure-2.svg +9 -0
- package/assets/images/ukaton-pressure-3.svg +9 -0
- package/assets/images/ukaton-pressure-4.svg +9 -0
- package/assets/images/ukaton-pressure-5.svg +9 -0
- package/assets/images/ukaton-pressure-6.svg +9 -0
- package/assets/images/ukaton-pressure-7.svg +9 -0
- package/assets/images/ukaton-pressure-8.svg +9 -0
- package/assets/images/ukaton-pressure-9.svg +9 -0
- package/assets/images/ukaton-right-insole.svg +798 -0
- package/build/brilliantsole.cjs +2870 -882
- package/build/brilliantsole.cjs.map +1 -1
- package/build/brilliantsole.js +2477 -782
- package/build/brilliantsole.js.map +1 -1
- package/build/brilliantsole.ls.js +2260 -592
- package/build/brilliantsole.ls.js.map +1 -1
- package/build/brilliantsole.min.js +1 -1
- package/build/brilliantsole.min.js.map +1 -1
- package/build/brilliantsole.module.d.ts +302 -116
- package/build/brilliantsole.module.js +2468 -782
- package/build/brilliantsole.module.js.map +1 -1
- package/build/brilliantsole.module.min.d.ts +302 -116
- package/build/brilliantsole.module.min.js +1 -1
- package/build/brilliantsole.module.min.js.map +1 -1
- package/build/brilliantsole.node.module.d.ts +295 -113
- package/build/brilliantsole.node.module.js +2860 -882
- package/build/brilliantsole.node.module.js.map +1 -1
- package/build/dts/BS-output.d.ts +10 -0
- package/build/dts/BS.d.ts +21 -9
- package/build/dts/CameraManager.d.ts +72 -0
- package/build/dts/Device.d.ts +53 -16
- package/build/dts/DeviceInformationManager.d.ts +4 -4
- package/build/dts/DeviceManager.d.ts +3 -0
- package/build/dts/FileTransferManager.d.ts +18 -8
- package/build/dts/InformationManager.d.ts +8 -5
- package/build/dts/TfliteManager.d.ts +22 -2
- package/build/dts/WifiManager.d.ts +61 -0
- package/build/dts/connection/BaseConnectionManager.d.ts +37 -3
- package/build/dts/connection/ClientConnectionManager.d.ts +11 -2
- package/build/dts/connection/bluetooth/BluetoothConnectionManager.d.ts +1 -0
- package/build/dts/connection/bluetooth/NobleConnectionManager.d.ts +3 -1
- package/build/dts/connection/bluetooth/WebBluetoothConnectionManager.d.ts +2 -0
- package/build/dts/connection/bluetooth/bluetoothUUIDs.d.ts +2 -2
- package/build/dts/connection/udp/UDPConnectionManager.d.ts +28 -0
- package/build/dts/connection/webSocket/WebSocketConnectionManager.d.ts +25 -0
- package/build/dts/devicePair/DevicePair.d.ts +14 -10
- package/build/dts/devicePair/DevicePairPressureSensorDataManager.d.ts +8 -4
- package/build/dts/devicePair/DevicePairSensorDataManager.d.ts +2 -2
- package/build/dts/scanner/BaseScanner.d.ts +4 -1
- package/build/dts/scanner/NobleScanner.d.ts +2 -1
- package/build/dts/sensor/MotionSensorDataManager.d.ts +5 -2
- package/build/dts/sensor/SensorDataManager.d.ts +5 -4
- package/build/dts/server/BaseClient.d.ts +6 -3
- package/build/dts/server/ServerUtils.d.ts +1 -1
- package/build/dts/server/websocket/WebSocketUtils.d.ts +1 -1
- package/build/dts/utils/CenterOfPressureHelper.d.ts +2 -2
- package/build/dts/utils/Console.d.ts +2 -0
- package/build/dts/utils/MathUtils.d.ts +2 -0
- package/build/dts/utils/ThrottleUtils.d.ts +2 -0
- package/build/dts/vibration/VibrationManager.d.ts +19 -2
- package/build/index.d.ts +299 -113
- package/build/index.node.d.ts +292 -110
- package/examples/3d/scene.html +19 -5
- package/examples/3d/script.js +90 -17
- package/examples/3d-generic/index.html +144 -0
- package/examples/3d-generic/script.js +266 -0
- package/examples/balance/script.js +2 -1
- package/examples/basic/index.html +232 -18
- package/examples/basic/script.js +746 -106
- package/examples/bottango/index.html +11 -1
- package/examples/bottango/script.js +2 -2
- package/examples/center-of-pressure/index.html +114 -114
- package/examples/center-of-pressure/script.js +1 -1
- package/examples/device-pair/index.html +58 -58
- package/examples/device-pair/script.js +12 -8
- package/examples/edge-impulse/script.js +135 -44
- package/examples/edge-impulse-test/README.md +11 -0
- package/examples/edge-impulse-test/edge-impulse-standalone.js +7228 -0
- package/examples/edge-impulse-test/edge-impulse-standalone.wasm +0 -0
- package/examples/edge-impulse-test/index.html +75 -0
- package/examples/edge-impulse-test/run-impulse.js +135 -0
- package/examples/edge-impulse-test/script.js +200 -0
- package/examples/gloves/edge-impulse-standalone.js +7228 -0
- package/examples/gloves/edge-impulse-standalone.wasm +0 -0
- package/examples/gloves/index.html +119 -0
- package/examples/gloves/run-impulse.js +135 -0
- package/examples/gloves/scene.html +124 -0
- package/examples/gloves/script.js +931 -0
- package/examples/graph/index.html +11 -1
- package/examples/graph/script.js +94 -37
- package/examples/pressure/index.html +180 -12
- package/examples/pressure/script.js +144 -7
- package/examples/punch/index.html +135 -0
- package/examples/punch/punch.tflite +0 -0
- package/examples/punch/script.js +169 -0
- package/examples/recording/index.html +191 -183
- package/examples/server/index.html +109 -23
- package/examples/server/script.js +322 -111
- package/examples/ukaton-firmware-update/index.html +20 -0
- package/examples/ukaton-firmware-update/manifest.json +11 -0
- package/examples/ukaton-firmware-update/merged-firmware.bin +0 -0
- package/examples/utils/aframe/aframe-master.min.js +2 -0
- package/examples/utils/aframe/bs-vibration.js +150 -0
- package/examples/utils/aframe/force-pushable.js +80 -0
- package/examples/utils/aframe/grabbable-anchor.js +46 -0
- package/examples/utils/aframe/grabbable-listener.js +31 -0
- package/examples/utils/aframe/grabbable-physics-body.js +190 -0
- package/examples/utils/aframe/grow-shrink.js +25 -0
- package/examples/utils/aframe/hand-punch.js +119 -0
- package/examples/utils/aframe/my-obb-collider.js +293 -0
- package/examples/utils/aframe/occlude-hand-tracking-controls.js +47 -0
- package/examples/utils/aframe/occlude-mesh.js +42 -0
- package/examples/utils/aframe/palm-up-detector.js +47 -0
- package/examples/utils/aframe/shadow-material.js +20 -0
- package/examples/utils/aframe/soft-shadow-light.js +9 -0
- package/examples/webxr/script.js +3 -3
- package/examples/webxr-2/assets/3d/soccerBall.glb +0 -0
- package/examples/webxr-2/assets/audio/shellBounce.wav +0 -0
- package/examples/webxr-2/assets/audio/shellHit.wav +0 -0
- package/examples/webxr-2/assets/audio/shellKick.wav +0 -0
- package/examples/webxr-2/assets/audio/soccerBounce.wav +0 -0
- package/examples/webxr-2/assets/audio/soccerKick.mp3 +0 -0
- package/examples/webxr-2/assets/images/shellTexture.png +0 -0
- package/examples/webxr-2/components/bs-ankle.js +337 -0
- package/examples/webxr-2/components/coin.js +84 -0
- package/examples/webxr-2/components/custom-wrap.js +17 -0
- package/examples/webxr-2/components/goomba.js +3250 -0
- package/examples/webxr-2/components/init-shell-material.js +215 -0
- package/examples/webxr-2/components/platter.js +172 -0
- package/examples/webxr-2/components/shell.js +374 -0
- package/examples/webxr-2/components/soccer-ball.js +250 -0
- package/examples/webxr-2/components/squashed-goomba.js +249 -0
- package/examples/webxr-2/edge-impulse-standalone.js +7228 -0
- package/examples/webxr-2/edge-impulse-standalone.wasm +0 -0
- package/examples/webxr-2/index.html +996 -0
- package/examples/webxr-2/kick.tflite +0 -0
- package/examples/webxr-2/kick2.tflite +0 -0
- package/examples/webxr-2/run-impulse.js +135 -0
- package/examples/webxr-2/script.js +384 -0
- package/package.json +2 -1
- package/src/.prettierrc +4 -0
- package/src/BS.ts +66 -9
- package/src/CameraManager.ts +499 -0
- package/src/Device.ts +620 -92
- package/src/DeviceInformationManager.ts +22 -11
- package/src/DeviceManager.ts +94 -25
- package/src/FileTransferManager.ts +146 -21
- package/src/FirmwareManager.ts +1 -1
- package/src/InformationManager.ts +62 -20
- package/src/TfliteManager.ts +172 -26
- package/src/WifiManager.ts +323 -0
- package/src/connection/BaseConnectionManager.ts +145 -30
- package/src/connection/ClientConnectionManager.ts +47 -11
- package/src/connection/bluetooth/BluetoothConnectionManager.ts +14 -3
- package/src/connection/bluetooth/NobleConnectionManager.ts +155 -42
- package/src/connection/bluetooth/WebBluetoothConnectionManager.ts +104 -35
- package/src/connection/bluetooth/bluetoothUUIDs.ts +40 -13
- package/src/connection/udp/UDPConnectionManager.ts +356 -0
- package/src/connection/websocket/WebSocketConnectionManager.ts +282 -0
- package/src/devicePair/DevicePair.ts +145 -49
- package/src/devicePair/DevicePairPressureSensorDataManager.ts +72 -24
- package/src/devicePair/DevicePairSensorDataManager.ts +5 -5
- package/src/scanner/BaseScanner.ts +49 -11
- package/src/scanner/NobleScanner.ts +81 -17
- package/src/sensor/BarometerSensorDataManager.ts +1 -1
- package/src/sensor/MotionSensorDataManager.ts +22 -7
- package/src/sensor/PressureSensorDataManager.ts +47 -13
- package/src/sensor/SensorConfigurationManager.ts +75 -24
- package/src/sensor/SensorDataManager.ts +107 -26
- package/src/server/BaseClient.ts +192 -37
- package/src/server/BaseServer.ts +201 -43
- package/src/server/ServerUtils.ts +39 -9
- package/src/server/udp/UDPServer.ts +74 -23
- package/src/server/udp/UDPUtils.ts +9 -2
- package/src/server/websocket/WebSocketClient.ts +30 -9
- package/src/server/websocket/WebSocketServer.ts +1 -1
- package/src/server/websocket/WebSocketUtils.ts +4 -2
- package/src/utils/CenterOfPressureHelper.ts +5 -5
- package/src/utils/Console.ts +62 -9
- package/src/utils/MathUtils.ts +31 -1
- package/src/utils/ParseUtils.ts +25 -6
- package/src/utils/ThrottleUtils.ts +62 -0
- package/src/utils/Timer.ts +1 -1
- package/src/utils/checksum.ts +1 -1
- package/src/utils/mcumgr.js +1 -1
- package/src/vibration/VibrationManager.ts +166 -40
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import Device, { SendMessageCallback } from "./Device.ts";
|
|
2
|
+
import { createConsole } from "./utils/Console.ts";
|
|
3
|
+
import { isInNode } from "./utils/environment.ts";
|
|
4
|
+
import EventDispatcher from "./utils/EventDispatcher.ts";
|
|
5
|
+
import { textDecoder, textEncoder } from "./utils/Text.ts";
|
|
6
|
+
import autoBind from "auto-bind";
|
|
7
|
+
|
|
8
|
+
const _console = createConsole("WifiManager", { log: false });
|
|
9
|
+
|
|
10
|
+
export const MinWifiSSIDLength = 1;
|
|
11
|
+
export const MaxWifiSSIDLength = 32;
|
|
12
|
+
|
|
13
|
+
export const MinWifiPasswordLength = 8;
|
|
14
|
+
export const MaxWifiPasswordLength = 64;
|
|
15
|
+
|
|
16
|
+
export const WifiMessageTypes = [
|
|
17
|
+
"isWifiAvailable",
|
|
18
|
+
"getWifiSSID",
|
|
19
|
+
"setWifiSSID",
|
|
20
|
+
"getWifiPassword",
|
|
21
|
+
"setWifiPassword",
|
|
22
|
+
"getWifiConnectionEnabled",
|
|
23
|
+
"setWifiConnectionEnabled",
|
|
24
|
+
"isWifiConnected",
|
|
25
|
+
"ipAddress",
|
|
26
|
+
"isWifiSecure",
|
|
27
|
+
] as const;
|
|
28
|
+
export type WifiMessageType = (typeof WifiMessageTypes)[number];
|
|
29
|
+
|
|
30
|
+
export const RequiredWifiMessageTypes: WifiMessageType[] = [
|
|
31
|
+
"getWifiSSID",
|
|
32
|
+
"getWifiPassword",
|
|
33
|
+
"getWifiConnectionEnabled",
|
|
34
|
+
"isWifiConnected",
|
|
35
|
+
"ipAddress",
|
|
36
|
+
"isWifiSecure",
|
|
37
|
+
] as const;
|
|
38
|
+
|
|
39
|
+
export const WifiEventTypes = WifiMessageTypes;
|
|
40
|
+
export type WifiEventType = (typeof WifiEventTypes)[number];
|
|
41
|
+
|
|
42
|
+
export interface WifiEventMessages {
|
|
43
|
+
isWifiAvailable: { isWifiAvailable: boolean };
|
|
44
|
+
getWifiSSID: { wifiSSID: string };
|
|
45
|
+
getWifiPassword: { wifiPassword: string };
|
|
46
|
+
getEnableWifiConnection: { wifiConnectionEnabled: boolean };
|
|
47
|
+
isWifiConnected: { isWifiConnected: boolean };
|
|
48
|
+
ipAddress: { ipAddress?: string };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type WifiEventDispatcher = EventDispatcher<
|
|
52
|
+
Device,
|
|
53
|
+
WifiEventType,
|
|
54
|
+
WifiEventMessages
|
|
55
|
+
>;
|
|
56
|
+
export type SendWifiMessageCallback = SendMessageCallback<WifiMessageType>;
|
|
57
|
+
|
|
58
|
+
class WifiManager {
|
|
59
|
+
constructor() {
|
|
60
|
+
autoBind(this);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
sendMessage!: SendWifiMessageCallback;
|
|
64
|
+
|
|
65
|
+
eventDispatcher!: WifiEventDispatcher;
|
|
66
|
+
get #dispatchEvent() {
|
|
67
|
+
return this.eventDispatcher.dispatchEvent;
|
|
68
|
+
}
|
|
69
|
+
get waitForEvent() {
|
|
70
|
+
return this.eventDispatcher.waitForEvent;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
requestRequiredInformation() {
|
|
74
|
+
_console.log("requesting required wifi information");
|
|
75
|
+
const messages = RequiredWifiMessageTypes.map((messageType) => ({
|
|
76
|
+
type: messageType,
|
|
77
|
+
}));
|
|
78
|
+
this.sendMessage(messages, false);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// PROPERTIES
|
|
82
|
+
|
|
83
|
+
#isWifiAvailable = false;
|
|
84
|
+
get isWifiAvailable() {
|
|
85
|
+
return this.#isWifiAvailable;
|
|
86
|
+
}
|
|
87
|
+
#updateIsWifiAvailable(updatedIsWifiAvailable: boolean) {
|
|
88
|
+
_console.assertTypeWithError(updatedIsWifiAvailable, "boolean");
|
|
89
|
+
this.#isWifiAvailable = updatedIsWifiAvailable;
|
|
90
|
+
_console.log({ isWifiAvailable: this.#isWifiAvailable });
|
|
91
|
+
this.#dispatchEvent("isWifiAvailable", {
|
|
92
|
+
isWifiAvailable: this.#isWifiAvailable,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#assertWifiIsAvailable() {
|
|
97
|
+
_console.assertWithError(this.#isWifiAvailable, "wifi is not available");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// WIFI SSID
|
|
101
|
+
#wifiSSID = "";
|
|
102
|
+
get wifiSSID() {
|
|
103
|
+
return this.#wifiSSID;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#updateWifiSSID(updatedWifiSSID: string) {
|
|
107
|
+
_console.assertTypeWithError(updatedWifiSSID, "string");
|
|
108
|
+
this.#wifiSSID = updatedWifiSSID;
|
|
109
|
+
_console.log({ wifiSSID: this.#wifiSSID });
|
|
110
|
+
this.#dispatchEvent("getWifiSSID", { wifiSSID: this.#wifiSSID });
|
|
111
|
+
}
|
|
112
|
+
async setWifiSSID(newWifiSSID: string) {
|
|
113
|
+
this.#assertWifiIsAvailable();
|
|
114
|
+
if (this.#wifiConnectionEnabled) {
|
|
115
|
+
_console.error("cannot change ssid while wifi connection is enabled");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
_console.assertTypeWithError(newWifiSSID, "string");
|
|
119
|
+
_console.assertRangeWithError(
|
|
120
|
+
"wifiSSID",
|
|
121
|
+
newWifiSSID.length,
|
|
122
|
+
MinWifiSSIDLength,
|
|
123
|
+
MaxWifiSSIDLength
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const setWifiSSIDData = textEncoder.encode(newWifiSSID);
|
|
127
|
+
_console.log({ setWifiSSIDData });
|
|
128
|
+
|
|
129
|
+
const promise = this.waitForEvent("getWifiSSID");
|
|
130
|
+
this.sendMessage([{ type: "setWifiSSID", data: setWifiSSIDData.buffer }]);
|
|
131
|
+
await promise;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// WIFI PASSWORD
|
|
135
|
+
#wifiPassword = "";
|
|
136
|
+
get wifiPassword() {
|
|
137
|
+
return this.#wifiPassword;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#updateWifiPassword(updatedWifiPassword: string) {
|
|
141
|
+
_console.assertTypeWithError(updatedWifiPassword, "string");
|
|
142
|
+
this.#wifiPassword = updatedWifiPassword;
|
|
143
|
+
_console.log({ wifiPassword: this.#wifiPassword });
|
|
144
|
+
this.#dispatchEvent("getWifiPassword", {
|
|
145
|
+
wifiPassword: this.#wifiPassword,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async setWifiPassword(newWifiPassword: string) {
|
|
149
|
+
this.#assertWifiIsAvailable();
|
|
150
|
+
if (this.#wifiConnectionEnabled) {
|
|
151
|
+
_console.error("cannot change password while wifi connection is enabled");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
_console.assertTypeWithError(newWifiPassword, "string");
|
|
155
|
+
if (newWifiPassword.length > 0) {
|
|
156
|
+
_console.assertRangeWithError(
|
|
157
|
+
"wifiPassword",
|
|
158
|
+
newWifiPassword.length,
|
|
159
|
+
MinWifiPasswordLength,
|
|
160
|
+
MaxWifiPasswordLength
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const setWifiPasswordData = textEncoder.encode(newWifiPassword);
|
|
165
|
+
_console.log({ setWifiPasswordData });
|
|
166
|
+
|
|
167
|
+
const promise = this.waitForEvent("getWifiPassword");
|
|
168
|
+
this.sendMessage([
|
|
169
|
+
{ type: "setWifiPassword", data: setWifiPasswordData.buffer },
|
|
170
|
+
]);
|
|
171
|
+
await promise;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ENABLE WIFI CONNECTION
|
|
175
|
+
#wifiConnectionEnabled!: boolean;
|
|
176
|
+
get wifiConnectionEnabled() {
|
|
177
|
+
return this.#wifiConnectionEnabled;
|
|
178
|
+
}
|
|
179
|
+
#updateWifiConnectionEnabled(wifiConnectionEnabled: boolean) {
|
|
180
|
+
_console.log({ wifiConnectionEnabled });
|
|
181
|
+
this.#wifiConnectionEnabled = wifiConnectionEnabled;
|
|
182
|
+
this.#dispatchEvent("getWifiConnectionEnabled", {
|
|
183
|
+
wifiConnectionEnabled: wifiConnectionEnabled,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
async setWifiConnectionEnabled(
|
|
187
|
+
newWifiConnectionEnabled: boolean,
|
|
188
|
+
sendImmediately: boolean = true
|
|
189
|
+
) {
|
|
190
|
+
this.#assertWifiIsAvailable();
|
|
191
|
+
_console.assertTypeWithError(newWifiConnectionEnabled, "boolean");
|
|
192
|
+
if (this.#wifiConnectionEnabled == newWifiConnectionEnabled) {
|
|
193
|
+
_console.log(
|
|
194
|
+
`redundant wifiConnectionEnabled assignment ${newWifiConnectionEnabled}`
|
|
195
|
+
);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const promise = this.waitForEvent("getWifiConnectionEnabled");
|
|
200
|
+
this.sendMessage(
|
|
201
|
+
[
|
|
202
|
+
{
|
|
203
|
+
type: "setWifiConnectionEnabled",
|
|
204
|
+
data: Uint8Array.from([Number(newWifiConnectionEnabled)]).buffer,
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
sendImmediately
|
|
208
|
+
);
|
|
209
|
+
await promise;
|
|
210
|
+
}
|
|
211
|
+
async toggleWifiConnection() {
|
|
212
|
+
return this.setWifiConnectionEnabled(!this.wifiConnectionEnabled);
|
|
213
|
+
}
|
|
214
|
+
async enableWifiConnection() {
|
|
215
|
+
return this.setWifiConnectionEnabled(true);
|
|
216
|
+
}
|
|
217
|
+
async disableWifiConnection() {
|
|
218
|
+
return this.setWifiConnectionEnabled(false);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// IS WIFI CONNECTED
|
|
222
|
+
#isWifiConnected = false;
|
|
223
|
+
get isWifiConnected() {
|
|
224
|
+
return this.#isWifiConnected;
|
|
225
|
+
}
|
|
226
|
+
#updateIsWifiConnected(updatedIsWifiConnected: boolean) {
|
|
227
|
+
_console.assertTypeWithError(updatedIsWifiConnected, "boolean");
|
|
228
|
+
this.#isWifiConnected = updatedIsWifiConnected;
|
|
229
|
+
_console.log({ isWifiConnected: this.#isWifiConnected });
|
|
230
|
+
this.#dispatchEvent("isWifiConnected", {
|
|
231
|
+
isWifiConnected: this.#isWifiConnected,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// IP ADDRESS
|
|
236
|
+
#ipAddress?: string;
|
|
237
|
+
get ipAddress() {
|
|
238
|
+
return this.#ipAddress;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#updateIpAddress(updatedIpAddress?: string) {
|
|
242
|
+
this.#ipAddress = updatedIpAddress;
|
|
243
|
+
_console.log({ ipAddress: this.#ipAddress });
|
|
244
|
+
this.#dispatchEvent("ipAddress", {
|
|
245
|
+
ipAddress: this.#ipAddress,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// IS WIFI SECURE
|
|
250
|
+
#isWifiSecure = false;
|
|
251
|
+
get isWifiSecure() {
|
|
252
|
+
return this.#isWifiSecure;
|
|
253
|
+
}
|
|
254
|
+
#updateIsWifiSecure(updatedIsWifiSecure: boolean) {
|
|
255
|
+
_console.assertTypeWithError(updatedIsWifiSecure, "boolean");
|
|
256
|
+
this.#isWifiSecure = updatedIsWifiSecure;
|
|
257
|
+
_console.log({ isWifiSecure: this.#isWifiSecure });
|
|
258
|
+
this.#dispatchEvent("isWifiSecure", {
|
|
259
|
+
isWifiSecure: this.#isWifiSecure,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// MESSAGE
|
|
264
|
+
parseMessage(messageType: WifiMessageType, dataView: DataView) {
|
|
265
|
+
_console.log({ messageType });
|
|
266
|
+
|
|
267
|
+
switch (messageType) {
|
|
268
|
+
case "isWifiAvailable":
|
|
269
|
+
const isWifiAvailable = Boolean(dataView.getUint8(0));
|
|
270
|
+
_console.log({ isWifiAvailable });
|
|
271
|
+
this.#updateIsWifiAvailable(isWifiAvailable);
|
|
272
|
+
break;
|
|
273
|
+
case "getWifiSSID":
|
|
274
|
+
case "setWifiSSID":
|
|
275
|
+
const ssid = textDecoder.decode(dataView.buffer);
|
|
276
|
+
_console.log({ ssid });
|
|
277
|
+
this.#updateWifiSSID(ssid);
|
|
278
|
+
break;
|
|
279
|
+
case "getWifiPassword":
|
|
280
|
+
case "setWifiPassword":
|
|
281
|
+
const password = textDecoder.decode(dataView.buffer);
|
|
282
|
+
_console.log({ password });
|
|
283
|
+
this.#updateWifiPassword(password);
|
|
284
|
+
break;
|
|
285
|
+
case "getWifiConnectionEnabled":
|
|
286
|
+
case "setWifiConnectionEnabled":
|
|
287
|
+
const enableWifiConnection = Boolean(dataView.getUint8(0));
|
|
288
|
+
_console.log({ enableWifiConnection });
|
|
289
|
+
this.#updateWifiConnectionEnabled(enableWifiConnection);
|
|
290
|
+
break;
|
|
291
|
+
case "isWifiConnected":
|
|
292
|
+
const isWifiConnected = Boolean(dataView.getUint8(0));
|
|
293
|
+
_console.log({ isWifiConnected });
|
|
294
|
+
this.#updateIsWifiConnected(isWifiConnected);
|
|
295
|
+
break;
|
|
296
|
+
case "ipAddress":
|
|
297
|
+
let ipAddress: string | undefined = undefined;
|
|
298
|
+
if (dataView.byteLength == 4) {
|
|
299
|
+
ipAddress = new Uint8Array(dataView.buffer.slice(0, 4)).join(".");
|
|
300
|
+
}
|
|
301
|
+
_console.log({ ipAddress });
|
|
302
|
+
this.#updateIpAddress(ipAddress);
|
|
303
|
+
break;
|
|
304
|
+
case "isWifiSecure":
|
|
305
|
+
const isWifiSecure = Boolean(dataView.getUint8(0));
|
|
306
|
+
_console.log({ isWifiSecure });
|
|
307
|
+
this.#updateIsWifiSecure(isWifiSecure);
|
|
308
|
+
break;
|
|
309
|
+
default:
|
|
310
|
+
throw Error(`uncaught messageType ${messageType}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
clear() {
|
|
315
|
+
this.#wifiSSID = "";
|
|
316
|
+
this.#wifiPassword = "";
|
|
317
|
+
this.#ipAddress = "";
|
|
318
|
+
this.#isWifiConnected = false;
|
|
319
|
+
this.#isWifiAvailable = false;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export default WifiManager;
|
|
@@ -5,21 +5,69 @@ import { FileTransferMessageTypes } from "../FileTransferManager.ts";
|
|
|
5
5
|
import { TfliteMessageTypes } from "../TfliteManager.ts";
|
|
6
6
|
import { concatenateArrayBuffers } from "../utils/ArrayBufferUtils.ts";
|
|
7
7
|
import { parseMessage } from "../utils/ParseUtils.ts";
|
|
8
|
-
import {
|
|
8
|
+
import { DeviceInformationTypes } from "../DeviceInformationManager.ts";
|
|
9
9
|
import { InformationMessageTypes } from "../InformationManager.ts";
|
|
10
10
|
import { VibrationMessageTypes } from "../vibration/VibrationManager.ts";
|
|
11
11
|
import { SensorConfigurationMessageTypes } from "../sensor/SensorConfigurationManager.ts";
|
|
12
12
|
import { SensorDataMessageTypes } from "../sensor/SensorDataManager.ts";
|
|
13
|
+
import { WifiMessageTypes } from "../WifiManager.ts";
|
|
14
|
+
import { CameraMessageTypes } from "../CameraManager.ts";
|
|
13
15
|
|
|
14
|
-
const _console = createConsole("BaseConnectionManager", { log:
|
|
16
|
+
const _console = createConsole("BaseConnectionManager", { log: false });
|
|
15
17
|
|
|
16
|
-
export const ConnectionTypes = [
|
|
18
|
+
export const ConnectionTypes = [
|
|
19
|
+
"webBluetooth",
|
|
20
|
+
"noble",
|
|
21
|
+
"client",
|
|
22
|
+
"webSocket",
|
|
23
|
+
"udp",
|
|
24
|
+
] as const;
|
|
17
25
|
export type ConnectionType = (typeof ConnectionTypes)[number];
|
|
18
26
|
|
|
19
|
-
export const
|
|
27
|
+
export const ClientConnectionTypes = ["noble", "webSocket", "udp"] as const;
|
|
28
|
+
export type ClientConnectionType = (typeof ClientConnectionTypes)[number];
|
|
29
|
+
|
|
30
|
+
interface BaseConnectOptions {
|
|
31
|
+
type: "client" | "webBluetooth" | "webSocket" | "udp";
|
|
32
|
+
}
|
|
33
|
+
export interface WebBluetoothConnectOptions extends BaseConnectOptions {
|
|
34
|
+
type: "webBluetooth";
|
|
35
|
+
}
|
|
36
|
+
interface BaseWifiConnectOptions extends BaseConnectOptions {
|
|
37
|
+
ipAddress: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ClientConnectOptions extends BaseConnectOptions {
|
|
40
|
+
type: "client";
|
|
41
|
+
subType?: "noble" | "webSocket" | "udp";
|
|
42
|
+
}
|
|
43
|
+
export interface WebSocketConnectOptions extends BaseWifiConnectOptions {
|
|
44
|
+
type: "webSocket";
|
|
45
|
+
isWifiSecure?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface UDPConnectOptions extends BaseWifiConnectOptions {
|
|
48
|
+
type: "udp";
|
|
49
|
+
//sendPort: number;
|
|
50
|
+
receivePort?: number;
|
|
51
|
+
}
|
|
52
|
+
export type ConnectOptions =
|
|
53
|
+
| WebBluetoothConnectOptions
|
|
54
|
+
| WebSocketConnectOptions
|
|
55
|
+
| UDPConnectOptions
|
|
56
|
+
| ClientConnectOptions;
|
|
57
|
+
|
|
58
|
+
export const ConnectionStatuses = [
|
|
59
|
+
"notConnected",
|
|
60
|
+
"connecting",
|
|
61
|
+
"connected",
|
|
62
|
+
"disconnecting",
|
|
63
|
+
] as const;
|
|
20
64
|
export type ConnectionStatus = (typeof ConnectionStatuses)[number];
|
|
21
65
|
|
|
22
|
-
export const ConnectionEventTypes = [
|
|
66
|
+
export const ConnectionEventTypes = [
|
|
67
|
+
...ConnectionStatuses,
|
|
68
|
+
"connectionStatus",
|
|
69
|
+
"isConnected",
|
|
70
|
+
] as const;
|
|
23
71
|
export type ConnectionEventType = (typeof ConnectionEventTypes)[number];
|
|
24
72
|
|
|
25
73
|
export interface ConnectionStatusEventMessages {
|
|
@@ -41,8 +89,10 @@ export const TxRxMessageTypes = [
|
|
|
41
89
|
...SensorConfigurationMessageTypes,
|
|
42
90
|
...SensorDataMessageTypes,
|
|
43
91
|
...VibrationMessageTypes,
|
|
44
|
-
...TfliteMessageTypes,
|
|
45
92
|
...FileTransferMessageTypes,
|
|
93
|
+
...TfliteMessageTypes,
|
|
94
|
+
...WifiMessageTypes,
|
|
95
|
+
...CameraMessageTypes,
|
|
46
96
|
] as const;
|
|
47
97
|
export type TxRxMessageType = (typeof TxRxMessageTypes)[number];
|
|
48
98
|
|
|
@@ -53,11 +103,12 @@ export const BatteryLevelMessageTypes = ["batteryLevel"] as const;
|
|
|
53
103
|
export type BatteryLevelMessageType = (typeof BatteryLevelMessageTypes)[number];
|
|
54
104
|
|
|
55
105
|
export const MetaConnectionMessageTypes = ["rx", "tx"] as const;
|
|
56
|
-
export type MetaConnectionMessageType =
|
|
106
|
+
export type MetaConnectionMessageType =
|
|
107
|
+
(typeof MetaConnectionMessageTypes)[number];
|
|
57
108
|
|
|
58
109
|
export const ConnectionMessageTypes = [
|
|
59
110
|
...BatteryLevelMessageTypes,
|
|
60
|
-
...
|
|
111
|
+
...DeviceInformationTypes,
|
|
61
112
|
...MetaConnectionMessageTypes,
|
|
62
113
|
...TxRxMessageTypes,
|
|
63
114
|
...SMPMessageTypes,
|
|
@@ -65,7 +116,10 @@ export const ConnectionMessageTypes = [
|
|
|
65
116
|
export type ConnectionMessageType = (typeof ConnectionMessageTypes)[number];
|
|
66
117
|
|
|
67
118
|
export type ConnectionStatusCallback = (status: ConnectionStatus) => void;
|
|
68
|
-
export type MessageReceivedCallback = (
|
|
119
|
+
export type MessageReceivedCallback = (
|
|
120
|
+
messageType: ConnectionMessageType,
|
|
121
|
+
dataView: DataView
|
|
122
|
+
) => void;
|
|
69
123
|
export type MessagesReceivedCallback = () => void;
|
|
70
124
|
|
|
71
125
|
abstract class BaseConnectionManager {
|
|
@@ -90,6 +144,10 @@ abstract class BaseConnectionManager {
|
|
|
90
144
|
return this.baseConstructor.isSupported;
|
|
91
145
|
}
|
|
92
146
|
|
|
147
|
+
get canUpdateFirmware() {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
|
|
93
151
|
static type: ConnectionType;
|
|
94
152
|
get type(): ConnectionType {
|
|
95
153
|
return this.baseConstructor.type;
|
|
@@ -97,7 +155,10 @@ abstract class BaseConnectionManager {
|
|
|
97
155
|
|
|
98
156
|
/** @throws {Error} if not supported */
|
|
99
157
|
#assertIsSupported() {
|
|
100
|
-
_console.assertWithError(
|
|
158
|
+
_console.assertWithError(
|
|
159
|
+
this.isSupported,
|
|
160
|
+
`${this.constructor.name} is not supported`
|
|
161
|
+
);
|
|
101
162
|
}
|
|
102
163
|
|
|
103
164
|
constructor() {
|
|
@@ -111,7 +172,9 @@ abstract class BaseConnectionManager {
|
|
|
111
172
|
protected set status(newConnectionStatus) {
|
|
112
173
|
_console.assertEnumWithError(newConnectionStatus, ConnectionStatuses);
|
|
113
174
|
if (this.#status == newConnectionStatus) {
|
|
114
|
-
_console.log(
|
|
175
|
+
_console.log(
|
|
176
|
+
`tried to assign same connection status "${newConnectionStatus}"`
|
|
177
|
+
);
|
|
115
178
|
return;
|
|
116
179
|
}
|
|
117
180
|
_console.log(`new connection status "${newConnectionStatus}"`);
|
|
@@ -125,7 +188,7 @@ abstract class BaseConnectionManager {
|
|
|
125
188
|
}
|
|
126
189
|
|
|
127
190
|
if (this.#status == "notConnected") {
|
|
128
|
-
this.mtu =
|
|
191
|
+
this.mtu = this.defaultMtu;
|
|
129
192
|
}
|
|
130
193
|
}
|
|
131
194
|
|
|
@@ -133,30 +196,40 @@ abstract class BaseConnectionManager {
|
|
|
133
196
|
return this.status == "connected";
|
|
134
197
|
}
|
|
135
198
|
|
|
199
|
+
get isAvailable() {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
|
|
136
203
|
/** @throws {Error} if connected */
|
|
137
|
-
|
|
204
|
+
protected assertIsNotConnected() {
|
|
138
205
|
_console.assertWithError(!this.isConnected, "device is already connected");
|
|
139
206
|
}
|
|
140
207
|
/** @throws {Error} if connecting */
|
|
141
208
|
#assertIsNotConnecting() {
|
|
142
|
-
_console.assertWithError(
|
|
209
|
+
_console.assertWithError(
|
|
210
|
+
this.status != "connecting",
|
|
211
|
+
"device is already connecting"
|
|
212
|
+
);
|
|
143
213
|
}
|
|
144
214
|
/** @throws {Error} if not connected */
|
|
145
|
-
|
|
215
|
+
protected assertIsConnected() {
|
|
146
216
|
_console.assertWithError(this.isConnected, "device is not connected");
|
|
147
217
|
}
|
|
148
218
|
/** @throws {Error} if disconnecting */
|
|
149
219
|
#assertIsNotDisconnecting() {
|
|
150
|
-
_console.assertWithError(
|
|
220
|
+
_console.assertWithError(
|
|
221
|
+
this.status != "disconnecting",
|
|
222
|
+
"device is already disconnecting"
|
|
223
|
+
);
|
|
151
224
|
}
|
|
152
225
|
/** @throws {Error} if not connected or is disconnecting */
|
|
153
|
-
|
|
154
|
-
this
|
|
226
|
+
assertIsConnectedAndNotDisconnecting() {
|
|
227
|
+
this.assertIsConnected();
|
|
155
228
|
this.#assertIsNotDisconnecting();
|
|
156
229
|
}
|
|
157
230
|
|
|
158
231
|
async connect() {
|
|
159
|
-
this
|
|
232
|
+
this.assertIsNotConnected();
|
|
160
233
|
this.#assertIsNotConnecting();
|
|
161
234
|
this.status = "connecting";
|
|
162
235
|
}
|
|
@@ -164,26 +237,31 @@ abstract class BaseConnectionManager {
|
|
|
164
237
|
return false;
|
|
165
238
|
}
|
|
166
239
|
async reconnect() {
|
|
167
|
-
this
|
|
240
|
+
this.assertIsNotConnected();
|
|
168
241
|
this.#assertIsNotConnecting();
|
|
169
|
-
_console.
|
|
242
|
+
_console.assertWithError(this.canReconnect, "unable to reconnect");
|
|
243
|
+
this.status = "connecting";
|
|
244
|
+
_console.log("attempting to reconnect...");
|
|
170
245
|
}
|
|
171
246
|
async disconnect() {
|
|
172
|
-
this
|
|
247
|
+
this.assertIsConnected();
|
|
173
248
|
this.#assertIsNotDisconnecting();
|
|
174
249
|
this.status = "disconnecting";
|
|
175
250
|
_console.log("disconnecting from device...");
|
|
176
251
|
}
|
|
177
252
|
|
|
178
253
|
async sendSmpMessage(data: ArrayBuffer) {
|
|
179
|
-
this
|
|
254
|
+
this.assertIsConnectedAndNotDisconnecting();
|
|
180
255
|
_console.log("sending smp message", data);
|
|
181
256
|
}
|
|
182
257
|
|
|
183
258
|
#pendingMessages: TxMessage[] = [];
|
|
184
259
|
#isSendingMessages = false;
|
|
185
|
-
async sendTxMessages(
|
|
186
|
-
|
|
260
|
+
async sendTxMessages(
|
|
261
|
+
messages: TxMessage[] | undefined,
|
|
262
|
+
sendImmediately: boolean = true
|
|
263
|
+
) {
|
|
264
|
+
this.assertIsConnectedAndNotDisconnecting();
|
|
187
265
|
|
|
188
266
|
if (messages) {
|
|
189
267
|
this.#pendingMessages.push(...messages);
|
|
@@ -196,7 +274,11 @@ abstract class BaseConnectionManager {
|
|
|
196
274
|
}
|
|
197
275
|
|
|
198
276
|
if (this.#isSendingMessages) {
|
|
199
|
-
|
|
277
|
+
_console.log("already sending messages - waiting until later");
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (this.#pendingMessages.length == 0) {
|
|
281
|
+
_console.log("no pendingMessages");
|
|
200
282
|
return;
|
|
201
283
|
}
|
|
202
284
|
this.#isSendingMessages = true;
|
|
@@ -214,12 +296,27 @@ abstract class BaseConnectionManager {
|
|
|
214
296
|
|
|
215
297
|
if (this.mtu) {
|
|
216
298
|
while (arrayBuffers.length > 0) {
|
|
299
|
+
if (
|
|
300
|
+
arrayBuffers.every(
|
|
301
|
+
(arrayBuffer) => arrayBuffer.byteLength > this.mtu! - 3
|
|
302
|
+
)
|
|
303
|
+
) {
|
|
304
|
+
_console.log("every arrayBuffer is too big to send");
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
_console.log("remaining arrayBuffers.length", arrayBuffers.length);
|
|
217
308
|
let arrayBufferByteLength = 0;
|
|
218
309
|
let arrayBufferCount = 0;
|
|
219
310
|
arrayBuffers.some((arrayBuffer) => {
|
|
220
311
|
if (arrayBufferByteLength + arrayBuffer.byteLength > this.mtu! - 3) {
|
|
312
|
+
_console.log(
|
|
313
|
+
`stopping appending arrayBuffers ( length ${arrayBuffer.byteLength} too much)`
|
|
314
|
+
);
|
|
221
315
|
return true;
|
|
222
316
|
}
|
|
317
|
+
_console.log(
|
|
318
|
+
`allowing arrayBuffer with length ${arrayBuffer.byteLength}`
|
|
319
|
+
);
|
|
223
320
|
arrayBufferCount++;
|
|
224
321
|
arrayBufferByteLength += arrayBuffer.byteLength;
|
|
225
322
|
});
|
|
@@ -227,26 +324,36 @@ abstract class BaseConnectionManager {
|
|
|
227
324
|
_console.log({ arrayBufferCount, arrayBuffersToSend });
|
|
228
325
|
|
|
229
326
|
const arrayBuffer = concatenateArrayBuffers(...arrayBuffersToSend);
|
|
230
|
-
_console.log("sending arrayBuffer", arrayBuffer);
|
|
327
|
+
_console.log("sending arrayBuffer (partitioned)", arrayBuffer);
|
|
231
328
|
await this.sendTxData(arrayBuffer);
|
|
232
329
|
}
|
|
233
330
|
} else {
|
|
234
331
|
const arrayBuffer = concatenateArrayBuffers(...arrayBuffers);
|
|
235
|
-
_console.log("sending arrayBuffer", arrayBuffer);
|
|
332
|
+
_console.log("sending arrayBuffer (all)", arrayBuffer);
|
|
236
333
|
await this.sendTxData(arrayBuffer);
|
|
237
334
|
}
|
|
238
335
|
|
|
239
336
|
this.#isSendingMessages = false;
|
|
337
|
+
|
|
338
|
+
this.sendTxMessages(undefined, true);
|
|
240
339
|
}
|
|
241
340
|
|
|
242
|
-
|
|
341
|
+
protected defaultMtu = 23;
|
|
342
|
+
//mtu?: number;
|
|
343
|
+
mtu?: number = this.defaultMtu;
|
|
243
344
|
|
|
244
345
|
async sendTxData(data: ArrayBuffer) {
|
|
245
346
|
_console.log("sendTxData", data);
|
|
246
347
|
}
|
|
247
348
|
|
|
248
349
|
parseRxMessage(dataView: DataView) {
|
|
249
|
-
parseMessage(
|
|
350
|
+
parseMessage(
|
|
351
|
+
dataView,
|
|
352
|
+
TxRxMessageTypes,
|
|
353
|
+
this.#onRxMessage.bind(this),
|
|
354
|
+
null,
|
|
355
|
+
true
|
|
356
|
+
);
|
|
250
357
|
this.onMessagesReceived!();
|
|
251
358
|
}
|
|
252
359
|
|
|
@@ -268,6 +375,14 @@ abstract class BaseConnectionManager {
|
|
|
268
375
|
this.#isSendingMessages = false;
|
|
269
376
|
this.#pendingMessages.length = 0;
|
|
270
377
|
}
|
|
378
|
+
|
|
379
|
+
remove() {
|
|
380
|
+
this.clear();
|
|
381
|
+
|
|
382
|
+
this.onStatusUpdated = undefined;
|
|
383
|
+
this.onMessageReceived = undefined;
|
|
384
|
+
this.onMessagesReceived = undefined;
|
|
385
|
+
}
|
|
271
386
|
}
|
|
272
387
|
|
|
273
388
|
export default BaseConnectionManager;
|