mini_program_gizwits_sdk 3.6.4 → 3.6.5

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 (134) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
  3. package/yarn-error.log +6901 -0
  4. package/dist/src/GizLog.d.ts +0 -18
  5. package/dist/src/crc/calculators/crc16modbus.d.ts +0 -2
  6. package/dist/src/crc/calculators/crc32.d.ts +0 -2
  7. package/dist/src/crc/crc16modbus.d.ts +0 -7
  8. package/dist/src/crc/crc32.d.ts +0 -7
  9. package/dist/src/crc/create_buffer.d.ts +0 -3
  10. package/dist/src/crc/define_crc.d.ts +0 -7
  11. package/dist/src/crc/index.d.ts +0 -19
  12. package/dist/src/crc/types.d.ts +0 -11
  13. package/dist/src/errorCode.d.ts +0 -3
  14. package/dist/src/globalData.d.ts +0 -2
  15. package/dist/src/handler/EventListener.d.ts +0 -9
  16. package/dist/src/handler/ble.d.ts +0 -105
  17. package/dist/src/handler/lan.d.ts +0 -78
  18. package/dist/src/handler/socket.d.ts +0 -151
  19. package/dist/src/openApiRequest.d.ts +0 -3
  20. package/dist/src/productConfigFileManage.d.ts +0 -11
  21. package/dist/src/protocol/Bind.d.ts +0 -7
  22. package/dist/src/protocol/DeviceInfo.d.ts +0 -11
  23. package/dist/src/protocol/DiscoverUDP.d.ts +0 -17
  24. package/dist/src/protocol/GetDeviceStatus.d.ts +0 -5
  25. package/dist/src/protocol/Login.d.ts +0 -12
  26. package/dist/src/protocol/Ntp.d.ts +0 -5
  27. package/dist/src/protocol/OTA/AwaitNoti.d.ts +0 -7
  28. package/dist/src/protocol/OTA/CheckCanOTA.d.ts +0 -10
  29. package/dist/src/protocol/OTA/OTAPackPackage.d.ts +0 -8
  30. package/dist/src/protocol/OTA/OtaComplete.d.ts +0 -8
  31. package/dist/src/protocol/OTA/PreOTA.d.ts +0 -11
  32. package/dist/src/protocol/OTA/ResetPosition.d.ts +0 -6
  33. package/dist/src/protocol/OffLineData.d.ts +0 -23
  34. package/dist/src/protocol/ProtocolBase.d.ts +0 -11
  35. package/dist/src/protocol/Reset.d.ts +0 -8
  36. package/dist/src/protocol/SetReset.d.ts +0 -7
  37. package/dist/src/protocol/WifiConfig.d.ts +0 -6
  38. package/dist/src/protocol/dataPoint.d.ts +0 -34
  39. package/dist/src/protocol/tool.d.ts +0 -14
  40. package/dist/src/randomCode.d.ts +0 -3
  41. package/dist/src/request.d.ts +0 -1
  42. package/dist/src/sdk.d.ts +0 -136
  43. package/dist/src/sentry.d.ts +0 -2
  44. package/dist/src/services/devices.d.ts +0 -47
  45. package/dist/src/services/login.d.ts +0 -4
  46. package/dist/src/services/monitor.d.ts +0 -12
  47. package/dist/src/services/ota.d.ts +0 -7
  48. package/dist/src/services/tool.d.ts +0 -4
  49. package/dist/src/services/uploadP0.d.ts +0 -14
  50. package/dist/src/sleep.d.ts +0 -2
  51. package/dist/src/types/index.d.ts +0 -361
  52. package/dist/src/utils.d.ts +0 -46
  53. package/dist/src/wechatApi.d.ts +0 -19
  54. package/dist/src/wifiConfig/ConfigBase.d.ts +0 -27
  55. package/dist/src/wifiConfig/ap.d.ts +0 -11
  56. package/dist/src/wifiConfig/ble.d.ts +0 -41
  57. package/dist/src/wifiConfig/nfc/disposeData.d.ts +0 -2
  58. package/dist/src/wifiConfig/nfc/formatData.d.ts +0 -3
  59. package/dist/src/wifiConfig/nfc/formatSSID.d.ts +0 -6
  60. package/dist/src/wifiConfig/nfc/index.d.ts +0 -22
  61. package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +0 -1
  62. package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +0 -6
  63. package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +0 -5
  64. package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +0 -1
  65. package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +0 -1
  66. package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +0 -2
  67. package/dist/src/wifiConfig/nfc/types.d.ts +0 -15
  68. package/index.ts +0 -8
  69. package/src/GizLog.ts +0 -51
  70. package/src/crc/calculators/crc16modbus.ts +0 -36
  71. package/src/crc/calculators/crc32.ts +0 -47
  72. package/src/crc/crc16modbus.ts +0 -3
  73. package/src/crc/crc32.ts +0 -4
  74. package/src/crc/create_buffer.ts +0 -7
  75. package/src/crc/define_crc.ts +0 -9
  76. package/src/crc/index.ts +0 -10
  77. package/src/crc/package.json +0 -3
  78. package/src/crc/types.ts +0 -10
  79. package/src/errorCode.ts +0 -83
  80. package/src/globalData.ts +0 -9
  81. package/src/handler/EventListener.ts +0 -44
  82. package/src/handler/ble.ts +0 -1369
  83. package/src/handler/lan.ts +0 -389
  84. package/src/handler/socket.ts +0 -686
  85. package/src/openApiRequest.ts +0 -50
  86. package/src/productConfigFileManage.ts +0 -72
  87. package/src/protocol/Bind.ts +0 -22
  88. package/src/protocol/DeviceInfo.ts +0 -37
  89. package/src/protocol/DiscoverUDP.ts +0 -80
  90. package/src/protocol/GetDeviceStatus.ts +0 -61
  91. package/src/protocol/Login.ts +0 -43
  92. package/src/protocol/Ntp.ts +0 -13
  93. package/src/protocol/OTA/AwaitNoti.ts +0 -14
  94. package/src/protocol/OTA/CheckCanOTA.ts +0 -23
  95. package/src/protocol/OTA/OTAPackPackage.ts +0 -37
  96. package/src/protocol/OTA/OtaComplete.ts +0 -17
  97. package/src/protocol/OTA/PreOTA.ts +0 -48
  98. package/src/protocol/OTA/ResetPosition.ts +0 -14
  99. package/src/protocol/OffLineData.ts +0 -81
  100. package/src/protocol/ProtocolBase.ts +0 -54
  101. package/src/protocol/Reset.ts +0 -16
  102. package/src/protocol/SetReset.ts +0 -13
  103. package/src/protocol/WifiConfig.ts +0 -42
  104. package/src/protocol/dataPoint.ts +0 -687
  105. package/src/protocol/tool.ts +0 -140
  106. package/src/randomCode.ts +0 -25
  107. package/src/request.ts +0 -22
  108. package/src/sdk.ts +0 -1536
  109. package/src/sentry.ts +0 -55
  110. package/src/services/devices.ts +0 -313
  111. package/src/services/login.ts +0 -11
  112. package/src/services/monitor.ts +0 -117
  113. package/src/services/ota.ts +0 -17
  114. package/src/services/tool.ts +0 -10
  115. package/src/services/uploadP0.ts +0 -57
  116. package/src/sleep.ts +0 -2
  117. package/src/types/index.ts +0 -456
  118. package/src/utils.ts +0 -449
  119. package/src/wechatApi.ts +0 -211
  120. package/src/wifiConfig/ConfigBase.ts +0 -235
  121. package/src/wifiConfig/ap.ts +0 -185
  122. package/src/wifiConfig/ble.ts +0 -460
  123. package/src/wifiConfig/nfc/disposeData.ts +0 -63
  124. package/src/wifiConfig/nfc/formatData.ts +0 -46
  125. package/src/wifiConfig/nfc/formatSSID.ts +0 -59
  126. package/src/wifiConfig/nfc/index.ts +0 -134
  127. package/src/wifiConfig/nfc/isIncludedCH.ts +0 -8
  128. package/src/wifiConfig/nfc/nfcAConnect.ts +0 -30
  129. package/src/wifiConfig/nfc/nfcATransceive.ts +0 -29
  130. package/src/wifiConfig/nfc/ssIDToASC.ts +0 -12
  131. package/src/wifiConfig/nfc/stringToGbk.ts +0 -51
  132. package/src/wifiConfig/nfc/transceive.wx.ts +0 -124
  133. package/src/wifiConfig/nfc/types.ts +0 -18
  134. package/src/wifiConfig/timeZoneName.json +0 -1
