@react-native-ohos/react-native-ble-plx 3.2.1-rc.1 → 3.2.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.
Files changed (65) hide show
  1. package/LICENSE +202 -202
  2. package/README.OpenSource +10 -10
  3. package/README.md +9 -9
  4. package/app.plugin.js +1 -1
  5. package/harmony/rn_bleplx/build-profile.json5 +7 -7
  6. package/harmony/rn_bleplx/hvigorfile.ts +1 -1
  7. package/harmony/rn_bleplx/index.ets +26 -26
  8. package/harmony/rn_bleplx/obfuscation-rules.txt +17 -17
  9. package/harmony/rn_bleplx/oh-package.json5 +13 -13
  10. package/harmony/rn_bleplx/src/main/cpp/BlePlxPackage.h +36 -36
  11. package/harmony/rn_bleplx/src/main/cpp/CMakeLists.txt +9 -9
  12. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/BaseReactNativeBlePlxPackage.h +65 -65
  13. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/turbo_modules/BlePlx.cpp +59 -59
  14. package/harmony/rn_bleplx/src/main/cpp/generated/RNOH/generated/turbo_modules/BlePlx.h +16 -16
  15. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ComponentDescriptors.h +22 -22
  16. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.cpp +18 -18
  17. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/EventEmitters.h +19 -19
  18. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.cpp +21 -21
  19. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/Props.h +20 -20
  20. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.cpp +19 -19
  21. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/ShadowNodes.h +25 -25
  22. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.cpp +18 -18
  23. package/harmony/rn_bleplx/src/main/cpp/generated/react/renderer/components/react_native_ble_plx/States.h +22 -22
  24. package/harmony/rn_bleplx/src/main/ets/BleDevice.ts +98 -98
  25. package/harmony/rn_bleplx/src/main/ets/BleModule.ts +1219 -1219
  26. package/harmony/rn_bleplx/src/main/ets/BlePlxInterface.ts +26 -26
  27. package/harmony/rn_bleplx/src/main/ets/BlePlxModule.ts +246 -246
  28. package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ets +46 -46
  29. package/harmony/rn_bleplx/src/main/ets/Characteristic.ts +179 -179
  30. package/harmony/rn_bleplx/src/main/ets/CommonConstants.ts +29 -29
  31. package/harmony/rn_bleplx/src/main/ets/Descriptor.ts +143 -143
  32. package/harmony/rn_bleplx/src/main/ets/Service.ts +85 -85
  33. package/harmony/rn_bleplx/src/main/ets/common/BleError.ts +90 -90
  34. package/harmony/rn_bleplx/src/main/ets/common/BleErrorToJsObjectConverter.ts +62 -62
  35. package/harmony/rn_bleplx/src/main/ets/common/BleEvent.ts +32 -32
  36. package/harmony/rn_bleplx/src/main/ets/common/BleUtils.ts +86 -86
  37. package/harmony/rn_bleplx/src/main/ets/common/IdGenerator.ts +49 -49
  38. package/harmony/rn_bleplx/src/main/ets/common/IdGeneratorKey.ts +70 -70
  39. package/harmony/rn_bleplx/src/main/ets/common/InstanceIdGenerator.ts +36 -36
  40. package/harmony/rn_bleplx/src/main/ets/common/Logger.ts +64 -64
  41. package/harmony/rn_bleplx/src/main/ets/common/PermissionHandler.ts +98 -98
  42. package/harmony/rn_bleplx/src/main/ets/common/ServiceFactory.ts +37 -37
  43. package/harmony/rn_bleplx/src/main/ets/generated/components/ts.ts +5 -5
  44. package/harmony/rn_bleplx/src/main/ets/generated/index.ets +5 -5
  45. package/harmony/rn_bleplx/src/main/ets/generated/ts.ts +6 -6
  46. package/harmony/rn_bleplx/src/main/ets/generated/turboModules/BlePlx.ts +100 -100
  47. package/harmony/rn_bleplx/src/main/ets/generated/turboModules/ts.ts +5 -5
  48. package/harmony/rn_bleplx/src/main/module.json5 +6 -6
  49. package/harmony/rn_bleplx/ts.ets +25 -25
  50. package/harmony/rn_bleplx.har +0 -0
  51. package/package.json +185 -185
  52. package/src/BleError.js +555 -555
  53. package/src/BleManager.js +1287 -1287
  54. package/src/BleModule.js +847 -847
  55. package/src/Characteristic.js +166 -166
  56. package/src/Descriptor.js +82 -82
  57. package/src/Device.js +370 -370
  58. package/src/NativeBlePlx.ts +121 -121
  59. package/src/Service.js +188 -188
  60. package/src/TypeDefinition.js +360 -360
  61. package/src/Utils.js +26 -26
  62. package/src/index.d.ts +2113 -2113
  63. package/src/index.js +20 -20
  64. package/harmony/rn_bleplx/src/main/ets/BlePlxPackage.ts +0 -46
  65. package/harmony/rn_bleplx/ts.ts +0 -26
