mini_program_gizwits_sdk 3.6.4 → 3.6.5
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/package.json +1 -1
- package/yarn-error.log +6901 -0
- package/dist/src/GizLog.d.ts +0 -18
- package/dist/src/crc/calculators/crc16modbus.d.ts +0 -2
- package/dist/src/crc/calculators/crc32.d.ts +0 -2
- package/dist/src/crc/crc16modbus.d.ts +0 -7
- package/dist/src/crc/crc32.d.ts +0 -7
- package/dist/src/crc/create_buffer.d.ts +0 -3
- package/dist/src/crc/define_crc.d.ts +0 -7
- package/dist/src/crc/index.d.ts +0 -19
- package/dist/src/crc/types.d.ts +0 -11
- package/dist/src/errorCode.d.ts +0 -3
- package/dist/src/globalData.d.ts +0 -2
- package/dist/src/handler/EventListener.d.ts +0 -9
- package/dist/src/handler/ble.d.ts +0 -105
- package/dist/src/handler/lan.d.ts +0 -78
- package/dist/src/handler/socket.d.ts +0 -151
- package/dist/src/openApiRequest.d.ts +0 -3
- package/dist/src/productConfigFileManage.d.ts +0 -11
- package/dist/src/protocol/Bind.d.ts +0 -7
- package/dist/src/protocol/DeviceInfo.d.ts +0 -11
- package/dist/src/protocol/DiscoverUDP.d.ts +0 -17
- package/dist/src/protocol/GetDeviceStatus.d.ts +0 -5
- package/dist/src/protocol/Login.d.ts +0 -12
- package/dist/src/protocol/Ntp.d.ts +0 -5
- package/dist/src/protocol/OTA/AwaitNoti.d.ts +0 -7
- package/dist/src/protocol/OTA/CheckCanOTA.d.ts +0 -10
- package/dist/src/protocol/OTA/OTAPackPackage.d.ts +0 -8
- package/dist/src/protocol/OTA/OtaComplete.d.ts +0 -8
- package/dist/src/protocol/OTA/PreOTA.d.ts +0 -11
- package/dist/src/protocol/OTA/ResetPosition.d.ts +0 -6
- package/dist/src/protocol/OffLineData.d.ts +0 -23
- package/dist/src/protocol/ProtocolBase.d.ts +0 -11
- package/dist/src/protocol/Reset.d.ts +0 -8
- package/dist/src/protocol/SetReset.d.ts +0 -7
- package/dist/src/protocol/WifiConfig.d.ts +0 -6
- package/dist/src/protocol/dataPoint.d.ts +0 -34
- package/dist/src/protocol/tool.d.ts +0 -14
- package/dist/src/randomCode.d.ts +0 -3
- package/dist/src/request.d.ts +0 -1
- package/dist/src/sdk.d.ts +0 -136
- package/dist/src/sentry.d.ts +0 -2
- package/dist/src/services/devices.d.ts +0 -47
- package/dist/src/services/login.d.ts +0 -4
- package/dist/src/services/monitor.d.ts +0 -12
- package/dist/src/services/ota.d.ts +0 -7
- package/dist/src/services/tool.d.ts +0 -4
- package/dist/src/services/uploadP0.d.ts +0 -14
- package/dist/src/sleep.d.ts +0 -2
- package/dist/src/types/index.d.ts +0 -361
- package/dist/src/utils.d.ts +0 -46
- package/dist/src/wechatApi.d.ts +0 -19
- package/dist/src/wifiConfig/ConfigBase.d.ts +0 -27
- package/dist/src/wifiConfig/ap.d.ts +0 -11
- package/dist/src/wifiConfig/ble.d.ts +0 -41
- package/dist/src/wifiConfig/nfc/disposeData.d.ts +0 -2
- package/dist/src/wifiConfig/nfc/formatData.d.ts +0 -3
- package/dist/src/wifiConfig/nfc/formatSSID.d.ts +0 -6
- package/dist/src/wifiConfig/nfc/index.d.ts +0 -22
- package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +0 -1
- package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +0 -6
- package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +0 -5
- package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +0 -1
- package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +0 -1
- package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +0 -2
- package/dist/src/wifiConfig/nfc/types.d.ts +0 -15
- package/index.ts +0 -8
- package/src/GizLog.ts +0 -51
- package/src/crc/calculators/crc16modbus.ts +0 -36
- package/src/crc/calculators/crc32.ts +0 -47
- package/src/crc/crc16modbus.ts +0 -3
- package/src/crc/crc32.ts +0 -4
- package/src/crc/create_buffer.ts +0 -7
- package/src/crc/define_crc.ts +0 -9
- package/src/crc/index.ts +0 -10
- package/src/crc/package.json +0 -3
- package/src/crc/types.ts +0 -10
- package/src/errorCode.ts +0 -83
- package/src/globalData.ts +0 -9
- package/src/handler/EventListener.ts +0 -44
- package/src/handler/ble.ts +0 -1369
- package/src/handler/lan.ts +0 -389
- package/src/handler/socket.ts +0 -686
- package/src/openApiRequest.ts +0 -50
- package/src/productConfigFileManage.ts +0 -72
- package/src/protocol/Bind.ts +0 -22
- package/src/protocol/DeviceInfo.ts +0 -37
- package/src/protocol/DiscoverUDP.ts +0 -80
- package/src/protocol/GetDeviceStatus.ts +0 -61
- package/src/protocol/Login.ts +0 -43
- package/src/protocol/Ntp.ts +0 -13
- package/src/protocol/OTA/AwaitNoti.ts +0 -14
- package/src/protocol/OTA/CheckCanOTA.ts +0 -23
- package/src/protocol/OTA/OTAPackPackage.ts +0 -37
- package/src/protocol/OTA/OtaComplete.ts +0 -17
- package/src/protocol/OTA/PreOTA.ts +0 -48
- package/src/protocol/OTA/ResetPosition.ts +0 -14
- package/src/protocol/OffLineData.ts +0 -81
- package/src/protocol/ProtocolBase.ts +0 -54
- package/src/protocol/Reset.ts +0 -16
- package/src/protocol/SetReset.ts +0 -13
- package/src/protocol/WifiConfig.ts +0 -42
- package/src/protocol/dataPoint.ts +0 -687
- package/src/protocol/tool.ts +0 -140
- package/src/randomCode.ts +0 -25
- package/src/request.ts +0 -22
- package/src/sdk.ts +0 -1536
- package/src/sentry.ts +0 -55
- package/src/services/devices.ts +0 -313
- package/src/services/login.ts +0 -11
- package/src/services/monitor.ts +0 -117
- package/src/services/ota.ts +0 -17
- package/src/services/tool.ts +0 -10
- package/src/services/uploadP0.ts +0 -57
- package/src/sleep.ts +0 -2
- package/src/types/index.ts +0 -456
- package/src/utils.ts +0 -449
- package/src/wechatApi.ts +0 -211
- package/src/wifiConfig/ConfigBase.ts +0 -235
- package/src/wifiConfig/ap.ts +0 -185
- package/src/wifiConfig/ble.ts +0 -460
- package/src/wifiConfig/nfc/disposeData.ts +0 -63
- package/src/wifiConfig/nfc/formatData.ts +0 -46
- package/src/wifiConfig/nfc/formatSSID.ts +0 -59
- package/src/wifiConfig/nfc/index.ts +0 -134
- package/src/wifiConfig/nfc/isIncludedCH.ts +0 -8
- package/src/wifiConfig/nfc/nfcAConnect.ts +0 -30
- package/src/wifiConfig/nfc/nfcATransceive.ts +0 -29
- package/src/wifiConfig/nfc/ssIDToASC.ts +0 -12
- package/src/wifiConfig/nfc/stringToGbk.ts +0 -51
- package/src/wifiConfig/nfc/transceive.wx.ts +0 -124
- package/src/wifiConfig/nfc/types.ts +0 -18
- package/src/wifiConfig/timeZoneName.json +0 -1
package/src/openApiRequest.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import errorCode from './errorCode';
|
|
2
|
-
import { getGlobalData } from "./globalData";
|
|
3
|
-
import request from './request';
|
|
4
|
-
import { IError, IServiceResult, IWechatApiResult } from './types';
|
|
5
|
-
|
|
6
|
-
const openApiRequest = async <T>(url: string, options: any, needToken: boolean = true): Promise<IServiceResult<T>> => {
|
|
7
|
-
const requestOptions = { ...options };
|
|
8
|
-
const headers: any = {
|
|
9
|
-
'Content-Type': 'application/json',
|
|
10
|
-
'X-Gizwits-Application-Id': getGlobalData('appID'),
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
if (needToken) {
|
|
14
|
-
headers['X-Gizwits-User-token'] = getGlobalData('token');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
requestOptions.header = { ...headers, ...options.headers };
|
|
18
|
-
delete requestOptions.headers;
|
|
19
|
-
const openApiUrl = getGlobalData('cloudServiceInfo').openAPIInfo;
|
|
20
|
-
const res = await request<IWechatApiResult<T>>('https://' + openApiUrl + url, requestOptions);
|
|
21
|
-
// 统一封装OPEN API的错误码
|
|
22
|
-
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
23
|
-
return {
|
|
24
|
-
success: true,
|
|
25
|
-
data: res.data
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let baseError = {
|
|
30
|
-
success: false,
|
|
31
|
-
err: {
|
|
32
|
-
errorCode: errorCode.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,
|
|
33
|
-
errorMessage: '',
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
baseError = {
|
|
38
|
-
success: false,
|
|
39
|
-
err: {
|
|
40
|
-
errorCode: (res.data as any).error_code,
|
|
41
|
-
errorMessage: (res.data as any).error_message,
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
} catch (error) {
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
return baseError;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default openApiRequest;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import openApiRequest from './openApiRequest';
|
|
2
|
-
import { IProductConfigData, IDataPointConfig } from './types';
|
|
3
|
-
// 管理配置文件
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class ProductConfigFileManage {
|
|
7
|
-
data: IProductConfigData = {};
|
|
8
|
-
key = 'dataPointConfig';
|
|
9
|
-
|
|
10
|
-
init = async () => {
|
|
11
|
-
const data = await wx.getStorageSync(this.key) || '{}';
|
|
12
|
-
let dataJson = {};
|
|
13
|
-
try {
|
|
14
|
-
dataJson = JSON.parse(data);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
this.data = dataJson;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getConfigFileMap: Record<string, Promise<IDataPointConfig | null>> = {};
|
|
22
|
-
|
|
23
|
-
public getConfigFile = (pk: string): Promise<IDataPointConfig | null> => {
|
|
24
|
-
if (!this.data[pk]) {
|
|
25
|
-
|
|
26
|
-
if (this.getConfigFileMap[pk]) {
|
|
27
|
-
// 正在请求中
|
|
28
|
-
return this.getConfigFileMap[pk];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const promise = new Promise<IDataPointConfig | null>(async (resolve) => {
|
|
32
|
-
// 不在缓存里,去云端获取
|
|
33
|
-
const url = `/app/datapoint?product_key=${pk}`;
|
|
34
|
-
const data = await openApiRequest<IDataPointConfig>(`${url}`, { method: 'GET' });
|
|
35
|
-
if (data.success && data.data?.entities) {
|
|
36
|
-
this.data[pk] = data.data as IDataPointConfig;
|
|
37
|
-
resolve(this.data[pk]);
|
|
38
|
-
// 更新缓存
|
|
39
|
-
wx.setStorageSync(this.key, JSON.stringify(this.data))
|
|
40
|
-
} else {
|
|
41
|
-
// 请求失败
|
|
42
|
-
resolve(null);
|
|
43
|
-
}
|
|
44
|
-
this.getConfigFileMap[pk] = null;
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
this.getConfigFileMap[pk] = promise;
|
|
48
|
-
return promise;
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
return Promise.resolve(this.data[pk]);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public getAttrItem = async (pk: string, key: string) => {
|
|
55
|
-
if (!this.data[pk]) {
|
|
56
|
-
await this.getConfigFile(pk)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
for (let index in this.data[pk].entities[0].attrs) {
|
|
60
|
-
const item = this.data[pk].entities[0].attrs[index]
|
|
61
|
-
if (item.name === key) {
|
|
62
|
-
return item;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const productConfigFileManage = new ProductConfigFileManage();
|
|
70
|
-
productConfigFileManage.init();
|
|
71
|
-
|
|
72
|
-
export default productConfigFileManage;
|
package/src/protocol/Bind.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import ProtocolBase from "./ProtocolBase";
|
|
2
|
-
import { arrayToString } from "./tool";
|
|
3
|
-
|
|
4
|
-
class Bind extends ProtocolBase {
|
|
5
|
-
passcode: string = '';
|
|
6
|
-
constructor(data: number[]) {
|
|
7
|
-
super(data);
|
|
8
|
-
let index = 0;
|
|
9
|
-
const passcodeLen = parseInt(arrayToString(this.content.slice(index, index + 2)), 16);
|
|
10
|
-
index += 2;
|
|
11
|
-
let passcodeString = '';
|
|
12
|
-
this.content.slice(index, index + passcodeLen).map(item => {
|
|
13
|
-
passcodeString += String.fromCharCode(item);
|
|
14
|
-
});
|
|
15
|
-
this.passcode = passcodeString;
|
|
16
|
-
}
|
|
17
|
-
static pack = () => {
|
|
18
|
-
return [0,0,0,3,3,0,0,6];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default Bind;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import ProtocolBase from "./ProtocolBase";
|
|
2
|
-
import { arrayToASCII, arrayToString } from "./tool";
|
|
3
|
-
|
|
4
|
-
class DeviceInfo extends ProtocolBase {
|
|
5
|
-
moduleSoftVersion: string = '';
|
|
6
|
-
moduleHardVersion: string = '';
|
|
7
|
-
|
|
8
|
-
mcuSoftVersion: string = '';
|
|
9
|
-
mcuHardVersion: string = '';
|
|
10
|
-
businessVersion: string = ''; //业务版本号
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
constructor(data: number[]) {
|
|
14
|
-
super(data);
|
|
15
|
-
let index = 0;
|
|
16
|
-
|
|
17
|
-
this.moduleHardVersion = arrayToASCII(this.content.slice(index, index + 8))
|
|
18
|
-
index += 8;
|
|
19
|
-
|
|
20
|
-
this.moduleSoftVersion = arrayToASCII(this.content.slice(index, index + 8))
|
|
21
|
-
index += 8;
|
|
22
|
-
|
|
23
|
-
this.mcuHardVersion = arrayToASCII(this.content.slice(index, index + 8))
|
|
24
|
-
index += 8;
|
|
25
|
-
|
|
26
|
-
this.mcuSoftVersion = arrayToASCII(this.content.slice(index, index + 8))
|
|
27
|
-
index += 8;
|
|
28
|
-
|
|
29
|
-
this.businessVersion = arrayToASCII(this.content.slice(index, index + 8))
|
|
30
|
-
index += 8;
|
|
31
|
-
}
|
|
32
|
-
static pack = () => {
|
|
33
|
-
return [0,0,0,3,3,0,0,0x13];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default DeviceInfo;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import GizLog from "../GizLog";
|
|
2
|
-
import ProtocolBase from "./ProtocolBase";
|
|
3
|
-
import { arrayToString, fillString } from "./tool";
|
|
4
|
-
|
|
5
|
-
type TDecodeType = 'ASCII' | 'HEX'
|
|
6
|
-
|
|
7
|
-
class DiscoverUDP extends ProtocolBase {
|
|
8
|
-
|
|
9
|
-
did = '';
|
|
10
|
-
mac = '';
|
|
11
|
-
productKey = '';
|
|
12
|
-
deviceType = 0;
|
|
13
|
-
apiUrl = "";
|
|
14
|
-
protocolVersion = ""
|
|
15
|
-
mcuVersion = ""
|
|
16
|
-
moduleVersion = ""
|
|
17
|
-
|
|
18
|
-
constructor(data: number[]) {
|
|
19
|
-
super(data);
|
|
20
|
-
let index = 0;
|
|
21
|
-
try {
|
|
22
|
-
index = this.baseParse(index, 'did')
|
|
23
|
-
index = this.baseParse(index, 'mac', 'HEX')
|
|
24
|
-
index = this.baseParse(index, 'moduleVersion')
|
|
25
|
-
index = this.baseParse(index, 'productKey')
|
|
26
|
-
index += 8
|
|
27
|
-
index = this.parseEndChat(index, 'apiUrl')
|
|
28
|
-
index = this.parseEndChat(index, 'protocolVersion')
|
|
29
|
-
this.mcuVersion = ""
|
|
30
|
-
this.content.slice(index, this.content.length).map(item => {
|
|
31
|
-
this.mcuVersion += String.fromCharCode(item);
|
|
32
|
-
})
|
|
33
|
-
} catch (error) {
|
|
34
|
-
GizLog.warn('Parse DiscoverUDP error', error)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
parseEndChat = (index, key) => {
|
|
39
|
-
let string = ''
|
|
40
|
-
const data = this.content.slice(index, this.content.length);
|
|
41
|
-
for (let i in data) {
|
|
42
|
-
const item = data[i];
|
|
43
|
-
index += 1;
|
|
44
|
-
if (item === 0){
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
string += String.fromCharCode(item);
|
|
48
|
-
}
|
|
49
|
-
this[key] = string
|
|
50
|
-
return index;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
baseParse = (index, key, type:TDecodeType = 'ASCII') => {
|
|
54
|
-
const len = parseInt(arrayToString(this.content.slice(index, index + 2)), 16);
|
|
55
|
-
index += 2;
|
|
56
|
-
let stringData = '';
|
|
57
|
-
this.content.slice(index, index + len).map(item => {
|
|
58
|
-
if (type === 'ASCII') {
|
|
59
|
-
stringData += String.fromCharCode(item);
|
|
60
|
-
} else {
|
|
61
|
-
const hexData = item.toString(16);
|
|
62
|
-
stringData += fillString(hexData, 2);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
this[key] = stringData;
|
|
66
|
-
return index + len;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
static pack = () => {
|
|
70
|
-
const config = [0,0,0,3,3,0,0,3];
|
|
71
|
-
const buffer = new ArrayBuffer(config.length);
|
|
72
|
-
const uint8Array = new Uint8Array(buffer);
|
|
73
|
-
for (let i = 0; i < buffer.byteLength; i++) {
|
|
74
|
-
uint8Array[i] = config[i];
|
|
75
|
-
}
|
|
76
|
-
return uint8Array;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default DiscoverUDP;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import productConfigFileManage from "../productConfigFileManage";
|
|
2
|
-
import ProtocolBase from "./ProtocolBase";
|
|
3
|
-
import { fillString, hexStrint2byte, string2Bytes } from "./tool";
|
|
4
|
-
|
|
5
|
-
class GetDeviceStatus extends ProtocolBase {
|
|
6
|
-
static pack = async (productKey: string, gwDid?: string, attrNames?: string[], ) => {
|
|
7
|
-
const configFile = await productConfigFileManage.getConfigFile(productKey);
|
|
8
|
-
if (configFile) {
|
|
9
|
-
const isAdaptiveDatapoint = configFile.protocolType === 'var_len';
|
|
10
|
-
const header = [0,0,0,3];
|
|
11
|
-
const len = [0];
|
|
12
|
-
let flag = [0];
|
|
13
|
-
const cmd = [0,147];
|
|
14
|
-
let sn = [0,0,0,0];
|
|
15
|
-
let payload = [2];
|
|
16
|
-
|
|
17
|
-
if (gwDid) {
|
|
18
|
-
flag = [1];
|
|
19
|
-
const hexLen = fillString(gwDid.length.toString(16), 4)
|
|
20
|
-
|
|
21
|
-
const didLen = hexStrint2byte(hexLen);
|
|
22
|
-
const did = string2Bytes(gwDid);
|
|
23
|
-
sn = sn.concat(didLen).concat(did);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (isAdaptiveDatapoint) {
|
|
27
|
-
// 变长action
|
|
28
|
-
payload = [18];
|
|
29
|
-
// 根据 attrs 补充flag
|
|
30
|
-
let flagString = '';
|
|
31
|
-
|
|
32
|
-
if (!attrNames) {
|
|
33
|
-
// 全部填充
|
|
34
|
-
configFile.entities[0].attrs.map(() => {
|
|
35
|
-
flagString = `1${flagString}`;
|
|
36
|
-
})
|
|
37
|
-
} else {
|
|
38
|
-
const attrs = attrNames.reduce((acc, cur) => ({ ...acc, [cur]: 1 }), {});
|
|
39
|
-
configFile.entities[0].attrs.map((item) => {
|
|
40
|
-
if (attrs[item.name]) {
|
|
41
|
-
flagString = `1${flagString}`;
|
|
42
|
-
} else {
|
|
43
|
-
flagString = `0${flagString}`;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
flagString = fillString(flagString, Math.ceil(flagString.length / 8) * 8);
|
|
49
|
-
payload = payload.concat(hexStrint2byte(parseInt(flagString, 2).toString(16)));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const endData = flag.concat(cmd).concat(sn).concat(payload);
|
|
53
|
-
len[0] = endData.length;
|
|
54
|
-
|
|
55
|
-
return header.concat(len).concat(endData);
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export default GetDeviceStatus;
|
package/src/protocol/Login.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import ProtocolBase from "./ProtocolBase";
|
|
2
|
-
import { arrayToString, fillString, hexStrint2byte, string2Bytes } from "./tool";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
interface IPackParame {
|
|
6
|
-
passcode: string;
|
|
7
|
-
}
|
|
8
|
-
class Login extends ProtocolBase {
|
|
9
|
-
result: boolean = false;
|
|
10
|
-
didLength: number = 0;
|
|
11
|
-
did: string = '';
|
|
12
|
-
constructor(data: number[]) {
|
|
13
|
-
super(data);
|
|
14
|
-
|
|
15
|
-
let index = 0;
|
|
16
|
-
this.result = this.content[0] === 0;
|
|
17
|
-
index ++;
|
|
18
|
-
if (this.flag[0] === 1) {
|
|
19
|
-
this.didLength = parseInt(arrayToString(this.content.slice(index, index + 2)), 16);
|
|
20
|
-
|
|
21
|
-
index += 2;
|
|
22
|
-
let didString = '';
|
|
23
|
-
this.content.slice(index, this.content.length).map(item => {
|
|
24
|
-
didString += String.fromCharCode(item);
|
|
25
|
-
});
|
|
26
|
-
this.did = didString;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
static pack = ({passcode}: IPackParame) => {
|
|
30
|
-
const header = [0,0,0,3];
|
|
31
|
-
let len = [0];
|
|
32
|
-
const flag = [0];
|
|
33
|
-
const cmd = [0,8];
|
|
34
|
-
const passcodeLen = hexStrint2byte(fillString(passcode.length.toString(16), 4));
|
|
35
|
-
const passcodeArr = string2Bytes(passcode);
|
|
36
|
-
|
|
37
|
-
const data = flag.concat(cmd).concat(passcodeLen).concat(passcodeArr);
|
|
38
|
-
len = hexStrint2byte(data.length.toString(16));
|
|
39
|
-
return header.concat(len).concat(data);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export default Login;
|
package/src/protocol/Ntp.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import ProtocolBase from "./ProtocolBase";
|
|
2
|
-
import { completeBlock, fillString, string2Bytes } from "./tool";
|
|
3
|
-
|
|
4
|
-
class Ntp extends ProtocolBase {
|
|
5
|
-
static pack = () => {
|
|
6
|
-
const time = parseInt(`${Date.now() / 1000}`, 10);
|
|
7
|
-
const timeString = fillString(time.toString(2), 5 * 8)
|
|
8
|
-
|
|
9
|
-
return [0,0,0,3,8,0,0,89].concat(completeBlock(timeString));
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default Ntp;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import ProtocolBase from "../ProtocolBase";
|
|
2
|
-
|
|
3
|
-
class AwaitNoti extends ProtocolBase {
|
|
4
|
-
state = 0; // 0继续 1失败
|
|
5
|
-
constructor(data: number[]) {
|
|
6
|
-
super(data);
|
|
7
|
-
this.state = this.content[0]
|
|
8
|
-
}
|
|
9
|
-
static pack = (position: number) => {
|
|
10
|
-
return [0,0,0,3];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default AwaitNoti;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { IOTAType } from "../../types";
|
|
2
|
-
import ProtocolBase from "../ProtocolBase";
|
|
3
|
-
|
|
4
|
-
class CheckCanOTA extends ProtocolBase {
|
|
5
|
-
type: IOTAType = 'MCU';
|
|
6
|
-
state: number = 0; // 0可以更新 1 不可以更新
|
|
7
|
-
version: number = 0; // 当前ota协议版本
|
|
8
|
-
constructor(data: number[]) {
|
|
9
|
-
super(data);
|
|
10
|
-
let index = 0;
|
|
11
|
-
this.type = this.content[index] === 1 ? 'MODULE' : 'MCU'
|
|
12
|
-
index += 1;
|
|
13
|
-
this.state = this.content[index];
|
|
14
|
-
index += 1;
|
|
15
|
-
this.version = this.content[index];
|
|
16
|
-
}
|
|
17
|
-
static pack = (type: IOTAType) => {
|
|
18
|
-
const typeData = type === 'MCU' ? 2 : 1
|
|
19
|
-
return [0,0,0,3,4,0,0,0x41, typeData];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default CheckCanOTA;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { crc16modbus } from '../../crc'
|
|
2
|
-
import { getVariableLength } from "../dataPoint";
|
|
3
|
-
import ProtocolBase from "../ProtocolBase";
|
|
4
|
-
import { bytesToInt, fillString, hexStrint2byte } from "../tool";
|
|
5
|
-
|
|
6
|
-
class OTAPackPackage extends ProtocolBase {
|
|
7
|
-
|
|
8
|
-
packageNum = 0;
|
|
9
|
-
state = 0;
|
|
10
|
-
|
|
11
|
-
constructor(data: number[]) {
|
|
12
|
-
super(data);
|
|
13
|
-
let index = 0;
|
|
14
|
-
this.packageNum = bytesToInt(this.content.slice(index, index + 2))
|
|
15
|
-
index += 2;
|
|
16
|
-
this.state = this.content[index]
|
|
17
|
-
}
|
|
18
|
-
static pack = (data: number[], packageNum: number) => {
|
|
19
|
-
const header = [0,0,0,3]
|
|
20
|
-
const flag = [0]
|
|
21
|
-
|
|
22
|
-
const cmd = [0,0x47]
|
|
23
|
-
const packageNumBytes = hexStrint2byte(fillString(packageNum.toString(16), 4)) // 包号
|
|
24
|
-
const packageLenBytes = hexStrint2byte(fillString(data.length.toString(16), 4)) // 包长度
|
|
25
|
-
|
|
26
|
-
const crc16Hex = fillString(crc16modbus(new Uint8Array(data)).toString(16), 4);
|
|
27
|
-
const crc16Bytes = hexStrint2byte(crc16Hex);
|
|
28
|
-
let content = flag;
|
|
29
|
-
content = content.concat(cmd, packageNumBytes, packageLenBytes, crc16Bytes, data)
|
|
30
|
-
|
|
31
|
-
const len = getVariableLength(content)
|
|
32
|
-
|
|
33
|
-
return header.concat(len, content);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default OTAPackPackage;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import ProtocolBase from "../ProtocolBase";
|
|
2
|
-
|
|
3
|
-
type IState = 0 | 1 | 2 | 3 | 4
|
|
4
|
-
|
|
5
|
-
class OtaComplete extends ProtocolBase {
|
|
6
|
-
state: IState = 0; // 0x00 成功 0x01 长度不对 0x02 CRC 失败 0x03 取消 0x04 其他
|
|
7
|
-
constructor(data: number[]) {
|
|
8
|
-
super(data);
|
|
9
|
-
let index = 0;
|
|
10
|
-
this.state = this.content[index] as any
|
|
11
|
-
}
|
|
12
|
-
static pack = (state: IState) => {
|
|
13
|
-
return [0,0,0,3,4,0,0,0x50, state];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default OtaComplete;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { getVariableLength } from "../dataPoint";
|
|
2
|
-
import ProtocolBase from "../ProtocolBase";
|
|
3
|
-
import { bytesToHexString, bytesToInt, fillString, hexStrint2byte, string2Bytes } from "../tool";
|
|
4
|
-
|
|
5
|
-
type TState = 0 | 1 | 2 | 3 // 0x00 正常升级 0x01 pk不一致 0x02 版本低于当前 0x03 大小超过范围
|
|
6
|
-
class PreOTA extends ProtocolBase {
|
|
7
|
-
|
|
8
|
-
state: TState = 0
|
|
9
|
-
processedLen: number = 0 // 已经接收的长度
|
|
10
|
-
processedCrc32: string = '';
|
|
11
|
-
packageMaxLen: number = 20; // 发过去的每一包,最大长度
|
|
12
|
-
|
|
13
|
-
constructor(data: number[]) {
|
|
14
|
-
super(data);
|
|
15
|
-
let index = 0;
|
|
16
|
-
this.state = this.content[index] as TState;
|
|
17
|
-
index += 1;
|
|
18
|
-
|
|
19
|
-
this.processedLen = bytesToInt(this.content.slice(index, index + 4));
|
|
20
|
-
index += 4;
|
|
21
|
-
this.processedCrc32 = bytesToHexString(this.content.slice(index, index + 4))
|
|
22
|
-
index += 4;
|
|
23
|
-
|
|
24
|
-
this.packageMaxLen = bytesToInt(this.content.slice(index, index + 2));
|
|
25
|
-
}
|
|
26
|
-
static pack = (pk: string, softVer: string, md5: string, fileLen: number, crc32: number) => {
|
|
27
|
-
const header = [0,0,0,3]
|
|
28
|
-
const cmd = [0,0x43]
|
|
29
|
-
const flag = [0]
|
|
30
|
-
|
|
31
|
-
const pkBytes = string2Bytes(pk)
|
|
32
|
-
const pkLen = pk.length;
|
|
33
|
-
const softVerBytes = string2Bytes(fillString(softVer, 8))
|
|
34
|
-
const md5Bytes = hexStrint2byte(md5)
|
|
35
|
-
const crc32Bytes = hexStrint2byte(fillString(crc32.toString(16), 8))
|
|
36
|
-
|
|
37
|
-
const fileLenBytes = hexStrint2byte(fillString(fileLen.toString(16), 8))
|
|
38
|
-
|
|
39
|
-
let content = flag;
|
|
40
|
-
content = content.concat(cmd, [pkLen], pkBytes, softVerBytes, md5Bytes, fileLenBytes,crc32Bytes)
|
|
41
|
-
|
|
42
|
-
const len = getVariableLength(content)
|
|
43
|
-
|
|
44
|
-
return header.concat(len, content);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default PreOTA;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import ProtocolBase from "../ProtocolBase";
|
|
2
|
-
import { fillString, hexStrint2byte } from "../tool";
|
|
3
|
-
|
|
4
|
-
class ResetPosition extends ProtocolBase {
|
|
5
|
-
constructor(data: number[]) {
|
|
6
|
-
super(data);
|
|
7
|
-
}
|
|
8
|
-
static pack = (position: number) => {
|
|
9
|
-
const positionBytes = hexStrint2byte(fillString(position.toString(16), 8))
|
|
10
|
-
return [0,0,0,3,7,0,0,0x45, ...positionBytes];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default ResetPosition;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import ProtocolBase from "./ProtocolBase";
|
|
2
|
-
import { arrayToString, completeBlock, fillString, hexStrint2byte } from "./tool";
|
|
3
|
-
|
|
4
|
-
export class RequestSync extends ProtocolBase {
|
|
5
|
-
state: number = 0; // 0 允许同步 1 没有数据 2其他
|
|
6
|
-
len: number = 0; // 需要同步的数据长度
|
|
7
|
-
constructor(data: number[]) {
|
|
8
|
-
super(data);
|
|
9
|
-
let index = 0
|
|
10
|
-
|
|
11
|
-
this.len = parseInt(arrayToString(this.content.slice(index, index + 2)), 16);
|
|
12
|
-
index += 2
|
|
13
|
-
|
|
14
|
-
this.state = this.content[index];
|
|
15
|
-
}
|
|
16
|
-
static pack = () => {
|
|
17
|
-
return [0,0,0,3,3,0,0,113];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export class SyncPackage extends ProtocolBase {
|
|
23
|
-
id: number = 0;
|
|
24
|
-
timestemp: number = 0;
|
|
25
|
-
payloadLen: number = 0;
|
|
26
|
-
payload: number[] = [];
|
|
27
|
-
constructor(data: number[]) {
|
|
28
|
-
super(data);
|
|
29
|
-
|
|
30
|
-
let index = 0;
|
|
31
|
-
this.id = parseInt(arrayToString(this.content.slice(index, index + 2)), 16);
|
|
32
|
-
|
|
33
|
-
index += 2;
|
|
34
|
-
|
|
35
|
-
this.timestemp = parseInt(arrayToString(this.content.slice(index, index + 5)), 16);
|
|
36
|
-
index += 5;
|
|
37
|
-
|
|
38
|
-
this.payloadLen = parseInt(arrayToString(this.content.slice(index, index + 2)), 16);
|
|
39
|
-
index += 2;
|
|
40
|
-
|
|
41
|
-
this.payload = this.content.slice(index, this.content.length)
|
|
42
|
-
}
|
|
43
|
-
static pack = (id: number) => {
|
|
44
|
-
let stringData = id.toString(2)
|
|
45
|
-
stringData = fillString(stringData, 8 * 2)
|
|
46
|
-
const packageData = [0,0,0,3, 5].concat([0,0,115]).concat(completeBlock(stringData))
|
|
47
|
-
return packageData;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 删除数据
|
|
52
|
-
export class DeletePackage extends ProtocolBase {
|
|
53
|
-
static pack = (id: number) => {
|
|
54
|
-
let stringData = id.toString(2)
|
|
55
|
-
stringData = fillString(stringData, 8 * 2)
|
|
56
|
-
const packageData = [0,0,0,3,5].concat([0,0,117]).concat(completeBlock(stringData))
|
|
57
|
-
return packageData;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// let time = 1669711410;
|
|
62
|
-
// let timeBytes: any = time.toString(16)
|
|
63
|
-
// timeBytes = fillString(timeBytes, 10)
|
|
64
|
-
// timeBytes = hexStrint2byte(timeBytes)
|
|
65
|
-
// console.log(timeBytes)
|
|
66
|
-
|
|
67
|
-
// const syncPackage = new SyncPackage([0,0,0,3,15 ,0, 0, 83,1,1,1,1].concat(timeBytes).concat([0, 1, 1]))
|
|
68
|
-
// console.log(syncPackage)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
export class CancelSync extends ProtocolBase {
|
|
72
|
-
state: number = 0; // 0 同步完成 01 异常 02 其他
|
|
73
|
-
constructor(data: number[]) {
|
|
74
|
-
super(data);
|
|
75
|
-
this.state = this.content[0];
|
|
76
|
-
}
|
|
77
|
-
static pack = () => {
|
|
78
|
-
const packageData = [0,0,0,3, 3, 0, 0, 119]
|
|
79
|
-
return packageData;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { arrayToString, checkHeader, getProtocolLen } from "./tool";
|
|
2
|
-
|
|
3
|
-
class ProtocolBase {
|
|
4
|
-
header: string = '';
|
|
5
|
-
len:number = 0;
|
|
6
|
-
flag:number[] = [0];
|
|
7
|
-
cmd :string = '';
|
|
8
|
-
content:number[] = [];
|
|
9
|
-
|
|
10
|
-
constructor(data?: number[]) {
|
|
11
|
-
if (data && data.length > 0) {
|
|
12
|
-
this.formatP0(data);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
static decodeLen = (arr) => {
|
|
17
|
-
let multiplier = 1;
|
|
18
|
-
let value=0;
|
|
19
|
-
let digit = 0;
|
|
20
|
-
let index = 0;
|
|
21
|
-
do {
|
|
22
|
-
digit = arr[index];
|
|
23
|
-
value += (digit & 127) * multiplier;
|
|
24
|
-
multiplier *= 128;
|
|
25
|
-
index += 1;
|
|
26
|
-
} while ((digit & 128) != 0);
|
|
27
|
-
return value;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
formatP0 = (data) => {
|
|
31
|
-
let pointer = checkHeader(data);
|
|
32
|
-
|
|
33
|
-
if (pointer === false) {
|
|
34
|
-
// 包头错误
|
|
35
|
-
throw new Error("Header Error");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this.header = arrayToString(data.slice(0, pointer));
|
|
39
|
-
|
|
40
|
-
const nextData = data.slice(pointer, data.length);
|
|
41
|
-
|
|
42
|
-
const lengthIndex = getProtocolLen(nextData);
|
|
43
|
-
|
|
44
|
-
this.len = ProtocolBase.decodeLen(nextData.slice(0, lengthIndex));
|
|
45
|
-
pointer += lengthIndex;
|
|
46
|
-
this.flag = data.slice(pointer, pointer + 1);
|
|
47
|
-
pointer += 1;
|
|
48
|
-
this.cmd = arrayToString(data.slice(pointer, pointer + 2));
|
|
49
|
-
pointer += 2;
|
|
50
|
-
this.content = data.slice(pointer, data.length)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export default ProtocolBase;
|