mini_program_gizwits_sdk 3.7.1-kuka → 3.7.2-beta.0

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/README.md +209 -25
  2. package/{index.ts → dist/index.d.ts} +3 -3
  3. package/dist/index.js +6 -4
  4. package/dist/src/crc/calculators/crc16modbus.d.ts +2 -0
  5. package/dist/src/crc/calculators/crc32.d.ts +2 -0
  6. package/dist/src/crc/crc16modbus.d.ts +7 -0
  7. package/dist/src/crc/crc32.d.ts +7 -0
  8. package/dist/src/crc/create_buffer.d.ts +3 -0
  9. package/dist/src/crc/define_crc.d.ts +7 -0
  10. package/dist/src/crc/index.d.ts +19 -0
  11. package/{src/crc/types.ts → dist/src/crc/types.d.ts} +1 -1
  12. package/dist/src/handler/EventListener.d.ts +9 -0
  13. package/dist/src/handler/ble.d.ts +130 -0
  14. package/dist/src/handler/lan.d.ts +78 -0
  15. package/dist/src/handler/socket.d.ts +161 -0
  16. package/dist/src/protocol/Bind.d.ts +7 -0
  17. package/dist/src/protocol/DeviceInfo.d.ts +11 -0
  18. package/dist/src/protocol/DiscoverUDP.d.ts +17 -0
  19. package/dist/src/protocol/GetDeviceStatus.d.ts +5 -0
  20. package/dist/src/protocol/Login.d.ts +12 -0
  21. package/dist/src/protocol/Ntp.d.ts +5 -0
  22. package/dist/src/protocol/OTA/AwaitNoti.d.ts +7 -0
  23. package/dist/src/protocol/OTA/CheckCanOTA.d.ts +10 -0
  24. package/dist/src/protocol/OTA/OTAPackPackage.d.ts +8 -0
  25. package/dist/src/protocol/OTA/OtaComplete.d.ts +8 -0
  26. package/dist/src/protocol/OTA/PreOTA.d.ts +11 -0
  27. package/dist/src/protocol/OTA/ResetPosition.d.ts +6 -0
  28. package/dist/src/protocol/OffLineData.d.ts +23 -0
  29. package/dist/src/protocol/ProtocolBase.d.ts +12 -0
  30. package/dist/src/protocol/Reset.d.ts +8 -0
  31. package/dist/src/protocol/SetReset.d.ts +7 -0
  32. package/dist/src/protocol/TransparentData.d.ts +12 -0
  33. package/dist/src/protocol/WifiConfig.d.ts +11 -0
  34. package/dist/src/protocol/dataPoint.d.ts +34 -0
  35. package/dist/src/protocol/tool.d.ts +14 -0
  36. package/dist/src/sdk.d.ts +154 -0
  37. package/dist/src/services/devices.d.ts +52 -0
  38. package/dist/src/services/login.d.ts +4 -0
  39. package/dist/src/services/monitor.d.ts +12 -0
  40. package/dist/src/services/ota.d.ts +7 -0
  41. package/dist/src/services/tool.d.ts +4 -0
  42. package/dist/src/services/uploadP0.d.ts +14 -0
  43. package/dist/src/types/index.d.ts +398 -0
  44. package/dist/src/utils/GizLog.d.ts +18 -0
  45. package/dist/src/utils/bleConfigLog.d.ts +11 -0
  46. package/dist/src/utils/connectedBssid.d.ts +6 -0
  47. package/dist/src/utils/errorCode.d.ts +3 -0
  48. package/dist/src/utils/globalData.d.ts +2 -0
  49. package/dist/src/utils/openApiRequest.d.ts +27 -0
  50. package/dist/src/utils/productConfigFileManage.d.ts +15 -0
  51. package/dist/src/utils/randomCode.d.ts +3 -0
  52. package/dist/src/utils/request.d.ts +1 -0
  53. package/dist/src/utils/sentry.d.ts +2 -0
  54. package/dist/src/utils/sleep.d.ts +2 -0
  55. package/dist/src/utils/utils.d.ts +55 -0
  56. package/dist/src/utils/wechatApi.d.ts +24 -0
  57. package/dist/src/utils/wifiConfigLogReport.d.ts +28 -0
  58. package/dist/src/wifiConfig/ConfigBase.d.ts +27 -0
  59. package/dist/src/wifiConfig/ap.d.ts +11 -0
  60. package/dist/src/wifiConfig/ble.d.ts +43 -0
  61. package/dist/src/wifiConfig/nfc/disposeData.d.ts +2 -0
  62. package/dist/src/wifiConfig/nfc/formatData.d.ts +3 -0
  63. package/dist/src/wifiConfig/nfc/formatSSID.d.ts +6 -0
  64. package/dist/src/wifiConfig/nfc/index.d.ts +22 -0
  65. package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +1 -0
  66. package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +6 -0
  67. package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +5 -0
  68. package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +1 -0
  69. package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +1 -0
  70. package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +2 -0
  71. package/dist/src/wifiConfig/nfc/types.d.ts +15 -0
  72. package/global.d.ts +3 -19
  73. package/package.json +16 -7
  74. package/.istanbul.yml +0 -4
  75. package/.travis.yml +0 -23
  76. package/.vscode/launch.json +0 -19
  77. package/.vscode/settings.json +0 -3
  78. package/src/GizLog.ts +0 -51
  79. package/src/aepApi/aepApiRequest.ts +0 -61
  80. package/src/crc/calculators/crc16modbus.ts +0 -36
  81. package/src/crc/calculators/crc32.ts +0 -47
  82. package/src/crc/crc16modbus.ts +0 -3
  83. package/src/crc/crc32.ts +0 -4
  84. package/src/crc/create_buffer.ts +0 -7
  85. package/src/crc/define_crc.ts +0 -9
  86. package/src/crc/index.ts +0 -10
  87. package/src/crc/package.json +0 -3
  88. package/src/errorCode.ts +0 -84
  89. package/src/global.d.ts +0 -53
  90. package/src/globalData.ts +0 -9
  91. package/src/handler/EventListener.ts +0 -44
  92. package/src/handler/ble.ts +0 -1485
  93. package/src/handler/lan.ts +0 -409
  94. package/src/handler/socket.ts +0 -625
  95. package/src/openApiRequest.ts +0 -62
  96. package/src/productConfigFileManage.ts +0 -58
  97. package/src/protocol/Bind.ts +0 -22
  98. package/src/protocol/DeviceInfo.ts +0 -36
  99. package/src/protocol/DiscoverUDP.ts +0 -80
  100. package/src/protocol/GetDeviceStatus.ts +0 -63
  101. package/src/protocol/Login.ts +0 -43
  102. package/src/protocol/Ntp.ts +0 -13
  103. package/src/protocol/OTA/AwaitNoti.ts +0 -14
  104. package/src/protocol/OTA/CheckCanOTA.ts +0 -23
  105. package/src/protocol/OTA/OTAPackPackage.ts +0 -36
  106. package/src/protocol/OTA/OtaComplete.ts +0 -17
  107. package/src/protocol/OTA/PreOTA.ts +0 -47
  108. package/src/protocol/OTA/ResetPosition.ts +0 -14
  109. package/src/protocol/OffLineData.ts +0 -81
  110. package/src/protocol/ProtocolBase.ts +0 -54
  111. package/src/protocol/Reset.ts +0 -15
  112. package/src/protocol/SetReset.ts +0 -11
  113. package/src/protocol/WifiConfig.ts +0 -42
  114. package/src/protocol/dataPoint.ts +0 -769
  115. package/src/protocol/thirdProtocol/YunZhiMianBleProtocolBase.ts +0 -39
  116. package/src/protocol/tool.ts +0 -147
  117. package/src/randomCode.ts +0 -36
  118. package/src/request.ts +0 -22
  119. package/src/sdk.ts +0 -1472
  120. package/src/sentry.ts +0 -55
  121. package/src/services/devices.ts +0 -309
  122. package/src/services/login.ts +0 -15
  123. package/src/services/ota.ts +0 -30
  124. package/src/services/tool.ts +0 -10
  125. package/src/services/uploadP0.ts +0 -56
  126. package/src/sleep.ts +0 -2
  127. package/src/types/index.ts +0 -48
  128. package/src/utils.ts +0 -419
  129. package/src/wechatApi.ts +0 -286
  130. package/src/wifiConfig/ConfigBase.ts +0 -185
  131. package/src/wifiConfig/ap.ts +0 -192
  132. package/src/wifiConfig/ble.ts +0 -436
  133. package/src/wifiConfig/ble_ailCloud.ts +0 -554
  134. package/yarn-error.log +0 -6901
