mini_program_gizwits_sdk 3.7.2-kuka → 3.7.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.
Files changed (138) hide show
  1. package/README.md +237 -23
  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 +4 -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 +79 -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/OTAStatus.d.ts +4 -0
  29. package/dist/src/protocol/OffLineData.d.ts +23 -0
  30. package/dist/src/protocol/ProtocolBase.d.ts +12 -0
  31. package/dist/src/protocol/Reset.d.ts +8 -0
  32. package/dist/src/protocol/SetReset.d.ts +7 -0
  33. package/dist/src/protocol/TransparentData.d.ts +12 -0
  34. package/dist/src/protocol/WifiConfig.d.ts +11 -0
  35. package/dist/src/protocol/dataPoint.d.ts +34 -0
  36. package/dist/src/protocol/tool.d.ts +14 -0
  37. package/dist/src/sdk.d.ts +158 -0
  38. package/dist/src/services/devices.d.ts +52 -0
  39. package/dist/src/services/login.d.ts +4 -0
  40. package/dist/src/services/monitor.d.ts +12 -0
  41. package/dist/src/services/ota.d.ts +7 -0
  42. package/dist/src/services/tool.d.ts +4 -0
  43. package/dist/src/services/uploadP0.d.ts +14 -0
  44. package/dist/src/types/index.d.ts +414 -0
  45. package/dist/src/types/otaStatus.d.ts +72 -0
  46. package/dist/src/utils/GizLog.d.ts +18 -0
  47. package/dist/src/utils/bleConfigLog.d.ts +11 -0
  48. package/dist/src/utils/connectedBssid.d.ts +6 -0
  49. package/dist/src/utils/errorCode.d.ts +3 -0
  50. package/dist/src/utils/globalData.d.ts +2 -0
  51. package/dist/src/utils/openApiRequest.d.ts +27 -0
  52. package/dist/src/utils/productConfigFileManage.d.ts +15 -0
  53. package/dist/src/utils/randomCode.d.ts +3 -0
  54. package/dist/src/utils/request.d.ts +1 -0
  55. package/dist/src/utils/sentry.d.ts +2 -0
  56. package/dist/src/utils/sleep.d.ts +2 -0
  57. package/dist/src/utils/utils.d.ts +55 -0
  58. package/dist/src/utils/wechatApi.d.ts +24 -0
  59. package/dist/src/utils/wifiConfigLogReport.d.ts +28 -0
  60. package/dist/src/wifiConfig/ConfigBase.d.ts +30 -0
  61. package/dist/src/wifiConfig/ap.d.ts +11 -0
  62. package/dist/src/wifiConfig/ble.d.ts +43 -0
  63. package/dist/src/wifiConfig/nfc/disposeData.d.ts +2 -0
  64. package/dist/src/wifiConfig/nfc/formatData.d.ts +3 -0
  65. package/dist/src/wifiConfig/nfc/formatSSID.d.ts +6 -0
  66. package/dist/src/wifiConfig/nfc/index.d.ts +22 -0
  67. package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +1 -0
  68. package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +6 -0
  69. package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +5 -0
  70. package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +1 -0
  71. package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +1 -0
  72. package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +2 -0
  73. package/dist/src/wifiConfig/nfc/types.d.ts +15 -0
  74. package/docs/ble-bssid.md +38 -0
  75. package/docs/ota-status.md +139 -0
  76. package/global.d.ts +3 -19
  77. package/package.json +13 -6
  78. package/.istanbul.yml +0 -4
  79. package/.travis.yml +0 -23
  80. package/.vscode/launch.json +0 -19
  81. package/.vscode/settings.json +0 -3
  82. package/src/GizLog.ts +0 -51
  83. package/src/aepApi/aepApiRequest.ts +0 -61
  84. package/src/crc/calculators/crc16modbus.ts +0 -36
  85. package/src/crc/calculators/crc32.ts +0 -47
  86. package/src/crc/crc16modbus.ts +0 -3
  87. package/src/crc/crc32.ts +0 -4
  88. package/src/crc/create_buffer.ts +0 -7
  89. package/src/crc/define_crc.ts +0 -9
  90. package/src/crc/index.ts +0 -10
  91. package/src/crc/package.json +0 -3
  92. package/src/errorCode.ts +0 -84
  93. package/src/global.d.ts +0 -53
  94. package/src/globalData.ts +0 -9
  95. package/src/handler/EventListener.ts +0 -44
  96. package/src/handler/ble.ts +0 -1485
  97. package/src/handler/lan.ts +0 -409
  98. package/src/handler/socket.ts +0 -625
  99. package/src/openApiRequest.ts +0 -62
  100. package/src/productConfigFileManage.ts +0 -58
  101. package/src/protocol/Bind.ts +0 -22
  102. package/src/protocol/DeviceInfo.ts +0 -36
  103. package/src/protocol/DiscoverUDP.ts +0 -80
  104. package/src/protocol/GetDeviceStatus.ts +0 -63
  105. package/src/protocol/Login.ts +0 -43
  106. package/src/protocol/Ntp.ts +0 -13
  107. package/src/protocol/OTA/AwaitNoti.ts +0 -14
  108. package/src/protocol/OTA/CheckCanOTA.ts +0 -23
  109. package/src/protocol/OTA/OTAPackPackage.ts +0 -36
  110. package/src/protocol/OTA/OtaComplete.ts +0 -17
  111. package/src/protocol/OTA/PreOTA.ts +0 -47
  112. package/src/protocol/OTA/ResetPosition.ts +0 -14
  113. package/src/protocol/OffLineData.ts +0 -81
  114. package/src/protocol/ProtocolBase.ts +0 -54
  115. package/src/protocol/Reset.ts +0 -15
  116. package/src/protocol/SetReset.ts +0 -11
  117. package/src/protocol/WifiConfig.ts +0 -42
  118. package/src/protocol/dataPoint.ts +0 -769
  119. package/src/protocol/thirdProtocol/YunZhiMianBleProtocolBase.ts +0 -39
  120. package/src/protocol/tool.ts +0 -147
  121. package/src/randomCode.ts +0 -36
  122. package/src/request.ts +0 -22
  123. package/src/sdk.ts +0 -1472
  124. package/src/sentry.ts +0 -55
  125. package/src/services/devices.ts +0 -309
  126. package/src/services/login.ts +0 -15
  127. package/src/services/ota.ts +0 -30
  128. package/src/services/tool.ts +0 -10
  129. package/src/services/uploadP0.ts +0 -56
  130. package/src/sleep.ts +0 -2
  131. package/src/types/index.ts +0 -48
  132. package/src/utils.ts +0 -419
  133. package/src/wechatApi.ts +0 -268
  134. package/src/wifiConfig/ConfigBase.ts +0 -185
  135. package/src/wifiConfig/ap.ts +0 -192
  136. package/src/wifiConfig/ble.ts +0 -436
  137. package/src/wifiConfig/ble_ailCloud.ts +0 -554
  138. package/yarn-error.log +0 -6901
