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,389 +0,0 @@
1
- import GizLog from "../GizLog";
2
- import Bind from "../protocol/Bind";
3
- import DiscoverUDP from "../protocol/DiscoverUDP";
4
- import Login from "../protocol/Login";
5
- import ProtocolBase from "../protocol/ProtocolBase";
6
- import { arrayToUint8, hexStrint2byte } from "../protocol/tool";
7
- import sleep from "../sleep";
8
- import { IDevice, ILanDevice, IResult, LanConnectDevice, TLanHandleEvent } from "../types";
9
- import { ab2hex, ab2numbers } from "../utils";
10
- import EventListener from "./EventListener";
11
-
12
- export class LanHandle extends EventListener<TLanHandleEvent> {
13
- // private characteristicUUIDSuffix: string;
14
- public connectedList: LanConnectDevice[] = [];
15
- public pks: string[] = [];
16
- // private globalListenerMap = {};
17
- public scanList: ILanDevice[] = [];
18
-
19
- private boradcastTimer: any;
20
-
21
- private UDPSocket: WechatMiniprogram.UDPSocket;
22
-
23
- private deviceUDPPort = 12414
24
- private appUDPPort = 2415
25
- private offlineThreshold = 20000 // 超过20s 没有信号,则认为离线
26
- private isActive = true //当前是否是前台
27
-
28
- private listenDevOfflineTimer: any = null;
29
-
30
-
31
- constructor({pks}) {
32
- super();
33
- this.pks = pks;
34
- }
35
-
36
- init = () => {
37
- if (this.UDPSocket) {
38
- this.UDPSocket = wx.createUDPSocket();
39
- this.UDPSocket.bind();
40
- this.UDPSocket.onMessage(this.onMessage);
41
- this.UDPSocket.onError(this.onError);
42
- GizLog.info('Start UDP Discover')
43
- this.startDiscover();
44
- this.listenDevOffline(this.offlineThreshold);
45
- wx.onAppShow(this.onAppShow);
46
- wx.onAppHide(this.onAppHide);
47
- }
48
- }
49
-
50
- private onAppShow = () => {
51
- // 更新所有蓝牙设备的Ctime
52
- this.isActive = true;
53
- this.scanList.map(item => {
54
- item.ctime = Date.now();
55
- })
56
- }
57
-
58
- private onAppHide = () => {
59
- this.isActive = false;
60
- }
61
-
62
- private listenDevOffline = (offlineThreshold: number) => {
63
- // 定时检查设备列表,移除超时设备
64
- this.listenDevOfflineTimer = setInterval(() => {
65
- // 非激活状态不处理
66
- if (!this.isActive) return;
67
- const now = new Date().getTime();
68
- const newDeviceList = this.scanList.filter((d) => {
69
- return now - d.ctime < offlineThreshold;
70
- });
71
- if (newDeviceList.length !== this.scanList.length) {
72
- GizLog.debug('remove lan device')
73
- this.scanList = newDeviceList;
74
- this.notifyDevices();
75
- }
76
- }, 500);
77
- };
78
-
79
- private notifyDevices = () => {
80
- if (this.listenerMap['GizLanDeviceList']) {
81
- this.listenerMap['GizLanDeviceList'].map((item) => {
82
- item(this.scanList);
83
- });
84
- }
85
- }
86
- private notifyDeviceData = (mac: string, data: string) => {
87
- if (this.listenerMap['GizLanDeviceData']) {
88
- this.listenerMap['GizLanDeviceData'].map((item) => {
89
- item(mac, data);
90
- });
91
- }
92
- }
93
-
94
- isSameDevice = (deviceA: IDevice, deviceB: IDevice) => {
95
- return deviceA.mac === deviceB.mac && deviceA.productKey === deviceB.productKey
96
- }
97
-
98
- // 解除订阅
99
- disConnectDevice = (target: IDevice) => {
100
- const index = this.connectedList.findIndex(item => item.productKey === target.productKey && item.mac === target.mac);
101
- try {
102
- if (index !== -1) {
103
- // 删除这个设备
104
- this.connectedList[index].socketHandle.destory();
105
- this.connectedList.splice(index, 1);
106
- }
107
- return {success: true}
108
-
109
- } catch (error) {
110
- return {success: false, err: error}
111
- }
112
- }
113
-
114
- onData = (mac: string, hexString: string) => {
115
- this.notifyDeviceData(mac, hexString);
116
- }
117
-
118
- connectDevice = async (device) => {
119
- const target = this.scanList.find(item => this.isSameDevice(device, item));
120
- // 检查是否有连接
121
- if (!target) {
122
- return {
123
- success: false,
124
- }
125
- }
126
-
127
- const connectDevice = this.connectedList.find(item => this.isSameDevice(device, (item as unknown as IDevice)))
128
- if (connectDevice) {
129
- return {
130
- success: true
131
- }
132
- } else {
133
- const tcpHandler = new TCPHandler({ip: target.ip, mac: target.mac, productKey: target.productKey, onClose: this.onDeviceClose, onData: this.onData})
134
- const res = await tcpHandler.connect()
135
- if (res.success) {
136
- this.connectedList.push({
137
- mac: target.mac,
138
- productKey: target.productKey,
139
- socketHandle: tcpHandler,
140
- })
141
- } else {
142
- tcpHandler.destory();
143
- }
144
- return res;
145
- }
146
-
147
- }
148
-
149
- onError = (err) => {
150
- GizLog.warn('Discover Error', err)
151
- }
152
-
153
- isMatchPk = (pk) => {
154
- if (this.pks.length === 0 ) {
155
- return true
156
- } else {
157
- return this.pks.includes(pk)
158
- }
159
- }
160
-
161
- onMessage = (res: WechatMiniprogram.UDPSocketOnMessageListenerResult) => {
162
- const numberArrary = ab2numbers(res.message)
163
- const discoverPackage = new DiscoverUDP(numberArrary)
164
- if (discoverPackage.mac !== '' && this.isMatchPk(discoverPackage.productKey)) {
165
- // 合法设备
166
- // GizLog.debug("find device", discoverPackage)
167
- this.updateDevice(discoverPackage, res.remoteInfo.address)
168
- }
169
- }
170
-
171
- // tcp 设备断开连接
172
- onDeviceClose = ({productKey, mac}) => {
173
- const index = this.connectedList.findIndex(item => item.productKey === productKey && item.mac === mac);
174
- if (index !== -1) {
175
- // 删除这个设备
176
- this.connectedList.splice(index, 1);
177
- }
178
- }
179
-
180
- // 数据点控制
181
- public write = async (device: IDevice, value: ArrayBuffer) => {
182
- GizLog.debug('send data to device', device, value, this.connectedList)
183
- const index = this.connectedList.findIndex(item => this.isSameDevice(item as unknown as IDevice, device));
184
- if (index !== -1) {
185
- const socketHandle = this.connectedList[index].socketHandle;
186
- return socketHandle.write(value)
187
- }
188
- return {
189
- success: false,
190
- message: 'device not sub',
191
- };
192
- };
193
-
194
- updateDevice = (updateDevice: DiscoverUDP, ip: string) => {
195
- const target = this.scanList.find(item => item.mac === updateDevice.mac);
196
- if (!target) {
197
- const device: ILanDevice = {
198
- mac: updateDevice.mac,
199
- ip,
200
- productKey: updateDevice.productKey,
201
- did: updateDevice.did,
202
- expandData: updateDevice,
203
- name: "",
204
- isBind: false,
205
- localName: '',
206
- connectType: "NONE",
207
- isOnline: false,
208
- isLanOnline: true,
209
- isBleOnline: false,
210
- ctime: Date.now()
211
- };
212
- this.scanList.push(device);
213
- this.notifyDevices();
214
- } else {
215
- // 存在设备 更新字段
216
- target.ctime = Date.now()
217
- }
218
- }
219
-
220
- sendBoradCast = () => {
221
- // 发送发现包
222
- if(this.UDPSocket) {
223
- this.UDPSocket.send({
224
- address: '255.255.255.255',
225
- message: DiscoverUDP.pack(),
226
- port: this.deviceUDPPort
227
- })
228
- GizLog.debug('Send UDP Discover')
229
- }
230
- }
231
-
232
- private startDiscover = () => {
233
- this.sendBoradCast()
234
- this.boradcastTimer = setInterval(() => {
235
- this.sendBoradCast()
236
- }, 5000)
237
- }
238
-
239
- public destory = () => {
240
- this.boradcastTimer && clearInterval(this.boradcastTimer);
241
- this.UDPSocket && this.UDPSocket.close();
242
- this.listenDevOfflineTimer && clearInterval(this.listenDevOfflineTimer);
243
- wx.offAppShow(this.onAppShow);
244
- wx.offAppHide(this.onAppHide);
245
- }
246
- }
247
-
248
-
249
- interface ITCPHandlerProps {
250
- ip: string
251
- mac: string
252
- productKey: string
253
- onClose: (ip) => void
254
- onData: (mac: string, data: string) => void
255
- }
256
- export class TCPHandler {
257
- private deviceTCPPort = 12416
258
- private ip = ""
259
- private productKey = ""
260
- private mac = ""
261
- private tcpHandler: WechatMiniprogram.TCPSocket = null;
262
- private onData = (mac: string, data: string) => {}
263
-
264
- private onCloseListener = ({mac, productKey}) => {}
265
-
266
- constructor({ip, onClose, mac, productKey, onData}: ITCPHandlerProps) {
267
- this.ip = ip;
268
- this.mac = mac;
269
- this.productKey = productKey;
270
- this.onData = onData;
271
- this.onCloseListener = onClose;
272
- }
273
-
274
- connect = async () => {
275
- // 创建
276
- return new Promise<IResult<any>>(async (res) => {
277
- const onConnect = () => {
278
- // 发送绑定
279
- const config = Bind.pack()
280
- this.tcpHandler.write(arrayToUint8(config))
281
- GizLog.debug('connect success try login')
282
- }
283
- const onError = (err) => {
284
- res({
285
- success: true,
286
- err: err
287
- })
288
- }
289
- const onMessage = (message: WechatMiniprogram.TCPSocketOnMessageListenerResult) => {
290
- // 接收绑定回复
291
- // 然后再发起登录
292
- const baseProtocol = new ProtocolBase(ab2numbers(message.message))
293
- switch (baseProtocol.cmd) {
294
- case '0007': {
295
- // 绑定命令字的回复
296
- const bindRes = new Bind(ab2numbers(message.message));
297
- const loginPack = Login.pack({passcode: bindRes.passcode})
298
- this.tcpHandler.write(arrayToUint8(loginPack))
299
- break;
300
- }
301
- case '0009': {
302
- const loginRes = new Login(ab2numbers(message.message))
303
- if (loginRes.result) {
304
- // 登录成功
305
- res({
306
- success: true
307
- })
308
- // 创建监听
309
- this.initListener()
310
- } else {
311
- // 设备通知登录失败
312
- res({
313
- success: false,
314
- })
315
- }
316
- }
317
- }
318
- }
319
-
320
- try {
321
- this.tcpHandler = wx.createTCPSocket();
322
-
323
- // 设置监听
324
- this.tcpHandler.onConnect(onConnect)
325
- this.tcpHandler.onError(onError)
326
- this.tcpHandler.onMessage(onMessage)
327
-
328
- this.tcpHandler.connect({
329
- address: this.ip,
330
- port: this.deviceTCPPort,
331
- timeout: 2
332
- })
333
- await sleep(4000)
334
- res({
335
- success: false,
336
- err: null
337
- })
338
- } catch(err) {
339
- GizLog.error("connect lan error", err);
340
- res({
341
- success: false,
342
- err: null
343
- })
344
- } finally {
345
- this.tcpHandler.offConnect(onConnect)
346
- this.tcpHandler.offError(onError)
347
- this.tcpHandler.offMessage(onMessage)
348
- }
349
- })
350
-
351
- }
352
-
353
- write = (data: ArrayBuffer) => {
354
- this.tcpHandler.write(data);
355
- return {
356
- success: true
357
- }
358
- }
359
-
360
- onMessage = (message) => {
361
- try {
362
- const hexString = ab2hex(message.message);
363
- const baseProtocol = new ProtocolBase(hexStrint2byte(hexString))
364
- GizLog.debug("on tcp message", baseProtocol)
365
- this.onData(this.mac, hexString)
366
- } catch (error) {
367
-
368
- }
369
- }
370
-
371
- onError = () => {}
372
-
373
- onClose = () => {
374
- this.onCloseListener({productKey: this.productKey, mac: this.mac})
375
- }
376
-
377
- initListener = () => {
378
- this.tcpHandler.onError(this.onError)
379
- this.tcpHandler.onMessage(this.onMessage)
380
- this.tcpHandler.onClose(this.onClose)
381
- }
382
-
383
- destory = () => {
384
- this.tcpHandler && this.tcpHandler.close();
385
- this.tcpHandler.offError(this.onError)
386
- this.tcpHandler.offMessage(this.onMessage)
387
- this.tcpHandler.offClose(this.onClose)
388
- }
389
- }