mini_program_gizwits_sdk 3.7.0-kuka → 3.7.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 (63) hide show
  1. package/README.md +96 -25
  2. package/{index.ts → dist/index.d.ts} +3 -3
  3. package/dist/index.js +5 -5
  4. package/global.d.ts +3 -19
  5. package/package.json +5 -5
  6. package/yarn-error.log +34 -34
  7. package/src/GizLog.ts +0 -51
  8. package/src/aepApi/aepApiRequest.ts +0 -61
  9. package/src/crc/calculators/crc16modbus.ts +0 -36
  10. package/src/crc/calculators/crc32.ts +0 -47
  11. package/src/crc/crc16modbus.ts +0 -3
  12. package/src/crc/crc32.ts +0 -4
  13. package/src/crc/create_buffer.ts +0 -7
  14. package/src/crc/define_crc.ts +0 -9
  15. package/src/crc/index.ts +0 -10
  16. package/src/crc/package.json +0 -3
  17. package/src/crc/types.ts +0 -10
  18. package/src/errorCode.ts +0 -84
  19. package/src/global.d.ts +0 -53
  20. package/src/globalData.ts +0 -9
  21. package/src/handler/EventListener.ts +0 -44
  22. package/src/handler/ble.ts +0 -1485
  23. package/src/handler/lan.ts +0 -409
  24. package/src/handler/socket.ts +0 -625
  25. package/src/openApiRequest.ts +0 -62
  26. package/src/productConfigFileManage.ts +0 -58
  27. package/src/protocol/Bind.ts +0 -22
  28. package/src/protocol/DeviceInfo.ts +0 -36
  29. package/src/protocol/DiscoverUDP.ts +0 -80
  30. package/src/protocol/GetDeviceStatus.ts +0 -63
  31. package/src/protocol/Login.ts +0 -43
  32. package/src/protocol/Ntp.ts +0 -13
  33. package/src/protocol/OTA/AwaitNoti.ts +0 -14
  34. package/src/protocol/OTA/CheckCanOTA.ts +0 -23
  35. package/src/protocol/OTA/OTAPackPackage.ts +0 -36
  36. package/src/protocol/OTA/OtaComplete.ts +0 -17
  37. package/src/protocol/OTA/PreOTA.ts +0 -47
  38. package/src/protocol/OTA/ResetPosition.ts +0 -14
  39. package/src/protocol/OffLineData.ts +0 -81
  40. package/src/protocol/ProtocolBase.ts +0 -54
  41. package/src/protocol/Reset.ts +0 -15
  42. package/src/protocol/SetReset.ts +0 -11
  43. package/src/protocol/WifiConfig.ts +0 -42
  44. package/src/protocol/dataPoint.ts +0 -769
  45. package/src/protocol/thirdProtocol/YunZhiMianBleProtocolBase.ts +0 -39
  46. package/src/protocol/tool.ts +0 -147
  47. package/src/randomCode.ts +0 -36
  48. package/src/request.ts +0 -22
  49. package/src/sdk.ts +0 -1472
  50. package/src/sentry.ts +0 -55
  51. package/src/services/devices.ts +0 -309
  52. package/src/services/login.ts +0 -15
  53. package/src/services/ota.ts +0 -30
  54. package/src/services/tool.ts +0 -10
  55. package/src/services/uploadP0.ts +0 -56
  56. package/src/sleep.ts +0 -2
  57. package/src/types/index.ts +0 -48
  58. package/src/utils.ts +0 -419
  59. package/src/wechatApi.ts +0 -210
  60. package/src/wifiConfig/ConfigBase.ts +0 -185
  61. package/src/wifiConfig/ap.ts +0 -192
  62. package/src/wifiConfig/ble.ts +0 -436
  63. package/src/wifiConfig/ble_ailCloud.ts +0 -554