@@ -0,0 +1,28 @@
1
+ import { AppInfo, MobileInfo, WifiConfigLog } from "../types";
2
+ declare class WifiConfigLogReport {
3
+ isSuccess: boolean;
4
+ ssid: string;
5
+ mode: number;
6
+ timeout: number;
7
+ isBind: boolean;
8
+ mobileInfo: MobileInfo;
9
+ appInfo: AppInfo;
10
+ productKey: string;
11
+ logs: WifiConfigLog[];
12
+ constructor();
13
+ init: (data: {
14
+ productKey?: string;
15
+ ssid: string;
16
+ mode: number;
17
+ timeout: number;
18
+ isBind: boolean;
19
+ }) => void;
20
+ getEnv: () => void;
21
+ updateProductKey: (key: string) => void;
22
+ appendEvent: (log: WifiConfigLog) => void;
23
+ report: () => Promise<void>;
24
+ cancel: () => Promise<void>;
25
+ clean: () => void;
26
+ }
27
+ declare const _default: WifiConfigLogReport;
28
+ export default _default;
@@ -0,0 +1,30 @@
1
+ import { IRandomCodesResult, IRejectCallback, IResult, TimeoutHandle } from "../types";
2
+ import { ConfigEventData, ConfigStage, ConfigStatus, IDevice } from "../types";
3
+ declare class ConfigBase {
4
+ ssid: string;
5
+ bssid: string;
6
+ password: string;
7
+ specialProductKeys: string[];
8
+ disableSearchDevice: boolean;
9
+ specialProductKeySecrets: string[];
10
+ timeoutHandler: TimeoutHandle;
11
+ eventCallBack: (event: ConfigEventData) => void;
12
+ private readonly progressStartedAt;
13
+ protected emitConfigEvent(event: ConfigEventData, callback?: (event: ConfigEventData) => void): void;
14
+ protected progress(stage: ConfigStage, status: ConfigStatus, fields?: Partial<ConfigEventData>): void;
15
+ private setDeviceOnboardingDeployRej?;
16
+ constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[]);
17
+ cleanTimeout: () => void;
18
+ stopDeviceOnboardingDeploy: () => void;
19
+ appendExtendData: (key: string) => string;
20
+ hasTimeoutHandler: (cb?: IRejectCallback) => boolean;
21
+ handleTimeout: () => void;
22
+ protected searchDevice: ({ ssid, password }: {
23
+ ssid: string;
24
+ password: string;
25
+ }) => Promise<IResult<IRandomCodesResult[]>>;
26
+ initDeviceOnboardingDeploy: (_res: any, rej: any) => void;
27
+ protected startTimeoutTimer: (timeout: number) => void;
28
+ protected bindDevices: (devices: IDevice[]) => Promise<IResult<IDevice[]>>;
29
+ }
30
+ export default ConfigBase;
@@ -0,0 +1,11 @@
1
+ import { IDevice, IRandomCodesResult, IResult, configDeviceParams, ISetDeviceOnboardingDeployProps } from "../types";
2
+ import ConfigBase from "./ConfigBase";
3
+ declare class ApConfig extends ConfigBase {
4
+ disableSendUDP: boolean;
5
+ private sendMessageInterval;
6
+ private UDPSocketHandler;
7
+ destroy: () => void;
8
+ configDevice: ({ ssid, password, softAPSSIDPrefix }: configDeviceParams) => Promise<IResult<IRandomCodesResult[]>>;
9
+ setDeviceOnboardingDeploy: ({ timeout, isBind, productKey, softAPSSIDPrefix, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
10
+ }
11
+ export default ApConfig;
@@ -0,0 +1,43 @@
1
+ import { BleHandle } from "../handler/ble";
2
+ import ConfigBase from "./ConfigBase";
3
+ import { IDevice, IError, ConfigEventData, IRandomCodesResult, IResult, configBLEDeviceParams } from "../types";
4
+ type EnableAndGetBluetoothDevicesRes = Promise<{
5
+ success: false;
6
+ err: IError;
7
+ } | {
8
+ success: true;
9
+ bleDevices?: IDevice[];
10
+ }>;
11
+ interface IArgs {
12
+ bleDeviceId: string;
13
+ arrayBuffer: ArrayBuffer;
14
+ usesBssid?: boolean;
15
+ serviceUUIDSuffix?: string;
16
+ characteristicUUIDSuffix?: string;
17
+ bleHandle: BleHandle;
18
+ eventCallBack?: (event: ConfigEventData) => void;
19
+ }
20
+ interface ISetDeviceOnboardingDeployProps {
21
+ timeout: number;
22
+ isBind: boolean;
23
+ softAPSSIDPrefix: string;
24
+ productKey?: string;
25
+ eventCallBack?: (event: ConfigEventData) => void;
26
+ }
27
+ declare class BLEConfig extends ConfigBase {
28
+ bleHandle: BleHandle;
29
+ constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[], bleHandle: BleHandle);
30
+ sendBLEConfigCmd: ({ bleDeviceId, arrayBuffer, usesBssid, serviceUUIDSuffix, characteristicUUIDSuffix, bleHandle, eventCallBack }: IArgs) => Promise<boolean | void>;
31
+ destroy: () => void;
32
+ isValidBleDevice: (device: IDevice, softAPSSIDPrefix?: string) => boolean;
33
+ enableBluetoothDevicesDescovery: () => Promise<{
34
+ success: false;
35
+ err: IError;
36
+ } | {
37
+ success: true;
38
+ }>;
39
+ enableAndGetBluetoothDevices: (softAPSSIDPrefix?: string) => EnableAndGetBluetoothDevicesRes;
40
+ setDeviceOnboardingDeploy: ({ timeout, isBind, softAPSSIDPrefix, productKey, eventCallBack, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
41
+ configBLEDevice: ({ ssid, password, softAPSSIDPrefix, }: configBLEDeviceParams) => Promise<IResult<IRandomCodesResult[]>>;
42
+ }
43
+ export default BLEConfig;
@@ -0,0 +1,2 @@
1
+ import { IDATA } from './types';
2
+ export declare const disposeData: (SSID: Uint8Array, isSSIDincludeCH: boolean, pwd: Uint8Array, passIP: Uint8Array, BSSID: Uint8Array) => IDATA;
@@ -0,0 +1,3 @@
1
+ type IType = 'BSSID' | 'pwd' | 'address';
2
+ export declare const formatData: (data: string, type: IType) => Uint8Array;
3
+ export {};
@@ -0,0 +1,6 @@
1
+ interface IExport {
2
+ SSIDTLV: any;
3
+ isSSIDIncludedCH: boolean;
4
+ }
5
+ export declare const formatSSID: (SSID: string) => IExport;
6
+ export {};
@@ -0,0 +1,22 @@
1
+ import ConfigBase from "../ConfigBase";
2
+ import { IDevice, IResult } from '../../types';
3
+ interface configDeviceParams {
4
+ ssid: string;
5
+ password: string;
6
+ bssid: string;
7
+ address: string;
8
+ }
9
+ interface ISetDeviceOnboardingDeployProps {
10
+ timeout: number;
11
+ isBind: boolean;
12
+ BSSID: string;
13
+ softAPSSIDPrefix: string;
14
+ }
15
+ declare class NFCConfig extends ConfigBase {
16
+ address: string;
17
+ constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[], address: string);
18
+ destroy: () => void;
19
+ configDevice: ({ ssid, password, bssid, address }: configDeviceParams) => Promise<IResult<import("../../types").IRandomCodesResult[]>>;
20
+ setDeviceOnboardingDeploy: ({ timeout, isBind, }: ISetDeviceOnboardingDeployProps) => Promise<IResult<IDevice[]>>;
21
+ }
22
+ export default NFCConfig;
@@ -0,0 +1 @@
1
+ export default function isIncludedCH(str: string): boolean;
@@ -0,0 +1,6 @@
1
+ type T = {
2
+ success: boolean;
3
+ nfcA: any;
4
+ };
5
+ export declare const nfcAConnect: (NFCAdapter: any) => Promise<T>;
6
+ export {};
@@ -0,0 +1,5 @@
1
+ type T = {
2
+ transceiveSuccess: boolean;
3
+ };
4
+ export declare const nfcATransceive: (nfcA: any, buffer: ArrayBuffer) => Promise<T>;
5
+ export {};
@@ -0,0 +1 @@
1
+ export declare const ssIDToASC: (SSID: string) => Uint8Array;
@@ -0,0 +1 @@
1
+ export default function stringToGbk(str: string): Uint8Array;
@@ -0,0 +1,2 @@
1
+ import { IDATA } from './types';
2
+ export declare const transceive: (DATA: IDATA) => void;
@@ -0,0 +1,15 @@
1
+ type PageStateProps = {
2
+ store: {};
3
+ };
4
+ interface WifiInfo {
5
+ SSID: string;
6
+ BSSID: string;
7
+ secure: boolean;
8
+ signalStrength: number;
9
+ frequency: number;
10
+ }
11
+ type IDATA = {
12
+ ArrayBuffer_sign: ArrayBuffer;
13
+ ArrayBuffer_others: ArrayBuffer;
14
+ };
15
+ export { PageStateProps, WifiInfo, IDATA };
@@ -0,0 +1,38 @@
1
+ # 蓝牙配网 BSSID
2
+
3
+ BLE 模式(`mode: 3`)会按设备广播状态的 bit 3 (`support5GConfig`) 选择协议。
4
+
5
+ - 未声明支持新版协议的设备:保持原来的 `0x0001` 报文,不调用 Wi-Fi 查询。
6
+ - 支持新版协议:优先使用调用方提供的有效 `bssid`;否则调用原生 `wx.startWifi`,成功后 `wx.getConnectedWifi({ partialInfo: false })`。
7
+ - 只有返回 SSID 与目标 SSID 完全一致时才使用当前 BSSID。查询不触发主动授权,不调用 `stopWifi`,不会关闭页面共享的 Wi-Fi 模块。
8
+ - 缺少 API、权限拒绝、查询失败、SSID 不同、BSSID 无效或占位地址、1.5 秒内无回调,均降级为原来的报文,继续配网。
9
+ - 有有效 BSSID 且设备支持时,使用与 App SDK 一致的 `0x0100` 报文:Unix 秒时间戳(大端)、SSID、去除冒号的 12 字符 BSSID、密码及原有扩展信息。字符串使用 UTF-8 字节长度。
10
+ - 新报文匹配 `0x0101` 且状态为 0 的 ACK;旧报文仍匹配 `0x0002`。使用 BLE 层拼接后的完整帧,避免超过单包大小的 ACK 被误判。
11
+ - `WIFI_CONFIG_PROTOCOL` 日志仅记录是否使用 BSSID 和获取/降级原因,不新增 BSSID 或密码日志。
12
+
13
+ SDK 内部自动获取,不需要调用方增加 BSSID 参数。本次仅修改 SDK 源码及构建产物,不自动修改其他小程序项目的依赖版本,也不发布 npm。
14
+
15
+ ## 验证
16
+
17
+ `npm run test:bssid` 覆盖协议字节、广播能力解析、回调式 Wi-Fi API、超时与迟到回调、降级及真实 BLE 配网流程的协议选择和 ACK 清理。
18
+
19
+ 真机验收需分别测试支持新版协议的设备和旧设备:同 SSID、不同 SSID、关闭 Wi-Fi、拒绝定位权限,以及 Android / iOS / HarmonyOS;获取不到 BSSID 时应仍能按原方式配网。
20
+
21
+ ## 真机查看日志
22
+
23
+ 测试工程已经通过 `src/utils/sdk.ts` 引用这个本地 SDK。重新编译并真机调试后,执行一次 BLE 配网,在控制台筛选 `[BLE_CONFIG]`。
24
+ 如果应用调整过 SDK 日志级别,在初始化后执行 `sdk.setLogLevel('info')`(也可以用 `'debug'`)。
25
+
26
+ - `bssid_lookup`:开始查询;超时上限为 1500 ms。
27
+ - `bssid_result`:`reason`、`hasBssid`、`ssidMatched`、耗时;失败时包含 `api`、`errCode`、`errno`(如有)。
28
+ - `protocol_selected`:设备的 `support5GConfig`、是否实际使用 BSSID、选择原因、命令和报文长度。
29
+ - `send_start` / `write_result` / `write_retry`:实际请求命令、首次写入返回及重发次数。
30
+ - `ack_received`:收到的命令、状态(新版 ACK)、期望命令、`accepted` 是否通过 ACK 校验。
31
+ - `ack_timeout`:等待 ACK 超时和写入次数。
32
+ - `send_end`:是否收到有效 ACK、耗时,以及 SDK 主动请求断开连接。
33
+
34
+ 典型成功路径:`bssid_result` 的 `reason=current_wifi`、`hasBssid=true` → `protocol_selected` 的 `command=0x0100`、`usesBssid=true` → `ack_received` 的 `command=0x0101`、`state=0`、`accepted=true`。
35
+
36
+ 降级路径:`hasBssid=false` 或设备不支持新版协议 → `command=0x0001`、`usesBssid=false` → 期望 ACK 为 `0x0002`。降级本身不是配网失败。
37
+
38
+ 新日志不打印 SSID、完整 BSSID、密码或完整配网报文。`accepted=true` 只表示配置 ACK 校验通过,不代表设备已经联网成功。
@@ -0,0 +1,139 @@
1
+ # OTA 状态回调与查询
2
+
3
+ 本接口实现 OTA 状态扩展 v1:设备以 `0x15` 上报完整快照,应用以 `0x16` 查询当前状态。它们是独立的数据点业务命令,不嵌套在 `sendTransparentData` 的 `0x05` 内,也不是 `GizDeviceTransparentData` 的 `0x06` 载荷。
4
+
5
+ **设备是否支持、是否查询、是否展示,由应用层判断。** SDK 不检查型号或版本、不自动查询或轮询、不启动升级、不缓存上次任务结果。原有 `startUpgrade`、透传接口和事件仍可使用。
6
+
7
+ ## 接入示例
8
+
9
+ ```ts
10
+ import GizwitsMiniSDK, {
11
+ OTAStatusType,
12
+ OTAStatusState,
13
+ OTAStatusReason,
14
+ } from 'mini_program_gizwits_sdk';
15
+ import type { IDevice, OTAStatusEvent } from 'mini_program_gizwits_sdk';
16
+
17
+ // sdk 已初始化,device 已通过现有 subscribe 接口完成订阅。
18
+ // supportsOTAStatus 来自应用自己的产品配置 / 能力信息。
19
+ async function enterOTAPage(sdk: GizwitsMiniSDK, device: IDevice, supportsOTAStatus: boolean) {
20
+ if (!supportsOTAStatus) return () => {};
21
+
22
+ const sdid = 0; // 本机;代理子设备时使用中控 device + 子设备 SDID
23
+ const otaType = OTAStatusType.MCU;
24
+ const stop = sdk.onOTAStatus((event: OTAStatusEvent) => {
25
+ if (event.device.mac !== device.mac || event.device.productKey !== device.productKey
26
+ || event.sdid !== sdid || event.otaType !== otaType) return;
27
+
28
+ // null 表示无可展示的进度,不能当作 0% 或 255%。
29
+ console.log(event.progress, OTAStatusState[event.state]);
30
+ if (event.state === OTAStatusState.FAILED || event.state === OTAStatusState.UNAVAILABLE) {
31
+ console.log(OTAStatusReason[event.reason]);
32
+ }
33
+ // IDLE 仅表示当前无任务;应用应通过现有版本接口确认升级结果。
34
+ });
35
+
36
+ const sent = await sdk.queryOTAStatus(device, { otaType, sdid });
37
+ if (!sent.success) console.warn('查询发送失败', sent.message);
38
+ // 页面退出时调用 stop()。发送成功后若无回调,由应用决定等待时长和提示方式。
39
+ return stop;
40
+ }
41
+ ```
42
+
43
+ 先监听,再查询。重新进入页面可查询一次,不需要应用持续轮询。也可使用通用事件接口:
44
+
45
+ ```ts
46
+ await sdk.addEventListener('GizDeviceOTAStatus', callback);
47
+ sdk.removeEventListener('GizDeviceOTAStatus', callback);
48
+ ```
49
+
50
+ `onOTAStatus(callback)` 返回取消监听函数。两种注册方式是同一个事件,无需重复注册;监听范围为 SDK 收到的所有设备,应用按外层设备、`sdid`、`otaType` 筛选。没有监听时不启用 OTA 事件分流。
51
+
52
+ ## 查询接口
53
+
54
+ `queryOTAStatus(device, { otaType, sdid? }): Promise<ISDKResult<void>>`
55
+
56
+ | 参数 | 说明 |
57
+ | --- | --- |
58
+ | `device` | 已订阅设备,至少包含 `mac`、`productKey`;SDK 使用当前路由 |
59
+ | `otaType` | `OTAStatusType.MODULE = 1`、`MCU = 2`、`VOICE = 3`,必填 |
60
+ | `sdid` | 默认 `0` 本机;子设备为 `1–0x7fffffff`;不支持 GroupID |
61
+
62
+ 返回值仅表示链路发送 / 云端请求结果,**不是 OTA 查询结果,也不是设备支持证明**。真正的状态通过 `onOTAStatus` 返回;传输层 `0x0094` ACK 不触发状态回调。无响应也不能直接推断空闲或升级失败。协议无任务 ID,SDK 不把某条快照绑定到某次查询 Promise。
63
+
64
+ 路由沿用 `writeRaw`:BLE 连接、LAN TCP、WAN;BLE 广播和无连接状态返回失败。LAN / BLE 封装完整 `0x0093` P0;WAN 沿用已有 WebSocket P0 发送方式,OpenAPI 回退发送 `Action + Payload`,查询不依赖产品数据点定义。WAN 上行兼容完整 P0 和 `Action + Payload` raw 数组,并保留原有 raw 通知。
65
+
66
+ 各设备必须在所选链路实现该扩展。当前固件协议规定 WiFi 本地 / 云端承载,SDK 的 BLE 编解码能力不代表所有 BLE 固件已支持;应用应依据产品能力选择。
67
+
68
+ ## 回调字段
69
+
70
+ | 字段 | 说明 |
71
+ | --- | --- |
72
+ | `device` | 外层设备;中控代理时为中控本身 |
73
+ | `version` | `1` |
74
+ | `sdid` | 本机 `0` 或子设备 ID;与云端 DID 字符串不同 |
75
+ | `otaType` | 被升级组件,见 `OTAStatusType`;不要复用旧 OTA 下载接口类型 |
76
+ | `state` | `OTAStatusState` |
77
+ | `progress` | 整体整数百分比,进行中 / 失败 `0–95`,成功 `100`;空闲 / 查询不可用为 `null` |
78
+ | `result` | `OTAStatusResult.NONE = 0`、`SUCCESS = 1`、`FAILURE = 2` |
79
+ | `reason` | `OTAStatusReason`,正常为 `NONE = 0` |
80
+
81
+ SDK 原样传递整体进度,不按阶段重新计算、不虚增、不跨任务强制递增。固件负责 MCU 两种模式及语音模组的进度计算。仅 `SUCCEEDED + SUCCESS + 100` 代表成功;任务结束后查询可能返回 `IDLE`,应用通过版本接口确认,不能把 `IDLE` 当作成功。
82
+
83
+ 设备负责普通进度变化至少 5 个百分点、最短间隔 5 秒、20 秒保活;状态变化、结束、查询响应可即时上报。SDK 不二次节流或去重,重复进度可能是保活。固件不能通信时,SDK 也不会合成保活或失败事件。
84
+
85
+ 解析器校验长度、版本、目标、枚举及状态 / 进度 / 结果 / 原因组合。未知版本、预留值、畸形报文、旧 `0x06` 透传和纯 ACK 不产生 OTA 状态回调。
86
+
87
+ ## 状态速查
88
+
89
+ | 值 | `OTAStatusState` | 含义 |
90
+ | --- | --- | --- |
91
+ | `00` | `IDLE` | 当前无任务 |
92
+ | `01` | `PREPARING` | 准备 / 预检查 |
93
+ | `02` | `DOWNLOADING` | 下载 / 接收固件 |
94
+ | `03` | `VERIFYING` | 校验中 |
95
+ | `04` | `VERIFIED` | 校验通过 |
96
+ | `05` | `INSTALLING` | 目标正在擦除 / 写入 / 应用固件 |
97
+ | `06` | `REBOOTING` | 等待重启 |
98
+ | `07` | `CONFIRMING` | 等待版本 / 启动确认,进度 95 |
99
+ | `08` | `SUCCEEDED` | 成功,进度 100 |
100
+ | `09` | `FAILED` | 升级失败,保留进度 |
101
+ | `0A` | `UNAVAILABLE` | 本次查询不可用,不代表 OTA 失败 |
102
+ | `0B` | `TRANSFERRING` | 完整缓存后向目标传输 |
103
+ | `0C` | `STREAMING` | MCU 边下边传 |
104
+
105
+ ## 原因速查
106
+
107
+ 以下数值均为十六进制,对应 `OTAStatusReason`。
108
+
109
+ | 值 | 枚举 | 含义 |
110
+ | --- | --- | --- |
111
+ | `0000` | `NONE` | 无异常 |
112
+ | `0001` | `UNKNOWN_ERROR` | 未分类失败 |
113
+ | `0002` | `INVALID_FIRMWARE_INFO` | 固件信息非法 |
114
+ | `0003` | `PRODUCT_MISMATCH` | 产品不匹配 |
115
+ | `0004` | `HARDWARE_MISMATCH` | 硬件不匹配 |
116
+ | `0005` | `VERSION_REJECTED` | 版本不允许升级 |
117
+ | `0006` | `INSUFFICIENT_STORAGE` | 存储不足 |
118
+ | `0007` | `POWER_NOT_READY` | 供电条件不满足 |
119
+ | `0008` | `DOWNLOAD_FAILED` | 下载失败 |
120
+ | `0009` | `DOWNLOAD_TIMEOUT` | 下载超时 |
121
+ | `000A` | `SIZE_MISMATCH` | 大小不匹配 |
122
+ | `000B` | `CHECKSUM_MISMATCH` | 校验和不匹配 |
123
+ | `000C` | `SIGNATURE_INVALID` | 签名无效 |
124
+ | `000D` | `IMAGE_PROCESS_FAILED` | 镜像处理失败 |
125
+ | `000E` | `FLASH_ERASE_FAILED` | 擦除失败 |
126
+ | `000F` | `FLASH_WRITE_FAILED` | 写入失败 |
127
+ | `0010` | `TARGET_COMMUNICATION_FAILED` | 与目标通信失败 |
128
+ | `0011` | `ACTIVATION_TIMEOUT` | 激活超时 |
129
+ | `0012` | `BOOT_CONFIRM_FAILED` | 启动确认失败 |
130
+ | `0013` | `ROLLED_BACK` | 已回滚 |
131
+ | `0014` | `CANCELLED` | 已取消 |
132
+ | `0015` | `INTERRUPTED` | 升级中断 |
133
+ | `0101` | `TARGET_NOT_FOUND` | 目标不存在 |
134
+ | `0102` | `OTA_TYPE_UNSUPPORTED` | 组件类型不支持 |
135
+ | `0103` | `TARGET_OFFLINE` | 目标离线 |
136
+ | `0104` | `QUERY_TIMEOUT` | 中控查询目标超时 |
137
+ | `0105` | `STATE_UNAVAILABLE` | 当前状态不可获取 |
138
+
139
+ 完整线协议见 [OTA 状态上报与查询](https://sdkdoc-protocol.iotsdk.com/protocol/datapoint/ota)。
package/global.d.ts CHANGED
@@ -6,23 +6,7 @@ declare namespace md5 {
6
6
 
7
7
  declare function md5(data: any): any;
8
8
 
9
- type TUtf8 = {
10
- toBytes: (data: any) => any
11
- }
12
-
13
- type TUtils = {
14
- utf8: TUtf8;
15
- }
16
-
17
- interface ecb {
18
- new(data: any): any;
19
- }
20
-
21
- type TModeOfOperation = {
22
- ecb: ecb;
23
- }
24
-
25
9
  declare namespace aesjs {
26
- const utils: TUtils;
27
- const ModeOfOperation: TModeOfOperation;
28
- }
10
+ const utils: any;
11
+ const ModeOfOperation: any;
12
+ }
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "mini_program_gizwits_sdk",
3
- "version": "3.7.2-kuka",
4
- "description": "bump sdk version",
3
+ "version": "3.7.2",
4
+ "description": "mini_program_gizwits_sdk",
5
5
  "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": ["dist", "README.md", "global.d.ts", "docs"],
6
8
  "scripts": {
9
+ "test:bssid": "mocha -r ts-node/register tests/bssid/*.spec.ts --timeout 5000",
7
10
  "test": "node_modules/mocha/bin/_mocha -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s",
8
11
  "testBle": "node_modules/mocha/bin/_mocha -r ts-node/register tests/utils/randomCode.spec.ts -file ./tests/setup-wx.js -timeout 60s",
9
- "build": "[ -d './dist' ] && rm -r ./dist; NODE_OPTIONS=--openssl-legacy-provider webpack",
12
+ "build": "rm -rf ./dist && tsc --emitDeclarationOnly && webpack",
13
+ "link:dev": "yarn link && webpack --watch --mode development --devtool source-map",
14
+ "test:ota-status": "mocha -r ts-node/register --file ./tests/setup-wx.js tests/protocol/otaStatus.spec.ts --timeout 5000",
15
+ "test:transparent": "mocha -r ts-node/register --file ./tests/setup-wx.js tests/protocol/transparentData.spec.ts tests/protocol/otaTransferLock.spec.ts --timeout 5000",
16
+ "pack:local": "npm run build && npm pack",
10
17
  "release": "npm run build && release-it",
11
18
  "cover": "istanbul cover node_modules/mocha/bin/_mocha -- -r ts-node/register tests/**/*.spec.ts -file ./tests/setup-wx.js -timeout 60s",
12
19
  "coveralls": "npm run cover -- --report lcovonly && cat ./coverage/lcov.info | coveralls"
@@ -31,13 +38,13 @@
31
38
  "chai": "^4.2.0",
32
39
  "coveralls": "^3.0.11",
33
40
  "istanbul": "^1.1.0-alpha.1",
34
- "miniprogram-api-typings": "^3.5.0",
41
+ "miniprogram-api-typings": "^4.1.2",
35
42
  "mocha": "^7.1.1",
36
43
  "release-it": "^14.2.2",
37
44
  "sinon": "^9.2.4",
38
45
  "ts-loader": "^6.2.2",
39
46
  "ts-node": "^8.8.1",
40
- "typescript": "^3.8.3",
47
+ "typescript": "^4.9.5",
41
48
  "uglifyjs-webpack-plugin": "^2.2.0",
42
49
  "webpack": "^4.42.1",
43
50
  "webpack-bundle-analyzer": "^4.5.0",
@@ -52,4 +59,4 @@
52
59
  "dependencies": {
53
60
  "crypto-js": "^4.1.1"
54
61
  }
55
- }
62
+ }
package/.istanbul.yml DELETED
@@ -1,4 +0,0 @@
1
- instrumentation:
2
- root: . # 执行的根目录
3
- extensions:
4
- - .ts # 检查覆盖率的文件扩张名
package/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - 10
4
- branches:
5
- only:
6
- - master
7
- install:
8
- - npm install
9
- script:
10
- - npm run test
11
- - npm run build
12
- after_success:
13
- - npm run coveralls
14
- deploy:
15
- provider: npm
16
- email: rbwang@gizwits.com
17
- api_key:
18
- secure: GrkNtVOo77beuB+ZyMWIeXQa2rYJtpstJYBX7aLQlg7Fb/yvlOywIARI+sW4RmvnrIOVYwVwhX24m9Jq2B/IU6ToiH5LNKeqLVeBaZmcYE2ribl3XkImzO6ZJLDEvMA7/cW8ZP6Pqm5rd1H5xHLYrwe6cwyp4S2LH8FF8scf3HVlDLlkpK+umMgep6nMgXSV0GVz0lrHfFEECvEY4UAuS/gZb9bPk8N8WMW8oqIZHP+yJ/floDopAAEJ+iCvl6SdykZjwmIQf0ZI/l6glgEUITGiai3CYkGcoyENm/itQC0y+wtZhjQmKyHI0zznwswnj33DE2kUla0BLu0P2mW78hlHEKwgdpvbZGlPnS94MTZ7qPkDtHwujJz7/oy54AiNR5LWYdUxLby7n495PKO+eJjYa/zuwjMRavLY86bZIsHTzHTjOVutD9IfsbyeAOSGeowuA3sw5n24R7CmG2oDCbGaQznXayWCcnZteJqLmFmY5B15v3QfcOM5dX/QqLUEZOy6l10bXXElnGqsWLs8Te2a6WeT5TmxqAKA+ljPMzcp7E2jIAiLny7EcRN7yxnTXVO8cVJ42MHlFX93TlFNJlWBi663dV2imb6xi2gK6m66OWgH7pfx32l8PhsAtv9mI43ADRWrRd7E5/jy1hgPbar6dDaDK4tR/gtunWh6KgQ=
19
- skip_cleanup: true
20
- on:
21
- branch: master
22
- tag: latest
23
- condition: "$TRAVIS_TAG =~ ^v[0-9]+.[0-9]+.[0-9]+$"
@@ -1,19 +0,0 @@
1
- {
2
- // 使用 IntelliSense 了解相关属性。
3
- // 悬停以查看现有属性的描述。
4
- // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "type": "node",
9
- "request": "launch",
10
- "name": "Mocha Tests",
11
- "url": "http://localhost:8080",
12
- "webRoot": "${workspaceFolder}",
13
- "skipFiles": [
14
- "<node_internals>/**"
15
- ],
16
- "program":"${workspaceFolder}/node_modules/mocha/bin/_mocha -r ts-node/register tests/bleConfig/sdk.ble.spec.ts -file ./tests/setup-wx.js -timeout 60s"
17
- }
18
- ]
19
- }
@@ -1,3 +0,0 @@
1
- {
2
- "mocha.enabled": true
3
- }
package/src/GizLog.ts DELETED
@@ -1,51 +0,0 @@
1
- import errorCode from './errorCode';
2
- import sentry from './sentry';
3
-
4
- export type TLogType = 'debug' | 'info' | 'warn' | 'error';
5
- class Log {
6
-
7
- logMap = [
8
- {id: 'debug'},
9
- {id: 'info'},
10
- {id: 'warn'},
11
- {id: 'error'}
12
- ]
13
-
14
- console = console
15
- // debug info(log) warn error
16
- debug = (...data)=> {
17
- this.console.debug(...data);
18
- }
19
- info = (...data) => {
20
- this.console.info(...data);
21
-
22
- }
23
- log = (...data) => {
24
- this.console.log(...data);
25
-
26
- }
27
- warn = (...data) => {
28
- this.console.warn(...data);
29
- }
30
- error = (info: string, error: Error) => {
31
- this.console.error(info, error);
32
- sentry(error)
33
- }
34
-
35
- setLogLevel = (type: TLogType) => {
36
- const targetIndex = this.logMap.findIndex(item => item.id === type);
37
- if (targetIndex !== -1) {
38
- this.console = {...console as any};
39
- this.logMap.map((item, index) => {
40
- if (index < targetIndex) {
41
- this.console[item.id] = () => {};
42
- }
43
- })
44
- return {success: true, err: null}
45
- } else {
46
- return {success: false,err: errorCode.GIZ_SDK_LOG_LEVEL_INVALID}
47
- }
48
- }
49
- }
50
-
51
- export default new Log();
@@ -1,61 +0,0 @@
1
- import request from '../request';
2
- import { getGlobalData } from '../globalData';
3
- import errorCode from '../errorCode';
4
- import GizLog from '../GizLog';
5
-
6
- interface IResult<T> {
7
- data: T;
8
- errMsg: string;
9
- statusCode: number;
10
- }
11
-
12
- export interface IServiceResult<T> {
13
- success: boolean;
14
- data?: T;
15
- err?: IError;
16
- }
17
-
18
- const aepApiRequest = async <T>(url: string, options: any, needToken: boolean = true): Promise<IServiceResult<T>> => {
19
- const requestOptions = { ...options };
20
- const headers: any = {
21
- 'Content-Type': 'application/json',
22
- 'X-Gizwits-Application-Id': getGlobalData('appID'),
23
- };
24
-
25
- if (needToken) {
26
- headers['Authorization'] = getGlobalData('token');
27
- }
28
-
29
- requestOptions.header = { ...headers, ...options.headers };
30
- delete requestOptions.headers;
31
- const aepApiUrl = getGlobalData('cloudServiceInfo').aepInfo;
32
- GizLog.debug('aepApiRequest', aepApiUrl + url);
33
- const res = await request<IResult<T>>(aepApiUrl + url, requestOptions);
34
- // 统一封装OPEN API的错误码
35
- if (res.statusCode >= 200 && res.statusCode < 300) {
36
- return {
37
- success: true,
38
- data: res.data,
39
- };
40
- }
41
-
42
- let baseError = {
43
- success: false,
44
- err: {
45
- errorCode: errorCode.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,
46
- errorMessage: '',
47
- },
48
- };
49
- try {
50
- baseError = {
51
- success: false,
52
- err: {
53
- errorCode: (res.data as any).error_code,
54
- errorMessage: (res.data as any).error_message,
55
- },
56
- };
57
- } catch (error) {}
58
- return baseError;
59
- };
60
-
61
- export default aepApiRequest;