@@ -1,63 +1,63 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (C) 2023 Huawei Device Co., Ltd.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { BleError } from './BleError';
26
-
27
- export class BleErrorToJsObjectConverter {
28
- public toJSCallback(error: BleError): any[] {
29
- const result: any[] = [];
30
- result.push(this.toJs(error));
31
- result.push(null);
32
- return result;
33
- }
34
-
35
- public toJs(error: BleError): string {
36
- const obj: any = {};
37
-
38
- obj["errorCode"] = error.errorCode;
39
-
40
- obj["attErrorCode"] =
41
- error.harmonyCode != null && error.harmonyCode >= 0 && error.harmonyCode < 0x80 ? error.harmonyCode : null;
42
-
43
- obj["iosErrorCode"] = null;
44
-
45
- obj["harmonyErrorCode"] = error.harmonyCode != null && error.harmonyCode >= 0x80 ? error.harmonyCode : null;
46
-
47
- this.appendString(obj, "reason", error.reason);
48
- this.appendString(obj, "deviceID", error.deviceID);
49
- this.appendString(obj, "serviceUUID", error.serviceUUID);
50
- this.appendString(obj, "characteristicUUID", error.characteristicUUID);
51
- this.appendString(obj, "descriptorUUID", error.descriptorUUID);
52
- this.appendString(obj, "internalMessage", error.internalMessage);
53
- return JSON.stringify(obj);
54
- }
55
-
56
- private appendString(obj: any, key: string, value: string | undefined): void {
57
- if (value !== undefined) {
58
- obj[key] = value === null ? null : value;
59
- } else {
60
- obj[key] = null;
61
- }
62
- }
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { BleError } from './BleError';
26
+
27
+ export class BleErrorToJsObjectConverter {
28
+ public toJSCallback(error: BleError): any[] {
29
+ const result: any[] = [];
30
+ result.push(this.toJs(error));
31
+ result.push(null);
32
+ return result;
33
+ }
34
+
35
+ public toJs(error: BleError): string {
36
+ const obj: any = {};
37
+
38
+ obj["errorCode"] = error.errorCode;
39
+
40
+ obj["attErrorCode"] =
41
+ error.harmonyCode != null && error.harmonyCode >= 0 && error.harmonyCode < 0x80 ? error.harmonyCode : null;
42
+
43
+ obj["iosErrorCode"] = null;
44
+
45
+ obj["harmonyErrorCode"] = error.harmonyCode != null && error.harmonyCode >= 0x80 ? error.harmonyCode : null;
46
+
47
+ this.appendString(obj, "reason", error.reason);
48
+ this.appendString(obj, "deviceID", error.deviceID);
49
+ this.appendString(obj, "serviceUUID", error.serviceUUID);
50
+ this.appendString(obj, "characteristicUUID", error.characteristicUUID);
51
+ this.appendString(obj, "descriptorUUID", error.descriptorUUID);
52
+ this.appendString(obj, "internalMessage", error.internalMessage);
53
+ return JSON.stringify(obj);
54
+ }
55
+
56
+ private appendString(obj: any, key: string, value: string | undefined): void {
57
+ if (value !== undefined) {
58
+ obj[key] = value === null ? null : value;
59
+ } else {
60
+ obj[key] = null;
61
+ }
62
+ }
63
63
  }
@@ -1,33 +1,33 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (C) 2023 Huawei Device Co., Ltd.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- export const BleEvent = {
26
- scanEvent: 'ScanEvent',
27
- readEvent: 'ReadEvent',
28
- stateChangeEvent: 'StateChangeEvent',
29
- restoreStateEvent: 'RestoreStateEvent',
30
- disconnectionEvent: 'DisconnectionEvent',
31
- connectingEvent: 'ConnectingEvent',
32
- connectedEvent: 'ConnectedEvent'
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ export const BleEvent = {
26
+ scanEvent: 'ScanEvent',
27
+ readEvent: 'ReadEvent',
28
+ stateChangeEvent: 'StateChangeEvent',
29
+ restoreStateEvent: 'RestoreStateEvent',
30
+ disconnectionEvent: 'DisconnectionEvent',
31
+ connectingEvent: 'ConnectingEvent',
32
+ connectedEvent: 'ConnectedEvent'
33
33
  }
@@ -1,86 +1,86 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (C) 2023 Huawei Device Co., Ltd.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { ValuesBucket } from '@kit.ArkData';
26
- import { ble } from '@kit.ConnectivityKit';
27
- import { buffer } from '@kit.ArkTS';
28
-
29
- // Base64转ArrayBuffer
30
- export function base64ToArrayBuffer(string: string): ArrayBuffer {
31
- let dataArray = new Uint8Array(buffer.from(string, 'base64').buffer);
32
- return dataArray.buffer;
33
- }
34
-
35
- // ArrayBuffer转Base64
36
- export function arrayBufferToBase64(arrayBuffer: ArrayBuffer): string {
37
- let base64 = ''
38
- let encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
39
- let bytes = new Uint8Array(arrayBuffer)
40
- let byteLength = bytes.byteLength
41
- let byteRemainder = byteLength % 3
42
- let mainLength = byteLength - byteRemainder
43
- let a, b, c, d
44
- let chunk
45
- // Main loop deals with bytes in chunks of 3
46
- for (let i = 0; i < mainLength; i = i + 3) {
47
- // Combine the three bytes into a single integer
48
- chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
49
- // Use bitmasks to extract 6-bit segments from the triplet
50
- a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18
51
- b = (chunk & 258048) >> 12 // 258048 = (2^6 - 1) << 12
52
- c = (chunk & 4032) >> 6 // 4032 = (2^6 - 1) << 6
53
- d = chunk & 63 // 63 = 2^6 - 1
54
- // Convert the raw binary segments to the appropriate ASCII encoding
55
- base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]
56
- }
57
- // Deal with the remaining bytes and padding
58
- if (byteRemainder === 1) {
59
- chunk = bytes[mainLength]
60
- a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2
61
- // Set the 4 least significant bits to zero
62
- b = (chunk & 3) << 4 // 3 = 2^2 - 1
63
- base64 += encodings[a] + encodings[b] + '=='
64
- } else if (byteRemainder === 2) {
65
- chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]
66
- a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10
67
- b = (chunk & 1008) >> 4 // 1008 = (2^6 - 1) << 4
68
- // Set the 2 least significant bits to zero
69
- c = (chunk & 15) << 2 // 15 = 2^4 - 1
70
- base64 += encodings[a] + encodings[b] + encodings[c] + '='
71
- }
72
- return base64
73
- }
74
-
75
- export function scanResultToJsObjectConverter(scanResult: ble.ScanResult): ValuesBucket {
76
- return {
77
- id: scanResult.deviceId,
78
- name: scanResult.deviceName,
79
- rssi: scanResult.rssi,
80
- isConnectable: scanResult.connectable,
81
- manufacturerData: arrayBufferToBase64(scanResult.data),
82
- localName: '',
83
- rawScanRecord: '',
84
- mtu: 0
85
- }
86
- }
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { ValuesBucket } from '@kit.ArkData';
26
+ import { ble } from '@kit.ConnectivityKit';
27
+ import { buffer } from '@kit.ArkTS';
28
+
29
+ // Base64转ArrayBuffer
30
+ export function base64ToArrayBuffer(string: string): ArrayBuffer {
31
+ let dataArray = new Uint8Array(buffer.from(string, 'base64').buffer);
32
+ return dataArray.buffer;
33
+ }
34
+
35
+ // ArrayBuffer转Base64
36
+ export function arrayBufferToBase64(arrayBuffer: ArrayBuffer): string {
37
+ let base64 = ''
38
+ let encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
39
+ let bytes = new Uint8Array(arrayBuffer)
40
+ let byteLength = bytes.byteLength
41
+ let byteRemainder = byteLength % 3
42
+ let mainLength = byteLength - byteRemainder
43
+ let a, b, c, d
44
+ let chunk
45
+ // Main loop deals with bytes in chunks of 3
46
+ for (let i = 0; i < mainLength; i = i + 3) {
47
+ // Combine the three bytes into a single integer
48
+ chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
49
+ // Use bitmasks to extract 6-bit segments from the triplet
50
+ a = (chunk & 16515072) >> 18 // 16515072 = (2^6 - 1) << 18
51
+ b = (chunk & 258048) >> 12 // 258048 = (2^6 - 1) << 12
52
+ c = (chunk & 4032) >> 6 // 4032 = (2^6 - 1) << 6
53
+ d = chunk & 63 // 63 = 2^6 - 1
54
+ // Convert the raw binary segments to the appropriate ASCII encoding
55
+ base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]
56
+ }
57
+ // Deal with the remaining bytes and padding
58
+ if (byteRemainder === 1) {
59
+ chunk = bytes[mainLength]
60
+ a = (chunk & 252) >> 2 // 252 = (2^6 - 1) << 2
61
+ // Set the 4 least significant bits to zero
62
+ b = (chunk & 3) << 4 // 3 = 2^2 - 1
63
+ base64 += encodings[a] + encodings[b] + '=='
64
+ } else if (byteRemainder === 2) {
65
+ chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]
66
+ a = (chunk & 64512) >> 10 // 64512 = (2^6 - 1) << 10
67
+ b = (chunk & 1008) >> 4 // 1008 = (2^6 - 1) << 4
68
+ // Set the 2 least significant bits to zero
69
+ c = (chunk & 15) << 2 // 15 = 2^4 - 1
70
+ base64 += encodings[a] + encodings[b] + encodings[c] + '='
71
+ }
72
+ return base64
73
+ }
74
+
75
+ export function scanResultToJsObjectConverter(scanResult: ble.ScanResult): ValuesBucket {
76
+ return {
77
+ id: scanResult.deviceId,
78
+ name: scanResult.deviceName,
79
+ rssi: scanResult.rssi,
80
+ isConnectable: scanResult.connectable,
81
+ manufacturerData: arrayBufferToBase64(scanResult.data),
82
+ localName: '',
83
+ rawScanRecord: '',
84
+ mtu: 0
85
+ }
86
+ }
@@ -1,49 +1,49 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (C) 2023 Huawei Device Co., Ltd.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { IdGeneratorKey } from './IdGeneratorKey';
26
-
27
- export class IdGenerator {
28
- private static idMap = new Map<IdGeneratorKey, number>();
29
- private static nextKey = 0;
30
-
31
- static getIdForKey(idGeneratorKey: IdGeneratorKey): number {
32
- var id: number = undefined;
33
- this.idMap.forEach((value, key) => {
34
- if (key.equals(idGeneratorKey)) {
35
- id = value;
36
- }
37
- });
38
- if (id !== undefined) {
39
- return id;
40
- }
41
- this.idMap.set(idGeneratorKey, ++this.nextKey);
42
- return this.nextKey;
43
- }
44
-
45
- static clear(): void {
46
- this.idMap.clear();
47
- this.nextKey = 0;
48
- }
49
- }
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { IdGeneratorKey } from './IdGeneratorKey';
26
+
27
+ export class IdGenerator {
28
+ private static idMap = new Map<IdGeneratorKey, number>();
29
+ private static nextKey = 0;
30
+
31
+ static getIdForKey(idGeneratorKey: IdGeneratorKey): number {
32
+ var id: number = undefined;
33
+ this.idMap.forEach((value, key) => {
34
+ if (key.equals(idGeneratorKey)) {
35
+ id = value;
36
+ }
37
+ });
38
+ if (id !== undefined) {
39
+ return id;
40
+ }
41
+ this.idMap.set(idGeneratorKey, ++this.nextKey);
42
+ return this.nextKey;
43
+ }
44
+
45
+ static clear(): void {
46
+ this.idMap.clear();
47
+ this.nextKey = 0;
48
+ }
49
+ }
@@ -1,70 +1,70 @@
1
- /*
2
- * MIT License
3
- *
4
- * Copyright (C) 2023 Huawei Device Co., Ltd.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- export class IdGeneratorKey {
26
- readonly deviceAddress: string;
27
- readonly uuid: string;
28
- readonly id: number;
29
-
30
- constructor(deviceAddress: string, uuid: string, id: number) {
31
- this.deviceAddress = deviceAddress;
32
- this.uuid = uuid;
33
- this.id = id;
34
- }
35
-
36
- equals(other: any): boolean {
37
- if (this === other) {
38
- return true;
39
- }
40
- if (other === null || typeof other !== 'object' || !(other instanceof IdGeneratorKey)) {
41
- return false;
42
- }
43
-
44
- const that = other as IdGeneratorKey;
45
-
46
- if (this.id !== that.id) {
47
- return false;
48
- }
49
- if (this.deviceAddress !== that.deviceAddress) {
50
- return false;
51
- }
52
- return this.uuid === that.uuid;
53
- }
54
-
55
- hashCode(): number {
56
- let result = this.stringHashCode(this.deviceAddress);
57
- result = 31 * result + this.stringHashCode(this.uuid);
58
- result = 31 * result + this.id;
59
- return result;
60
- }
61
-
62
- stringHashCode(str: string): number {
63
- let hash = 0;
64
- for (let i = 0; i < str.length; i++) {
65
- hash = ((hash << 5) - hash) + str.charCodeAt(i);
66
- hash |= 0; // Convert to 32bit integer
67
- }
68
- return hash;
69
- }
70
- }
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ export class IdGeneratorKey {
26
+ readonly deviceAddress: string;
27
+ readonly uuid: string;
28
+ readonly id: number;
29
+
30
+ constructor(deviceAddress: string, uuid: string, id: number) {
31
+ this.deviceAddress = deviceAddress;
32
+ this.uuid = uuid;
33
+ this.id = id;
34
+ }
35
+
36
+ equals(other: any): boolean {
37
+ if (this === other) {
38
+ return true;
39
+ }
40
+ if (other === null || typeof other !== 'object' || !(other instanceof IdGeneratorKey)) {
41
+ return false;
42
+ }
43
+
44
+ const that = other as IdGeneratorKey;
45
+
46
+ if (this.id !== that.id) {
47
+ return false;
48
+ }
49
+ if (this.deviceAddress !== that.deviceAddress) {
50
+ return false;
51
+ }
52
+ return this.uuid === that.uuid;
53
+ }
54
+
55
+ hashCode(): number {
56
+ let result = this.stringHashCode(this.deviceAddress);
57
+ result = 31 * result + this.stringHashCode(this.uuid);
58
+ result = 31 * result + this.id;
59
+ return result;
60
+ }
61
+
62
+ stringHashCode(str: string): number {
63
+ let hash = 0;
64
+ for (let i = 0; i < str.length; i++) {
65
+ hash = ((hash << 5) - hash) + str.charCodeAt(i);
66
+ hash |= 0; // Convert to 32bit integer
67
+ }
68
+ return hash;
69
+ }
70
+ }