@@ -1,436 +0,0 @@
1
- import errorCode from "../errorCode";
2
- import { IRandomCodesResult, IResult } from "../sdk";
3
- import { ab2hex, advertisData2PkAndMac, isWXDevicesResult } from '../utils';
4
-
5
- import {
6
- getBluetoothAdapterState,
7
- startBluetoothDevicesDiscovery,
8
- getBluetoothDevices,
9
- notifyBLECharacteristicValueChange,
10
- unpackWriteBLECharacteristicValue,
11
- getBLEDeviceServices,
12
- getBLEDeviceCharacteristics,
13
- retryConnect,
14
- } from '../wechatApi';
15
- import sleep from "../sleep";
16
- import ConfigBase from "./ConfigBase";
17
- import WifiConfig from "../protocol/WifiConfig";
18
- import GizLog from "../GizLog";
19
- import { BleHandle } from "../handler/ble";
20
-
21
- interface IArgs {
22
- bleDeviceId: string;
23
- arrayBuffer: ArrayBuffer;
24
- serviceUUIDSuffix?: string;
25
- characteristicUUIDSuffix?: string;
26
- bleHandle: BleHandle;
27
- }
28
-
29
- const configAck = '0000000303000002';
30
-
31
- export function sendBLEConfigCmd({
32
- bleDeviceId,
33
- arrayBuffer,
34
- serviceUUIDSuffix = 'fe60',
35
- characteristicUUIDSuffix = 'fe61',
36
- bleHandle
37
- }: IArgs) {
38
- let sendInterval = null;
39
- let closeTimeout = null;
40
-
41
- const checkInterrupt = () => {
42
- if (closeTimeout === null) {
43
- sendInterval && clearInterval(sendInterval);
44
- return true;
45
- }
46
- return false;
47
- }
48
-
49
- return new Promise<boolean>(async (resolve, reject) => {
50
- try {
51
- GizLog.debug(
52
- 'GIZ_SDK: ssid info: ', arrayBuffer
53
- );
54
- // 设置超时
55
- closeTimeout = setTimeout(() => {
56
- sendInterval && clearInterval(sendInterval);
57
- // 发送超时 返回失败
58
- closeTimeout = null;
59
- resolve(false);
60
- }, 5 * 1000)
61
- GizLog.debug(
62
- 'GIZ_SDK: createBLEConnection start: ', bleDeviceId
63
- );
64
- await bleHandle.disableScan()
65
-
66
- const connectData = await retryConnect(bleDeviceId, 10 * 1000);
67
- bleHandle.enableScan();
68
-
69
- GizLog.debug(
70
- 'GIZ_SDK: createBLEConnection end, res:', connectData
71
- );
72
- const services = await getBLEDeviceServices(bleDeviceId);
73
- GizLog.debug(
74
- 'GIZ_SDK: getBLEDeviceServices end, res:', services
75
- );
76
- const service = services.find((s) =>
77
- s.uuid.split('-')[0].toLowerCase().endsWith(serviceUUIDSuffix)
78
- );
79
- if (!service) {
80
- // 获取蓝牙设备服务异常
81
- GizLog.debug(
82
- 'GIZ_SDK: get ble device services fail',
83
- bleDeviceId,
84
- services
85
- );
86
- resolve(false);
87
- return;
88
- }
89
-
90
- const characteristics = await getBLEDeviceCharacteristics(
91
- bleDeviceId,
92
- service.uuid
93
- );
94
- GizLog.debug(
95
- 'GIZ_SDK: getBLEDeviceCharacteristics end, res:', characteristics
96
- );
97
- const characteristic = characteristics.find((c) =>
98
- c.uuid.split('-')[0].toLowerCase().endsWith(characteristicUUIDSuffix)
99
- );
100
- if (!characteristic) {
101
- // 获取蓝牙设备特征值异常
102
- GizLog.debug(
103
- 'GIZ_SDK: get ble device characteristics fail',
104
- bleDeviceId,
105
- characteristics
106
- );
107
- resolve(false);
108
- return;
109
- }
110
-
111
- if (
112
- !characteristic.properties.notify &&
113
- !characteristic.properties.indicate
114
- ) {
115
- GizLog.debug(
116
- 'GIZ_SDK: the ble device characteristic not support notify or indicate',
117
- bleDeviceId,
118
- characteristic
119
- );
120
- // 该设备不支持 notify & indicate 操作
121
- resolve(false);
122
- return;
123
- }
124
-
125
- GizLog.debug(
126
- 'GIZ_SDK: check characteristic and service success',
127
- );
128
-
129
- await notifyBLECharacteristicValueChange(
130
- bleDeviceId,
131
- service.uuid,
132
- characteristic.uuid
133
- );
134
-
135
- // 这里有个问题,模组好像不一定每次都会回
136
- const handleBLECharacteristicValueChange = (res: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult) => {
137
- const hexString = ab2hex(res.value);
138
- GizLog.debug('GIZ_SDK: 收到设备返回ack', hexString)
139
- if (hexString === configAck) {
140
- // 发送成功
141
- bleHandle.removeEventListener("GizBleDeviceData", handleBLECharacteristicValueChange)
142
- resolve(true);
143
- }
144
- };
145
-
146
- bleHandle.addEventListener("GizBleDeviceData", handleBLECharacteristicValueChange)
147
-
148
- // 订阅特征值变化
149
- // wx.onBLECharacteristicValueChange(handleBLECharacteristicValueChange);
150
-
151
- GizLog.debug(
152
- 'GIZ_SDK: on notifyBLECharacteristicValueChange success',
153
- );
154
-
155
- if (checkInterrupt()) return;
156
-
157
- await unpackWriteBLECharacteristicValue(
158
- bleDeviceId,
159
- service.uuid,
160
- characteristic.uuid,
161
- arrayBuffer
162
- );
163
- sendInterval = setInterval(() => {
164
- if (checkInterrupt()) return;
165
- unpackWriteBLECharacteristicValue(
166
- bleDeviceId,
167
- service.uuid,
168
- characteristic.uuid,
169
- arrayBuffer
170
- );
171
- }, 2000)
172
-
173
- // if (res.errCode === 0) {
174
- // resolve(true);
175
- // } else{
176
- // resolve(false);
177
- // }
178
- GizLog.debug('GIZ_SDK: unpackWriteBLECharacteristicValue end');
179
- } catch (error) {
180
- reject(false);
181
- GizLog.debug('GIZ_SDK: sendBLEConfigCmd error', error);
182
- }
183
- })
184
- .catch((error) => {
185
- GizLog.debug('GIZ_SDK: sendBLEConfigCmd error', error);
186
- })
187
- .finally(() => {
188
- // 关闭连接
189
- closeTimeout && clearTimeout(closeTimeout);
190
- sendInterval && clearInterval(sendInterval);
191
- wx.closeBLEConnection({ deviceId: bleDeviceId });
192
- });
193
- }
194
-
195
- interface configBLEDeviceParams {
196
- ssid: string;
197
- password: string;
198
- softAPSSIDPrefix?: string;
199
- timeout: number;
200
- }
201
-
202
-
203
- interface ISetDeviceOnboardingDeployProps {
204
- timeout: number;
205
- isBind: boolean;
206
- softAPSSIDPrefix: string;
207
- }
208
-
209
-
210
- class BLEConfig extends ConfigBase {
211
- bleHandle: BleHandle;
212
-
213
- constructor(ssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[],bleHandle: BleHandle) {
214
- super(ssid,password,specialProductKeys,specialProductKeySecrets)
215
- this.bleHandle = bleHandle;
216
- }
217
- destroy = () => {
218
- this.cleanTimeout();
219
- }
220
- isValidBleDevice = (
221
- bleDevice: WechatMiniprogram.BlueToothDevice,
222
- softAPSSIDPrefix?: string
223
- ) => {
224
- if (!bleDevice || !bleDevice.advertisData) {
225
- // 无效蓝牙设备或者蓝牙设备广播数据为空,返回失败
226
- return false;
227
- }
228
-
229
- const {productKey, mac} = advertisData2PkAndMac(bleDevice.advertisData, this.specialProductKeys)
230
-
231
-
232
- if (!this.specialProductKeys.includes(productKey)) {
233
- // 不在PK列表
234
- return false;
235
- }
236
- GizLog.debug(`GIZ_SDK: isValidBleDevice mac: ${mac} pk: ${productKey} name: ${bleDevice.name}`)
237
- GizLog.debug(`GIZ_SDK: softAPSSIDPrefix: ${softAPSSIDPrefix} ismatch : ${bleDevice.name && bleDevice.name.startsWith(softAPSSIDPrefix)}`)
238
- return (
239
- !softAPSSIDPrefix ||
240
- (bleDevice.name && bleDevice.name.startsWith(softAPSSIDPrefix))
241
- );
242
- };
243
-
244
-
245
- enableBluetoothDevicesDescovery = async (): Promise<
246
- { success: false; err: IError } | { success: true }
247
- > => {
248
- // try {
249
- // await closeBluetoothAdapter();
250
- // await openBluetoothAdapter();
251
- // } catch (error) {
252
-
253
- // }
254
- const stateRes = await getBluetoothAdapterState();
255
- if (!stateRes.available) {
256
- return {
257
- success: false,
258
- err: {
259
- errorCode: errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON.errorCode,
260
- errorMessage: '蓝牙状态不可用',
261
- },
262
- };
263
- }
264
-
265
- await startBluetoothDevicesDiscovery();
266
- return { success: true };
267
- };
268
-
269
-
270
- enableAndGetBluetoothDevices = async (
271
- softAPSSIDPrefix?: string
272
- ): Promise<
273
- | { success: false; err: IError }
274
- | { success: true; bleDevices?: WechatMiniprogram.BlueToothDevice[] }
275
- > => {
276
- const discoveryRes = await this.enableBluetoothDevicesDescovery();
277
- if (!discoveryRes.success) {
278
- return discoveryRes;
279
- }
280
- GizLog.debug('GIZ_SDK: start enableAndGetBluetoothDevices');
281
-
282
- const bleDevices: WechatMiniprogram.BlueToothDevice[] = (
283
- await getBluetoothDevices()
284
- ).filter((d) => this.isValidBleDevice(d, softAPSSIDPrefix));
285
- GizLog.debug('GIZ_SDK: getBluetoothDevices success', bleDevices);
286
- return {
287
- success: true,
288
- bleDevices,
289
- };
290
- };
291
- setDeviceOnboardingDeploy = ({
292
- timeout,
293
- isBind = true,
294
- softAPSSIDPrefix,
295
- }: ISetDeviceOnboardingDeployProps) => {
296
- return new Promise<IResult<IDevice[]>>(async (res, rej) => {
297
- const ssid = this.ssid;
298
- const password = this.password;
299
- this.destroy();
300
- this.initDeviceOnboardingDeploy(res, rej);
301
- this.startTimeoutTimer(timeout);
302
- try {
303
- const result = await this.configBLEDevice({
304
- ssid,
305
- password,
306
- timeout: timeout * 1000,
307
- softAPSSIDPrefix,
308
- });
309
-
310
- const newData: IDevice[] = (result.data || []).map(item => {
311
- return {
312
- mac: item.mac,
313
- productKey: item.product_key,
314
- did: item.did,
315
- name: '',
316
- isBind: false,
317
- connectType: 'NONE',
318
- isBleOnline: false,
319
- isLanOnline: false,
320
- isOnline: false,
321
- }
322
- })
323
- if (isBind) {
324
- res(await this.bindDevices(newData));
325
- } else {
326
- // 不需要绑定 直接返回成功
327
- res({
328
- success: true,
329
- data: newData,
330
- });
331
- }
332
- } catch (error) {
333
- res({
334
- success: false,
335
- data: error
336
- });
337
- } finally {
338
- this.destroy();
339
- }
340
- });
341
- }
342
- /**
343
- * 负责发蓝牙设备指令
344
- */
345
- configBLEDevice = ({
346
- ssid,
347
- password,
348
- softAPSSIDPrefix,
349
- }: configBLEDeviceParams) => {
350
- return new Promise<IResult<IRandomCodesResult[]>>(async (res, rej) => {
351
- GizLog.debug('GIZ_SDK: start config ble device');
352
- const enableAndGetRes = await this.enableAndGetBluetoothDevices(
353
- softAPSSIDPrefix
354
- ).catch((error) => {
355
- return {
356
- success: false,
357
- err: {
358
- errorCode: errorCode.WECHAT_ERROR.errorCode,
359
- errorMessage: JSON.stringify(error),
360
- },
361
- };
362
- });
363
-
364
- if (!isWXDevicesResult(enableAndGetRes)) {
365
- // 开启获取蓝牙失败
366
- return rej(enableAndGetRes);
367
- }
368
-
369
- const { bleDevices } = enableAndGetRes;
370
-
371
- GizLog.debug('GIZ_SDK: enableAndGetBluetoothDevices success, target devices: ', bleDevices);
372
-
373
- const handleFoundDevices = async ({
374
- devices,
375
- }: {
376
- devices: WechatMiniprogram.BlueToothDevice[];
377
- }) => {
378
- this.hasTimeoutHandler()
379
- ? Array.prototype.push.apply(
380
- bleDevices,
381
- devices.filter((d) => this.isValidBleDevice(d, softAPSSIDPrefix))
382
- )
383
- : wx.offBluetoothDeviceFound(handleFoundDevices);
384
- };
385
-
386
- wx.onBluetoothDeviceFound(handleFoundDevices);
387
-
388
- const uint8Array = WifiConfig.pack(ssid,password);
389
- const startConfigDevice = async () => {
390
- GizLog.debug('GIZ_SDK: startConfigDevice');
391
- if (!this.hasTimeoutHandler()) {
392
- return;
393
- }
394
- const bleDevice = bleDevices.shift();
395
- if (bleDevice) {
396
- GizLog.debug('GIZ_SDK: startConfigDevice, target device: ', bleDevice);
397
- }
398
-
399
- const success =
400
- bleDevice &&
401
- (await sendBLEConfigCmd({
402
- bleDeviceId: bleDevice.deviceId,
403
- arrayBuffer: uint8Array.buffer,
404
- bleHandle: this.bleHandle
405
- }));
406
-
407
- if (!success) {
408
- // 如果校验设备或者发送不成功,重试下一个设备
409
- await sleep(500);
410
- await startBluetoothDevicesDiscovery();
411
- await startConfigDevice();
412
- return;
413
- }
414
-
415
- // 如果有一个设备发送成功,则不再发现新设备
416
- GizLog.debug("GIZ_SDK: offBluetoothDeviceFound ready search device")
417
- wx.offBluetoothDeviceFound(handleFoundDevices);
418
- };
419
-
420
- // 开始大循环搜索
421
- try {
422
- // const devicesReturn = await this.searchDevice({ ssid, password });
423
- this.searchDevice({ ssid, password }).then(devicesReturn => {
424
- res(devicesReturn);
425
- })
426
- } catch (error) {
427
- rej(error);
428
- GizLog.error("GIZ_SDK: searchDevice error", new Error(JSON.stringify(error)))
429
- }
430
-
431
- await startConfigDevice();
432
- });
433
- };
434
- }
435
-
436
- export default BLEConfig;