mini_program_gizwits_sdk 3.6.3 → 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 (135) hide show
  1. package/README.md +4 -0
  2. package/dist/index.js +3 -3
  3. package/package.json +1 -1
  4. package/yarn-error.log +6901 -0
  5. package/dist/src/GizLog.d.ts +0 -18
  6. package/dist/src/crc/calculators/crc16modbus.d.ts +0 -2
  7. package/dist/src/crc/calculators/crc32.d.ts +0 -2
  8. package/dist/src/crc/crc16modbus.d.ts +0 -7
  9. package/dist/src/crc/crc32.d.ts +0 -7
  10. package/dist/src/crc/create_buffer.d.ts +0 -3
  11. package/dist/src/crc/define_crc.d.ts +0 -7
  12. package/dist/src/crc/index.d.ts +0 -19
  13. package/dist/src/crc/types.d.ts +0 -11
  14. package/dist/src/errorCode.d.ts +0 -3
  15. package/dist/src/globalData.d.ts +0 -2
  16. package/dist/src/handler/EventListener.d.ts +0 -9
  17. package/dist/src/handler/ble.d.ts +0 -105
  18. package/dist/src/handler/lan.d.ts +0 -78
  19. package/dist/src/handler/socket.d.ts +0 -151
  20. package/dist/src/openApiRequest.d.ts +0 -3
  21. package/dist/src/productConfigFileManage.d.ts +0 -11
  22. package/dist/src/protocol/Bind.d.ts +0 -7
  23. package/dist/src/protocol/DeviceInfo.d.ts +0 -11
  24. package/dist/src/protocol/DiscoverUDP.d.ts +0 -17
  25. package/dist/src/protocol/GetDeviceStatus.d.ts +0 -5
  26. package/dist/src/protocol/Login.d.ts +0 -12
  27. package/dist/src/protocol/Ntp.d.ts +0 -5
  28. package/dist/src/protocol/OTA/AwaitNoti.d.ts +0 -7
  29. package/dist/src/protocol/OTA/CheckCanOTA.d.ts +0 -10
  30. package/dist/src/protocol/OTA/OTAPackPackage.d.ts +0 -8
  31. package/dist/src/protocol/OTA/OtaComplete.d.ts +0 -8
  32. package/dist/src/protocol/OTA/PreOTA.d.ts +0 -11
  33. package/dist/src/protocol/OTA/ResetPosition.d.ts +0 -6
  34. package/dist/src/protocol/OffLineData.d.ts +0 -23
  35. package/dist/src/protocol/ProtocolBase.d.ts +0 -11
  36. package/dist/src/protocol/Reset.d.ts +0 -8
  37. package/dist/src/protocol/SetReset.d.ts +0 -7
  38. package/dist/src/protocol/WifiConfig.d.ts +0 -6
  39. package/dist/src/protocol/dataPoint.d.ts +0 -34
  40. package/dist/src/protocol/tool.d.ts +0 -14
  41. package/dist/src/randomCode.d.ts +0 -3
  42. package/dist/src/request.d.ts +0 -1
  43. package/dist/src/sdk.d.ts +0 -136
  44. package/dist/src/sentry.d.ts +0 -2
  45. package/dist/src/services/devices.d.ts +0 -47
  46. package/dist/src/services/login.d.ts +0 -4
  47. package/dist/src/services/monitor.d.ts +0 -12
  48. package/dist/src/services/ota.d.ts +0 -7
  49. package/dist/src/services/tool.d.ts +0 -4
  50. package/dist/src/services/uploadP0.d.ts +0 -14
  51. package/dist/src/sleep.d.ts +0 -2
  52. package/dist/src/types/index.d.ts +0 -360
  53. package/dist/src/utils.d.ts +0 -46
  54. package/dist/src/wechatApi.d.ts +0 -19
  55. package/dist/src/wifiConfig/ConfigBase.d.ts +0 -27
  56. package/dist/src/wifiConfig/ap.d.ts +0 -11
  57. package/dist/src/wifiConfig/ble.d.ts +0 -41
  58. package/dist/src/wifiConfig/nfc/disposeData.d.ts +0 -2
  59. package/dist/src/wifiConfig/nfc/formatData.d.ts +0 -3
  60. package/dist/src/wifiConfig/nfc/formatSSID.d.ts +0 -6
  61. package/dist/src/wifiConfig/nfc/index.d.ts +0 -22
  62. package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +0 -1
  63. package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +0 -6
  64. package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +0 -5
  65. package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +0 -1
  66. package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +0 -1
  67. package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +0 -2
  68. package/dist/src/wifiConfig/nfc/types.d.ts +0 -15
  69. package/index.ts +0 -8
  70. package/src/GizLog.ts +0 -51
  71. package/src/crc/calculators/crc16modbus.ts +0 -36
  72. package/src/crc/calculators/crc32.ts +0 -47
  73. package/src/crc/crc16modbus.ts +0 -3
  74. package/src/crc/crc32.ts +0 -4
  75. package/src/crc/create_buffer.ts +0 -7
  76. package/src/crc/define_crc.ts +0 -9
  77. package/src/crc/index.ts +0 -10
  78. package/src/crc/package.json +0 -3
  79. package/src/crc/types.ts +0 -10
  80. package/src/errorCode.ts +0 -83
  81. package/src/globalData.ts +0 -9
  82. package/src/handler/EventListener.ts +0 -44
  83. package/src/handler/ble.ts +0 -1369
  84. package/src/handler/lan.ts +0 -388
  85. package/src/handler/socket.ts +0 -686
  86. package/src/openApiRequest.ts +0 -50
  87. package/src/productConfigFileManage.ts +0 -72
  88. package/src/protocol/Bind.ts +0 -22
  89. package/src/protocol/DeviceInfo.ts +0 -37
  90. package/src/protocol/DiscoverUDP.ts +0 -80
  91. package/src/protocol/GetDeviceStatus.ts +0 -61
  92. package/src/protocol/Login.ts +0 -43
  93. package/src/protocol/Ntp.ts +0 -13
  94. package/src/protocol/OTA/AwaitNoti.ts +0 -14
  95. package/src/protocol/OTA/CheckCanOTA.ts +0 -23
  96. package/src/protocol/OTA/OTAPackPackage.ts +0 -37
  97. package/src/protocol/OTA/OtaComplete.ts +0 -17
  98. package/src/protocol/OTA/PreOTA.ts +0 -48
  99. package/src/protocol/OTA/ResetPosition.ts +0 -14
  100. package/src/protocol/OffLineData.ts +0 -81
  101. package/src/protocol/ProtocolBase.ts +0 -54
  102. package/src/protocol/Reset.ts +0 -16
  103. package/src/protocol/SetReset.ts +0 -13
  104. package/src/protocol/WifiConfig.ts +0 -42
  105. package/src/protocol/dataPoint.ts +0 -687
  106. package/src/protocol/tool.ts +0 -140
  107. package/src/randomCode.ts +0 -25
  108. package/src/request.ts +0 -22
  109. package/src/sdk.ts +0 -1536
  110. package/src/sentry.ts +0 -55
  111. package/src/services/devices.ts +0 -312
  112. package/src/services/login.ts +0 -11
  113. package/src/services/monitor.ts +0 -117
  114. package/src/services/ota.ts +0 -17
  115. package/src/services/tool.ts +0 -10
  116. package/src/services/uploadP0.ts +0 -57
  117. package/src/sleep.ts +0 -2
  118. package/src/types/index.ts +0 -455
  119. package/src/utils.ts +0 -448
  120. package/src/wechatApi.ts +0 -211
  121. package/src/wifiConfig/ConfigBase.ts +0 -235
  122. package/src/wifiConfig/ap.ts +0 -184
  123. package/src/wifiConfig/ble.ts +0 -481
  124. package/src/wifiConfig/nfc/disposeData.ts +0 -63
  125. package/src/wifiConfig/nfc/formatData.ts +0 -46
  126. package/src/wifiConfig/nfc/formatSSID.ts +0 -59
  127. package/src/wifiConfig/nfc/index.ts +0 -133
  128. package/src/wifiConfig/nfc/isIncludedCH.ts +0 -8
  129. package/src/wifiConfig/nfc/nfcAConnect.ts +0 -30
  130. package/src/wifiConfig/nfc/nfcATransceive.ts +0 -29
  131. package/src/wifiConfig/nfc/ssIDToASC.ts +0 -12
  132. package/src/wifiConfig/nfc/stringToGbk.ts +0 -51
  133. package/src/wifiConfig/nfc/transceive.wx.ts +0 -124
  134. package/src/wifiConfig/nfc/types.ts +0 -18
  135. package/src/wifiConfig/timeZoneName.json +0 -1
