mini_program_gizwits_sdk 3.4.1 → 3.4.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/src/sdk.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { TLogType } from './GizLog';
|
|
2
1
|
import { IDataPointConfig } from './protocol/DataPoint';
|
|
2
|
+
import { OTAEventCallback, OTAProgressEventCallback } from './handler/ble';
|
|
3
|
+
import { TLogType } from './GizLog';
|
|
3
4
|
import { IOpenApiDevice, ISafeRegisterReturn, IUnbindReturn } from './services/devices';
|
|
4
5
|
import { ILoginRes } from './services/login';
|
|
5
6
|
interface SyncCallBackParams {
|
|
@@ -171,6 +172,19 @@ declare class GizwitsMiniSDK {
|
|
|
171
172
|
success: boolean;
|
|
172
173
|
}>;
|
|
173
174
|
bindRemoteDevice: ({ mac, productKey, alias, beOwner, }: IBindRemoteDeviceParams) => Promise<ISDKResult<IOpenApiDevice>>;
|
|
175
|
+
checkUpdate: ({ device, type }: {
|
|
176
|
+
device: IDevice;
|
|
177
|
+
type: IOTAType;
|
|
178
|
+
}) => Promise<import("./openApiRequest").IServiceResult<import("./services/ota").OTARes>>;
|
|
179
|
+
getDeviceInfo: ({ device }: {
|
|
180
|
+
device: IDevice;
|
|
181
|
+
}) => Promise<IResult<import("./protocol/DeviceInfo").default>>;
|
|
182
|
+
startUpgrade: ({ device, type, onProgress, onEvent }: {
|
|
183
|
+
device: IDevice;
|
|
184
|
+
type: IOTAType;
|
|
185
|
+
onProgress: OTAProgressEventCallback;
|
|
186
|
+
onEvent: OTAEventCallback;
|
|
187
|
+
}) => Promise<import("./openApiRequest").IServiceResult<import("./services/ota").OTARes>>;
|
|
174
188
|
unbindDevice: ({ devices, }: {
|
|
175
189
|
devices: IDevice[];
|
|
176
190
|
}) => Promise<ISDKResult<IUnbindReturn>>;
|
package/package.json
CHANGED
package/src/handler/lan.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import GizLog from "../GizLog";
|
|
2
2
|
import Bind from "../protocol/Bind";
|
|
3
|
-
import DiscoverUDP from "../protocol/
|
|
3
|
+
import DiscoverUDP from "../protocol/DiscoverUDP";
|
|
4
4
|
import Login from "../protocol/Login";
|
|
5
5
|
import ProtocolBase from "../protocol/ProtocolBase";
|
|
6
6
|
import { arrayToUint8, hexStrint2byte } from "../protocol/tool";
|
package/src/sdk.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { getGlobalData, setGlobalData } from './globalData';
|
|
2
|
-
import { BleHandle } from './handler/ble';
|
|
3
|
-
import GizwitsWS from './handler/socket';
|
|
4
2
|
|
|
5
|
-
import { errorCode } from '..';
|
|
6
3
|
import sdkConfig from '../package.json';
|
|
7
|
-
import GizLog, { TLogType } from './GizLog';
|
|
8
4
|
import { LanHandle } from './handler/lan';
|
|
9
5
|
import productConfigFileManage from './productConfigFileManage';
|
|
10
6
|
import { formatEnum, IDataPointConfig, pack, unpack } from './protocol/DataPoint';
|
|
@@ -12,6 +8,14 @@ import Ntp from './protocol/Ntp';
|
|
|
12
8
|
import { CancelSync, DeletePackage, RequestSync, SyncPackage } from './protocol/OffLineData';
|
|
13
9
|
import ProtocolBase from './protocol/ProtocolBase';
|
|
14
10
|
import { arrayToString, hexStrint2byte } from './protocol/tool';
|
|
11
|
+
import { BleHandle, OTAEventCallback, OTAProgressEventCallback } from './handler/ble';
|
|
12
|
+
import GizwitsWS from './handler/socket';
|
|
13
|
+
import Reset from './protocol/Reset';
|
|
14
|
+
import SetReset from './protocol/SetReset';
|
|
15
|
+
|
|
16
|
+
import GizLog, { TLogType } from './GizLog';
|
|
17
|
+
import errorCode from './errorCode';
|
|
18
|
+
|
|
15
19
|
import {
|
|
16
20
|
bindMac,
|
|
17
21
|
editBindInfo,
|
|
@@ -454,6 +458,32 @@ class GizwitsMiniSDK {
|
|
|
454
458
|
}
|
|
455
459
|
break
|
|
456
460
|
}
|
|
461
|
+
case '0062': {
|
|
462
|
+
// 蓝牙重置命令,app代理设备进行重置
|
|
463
|
+
const resetInfo = new Reset(bleBytesData)
|
|
464
|
+
GizLog.debug("收到代理重置事件", resetInfo)
|
|
465
|
+
|
|
466
|
+
if (resetInfo.status === 1) {
|
|
467
|
+
// 需要重置
|
|
468
|
+
this.deviceSafetyApi({
|
|
469
|
+
mac: target.mac,
|
|
470
|
+
productKey: target.productKey,
|
|
471
|
+
isReset: true
|
|
472
|
+
}).then(async data => {
|
|
473
|
+
GizLog.debug("代理重置结果", data)
|
|
474
|
+
if (data.success && data.data.successDevices.length > 0) {
|
|
475
|
+
// 回写数据
|
|
476
|
+
GizLog.debug("重置成功,回写数据")
|
|
477
|
+
await this.bleHandle.write(curDevice.deviceId, numberArray2Uint8Array(SetReset.pack(0)).buffer)
|
|
478
|
+
}
|
|
479
|
+
})
|
|
480
|
+
}
|
|
481
|
+
break;
|
|
482
|
+
}
|
|
483
|
+
case '0064': {
|
|
484
|
+
// 回写重置结果ack,暂时先忽略
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
457
487
|
case '0072': {
|
|
458
488
|
// 设备回复是否允许同步数据
|
|
459
489
|
const requestSyncData = new RequestSync(bleBytesData)
|
|
@@ -1133,6 +1163,96 @@ class GizwitsMiniSDK {
|
|
|
1133
1163
|
};
|
|
1134
1164
|
};
|
|
1135
1165
|
|
|
1166
|
+
checkUpdate = async ({
|
|
1167
|
+
device, type
|
|
1168
|
+
}: {device: IDevice, type: IOTAType}) => {
|
|
1169
|
+
const target = this.allDevices.find((item) => isSameDevice(item, device));
|
|
1170
|
+
if (target) {
|
|
1171
|
+
if (!target.did) {
|
|
1172
|
+
// 设备没有绑定
|
|
1173
|
+
return {
|
|
1174
|
+
success: false,
|
|
1175
|
+
err: errorCode.GIZ_OPENAPI_DEVICE_NOT_BOUND,
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
switch(target.connectType) {
|
|
1179
|
+
case 'BLE': {
|
|
1180
|
+
return this.bleHandle.checkUpdate({device,type})
|
|
1181
|
+
}
|
|
1182
|
+
default: {
|
|
1183
|
+
return {
|
|
1184
|
+
success: false,
|
|
1185
|
+
err: errorCode.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT,
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return {
|
|
1191
|
+
success: false,
|
|
1192
|
+
err: errorCode.GIZ_SDK_DEVICE_NOT_SUBSCRIBED,
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
getDeviceInfo = async ({
|
|
1197
|
+
device
|
|
1198
|
+
}: {device: IDevice}) => {
|
|
1199
|
+
const target = this.allDevices.find((item) => isSameDevice(item, device));
|
|
1200
|
+
if (target) {
|
|
1201
|
+
if (!target.did) {
|
|
1202
|
+
// 设备没有绑定
|
|
1203
|
+
return {
|
|
1204
|
+
success: false,
|
|
1205
|
+
err: errorCode.GIZ_OPENAPI_DEVICE_NOT_BOUND,
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
switch(target.connectType) {
|
|
1209
|
+
case 'BLE': {
|
|
1210
|
+
return this.bleHandle.getDeviceInfo({deviceId: device.bleDeviceID})
|
|
1211
|
+
}
|
|
1212
|
+
default: {
|
|
1213
|
+
return {
|
|
1214
|
+
success: false,
|
|
1215
|
+
err: errorCode.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT,
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
return {
|
|
1221
|
+
success: false,
|
|
1222
|
+
err: errorCode.GIZ_SDK_DEVICE_NOT_SUBSCRIBED,
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
startUpgrade = async ({
|
|
1227
|
+
device, type, onProgress, onEvent
|
|
1228
|
+
}: {device: IDevice, type: IOTAType, onProgress: OTAProgressEventCallback, onEvent: OTAEventCallback}) => {
|
|
1229
|
+
const target = this.allDevices.find((item) => isSameDevice(item, device));
|
|
1230
|
+
if (target) {
|
|
1231
|
+
if (!target.did) {
|
|
1232
|
+
// 设备没有绑定
|
|
1233
|
+
return {
|
|
1234
|
+
success: false,
|
|
1235
|
+
err: errorCode.GIZ_OPENAPI_DEVICE_NOT_BOUND,
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
switch(target.connectType) {
|
|
1239
|
+
case 'BLE': {
|
|
1240
|
+
return this.bleHandle.startUpgrade({device,type, productKey: device.productKey, onProgress, onEvent})
|
|
1241
|
+
}
|
|
1242
|
+
default: {
|
|
1243
|
+
return {
|
|
1244
|
+
success: false,
|
|
1245
|
+
err: errorCode.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT,
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
return {
|
|
1251
|
+
success: false,
|
|
1252
|
+
err: errorCode.GIZ_SDK_DEVICE_NOT_SUBSCRIBED,
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1136
1256
|
unbindDevice = async ({
|
|
1137
1257
|
devices,
|
|
1138
1258
|
}: {
|
|
File without changes
|