mini_program_gizwits_sdk 3.2.30 → 3.2.32-FeiSiMan

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 (41) hide show
  1. package/dist/index.js +3 -3
  2. package/dist/src/aepApi/aepApiRequest.d.ts +7 -0
  3. package/dist/src/handler/ble.d.ts +5 -10
  4. package/dist/src/protocol/Reset.d.ts +8 -0
  5. package/dist/src/protocol/SetReset.d.ts +7 -0
  6. package/dist/src/sdk.d.ts +204 -0
  7. package/dist/src/wifiConfig/ConfigBase.d.ts +2 -1
  8. package/dist/src/wifiConfig/ble.d.ts +16 -3
  9. package/dist/src/wifiConfig/nfc/disposeData.d.ts +2 -0
  10. package/dist/src/wifiConfig/nfc/formatData.d.ts +3 -0
  11. package/dist/src/wifiConfig/nfc/formatSSID.d.ts +6 -0
  12. package/dist/src/wifiConfig/nfc/index.d.ts +22 -0
  13. package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +1 -0
  14. package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +6 -0
  15. package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +5 -0
  16. package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +1 -0
  17. package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +1 -0
  18. package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +2 -0
  19. package/dist/src/wifiConfig/nfc/types.d.ts +15 -0
  20. package/package.json +1 -1
  21. package/src/aepApi/aepApiRequest.ts +62 -0
  22. package/src/handler/ble.ts +32 -17
  23. package/src/protocol/Reset.ts +16 -0
  24. package/src/protocol/SetReset.ts +13 -0
  25. package/src/protocol/dataPoint.ts +18 -18
  26. package/src/sdk.ts +129 -36
  27. package/src/services/devices.ts +92 -4
  28. package/src/utils.ts +15 -5
  29. package/src/wifiConfig/ConfigBase.ts +3 -1
  30. package/src/wifiConfig/ble.ts +86 -26
  31. package/src/wifiConfig/nfc/disposeData.ts +63 -0
  32. package/src/wifiConfig/nfc/formatData.ts +46 -0
  33. package/src/wifiConfig/nfc/formatSSID.ts +59 -0
  34. package/src/wifiConfig/nfc/index.ts +136 -0
  35. package/src/wifiConfig/nfc/isIncludedCH.ts +8 -0
  36. package/src/wifiConfig/nfc/nfcAConnect.ts +30 -0
  37. package/src/wifiConfig/nfc/nfcATransceive.ts +29 -0
  38. package/src/wifiConfig/nfc/ssIDToASC.ts +12 -0
  39. package/src/wifiConfig/nfc/stringToGbk.ts +51 -0
  40. package/src/wifiConfig/nfc/transceive.wx.ts +124 -0
  41. package/src/wifiConfig/nfc/types.ts +18 -0