@@ -1,481 +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
- )
248
- }
249
- // isValidBleDevice = (
250
- // bleDevice: WechatMiniprogram.BlueToothDevice,
251
- // softAPSSIDPrefix?: string
252
- // ) => {
253
- // if (!bleDevice || !bleDevice.advertisData) {
254
- // // 无效蓝牙设备或者蓝牙设备广播数据为空,返回失败
255
- // return false;
256
- // }
257
- // const {productKey, mac, bleWorkStatus} = advertisData2PkAndMac(bleDevice.advertisData, this.specialProductKeys)
258
- // if (!this.specialProductKeys.includes(productKey)) {
259
- // // 不在PK列表
260
- // return false;
261
- // }
262
- // // 判断广播包是否可以配网
263
- // if (bleWorkStatus !== 1) return;
264
- // GizLog.debug(`GIZ_SDK: isValidBleDevice mac: ${mac} pk: ${productKey} name: ${bleDevice.name}`)
265
- // GizLog.debug(`GIZ_SDK: softAPSSIDPrefix: ${softAPSSIDPrefix} ismatch : ${bleDevice.name && bleDevice.name.startsWith(softAPSSIDPrefix)}`)
266
- // return (
267
- // !softAPSSIDPrefix ||
268
- // (bleDevice.name && bleDevice.name.startsWith(softAPSSIDPrefix))
269
- // );
270
- // };
271
-
272
-
273
- enableBluetoothDevicesDescovery = async (): Promise<
274
- { success: false; err: IError } | { success: true }
275
- > => {
276
- // try {
277
- // await closeBluetoothAdapter();
278
- // await openBluetoothAdapter();
279
- // } catch (error) {
280
-
281
- // }
282
- const stateRes = await getBluetoothAdapterState();
283
- if (!stateRes.available) {
284
- return {
285
- success: false,
286
- err: {
287
- errorCode: errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,
288
- errorMessage: '蓝牙状态不可用',
289
- },
290
- };
291
- }
292
-
293
- await startBluetoothDevicesDiscovery();
294
- return { success: true };
295
- };
296
-
297
-
298
- enableAndGetBluetoothDevices = async (
299
- softAPSSIDPrefix?: string
300
- ): EnableAndGetBluetoothDevicesRes => {
301
- const discoveryRes = await this.enableBluetoothDevicesDescovery();
302
- if (!discoveryRes.success) {
303
- return discoveryRes;
304
- }
305
- GizLog.debug('GIZ_SDK: start enableAndGetBluetoothDevices');
306
-
307
- // const bleDevices: WechatMiniprogram.BlueToothDevice[] = (
308
- // await getBluetoothDevices()
309
- // ).filter((d) => this.isValidBleDevice(d, softAPSSIDPrefix));
310
- const bleDevices: IDevice[] = this.bleHandle.scanList.filter(d => this.isValidBleDevice(d, softAPSSIDPrefix))
311
- GizLog.debug('GIZ_SDK: getBluetoothDevices success', bleDevices);
312
- return {
313
- success: true,
314
- bleDevices,
315
- };
316
- };
317
- setDeviceOnboardingDeploy = ({
318
- timeout,
319
- isBind = true,
320
- softAPSSIDPrefix,
321
- eventCallBack = (e) => {},
322
- }: ISetDeviceOnboardingDeployProps) => {
323
- this.eventCallBack = eventCallBack;
324
- return new Promise<IResult<IDevice[]>>(async (res, rej) => {
325
-
326
- // 清空扫描缓存
327
- this.bleHandle.scanList = [];
328
- this.eventCallBack?.({
329
- event: "GIZ_CONFIG_START",
330
- deviceID: null
331
- })
332
- const ssid = this.ssid;
333
- const password = this.password;
334
- this.destroy();
335
- this.initDeviceOnboardingDeploy(res, rej);
336
- this.startTimeoutTimer(timeout);
337
- try {
338
- const result = await this.configBLEDevice({
339
- ssid,
340
- password,
341
- timeout: timeout * 1000,
342
- softAPSSIDPrefix,
343
- });
344
-
345
- const newData: IDevice[] = (result.data || []).map(item => {
346
- return {
347
- mac: item.mac,
348
- productKey: item.product_key,
349
- did: item.did,
350
- name: '',
351
- isBind: false,
352
- connectType: 'NONE',
353
- isBleOnline: false,
354
- isLanOnline: false,
355
- isOnline: false,
356
- }
357
- })
358
- if (isBind) {
359
- res(await this.bindDevices(newData));
360
- } else {
361
- // 不需要绑定 直接返回成功
362
- res({
363
- success: true,
364
- data: newData,
365
- });
366
- }
367
- } catch (error) {
368
- res({
369
- success: false,
370
- data: error
371
- });
372
- } finally {
373
- this.destroy();
374
- }
375
- });
376
- }
377
- /**
378
- * 负责发蓝牙设备指令
379
- */
380
- configBLEDevice = ({
381
- ssid,
382
- password,
383
- softAPSSIDPrefix,
384
- }: configBLEDeviceParams) => {
385
- return new Promise<IResult<IRandomCodesResult[]>>(async (res, rej) => {
386
- GizLog.debug('GIZ_SDK: start config ble device');
387
- const enableAndGetRes = await this.enableAndGetBluetoothDevices(
388
- softAPSSIDPrefix
389
- ).catch((error) => {
390
- return {
391
- success: false,
392
- err: {
393
- errorCode: errorCode.WECHAT_ERROR.errorCode,
394
- errorMessage: JSON.stringify(error),
395
- },
396
- };
397
- });
398
-
399
- if (!isWXDevicesResult(enableAndGetRes)) {
400
- // 开启获取蓝牙失败
401
- return rej(enableAndGetRes);
402
- }
403
-
404
- let bleDevices: IDevice[] = enableAndGetRes.bleDevices as IDevice[];
405
-
406
- GizLog.debug('GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ', bleDevices);
407
-
408
- // const handleFoundDevices = async ({
409
- // devices,
410
- // }: {
411
- // devices: WechatMiniprogram.BlueToothDevice[];
412
- // }) => {
413
- // if(this.hasTimeoutHandler()) {
414
- // Array.prototype.push.apply(
415
- // bleDevices,
416
- // devices.filter((d) => this.isValidBleDevice(d, softAPSSIDPrefix))
417
- // )
418
- // } else {
419
- // wx.offBluetoothDeviceFound(()=>{});
420
- // }
421
- // };
422
-
423
- // wx.onBluetoothDeviceFound(handleFoundDevices);
424
- await startBluetoothDevicesDiscovery(true);
425
-
426
- const appendPassword = this.appendExtendData(password)
427
- const uint8Array = WifiConfig.pack(ssid,appendPassword);
428
- const startConfigDevice = async () => {
429
- GizLog.debug('GIZ_SDK: startConfigDevice');
430
- if (!this.hasTimeoutHandler()) {
431
- return;
432
- }
433
- const bleDevice = bleDevices.shift() as IDevice;
434
- if (bleDevice) {
435
- this.eventCallBack?.({
436
- event: "GIZ_DISCOVER_SUCCESS",
437
- deviceID: bleDevice.mac
438
- })
439
- GizLog.debug('GIZ_SDK: startConfigDevice, target device: ', bleDevice);
440
- }
441
-
442
- let success = false;
443
- if (bleDevice) {
444
- success = await this.sendBLEConfigCmd({
445
- bleDeviceId: bleDevice.bleDeviceID,
446
- arrayBuffer: uint8Array.buffer,
447
- bleHandle: this.bleHandle,
448
- eventCallBack: this.eventCallBack
449
- }) === true
450
- }
451
-
452
- if (!success) {
453
- // 如果校验设备或者发送不成功,重试下一个设备
454
- await sleep(500);
455
- bleDevices = this.bleHandle.scanList.filter((d) => this.isValidBleDevice(d, softAPSSIDPrefix));;
456
- await startConfigDevice();
457
- return;
458
- }
459
-
460
- // 如果有一个设备发送成功,则不再发现新设备
461
- GizLog.debug("GIZ_SDK: offBluetoothDeviceFound ready search device")
462
- // wx.offBluetoothDeviceFound(() => {});
463
- };
464
-
465
- // 开始大循环搜索
466
- try {
467
- // const devicesReturn = await this.searchDevice({ ssid, password });
468
- this.searchDevice({ ssid, password }).then(devicesReturn => {
469
- res(devicesReturn);
470
- })
471
- } catch (error) {
472
- rej(error);
473
- GizLog.error("GIZ_SDK: searchDevice error", new Error(JSON.stringify(error)))
474
- }
475
-
476
- await startConfigDevice();
477
- });
478
- };
479
- }
480
-
481
- 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
- };