mini_program_gizwits_sdk 3.2.28 → 3.3.2
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.
- package/dist/index.js +3 -3
- package/dist/src/GizLog.d.ts +1 -1
- package/dist/src/handler/ble.d.ts +5 -24
- package/dist/src/handler/lan.d.ts +3 -3
- package/dist/src/handler/socket.d.ts +2 -2
- package/dist/src/productConfigFileManage.d.ts +1 -1
- package/dist/src/protocol/DataPoint.d.ts +5 -5
- package/dist/src/protocol/DiscoverUdp.d.ts +1 -1
- package/dist/src/protocol/Reset.d.ts +8 -0
- package/dist/src/protocol/SetReset.d.ts +7 -0
- package/dist/src/sdk.d.ts +212 -0
- package/dist/src/utils.d.ts +2 -2
- package/dist/src/wifiConfig/ble.d.ts +1 -1
- package/package.json +5 -5
- package/src/handler/ble.ts +117 -210
- package/src/handler/lan.ts +6 -6
- package/src/handler/socket.ts +5 -5
- package/src/openApiRequest.ts +4 -4
- package/src/protocol/Reset.ts +16 -0
- package/src/protocol/SetReset.ts +13 -0
- package/src/sdk.ts +58 -32
- package/src/services/devices.ts +92 -4
- package/src/wifiConfig/ble.ts +23 -17
- package/dist/src/services/monitor.d.ts +0 -11
- package/src/services/monitor.ts +0 -116
package/src/handler/ble.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import GizLog from '../GizLog';
|
|
2
|
-
import Bind from '../protocol/Bind';
|
|
3
|
-
import { padBoradcastData } from '../protocol/DataPoint';
|
|
4
|
-
import GetDeviceStatus from '../protocol/GetDeviceStatus';
|
|
5
|
-
import Login from '../protocol/Login';
|
|
6
|
-
import ProtocolBase from '../protocol/ProtocolBase';
|
|
7
|
-
import { hexStrint2byte } from '../protocol/tool';
|
|
8
|
-
import { reportEvent } from '../services/monitor';
|
|
9
|
-
import sleep from '../sleep';
|
|
10
1
|
import {
|
|
11
2
|
ab2hex,
|
|
12
3
|
ab2numbers,
|
|
@@ -15,14 +6,23 @@ import {
|
|
|
15
6
|
numberArray2Uint8Array,
|
|
16
7
|
parseBroadcastData,
|
|
17
8
|
unionBy,
|
|
18
|
-
wrapErrorInfo
|
|
9
|
+
wrapErrorInfo,
|
|
19
10
|
} from '../utils';
|
|
20
11
|
import { retryConnect, unpackWriteBLECharacteristicValue } from '../wechatApi';
|
|
12
|
+
import Bind from '../protocol/Bind';
|
|
13
|
+
import { hexStrint2byte } from '../protocol/tool';
|
|
14
|
+
import ProtocolBase from '../protocol/ProtocolBase';
|
|
15
|
+
import Login from '../protocol/Login';
|
|
16
|
+
import GetDeviceStatus from '../protocol/GetDeviceStatus';
|
|
17
|
+
import { padBoradcastData } from '../protocol/DataPoint';
|
|
18
|
+
import GizLog from '../GizLog';
|
|
21
19
|
import EventListener from './EventListener';
|
|
20
|
+
import sleep from '../sleep';
|
|
21
|
+
import Reset from '../protocol/Reset';
|
|
22
22
|
|
|
23
23
|
type GizBleDeviceListotifications = (devices: IDevice[]) => void;
|
|
24
24
|
type GizBleDeviceDataNotifications = (
|
|
25
|
-
curDevice: WechatMiniprogram.
|
|
25
|
+
curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult,
|
|
26
26
|
hexString: string
|
|
27
27
|
) => void;
|
|
28
28
|
type GizBleErrorNotifications = (err: { errCode: number; errMsg: string }) => void;
|
|
@@ -68,81 +68,13 @@ interface ConstructorParams {
|
|
|
68
68
|
offlineThreshold?: number;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
function createUUID32() {
|
|
72
|
-
let dt = new Date().getTime();
|
|
73
|
-
let uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
|
|
74
|
-
/[xy]/g,
|
|
75
|
-
function (c) {
|
|
76
|
-
let r = (dt + Math.random() * 16) % 16 | 0;
|
|
77
|
-
dt = Math.floor(dt / 16);
|
|
78
|
-
return (c == "x" ? r : (r & 0x3) | 0x8).toString(16);
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
return uuid;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function reportConnectingEvent(eventType: "BleDeviceConnectEnd" | "BleDeviceConnectBind" | "BleDeviceConnectLogin") {
|
|
85
|
-
return function (
|
|
86
|
-
target: any,
|
|
87
|
-
propertyName: string,
|
|
88
|
-
descriptor: TypedPropertyDescriptor<any>
|
|
89
|
-
|
|
90
|
-
) {
|
|
91
|
-
const { value: method } = descriptor;
|
|
92
|
-
descriptor.value = function (...args: any[]) {
|
|
93
|
-
const ret = method!.apply(this, args);
|
|
94
|
-
return ret.then(({ _failureType_, ...res }) => {
|
|
95
|
-
reportEvent({
|
|
96
|
-
device: args[0] as IDevice,
|
|
97
|
-
eventID: (this as unknown as any).__event_id__,
|
|
98
|
-
eventType,
|
|
99
|
-
success: res.success,
|
|
100
|
-
});
|
|
101
|
-
return {
|
|
102
|
-
...res,
|
|
103
|
-
_failureType_: eventType,
|
|
104
|
-
};
|
|
105
|
-
})
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function reportConnectEvent(
|
|
111
|
-
target: any,
|
|
112
|
-
propertyName: string,
|
|
113
|
-
descriptor: TypedPropertyDescriptor<any>
|
|
114
|
-
) {
|
|
115
|
-
const { value: method } = descriptor;
|
|
116
|
-
descriptor.value = function (...args: any[]) {
|
|
117
|
-
const that = Object.create(this);
|
|
118
|
-
that.__event_id__ = createUUID32();
|
|
119
|
-
reportEvent({
|
|
120
|
-
device: args[0] as IDevice,
|
|
121
|
-
eventID: that.__event_id__,
|
|
122
|
-
eventType: 'BleDeviceConnectStart',
|
|
123
|
-
success: true,
|
|
124
|
-
});
|
|
125
|
-
const ret = method!.apply(that, args);
|
|
126
|
-
return ret.then(({ _failureType_, ...res }) => {
|
|
127
|
-
reportEvent({
|
|
128
|
-
device: args[0] as IDevice,
|
|
129
|
-
eventID: that.__event_id__,
|
|
130
|
-
eventType: 'BleDeviceConnectFinish',
|
|
131
|
-
success: res.success,
|
|
132
|
-
...(res.success ? {} : { failureType: _failureType_ })
|
|
133
|
-
});
|
|
134
|
-
return res;
|
|
135
|
-
})
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
71
|
export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
140
72
|
private serviceUUIDSuffix: string;
|
|
141
73
|
// private characteristicUUIDSuffix: string;
|
|
142
74
|
public connectedList: ConnectDevice[] = [];
|
|
143
75
|
private connectingDevId: string | null = null;
|
|
144
76
|
public pks: string[] = [];
|
|
145
|
-
private listenDevOfflineTimer: any = null;
|
|
77
|
+
private listenDevOfflineTimer: any = null;
|
|
146
78
|
|
|
147
79
|
private boradcastTimer: any;
|
|
148
80
|
private boradcastDataCache: any = {}
|
|
@@ -189,14 +121,14 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
189
121
|
this.offlineThreshold = offlineThreshold;
|
|
190
122
|
this.listenDevOffline();
|
|
191
123
|
this.listenConnection();
|
|
192
|
-
|
|
124
|
+
|
|
193
125
|
wx.onAppShow(this.onAppShow);
|
|
194
126
|
wx.onAppHide(this.onAppHide);
|
|
195
127
|
|
|
196
128
|
wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)
|
|
197
129
|
}
|
|
198
130
|
|
|
199
|
-
private onBluetoothAdapterStateChange = (res: WechatMiniprogram.
|
|
131
|
+
private onBluetoothAdapterStateChange = (res: WechatMiniprogram.OnBluetoothAdapterStateChangeCallbackResult) => {
|
|
200
132
|
GizLog.debug("onBluetoothAdapterStateChange", res)
|
|
201
133
|
if (res.available) {
|
|
202
134
|
// this.startScan(() => {}, 4000);
|
|
@@ -219,7 +151,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
219
151
|
this.isActive = false;
|
|
220
152
|
}
|
|
221
153
|
|
|
222
|
-
|
|
154
|
+
|
|
223
155
|
private listenDevOffline = () => {
|
|
224
156
|
// 定时检查设备列表,移除超时设备
|
|
225
157
|
this.listenDevOfflineTimer = setInterval(() => {
|
|
@@ -248,6 +180,8 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
248
180
|
}, 500);
|
|
249
181
|
};
|
|
250
182
|
|
|
183
|
+
|
|
184
|
+
|
|
251
185
|
private openBluetoothAdapter = (mode: 'central' | 'peripheral' = 'central') => {
|
|
252
186
|
return new Promise((resolve, reject) => {
|
|
253
187
|
wx.openBluetoothAdapter({
|
|
@@ -268,7 +202,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
268
202
|
};
|
|
269
203
|
|
|
270
204
|
private handleOnBLECharacteristicValueChange = async (
|
|
271
|
-
curDevice: WechatMiniprogram.
|
|
205
|
+
curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult
|
|
272
206
|
) => {
|
|
273
207
|
// 不存在数据
|
|
274
208
|
if (!curDevice.value) {
|
|
@@ -304,7 +238,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
304
238
|
this.tmpDataNum = 0;
|
|
305
239
|
};
|
|
306
240
|
|
|
307
|
-
private notiDeviceDataToSdk = (curDevice: WechatMiniprogram.
|
|
241
|
+
private notiDeviceDataToSdk = (curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult, data: string) => {
|
|
308
242
|
if (this.listenerMap['GizBleDeviceData']) {
|
|
309
243
|
this.listenerMap['GizBleDeviceData'].map((item) => {
|
|
310
244
|
item(curDevice, data);
|
|
@@ -435,7 +369,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
435
369
|
private checkDeviceIsChange = (a: IDevice, b: IDevice) => {
|
|
436
370
|
//检查设备是否发生变更
|
|
437
371
|
|
|
438
|
-
if (a.bleWorkStatus !== b.bleWorkStatus ||
|
|
372
|
+
if (a.bleWorkStatus !== b.bleWorkStatus ||
|
|
439
373
|
a.name !== b.name ||
|
|
440
374
|
a.isBleOnline !== b.isBleOnline ||
|
|
441
375
|
a.isOnline !== b.isOnline
|
|
@@ -446,7 +380,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
446
380
|
}
|
|
447
381
|
|
|
448
382
|
private handleBluetoothDeviceFound = (
|
|
449
|
-
resData: WechatMiniprogram.
|
|
383
|
+
resData: WechatMiniprogram.OnBluetoothDeviceFoundCallbackResult,
|
|
450
384
|
onScanDevice: OnScanDevice
|
|
451
385
|
) => {
|
|
452
386
|
/**
|
|
@@ -585,136 +519,109 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
585
519
|
public enableScan = () => {
|
|
586
520
|
this.disableScanFlag = false;
|
|
587
521
|
}
|
|
522
|
+
|
|
588
523
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
try
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
524
|
+
public connectDevice = async (deviceId: string) => {
|
|
525
|
+
// 先锁定这个设备 防止被剔除
|
|
526
|
+
try{
|
|
527
|
+
this.connectingDevId = deviceId;
|
|
528
|
+
try {
|
|
529
|
+
// 连接前 先停止搜索
|
|
530
|
+
await this.disableScan();
|
|
531
|
+
const connectRes = await retryConnect(deviceId)
|
|
532
|
+
this.enableScan();
|
|
533
|
+
GizLog.debug("connect res", connectRes)
|
|
534
|
+
|
|
535
|
+
// if (connectRes && connectRes.errCode == 0 && connectRes.errMsg === 'createBLEConnection:ok') {
|
|
536
|
+
// this.listenConnection(deviceId);
|
|
537
|
+
// }
|
|
538
|
+
} catch (error) {
|
|
539
|
+
// 已经连接,继续往下走登录流程
|
|
540
|
+
GizLog.error('GIZ_SDK: createBLEConnection error', new Error(JSON.stringify(error)))
|
|
541
|
+
if (error?.errMsg !== 'createBLEConnection:fail:already connect') {
|
|
542
|
+
this.notifyError(error);
|
|
543
|
+
return { success: false, message: error?.errMsg };
|
|
544
|
+
}
|
|
545
|
+
|
|
607
546
|
}
|
|
547
|
+
|
|
548
|
+
const getServicesRes = (await wx
|
|
549
|
+
.getBLEDeviceServices({ deviceId })
|
|
550
|
+
.catch((err) => this.notifyError(err))) as any;
|
|
551
|
+
|
|
552
|
+
const serviceId = getServicesRes?.services.find(
|
|
553
|
+
(service) =>
|
|
554
|
+
service.isPrimary &&
|
|
555
|
+
service.uuid.toLowerCase().includes(this.serviceUUIDSuffix)
|
|
556
|
+
)?.uuid;
|
|
557
|
+
if (!serviceId) {
|
|
558
|
+
return {
|
|
559
|
+
message: 'can not find valid serviceId',
|
|
560
|
+
success: false,
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
|
|
608
564
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
const serviceId = getServicesRes?.services.find(
|
|
616
|
-
(service) =>
|
|
617
|
-
service.isPrimary &&
|
|
618
|
-
service.uuid.toLowerCase().includes(this.serviceUUIDSuffix)
|
|
619
|
-
)?.uuid;
|
|
620
|
-
if (!serviceId) {
|
|
621
|
-
return {
|
|
622
|
-
message: 'can not find valid serviceId',
|
|
623
|
-
success: false,
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
|
|
565
|
+
const getCharRes = (await wx
|
|
566
|
+
.getBLEDeviceCharacteristics({
|
|
567
|
+
deviceId,
|
|
568
|
+
serviceId,
|
|
569
|
+
})
|
|
570
|
+
.catch((err) => this.notifyError(err))) as any;
|
|
627
571
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
deviceId: device.bleDeviceID,
|
|
631
|
-
serviceId,
|
|
632
|
-
})
|
|
633
|
-
.catch((err) => this.notifyError(err))) as any;
|
|
572
|
+
const characteristicId = getCharRes?.characteristics[0].uuid!;
|
|
573
|
+
|
|
634
574
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
serviceId,
|
|
641
|
-
|
|
575
|
+
// 登录成功 把设备插入 connectedList
|
|
576
|
+
const isNewDevice = this.connectedList.every(
|
|
577
|
+
(device) => device.deviceId !== deviceId
|
|
578
|
+
);
|
|
579
|
+
isNewDevice &&
|
|
580
|
+
this.connectedList.push({ deviceId, serviceId, characteristicId });
|
|
581
|
+
|
|
582
|
+
// 连接成功以后默认监听设备
|
|
583
|
+
await wx
|
|
584
|
+
.notifyBLECharacteristicValueChange({
|
|
585
|
+
deviceId,
|
|
586
|
+
serviceId,
|
|
587
|
+
characteristicId,
|
|
588
|
+
state: true,
|
|
589
|
+
type: 'notification',
|
|
590
|
+
})
|
|
591
|
+
.catch((err) => this.notifyError(err));
|
|
592
|
+
|
|
593
|
+
this.write(deviceId, numberArray2Uint8Array(Bind.pack()).buffer);
|
|
594
|
+
const data = await this.handleBindReq(deviceId);
|
|
595
|
+
GizLog.log('handleBindReq', data);
|
|
596
|
+
|
|
597
|
+
if (data.success) {
|
|
598
|
+
this.write(
|
|
599
|
+
deviceId,
|
|
600
|
+
numberArray2Uint8Array(Login.pack({ passcode: data.data })).buffer
|
|
601
|
+
);
|
|
602
|
+
const loginData = (await this.handleLoginReq(deviceId).catch((err) =>
|
|
603
|
+
this.notifyError(err)
|
|
604
|
+
)) as any;
|
|
605
|
+
if (loginData?.success) {
|
|
606
|
+
|
|
607
|
+
// 登录成功后查询一下 重置状态
|
|
608
|
+
this.write(deviceId, numberArray2Uint8Array(Reset.pack()).buffer);
|
|
609
|
+
return {
|
|
610
|
+
success: true,
|
|
611
|
+
message: 'ok',
|
|
612
|
+
};
|
|
613
|
+
}
|
|
642
614
|
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
615
|
|
|
646
|
-
@reportConnectingEvent('BleDeviceConnectBind')
|
|
647
|
-
private async connectDeviceBindRequest(device: IDevice) {
|
|
648
|
-
this.write(device.bleDeviceID, numberArray2Uint8Array(Bind.pack()).buffer);
|
|
649
|
-
const data = await this.handleBindReq(device.bleDeviceID);
|
|
650
|
-
GizLog.log('handleBindReq', data);
|
|
651
|
-
if (!data.success) {
|
|
652
616
|
// 绑定失败,异常退出断开蓝牙
|
|
653
617
|
await wx.closeBLEConnection({
|
|
654
|
-
deviceId
|
|
618
|
+
deviceId,
|
|
655
619
|
});
|
|
656
|
-
}
|
|
657
|
-
return data;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
@reportConnectingEvent('BleDeviceConnectLogin')
|
|
661
|
-
private async connectDeviceLoginRequest(device: IDevice, passcode: string) {
|
|
662
|
-
this.write(
|
|
663
|
-
device.bleDeviceID,
|
|
664
|
-
numberArray2Uint8Array(Login.pack({ passcode })).buffer
|
|
665
|
-
);
|
|
666
|
-
const loginData = (await this.handleLoginReq(device.bleDeviceID).catch((err) =>
|
|
667
|
-
this.notifyError(err)
|
|
668
|
-
)) as any;
|
|
669
|
-
return {
|
|
670
|
-
success: !!loginData?.success,
|
|
671
|
-
message: 'ok',
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
620
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
return connectRet;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
const { serviceId, characteristicId } = connectRet.data;
|
|
683
|
-
|
|
684
|
-
// 登录成功 把设备插入 connectedList
|
|
685
|
-
const isNewDevice = this.connectedList.every(
|
|
686
|
-
(d) => d.deviceId !== device.bleDeviceID
|
|
687
|
-
);
|
|
688
|
-
isNewDevice &&
|
|
689
|
-
this.connectedList.push({ deviceId: device.bleDeviceID, serviceId, characteristicId });
|
|
690
|
-
|
|
691
|
-
// 连接成功以后默认监听设备
|
|
692
|
-
await wx
|
|
693
|
-
.notifyBLECharacteristicValueChange({
|
|
694
|
-
deviceId: device.bleDeviceID,
|
|
695
|
-
serviceId,
|
|
696
|
-
characteristicId,
|
|
697
|
-
state: true,
|
|
698
|
-
type: 'notification',
|
|
699
|
-
})
|
|
700
|
-
.catch((err) => this.notifyError(err));
|
|
701
|
-
|
|
702
|
-
const bindRet = await this.connectDeviceBindRequest(device);
|
|
703
|
-
|
|
704
|
-
if (!bindRet.success) {
|
|
705
|
-
return bindRet;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
const loginRet = await this.connectDeviceLoginRequest(device, bindRet.data);
|
|
709
|
-
return loginRet;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
public connectDevice = async (device: IDevice) => {
|
|
714
|
-
// 先锁定这个设备 防止被剔除
|
|
715
|
-
try {
|
|
716
|
-
this.connectingDevId = device.bleDeviceID;
|
|
717
|
-
return this._connectDevice(device);
|
|
621
|
+
return {
|
|
622
|
+
success: false,
|
|
623
|
+
message: 'ok',
|
|
624
|
+
};
|
|
718
625
|
} finally {
|
|
719
626
|
this.connectingDevId = null;
|
|
720
627
|
}
|
|
@@ -724,7 +631,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
724
631
|
// 处理设备回复绑定消息
|
|
725
632
|
return new Promise<IDeviceReq<string>>((res) => {
|
|
726
633
|
const onListener = (
|
|
727
|
-
_curDevice: WechatMiniprogram.
|
|
634
|
+
_curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult,
|
|
728
635
|
hexString: string
|
|
729
636
|
) => {
|
|
730
637
|
if (_curDevice.deviceId !== deviceId) {
|
|
@@ -754,7 +661,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
754
661
|
private handleLoginReq = (deviceId) => {
|
|
755
662
|
return new Promise<IDeviceReq<String>>((res) => {
|
|
756
663
|
const onListener = (
|
|
757
|
-
_curDevice: WechatMiniprogram.
|
|
664
|
+
_curDevice: WechatMiniprogram.OnBLECharacteristicValueChangeCallbackResult,
|
|
758
665
|
hexString: string
|
|
759
666
|
) => {
|
|
760
667
|
//TODO 销毁监听
|
|
@@ -839,7 +746,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
839
746
|
},
|
|
840
747
|
});
|
|
841
748
|
GizLog.debug("GIZ_SDK: start adv", serviceUuids)
|
|
842
|
-
|
|
749
|
+
|
|
843
750
|
this.boradcastTimer = setTimeout(() => {
|
|
844
751
|
this.peripheralServer.stopAdvertising({});
|
|
845
752
|
this.boradcastTimer = null;
|
|
@@ -856,7 +763,7 @@ export class BleHandle extends EventListener<TBleHandleEvent> {
|
|
|
856
763
|
};
|
|
857
764
|
}
|
|
858
765
|
|
|
859
|
-
|
|
766
|
+
|
|
860
767
|
|
|
861
768
|
}
|
|
862
769
|
|
package/src/handler/lan.ts
CHANGED
|
@@ -3,7 +3,7 @@ import Bind from "../protocol/Bind";
|
|
|
3
3
|
import DiscoverUDP from "../protocol/DiscoverUdp";
|
|
4
4
|
import Login from "../protocol/Login";
|
|
5
5
|
import ProtocolBase from "../protocol/ProtocolBase";
|
|
6
|
-
import { arrayToUint8, hexStrint2byte } from "../protocol/tool";
|
|
6
|
+
import { arrayToString, arrayToUint8, hexStrint2byte } from "../protocol/tool";
|
|
7
7
|
import { IResult } from "../sdk";
|
|
8
8
|
import sleep from "../sleep";
|
|
9
9
|
import { ab2hex, ab2numbers } from "../utils";
|
|
@@ -46,7 +46,7 @@ export class LanHandle extends EventListener<TLanHandleEvent> {
|
|
|
46
46
|
private offlineThreshold = 20000 // 超过20s 没有信号,则认为离线
|
|
47
47
|
private isActive = true //当前是否是前台
|
|
48
48
|
|
|
49
|
-
private listenDevOfflineTimer: any = null;
|
|
49
|
+
private listenDevOfflineTimer: any = null;
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
constructor({pks}) {
|
|
@@ -179,7 +179,7 @@ export class LanHandle extends EventListener<TLanHandleEvent> {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
onMessage = (res: WechatMiniprogram.
|
|
182
|
+
onMessage = (res: WechatMiniprogram.UDPSocketOnMessageCallbackResult) => {
|
|
183
183
|
const numberArrary = ab2numbers(res.message)
|
|
184
184
|
const discoverPackage = new DiscoverUDP(numberArrary)
|
|
185
185
|
if (discoverPackage.mac !== '' && this.isMatchPk(discoverPackage.productKey)) {
|
|
@@ -306,7 +306,7 @@ class TCPHandler {
|
|
|
306
306
|
err: err
|
|
307
307
|
})
|
|
308
308
|
}
|
|
309
|
-
const onMessage = (message: WechatMiniprogram.
|
|
309
|
+
const onMessage = (message: WechatMiniprogram.TCPSocketOnMessageCallbackResult) => {
|
|
310
310
|
// 接收绑定回复
|
|
311
311
|
// 然后再发起登录
|
|
312
312
|
const baseProtocol = new ProtocolBase(ab2numbers(message.message))
|
|
@@ -339,7 +339,7 @@ class TCPHandler {
|
|
|
339
339
|
|
|
340
340
|
try {
|
|
341
341
|
this.tcpHandler = wx.createTCPSocket();
|
|
342
|
-
|
|
342
|
+
|
|
343
343
|
// 设置监听
|
|
344
344
|
this.tcpHandler.onConnect(onConnect)
|
|
345
345
|
this.tcpHandler.onError(onError)
|
|
@@ -384,7 +384,7 @@ class TCPHandler {
|
|
|
384
384
|
GizLog.debug("on tcp message", baseProtocol)
|
|
385
385
|
this.onData(this.mac, hexString)
|
|
386
386
|
} catch (error) {
|
|
387
|
-
|
|
387
|
+
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
|
package/src/handler/socket.ts
CHANGED
|
@@ -348,7 +348,7 @@ export class Connection {
|
|
|
348
348
|
this.close();
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
-
_networkChange = async (res: WechatMiniprogram.
|
|
351
|
+
_networkChange = async (res: WechatMiniprogram.OnNetworkStatusChangeCallbackResult) => {
|
|
352
352
|
GizLog.log('network change', res);
|
|
353
353
|
// if (res.isConnected && !this._websocket) {
|
|
354
354
|
// // 网络断开重连
|
|
@@ -394,7 +394,7 @@ export class Connection {
|
|
|
394
394
|
}
|
|
395
395
|
}, 1000);
|
|
396
396
|
}
|
|
397
|
-
|
|
397
|
+
|
|
398
398
|
}
|
|
399
399
|
|
|
400
400
|
_subDevices = (dids: string[]) => {
|
|
@@ -443,12 +443,12 @@ export class Connection {
|
|
|
443
443
|
let success = false;
|
|
444
444
|
if (res.errMsg === "sendSocketMessage:ok") {
|
|
445
445
|
success = true
|
|
446
|
-
}
|
|
446
|
+
}
|
|
447
447
|
resolve({
|
|
448
448
|
success,
|
|
449
449
|
message: res.errMsg
|
|
450
450
|
})
|
|
451
|
-
|
|
451
|
+
|
|
452
452
|
},
|
|
453
453
|
fail: (e) => {
|
|
454
454
|
GizLog.error('GIZ_SDK: Socket send error', new Error(JSON.stringify(e)));
|
|
@@ -524,7 +524,7 @@ export class Connection {
|
|
|
524
524
|
_startPing = () => {
|
|
525
525
|
this._heartbeatTimerId = setInterval(() => {
|
|
526
526
|
this._send({ cmd: 'ping' });
|
|
527
|
-
|
|
527
|
+
|
|
528
528
|
}, this._heartbeatInterval * 1000);
|
|
529
529
|
}
|
|
530
530
|
|
package/src/openApiRequest.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import errorCode from './errorCode';
|
|
2
|
-
import { getGlobalData } from "./globalData";
|
|
3
1
|
import request from './request';
|
|
2
|
+
import { getGlobalData } from "./globalData";
|
|
3
|
+
import errorCode from './errorCode';
|
|
4
4
|
|
|
5
5
|
interface IResult<T> {
|
|
6
6
|
data: T;
|
|
@@ -54,9 +54,9 @@ const openApiRequest = async <T>(url: string, options: any, needToken: boolean =
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
} catch (error) {
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
}
|
|
59
59
|
return baseError;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export default openApiRequest;
|
|
62
|
+
export default openApiRequest;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ProtocolBase from "./ProtocolBase";
|
|
2
|
+
import { arrayToString } from "./tool";
|
|
3
|
+
|
|
4
|
+
type IStatus = 0 | 1;
|
|
5
|
+
class Reset extends ProtocolBase {
|
|
6
|
+
status: IStatus = 0; // 0 没有进入重置 1 进入了重置状态
|
|
7
|
+
constructor(data: number[]) {
|
|
8
|
+
super(data);
|
|
9
|
+
this.status = this.content[0] as IStatus;
|
|
10
|
+
}
|
|
11
|
+
static pack = () => {
|
|
12
|
+
return [0,0,0,3,3,0,0,0x61];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default Reset;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ProtocolBase from "./ProtocolBase";
|
|
2
|
+
import { arrayToString } from "./tool";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
type IStatus = 0 | 1;
|
|
6
|
+
class SetReset extends ProtocolBase {
|
|
7
|
+
status: IStatus = 0; // 0 没有进入重置 1 进入了重置状态
|
|
8
|
+
static pack = (status: IStatus) => {
|
|
9
|
+
return [0,0,0,3,3,0,0,0x63, status];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default SetReset;
|