@@ -1,460 +0,0 @@
1
- import errorCode from "../errorCode";
2
- import { ab2hex, advertisData2PkAndMac, isWXDevicesResult } from '../utils';
3
-
4
- import GizLog from "../GizLog";
5
- import { BleHandle } from "../handler/ble";
6
- import WifiConfig from "../protocol/WifiConfig";
7
- import sleep from "../sleep";
8
- import {
9
- getBLEDeviceCharacteristics, getBLEDeviceServices, getBluetoothAdapterState, getBluetoothDevices,
10
- notifyBLECharacteristicValueChange, retryConnect, startBluetoothDevicesDiscovery, unpackWriteBLECharacteristicValue
11
- } from '../wechatApi';
12
- import ConfigBase from "./ConfigBase";
13
- import { IDevice, IError, ConfigEventData, IRandomCodesResult, IResult, configBLEDeviceParams } from "../types";
14
-
15
- type EnableAndGetBluetoothDevicesRes = Promise<
16
- | { success: false; err: IError }
17
- | { success: true; bleDevices?: IDevice[] }
18
- >;
19
-
20
- interface IArgs {
21
- bleDeviceId: string;
22
- arrayBuffer: ArrayBuffer;
23
- serviceUUIDSuffix?: string;
24
- characteristicUUIDSuffix?: string;
25
- bleHandle: BleHandle;
26
- eventCallBack: (event: ConfigEventData) => void, // 配网回调
27
- }
28
-
29
- const configAck = '0000000303000002';
30
-
31
-
32
- interface ISetDeviceOnboardingDeployProps {
33
- timeout: number;
34
- isBind: boolean;
35
- softAPSSIDPrefix: string;
36
- eventCallBack: (event: ConfigEventData) => void; // 配网回调
37
- }
38
-
39
-
40
- class BLEConfig extends ConfigBase {
41
- bleHandle: BleHandle;
42
-
43
- constructor(
44
- ssid: string, bssid: string,
45
- password: string, specialProductKeys: string[],
46
- specialProductKeySecrets: string[],
47
- bleHandle: BleHandle,
48
- ) {
49
- super(ssid, bssid, password,specialProductKeys,specialProductKeySecrets)
50
- this.bleHandle = bleHandle;
51
- }
52
-
53
- sendBLEConfigCmd = ({
54
- bleDeviceId,
55
- arrayBuffer,
56
- serviceUUIDSuffix = 'abf0',
57
- characteristicUUIDSuffix = 'abf7',
58
- bleHandle,
59
- eventCallBack
60
- }: IArgs) => {
61
- let sendInterval = null;
62
- let closeTimeout = null;
63
-
64
- const checkInterrupt = () => {
65
- if (closeTimeout === null) {
66
- sendInterval && clearInterval(sendInterval);
67
- return true;
68
- }
69
- return !this.hasTimeoutHandler();
70
- }
71
-
72
- return new Promise<boolean>(async (resolve, reject) => {
73
- try {
74
- GizLog.debug(
75
- 'GIZ_SDK: ssid info: ', arrayBuffer
76
- );
77
- // 设置超时
78
- closeTimeout = setTimeout(() => {
79
- sendInterval && clearInterval(sendInterval);
80
- // 发送超时 返回失败
81
- closeTimeout = null;
82
- resolve(false);
83
- }, 5 * 1000)
84
- GizLog.debug(
85
- 'GIZ_SDK: createBLEConnection start: ', bleDeviceId
86
- );
87
- await bleHandle.disableScan()
88
-
89
- const connectData = await retryConnect(bleDeviceId, 10 * 1000);
90
-
91
- eventCallBack?.({
92
- event: "GIZ_CONNECT_SUCCESS",
93
- deviceID: bleDeviceId
94
- })
95
-
96
- bleHandle.enableScan();
97
-
98
- GizLog.debug(
99
- 'GIZ_SDK: createBLEConnection end, res:', connectData
100
- );
101
- const services = await getBLEDeviceServices(bleDeviceId);
102
- GizLog.debug(
103
- 'GIZ_SDK: getBLEDeviceServices end, res:', services
104
- );
105
- const service = services.find((s) =>
106
- s.uuid.split('-')[0].toLowerCase().endsWith(serviceUUIDSuffix)
107
- );
108
- if (!service) {
109
- // 获取蓝牙设备服务异常
110
- GizLog.debug(
111
- 'GIZ_SDK: get ble device services fail',
112
- bleDeviceId,
113
- services
114
- );
115
- resolve(false);
116
- return;
117
- }
118
-
119
- const characteristics = await getBLEDeviceCharacteristics(
120
- bleDeviceId,
121
- service.uuid
122
- );
123
- GizLog.debug(
124
- 'GIZ_SDK: getBLEDeviceCharacteristics end, res:', characteristics
125
- );
126
- const characteristic = characteristics.find((c) =>
127
- c.uuid.split('-')[0].toLowerCase().endsWith(characteristicUUIDSuffix)
128
- );
129
- if (!characteristic) {
130
- // 获取蓝牙设备特征值异常
131
- GizLog.debug(
132
- 'GIZ_SDK: get ble device characteristics fail',
133
- bleDeviceId,
134
- characteristics
135
- );
136
- resolve(false);
137
- return;
138
- }
139
-
140
- if (
141
- !characteristic.properties.notify &&
142
- !characteristic.properties.indicate
143
- ) {
144
- GizLog.debug(
145
- 'GIZ_SDK: the ble device characteristic not support notify or indicate',
146
- bleDeviceId,
147
- characteristic
148
- );
149
- // 该设备不支持 notify & indicate 操作
150
- resolve(false);
151
- return;
152
- }
153
-
154
- GizLog.debug(
155
- 'GIZ_SDK: check characteristic and service success',
156
- );
157
-
158
-
159
- await notifyBLECharacteristicValueChange(
160
- bleDeviceId,
161
- service.uuid,
162
- characteristic.uuid
163
- );
164
-
165
- eventCallBack?.({
166
- event: "GIZ_CONFIG_SEND_SUCCESS",
167
- })
168
-
169
- // 这里有个问题,模组好像不一定每次都会回
170
- const handleBLECharacteristicValueChange = (res: WechatMiniprogram.OnBLECharacteristicValueChangeListenerResult) => {
171
- const hexString = ab2hex(res.value);
172
- GizLog.debug('GIZ_SDK: 收到设备返回ack', hexString)
173
- eventCallBack({
174
- event: "GIZ_CONFIG_RECV_SUCCESS",
175
- })
176
- if (hexString === configAck) {
177
- // 发送成功
178
- bleHandle.removeEventListener("GizBleDeviceData", handleBLECharacteristicValueChange)
179
- resolve(true);
180
- }
181
- };
182
-
183
- bleHandle.addEventListener("GizBleDeviceData", handleBLECharacteristicValueChange)
184
-
185
- // 订阅特征值变化
186
- // wx.onBLECharacteristicValueChange(handleBLECharacteristicValueChange);
187
-
188
- GizLog.debug(
189
- 'GIZ_SDK: on notifyBLECharacteristicValueChange success',
190
- );
191
-
192
- if (checkInterrupt()) return;
193
-
194
- await unpackWriteBLECharacteristicValue(
195
- bleDeviceId,
196
- service.uuid,
197
- characteristic.uuid,
198
- arrayBuffer
199
- );
200
- sendInterval = setInterval(() => {
201
- if (checkInterrupt()) return;
202
- unpackWriteBLECharacteristicValue(
203
- bleDeviceId,
204
- service.uuid,
205
- characteristic.uuid,
206
- arrayBuffer
207
- );
208
- }, 2000)
209
-
210
- // if (res.errCode === 0) {
211
- // resolve(true);
212
- // } else{
213
- // resolve(false);
214
- // }
215
- GizLog.debug('GIZ_SDK: unpackWriteBLECharacteristicValue end');
216
- } catch (error) {
217
- reject(false);
218
- GizLog.debug('GIZ_SDK: sendBLEConfigCmd error', error);
219
- }
220
- })
221
- .catch((error) => {
222
- GizLog.debug('GIZ_SDK: sendBLEConfigCmd error', error);
223
- })
224
- .finally(() => {
225
- // 关闭连接
226
- closeTimeout && clearTimeout(closeTimeout);
227
- sendInterval && clearInterval(sendInterval);
228
- this.bleHandle.disConnectDevice(bleDeviceId)
229
- });
230
- }
231
-
232
-
233
- destroy = () => {
234
- this.cleanTimeout();
235
- }
236
- isValidBleDevice = (device:IDevice, softAPSSIDPrefix?: string) => {
237
- if (device.bleWorkStatus === 0) return false;
238
- if (!this.specialProductKeys.includes(device.productKey)) {
239
- return false;
240
- }
241
-
242
- GizLog.debug(`GIZ_SDK: isValidBleDevice mac: ${device.mac} pk: ${device.productKey} name: ${device.name}`)
243
- GizLog.debug(`GIZ_SDK: softAPSSIDPrefix: ${softAPSSIDPrefix} ismatch : ${device.name && device.name.startsWith(softAPSSIDPrefix)}`)
244
- return (
245
- !softAPSSIDPrefix ||
246
- (device.name && device.name.startsWith(softAPSSIDPrefix))
247
- || (device.localName && device.localName.startsWith(softAPSSIDPrefix))
248
- )
249
- }
250
-
251
- enableBluetoothDevicesDescovery = async (): Promise<
252
- { success: false; err: IError } | { success: true }
253
- > => {
254
- // try {
255
- // await closeBluetoothAdapter();
256
- // await openBluetoothAdapter();
257
- // } catch (error) {
258
-
259
- // }
260
- const stateRes = await getBluetoothAdapterState();
261
- if (!stateRes.available) {
262
- return {
263
- success: false,
264
- err: {
265
- errorCode: errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,
266
- errorMessage: '蓝牙状态不可用',
267
- },
268
- };
269
- }
270
-
271
- await startBluetoothDevicesDiscovery();
272
- return { success: true };
273
- };
274
-
275
-
276
- enableAndGetBluetoothDevices = async (
277
- softAPSSIDPrefix?: string
278
- ): EnableAndGetBluetoothDevicesRes => {
279
- const discoveryRes = await this.enableBluetoothDevicesDescovery();
280
- if (!discoveryRes.success) {
281
- return discoveryRes;
282
- }
283
- GizLog.debug('GIZ_SDK: start enableAndGetBluetoothDevices');
284
-
285
- // const bleDevices: WechatMiniprogram.BlueToothDevice[] = (
286
- // await getBluetoothDevices()
287
- // ).filter((d) => this.isValidBleDevice(d, softAPSSIDPrefix));
288
- const bleDevices: IDevice[] = this.bleHandle.scanList.filter(d => this.isValidBleDevice(d, softAPSSIDPrefix))
289
- GizLog.debug('GIZ_SDK: getBluetoothDevices success', bleDevices);
290
- return {
291
- success: true,
292
- bleDevices,
293
- };
294
- };
295
- setDeviceOnboardingDeploy = ({
296
- timeout,
297
- isBind = true,
298
- softAPSSIDPrefix,
299
- eventCallBack = (e) => {},
300
- }: ISetDeviceOnboardingDeployProps) => {
301
- this.eventCallBack = eventCallBack;
302
- return new Promise<IResult<IDevice[]>>(async (res, rej) => {
303
-
304
- // 清空扫描缓存
305
- this.bleHandle.scanList = [];
306
- this.eventCallBack?.({
307
- event: "GIZ_CONFIG_START",
308
- deviceID: null
309
- })
310
- const ssid = this.ssid;
311
- const password = this.password;
312
- this.destroy();
313
- this.initDeviceOnboardingDeploy(res, rej);
314
- this.startTimeoutTimer(timeout);
315
- try {
316
- const result = await this.configBLEDevice({
317
- ssid,
318
- password,
319
- timeout: timeout * 1000,
320
- softAPSSIDPrefix,
321
- });
322
-
323
- const newData: IDevice[] = (result.data || []).map(item => {
324
- return {
325
- mac: item.mac,
326
- productKey: item.product_key,
327
- did: item.did,
328
- name: '',
329
- localName: '',
330
- isBind: false,
331
- connectType: 'NONE',
332
- isBleOnline: false,
333
- isLanOnline: false,
334
- isOnline: false,
335
- }
336
- })
337
- if (isBind) {
338
- res(await this.bindDevices(newData));
339
- } else {
340
- // 不需要绑定 直接返回成功
341
- res({
342
- success: true,
343
- data: newData,
344
- });
345
- }
346
- } catch (error) {
347
- res({
348
- success: false,
349
- data: error
350
- });
351
- } finally {
352
- this.destroy();
353
- }
354
- });
355
- }
356
- /**
357
- * 负责发蓝牙设备指令
358
- */
359
- configBLEDevice = ({
360
- ssid,
361
- password,
362
- softAPSSIDPrefix,
363
- }: configBLEDeviceParams) => {
364
- return new Promise<IResult<IRandomCodesResult[]>>(async (res, rej) => {
365
- GizLog.debug('GIZ_SDK: start config ble device');
366
- const enableAndGetRes = await this.enableAndGetBluetoothDevices(
367
- softAPSSIDPrefix
368
- ).catch((error) => {
369
- return {
370
- success: false,
371
- err: {
372
- errorCode: errorCode.WECHAT_ERROR.errorCode,
373
- errorMessage: JSON.stringify(error),
374
- },
375
- };
376
- });
377
-
378
- if (!isWXDevicesResult(enableAndGetRes)) {
379
- // 开启获取蓝牙失败
380
- return rej(enableAndGetRes);
381
- }
382
-
383
- let bleDevices: IDevice[] = enableAndGetRes.bleDevices as IDevice[];
384
-
385
- GizLog.debug('GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ', bleDevices);
386
-
387
- // const handleFoundDevices = async ({
388
- // devices,
389
- // }: {
390
- // devices: WechatMiniprogram.BlueToothDevice[];
391
- // }) => {
392
- // if(this.hasTimeoutHandler()) {
393
- // Array.prototype.push.apply(
394
- // bleDevices,
395
- // devices.filter((d) => this.isValidBleDevice(d, softAPSSIDPrefix))
396
- // )
397
- // } else {
398
- // wx.offBluetoothDeviceFound(()=>{});
399
- // }
400
- // };
401
-
402
- // wx.onBluetoothDeviceFound(handleFoundDevices);
403
- await startBluetoothDevicesDiscovery(true);
404
-
405
- const appendPassword = this.appendExtendData(password)
406
- const uint8Array = WifiConfig.pack(ssid,appendPassword);
407
- const startConfigDevice = async () => {
408
- GizLog.debug('GIZ_SDK: startConfigDevice');
409
- if (!this.hasTimeoutHandler()) {
410
- return;
411
- }
412
- const bleDevice = bleDevices.shift() as IDevice;
413
- if (bleDevice) {
414
- this.eventCallBack?.({
415
- event: "GIZ_DISCOVER_SUCCESS",
416
- deviceID: bleDevice.mac
417
- })
418
- GizLog.debug('GIZ_SDK: startConfigDevice, target device: ', bleDevice);
419
- }
420
-
421
- let success = false;
422
- if (bleDevice) {
423
- success = await this.sendBLEConfigCmd({
424
- bleDeviceId: bleDevice.bleDeviceID,
425
- arrayBuffer: uint8Array.buffer,
426
- bleHandle: this.bleHandle,
427
- eventCallBack: this.eventCallBack
428
- }) === true
429
- }
430
-
431
- if (!success) {
432
- // 如果校验设备或者发送不成功,重试下一个设备
433
- await sleep(500);
434
- bleDevices = this.bleHandle.scanList.filter((d) => this.isValidBleDevice(d, softAPSSIDPrefix));;
435
- await startConfigDevice();
436
- return;
437
- }
438
-
439
- // 如果有一个设备发送成功,则不再发现新设备
440
- GizLog.debug("GIZ_SDK: offBluetoothDeviceFound ready search device")
441
- // wx.offBluetoothDeviceFound(() => {});
442
- };
443
-
444
- // 开始大循环搜索
445
- try {
446
- // const devicesReturn = await this.searchDevice({ ssid, password });
447
- this.searchDevice({ ssid, password }).then(devicesReturn => {
448
- res(devicesReturn);
449
- })
450
- } catch (error) {
451
- rej(error);
452
- GizLog.error("GIZ_SDK: searchDevice error", new Error(JSON.stringify(error)))
453
- }
454
-
455
- await startConfigDevice();
456
- });
457
- };
458
- }
459
-
460
- export default BLEConfig;
@@ -1,63 +0,0 @@
1
- import { IDATA } from './types';
2
-
3
- /**
4
- * 配网标志位
5
- */
6
- const formatSign = (): Uint8Array => {
7
- const buffer = new ArrayBuffer(1);
8
- const uint8Array = new Uint8Array(buffer);
9
- uint8Array[0] = 1;
10
- return uint8Array;
11
- };
12
- /**
13
- * 标志位,APP端设置,含有中⽂字符SSID置为1,不含中⽂字符SSID置为0,默认为0
14
- * @param isSSIDincludeCH
15
- */
16
- const formatRouterType = (isSSIDincludeCH: boolean): Uint8Array => {
17
- const buffer = new ArrayBuffer(1);
18
- const uint8Array = new Uint8Array(buffer);
19
- uint8Array[0] = 0;
20
- if (isSSIDincludeCH) {
21
- uint8Array[0] = 1;
22
- }
23
- return uint8Array;
24
- };
25
- /**
26
- * 模块初始化标志位,默认未初始化,值为 0x55 0xaa代表已初始化,其他代表未初始化。
27
- */
28
- const formatInitValue = (): Uint8Array => {
29
- const buffer = new ArrayBuffer(2);
30
- const uint8Array = new Uint8Array(buffer);
31
- uint8Array[0] = parseInt('0x55', 16);
32
- uint8Array[1] = parseInt('0xaa', 16);
33
- return uint8Array;
34
- };
35
- /**
36
- * 处理整合传入的数据
37
- * @param SSID SSIDTLV
38
- * @param isSSIDincludeCH SSID是否含有中文
39
- * @param pwd pwdTLV
40
- * @param passIP passIPTLV
41
- * @param BSSID BSSIDTLV
42
- * @returns 最终要写入固件的数据
43
- */
44
- export const disposeData = (
45
- SSID: Uint8Array,
46
- isSSIDincludeCH: boolean,
47
- pwd: Uint8Array,
48
- passIP: Uint8Array,
49
- BSSID: Uint8Array
50
- ): IDATA => {
51
- const sign = formatSign();
52
- const routerType = formatRouterType(isSSIDincludeCH);
53
- const initValue = formatInitValue();
54
-
55
- const uint8Array_sign = Uint8Array.from([...sign, ...routerType, ...initValue]);
56
- const uint8Array_others = Uint8Array.from([...SSID, ...pwd, ...passIP, ...BSSID]);
57
- console.log(uint8Array_sign.buffer, 'uint8Array_sign.buffer', uint8Array_sign);
58
- console.log(uint8Array_others.buffer, 'uint8Array_others.buffer', uint8Array_others);
59
- return {
60
- ArrayBuffer_sign: uint8Array_sign.buffer,
61
- ArrayBuffer_others: uint8Array_others.buffer,
62
- };
63
- };
@@ -1,46 +0,0 @@
1
- type IType = 'BSSID' | 'pwd' | 'address';
2
- /**
3
- * BSSID去除冒号,转TLV编码(总长8字节)& pwd | passIP转TLV编码
4
- * @param data BSSID | pwd | passIP
5
- * @param type 'BSSID' & 'pwd' & 'passIP'
6
- * @returns BSSID(TLV) & pwd(TLV) & passIP(TLV): Uint8Array;
7
- */
8
- export const formatData = (data: string, type: IType): Uint8Array => {
9
- const isNull = data.length === 0;
10
- const Data = type === 'BSSID' ? data.split(':') : data.split('');
11
- let length: number = 0;
12
- let T: any = null;
13
- let L: number = 0;
14
- switch (type) {
15
- case 'BSSID':
16
- length = isNull ? 3 : Data.length + 2;
17
- T = 'b';
18
- L = isNull ? 0 : Data.length;
19
- break;
20
- case 'pwd':
21
- length = data.length + 2;
22
- T = 'p';
23
- L = data.length;
24
- break;
25
- case 'address':
26
- length = isNull ? 3 : Data.length + 2;
27
- T = 'i';
28
- L = isNull ? 0 : Data.length;
29
- break;
30
- }
31
- const buffer = new ArrayBuffer(length);
32
- const uint8Array = new Uint8Array(buffer);
33
- uint8Array[0] = T.charCodeAt(0); // Tag
34
- uint8Array[1] = L; // Length
35
-
36
- if (isNull) {
37
- uint8Array[2] = 0;
38
- } else {
39
- Data.forEach((byte, index) => {
40
- const v = type === 'BSSID' ? parseInt(byte, 16) : byte.charCodeAt(0);
41
- uint8Array[index + 2] = v; // 前两个字节为Tag\Length预留
42
- });
43
- }
44
- console.log(buffer, uint8Array, 'formatData', type);
45
- return uint8Array;
46
- };
@@ -1,59 +0,0 @@
1
- import { formatCodesFromStr, arrayToString } from '../../protocol/tool';
2
- import { unionBy } from '../../utils';
3
- import isIncludedCH from './isIncludedCH';
4
- import { ssIDToASC } from './ssIDToASC';
5
- import stringToGbk from './stringToGbk';
6
-
7
- interface IExport {
8
- SSIDTLV: any;
9
- isSSIDIncludedCH: boolean;
10
- }
11
- /**
12
- * SSID转TLV编码 / 判断SSID是否含有中文
13
- * @param SSID
14
- * @returns SSIDTLV: TLV(Uint8Array), isSSIDIncludedCH: boolean
15
- */
16
- export const formatSSID = (SSID: string): IExport => {
17
- const _export: IExport = {
18
- SSIDTLV: null,
19
- isSSIDIncludedCH: isIncludedCH(SSID),
20
- };
21
- // const enCode = isIncludedCH(SSID) ? stringToGbk(SSID) : ssIDToASC(SSID);
22
- // const length = enCode.byteLength;
23
-
24
- const [enCode, length] = formatCodesFromStr(SSID);
25
- const codeLength = parseInt(arrayToString(length), 16);
26
- if (codeLength <= 127) {
27
- const buffer = new ArrayBuffer(codeLength + 2);
28
- const uint8Array = new Uint8Array(buffer);
29
- uint8Array[0] = 's'.charCodeAt(0); // T
30
- uint8Array[1] = codeLength; // L
31
- enCode.forEach((byte, index) => {
32
- uint8Array[index + 2] = byte;
33
- });
34
- _export['SSIDTLV'] = uint8Array;
35
- } else {
36
- // @ts-ignore
37
- const extra_L = parseInt(length / 255) + 1;
38
- const buffer = new ArrayBuffer(codeLength + 2 + extra_L);
39
- const uint8Array = new Uint8Array(buffer);
40
- uint8Array[0] = 's'.charCodeAt(0); // T
41
- uint8Array[1] = 128 + extra_L; // L@No1.Byte
42
- if (extra_L === 1) {
43
- uint8Array[2] = codeLength; // L@No2.Byte
44
- } else {
45
- uint8Array[extra_L] = 255;
46
- uint8Array[extra_L + 1] = codeLength - 255 * (extra_L - 1);
47
- for (let d = extra_L; d >= 1; d--) {
48
- if (uint8Array[extra_L - d] === 0) {
49
- uint8Array[extra_L - d] = 255;
50
- }
51
- }
52
- }
53
- enCode.forEach((byte, index) => {
54
- uint8Array[index + 2 + extra_L] = byte;
55
- });
56
- _export['SSIDTLV'] = uint8Array;
57
- }
58
- return _export;
59
- };