@@ -0,0 +1,124 @@
1
+ import { nfcAConnect } from './nfcAConnect';
2
+ import { nfcATransceive } from './nfcATransceive';
3
+ import { IDATA } from './types';
4
+
5
+ /**
6
+ * 向nfc芯片发送数据
7
+ * @param DATA 需要传输的DATA
8
+ */
9
+ export const transceive = (DATA: IDATA) => {
10
+ // NFCAdapter实例
11
+ const nfc = wx.getNFCAdapter();
12
+ nfc.startDiscovery();
13
+
14
+ // 监听nfc Tag
15
+ nfc.onDiscovered(async (techs) => {
16
+ console.log(techs, 'onDiscovered');
17
+ let allSuccess: boolean = true;
18
+ const { success, nfcA } = await nfcAConnect(nfc);
19
+ if (success) {
20
+ // 先发送SSID、PWD、PaaS IP、BSSID
21
+ const byteLength = DATA.ArrayBuffer_others.byteLength;
22
+ // @ts-ignore
23
+ const remainder = parseInt(byteLength % 4); // 余数
24
+ // @ts-ignore
25
+ const quotient = parseInt(byteLength / 4); // 商数
26
+ let temp_quo = quotient; // 用于计算blockID
27
+ const DATAUint8 = new Uint8Array(DATA.ArrayBuffer_others);
28
+
29
+ // 商数 - 写入数据
30
+ for (let i = 0; i <= quotient * 4 - 4; i += 4) {
31
+ if (temp_quo > 0) {
32
+ const buffer = new ArrayBuffer(6);
33
+ const uint8Array = new Uint8Array(buffer);
34
+ const blockID = 49 + quotient - temp_quo;
35
+ uint8Array[0] = parseInt('0xa2', 16);
36
+ uint8Array[1] = blockID;
37
+ uint8Array[2] = DATAUint8[0 + i];
38
+ uint8Array[3] = DATAUint8[1 + i];
39
+ uint8Array[4] = DATAUint8[2 + i];
40
+ uint8Array[5] = DATAUint8[3 + i];
41
+ const { transceiveSuccess } = await nfcATransceive(nfcA, buffer);
42
+ temp_quo -= 1;
43
+ if (!transceiveSuccess) {
44
+ // 某次写入失败
45
+ allSuccess = false;
46
+ wx.hideLoading();
47
+ wx.showToast({
48
+ title: 'NFC写入失败!',
49
+ icon: 'error',
50
+ duration: 2000,
51
+ });
52
+ break;
53
+ }
54
+ }
55
+
56
+ if (remainder !== 0 && allSuccess) {
57
+ // 余数 - 写入数据
58
+ const buffer = new ArrayBuffer(6);
59
+ const uint8Array = new Uint8Array(buffer);
60
+ const blockID = 49 + quotient;
61
+ uint8Array[0] = parseInt('0xa2', 16);
62
+ uint8Array[1] = blockID;
63
+ switch (remainder) {
64
+ case 1:
65
+ uint8Array[2] = DATAUint8[byteLength - 1];
66
+ break;
67
+ case 2:
68
+ uint8Array[2] = DATAUint8[byteLength - 2];
69
+ uint8Array[3] = DATAUint8[byteLength - 1];
70
+ break;
71
+ case 3:
72
+ uint8Array[2] = DATAUint8[byteLength - 3];
73
+ uint8Array[3] = DATAUint8[byteLength - 2];
74
+ uint8Array[4] = DATAUint8[byteLength - 1];
75
+ break;
76
+ }
77
+ const { transceiveSuccess } = await nfcATransceive(nfcA, buffer);
78
+ if (!transceiveSuccess) {
79
+ // 写入失败
80
+ wx.hideLoading();
81
+ wx.showToast({
82
+ title: 'NFC写入失败!',
83
+ icon: 'error',
84
+ duration: 2000,
85
+ });
86
+ }
87
+ }
88
+ }
89
+ // 再发送标志位数据: block30
90
+ const buffer = new ArrayBuffer(6);
91
+ const uint8Array = new Uint8Array(buffer);
92
+ const uint8Array_sign = new Uint8Array(DATA.ArrayBuffer_sign);
93
+ uint8Array[0] = parseInt('0xa2', 16);
94
+ uint8Array[1] = 48;
95
+ uint8Array[2] = uint8Array_sign[0];
96
+ uint8Array[3] = uint8Array_sign[1];
97
+ uint8Array[4] = uint8Array_sign[2];
98
+ uint8Array[5] = uint8Array_sign[3];
99
+ const { transceiveSuccess } = await nfcATransceive(nfcA, buffer);
100
+ wx.hideLoading();
101
+ wx.showToast(
102
+ transceiveSuccess
103
+ ? {
104
+ title: 'NFC写入成功!',
105
+ icon: 'success',
106
+ duration: 2000,
107
+ }
108
+ : {
109
+ title: 'NFC写入失败!',
110
+ icon: 'error',
111
+ duration: 2000,
112
+ }
113
+ );
114
+ nfcA.close();
115
+ } else {
116
+ wx.hideLoading();
117
+ wx.showToast({
118
+ title: 'NFC连接失败!',
119
+ icon: 'error',
120
+ duration: 2000,
121
+ });
122
+ }
123
+ });
124
+ };
@@ -0,0 +1,18 @@
1
+ type PageStateProps = {
2
+ store: {};
3
+ };
4
+
5
+ interface WifiInfo {
6
+ SSID: string;
7
+ BSSID: string;
8
+ secure: boolean;
9
+ signalStrength: number;
10
+ frequency: number;
11
+ }
12
+
13
+ type IDATA = {
14
+ ArrayBuffer_sign: ArrayBuffer;
15
+ ArrayBuffer_others: ArrayBuffer;
16
+ };
17
+
18
+ export { PageStateProps, WifiInfo, IDATA };