@moshenguo/ms-data-sdk 0.1.4 → 0.1.6
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/build/MsDataSdk.types.d.ts +0 -1
- package/build/MsDataSdkModule.d.ts +0 -1
- package/build/MsDataSdkModule.web.d.ts +0 -1
- package/build/index.d.ts +0 -1
- package/build/sdk/bleConst.d.ts +212 -1
- package/build/sdk/bleSDK.d.ts +3 -1
- package/build/sdk/constants.d.ts +0 -1
- package/build/sdk/models.d.ts +44 -25
- package/build/sdk/resolveUtil.d.ts +229 -15
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/BleSDK.html +53 -52
- package/docs/classes/ResolveUtil.html +56 -14
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +2 -2
- package/docs/interfaces/MyAutomaticHRMonitoring.html +10 -10
- package/docs/interfaces/MyDeviceInfo.html +16 -6
- package/docs/interfaces/MyPersonalInfo.html +8 -2
- package/docs/interfaces/MySedentaryReminderV4.html +10 -10
- package/docs/interfaces/MyWeeksV4.html +14 -6
- package/docs/modules.html +1 -1
- package/docs/variables/BleConst.html +96 -1
- package/docs/variables/DeviceKey.html +113 -1
- package/package.json +24 -17
- package/build/MsDataSdk.types.d.ts.map +0 -1
- package/build/MsDataSdk.types.js +0 -2
- package/build/MsDataSdk.types.js.map +0 -1
- package/build/MsDataSdkModule.d.ts.map +0 -1
- package/build/MsDataSdkModule.js +0 -4
- package/build/MsDataSdkModule.js.map +0 -1
- package/build/MsDataSdkModule.web.d.ts.map +0 -1
- package/build/MsDataSdkModule.web.js +0 -12
- package/build/MsDataSdkModule.web.js.map +0 -1
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -6
- package/build/index.js.map +0 -1
- package/build/sdk/bleConst.d.ts.map +0 -1
- package/build/sdk/bleConst.js +0 -287
- package/build/sdk/bleConst.js.map +0 -1
- package/build/sdk/bleSDK.d.ts.map +0 -1
- package/build/sdk/bleSDK.js +0 -1106
- package/build/sdk/bleSDK.js.map +0 -1
- package/build/sdk/constants.d.ts.map +0 -1
- package/build/sdk/constants.js +0 -20
- package/build/sdk/constants.js.map +0 -1
- package/build/sdk/models.d.ts.map +0 -1
- package/build/sdk/models.js +0 -2
- package/build/sdk/models.js.map +0 -1
- package/build/sdk/resolveUtil.d.ts.map +0 -1
- package/build/sdk/resolveUtil.js +0 -1448
- package/build/sdk/resolveUtil.js.map +0 -1
- package/docs/interfaces/MyAlarmClockV4.html +0 -9
package/build/sdk/bleSDK.js
DELETED
|
@@ -1,1106 +0,0 @@
|
|
|
1
|
-
import { DeviceConst, BleConst } from './bleConst';
|
|
2
|
-
import { ResolveUtil } from './resolveUtil';
|
|
3
|
-
export class BleSDK {
|
|
4
|
-
static DATA_READ_START = 0;
|
|
5
|
-
static DATA_READ_CONTINUE = 2;
|
|
6
|
-
static DATA_DELETE = 99;
|
|
7
|
-
static DistanceMode_MILE = 0x81;
|
|
8
|
-
static DistanceMode_KM = 0x80;
|
|
9
|
-
static TimeMode_12h = 0x81;
|
|
10
|
-
static TimeMode_24h = 0x80;
|
|
11
|
-
static WristOn_Enable = 0x81;
|
|
12
|
-
static WristOn_DisEnable = 0x80;
|
|
13
|
-
static TempUnit_C = 0x80;
|
|
14
|
-
static TempUnit_F = 0x81;
|
|
15
|
-
static TAG = "BleSDK";
|
|
16
|
-
static isRuning = false;
|
|
17
|
-
static ecgopen = false;
|
|
18
|
-
static read = false;
|
|
19
|
-
static pregnancyCycleRead = false;
|
|
20
|
-
static isSettingSocial = false;
|
|
21
|
-
static StartDeviceMeasurementWithType = false;
|
|
22
|
-
static generateValue(size) {
|
|
23
|
-
return new Array(size).fill(0);
|
|
24
|
-
}
|
|
25
|
-
static hexByte2Int(b, count) {
|
|
26
|
-
return (b & 0xff) * Math.pow(256, count);
|
|
27
|
-
}
|
|
28
|
-
static generateInitValue() {
|
|
29
|
-
return this.generateValue(16);
|
|
30
|
-
}
|
|
31
|
-
static arrayCopy(source, srcPos, dest, destPos, length) {
|
|
32
|
-
for (let i = 0; i < length; i++) {
|
|
33
|
-
dest[destPos + i] = source[srcPos + i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
static crcValue(list) {
|
|
37
|
-
let crcValue = 0;
|
|
38
|
-
for (const value of list) {
|
|
39
|
-
crcValue += value;
|
|
40
|
-
}
|
|
41
|
-
list[15] = crcValue & 0xff;
|
|
42
|
-
}
|
|
43
|
-
static crcDynamicValue(list) {
|
|
44
|
-
let crcValue = 0;
|
|
45
|
-
for (const value of list) {
|
|
46
|
-
crcValue += value;
|
|
47
|
-
}
|
|
48
|
-
list[list.length - 1] = crcValue & 0xff;
|
|
49
|
-
}
|
|
50
|
-
static getBcdValue(value) {
|
|
51
|
-
return Math.floor(value / 10) * 16 + (value % 10);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* 数据解析方法
|
|
55
|
-
* @param 蓝牙返回原始数据
|
|
56
|
-
* @returns 解析后的数据
|
|
57
|
-
*/
|
|
58
|
-
static dataParsingWithData(value) {
|
|
59
|
-
if (!value || value.length === 0) {
|
|
60
|
-
return ResolveUtil.setMethodError('Empty data');
|
|
61
|
-
}
|
|
62
|
-
const cmd = value[0];
|
|
63
|
-
switch (cmd) {
|
|
64
|
-
case DeviceConst.CMD_Set_Goal:
|
|
65
|
-
return ResolveUtil.setMethodSuccessful(BleConst.SetStepGoal);
|
|
66
|
-
case DeviceConst.CMD_Set_UseInfo:
|
|
67
|
-
return ResolveUtil.setMethodSuccessful(BleConst.SetPersonalInfo);
|
|
68
|
-
case DeviceConst.CMD_Set_Name:
|
|
69
|
-
break;
|
|
70
|
-
case DeviceConst.CMD_Set_MOT_SIGN:
|
|
71
|
-
return ResolveUtil.setMethodSuccessful(BleConst.SetMotorVibrationWithTimes);
|
|
72
|
-
case DeviceConst.CMD_Set_DeviceInfo:
|
|
73
|
-
return ResolveUtil.setMethodSuccessful(BleConst.SetDeviceInfo);
|
|
74
|
-
case DeviceConst.CMD_Set_AutoHeart:
|
|
75
|
-
return ResolveUtil.setMethodSuccessful(BleConst.SetAutomaticHRMonitoring);
|
|
76
|
-
case DeviceConst.CMD_Set_ActivityAlarm: //设置 久坐提醒
|
|
77
|
-
return ResolveUtil.setMethodSuccessful(BleConst.SetSedentaryReminder);
|
|
78
|
-
case DeviceConst.CMD_Set_DeviceID:
|
|
79
|
-
return ResolveUtil.setMacSuccessful();
|
|
80
|
-
case DeviceConst.CMD_Start_EXERCISE:
|
|
81
|
-
return ResolveUtil.setMethodSuccessful(BleConst.EnterActivityMode);
|
|
82
|
-
case DeviceConst.CMD_Set_TemperatureCorrection:
|
|
83
|
-
if (value[2] !== 0 && value[3] !== 0) {
|
|
84
|
-
return ResolveUtil.getTemperatureCorrectionValue(value);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
return ResolveUtil.setMethodSuccessful(BleConst.CMD_Set_TemperatureCorrection);
|
|
88
|
-
}
|
|
89
|
-
case DeviceConst.CMD_HeartPackageFromDevice:
|
|
90
|
-
return ResolveUtil.getActivityExerciseData(value);
|
|
91
|
-
case DeviceConst.CMD_SET_TIME:
|
|
92
|
-
return ResolveUtil.setTimeSuccessful(value);
|
|
93
|
-
case DeviceConst.CMD_Get_SPORTData:
|
|
94
|
-
return ResolveUtil.getExerciseData(value);
|
|
95
|
-
case DeviceConst.CMD_GET_TIME:
|
|
96
|
-
return ResolveUtil.getDeviceTime(value);
|
|
97
|
-
case DeviceConst.CMD_GET_USERINFO:
|
|
98
|
-
return ResolveUtil.getUserInfo(value);
|
|
99
|
-
case DeviceConst.CMD_Get_DeviceInfo:
|
|
100
|
-
return ResolveUtil.getDeviceInfo(value);
|
|
101
|
-
case DeviceConst.CMD_Enable_Activity:
|
|
102
|
-
return ResolveUtil.getActivityData(value);
|
|
103
|
-
case DeviceConst.CMD_Get_Goal:
|
|
104
|
-
return ResolveUtil.getGoal(value);
|
|
105
|
-
case DeviceConst.CMD_Get_BatteryLevel:
|
|
106
|
-
return ResolveUtil.getDeviceBattery(value);
|
|
107
|
-
case DeviceConst.CMD_Get_Address:
|
|
108
|
-
return ResolveUtil.getDeviceAddress(value);
|
|
109
|
-
case DeviceConst.CMD_Get_Version:
|
|
110
|
-
return ResolveUtil.getDeviceVersion(value);
|
|
111
|
-
case DeviceConst.CMD_Get_Name:
|
|
112
|
-
return ResolveUtil.getDeviceName(value);
|
|
113
|
-
case DeviceConst.CMD_Get_AutoHeart:
|
|
114
|
-
return ResolveUtil.getAutoHeart(value);
|
|
115
|
-
case DeviceConst.CMD_Reset:
|
|
116
|
-
return ResolveUtil.Reset();
|
|
117
|
-
case DeviceConst.CMD_Mcu_Reset:
|
|
118
|
-
return ResolveUtil.MCUReset();
|
|
119
|
-
case DeviceConst.CMD_Notify:
|
|
120
|
-
return ResolveUtil.Notify();
|
|
121
|
-
case DeviceConst.CMD_Get_ActivityAlarm:
|
|
122
|
-
return ResolveUtil.getActivityAlarm(value);
|
|
123
|
-
case DeviceConst.CMD_Get_TotalData:
|
|
124
|
-
return ResolveUtil.getTotalStepData(value);
|
|
125
|
-
case DeviceConst.CMD_Get_DetailData:
|
|
126
|
-
return ResolveUtil.getDetailData(value);
|
|
127
|
-
case DeviceConst.CMD_Get_SleepData:
|
|
128
|
-
return ResolveUtil.getSleepData(value);
|
|
129
|
-
case DeviceConst.CMD_Get_HeartData:
|
|
130
|
-
return ResolveUtil.getHeartData(value);
|
|
131
|
-
case DeviceConst.CMD_Get_OnceHeartData:
|
|
132
|
-
return ResolveUtil.getOnceHeartData(value);
|
|
133
|
-
case DeviceConst.CMD_Get_HrvTestData:
|
|
134
|
-
return ResolveUtil.getHrvTestData(value);
|
|
135
|
-
case DeviceConst.CMD_Get_Clock: //获取闹钟数据
|
|
136
|
-
return ResolveUtil.getClockData(value);
|
|
137
|
-
case DeviceConst.CMD_Set_Clock:
|
|
138
|
-
return ResolveUtil.updateClockSuccessful(value);
|
|
139
|
-
case DeviceConst.CMD_Set_NewDeviceInfo:
|
|
140
|
-
return ResolveUtil.setNewDeviceInfo(value);
|
|
141
|
-
case DeviceConst.CMD_Get_NewDeviceInfo:
|
|
142
|
-
return ResolveUtil.getNewDeviceInfo(value);
|
|
143
|
-
case DeviceConst.Enter_photo_modeback:
|
|
144
|
-
return ResolveUtil.enterPhotoModeback(value);
|
|
145
|
-
case DeviceConst.Enter_photo_mode:
|
|
146
|
-
return ResolveUtil.setMethodSuccessful(BleConst.EnterPhotoMode);
|
|
147
|
-
case DeviceConst.Exit_photo_mode:
|
|
148
|
-
return ResolveUtil.setMethodSuccessful(BleConst.BackHomeView);
|
|
149
|
-
case DeviceConst.CMD_ECGQuality:
|
|
150
|
-
return ResolveUtil.eCGQuality(value);
|
|
151
|
-
case DeviceConst.CMD_ECGDATA:
|
|
152
|
-
case DeviceConst.CMD_PPGGDATA:
|
|
153
|
-
break;
|
|
154
|
-
case DeviceConst.Weather:
|
|
155
|
-
return ResolveUtil.setMethodSuccessful(BleConst.Weather);
|
|
156
|
-
case DeviceConst.Braceletdial:
|
|
157
|
-
return ResolveUtil.braceletdial(false, value); // isRunning 暂设为 false
|
|
158
|
-
case DeviceConst.SportMode:
|
|
159
|
-
return ResolveUtil.setMethodSuccessful(BleConst.SportMode);
|
|
160
|
-
case DeviceConst.GetSportMode:
|
|
161
|
-
return ResolveUtil.getSportMode(value);
|
|
162
|
-
case DeviceConst.MeasurementWithType:
|
|
163
|
-
return ResolveUtil.measurementWithType(true, value); // StartDeviceMeasurementWithType 设为 true
|
|
164
|
-
case DeviceConst.GPSControlCommand:
|
|
165
|
-
return ResolveUtil.gPSControlCommand(value);
|
|
166
|
-
case DeviceConst.CMD_Get_GPSDATA:
|
|
167
|
-
return ResolveUtil.getHistoryGpsData(value);
|
|
168
|
-
case DeviceConst.Clear_Bracelet_data:
|
|
169
|
-
return ResolveUtil.setMethodSuccessful(BleConst.Clear_Bracelet_data);
|
|
170
|
-
case DeviceConst.CMD_Get_Auto_Blood_oxygen:
|
|
171
|
-
return ResolveUtil.getAutoBloodOxygen(value);
|
|
172
|
-
case DeviceConst.CMD_Get_Blood_oxygen:
|
|
173
|
-
return ResolveUtil.getBloodoxygen(value);
|
|
174
|
-
case DeviceConst.CMD_SET_SOCIAL:
|
|
175
|
-
return ResolveUtil.setMethodSuccessful(BleConst.SocialdistanceSetting);
|
|
176
|
-
case DeviceConst.Sos:
|
|
177
|
-
return ResolveUtil.setMethodSuccessful(BleConst.Sos);
|
|
178
|
-
case DeviceConst.Temperature_history:
|
|
179
|
-
return ResolveUtil.getTempData(value);
|
|
180
|
-
case DeviceConst.GetAxillaryTemperatureDataWithMode:
|
|
181
|
-
return ResolveUtil.getTempDataer(value);
|
|
182
|
-
case DeviceConst.CMD_QrCode:
|
|
183
|
-
return ResolveUtil.getQrCode(value, false);
|
|
184
|
-
case DeviceConst.CMD_GET_BLOODSUGAR:
|
|
185
|
-
return ResolveUtil.setBoolSugarStatus(value);
|
|
186
|
-
case DeviceConst.CMD_GET_BLOODSUGAR_DATA:
|
|
187
|
-
return ResolveUtil.setBoolSugarValue(value);
|
|
188
|
-
case DeviceConst.GetEcgPpgStatus:
|
|
189
|
-
return ResolveUtil.ecgResult(value);
|
|
190
|
-
case DeviceConst.PregnancyCycle:
|
|
191
|
-
return ResolveUtil.readPregnancyCycle(value);
|
|
192
|
-
case DeviceConst.GetEcgSaveData:
|
|
193
|
-
return ResolveUtil.getEcgHistoryData(value);
|
|
194
|
-
case DeviceConst.WomenHealth:
|
|
195
|
-
if (value[1] === 0) {
|
|
196
|
-
return ResolveUtil.setMethodSuccessful(BleConst.SetWomenHealth);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
return ResolveUtil.readWomenHealth(value);
|
|
200
|
-
}
|
|
201
|
-
case DeviceConst.BloodsugarWithMode:
|
|
202
|
-
const ppi2 = this.hexByte2Int(value[2], 0);
|
|
203
|
-
switch (ppi2) {
|
|
204
|
-
case 1:
|
|
205
|
-
return ResolveUtil.setMethodSuccessful(BleConst.ppgStartSucessed);
|
|
206
|
-
case 2:
|
|
207
|
-
return ResolveUtil.setMethodSuccessful(BleConst.ppgResult);
|
|
208
|
-
case 3:
|
|
209
|
-
return ResolveUtil.setMethodSuccessful(BleConst.ppgStop);
|
|
210
|
-
case 4:
|
|
211
|
-
return ResolveUtil.setMethodSuccessful(BleConst.ppgMeasurementProgress);
|
|
212
|
-
case 5:
|
|
213
|
-
return ResolveUtil.setMethodSuccessful(BleConst.ppgQuit);
|
|
214
|
-
default:
|
|
215
|
-
return ResolveUtil.setMethodSuccessful(BleConst.ppgStartFailed);
|
|
216
|
-
}
|
|
217
|
-
case DeviceConst.CMD_Get_PPITestData:
|
|
218
|
-
return ResolveUtil.getPPITestData(value);
|
|
219
|
-
case DeviceConst.CMD_SETTING_HRV_TIME:
|
|
220
|
-
return ResolveUtil.getHrvTimeData(value);
|
|
221
|
-
case DeviceConst.CMD_CLOSE_DEVICE:
|
|
222
|
-
return ResolveUtil.closeDevices(value);
|
|
223
|
-
case DeviceConst.CMD_AUTO_CHECK_STATUS:
|
|
224
|
-
return ResolveUtil.getOffCheckStatus(value);
|
|
225
|
-
}
|
|
226
|
-
return ResolveUtil.setMethodError(this.getBcdValue(value[0]).toString());
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* 血糖
|
|
230
|
-
* @param ppgMode
|
|
231
|
-
* @param ppgStatus
|
|
232
|
-
* @returns
|
|
233
|
-
*/
|
|
234
|
-
static bloodsugarWithMode(ppgMode, ppgStatus) {
|
|
235
|
-
const value = this.generateInitValue();
|
|
236
|
-
value[0] = DeviceConst.BloodsugarWithMode;
|
|
237
|
-
value[1] = ppgMode;
|
|
238
|
-
if (ppgMode === 2 || ppgMode === 4) {
|
|
239
|
-
value[2] = ppgStatus;
|
|
240
|
-
}
|
|
241
|
-
this.crcValue(value);
|
|
242
|
-
return value;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
*
|
|
246
|
-
*获得睡眠详细数据
|
|
247
|
-
* @param {number} mode 0-读最近的睡眠详细数据 2-继续上次读的位置下一段数据 99-删除睡眠数据
|
|
248
|
-
* @return {*} {number[]} detailed sleep data
|
|
249
|
-
*/
|
|
250
|
-
static getDetailSleepDataWithMode(mode) {
|
|
251
|
-
const value = this.generateInitValue();
|
|
252
|
-
value[0] = DeviceConst.CMD_Get_SleepData;
|
|
253
|
-
value[1] = mode === 99 ? 0x99 : mode;
|
|
254
|
-
this.crcValue(value);
|
|
255
|
-
return value;
|
|
256
|
-
}
|
|
257
|
-
static insertDateValue(list, time) {
|
|
258
|
-
if (!time || time.length <= 0)
|
|
259
|
-
return;
|
|
260
|
-
const [datePart, timePart] = time.split(' ');
|
|
261
|
-
const [year, month, day] = datePart.split('-').map(Number);
|
|
262
|
-
const [hour, minute, second] = timePart.split(':').map(Number);
|
|
263
|
-
list[4] = this.getBcdValue(year - 2000);
|
|
264
|
-
list[5] = this.getBcdValue(month);
|
|
265
|
-
list[6] = this.getBcdValue(day);
|
|
266
|
-
list[7] = this.getBcdValue(hour);
|
|
267
|
-
list[8] = this.getBcdValue(minute);
|
|
268
|
-
list[9] = this.getBcdValue(second);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
*
|
|
272
|
-
*获得HRV测试数据
|
|
273
|
-
* @param {number} mode 0-读最近的详细数据 2-继续上次读的位置下一段数据 99-删除数据
|
|
274
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
275
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
276
|
-
*/
|
|
277
|
-
static getHRVDataWithMode(mode, time) {
|
|
278
|
-
const value = this.generateInitValue(); // 初始化 buffer
|
|
279
|
-
value[0] = DeviceConst.CMD_Get_HrvTestData;
|
|
280
|
-
if (mode === 99) {
|
|
281
|
-
value[1] = 0x99;
|
|
282
|
-
}
|
|
283
|
-
else if (mode === 0) {
|
|
284
|
-
value[1] = 0x00;
|
|
285
|
-
}
|
|
286
|
-
else if (mode === 1) {
|
|
287
|
-
value[1] = 0x01;
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
value[1] = 0x02;
|
|
291
|
-
}
|
|
292
|
-
this.insertDateValue(value, time);
|
|
293
|
-
this.crcValue(value);
|
|
294
|
-
return value;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
*
|
|
298
|
-
* ppi数据
|
|
299
|
-
* @param {number} mode
|
|
300
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
301
|
-
*/
|
|
302
|
-
static getPPIDDataWithMode(mode) {
|
|
303
|
-
const value = this.generateInitValue(); // 初始化 buffer
|
|
304
|
-
value[0] = DeviceConst.CMD_Get_PPITestData;
|
|
305
|
-
if (mode === 99) {
|
|
306
|
-
value[1] = 0x99;
|
|
307
|
-
}
|
|
308
|
-
else if (mode === 0) {
|
|
309
|
-
value[1] = 0x00;
|
|
310
|
-
}
|
|
311
|
-
else if (mode === 1) {
|
|
312
|
-
value[1] = 0x01;
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
value[1] = 0x02;
|
|
316
|
-
}
|
|
317
|
-
this.crcValue(value);
|
|
318
|
-
return value;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
*
|
|
322
|
-
* hrv测试数据
|
|
323
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
324
|
-
*/
|
|
325
|
-
static getHrvTestTime() {
|
|
326
|
-
const value = this.generateInitValue();
|
|
327
|
-
value[0] = DeviceConst.CMD_SETTING_HRV_TIME;
|
|
328
|
-
value[1] = 0x00;
|
|
329
|
-
this.crcValue(value);
|
|
330
|
-
return value;
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
*
|
|
334
|
-
* 设置Hrv测试时长
|
|
335
|
-
* @param {number} time
|
|
336
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
337
|
-
*/
|
|
338
|
-
static setHrvTestTime(time) {
|
|
339
|
-
const value = this.generateInitValue();
|
|
340
|
-
value[0] = DeviceConst.CMD_SETTING_HRV_TIME;
|
|
341
|
-
value[1] = 0x01;
|
|
342
|
-
value[2] = time;
|
|
343
|
-
this.crcValue(value);
|
|
344
|
-
return value;
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
*
|
|
348
|
-
* 断开蓝牙
|
|
349
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
350
|
-
*/
|
|
351
|
-
static closeBlueDevice() {
|
|
352
|
-
const value = this.generateInitValue();
|
|
353
|
-
value[0] = DeviceConst.CMD_CLOSE_DEVICE;
|
|
354
|
-
this.crcValue(value);
|
|
355
|
-
return value;
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
*
|
|
359
|
-
* 血糖开始测量
|
|
360
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
361
|
-
*/
|
|
362
|
-
static startBloodSugar() {
|
|
363
|
-
const value = this.generateInitValue();
|
|
364
|
-
value[0] = DeviceConst.CMD_GET_BLOODSUGAR;
|
|
365
|
-
value[1] = 0x01;
|
|
366
|
-
this.crcValue(value);
|
|
367
|
-
return value;
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
*
|
|
371
|
-
* 血糖进度设置
|
|
372
|
-
* @param {number} progress
|
|
373
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
374
|
-
*/
|
|
375
|
-
static progressBloodSugar(progress) {
|
|
376
|
-
const value = this.generateInitValue();
|
|
377
|
-
value[0] = DeviceConst.CMD_GET_BLOODSUGAR;
|
|
378
|
-
value[1] = 0x04;
|
|
379
|
-
value[2] = progress;
|
|
380
|
-
this.crcValue(value);
|
|
381
|
-
return value;
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
*
|
|
385
|
-
* 结束测量血糖
|
|
386
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
387
|
-
*/
|
|
388
|
-
static endBloodSugar() {
|
|
389
|
-
const value = this.generateInitValue();
|
|
390
|
-
value[0] = DeviceConst.CMD_GET_BLOODSUGAR;
|
|
391
|
-
value[1] = 0x03;
|
|
392
|
-
this.crcValue(value);
|
|
393
|
-
return value;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
*
|
|
397
|
-
* 获取某天总数据
|
|
398
|
-
* @param {number} mode 表⽰是从最新的位置开始读取(最多50组数据) 2:表⽰接着读取(当数据总数⼤于50的时候) 0x99:表⽰删除所有运动数据
|
|
399
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
400
|
-
*/
|
|
401
|
-
static getTotalActivityDataWithMode(mode) {
|
|
402
|
-
const value = this.generateInitValue(); // 初始化 buffer
|
|
403
|
-
value[0] = DeviceConst.CMD_Get_TotalData;
|
|
404
|
-
if (mode === 99) {
|
|
405
|
-
value[1] = 0x99;
|
|
406
|
-
}
|
|
407
|
-
else if (mode === 0) {
|
|
408
|
-
value[1] = 0x00;
|
|
409
|
-
}
|
|
410
|
-
else if (mode === 1) {
|
|
411
|
-
value[1] = 0x01;
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
value[1] = 0x02;
|
|
415
|
-
}
|
|
416
|
-
this.crcValue(value);
|
|
417
|
-
return value;
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
*
|
|
421
|
-
* /根据某个日期获取到最新的总数据
|
|
422
|
-
* @param {number} mode 0-表⽰是从最新的位置开始读取(最多50组数据) 2-表⽰接着读取(当数据总数⼤于50的时候) 99-表⽰删除所有运动数据
|
|
423
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
424
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
425
|
-
*/
|
|
426
|
-
static getTotalActivityDataWithModeForTime(mode, time) {
|
|
427
|
-
const value = this.generateInitValue(); // 初始化 buffer
|
|
428
|
-
value[0] = DeviceConst.CMD_Get_TotalData;
|
|
429
|
-
if (mode === 99) {
|
|
430
|
-
value[1] = 0x99;
|
|
431
|
-
}
|
|
432
|
-
else if (mode === 0) {
|
|
433
|
-
value[1] = 0x00;
|
|
434
|
-
}
|
|
435
|
-
else if (mode === 1) {
|
|
436
|
-
value[1] = 0x01;
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
value[1] = 0x02;
|
|
440
|
-
}
|
|
441
|
-
this.insertDateValue(value, time);
|
|
442
|
-
this.crcValue(value);
|
|
443
|
-
return value;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
*
|
|
447
|
-
* 获得睡眠详细数据
|
|
448
|
-
* @param {number} mode 0-读最近的睡眠详细数据 2-继续上次读的位置下一段数据 99-删除睡眠数据
|
|
449
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
450
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
451
|
-
*/
|
|
452
|
-
static getDetailSleepDataWithModeForTime(mode, time) {
|
|
453
|
-
const value = this.generateInitValue();
|
|
454
|
-
value[0] = DeviceConst.CMD_Get_SleepData;
|
|
455
|
-
value[1] = mode === 99 ? 0x99 : mode;
|
|
456
|
-
this.insertDateValue(value, time);
|
|
457
|
-
this.crcValue(value);
|
|
458
|
-
return value;
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
*
|
|
462
|
-
* 获得步数详细数据
|
|
463
|
-
|
|
464
|
-
* @param {number} mode 0-读最近的详细数据 2-继续上次读的位置下一段数据 99-删除数据
|
|
465
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
466
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
467
|
-
*/
|
|
468
|
-
static getDetailActivityDataWithModeForTime(mode, time) {
|
|
469
|
-
const value = this.generateInitValue();
|
|
470
|
-
value[0] = DeviceConst.CMD_Get_DetailData;
|
|
471
|
-
value[1] = mode === 99 ? 0x99 : mode;
|
|
472
|
-
this.insertDateValue(value, time);
|
|
473
|
-
this.crcValue(value);
|
|
474
|
-
return value;
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
*
|
|
478
|
-
* 自动测试温度数据
|
|
479
|
-
* @param {number} mode 0-读最近的详细数据 2-继续上次读的位置下一段数据 99-删除数据
|
|
480
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
481
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
482
|
-
*/
|
|
483
|
-
static getTemperature_historyDataWithMode(mode, time) {
|
|
484
|
-
const value = this.generateInitValue();
|
|
485
|
-
value[0] = DeviceConst.Temperature_history;
|
|
486
|
-
value[1] = mode === 99 ? 0x99 : mode;
|
|
487
|
-
this.insertDateValue(value, time);
|
|
488
|
-
this.crcValue(value);
|
|
489
|
-
return value;
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
*
|
|
493
|
-
* 手动测试温度数据
|
|
494
|
-
* @param {number} mode 0-读最近的详细数据 2-继续上次读的位置下一段数据 99-删除数据
|
|
495
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
496
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
497
|
-
*/
|
|
498
|
-
static getAxillaryTemperatureDataWithMode(mode, time) {
|
|
499
|
-
const value = this.generateInitValue();
|
|
500
|
-
value[0] = DeviceConst.GetAxillaryTemperatureDataWithMode;
|
|
501
|
-
if (mode === 99) {
|
|
502
|
-
value[1] = 0x99;
|
|
503
|
-
}
|
|
504
|
-
else if (mode === 0) {
|
|
505
|
-
value[1] = 0x00;
|
|
506
|
-
}
|
|
507
|
-
else if (mode === 1) {
|
|
508
|
-
value[1] = 0x01;
|
|
509
|
-
}
|
|
510
|
-
else {
|
|
511
|
-
value[1] = 0x02;
|
|
512
|
-
}
|
|
513
|
-
this.insertDateValue(value, time);
|
|
514
|
-
this.crcValue(value);
|
|
515
|
-
return value;
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
*
|
|
519
|
-
* 运动模式开关
|
|
520
|
-
* @param {number} activityMode 运动模式类型
|
|
521
|
-
* @param {number} WorkMode 1:开始 , 2:暂停, 3:继续, 4结束。5: 查询状态
|
|
522
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
523
|
-
*/
|
|
524
|
-
static enterActivityMode(activityMode, WorkMode) {
|
|
525
|
-
const value = this.generateInitValue();
|
|
526
|
-
value[0] = DeviceConst.CMD_Start_EXERCISE;
|
|
527
|
-
value[1] = WorkMode;
|
|
528
|
-
value[2] = activityMode;
|
|
529
|
-
this.crcValue(value);
|
|
530
|
-
return value;
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* 发送运动模式心跳包(配合"EnterActivityMode"使用)
|
|
534
|
-
* 当手环是通过APP进入多运动模式后,APP必须每隔1秒发送一个数据给手环,否则手环会退出多运动模式
|
|
535
|
-
* @param {number} distance 距离,浮点数。单位是KM。
|
|
536
|
-
* @param {number} space 配速度,MM:分钟,SS秒钟
|
|
537
|
-
* @param {number} rssi APPGPS信号强度。范围是:1,2,3
|
|
538
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
539
|
-
*/
|
|
540
|
-
static sendHeartPackage(distance, space, rssi) {
|
|
541
|
-
// 1. 初始化数据包(8 字节 + 1 字节 CRC => 总共 9 字节?根据协议可调)
|
|
542
|
-
const value = this.generateInitValue(); // 返回长度为 8 或 9 的数组
|
|
543
|
-
// 2. 拆分 space 为 分钟 和 秒
|
|
544
|
-
const min = Math.floor(space / 60) & 0xff;
|
|
545
|
-
const second = (space % 60) & 0xff;
|
|
546
|
-
// 3. 使用 DataView 写入 float32(小端序)
|
|
547
|
-
const buffer = new ArrayBuffer(4);
|
|
548
|
-
const dataView = new DataView(buffer);
|
|
549
|
-
dataView.setFloat32(0, distance, true); // true = little endian
|
|
550
|
-
const distanceBytes = Array.from(new Uint8Array(buffer)); // 转为 [b0, b1, b2, b3]
|
|
551
|
-
// 4. 组装数据包
|
|
552
|
-
value[0] = DeviceConst.CMD_heart_package;
|
|
553
|
-
this.arrayCopy(distanceBytes, 0, value, 1, distanceBytes.length);
|
|
554
|
-
value[5] = min;
|
|
555
|
-
value[6] = second;
|
|
556
|
-
value[7] = rssi & 0xff; // 确保是 1 字节
|
|
557
|
-
this.crcValue(value);
|
|
558
|
-
return value;
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
*
|
|
562
|
-
* 启动或关闭实时计步模式
|
|
563
|
-
* @param {boolean} enable 1:启动实时计步,0:关闭实时计步
|
|
564
|
-
* @param {boolean} tempEnable 1:开启实时温度 0:关闭实时温度
|
|
565
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
566
|
-
*/
|
|
567
|
-
static realTimeStep(enable, tempEnable) {
|
|
568
|
-
const value = this.generateInitValue();
|
|
569
|
-
value[0] = DeviceConst.CMD_Enable_Activity;
|
|
570
|
-
value[1] = enable ? 1 : 0;
|
|
571
|
-
value[2] = tempEnable ? 1 : 0;
|
|
572
|
-
this.crcValue(value);
|
|
573
|
-
return value;
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
*
|
|
577
|
-
* 停止实时计步
|
|
578
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
579
|
-
*/
|
|
580
|
-
static stopGo() {
|
|
581
|
-
const value = this.generateInitValue();
|
|
582
|
-
value[0] = DeviceConst.CMD_Enable_Activity;
|
|
583
|
-
value[1] = 0;
|
|
584
|
-
this.crcValue(value);
|
|
585
|
-
return value;
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* 设置个人信息
|
|
589
|
-
*
|
|
590
|
-
* @param {MyPersonalInfo} info
|
|
591
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
592
|
-
*/
|
|
593
|
-
static setPersonalInfo(info) {
|
|
594
|
-
const value = this.generateInitValue();
|
|
595
|
-
value[0] = DeviceConst.CMD_Set_UseInfo;
|
|
596
|
-
value[1] = info.sex;
|
|
597
|
-
value[2] = info.age;
|
|
598
|
-
value[3] = info.height;
|
|
599
|
-
value[4] = info.weight;
|
|
600
|
-
if (info.stepLength) {
|
|
601
|
-
value[5] = info.stepLength;
|
|
602
|
-
}
|
|
603
|
-
this.crcValue(value);
|
|
604
|
-
return value;
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
*
|
|
608
|
-
* 获取个人信息
|
|
609
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
610
|
-
*/
|
|
611
|
-
static getPersonalInfo() {
|
|
612
|
-
const value = this.generateInitValue(); // 初始化 buffer
|
|
613
|
-
value[0] = DeviceConst.CMD_GET_USERINFO;
|
|
614
|
-
this.crcValue(value);
|
|
615
|
-
return value;
|
|
616
|
-
}
|
|
617
|
-
///进入dfu模式
|
|
618
|
-
///Entering dfu mode
|
|
619
|
-
static enterOTA() {
|
|
620
|
-
const value = this.generateInitValue();
|
|
621
|
-
value[0] = DeviceConst.CMD_Start_Ota;
|
|
622
|
-
this.crcValue(value);
|
|
623
|
-
return value;
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
*
|
|
627
|
-
* 获取设备版本号
|
|
628
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
629
|
-
*/
|
|
630
|
-
static getDeviceVersion() {
|
|
631
|
-
const value = this.generateInitValue();
|
|
632
|
-
value[0] = DeviceConst.CMD_Get_Version;
|
|
633
|
-
this.crcValue(value);
|
|
634
|
-
return value;
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
*
|
|
638
|
-
* 恢复出厂设置
|
|
639
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
640
|
-
*/
|
|
641
|
-
static reset() {
|
|
642
|
-
const value = this.generateInitValue();
|
|
643
|
-
value[0] = DeviceConst.CMD_Reset;
|
|
644
|
-
this.crcValue(value);
|
|
645
|
-
return value;
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
*
|
|
649
|
-
* 获取设备mac地址
|
|
650
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
651
|
-
*/
|
|
652
|
-
static getDeviceMacAddress() {
|
|
653
|
-
const value = this.generateInitValue();
|
|
654
|
-
value[0] = DeviceConst.CMD_Get_Address;
|
|
655
|
-
this.crcValue(value);
|
|
656
|
-
return value;
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
*
|
|
660
|
-
* 获取设备电量
|
|
661
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
662
|
-
*/
|
|
663
|
-
static getDeviceBatteryLevel() {
|
|
664
|
-
const value = this.generateInitValue();
|
|
665
|
-
value[0] = DeviceConst.CMD_Get_BatteryLevel;
|
|
666
|
-
this.crcValue(value);
|
|
667
|
-
return value;
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
|
-
*
|
|
671
|
-
* 重启设备
|
|
672
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
673
|
-
*/
|
|
674
|
-
static mcuReset() {
|
|
675
|
-
const value = this.generateInitValue();
|
|
676
|
-
value[0] = DeviceConst.CMD_Mcu_Reset;
|
|
677
|
-
this.crcValue(value);
|
|
678
|
-
return value;
|
|
679
|
-
}
|
|
680
|
-
/**
|
|
681
|
-
* 设置设备名称
|
|
682
|
-
*
|
|
683
|
-
* @param {string} deviceName 设备名称(最多14个ASCII字符)
|
|
684
|
-
* @return {*} {number[]} 指令包(7字节)
|
|
685
|
-
*/
|
|
686
|
-
static setDeviceName(deviceName) {
|
|
687
|
-
const value = this.generateInitValue(); // 初始化7字节数组
|
|
688
|
-
const maxLength = 14;
|
|
689
|
-
const length = Math.min(deviceName.length, maxLength);
|
|
690
|
-
value[0] = DeviceConst.CMD_Set_Name;
|
|
691
|
-
// 写入设备名称(ASCII 编码)
|
|
692
|
-
for (let i = 0; i < length; i++) {
|
|
693
|
-
value[i + 1] = deviceName.charCodeAt(i); // 相当于 Dart 的 codeUnitAt(i)
|
|
694
|
-
}
|
|
695
|
-
// 填充剩余字节为 0(可选,保持干净)
|
|
696
|
-
for (let i = length + 1; i < 6; i++) {
|
|
697
|
-
value[i] = 0;
|
|
698
|
-
}
|
|
699
|
-
// 计算 CRC 并写入最后一个字节
|
|
700
|
-
this.crcValue(value);
|
|
701
|
-
return value;
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* 获取设备名称
|
|
705
|
-
* @return {*} {number[]} 指令包(7字节)
|
|
706
|
-
*/
|
|
707
|
-
static getDeviceName() {
|
|
708
|
-
const value = this.generateInitValue();
|
|
709
|
-
value[0] = DeviceConst.CMD_Get_Name;
|
|
710
|
-
// 其余字节保持为 0
|
|
711
|
-
for (let i = 1; i < 6; i++) {
|
|
712
|
-
value[i] = 0;
|
|
713
|
-
}
|
|
714
|
-
// 计算 CRC
|
|
715
|
-
this.crcValue(value);
|
|
716
|
-
return value;
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
*
|
|
720
|
-
* 设置设备时间
|
|
721
|
-
* @param {Date} dateTime
|
|
722
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
723
|
-
*/
|
|
724
|
-
static setDeviceTime(dateTime) {
|
|
725
|
-
const value = this.generateInitValue();
|
|
726
|
-
const year = dateTime.getFullYear();
|
|
727
|
-
const month = dateTime.getMonth() + 1;
|
|
728
|
-
const day = dateTime.getDate();
|
|
729
|
-
const hour = dateTime.getHours();
|
|
730
|
-
const minute = dateTime.getMinutes();
|
|
731
|
-
const second = dateTime.getSeconds();
|
|
732
|
-
value[0] = DeviceConst.CMD_SET_TIME;
|
|
733
|
-
value[1] = this.getBcdValue(year);
|
|
734
|
-
value[2] = this.getBcdValue(month);
|
|
735
|
-
value[3] = this.getBcdValue(day);
|
|
736
|
-
value[4] = this.getBcdValue(hour);
|
|
737
|
-
value[5] = this.getBcdValue(minute);
|
|
738
|
-
value[6] = this.getBcdValue(second);
|
|
739
|
-
this.crcValue(value);
|
|
740
|
-
return value;
|
|
741
|
-
}
|
|
742
|
-
/**
|
|
743
|
-
*
|
|
744
|
-
* 获取设备时间
|
|
745
|
-
* @return {*} {number[]}
|
|
746
|
-
*/
|
|
747
|
-
static getDeviceTime() {
|
|
748
|
-
const value = this.generateInitValue();
|
|
749
|
-
value[0] = DeviceConst.CMD_GET_TIME;
|
|
750
|
-
this.crcValue(value);
|
|
751
|
-
return value;
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
*
|
|
755
|
-
* 设置设备信息
|
|
756
|
-
* @param {MyDeviceInfo} deviceBaseParameter
|
|
757
|
-
* @return {*} {number[]}
|
|
758
|
-
*/
|
|
759
|
-
static setDeviceInfo(deviceBaseParameter) {
|
|
760
|
-
const value = this.generateInitValue();
|
|
761
|
-
value[0] = DeviceConst.CMD_Set_DeviceInfo;
|
|
762
|
-
value[1] = deviceBaseParameter.DistanceUnit ? 0x81 : 0x80;
|
|
763
|
-
value[2] = deviceBaseParameter.is12Hour ? 0x81 : 0x80;
|
|
764
|
-
value[3] = deviceBaseParameter.Hand_up_light_screen_switch ? 0x81 : 0x80;
|
|
765
|
-
value[4] = !deviceBaseParameter.Fahrenheit ? 0x81 : 0x80;
|
|
766
|
-
value[5] = deviceBaseParameter.Nightmode ? 0x81 : 0x80;
|
|
767
|
-
value[6] = 0x80;
|
|
768
|
-
value[9] = 0x80 + deviceBaseParameter.baseheart;
|
|
769
|
-
value[11] = 0x80 + deviceBaseParameter.screenBrightness;
|
|
770
|
-
value[12] = 0x80 + deviceBaseParameter.indexDial;
|
|
771
|
-
value[14] = 0x80 + deviceBaseParameter.languages;
|
|
772
|
-
this.crcValue(value);
|
|
773
|
-
return value;
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
*健康测量控制
|
|
777
|
-
*
|
|
778
|
-
* @param {number} dataType 测试类型 0x01,HRV 0x02,心率测量 0x03,血氧测量
|
|
779
|
-
* @param {boolean} open 1开启测量 0 关闭测量
|
|
780
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
781
|
-
*/
|
|
782
|
-
static healthMeasurementWithDataType(dataType, open) {
|
|
783
|
-
this.StartDeviceMeasurementWithType = open;
|
|
784
|
-
const value = this.generateInitValue();
|
|
785
|
-
value[0] = DeviceConst.MeasurementWithType;
|
|
786
|
-
value[1] = dataType;
|
|
787
|
-
value[2] = open ? 0x01 : 0x00;
|
|
788
|
-
this.crcValue(value);
|
|
789
|
-
return value;
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
*
|
|
793
|
-
* 设置手环表盘模式
|
|
794
|
-
* @param {number} mode 表盘模式(0, 1, 2... 根据设备定义)
|
|
795
|
-
* @return {*} {number[]} 指令包(7字节)
|
|
796
|
-
*/
|
|
797
|
-
static setBraceletdial(mode) {
|
|
798
|
-
// 设置运行状态(可选,用于控制流程)
|
|
799
|
-
this.isRuning = true;
|
|
800
|
-
const value = this.generateInitValue(); // 初始化 7 字节数组
|
|
801
|
-
value[0] = DeviceConst.Braceletdial; // 命令字
|
|
802
|
-
value[1] = mode; // 模式值
|
|
803
|
-
this.crcValue(value);
|
|
804
|
-
return value;
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
*
|
|
808
|
-
* 设置自动检测心率时段
|
|
809
|
-
* @param {MyAutomaticHRMonitoring} autoHeart
|
|
810
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
811
|
-
*/
|
|
812
|
-
static setAutomaticHRMonitoring(autoHeart) {
|
|
813
|
-
const value = this.generateInitValue();
|
|
814
|
-
const time = autoHeart.time;
|
|
815
|
-
value[0] = DeviceConst.CMD_Set_AutoHeart;
|
|
816
|
-
value[1] = autoHeart.open;
|
|
817
|
-
value[2] = this.getBcdValue(autoHeart.startHour);
|
|
818
|
-
value[3] = this.getBcdValue(autoHeart.startMinute);
|
|
819
|
-
value[4] = this.getBcdValue(autoHeart.endHour);
|
|
820
|
-
value[5] = this.getBcdValue(autoHeart.endMinute);
|
|
821
|
-
value[6] = autoHeart.week;
|
|
822
|
-
value[7] = (time & 0xff);
|
|
823
|
-
value[8] = ((time >> 8) & 0xff);
|
|
824
|
-
value[9] = autoHeart.type;
|
|
825
|
-
this.crcValue(value);
|
|
826
|
-
return value;
|
|
827
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
*
|
|
830
|
-
* 读取自动检测心率时段
|
|
831
|
-
* @param {number} type 1、读取心率设置时间 2、读取设置血氧时间 4、读取HRV设置时间段
|
|
832
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
833
|
-
*/
|
|
834
|
-
static getAutomaticHRMonitoring(type) {
|
|
835
|
-
const value = this.generateInitValue();
|
|
836
|
-
value[0] = DeviceConst.CMD_Get_AutoHeart;
|
|
837
|
-
value[1] = type;
|
|
838
|
-
this.crcValue(value);
|
|
839
|
-
return value;
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
*
|
|
843
|
-
*获取多模式运动数据
|
|
844
|
-
* @param {number} mode 0:表⽰是从最新的位置开始读取(最多50组数据) 2:表⽰接着读取(当数据总数⼤于50的时候) 0x99:表⽰删除所有GPS数据
|
|
845
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
846
|
-
*/
|
|
847
|
-
static getActivityModeDataWithMode(mode) {
|
|
848
|
-
const value = this.generateInitValue();
|
|
849
|
-
value[0] = DeviceConst.CMD_Get_SPORTData;
|
|
850
|
-
value[1] = mode;
|
|
851
|
-
this.crcValue(value);
|
|
852
|
-
return value;
|
|
853
|
-
}
|
|
854
|
-
/**
|
|
855
|
-
*
|
|
856
|
-
* 获得单次心率数据(间隔测试心率)
|
|
857
|
-
* @param {number} mode 0-读最近的详细数据 2-继续上次读的位置下一段数据 99-删除数据
|
|
858
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
859
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
860
|
-
*/
|
|
861
|
-
static getStaticHRWithMode(mode, time) {
|
|
862
|
-
const value = this.generateInitValue();
|
|
863
|
-
value[0] = DeviceConst.CMD_Get_OnceHeartData;
|
|
864
|
-
value[1] = mode;
|
|
865
|
-
this.insertDateValue(value, time);
|
|
866
|
-
this.crcValue(value);
|
|
867
|
-
return value;
|
|
868
|
-
}
|
|
869
|
-
/**
|
|
870
|
-
*
|
|
871
|
-
* 获得心率数据
|
|
872
|
-
* @param {number} mode 0-读最近的详细数据 2-继续上次读的位置下一段数据 99-删除数据
|
|
873
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
874
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
875
|
-
*/
|
|
876
|
-
static getDynamicHRWithMode(mode, time) {
|
|
877
|
-
const value = this.generateInitValue();
|
|
878
|
-
value[0] = DeviceConst.CMD_Get_HeartData;
|
|
879
|
-
value[1] = mode;
|
|
880
|
-
this.insertDateValue(value, time);
|
|
881
|
-
this.crcValue(value);
|
|
882
|
-
return value;
|
|
883
|
-
}
|
|
884
|
-
/**
|
|
885
|
-
*
|
|
886
|
-
* 获得血氧数据
|
|
887
|
-
* @param {number} mode 0-读最近的详细数据 2-继续上次读的位置下一段数据 99-删除数据
|
|
888
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
889
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
890
|
-
*/
|
|
891
|
-
static getBloodOxygen(mode, time) {
|
|
892
|
-
const value = this.generateInitValue();
|
|
893
|
-
value[0] = DeviceConst.CMD_Get_Blood_oxygen;
|
|
894
|
-
value[1] = mode;
|
|
895
|
-
this.insertDateValue(value, time);
|
|
896
|
-
this.crcValue(value);
|
|
897
|
-
return value;
|
|
898
|
-
}
|
|
899
|
-
/**
|
|
900
|
-
*
|
|
901
|
-
* 获得血氧数据(自动测试)
|
|
902
|
-
* @param {number} mode 0-读最近的详细数据 2-继续上次读的位置下一段数据 99-删除数据
|
|
903
|
-
* @param {string} time yyyy-MM-dd HH:mm:ss
|
|
904
|
-
* @return {*} {number[]}
|
|
905
|
-
*/
|
|
906
|
-
static getAutoBloodOxygen(mode, time) {
|
|
907
|
-
const value = this.generateInitValue();
|
|
908
|
-
value[0] = DeviceConst.CMD_Get_Auto_Blood_oxygen;
|
|
909
|
-
value[1] = mode;
|
|
910
|
-
this.insertDateValue(value, time);
|
|
911
|
-
this.crcValue(value);
|
|
912
|
-
return value;
|
|
913
|
-
}
|
|
914
|
-
/**
|
|
915
|
-
* 设置目标步数指令
|
|
916
|
-
* @param stepGoal 步数目标 (int, 4 bytes, Big-Endian)
|
|
917
|
-
* @param targetExecutionTime 目标完成时间(分钟)(int, 2 bytes)
|
|
918
|
-
* @param distance 距离目标(千米)(int, 2 bytes)
|
|
919
|
-
* @param calorie 卡路里目标 (int, 2 bytes)
|
|
920
|
-
* @param sleepTime 睡眠时间目标(分钟)(int, 2 bytes)
|
|
921
|
-
* @returns number[] 指令字节数组(16字节,含CRC)
|
|
922
|
-
*/
|
|
923
|
-
static setStepGoal(stepGoal, targetExecutionTime, distance, calorie, sleepTime) {
|
|
924
|
-
// 1. 初始化 16 字节数组,填充 0
|
|
925
|
-
const value = this.generateInitValue();
|
|
926
|
-
value[0] = DeviceConst.CMD_Set_Goal;
|
|
927
|
-
;
|
|
928
|
-
// 3. 写入 stepGoal (4 bytes, Big-Endian: 高位在后)
|
|
929
|
-
value[4] = (stepGoal >> 24) & 0xff;
|
|
930
|
-
value[3] = (stepGoal >> 16) & 0xff;
|
|
931
|
-
value[2] = (stepGoal >> 8) & 0xff;
|
|
932
|
-
value[1] = stepGoal & 0xff;
|
|
933
|
-
// 4. 写入 targetExecutionTime (2 bytes, Big-Endian)
|
|
934
|
-
value[6] = (targetExecutionTime >> 8) & 0xff;
|
|
935
|
-
value[5] = targetExecutionTime & 0xff;
|
|
936
|
-
// 5. 写入 distance (2 bytes, Big-Endian)
|
|
937
|
-
value[8] = (distance >> 8) & 0xff;
|
|
938
|
-
value[7] = distance & 0xff;
|
|
939
|
-
// 6. 写入 calorie (2 bytes, Big-Endian)
|
|
940
|
-
value[10] = (calorie >> 8) & 0xff;
|
|
941
|
-
value[9] = calorie & 0xff;
|
|
942
|
-
// 7. 写入 sleepTime (2 bytes, Big-Endian)
|
|
943
|
-
value[12] = (sleepTime >> 8) & 0xff;
|
|
944
|
-
value[11] = sleepTime & 0xff;
|
|
945
|
-
this.crcValue(value);
|
|
946
|
-
return value;
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
*
|
|
950
|
-
* 读取目标步数
|
|
951
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
952
|
-
*/
|
|
953
|
-
static GetStepGoal() {
|
|
954
|
-
const value = this.generateInitValue();
|
|
955
|
-
value[0] = DeviceConst.CMD_Get_Goal;
|
|
956
|
-
this.crcValue(value);
|
|
957
|
-
return value;
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* 获取手环基本参数(设备信息)
|
|
961
|
-
* @returns Uint8Array 指令包(7字节),用于发送 BLE 请求
|
|
962
|
-
*/
|
|
963
|
-
static getDeviceInfo() {
|
|
964
|
-
const value = this.generateInitValue();
|
|
965
|
-
value[0] = DeviceConst.CMD_Get_DeviceInfo; // 设置命令字
|
|
966
|
-
this.crcValue(value);
|
|
967
|
-
return value;
|
|
968
|
-
}
|
|
969
|
-
static sendHex(data, isCrc) {
|
|
970
|
-
const current = [...data];
|
|
971
|
-
if (isCrc) {
|
|
972
|
-
this.crcDynamicValue(current);
|
|
973
|
-
}
|
|
974
|
-
return current;
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
*
|
|
978
|
-
* 获取闹钟
|
|
979
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
980
|
-
*/
|
|
981
|
-
static getAlarmClock() {
|
|
982
|
-
const value = this.generateInitValue();
|
|
983
|
-
value[0] = DeviceConst.CMD_Get_Clock;
|
|
984
|
-
this.crcValue(value);
|
|
985
|
-
return value;
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
*
|
|
989
|
-
* 删除所有闹钟
|
|
990
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
991
|
-
*/
|
|
992
|
-
static deleteAllAlarmClock() {
|
|
993
|
-
const value = this.generateInitValue();
|
|
994
|
-
value[0] = DeviceConst.CMD_Get_Clock;
|
|
995
|
-
value[1] = 0x99;
|
|
996
|
-
this.crcValue(value);
|
|
997
|
-
return value;
|
|
998
|
-
}
|
|
999
|
-
/**
|
|
1000
|
-
*
|
|
1001
|
-
*设置所有闹钟
|
|
1002
|
-
* @param {any[]} arrayClockAlarm
|
|
1003
|
-
* @return {*} {number[][]}
|
|
1004
|
-
*/
|
|
1005
|
-
static setAlarmClock(arrayClockAlarm) {
|
|
1006
|
-
const result = [];
|
|
1007
|
-
const LENGTH_UNIT = 39;
|
|
1008
|
-
const MAX_SEND_BYTES = 128;
|
|
1009
|
-
const totalCount = arrayClockAlarm.length * LENGTH_UNIT + 2;
|
|
1010
|
-
if (totalCount > MAX_SEND_BYTES) {
|
|
1011
|
-
// 超过一次发送的长度,需要分包
|
|
1012
|
-
const canSendCount = Math.floor(MAX_SEND_BYTES / LENGTH_UNIT);
|
|
1013
|
-
const needSendCount = Math.ceil(arrayClockAlarm.length / canSendCount);
|
|
1014
|
-
for (let i = 0; i < needSendCount; i++) {
|
|
1015
|
-
const isLast = i === needSendCount - 1;
|
|
1016
|
-
const countInThisPacket = isLast ? arrayClockAlarm.length - canSendCount * i : canSendCount;
|
|
1017
|
-
const buffer = new Array(countInThisPacket * LENGTH_UNIT + (isLast ? 2 : 0)).fill(0);
|
|
1018
|
-
for (let m = 0; m < countInThisPacket; m++) {
|
|
1019
|
-
const dicClock = arrayClockAlarm[canSendCount * i + m];
|
|
1020
|
-
const { openOrClose, clockType, clockTime, week, textLength, text } = dicClock;
|
|
1021
|
-
const offset = m * LENGTH_UNIT;
|
|
1022
|
-
buffer[offset] = 0x23;
|
|
1023
|
-
buffer[offset + 1] = arrayClockAlarm.length;
|
|
1024
|
-
buffer[offset + 2] = canSendCount * i + m;
|
|
1025
|
-
buffer[offset + 3] = openOrClose;
|
|
1026
|
-
buffer[offset + 4] = clockType;
|
|
1027
|
-
buffer[offset + 5] = this.getBcdValue(clockTime.substring(0, 2));
|
|
1028
|
-
buffer[offset + 6] = this.getBcdValue(clockTime.substring(3, 5));
|
|
1029
|
-
buffer[offset + 7] = week;
|
|
1030
|
-
buffer[offset + 8] = textLength;
|
|
1031
|
-
for (let j = 0; j < textLength; j++) {
|
|
1032
|
-
buffer[offset + 9 + j] = text.charCodeAt(j) || 0;
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
if (isLast) {
|
|
1036
|
-
buffer[buffer.length - 2] = 0x23;
|
|
1037
|
-
buffer[buffer.length - 1] = 0xff;
|
|
1038
|
-
}
|
|
1039
|
-
result.push(buffer);
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
else {
|
|
1043
|
-
const buffer = new Array(totalCount).fill(0);
|
|
1044
|
-
arrayClockAlarm.forEach((dicClock, i) => {
|
|
1045
|
-
const { openOrClose, clockType, clockTime, week, textLength, text } = dicClock;
|
|
1046
|
-
const offset = i * LENGTH_UNIT;
|
|
1047
|
-
buffer[offset] = 0x23;
|
|
1048
|
-
buffer[offset + 1] = arrayClockAlarm.length;
|
|
1049
|
-
buffer[offset + 2] = i;
|
|
1050
|
-
buffer[offset + 3] = openOrClose;
|
|
1051
|
-
buffer[offset + 4] = clockType;
|
|
1052
|
-
buffer[offset + 5] = this.getBcdValue(clockTime.substring(0, 2));
|
|
1053
|
-
buffer[offset + 6] = this.getBcdValue(clockTime.substring(3, 5));
|
|
1054
|
-
buffer[offset + 7] = week;
|
|
1055
|
-
buffer[offset + 8] = textLength;
|
|
1056
|
-
for (let j = 0; j < textLength; j++) {
|
|
1057
|
-
buffer[offset + 9 + j] = text.charCodeAt(j) || 0;
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
buffer[totalCount - 2] = 0x23;
|
|
1061
|
-
buffer[totalCount - 1] = 0xff;
|
|
1062
|
-
result.push(buffer);
|
|
1063
|
-
}
|
|
1064
|
-
return result;
|
|
1065
|
-
}
|
|
1066
|
-
/**
|
|
1067
|
-
*
|
|
1068
|
-
* 获取久坐提醒
|
|
1069
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
1070
|
-
*/
|
|
1071
|
-
static getSedentaryReminder() {
|
|
1072
|
-
const value = this.generateInitValue();
|
|
1073
|
-
value[0] = DeviceConst.CMD_Get_ActivityAlarm;
|
|
1074
|
-
this.crcValue(value);
|
|
1075
|
-
return value;
|
|
1076
|
-
}
|
|
1077
|
-
/**
|
|
1078
|
-
* 设置久坐提醒
|
|
1079
|
-
*
|
|
1080
|
-
* @param {MySedentaryReminderV4} reminder
|
|
1081
|
-
* @return {*} {number[]} 指令包,给固件发生指令
|
|
1082
|
-
*/
|
|
1083
|
-
static setSedentaryReminder(reminder) {
|
|
1084
|
-
const value = this.generateInitValue();
|
|
1085
|
-
value[0] = DeviceConst.CMD_Set_ActivityAlarm;
|
|
1086
|
-
value[1] = this.getBcdValue(reminder.startTime_Hour);
|
|
1087
|
-
value[2] = this.getBcdValue(reminder.startTime_Minutes);
|
|
1088
|
-
value[3] = this.getBcdValue(reminder.endTime_Hour);
|
|
1089
|
-
value[4] = this.getBcdValue(reminder.endTime_Minutes);
|
|
1090
|
-
const week = (reminder.weeks.sunday ? 1 : 0) +
|
|
1091
|
-
(reminder.weeks.monday ? 2 : 0) +
|
|
1092
|
-
(reminder.weeks.Tuesday ? 4 : 0) +
|
|
1093
|
-
(reminder.weeks.Wednesday ? 8 : 0) +
|
|
1094
|
-
(reminder.weeks.Thursday ? 16 : 0) +
|
|
1095
|
-
(reminder.weeks.Friday ? 32 : 0) +
|
|
1096
|
-
(reminder.weeks.Saturday ? 64 : 0);
|
|
1097
|
-
value[5] = week;
|
|
1098
|
-
value[6] = reminder.intervalTime;
|
|
1099
|
-
value[7] = reminder.leastSteps;
|
|
1100
|
-
value[8] = reminder.mode;
|
|
1101
|
-
this.crcValue(value);
|
|
1102
|
-
return value;
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
export default BleSDK;
|
|
1106
|
-
//# sourceMappingURL=bleSDK.js.map
|