@@ -1,185 +0,0 @@
1
- import { IRandomCodesResult, IResult, TimeoutHandle } from "../sdk";
2
- import sleep from "../sleep";
3
- import errorCode from "../errorCode";
4
- import { bindMac, checkDeviceRegister } from '../services/devices';
5
- import GizLog from "../GizLog";
6
-
7
- interface IRejectCallback {
8
- (result: IResult<unknown>): void;
9
- }
10
- class ConfigBase {
11
- ssid = '';
12
- password = '';
13
- specialProductKeys: string[] = [];
14
- disableSearchDevice = false;
15
- specialProductKeySecrets: string[] = []
16
- private timeoutHandler: TimeoutHandle = null;
17
- private setDeviceOnboardingDeployRej?: (value: unknown) => void = () => {}; // 保存promise的rej,用于临时中断
18
- // private setDeviceOnboardingDeployRes?: (value: unknown) => void = () => {}; // 保存promise的res,用于临时中断
19
-
20
- constructor(ssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[]) {
21
- this.ssid = ssid;
22
- this.password = password;
23
- this.specialProductKeys = specialProductKeys;
24
- this.specialProductKeySecrets = specialProductKeySecrets;
25
- }
26
-
27
- public cleanTimeout = () => {
28
- this.disableSearchDevice = true;
29
- this.timeoutHandler && clearTimeout(this.timeoutHandler);
30
- this.timeoutHandler = null;
31
- }
32
-
33
- stopDeviceOnboardingDeploy = (): void => {
34
- if (this.setDeviceOnboardingDeployRej) {
35
- this.setDeviceOnboardingDeployRej({
36
- success: false,
37
- err: errorCode.GIZ_SDK_ONBOARDING_STOPPED,
38
- });
39
- }
40
- this.cleanTimeout();
41
- };
42
-
43
- hasTimeoutHandler = (cb?: IRejectCallback) => {
44
- if (this.timeoutHandler) {
45
- // 方法还在执行中
46
- cb &&
47
- cb({
48
- success: false,
49
- err: errorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING,
50
- });
51
- return true;
52
- }
53
- return false;
54
- };
55
-
56
- handleTimeout = () => {
57
- if (this.setDeviceOnboardingDeployRej) {
58
- this.setDeviceOnboardingDeployRej({
59
- success: false,
60
- err: {
61
- errorCode: errorCode.CONFIG_TIME_OUT,
62
- errorMessage: 'time out',
63
- },
64
- });
65
- }
66
- this.timeoutHandler = null;
67
- }
68
-
69
- /**
70
- * 大循环确认
71
- */
72
- protected searchDevice = ({ ssid, password }: { ssid: string; password: string }) => {
73
- return new Promise<IResult<IRandomCodesResult[]>>((res, rej) => {
74
- GizLog.debug('GIZ_SDK: 开始大循环搜索设备')
75
- const query = async () => {
76
-
77
- if (!this.hasTimeoutHandler()) {
78
- return;
79
- }
80
-
81
- try {
82
- const data = await checkDeviceRegister({
83
- SSID: ssid,
84
- password,
85
- productKeys: this.specialProductKeys,
86
- })
87
-
88
- // GizLog.debug('GIZ_SDK: try get device random codes', data);
89
- if (data.err?.errorCode === errorCode.GIZ_OPENAPI_TOKEN_INVALID.errorCode) {
90
- // token 失效
91
- rej({
92
- success: false,
93
- err: errorCode.GIZ_OPENAPI_TOKEN_INVALID,
94
- });
95
- return;
96
- }
97
-
98
- if (data.err || (data.data as IRandomCodesResult[]).length === 0) {
99
- // 重新请求
100
- GizLog.debug('GIZ_SDK: 大循环没有发现设备');
101
- await sleep(1500);
102
- !this.disableSearchDevice && query();
103
- } else {
104
- // 搜索到设备
105
- GizLog.debug('GIZ_SDK: 大循环搜索到设备', data);
106
- res({
107
- success: true,
108
- data: data.data,
109
- });
110
- }
111
- } catch (error) {
112
- // 重新请求
113
- await sleep(3000);
114
- !this.disableSearchDevice && query();
115
- // GizLog.debug('GIZ_SDK: random codes error', error);
116
- }
117
- };
118
- query();
119
- });
120
- };
121
-
122
- initDeviceOnboardingDeploy = (_res, rej) => {
123
- // this.setDeviceOnboardingDeployRes = res;
124
-
125
- // 都用res 返回,不然外面需要trh
126
- this.setDeviceOnboardingDeployRej = _res;
127
- this.disableSearchDevice = false;
128
- };
129
-
130
- protected startTimeoutTimer = (timeout: number) => {
131
- /**
132
- * 设置超时时间
133
- */
134
- this.timeoutHandler = setTimeout(this.handleTimeout, timeout * 1000);
135
- };
136
-
137
- /**
138
- * 绑定多个设备
139
- */
140
- protected bindDevices = (devices: IDevice[]) => {
141
- GizLog.log('GIZ_SDK: start bind device');
142
- return new Promise<IResult<IDevice[]>>(async (res, rej) => {
143
- const promises = devices.map((item) => {
144
- const index = this.specialProductKeys.findIndex(
145
- (pk) => item.productKey === pk
146
- );
147
- if (index === -1) return;
148
- const ps = this.specialProductKeySecrets[index];
149
-
150
- return bindMac({
151
- mac: item.mac,
152
- productKey: item.productKey,
153
- productSecret: ps,
154
- })
155
- });
156
-
157
- try {
158
- const data = await Promise.all(promises);
159
- const successDevices = devices.filter((_, index) => {
160
- const item = data[index];
161
- return item && item.success;
162
- });
163
- if (successDevices.length > 0) {
164
- GizLog.log('GIZ_SDK: bind device success', successDevices);
165
- // 绑定成功,重新初始化socket
166
- res({
167
- success: true,
168
- data: successDevices,
169
- });
170
- } else {
171
- GizLog.log('GIZ_SDK: bind device error', data);
172
- rej({
173
- success: false,
174
- data: devices,
175
- err: errorCode.GIZ_SDK_BIND_DEVICE_FAILED,
176
- });
177
- }
178
- } catch (error) {
179
- rej(error);
180
- }
181
- });
182
- };
183
- }
184
-
185
- export default ConfigBase;
@@ -1,192 +0,0 @@
1
- import errorCode from "../errorCode";
2
- import GizLog from "../GizLog";
3
- import WifiConfig from "../protocol/WifiConfig";
4
- import { IRandomCodesResult, IResult, IntervalHandle } from "../sdk";
5
- import ConfigBase from "./ConfigBase";
6
-
7
-
8
- interface configDeviceParams {
9
- ssid: string;
10
- password: string;
11
- softAPSSIDPrefix: string;
12
- }
13
-
14
- interface ISetDeviceOnboardingDeployProps {
15
- timeout: number;
16
- isBind: boolean;
17
- softAPSSIDPrefix: string;
18
- }
19
- class ApConfig extends ConfigBase {
20
-
21
- disableSendUDP = false;
22
- private sendMessageInterval: IntervalHandle = null;
23
- private UDPSocketHandler: WechatMiniprogram.UDPSocket | null = null;
24
-
25
- destroy = () => {
26
- this.cleanTimeout();
27
- this.sendMessageInterval && clearInterval(this.sendMessageInterval);
28
- this.sendMessageInterval = null;
29
-
30
- if (this.UDPSocketHandler) {
31
- this.UDPSocketHandler.offError();
32
- this.UDPSocketHandler.offMessage();
33
- this.UDPSocketHandler.close();
34
- }
35
- }
36
-
37
- /**
38
- * 负责发指令
39
- */
40
- configDevice = ({ ssid, password, softAPSSIDPrefix }: configDeviceParams) => {
41
- return new Promise<IResult<IRandomCodesResult[]>>((res, rej) => {
42
- GizLog.debug('GIZ_SDK: start config device');
43
- let searchingDevice = false;
44
- let UDP_ERROR_NUM = 0;
45
- const uint8Array = WifiConfig.pack(ssid,password);
46
- /**
47
- * 连接socket 发送
48
- */
49
- this.UDPSocketHandler = wx.createUDPSocket();
50
- this.UDPSocketHandler.bind();
51
-
52
- this.disableSendUDP = false;
53
-
54
- /**
55
- * TODO
56
- * 收到设备回的包后终止
57
- * 或者超时
58
- * 或者成功
59
- */
60
- const sendMessage = () => {
61
- try {
62
- !this.disableSendUDP &&
63
- this.UDPSocketHandler!.send({
64
- address: '10.10.100.254',
65
- port: 12414,
66
- message: uint8Array,
67
- offset: 0,
68
- length: uint8Array.byteLength,
69
- });
70
- } catch (error) {
71
- }
72
- };
73
-
74
- // 执行
75
- this.sendMessageInterval = setInterval(() => {
76
- sendMessage();
77
- }, 2000);
78
-
79
- this.UDPSocketHandler.onError((data: any) => {
80
- UDP_ERROR_NUM += 1;
81
- // UDPSocketHandler.close();
82
- // 重试三次不行还是失败
83
- if (UDP_ERROR_NUM > 2) {
84
- this.destroy();
85
- rej({
86
- success: false,
87
- err: {
88
- errorCode: errorCode.WECHAT_ERROR.errorCode,
89
- errorMessage: data.errMsg,
90
- },
91
- });
92
- }
93
- });
94
-
95
- // 清理一些监听,调用搜索设备
96
- const searchDeviceHandle = async () => {
97
- if (searchingDevice) return;
98
- this.UDPSocketHandler!.offMessage();
99
- this.UDPSocketHandler!.offError();
100
- this.sendMessageInterval && clearInterval(this.sendMessageInterval);
101
- this.disableSendUDP = true;
102
- // 标记可以停止监听
103
- searchingDevice = true;
104
- // 关闭socket
105
- try {
106
- const devicesReturn = await this.searchDevice({ ssid, password });
107
- res(devicesReturn);
108
- } catch (error) {
109
- rej(error);
110
- }
111
- };
112
-
113
- this.UDPSocketHandler.onMessage((_data) => {
114
- // 收到回调 可以停止发包
115
- searchDeviceHandle();
116
- });
117
-
118
- // 没有收到udp回复的时候不进入配网
119
- wx.onNetworkStatusChange(async () => {
120
- // 发生网络切换的时候也停止发包,进入大循环配网
121
- // 搜索中的时候不要重复搜索
122
- !searchingDevice &&
123
- wx.getConnectedWifi({
124
- success: async (data) => {
125
- /**
126
- * 检查当前网络还是不是热点网络
127
- */
128
- data.wifi.SSID.indexOf(softAPSSIDPrefix) === -1 &&
129
- searchDeviceHandle();
130
- },
131
- });
132
- });
133
- });
134
- };
135
- /**
136
- * 配网接口
137
- * setDeviceOnboardingDeploy方法不可重复调用
138
- */
139
- setDeviceOnboardingDeploy = ({
140
- timeout,
141
- isBind = true,
142
- softAPSSIDPrefix,
143
- }: ISetDeviceOnboardingDeployProps) => {
144
- const ssid = this.ssid;
145
- const password = this.password;
146
- return new Promise<IResult<IDevice[]>>(async (res, rej) => {
147
- this.destroy();
148
- this.initDeviceOnboardingDeploy(res, rej);
149
- this.startTimeoutTimer(timeout);
150
-
151
- try {
152
- const result = await this.configDevice({
153
- ssid,
154
- password,
155
- softAPSSIDPrefix,
156
- });
157
- const newData: IDevice[] = (result.data || []).map(item => {
158
- return {
159
- mac: item.mac,
160
- productKey: item.product_key,
161
- did: item.did,
162
- name: '',
163
- isBind: false,
164
- connectType: 'NONE',
165
- isBleOnline: false,
166
- isLanOnline: false,
167
- isOnline: false,
168
- }
169
- })
170
- if (isBind) {
171
- try {
172
- res(await this.bindDevices(newData));
173
- } catch (error) {
174
- rej(error);
175
- }
176
- } else {
177
- // 不需要绑定 直接返回成功
178
- res({
179
- success: true,
180
- data: newData,
181
- });
182
- }
183
- } catch (error) {
184
- rej(error);
185
- } finally {
186
- this.destroy();
187
- }
188
- });
189
- };
190
- }
191
-
192
- export default ApConfig;