capacitor-plugin-ihealth 1.1.1 → 1.1.3
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/README.md +6 -6
- package/android/build.gradle +23 -2
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/assets/libiHealth.so +0 -0
- package/android/src/main/assets/libs/arm64-v8a/libBodyfat_SDK.so +0 -0
- package/android/src/main/assets/libs/arm64-v8a/libECGOffline.so +0 -0
- package/android/src/main/assets/libs/arm64-v8a/libECGOnline.so +0 -0
- package/android/src/main/assets/libs/arm64-v8a/libVeryFitMulti.so +0 -0
- package/android/src/main/assets/libs/arm64-v8a/libiHealth.so +0 -0
- package/android/src/main/java/com/managemyhealth/plugins/ihealth/BaseApplication.java +51 -0
- package/android/src/main/java/com/managemyhealth/plugins/ihealth/DeviceCharacteristic.java +49 -0
- package/android/src/main/java/com/managemyhealth/plugins/ihealth/ihealthPlugin.java +1966 -3
- package/android/src/main/libiHealth.so +0 -0
- package/dist/docs.json +3 -3
- package/dist/esm/definitions.d.ts +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/ihealthPlugin.swift +50 -18
- package/package.json +1 -1
@@ -1,22 +1,1985 @@
|
|
1
1
|
package com.managemyhealth.plugins.ihealth;
|
2
2
|
|
3
|
+
import android.annotation.SuppressLint;
|
4
|
+
import android.bluetooth.BluetoothAdapter;
|
5
|
+
import android.os.Bundle;
|
6
|
+
import android.os.Handler;
|
7
|
+
import android.os.Looper;
|
8
|
+
import android.os.Message;
|
9
|
+
import android.util.Log;
|
10
|
+
|
11
|
+
import androidx.annotation.NonNull;
|
12
|
+
|
3
13
|
import com.getcapacitor.JSObject;
|
4
14
|
import com.getcapacitor.Plugin;
|
5
15
|
import com.getcapacitor.PluginCall;
|
6
16
|
import com.getcapacitor.PluginMethod;
|
7
17
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
18
|
+
import java.io.InputStream;
|
19
|
+
import java.util.ArrayList;
|
20
|
+
import java.util.Date;
|
21
|
+
|
22
|
+
import com.ihealth.communication.control.Bg5sControl;
|
23
|
+
import com.ihealth.communication.control.Bg5sProfile;
|
24
|
+
import com.ihealth.communication.control.Bp550BTControl;
|
25
|
+
import com.ihealth.communication.control.Bp5sControl;
|
26
|
+
import com.ihealth.communication.control.BpProfile;
|
27
|
+
import com.ihealth.communication.control.Hs2sControl;
|
28
|
+
import com.ihealth.communication.control.Hs4sControl;
|
29
|
+
import com.ihealth.communication.control.HsProfile;
|
30
|
+
import com.ihealth.communication.control.Hs2sProfile;//hs2s profile
|
31
|
+
import com.ihealth.communication.control.Po3Control;
|
32
|
+
import com.ihealth.communication.control.PoProfile;
|
33
|
+
import com.ihealth.communication.control.Pt3sbtControl;
|
34
|
+
import com.ihealth.communication.control.Pt3sbtProfile;
|
35
|
+
import com.ihealth.communication.control.UpgradeProfile;
|
36
|
+
import com.ihealth.communication.manager.DiscoveryTypeEnum;
|
37
|
+
import com.ihealth.communication.manager.iHealthDevicesCallback;
|
38
|
+
import com.ihealth.communication.manager.iHealthDevicesManager;
|
39
|
+
|
40
|
+
import org.json.JSONArray;
|
41
|
+
import org.json.JSONException;
|
42
|
+
import org.json.JSONObject;
|
43
|
+
import org.json.JSONTokener;
|
44
|
+
//
|
45
|
+
|
46
|
+
import java.util.Calendar;
|
47
|
+
|
48
|
+
import java.util.Map;
|
49
|
+
|
50
|
+
|
8
51
|
|
9
52
|
@CapacitorPlugin(name = "ihealth")
|
10
53
|
public class ihealthPlugin extends Plugin {
|
11
54
|
|
55
|
+
private int mClientCallbackId;
|
56
|
+
private int mScanClientCallbackId;
|
57
|
+
private int mConnectDeviceClientCallbackId;
|
58
|
+
|
59
|
+
public static final String PageLogTag = "MMH-IHEALTH-LOG >> ";
|
60
|
+
public static final int HANDLER_SCAN = 101;
|
61
|
+
public static final int HANDLER_CONNECTED = 102;
|
62
|
+
public static final int HANDLER_DISCONNECT = 103;
|
63
|
+
public static final int HANDLER_CONNECT_FAIL = 104;
|
64
|
+
public static final int HANDLER_RECONNECT = 105;
|
65
|
+
|
66
|
+
public static final int HANDLER_MESSAGE = 101;
|
67
|
+
|
68
|
+
ArrayList<String> test_user_id = new ArrayList<String>();
|
69
|
+
public int Hs2sCounter=0;
|
70
|
+
|
71
|
+
public String Bp5scount=null;
|
72
|
+
public JSONArray hs2sDeviceUserInfo = new JSONArray();
|
73
|
+
public int Bp5sDataCount=0;
|
74
|
+
public String Hs2suserdata="";
|
75
|
+
public String Bp5suserdata="";
|
76
|
+
public String Bp5sLivedata="";
|
77
|
+
public boolean notify = false;
|
78
|
+
public boolean offlineDataFound = false;
|
79
|
+
public boolean liveDataFound = false;
|
80
|
+
|
81
|
+
public boolean hs2sOffline = false;
|
82
|
+
public boolean hs2sanonym = false;
|
83
|
+
public boolean deviceDiscover = false;
|
84
|
+
public boolean deviceConnect = false;
|
85
|
+
public boolean deviceConnectFail = false;
|
86
|
+
public boolean deviceDisconnect = false;
|
87
|
+
public boolean isDisconnectReq = false;
|
88
|
+
public boolean isDevicePairingReq = false;
|
89
|
+
|
90
|
+
private Bg5sControl mBg5sControl;
|
91
|
+
private Bp550BTControl mBp550btControl;
|
92
|
+
|
93
|
+
private Bp5sControl mBp5sControl;
|
94
|
+
|
95
|
+
private Pt3sbtControl mPt3sbtControl;
|
96
|
+
|
97
|
+
private Po3Control mPo3Control;
|
98
|
+
|
99
|
+
private Hs4sControl mHs4SControl;
|
100
|
+
|
101
|
+
private Hs2sControl mHs2SControl;
|
102
|
+
private Date date = new Date();
|
103
|
+
|
104
|
+
|
105
|
+
String deviceName, deviceMac;
|
106
|
+
String deviceModel,deviceTypeG;
|
107
|
+
|
12
108
|
private ihealth implementation = new ihealth();
|
13
109
|
|
110
|
+
ihealthPlugin context = this;
|
111
|
+
|
112
|
+
@PluginMethod
|
113
|
+
public void authoriseiHealthSdk(PluginCall call) {
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
showLog("authorizeSDK() CALLED");
|
118
|
+
try {
|
119
|
+
|
120
|
+
InputStream is = BaseApplication.applicationContext.getAssets().open("com_medtechglobal_managemyhealth_uk_android.pem");
|
121
|
+
int size = is.available();
|
122
|
+
byte[] buffer = new byte[size];
|
123
|
+
is.read(buffer);
|
124
|
+
is.close();
|
125
|
+
new Handler().postDelayed(new Runnable() {
|
126
|
+
@Override
|
127
|
+
public void run() {
|
128
|
+
try {
|
129
|
+
showLog("inside try");
|
130
|
+
boolean isPass = iHealthDevicesManager.getInstance().sdkAuthWithLicense(buffer);
|
131
|
+
showLog("isPass");
|
132
|
+
showLog(String.valueOf(isPass));
|
133
|
+
if (isPass){
|
134
|
+
showLog("SDK Authorization PASS");
|
135
|
+
call.resolve();
|
136
|
+
}
|
137
|
+
else {
|
138
|
+
showLog("SDK Authorization FAILED");
|
139
|
+
}
|
140
|
+
}catch (Exception e){
|
141
|
+
showLog("try-----------eeee");
|
142
|
+
showLog(e.toString());
|
143
|
+
showLog("try-----------eeee close");
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
}
|
148
|
+
}, 0);
|
149
|
+
|
150
|
+
} catch (Exception e) {
|
151
|
+
showLog("SDK Authorization >> ERROR OCCURRED");
|
152
|
+
e.printStackTrace();
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
14
157
|
@PluginMethod
|
15
|
-
public void
|
16
|
-
|
158
|
+
public void startBP5SMeasurement(PluginCall call) {
|
159
|
+
Bp5suserdata = "";
|
160
|
+
mBp5sControl.startMeasure();
|
161
|
+
}
|
162
|
+
@PluginMethod
|
163
|
+
public void getConnectedDeviceInstance(PluginCall call) {
|
164
|
+
mClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
165
|
+
// iHealthDevicesManager.getInstance().addCallbackFilterForDeviceType(mClientCallbackId, deviceTypeG);
|
166
|
+
mBp5sControl = iHealthDevicesManager.getInstance().getBp5sControl(deviceMac);
|
167
|
+
|
168
|
+
}
|
169
|
+
@PluginMethod
|
170
|
+
public void scanDiscover(PluginCall call) {
|
171
|
+
showLog("date.toString()====================================");
|
172
|
+
showLog(date.toString());
|
173
|
+
resetData();
|
174
|
+
String devicemodel = call.getString("deviceModel");
|
175
|
+
deviceModel= devicemodel;
|
176
|
+
switch (deviceModel){
|
177
|
+
case "HS4S":
|
178
|
+
selectHS4SAndScan();
|
179
|
+
break;
|
180
|
+
case "HS2S":
|
181
|
+
selectHS2SAndScan();
|
182
|
+
break;
|
183
|
+
case "KN-550BT":
|
184
|
+
selectBPTrackAndScan();
|
185
|
+
break;
|
186
|
+
case "BP5S":
|
187
|
+
selectBP5SAndScan();
|
188
|
+
break;
|
189
|
+
case "BG5S":
|
190
|
+
selectBG5SAndScan();
|
191
|
+
break;
|
192
|
+
case "PO3":
|
193
|
+
selectPO3AndScan();
|
194
|
+
break;
|
195
|
+
case "PT3SBT":
|
196
|
+
selectPT3SBTAndScan();
|
197
|
+
|
198
|
+
break;
|
199
|
+
default:
|
200
|
+
break;
|
201
|
+
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
public void resetData(){
|
206
|
+
Hs2sCounter=0;
|
207
|
+
Bp5scount=null;
|
208
|
+
hs2sDeviceUserInfo = new JSONArray();
|
209
|
+
Bp5sDataCount=0;
|
210
|
+
Hs2suserdata="";
|
211
|
+
Bp5suserdata="";
|
212
|
+
Bp5sLivedata="";
|
213
|
+
notify = false;
|
214
|
+
offlineDataFound = false;
|
215
|
+
hs2sOffline = false;
|
216
|
+
hs2sanonym = false;
|
217
|
+
liveDataFound = false;
|
218
|
+
isDisconnectReq = false;
|
219
|
+
isDevicePairingReq = false;
|
220
|
+
// mBg5sControl=null;
|
221
|
+
// mBp550btControl=null;
|
222
|
+
// mBp5sControl=null;
|
223
|
+
// mPt3sbtControl=null;
|
224
|
+
// mPo3Control=null;
|
225
|
+
// mHs4SControl=null;
|
226
|
+
// mHs2SControl=null;
|
227
|
+
deviceName=null;
|
228
|
+
deviceMac=null;
|
229
|
+
deviceModel=null;
|
230
|
+
deviceTypeG=null;
|
231
|
+
deviceDiscover = false;
|
232
|
+
deviceConnect = false;
|
233
|
+
deviceConnectFail = false;
|
234
|
+
deviceDisconnect = false;
|
235
|
+
}
|
236
|
+
public void selectPO3AndScan(){
|
237
|
+
offlineDataFound=false;
|
238
|
+
deviceTypeG ="PO3";
|
239
|
+
mScanClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
240
|
+
DiscoveryTypeEnum discoveryTypeEnum = getDiscoveryTypeEnum(deviceModel);
|
241
|
+
if (discoveryTypeEnum!= null) {
|
242
|
+
iHealthDevicesManager.getInstance().startDiscovery(discoveryTypeEnum);
|
243
|
+
}
|
244
|
+
|
245
|
+
}
|
246
|
+
public void selectBG5SAndScan(){
|
247
|
+
offlineDataFound= false;
|
248
|
+
deviceTypeG ="BG5S";
|
249
|
+
mScanClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
250
|
+
DiscoveryTypeEnum discoveryTypeEnum = getDiscoveryTypeEnum(deviceModel);
|
251
|
+
if (discoveryTypeEnum!= null) {
|
252
|
+
iHealthDevicesManager.getInstance().startDiscovery(discoveryTypeEnum);
|
253
|
+
}
|
254
|
+
}
|
255
|
+
public void selectPT3SBTAndScan(){
|
256
|
+
offlineDataFound= false;
|
257
|
+
|
258
|
+
deviceTypeG ="PT3SBT";
|
259
|
+
mScanClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
260
|
+
DiscoveryTypeEnum discoveryTypeEnum = getDiscoveryTypeEnum(deviceModel);
|
261
|
+
if (discoveryTypeEnum!= null) {
|
262
|
+
iHealthDevicesManager.getInstance().startDiscovery(discoveryTypeEnum);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
public void selectHS4SAndScan(){
|
266
|
+
offlineDataFound= false;
|
267
|
+
|
268
|
+
deviceTypeG ="HS4S";
|
269
|
+
mScanClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
270
|
+
DiscoveryTypeEnum discoveryTypeEnum = getDiscoveryTypeEnum(deviceModel);
|
271
|
+
if (discoveryTypeEnum!= null) {
|
272
|
+
iHealthDevicesManager.getInstance().startDiscovery(discoveryTypeEnum);
|
273
|
+
}
|
274
|
+
|
275
|
+
} public void selectHS2SAndScan(){
|
276
|
+
offlineDataFound= false;
|
277
|
+
deviceTypeG ="HS2S";
|
278
|
+
mScanClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
279
|
+
DiscoveryTypeEnum discoveryTypeEnum = getDiscoveryTypeEnum(deviceModel);
|
280
|
+
if (discoveryTypeEnum!= null) {
|
281
|
+
iHealthDevicesManager.getInstance().startDiscovery(discoveryTypeEnum);
|
282
|
+
}
|
283
|
+
|
284
|
+
} public void selectBPTrackAndScan(){
|
285
|
+
offlineDataFound= false;
|
286
|
+
deviceTypeG ="KN-550BT";
|
287
|
+
mScanClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
288
|
+
DiscoveryTypeEnum discoveryTypeEnum = getDiscoveryTypeEnum("BP550BT");
|
289
|
+
if (discoveryTypeEnum!= null) {
|
290
|
+
iHealthDevicesManager.getInstance().startDiscovery(discoveryTypeEnum);
|
291
|
+
}
|
292
|
+
|
293
|
+
}
|
294
|
+
public void selectBP5SAndScan(){
|
295
|
+
Bp5suserdata="";
|
296
|
+
Bp5sDataCount =0;
|
297
|
+
Bp5scount = null;
|
298
|
+
mScanClientCallbackId= 0;
|
299
|
+
mClientCallbackId = 0;
|
300
|
+
deviceTypeG ="BP5S";
|
301
|
+
mScanClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
302
|
+
DiscoveryTypeEnum discoveryTypeEnum = getDiscoveryTypeEnum(deviceModel);
|
303
|
+
if (discoveryTypeEnum!= null) {
|
304
|
+
iHealthDevicesManager.getInstance().startDiscovery(discoveryTypeEnum);
|
305
|
+
}
|
306
|
+
|
307
|
+
}
|
308
|
+
private DiscoveryTypeEnum getDiscoveryTypeEnum(String modelValue) {
|
309
|
+
for (DiscoveryTypeEnum type : DiscoveryTypeEnum.values()) {
|
310
|
+
if (modelValue.equals(type.name()))
|
311
|
+
return type;
|
312
|
+
}
|
313
|
+
|
314
|
+
return null;}
|
315
|
+
|
316
|
+
private iHealthDevicesCallback miHealthDevicesCallback = new iHealthDevicesCallback() {
|
317
|
+
@Override
|
318
|
+
public void onScanDevice(String mac, String deviceType, int rssi, Map manufactorData) {
|
319
|
+
showLog("onScanDevice >> started");
|
320
|
+
showLog("onScanDevice - mac:" + mac + " - deviceModel:" + deviceType + " - rssi:" + rssi + " - manufactorData:" + manufactorData);
|
321
|
+
JSObject scanEvent = new JSObject();
|
322
|
+
scanEvent.put("deviceMacAddress", mac);
|
323
|
+
|
324
|
+
deviceMac = mac;
|
325
|
+
JSObject eventData = new JSObject();
|
326
|
+
showLog("deeeeeeeeeeeeeeeeeee");
|
327
|
+
showLog(deviceTypeG);
|
328
|
+
showLog(deviceType);
|
329
|
+
if(deviceType==deviceTypeG){
|
330
|
+
if(!deviceDiscover){
|
331
|
+
notifyListeners("deviceDiscover", scanEvent);
|
332
|
+
deviceDiscover=true;
|
333
|
+
}
|
334
|
+
isDevicePairingReq=true;
|
335
|
+
boolean request = iHealthDevicesManager.getInstance().connectDevice("", mac, deviceType);
|
336
|
+
showLog(String.valueOf(request));
|
337
|
+
mConnectDeviceClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
338
|
+
|
339
|
+
|
340
|
+
if (request) {
|
341
|
+
eventData.put("deviceConnect", "success");
|
342
|
+
if(!deviceConnect){
|
343
|
+
notifyListeners("deviceConnect", eventData);
|
344
|
+
deviceConnect=true;
|
345
|
+
}
|
346
|
+
iHealthDevicesManager.getInstance().stopDiscovery();
|
347
|
+
} else {
|
348
|
+
eventData.put("deviceConnectFail", "failed");
|
349
|
+
if(!deviceConnectFail) {
|
350
|
+
notifyListeners("deviceConnectFail", eventData);
|
351
|
+
deviceConnectFail=true;
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
else {
|
356
|
+
eventData.put("deviceConnectFail", "failed");
|
357
|
+
if(!deviceConnectFail){
|
358
|
+
notifyListeners("deviceConnectFail", eventData);
|
359
|
+
deviceConnectFail=true;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
showLog("onScanDevice > ended");
|
366
|
+
}
|
367
|
+
|
368
|
+
|
369
|
+
@Override
|
370
|
+
public void onDeviceConnectionStateChange(String mac, String deviceType, int status, int errorID, Map manufactorData) {
|
371
|
+
|
372
|
+
showLog("onDeviceConnectionStateChange");
|
373
|
+
showLog("mac:" + mac + " deviceType:" + deviceType + " status:" + status + " errorid:" + errorID + " -manufactorData:" + manufactorData);
|
374
|
+
showLog("status: " + status);
|
375
|
+
Bundle bundle = new Bundle();
|
376
|
+
bundle.putString("mac", mac);
|
377
|
+
bundle.putString("type", deviceType);
|
378
|
+
Message msg = new Message();
|
379
|
+
Handler handler = new Handler();
|
380
|
+
|
381
|
+
switch (status) {
|
382
|
+
case iHealthDevicesManager.DEVICE_STATE_CONNECTED:
|
383
|
+
msg.what = HANDLER_CONNECTED;
|
384
|
+
iHealthDevicesManager.getInstance().stopDiscovery();
|
385
|
+
|
386
|
+
switch (deviceType) {
|
387
|
+
case "KN-550BT":
|
388
|
+
mClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
389
|
+
// iHealthDevicesManager.getInstance().addCallbackFilterForDeviceType(mClientCallbackId, deviceType);
|
390
|
+
|
391
|
+
mBp550btControl = iHealthDevicesManager.getInstance().getBp550BTControl(deviceMac);
|
392
|
+
showLog("============ inside get foling of KN-550BT");
|
393
|
+
showLog(String.valueOf(mBp550btControl));
|
394
|
+
mBp550btControl.getFunctionInfo();
|
395
|
+
mBp550btControl.getOfflineData();
|
396
|
+
|
397
|
+
break;
|
398
|
+
case "BP5S":
|
399
|
+
mClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
400
|
+
iHealthDevicesManager.getInstance().addCallbackFilterForDeviceType(mClientCallbackId, deviceType);
|
401
|
+
mBp5sControl = iHealthDevicesManager.getInstance().getBp5sControl(deviceMac);
|
402
|
+
mBp5sControl.getOfflineDataNum();
|
403
|
+
|
404
|
+
|
405
|
+
break;
|
406
|
+
case "PT3SBT":
|
407
|
+
mClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
408
|
+
iHealthDevicesManager.getInstance().addCallbackFilterForDeviceType(mClientCallbackId, deviceType);
|
409
|
+
|
410
|
+
mPt3sbtControl = iHealthDevicesManager.getInstance().getPt3sbtDevice(deviceMac);
|
411
|
+
mPt3sbtControl.setTime();
|
412
|
+
mPt3sbtControl.getHistoryData();
|
413
|
+
showLog(" mPt3sbtControl.getHistoryData();");
|
414
|
+
break;
|
415
|
+
case "PO3":
|
416
|
+
mClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
417
|
+
|
418
|
+
iHealthDevicesManager.getInstance().addCallbackFilterForDeviceType(mClientCallbackId, deviceType);
|
419
|
+
|
420
|
+
mPo3Control = iHealthDevicesManager.getInstance().getPo3Control(deviceMac);
|
421
|
+
mPo3Control.getHistoryData();
|
422
|
+
|
423
|
+
break;
|
424
|
+
case "BG5S":
|
425
|
+
|
426
|
+
mClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
427
|
+
|
428
|
+
iHealthDevicesManager.getInstance().addCallbackFilterForDeviceType(mClientCallbackId, deviceType);
|
429
|
+
|
430
|
+
mBg5sControl = iHealthDevicesManager.getInstance().getBg5sControl(deviceMac);
|
431
|
+
if(isDevicePairingReq){
|
432
|
+
mBg5sControl.setTime(date,1);
|
433
|
+
mBg5sControl.getOfflineData();
|
434
|
+
}else{
|
435
|
+
mBg5sControl.setUnit(Bg5sProfile.UNIT_MMOL);
|
436
|
+
JSObject result = new JSObject();
|
437
|
+
result.put("deviceName", deviceType);
|
438
|
+
result.put("deviceMacAddress", mac);
|
439
|
+
if(!deviceDiscover) {
|
440
|
+
notifyListeners("deviceDiscover", result);
|
441
|
+
deviceDiscover=true;
|
442
|
+
}
|
443
|
+
|
444
|
+
}
|
445
|
+
|
446
|
+
|
447
|
+
break;
|
448
|
+
case "HS4S":
|
449
|
+
mClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
450
|
+
|
451
|
+
iHealthDevicesManager.getInstance().addCallbackFilterForDeviceType(mClientCallbackId, deviceType);
|
452
|
+
|
453
|
+
mHs4SControl = iHealthDevicesManager.getInstance().getHs4sControl(deviceMac);
|
454
|
+
mHs4SControl.getOfflineData();
|
455
|
+
break;
|
456
|
+
case "HS2S":
|
457
|
+
|
458
|
+
mClientCallbackId = iHealthDevicesManager.getInstance().registerClientCallback(miHealthDevicesCallback);
|
459
|
+
|
460
|
+
iHealthDevicesManager.getInstance().addCallbackFilterForDeviceType(mClientCallbackId, deviceType);
|
461
|
+
|
462
|
+
mHs2SControl = iHealthDevicesManager.getInstance().getHs2sControl(deviceMac);
|
463
|
+
mHs2SControl.getUserInfo();
|
464
|
+
// mHs2SControl.getAnonymousDataCount();
|
465
|
+
// mHs2SControl.getAnonymousData();
|
466
|
+
break;
|
467
|
+
}
|
468
|
+
|
469
|
+
showLog("DEVICE_STATE_CONNECTED");
|
470
|
+
break;
|
471
|
+
case iHealthDevicesManager.DEVICE_STATE_DISCONNECTED:
|
472
|
+
msg.what = HANDLER_DISCONNECT;
|
473
|
+
JSObject disconnectResult = new JSObject();
|
474
|
+
disconnectResult.put("data", "device disconnected");
|
475
|
+
if(!deviceDisconnect){
|
476
|
+
notifyListeners("deviceDisconnect", disconnectResult);
|
477
|
+
deviceDisconnect=true;
|
478
|
+
}
|
479
|
+
showLog("HANDLER_DISCONNECT");
|
480
|
+
break;
|
481
|
+
case iHealthDevicesManager.DEVICE_STATE_CONNECTIONFAIL:
|
482
|
+
msg.what = HANDLER_CONNECT_FAIL;
|
483
|
+
|
484
|
+
showLog("HANDLER_CONNECT_FAIL");
|
485
|
+
|
486
|
+
JSObject failConnectionresult = new JSObject();
|
487
|
+
failConnectionresult.put("connectfail", "Device ConnectFail");
|
488
|
+
if(!deviceConnectFail) {
|
489
|
+
notifyListeners("deviceConnectFail", failConnectionresult);
|
490
|
+
deviceConnectFail=true;
|
491
|
+
}
|
492
|
+
break;
|
493
|
+
case iHealthDevicesManager.DEVICE_STATE_RECONNECTING:
|
494
|
+
msg.what = HANDLER_RECONNECT;
|
495
|
+
break;
|
496
|
+
}
|
497
|
+
|
498
|
+
msg.setData(bundle);
|
499
|
+
myHandler.sendMessage(msg);
|
500
|
+
showLog("onDeviceConnectionStateChange > Completed");
|
501
|
+
}
|
502
|
+
|
503
|
+
@Override
|
504
|
+
public void onScanError(String reason, long latency) {
|
505
|
+
showLog("SCANNING OUTPUT :: onScanError");
|
506
|
+
Log.e(PageLogTag, reason);
|
507
|
+
Log.e(PageLogTag, "please wait for " + latency + " ms");
|
508
|
+
JSObject errorObj = new JSObject();
|
509
|
+
errorObj.put("onScanError", "reason:"+reason+"\n");
|
510
|
+
//notifyListeners("onDeviceNotify", errorObj);
|
511
|
+
//com.ihealth.communication.utils.Log.i("onScanError", "completed");
|
512
|
+
if (mScanClientCallbackId > 0) {
|
513
|
+
showLog("SCANNING OUTPUT :: unRegisterClientCallback => Scan Callback - 1");
|
514
|
+
if (iHealthDevicesManager.getInstance().isDiscovering())
|
515
|
+
iHealthDevicesManager.getInstance().stopDiscovery();
|
516
|
+
|
517
|
+
iHealthDevicesManager.getInstance().unRegisterClientCallback(mScanClientCallbackId);
|
518
|
+
mScanClientCallbackId = 0;
|
519
|
+
}
|
520
|
+
}
|
521
|
+
|
522
|
+
@Override
|
523
|
+
public void onScanFinish() {
|
524
|
+
super.onScanFinish();
|
525
|
+
showLog("SCANNING OUTPUT :: onScanFinish > finish");
|
526
|
+
//com.ihealth.communication.utils.Log.i("onScanFinish", "finish");
|
527
|
+
|
528
|
+
if (mScanClientCallbackId > 0) {
|
529
|
+
showLog("SCANNING OUTPUT :: unRegisterClientCallback => Scan Callback - 2");
|
530
|
+
if (iHealthDevicesManager.getInstance().isDiscovering())
|
531
|
+
iHealthDevicesManager.getInstance().stopDiscovery();
|
532
|
+
|
533
|
+
iHealthDevicesManager.getInstance().unRegisterClientCallback(mScanClientCallbackId);
|
534
|
+
mScanClientCallbackId = 0;
|
535
|
+
}
|
536
|
+
}
|
537
|
+
|
538
|
+
@Override
|
539
|
+
public void onDeviceConnectionStateChange(String mac, String deviceType, int status, int errorID) {
|
540
|
+
showLog("onDeviceConnectionStateChange > Called");
|
541
|
+
showLog("mac: " + mac);
|
542
|
+
showLog("deviceType: " + deviceType);
|
543
|
+
showLog("status: " + status);
|
544
|
+
//if (status == iHealthDevicesManager.DEVICE_STATE_DISCONNECTED) {
|
545
|
+
//}
|
546
|
+
}
|
547
|
+
|
548
|
+
@Override
|
549
|
+
public void onUserStatus(String username, int userStatus) {
|
550
|
+
showLog("username: " + username);
|
551
|
+
showLog("userState: " + userStatus);
|
552
|
+
}
|
553
|
+
|
554
|
+
@Override
|
555
|
+
public void onDeviceNotify(String mac, String deviceType, String action, String message) {
|
556
|
+
showLog("onDeviceNotify > Started");
|
557
|
+
showLog("mac: " + mac);
|
558
|
+
showLog("deviceType: " + deviceType);
|
559
|
+
showLog("action: " + action);
|
560
|
+
showLog("message: " + message);
|
561
|
+
|
562
|
+
JSObject logger = new JSObject();
|
563
|
+
// logger.put("onDeviceNotify", "action:"+action+""+""+"deviceType: "+deviceType+"\n");
|
564
|
+
//notifyListeners("onDeviceNotify", logger);
|
565
|
+
|
566
|
+
String firmwareVersionCloud = "";
|
567
|
+
String deviceTimeString = "";
|
568
|
+
switch (deviceType) {
|
569
|
+
case "BP5S":
|
570
|
+
case "KN-550BT":
|
571
|
+
switch (action) {
|
572
|
+
case BpProfile.ACTION_BATTERY_BP:
|
573
|
+
try {
|
574
|
+
JSONObject info = new JSONObject(message);
|
575
|
+
String battery = info.getString(BpProfile.BATTERY_BP);
|
576
|
+
Message msg = new Message();
|
577
|
+
msg.what = HANDLER_MESSAGE;
|
578
|
+
msg.obj = "battery: " + battery;
|
579
|
+
myHandler.sendMessage(msg);
|
580
|
+
} catch (JSONException e) {
|
581
|
+
Log.e(PageLogTag, e.getMessage());
|
582
|
+
e.printStackTrace();
|
583
|
+
}
|
584
|
+
break;
|
585
|
+
case BpProfile.ACTION_COMMUNICATION_TIMEOUT:
|
586
|
+
case BpProfile.ACTION_DELETE_ALL_MEMORY_SUCCESS:
|
587
|
+
if (mBp550btControl != null) {
|
588
|
+
// mBp550btControl.disconnect();
|
589
|
+
// mBp550btControl.destroy();
|
590
|
+
}
|
591
|
+
if (mBp5sControl != null) {
|
592
|
+
// mBp5sControl.disconnect();
|
593
|
+
// mBp5sControl.destroy();
|
594
|
+
}
|
595
|
+
break;
|
596
|
+
case BpProfile.ACTION_ERROR_BP:
|
597
|
+
|
598
|
+
if (mBp550btControl != null) {
|
599
|
+
// mBp550btControl.disconnect();
|
600
|
+
// mBp550btControl.destroy();
|
601
|
+
}
|
602
|
+
if (mBp5sControl != null) {
|
603
|
+
// mBp5sControl.disconnect();
|
604
|
+
// mBp5sControl.destroy();
|
605
|
+
}
|
606
|
+
try {
|
607
|
+
JSONObject info = new JSONObject(message);
|
608
|
+
String num = info.getString(BpProfile.ERROR_NUM_BP);
|
609
|
+
Message msg = new Message();
|
610
|
+
msg.what = HANDLER_MESSAGE;
|
611
|
+
msg.obj = "error num: " + num;
|
612
|
+
JSObject bperror = new JSObject();
|
613
|
+
bperror.put("BPError", "Error:"+msg+"\n");
|
614
|
+
//notifyListeners("onDeviceNotify", bperror);
|
615
|
+
myHandler.sendMessage(msg);
|
616
|
+
} catch (JSONException e) {
|
617
|
+
|
618
|
+
Log.e(PageLogTag, e.getMessage());
|
619
|
+
e.printStackTrace();
|
620
|
+
}
|
621
|
+
break;
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
case BpProfile.ACTION_HISTORICAL_DATA_BP, BpProfile.ACTION_ONLINE_RESULT_BP:
|
626
|
+
String str = "{}";
|
627
|
+
try {
|
628
|
+
JSONObject info = new JSONObject(message);
|
629
|
+
showLog("info has ======");
|
630
|
+
showLog(String.valueOf(info));
|
631
|
+
showLog(String.valueOf(info.has(BpProfile.HISTORICAL_DATA_BP)));
|
632
|
+
|
633
|
+
if (info.has(BpProfile.HISTORICAL_DATA_BP)) {
|
634
|
+
JSONArray array = info.getJSONArray(BpProfile.HISTORICAL_DATA_BP);
|
635
|
+
|
636
|
+
for (int i = 0; i < array.length(); i++) {
|
637
|
+
JSONObject obj = array.getJSONObject(i);
|
638
|
+
String dataID = obj.getString(BpProfile.DATAID);
|
639
|
+
if(!Bp5suserdata.contains(dataID)){
|
640
|
+
Bp5suserdata = Bp5suserdata + array.toString();
|
641
|
+
Bp5suserdata = Bp5suserdata.replace("[","");
|
642
|
+
Bp5suserdata = Bp5suserdata.replace("]",",");
|
643
|
+
showLog(" array.length()==============");
|
644
|
+
showLog(String.valueOf(array.length()));
|
645
|
+
Bp5sDataCount = Bp5sDataCount + array.length();
|
646
|
+
break;
|
647
|
+
}
|
648
|
+
}
|
649
|
+
|
650
|
+
//Bp5suserdata = Bp5suserdata + array.toString();
|
651
|
+
// if(deviceType=="BP5S"){
|
652
|
+
|
653
|
+
if(deviceType=="BP5S"){
|
654
|
+
//JSONArray jsonArray = new JSONArray(Bp5suserdata);
|
655
|
+
//JSONArray array = info.getJSONArray(BpProfile.HISTORICAL_DATA_BP);
|
656
|
+
|
657
|
+
if(Bp5sDataCount==Integer.parseInt(Bp5scount)){
|
658
|
+
if (mBp5sControl != null) {
|
659
|
+
mBp5sControl.getFunctionInfo();
|
660
|
+
}
|
661
|
+
|
662
|
+
JSObject result = new JSObject();
|
663
|
+
|
664
|
+
Bp5suserdata = "["+Bp5suserdata+"]";
|
665
|
+
Bp5suserdata = Bp5suserdata.replace(",]","]");
|
666
|
+
|
667
|
+
result.put("deviceDataArr", Bp5suserdata);
|
668
|
+
Bp5suserdata= "";
|
669
|
+
|
670
|
+
result.put("deviceModel", "BP5S");
|
671
|
+
Log.d(PageLogTag, "info from BP > if" + result.toString());
|
672
|
+
//System.out.println("info from BP>>>" + result);
|
673
|
+
notifyListeners("deviceDatafound", result);
|
674
|
+
showLog("triggered deviceDatafound");
|
675
|
+
|
676
|
+
}
|
677
|
+
else if (array.length() == 0){
|
678
|
+
JSObject result1 = new JSObject();
|
679
|
+
result1.put("message", "Data not found");
|
680
|
+
notifyListeners("dataNotFound", result1);
|
681
|
+
|
682
|
+
}
|
683
|
+
}else{
|
684
|
+
if (mBp550btControl != null) {
|
685
|
+
mBp550btControl.getFunctionInfo();
|
686
|
+
}
|
687
|
+
System.out.println("info from BP>>>" + info);
|
688
|
+
System.out.println("info from BP>>>" + info.length());
|
689
|
+
if (info.length() == 0) {
|
690
|
+
JSObject result1 = new JSObject();
|
691
|
+
result1.put("message", "Data not found");
|
692
|
+
notifyListeners("dataNotFound", result1);
|
693
|
+
} else {
|
694
|
+
//Data found and returned back
|
695
|
+
JSObject result = new JSObject();
|
696
|
+
result.put("deviceDataArr", info);
|
697
|
+
result.put("deviceModel", "KN-550BT");
|
698
|
+
Log.d(PageLogTag, "info from BP > kttt" + result.toString());
|
699
|
+
//System.out.println("info from BP>>>" + result);
|
700
|
+
if(!offlineDataFound)
|
701
|
+
notifyListeners("deviceDatafound", result);
|
702
|
+
offlineDataFound =true;
|
703
|
+
}}
|
704
|
+
} else if (action==BpProfile.ACTION_ONLINE_RESULT_BP){
|
705
|
+
if (mBp5sControl != null) {
|
706
|
+
mBp5sControl.getFunctionInfo();
|
707
|
+
}
|
708
|
+
if(Bp5suserdata!=null){
|
709
|
+
JSObject result = new JSObject();
|
710
|
+
Bp5suserdata = info.toString();
|
711
|
+
Bp5suserdata = "[" + Bp5suserdata + "]";
|
712
|
+
Bp5suserdata = Bp5suserdata.replace(",]", "]");
|
713
|
+
result.put("deviceDataArr", Bp5suserdata);
|
714
|
+
|
715
|
+
result.put("deviceModel", "BP5S");
|
716
|
+
result.put("deviceMacAddress",deviceMac );
|
717
|
+
result.put("isFromLive",true );
|
718
|
+
Log.d(PageLogTag, "info from BP > else" + result.toString());
|
719
|
+
notifyListeners("deviceDatafound", result);
|
720
|
+
showLog("triggered deviceDatafound");
|
721
|
+
Bp5suserdata = null;
|
722
|
+
}
|
723
|
+
|
724
|
+
}else {
|
725
|
+
Message msg = new Message();
|
726
|
+
msg.what = HANDLER_MESSAGE;
|
727
|
+
msg.obj = str;
|
728
|
+
myHandler.sendMessage(msg);
|
729
|
+
JSObject result1 = new JSObject();
|
730
|
+
result1.put("message", "Data not found");
|
731
|
+
notifyListeners("dataNotFound", result1);
|
732
|
+
}
|
733
|
+
} catch (JSONException e) {
|
734
|
+
JSObject bperror1 = new JSObject();
|
735
|
+
bperror1.put("BPError", "exception:"+e.getMessage()+"\n");
|
736
|
+
//notifyListeners("onDeviceNotify", bperror1);
|
737
|
+
Log.e(PageLogTag, e.getMessage());
|
738
|
+
e.printStackTrace();
|
739
|
+
}
|
740
|
+
break;
|
741
|
+
case BpProfile.ACTION_HISTORICAL_NUM_BP:
|
742
|
+
showLog("BpProfile.ACTION_HISTORICAL_NUM_BP");
|
743
|
+
try {
|
744
|
+
JSONObject info = new JSONObject(message);
|
745
|
+
String num = info.getString(BpProfile.HISTORICAL_NUM_BP);
|
746
|
+
Message msg = new Message();
|
747
|
+
msg.what = HANDLER_MESSAGE;
|
748
|
+
msg.obj = "num: " + num;
|
749
|
+
|
750
|
+
Bp5scount = num;
|
751
|
+
if(Integer.parseInt(num)>0){
|
752
|
+
mBp5sControl.getOfflineData();
|
753
|
+
}else{
|
754
|
+
JSObject result1 = new JSObject();
|
755
|
+
result1.put("message", "Data not found");
|
756
|
+
notifyListeners("dataNotFound", result1);
|
757
|
+
|
758
|
+
}
|
759
|
+
|
760
|
+
|
761
|
+
myHandler.sendMessage(msg);
|
762
|
+
|
763
|
+
} catch (JSONException e) {
|
764
|
+
JSObject bperror1 = new JSObject();
|
765
|
+
bperror1.put("BPError", "exception:"+e.getMessage()+"\n");
|
766
|
+
//notifyListeners("onDeviceNotify", bperror1);
|
767
|
+
|
768
|
+
Log.e(PageLogTag, e.getMessage());
|
769
|
+
e.printStackTrace();
|
770
|
+
}
|
771
|
+
break;
|
772
|
+
case BpProfile.ACTION_SET_UNIT_SUCCESS_BP:
|
773
|
+
Message msg1 = new Message();
|
774
|
+
msg1.what = HANDLER_MESSAGE;
|
775
|
+
msg1.obj = "set unit success";
|
776
|
+
myHandler.sendMessage(msg1);
|
777
|
+
break;
|
778
|
+
|
779
|
+
case BpProfile.ACTION_ONLINE_PULSEWAVE_BP:
|
780
|
+
showLog("inside ACTION_FUNCTION_INFORMATION_BP");
|
781
|
+
try{
|
782
|
+
JSONObject info = new JSONObject(message);
|
783
|
+
String Bp5sdata = String.valueOf(info.getString("pressure"));
|
784
|
+
JSObject eventData = new JSObject();
|
785
|
+
eventData.put("result", Bp5sdata);
|
786
|
+
eventData.put("deviceModel","BP5S" );
|
787
|
+
eventData.put("deviceMacAddress",deviceMac );
|
788
|
+
notifyListeners("OnlineDeviceData",eventData);
|
789
|
+
|
790
|
+
|
791
|
+
// if (info.has(BpProfile.)) {
|
792
|
+
// JSONArray array = info.getJSONArray(BpProfile.HISTORICAL_DATA_BP);
|
793
|
+
// }
|
794
|
+
}catch (Exception e){}
|
795
|
+
Message msg2 = new Message();
|
796
|
+
msg2.what = HANDLER_MESSAGE;
|
797
|
+
msg2.obj = message;
|
798
|
+
myHandler.sendMessage(msg2);
|
799
|
+
break;
|
800
|
+
case BpProfile.ACTION_SET_STATUS_DISPLAY_SUCCESS:
|
801
|
+
Message msg3 = new Message();
|
802
|
+
msg3.what = HANDLER_MESSAGE;
|
803
|
+
msg3.obj = "set display success";
|
804
|
+
myHandler.sendMessage(msg3);
|
805
|
+
break;
|
806
|
+
default:
|
807
|
+
Message msg4 = new Message();
|
808
|
+
msg4.what = HANDLER_MESSAGE;
|
809
|
+
msg4.obj = "message: " + message;
|
810
|
+
myHandler.sendMessage(msg4);
|
811
|
+
break;
|
812
|
+
}
|
813
|
+
|
814
|
+
// if (mBp550btControl != null) {
|
815
|
+
// mBp550btControl.disconnect();
|
816
|
+
// mBp550btControl.destroy();
|
817
|
+
// }
|
818
|
+
if (mBp5sControl != null) {
|
819
|
+
|
820
|
+
// mBp5sControl.disconnect();
|
821
|
+
//mBp5sControl.destroy();
|
822
|
+
}
|
823
|
+
break;
|
824
|
+
case "PT3SBT":
|
825
|
+
if (mPt3sbtControl != null)
|
826
|
+
// mPt3sbtControl.setTime();
|
827
|
+
|
828
|
+
// Calendar c = Calendar.getInstance();
|
829
|
+
// System.out.println("Current dateTime => " + c.getTime());
|
830
|
+
// SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
|
831
|
+
// String formattedDate = df.format(c.getTime());
|
832
|
+
// showLog("Format dateTime => " + formattedDate);
|
833
|
+
// System.out.println("Format dateTime => " + formattedDate);
|
834
|
+
|
835
|
+
switch (action){
|
836
|
+
case Pt3sbtProfile.TEMPERATURE:
|
837
|
+
showLog("TEMPERATURE====================");
|
838
|
+
showLog("message: " + message);
|
839
|
+
break;
|
840
|
+
case Pt3sbtProfile.ACTION_TEMPERATURE_MEASUREMENT:
|
841
|
+
showLog("ACTION_TEMPERATURE_MEASUREMENT====================");
|
842
|
+
|
843
|
+
showLog("message: " + message);
|
844
|
+
try {
|
845
|
+
JSONObject object = new JSONObject(message);
|
846
|
+
JSObject result = new JSObject();
|
847
|
+
result.put("deviceDataArr", object);
|
848
|
+
result.put("deviceModel", "PT3SBT");
|
849
|
+
result.put("isFromLive", true);
|
850
|
+
if(!liveDataFound){
|
851
|
+
notifyListeners("deviceDatafound", result);
|
852
|
+
liveDataFound= true;
|
853
|
+
final Handler handler = new Handler(Looper.getMainLooper());
|
854
|
+
handler.postDelayed(new Runnable() {
|
855
|
+
@Override
|
856
|
+
public void run() {
|
857
|
+
liveDataFound= false;
|
858
|
+
}
|
859
|
+
}, 1000);
|
860
|
+
}
|
861
|
+
} catch (JSONException e) {
|
862
|
+
JSObject pt3sbterror1 = new JSObject();
|
863
|
+
pt3sbterror1.put("PT3SBTError", "exception:"+e.getMessage()+"\n");
|
864
|
+
notifyListeners("onDeviceNotify", pt3sbterror1);
|
17
865
|
|
866
|
+
Log.e(PageLogTag, e.getMessage());
|
867
|
+
e.printStackTrace();
|
868
|
+
}
|
869
|
+
break;
|
870
|
+
case Pt3sbtProfile.ACTION_DELETE_HISTORY_DATA:
|
871
|
+
showLog("message: " + message);
|
872
|
+
break;
|
873
|
+
case Pt3sbtProfile.ACTION_GET_HISTORY_DATA:
|
874
|
+
try {
|
875
|
+
JSONObject object = new JSONObject(message);
|
876
|
+
JSObject result = new JSObject();
|
877
|
+
result.put("deviceDataArr", object);
|
878
|
+
result.put("deviceModel", "PT3SBT");
|
879
|
+
//result.put("time", formattedDate);
|
880
|
+
if(!offlineDataFound){
|
881
|
+
notifyListeners("deviceDatafound", result);
|
882
|
+
offlineDataFound= true;
|
883
|
+
|
884
|
+
|
885
|
+
// mPt3sbtControl.
|
886
|
+
|
887
|
+
}
|
888
|
+
} catch (JSONException e) {
|
889
|
+
JSObject pt3sbterror1 = new JSObject();
|
890
|
+
pt3sbterror1.put("PT3SBTError", "exception:"+e.getMessage()+"\n");
|
891
|
+
notifyListeners("onDeviceNotify", pt3sbterror1);
|
892
|
+
|
893
|
+
Log.e(PageLogTag, e.getMessage());
|
894
|
+
e.printStackTrace();
|
895
|
+
} finally {
|
896
|
+
// if (mPt3sbtControl != null) {
|
897
|
+
// mPt3sbtControl.setTime();
|
898
|
+
// mPt3sbtControl.disconnect();
|
899
|
+
// }
|
900
|
+
}
|
901
|
+
break;
|
902
|
+
default:
|
903
|
+
break;
|
904
|
+
}
|
905
|
+
// try {
|
906
|
+
// JSONObject object = new JSONObject(message);
|
907
|
+
// JSObject result = new JSObject();
|
908
|
+
// result.put("deviceDataArr", object);
|
909
|
+
// result.put("deviceModel", "PT3SBT");
|
910
|
+
// //result.put("time", formattedDate);
|
911
|
+
// notifyListeners("deviceDatafound", result);
|
912
|
+
// } catch (JSONException e) {
|
913
|
+
// Log.e(PageLogTag, e.getMessage());
|
914
|
+
// e.printStackTrace();
|
915
|
+
// } finally {
|
916
|
+
// if (mPt3sbtControl != null) {
|
917
|
+
// mPt3sbtControl.setTime();
|
918
|
+
// mPt3sbtControl.disconnect();
|
919
|
+
// }
|
920
|
+
// }
|
921
|
+
|
922
|
+
// if (UpgradeProfile.ACTION_DEVICE_CLOUD_FIRMWARE_VERSION.equals(action)) {
|
923
|
+
// try {
|
924
|
+
// JSONObject object = new JSONObject(message);
|
925
|
+
// firmwareVersionCloud = object.optString(UpgradeProfile.DEVICE_CLOUD_FIRMWARE_VERSION);
|
926
|
+
//
|
927
|
+
// //addLogInfo("firmwareVersionCloud: " + firmwareVersionCloud);
|
928
|
+
// showLog("firmwareVersionCloud > " + firmwareVersionCloud);
|
929
|
+
// } catch (JSONException e) {
|
930
|
+
// Log.e(PageLogTag, e.getMessage());
|
931
|
+
// e.printStackTrace();
|
932
|
+
// }
|
933
|
+
// } else if (UpgradeProfile.ACTION_DEVICE_UP_DOWNLOAD_COMPLETED.equals(action)) {
|
934
|
+
// //msg.obj = "download success";
|
935
|
+
// }
|
936
|
+
|
937
|
+
// if(mClientCallbackId > 0) {
|
938
|
+
// iHealthDevicesManager.getInstance().unRegisterClientCallback(mClientCallbackId);
|
939
|
+
// }
|
940
|
+
break;
|
941
|
+
case "BG5S":
|
942
|
+
try {
|
943
|
+
JSONObject object = new JSONObject(message);
|
944
|
+
// deviceTimeString = object.getString(Bg5sProfile.INFO_TIME);//commented
|
945
|
+
} catch (JSONException e) {
|
946
|
+
showLog("BG5S :: ERROR LOG");
|
947
|
+
Log.e(PageLogTag, e.getMessage());
|
948
|
+
e.printStackTrace();
|
949
|
+
}
|
950
|
+
|
951
|
+
Message msg = new Message();
|
952
|
+
msg.what = HANDLER_MESSAGE;
|
953
|
+
|
954
|
+
switch (action) {
|
955
|
+
case Bg5sProfile.ACTION_GET_STATUS_INFO:
|
956
|
+
msg.obj = "statusInfo: " + message;
|
957
|
+
//try {
|
958
|
+
// JSONObject object = new JSONObject(message);
|
959
|
+
// System.out.println(">>>deviceTimeString"+message);
|
960
|
+
// deviceTimeString = object.getString(Bg5sProfile.INFO_TIME);
|
961
|
+
// } catch (JSONException e) {
|
962
|
+
// e.printStackTrace();
|
963
|
+
// }
|
964
|
+
break;
|
965
|
+
case Bg5sProfile.ACTION_ERROR:
|
966
|
+
// deviceDisconnect();
|
967
|
+
JSObject bgActionErrorResult = new JSObject();
|
968
|
+
bgActionErrorResult.put("message", message);
|
969
|
+
notifyListeners("dataNotFound", bgActionErrorResult);
|
970
|
+
msg.obj = "error: " + message;
|
971
|
+
break;
|
972
|
+
case Bg5sProfile.ACTION_SET_TIME:
|
973
|
+
msg.obj = "set time success";
|
974
|
+
break;
|
975
|
+
case Bg5sProfile.ACTION_SET_UNIT:
|
976
|
+
msg.obj = "set unit success";
|
977
|
+
// deviceDisconnect();
|
978
|
+
break;
|
979
|
+
case Bg5sProfile.ACTION_SEND_CODE:
|
980
|
+
msg.obj = "send code : " + message;
|
981
|
+
break;
|
982
|
+
case Bg5sProfile.ACTION_DELETE_USED_STRIP:
|
983
|
+
msg.obj = "delete used strip success";
|
984
|
+
break;
|
985
|
+
case Bg5sProfile.ACTION_DELETE_OFFLINE_DATA:
|
986
|
+
msg.obj = "delete offline data success";
|
987
|
+
if (mBg5sControl != null) {
|
988
|
+
// mBg5sControl.closeBluetooth();
|
989
|
+
// mBg5sControl.disconnect();
|
990
|
+
}
|
991
|
+
break;
|
992
|
+
case Bg5sProfile.ACTION_KEEP_LINK:
|
993
|
+
msg.obj = "keep link success";
|
994
|
+
break;
|
995
|
+
case Bg5sProfile.ACTION_STRIP_IN:
|
996
|
+
msg.obj = "strip in";
|
997
|
+
break;
|
998
|
+
case Bg5sProfile.ACTION_GET_BLOOD:
|
999
|
+
msg.obj = "get blood";
|
1000
|
+
break;
|
1001
|
+
case Bg5sProfile.ACTION_STRIP_OUT:
|
1002
|
+
msg.obj = "strip out";
|
1003
|
+
break;
|
1004
|
+
case Bg5sProfile.ACTION_RESULT:
|
1005
|
+
offlineDataFound =false;
|
1006
|
+
msg.obj = "start measure success";
|
1007
|
+
showLog("startmeasure show log");
|
1008
|
+
showLog(message);
|
1009
|
+
JSONObject info_liveBg5s = null;
|
1010
|
+
try {
|
1011
|
+
info_liveBg5s = new JSONObject(message);
|
1012
|
+
JSObject result = new JSObject();
|
1013
|
+
result.put("deviceDataArr", info_liveBg5s);
|
1014
|
+
result.put("deviceModel", "BG5S");
|
1015
|
+
result.put("isFromLive", true);
|
1016
|
+
showLog("result");
|
1017
|
+
showLog(String.valueOf(result));
|
1018
|
+
if(!liveDataFound){
|
1019
|
+
notifyListeners("deviceDatafound", result);
|
1020
|
+
liveDataFound= true;
|
1021
|
+
}
|
1022
|
+
} catch (JSONException e) {
|
1023
|
+
throw new RuntimeException(e);
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
case Bg5sProfile.ACTION_START_MEASURE:
|
1027
|
+
|
1028
|
+
|
1029
|
+
|
1030
|
+
break;
|
1031
|
+
case Bg5sProfile.ACTION_GET_OFFLINE_DATA:
|
1032
|
+
liveDataFound = false;
|
1033
|
+
if (mBg5sControl != null) {
|
1034
|
+
// mBg5sControl.setTime(Calendar.getInstance().getTime(), Calendar.getInstance().getTimeZone().getRawOffset());//commented
|
1035
|
+
msg.obj = "offline data: " + message + "\nAfter adjust:" + mBg5sControl.adjustOfflineData(deviceTimeString, message);
|
1036
|
+
|
1037
|
+
// JSONObject object = null;
|
1038
|
+
// String deviceTimeString = null;
|
1039
|
+
// try {
|
1040
|
+
// object = new JSONObject(message);
|
1041
|
+
// deviceTimeString = object.getString(Bg5sProfile.INFO_TIME);
|
1042
|
+
// System.out.println("DEVICETIME >>"+deviceTimeString);
|
1043
|
+
// } catch (JSONException e) {
|
1044
|
+
// e.printStackTrace();
|
1045
|
+
// }
|
1046
|
+
|
1047
|
+
try {
|
1048
|
+
JSONObject info = new JSONObject(message);
|
1049
|
+
|
1050
|
+
JSObject result = new JSObject();
|
1051
|
+
result.put("deviceDataArr", info);
|
1052
|
+
result.put("isFromLive",false);
|
1053
|
+
// result.put("date", deviceTimeString);
|
1054
|
+
result.put("deviceModel", "BG5S");
|
1055
|
+
|
1056
|
+
if(!offlineDataFound){
|
1057
|
+
notifyListeners("deviceDatafound", result);
|
1058
|
+
offlineDataFound= true;
|
1059
|
+
mBg5sControl.startMeasure(2);
|
1060
|
+
}
|
1061
|
+
// deviceDisconnect();
|
1062
|
+
} catch (JSONException e) {
|
1063
|
+
JSObject bg5serror = new JSObject();
|
1064
|
+
bg5serror.put("BG5SError", "exception:"+e.getMessage()+"\n");
|
1065
|
+
//notifyListeners("onDeviceNotify", bg5serror);
|
1066
|
+
Log.e(PageLogTag, e.getMessage());
|
1067
|
+
e.printStackTrace();
|
1068
|
+
}
|
1069
|
+
} else {
|
1070
|
+
msg.obj = "offline data: " + message;
|
1071
|
+
}
|
1072
|
+
|
1073
|
+
if (mBg5sControl != null) {
|
1074
|
+
// mBg5sControl.closeBluetooth();
|
1075
|
+
// mBg5sControl.disconnect();
|
1076
|
+
}
|
1077
|
+
break;
|
1078
|
+
case UpgradeProfile.ACTION_DEVICE_CLOUD_FIRMWARE_VERSION:
|
1079
|
+
msg.obj = "result: " + message;
|
1080
|
+
break;
|
1081
|
+
case UpgradeProfile.ACTION_DEVICE_UP_DOWNLOAD_COMPLETED:
|
1082
|
+
msg.obj = "download success";
|
1083
|
+
break;
|
1084
|
+
default:
|
1085
|
+
msg.obj = "notify() action = " + action + ", message = " + message;
|
1086
|
+
break;
|
1087
|
+
}
|
1088
|
+
|
1089
|
+
if (mBg5sControl != null) {
|
1090
|
+
// mBg5sControl.setTime(Calendar.getInstance().getTime(), Calendar.getInstance().getTimeZone().getRawOffset());//commented
|
1091
|
+
// mBg5sControl.closeBluetooth();
|
1092
|
+
// mBg5sControl.disconnect();
|
1093
|
+
}
|
1094
|
+
break;
|
1095
|
+
case "PO3":
|
1096
|
+
JSONTokener jsonTokener = new JSONTokener(message);
|
1097
|
+
switch (action) {
|
1098
|
+
case PoProfile.ACTION_OFFLINEDATA_PO:
|
1099
|
+
try {
|
1100
|
+
JSONObject object = (JSONObject) jsonTokener.nextValue();
|
1101
|
+
JSONArray jsonArray = object.getJSONArray(PoProfile.OFFLINEDATA_PO);
|
1102
|
+
for (int i = 0; i < jsonArray.length(); i++) {
|
1103
|
+
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
|
1104
|
+
String dataId = jsonObject.getString(PoProfile.DATAID);
|
1105
|
+
String dateString = jsonObject.getString(PoProfile.MEASURE_DATE_PO);
|
1106
|
+
int oxygen = jsonObject.getInt(PoProfile.BLOOD_OXYGEN_PO);
|
1107
|
+
int pulseRate = jsonObject.getInt(PoProfile.PULSE_RATE_PO);
|
1108
|
+
JSONArray jsonArray1 = jsonObject.getJSONArray(PoProfile.PULSE_WAVE_PO);
|
1109
|
+
int[] wave = new int[jsonArray1.length()];
|
1110
|
+
for (int j = 0; j < jsonArray1.length(); j++) {
|
1111
|
+
wave[j] = jsonArray1.getInt(j);
|
1112
|
+
}
|
1113
|
+
showLog("dataId:" + dataId + "--date:" + dateString + "--oxygen:" + oxygen + "--pulseRate:" + pulseRate + "-wave1:" + wave[0] + "-wave2:" + wave[1] + "-wave3:" + wave[2]);
|
1114
|
+
}
|
1115
|
+
|
1116
|
+
JSObject result = new JSObject();
|
1117
|
+
result.put("deviceDataArr", object);
|
1118
|
+
result.put("deviceMacAddress", deviceMac);
|
1119
|
+
result.put("isFromLive", false);
|
1120
|
+
|
1121
|
+
//result.put("time", deviceTimeString);
|
1122
|
+
result.put("deviceModel", "Oximeter");
|
1123
|
+
if(!offlineDataFound) {
|
1124
|
+
notifyListeners("deviceDatafound", result);
|
1125
|
+
showLog("poooooo22222222 " +String.valueOf(result));
|
1126
|
+
offlineDataFound =true;
|
1127
|
+
mPo3Control.startMeasure();
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
Message message2 = new Message();
|
1131
|
+
message2.what = 1;
|
1132
|
+
message2.obj = message;
|
1133
|
+
myHandler.sendMessage(message2);
|
1134
|
+
} catch (JSONException e) {
|
1135
|
+
JSObject po3error = new JSObject();
|
1136
|
+
po3error.put("PO3Error", "exception:"+e.getMessage()+"\n");
|
1137
|
+
//notifyListeners("onDeviceNotify", po3error);
|
1138
|
+
Log.e(PageLogTag, e.getMessage());
|
1139
|
+
e.printStackTrace();
|
1140
|
+
}
|
1141
|
+
break;
|
1142
|
+
case PoProfile.ACTION_LIVEDA_PO:
|
1143
|
+
try {
|
1144
|
+
JSONObject jsonObject = (JSONObject) jsonTokener.nextValue();
|
1145
|
+
|
1146
|
+
int oxygen = jsonObject.getInt(PoProfile.BLOOD_OXYGEN_PO);
|
1147
|
+
int pulseRate = jsonObject.getInt(PoProfile.PULSE_RATE_PO);
|
1148
|
+
float PI = (float) jsonObject.getDouble(PoProfile.PI_PO);
|
1149
|
+
|
1150
|
+
JSONArray jsonArray = jsonObject.getJSONArray(PoProfile.PULSE_WAVE_PO);
|
1151
|
+
int[] wave = new int[3];
|
1152
|
+
|
1153
|
+
for (int i = 0; i < jsonArray.length(); i++) {
|
1154
|
+
wave[i] = jsonArray.getInt(i);
|
1155
|
+
}
|
1156
|
+
|
1157
|
+
showLog("oxygen:" + oxygen + "--pulseRate:" + pulseRate + "--Pi:" + PI + "-wave1:" + wave[0] + "-wave2:" + wave[1] + "-wave3:" + wave[2]);
|
1158
|
+
Message message3 = new Message();
|
1159
|
+
message3.what = 1;
|
1160
|
+
message3.obj = message;
|
1161
|
+
myHandler.sendMessage(message3);
|
1162
|
+
|
1163
|
+
JSObject result = new JSObject();
|
1164
|
+
result.put("result", jsonObject);
|
1165
|
+
//result.put("time", deviceTimeString);
|
1166
|
+
result.put("deviceModel", "Oximeter");
|
1167
|
+
result.put("deviceMacAddress", deviceMac);
|
1168
|
+
result.put("isFromLive", true);
|
1169
|
+
// mPo3Control.stopMeasurement(oxygen, (int) PI,wave[0]);
|
1170
|
+
// if(action== PoProfile.ACTION_STOP_MEASUREMENT)
|
1171
|
+
showLog( " =OnlineDeviceData jsonObject"+ jsonObject.toString());
|
1172
|
+
notifyListeners("OnlineDeviceData", result);
|
1173
|
+
|
1174
|
+
|
1175
|
+
|
1176
|
+
|
1177
|
+
/* mBtnMeasurement.setEnabled(false);
|
1178
|
+
mBtnBattery.setEnabled(false);
|
1179
|
+
mBtnGetData.setEnabled(false);*/
|
1180
|
+
} catch (JSONException e) {
|
1181
|
+
JSObject po3error = new JSObject();
|
1182
|
+
po3error.put("liveDataFounderror", "exception:"+e.getMessage()+"\n");
|
1183
|
+
//notifyListeners("onDeviceNotify", po3error);
|
1184
|
+
e.printStackTrace();
|
1185
|
+
}
|
1186
|
+
break;
|
1187
|
+
case PoProfile.ACTION_RESULTDATA_PO:
|
1188
|
+
try {
|
1189
|
+
JSONObject jsonObject = (JSONObject) jsonTokener.nextValue();
|
1190
|
+
String dataId = jsonObject.getString(PoProfile.DATAID);
|
1191
|
+
|
1192
|
+
int oxygen = jsonObject.getInt(PoProfile.BLOOD_OXYGEN_PO);
|
1193
|
+
int pulseRate = jsonObject.getInt(PoProfile.PULSE_RATE_PO);
|
1194
|
+
float PI = (float) jsonObject.getDouble(PoProfile.PI_PO);
|
1195
|
+
|
1196
|
+
JSONArray jsonArray = jsonObject.getJSONArray(PoProfile.PULSE_WAVE_PO);
|
1197
|
+
int[] wave = new int[3];
|
1198
|
+
|
1199
|
+
for (int i = 0; i < jsonArray.length(); i++) {
|
1200
|
+
wave[i] = jsonArray.getInt(i);
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
showLog("dataId:" + dataId + "--oxygen:" + oxygen + "--pulseRate:" + pulseRate + "--Pi:" + PI + "-wave1:" + wave[0] + "-wave2:" + wave[1] + "-wave3:" + wave[2]);
|
1204
|
+
Message message3 = new Message();
|
1205
|
+
message3.what = 1;
|
1206
|
+
message3.obj = message;
|
1207
|
+
myHandler.sendMessage(message3);
|
1208
|
+
JSObject result = new JSObject();
|
1209
|
+
result.put("deviceDataArr", jsonObject);
|
1210
|
+
//result.put("time", deviceTimeString);
|
1211
|
+
result.put("deviceModel", "Oximeter");
|
1212
|
+
result.put("deviceMacAddress", deviceMac);
|
1213
|
+
result.put("isFromLive", true);
|
1214
|
+
if(!liveDataFound){
|
1215
|
+
notifyListeners("deviceDatafound", result);
|
1216
|
+
liveDataFound =true;
|
1217
|
+
}
|
1218
|
+
|
1219
|
+
/* mBtnMeasurement.setEnabled(true);
|
1220
|
+
mBtnBattery.setEnabled(true);
|
1221
|
+
mBtnGetData.setEnabled(true);*/
|
1222
|
+
} catch (JSONException e) {
|
1223
|
+
JSObject po3error = new JSObject();
|
1224
|
+
po3error.put("ACTION_RESULTDATA_PO", "exception:"+e.getMessage()+"\n");
|
1225
|
+
//notifyListeners("onDeviceNotify", po3error);
|
1226
|
+
Log.e(PageLogTag, e.getMessage());
|
1227
|
+
e.printStackTrace();
|
1228
|
+
}
|
1229
|
+
break;
|
1230
|
+
case PoProfile.ACTION_NO_OFFLINEDATA_PO:
|
1231
|
+
mPo3Control.startMeasure();
|
1232
|
+
JSObject poNoDataResult = new JSObject();
|
1233
|
+
poNoDataResult.put("message", "Data not found");
|
1234
|
+
notifyListeners("dataNotFound", poNoDataResult);
|
1235
|
+
|
1236
|
+
Message message2 = new Message();
|
1237
|
+
message2.what = 1;
|
1238
|
+
message2.obj = "no history data";
|
1239
|
+
myHandler.sendMessage(message2);
|
1240
|
+
break;
|
1241
|
+
case PoProfile.ACTION_BATTERY_PO:
|
1242
|
+
try {
|
1243
|
+
JSONObject jsonobject = (JSONObject) jsonTokener.nextValue();
|
1244
|
+
int battery = jsonobject.getInt(PoProfile.BATTERY_PO);
|
1245
|
+
showLog("battery:" + battery);
|
1246
|
+
} catch (JSONException e) {
|
1247
|
+
Log.e(PageLogTag, e.getMessage());
|
1248
|
+
e.printStackTrace();
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
Message message3 = new Message();
|
1252
|
+
message3.what = 1;
|
1253
|
+
message3.obj = message;
|
1254
|
+
myHandler.sendMessage(message3);
|
1255
|
+
break;
|
1256
|
+
case UpgradeProfile.ACTION_DEVICE_CLOUD_FIRMWARE_VERSION:
|
1257
|
+
Message message4 = new Message();
|
1258
|
+
message4.what = 1;
|
1259
|
+
message4.obj = "result: " + message4;
|
1260
|
+
myHandler.sendMessage(message4);
|
1261
|
+
|
1262
|
+
try {
|
1263
|
+
JSONObject object = new JSONObject(message);
|
1264
|
+
firmwareVersionCloud = object.optString(UpgradeProfile.DEVICE_CLOUD_FIRMWARE_VERSION);
|
1265
|
+
|
1266
|
+
/* if (Utils.compareVersion(firmwareVersion, firmwareVersionCloud) < 0) {
|
1267
|
+
mBtnDownload.setEnabled(true);
|
1268
|
+
addLogInfo("Need to upgrade");
|
1269
|
+
} else {
|
1270
|
+
mBtnDownload.setEnabled(false);
|
1271
|
+
mBtnUpgrade.setEnabled(false);
|
1272
|
+
addLogInfo("No need to upgrade");
|
1273
|
+
}*/
|
1274
|
+
} catch (JSONException e) {
|
1275
|
+
Log.e(PageLogTag, e.getMessage());
|
1276
|
+
e.printStackTrace();
|
1277
|
+
}
|
1278
|
+
break;
|
1279
|
+
case UpgradeProfile.ACTION_DEVICE_UP_DOWNLOAD_COMPLETED:
|
1280
|
+
Message message5 = new Message();
|
1281
|
+
message5.what = 1;
|
1282
|
+
message5.obj = "download success";
|
1283
|
+
myHandler.sendMessage(message5);
|
1284
|
+
// mBtnUpgrade.setEnabled(true);
|
1285
|
+
break;
|
1286
|
+
default:
|
1287
|
+
Message message6 = new Message();
|
1288
|
+
message6.what = 1;
|
1289
|
+
message6.obj = "notify() action = " + action + ", message = " + message;
|
1290
|
+
myHandler.sendMessage(message6);
|
1291
|
+
break;
|
1292
|
+
}
|
1293
|
+
|
1294
|
+
if (mPo3Control != null) {
|
1295
|
+
// mPo3Control.closeBluetooth();
|
1296
|
+
// mPo3Control.disconnect();
|
1297
|
+
}
|
1298
|
+
break;
|
1299
|
+
case "HS2S":
|
1300
|
+
JSONTokener jsonTokenerHs2s = new JSONTokener(message);
|
1301
|
+
|
1302
|
+
|
1303
|
+
|
1304
|
+
|
1305
|
+
switch (action) {
|
1306
|
+
|
1307
|
+
|
1308
|
+
// case Hs2sProfile.ACTION_BATTERY_HS:
|
1309
|
+
// try {
|
1310
|
+
// JSONObject jsonObject = (JSONObject) jsonTokenerHs2s.nextValue();
|
1311
|
+
// int battery = jsonObject.getInt(Hs2sProfile.BATTERY_HS);
|
1312
|
+
// Message msg1 = new Message();
|
1313
|
+
// msg1.what = 1;
|
1314
|
+
// msg1.obj = "battery:" + battery;
|
1315
|
+
// myHandler.sendMessage(msg1);
|
1316
|
+
// } catch (JSONException e) {
|
1317
|
+
// Log.e(PageLogTag, e.getMessage());
|
1318
|
+
// e.printStackTrace();
|
1319
|
+
// }
|
1320
|
+
// break;
|
1321
|
+
case Hs2sProfile.ACTION_ONLINE_RESULT:
|
1322
|
+
try {
|
1323
|
+
|
1324
|
+
JSONObject info = new JSONObject(message);
|
1325
|
+
String weight = info.getString(Hs2sProfile.DATA_WEIGHT);
|
1326
|
+
JSObject result = new JSObject();
|
1327
|
+
showLog("hshshshshshs===============================");
|
1328
|
+
showLog(info.toString());
|
1329
|
+
|
1330
|
+
result.put("deviceDataArr",info);
|
1331
|
+
result.put("deviceModel", "HS2S");
|
1332
|
+
result.put("deviceMacAddress", deviceMac);
|
1333
|
+
result.put("isFromLive", true);
|
1334
|
+
if(!liveDataFound){
|
1335
|
+
notifyListeners("deviceDatafound", result);
|
1336
|
+
liveDataFound=true;
|
1337
|
+
|
1338
|
+
}
|
1339
|
+
} catch (JSONException e) {
|
1340
|
+
throw new RuntimeException(e);
|
1341
|
+
}
|
1342
|
+
break;
|
1343
|
+
case Hs2sProfile.ACTION_ONLINE_REAL_TIME_WEIGHT:
|
1344
|
+
showLog("-p-----------message");
|
1345
|
+
showLog(message);
|
1346
|
+
|
1347
|
+
try {
|
1348
|
+
JSONObject info = new JSONObject(message);
|
1349
|
+
String weight = info.getString(Hs2sProfile.DATA_WEIGHT);
|
1350
|
+
JSObject result = new JSObject();
|
1351
|
+
result.put("result",weight);
|
1352
|
+
result.put("deviceModel", "HS2S");
|
1353
|
+
result.put("deviceMacAddress", deviceMac);
|
1354
|
+
notifyListeners("OnlineDeviceData", result);
|
1355
|
+
} catch (JSONException e) {
|
1356
|
+
throw new RuntimeException(e);
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
|
1360
|
+
break;
|
1361
|
+
case Hs2sProfile.ACTION_COMMUNICATION_TIMEOUT:
|
1362
|
+
case Hs2sProfile.ACTION_DELETE_ANONYMOUS_DATA:
|
1363
|
+
if(mHs2SControl != null){
|
1364
|
+
// mHs2SControl.disconnect();
|
1365
|
+
// mHs2SControl.destroy();
|
1366
|
+
}
|
1367
|
+
break;
|
1368
|
+
case Hs2sProfile.ACTION_DELETE_HISTORY_DATA:
|
1369
|
+
if(mHs2SControl != null && notify){
|
1370
|
+
// mHs2SControl.disconnect();
|
1371
|
+
// mHs2SControl.destroy();
|
1372
|
+
}
|
1373
|
+
break;
|
1374
|
+
case Hs2sProfile.ACTION_GET_USER_INFO:
|
1375
|
+
showLog("========hs2s userinfp");
|
1376
|
+
showLog("message");
|
1377
|
+
showLog(message);
|
1378
|
+
try{
|
1379
|
+
|
1380
|
+
JSONObject info = new JSONObject(message);
|
1381
|
+
if (info.has(Hs2sProfile.USER_INFO_ARRAY)) {
|
1382
|
+
|
1383
|
+
JSONArray array = info.getJSONArray(Hs2sProfile.USER_INFO_ARRAY);
|
1384
|
+
hs2sDeviceUserInfo = array;
|
1385
|
+
|
1386
|
+
if(array != null && array.length()>0){
|
1387
|
+
for (int i = 0; i < array.length(); i++) {
|
1388
|
+
JSONObject obj = array.getJSONObject(i);
|
1389
|
+
String user_id = obj.getString(Hs2sProfile.USER_INFO_USER_ID);
|
1390
|
+
// test_user_id.set(test_user_id.size(), user_id);
|
1391
|
+
test_user_id.add(user_id);
|
1392
|
+
if(i==array.length()-1){
|
1393
|
+
notify =true;
|
1394
|
+
// mHs2SControl.getAnonymousDataCount();
|
1395
|
+
}
|
1396
|
+
// else{
|
1397
|
+
// notify = false;
|
1398
|
+
// }
|
1399
|
+
}
|
1400
|
+
if(test_user_id.size()>0) {
|
1401
|
+
if(!hs2sOffline){
|
1402
|
+
getOfflineData("1111");
|
1403
|
+
hs2sOffline=true;}
|
1404
|
+
}else{
|
1405
|
+
if(!hs2sanonym){
|
1406
|
+
mHs2SControl.getAnonymousDataCount();
|
1407
|
+
hs2sanonym=true;}//commented
|
1408
|
+
}
|
1409
|
+
|
1410
|
+
}
|
1411
|
+
// else{
|
1412
|
+
// mHs2SControl.getAnonymousDataCount();
|
1413
|
+
// }
|
1414
|
+
|
1415
|
+
|
1416
|
+
|
1417
|
+
}
|
1418
|
+
|
1419
|
+
}catch (Exception e){
|
1420
|
+
JSObject hs2serror = new JSObject();
|
1421
|
+
hs2serror.put("ACTION_GET_USER_INFO", "exception:"+e.getMessage()+"\n");
|
1422
|
+
//notifyListeners("onDeviceNotify", hs2serror);
|
1423
|
+
|
1424
|
+
}
|
1425
|
+
|
1426
|
+
break;
|
1427
|
+
|
1428
|
+
case Hs2sProfile.ACTION_HISTORY_DATA:
|
1429
|
+
String str = "{}";
|
1430
|
+
// mHs2SControl.getAnonymousData();
|
1431
|
+
|
1432
|
+
try {
|
1433
|
+
JSONArray Hs2sSpecificUserdata = new JSONArray(message);
|
1434
|
+
|
1435
|
+
|
1436
|
+
// for (int i = 0; i < Hs2sSpecificUserdata.length(); i++) {
|
1437
|
+
// JSONObject jsonObject = (JSONObject) Hs2sSpecificUserdata.get(i);
|
1438
|
+
// String dateString = jsonObject.getString(Hs2sProfile.DATA_MEASURE_TIME);
|
1439
|
+
// float weight = (float) jsonObject.getDouble(Hs2sProfile.DATA_WEIGHT);
|
1440
|
+
// String dataId = jsonObject.getString(Hs2sProfile.DATA_ID);
|
1441
|
+
// showLog("dataId:" + dataId + "--date:" + dateString + "-weight:" + weight);
|
1442
|
+
// }
|
1443
|
+
// Message history = new Message();
|
1444
|
+
// history.what = 1;
|
1445
|
+
// history.obj = message;
|
1446
|
+
// myHandler.sendMessage(history);
|
1447
|
+
JSObject result = new JSObject();
|
1448
|
+
// result.put("deviceDataArr", message);
|
1449
|
+
if(!Hs2suserdata.contains(message.substring(1, message.length() - 1))) {
|
1450
|
+
Hs2suserdata = Hs2suserdata + message.substring(1, message.length() - 1);
|
1451
|
+
}
|
1452
|
+
Hs2sCounter++;
|
1453
|
+
if(Hs2sCounter<test_user_id.size()){
|
1454
|
+
if(!hs2sOffline){
|
1455
|
+
getOfflineData("2222");
|
1456
|
+
hs2sOffline=true;}
|
1457
|
+
}else{
|
1458
|
+
if(!hs2sanonym){
|
1459
|
+
mHs2SControl.getAnonymousDataCount();
|
1460
|
+
hs2sanonym=true;}
|
1461
|
+
}
|
1462
|
+
if(notify){
|
1463
|
+
// if(mHs2SControl != null){
|
1464
|
+
// mHs2SControl.getDeviceInfo();
|
1465
|
+
// }
|
1466
|
+
// mHs2SControl.getAnonymousDataCount();
|
1467
|
+
//result.put("deviceDataArr", "["+Hs2suserdata+"]");
|
1468
|
+
//result.put("deviceModel", "HS2S");
|
1469
|
+
//notifyListeners("deviceDatafound", result);
|
1470
|
+
//Hs2suserdata="";
|
1471
|
+
|
1472
|
+
|
1473
|
+
}
|
1474
|
+
//result.put("time", deviceTimeString);
|
1475
|
+
|
1476
|
+
|
1477
|
+
|
1478
|
+
|
1479
|
+
} catch (JSONException e) {
|
1480
|
+
JSObject hs2serror = new JSObject();
|
1481
|
+
hs2serror.put("ACTION_HISTORY_DATA", "exception:"+e.getMessage()+"\n");
|
1482
|
+
Log.e(PageLogTag, e.getMessage());
|
1483
|
+
e.printStackTrace();
|
1484
|
+
}
|
1485
|
+
case Hs2sProfile.ACTION_HISTORY_DATA_NUM:
|
1486
|
+
|
1487
|
+
if(Hs2sCounter < test_user_id.size()){
|
1488
|
+
mHs2SControl.getOfflineData(test_user_id.get(Hs2sCounter));
|
1489
|
+
}
|
1490
|
+
break;
|
1491
|
+
case Hs2sProfile.ACTION_ANONYMOUS_DATA_NUM:
|
1492
|
+
try {
|
1493
|
+
JSONObject info = new JSONObject(message);
|
1494
|
+
String countStr = info.getString(Hs2sProfile.ANONYMOUS_DATA_COUNT);
|
1495
|
+
if(Integer.parseInt(countStr) == 0){
|
1496
|
+
if(!Hs2suserdata.isEmpty()){
|
1497
|
+
JSObject result = new JSObject();
|
1498
|
+
String finalStr = "["+Hs2suserdata+"]";
|
1499
|
+
finalStr = finalStr.replace("}{","},{");
|
1500
|
+
JSONArray hs2sArr = new JSONArray(finalStr);
|
1501
|
+
result.put("deviceDataArr",hs2sArr);
|
1502
|
+
result.put("deviceModel", "HS2S");
|
1503
|
+
result.put("isFromLive", false);
|
1504
|
+
result.put("deviceMacAddress", deviceMac);
|
1505
|
+
if(!offlineDataFound){
|
1506
|
+
notifyListeners("deviceDatafound", result);
|
1507
|
+
notify =false;
|
1508
|
+
offlineDataFound =true;
|
1509
|
+
mHs2SControl.specifyOnlineUsers(test_user_id.get(0),85,1,25,175,1,1);
|
1510
|
+
|
1511
|
+
// mHs2SControl.startHeartRateMode();
|
1512
|
+
|
1513
|
+
|
1514
|
+
}
|
1515
|
+
if(mHs2SControl != null){
|
1516
|
+
// mHs2SControl.disconnect();
|
1517
|
+
// mHs2SControl.destroy();
|
1518
|
+
}
|
1519
|
+
}else{
|
1520
|
+
JSObject poNoDataResult = new JSObject();
|
1521
|
+
poNoDataResult.put("message", "Data not found");
|
1522
|
+
notifyListeners("dataNotFound", poNoDataResult);
|
1523
|
+
}
|
1524
|
+
|
1525
|
+
}else{
|
1526
|
+
mHs2SControl.getAnonymousData();
|
1527
|
+
}
|
1528
|
+
} catch (JSONException e) {
|
1529
|
+
JSObject hs2serror = new JSObject();
|
1530
|
+
hs2serror.put("ACTION_ANONYMOUS_DATA_NUM", "exception:"+e.getMessage()+"\n");
|
1531
|
+
}
|
1532
|
+
|
1533
|
+
break;
|
1534
|
+
case Hs2sProfile.ACTION_ANONYMOUS_DATA:
|
1535
|
+
|
1536
|
+
try {
|
1537
|
+
JSONArray Hs2sAnonymousdata = new JSONArray(message);
|
1538
|
+
if(mHs2SControl != null){
|
1539
|
+
mHs2SControl.getDeviceInfo();
|
1540
|
+
}
|
1541
|
+
Hs2suserdata = Hs2suserdata + message.substring(1, message.length() - 1);
|
1542
|
+
JSObject result = new JSObject();
|
1543
|
+
String finalStr = "["+Hs2suserdata+"]";
|
1544
|
+
finalStr = finalStr.replace("}{","},{");
|
1545
|
+
|
1546
|
+
JSONArray hs2sArr = new JSONArray(finalStr);
|
1547
|
+
result.put("deviceDataArr",hs2sArr);
|
1548
|
+
result.put("isFromLive", false);
|
1549
|
+
result.put("deviceMacAddress", deviceMac);
|
1550
|
+
result.put("deviceModel", "HS2S");
|
1551
|
+
if(!offlineDataFound){
|
1552
|
+
notifyListeners("deviceDatafound", result);
|
1553
|
+
Hs2suserdata = "";
|
1554
|
+
notify =false;
|
1555
|
+
offlineDataFound =true;
|
1556
|
+
|
1557
|
+
mHs2SControl.specifyOnlineUsers(test_user_id.get(0),85,1,25,175,1,1);
|
1558
|
+
|
1559
|
+
|
1560
|
+
}
|
1561
|
+
if(mHs2SControl != null){
|
1562
|
+
// mHs2SControl.disconnect();
|
1563
|
+
// mHs2SControl.destroy();
|
1564
|
+
}
|
1565
|
+
} catch (JSONException e) {
|
1566
|
+
JSObject hs2serror = new JSObject();
|
1567
|
+
hs2serror.put("ACTION_ANONYMOUS_DATA", "exception:"+e.getMessage()+"\n");
|
1568
|
+
//notifyListeners("onDeviceNotify", hs2serror);
|
1569
|
+
Log.e(PageLogTag, e.getMessage());
|
1570
|
+
e.printStackTrace();
|
1571
|
+
}
|
1572
|
+
break;
|
1573
|
+
case Hs2sProfile.ACTION_ERROR_HS:
|
1574
|
+
try {
|
1575
|
+
if(mHs2SControl != null){
|
1576
|
+
// mHs2SControl.disconnect();
|
1577
|
+
// mHs2SControl.destroy();
|
1578
|
+
}
|
1579
|
+
JSONObject jsonObject = (JSONObject) jsonTokenerHs2s.nextValue();
|
1580
|
+
|
1581
|
+
int err = jsonObject.getInt(HsProfile.ERROR_NUM_HS);
|
1582
|
+
showLog("weight:" + err);
|
1583
|
+
Message error = new Message();
|
1584
|
+
error.what = 1;
|
1585
|
+
error.obj = "err:" + err;
|
1586
|
+
myHandler.sendMessage(error);
|
1587
|
+
} catch (JSONException e) {
|
1588
|
+
Log.e(PageLogTag, e.getMessage());
|
1589
|
+
e.printStackTrace();
|
1590
|
+
}
|
1591
|
+
break;
|
1592
|
+
|
1593
|
+
|
1594
|
+
|
1595
|
+
}
|
1596
|
+
|
1597
|
+
|
1598
|
+
if (mHs2SControl != null) {
|
1599
|
+
}
|
1600
|
+
break;
|
1601
|
+
|
1602
|
+
case "HS4S":
|
1603
|
+
showLog("mac:" + mac + "--type:" + deviceType + "--action:" + action + "--message:" + message);
|
1604
|
+
JSONTokener jsonTokener1 = new JSONTokener(message);
|
1605
|
+
switch (action) {
|
1606
|
+
case HsProfile.ACTION_BATTERY_HS:
|
1607
|
+
try {
|
1608
|
+
JSONObject jsonObject = (JSONObject) jsonTokener1.nextValue();
|
1609
|
+
int battery = jsonObject.getInt(HsProfile.BATTERY_HS);
|
1610
|
+
Message msg1 = new Message();
|
1611
|
+
msg1.what = 1;
|
1612
|
+
msg1.obj = "battery:" + battery;
|
1613
|
+
myHandler.sendMessage(msg1);
|
1614
|
+
} catch (JSONException e) {
|
1615
|
+
Log.e(PageLogTag, e.getMessage());
|
1616
|
+
e.printStackTrace();
|
1617
|
+
}
|
1618
|
+
break;
|
1619
|
+
case HsProfile.ACTION_HISTORICAL_DATA_HS:
|
1620
|
+
try {
|
1621
|
+
JSONObject object = (JSONObject) jsonTokener1.nextValue();
|
1622
|
+
JSONArray jsonArray = object.getJSONArray(HsProfile.HISTORDATA_HS);
|
1623
|
+
|
1624
|
+
for (int i = 0; i < jsonArray.length(); i++) {
|
1625
|
+
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
|
1626
|
+
String dateString = jsonObject.getString(HsProfile.MEASUREMENT_DATE_HS);
|
1627
|
+
float weight = (float) jsonObject.getDouble(HsProfile.WEIGHT_HS);
|
1628
|
+
String dataId = jsonObject.getString(HsProfile.DATAID);
|
1629
|
+
showLog("dataId:" + dataId + "--date:" + dateString + "-weight:" + weight);
|
1630
|
+
}
|
1631
|
+
|
1632
|
+
Message history = new Message();
|
1633
|
+
history.what = 1;
|
1634
|
+
history.obj = message;
|
1635
|
+
myHandler.sendMessage(history);
|
1636
|
+
|
1637
|
+
JSObject result = new JSObject();
|
1638
|
+
result.put("deviceDataArr", message);
|
1639
|
+
result.put("deviceModel", "Scale");
|
1640
|
+
result.put("isFromLive", false);
|
1641
|
+
|
1642
|
+
if(!offlineDataFound){
|
1643
|
+
notifyListeners("deviceDatafound", result);
|
1644
|
+
offlineDataFound =true;
|
1645
|
+
mHs4SControl.measureOnline(0,0);
|
1646
|
+
|
1647
|
+
}
|
1648
|
+
} catch (JSONException e) {
|
1649
|
+
JSObject hs4serror = new JSObject();
|
1650
|
+
hs4serror.put("ACTION_HISTORICAL_DATA_HS", "exception:"+e.getMessage()+"\n");
|
1651
|
+
//notifyListeners("onDeviceNotify", hs4serror);
|
1652
|
+
Log.e(PageLogTag, e.getMessage());
|
1653
|
+
e.printStackTrace();
|
1654
|
+
}
|
1655
|
+
break;
|
1656
|
+
case HsProfile.ACTION_HISTORICAL_DATA_COMPLETE_HS:
|
1657
|
+
Message complete = new Message();
|
1658
|
+
complete.what = 1;
|
1659
|
+
complete.obj = "history data complete";
|
1660
|
+
myHandler.sendMessage(complete);
|
1661
|
+
break;
|
1662
|
+
case HsProfile.ACTION_READY_MEASURE_HS:
|
1663
|
+
// mHs4SControl.disconnect();
|
1664
|
+
break;
|
1665
|
+
case HsProfile.ACTION_LIVEDATA_HS:
|
1666
|
+
try {
|
1667
|
+
JSONObject jsonObject = (JSONObject) jsonTokener1.nextValue();
|
1668
|
+
|
1669
|
+
float weight = (float) jsonObject.getDouble(HsProfile.LIVEDATA_HS);
|
1670
|
+
showLog("weight:" + weight);
|
1671
|
+
Message value = new Message();
|
1672
|
+
value.what = 1;
|
1673
|
+
value.obj = "weight:" + weight;
|
1674
|
+
myHandler.sendMessage(value);
|
1675
|
+
JSObject result = new JSObject();
|
1676
|
+
result.put("deviceModel", "Scale");
|
1677
|
+
result.put("isFromLive", true);
|
1678
|
+
result.put("deviceDataArr", message);
|
1679
|
+
//result.put("time", deviceTimeString);
|
1680
|
+
result.put("deviceModel", "Scale");
|
1681
|
+
result.put("result", weight);
|
1682
|
+
notifyListeners("OnlineDeviceData", result);
|
1683
|
+
liveDataFound=false;
|
1684
|
+
|
1685
|
+
|
1686
|
+
} catch (JSONException e) {
|
1687
|
+
JSObject hs4serror = new JSObject();
|
1688
|
+
hs4serror.put("ACTION_LIVEDATA_HS", "exception:"+e.getMessage()+"\n");
|
1689
|
+
//notifyListeners("onDeviceNotify", hs4serror);
|
1690
|
+
Log.e(PageLogTag, e.getMessage());
|
1691
|
+
e.printStackTrace();
|
1692
|
+
}
|
1693
|
+
break;
|
1694
|
+
case HsProfile.ACTION_ONLINE_RESULT_HS:
|
1695
|
+
try {
|
1696
|
+
JSONObject jsonObject = (JSONObject) jsonTokener1.nextValue();
|
1697
|
+
|
1698
|
+
float weight = (float) jsonObject.getDouble(HsProfile.WEIGHT_HS);
|
1699
|
+
String dataId = jsonObject.getString(HsProfile.DATAID);
|
1700
|
+
showLog("dataId:" + dataId + "---weight:" + weight);
|
1701
|
+
Message result = new Message();
|
1702
|
+
result.what = 1;
|
1703
|
+
result.obj = "dataId:" + dataId + "---weight:" + weight;
|
1704
|
+
JSObject result1 = new JSObject();
|
1705
|
+
result1.put("deviceModel", "Scale");
|
1706
|
+
result1.put("isFromLive", true);
|
1707
|
+
result1.put("deviceDataArr", jsonObject);
|
1708
|
+
//result.put("time", deviceTimeString);
|
1709
|
+
result1.put("deviceModel", "Scale");
|
1710
|
+
result1.put("result", weight);
|
1711
|
+
|
1712
|
+
if(!liveDataFound){
|
1713
|
+
notifyListeners("deviceDatafound", result1);
|
1714
|
+
|
1715
|
+
liveDataFound =true;
|
1716
|
+
}
|
1717
|
+
myHandler.sendMessage(result);
|
1718
|
+
} catch (JSONException e) {
|
1719
|
+
JSObject hs4serror = new JSObject();
|
1720
|
+
hs4serror.put("ACTION_ONLINE_RESULT_HS", "exception:"+e.getMessage()+"\n");
|
1721
|
+
Log.e(PageLogTag, e.getMessage());
|
1722
|
+
e.printStackTrace();
|
1723
|
+
}
|
1724
|
+
break;
|
1725
|
+
case HsProfile.ACTION_NO_HISTORICALDATA:
|
1726
|
+
mHs4SControl.measureOnline(0,0);
|
1727
|
+
|
1728
|
+
JSObject wsNoDataResult = new JSObject();
|
1729
|
+
wsNoDataResult.put("message", "Data not found");
|
1730
|
+
notifyListeners("dataNotFound", wsNoDataResult);
|
1731
|
+
|
1732
|
+
Message empty = new Message();
|
1733
|
+
empty.what = 1;
|
1734
|
+
empty.obj = "no history data";
|
1735
|
+
myHandler.sendMessage(empty);
|
1736
|
+
break;
|
1737
|
+
case HsProfile.ACTION_ERROR_HS:
|
1738
|
+
try {
|
1739
|
+
JSONObject jsonObject = (JSONObject) jsonTokener1.nextValue();
|
1740
|
+
|
1741
|
+
int err = jsonObject.getInt(HsProfile.ERROR_NUM_HS);
|
1742
|
+
showLog("weight:" + err);
|
1743
|
+
Message error = new Message();
|
1744
|
+
error.what = 1;
|
1745
|
+
error.obj = "err:" + err;
|
1746
|
+
myHandler.sendMessage(error);
|
1747
|
+
} catch (JSONException e) {
|
1748
|
+
Log.e(PageLogTag, e.getMessage());
|
1749
|
+
e.printStackTrace();
|
1750
|
+
}
|
1751
|
+
break;
|
1752
|
+
case UpgradeProfile.ACTION_DEVICE_UP_INFO:
|
1753
|
+
try {
|
1754
|
+
JSONObject jsonObject = new JSONObject(message);
|
1755
|
+
String modelNumber = jsonObject.getString(UpgradeProfile.DEVICE_MODE);
|
1756
|
+
String hardwareVersion = jsonObject.getString(UpgradeProfile.DEVICE_HARDWARE_VERSION);
|
1757
|
+
String firmwareVersion = jsonObject.getString(UpgradeProfile.DEVICE_FIRMWARE_VERSION);
|
1758
|
+
|
1759
|
+
Message unknown = new Message();
|
1760
|
+
unknown.what = 1;
|
1761
|
+
unknown.obj = message;
|
1762
|
+
myHandler.sendMessage(unknown);
|
1763
|
+
} catch (JSONException e) {
|
1764
|
+
Log.e(PageLogTag, e.getMessage());
|
1765
|
+
e.printStackTrace();
|
1766
|
+
}
|
1767
|
+
break;
|
1768
|
+
case UpgradeProfile.ACTION_DEVICE_CLOUD_FIRMWARE_VERSION:
|
1769
|
+
try {
|
1770
|
+
JSONObject jsonObject = new JSONObject(message);
|
1771
|
+
firmwareVersionCloud = jsonObject.getString(UpgradeProfile.DEVICE_CLOUD_FIRMWARE_VERSION);
|
1772
|
+
|
1773
|
+
|
1774
|
+
|
1775
|
+
Message unknown = new Message();
|
1776
|
+
unknown.what = 1;
|
1777
|
+
unknown.obj = message;
|
1778
|
+
myHandler.sendMessage(unknown);
|
1779
|
+
} catch (JSONException e) {
|
1780
|
+
Log.e(PageLogTag, e.getMessage());
|
1781
|
+
e.printStackTrace();
|
1782
|
+
}
|
1783
|
+
break;
|
1784
|
+
case UpgradeProfile.ACTION_DEVICE_UP_DOWNLOAD_COMPLETED:
|
1785
|
+
Message unknown = new Message();
|
1786
|
+
unknown.what = 1;
|
1787
|
+
unknown.obj = "download success";
|
1788
|
+
myHandler.sendMessage(unknown);
|
1789
|
+
//mBtnUpgrade.setEnabled(true);
|
1790
|
+
break;
|
1791
|
+
default:
|
1792
|
+
Message unknown1 = new Message();
|
1793
|
+
unknown1.what = 1;
|
1794
|
+
unknown1.obj = message;
|
1795
|
+
myHandler.sendMessage(unknown1);
|
1796
|
+
break;
|
1797
|
+
}
|
1798
|
+
|
1799
|
+
if (mHs4SControl != null) {
|
1800
|
+
//mHs4SControl.disconnect();
|
1801
|
+
}
|
1802
|
+
|
1803
|
+
break;
|
1804
|
+
}
|
1805
|
+
|
1806
|
+
}
|
1807
|
+
};
|
1808
|
+
|
1809
|
+
@PluginMethod()
|
1810
|
+
public void initialiseCentralManager(@NonNull PluginCall call) {}
|
1811
|
+
@PluginMethod()
|
1812
|
+
public void disconnectDevice(@NonNull PluginCall call) {
|
1813
|
+
|
1814
|
+
switch(deviceTypeG) {
|
1815
|
+
case "HS4S":
|
1816
|
+
if(mHs4SControl != null){
|
1817
|
+
mHs4SControl.disconnect();
|
1818
|
+
mHs4SControl =null;
|
1819
|
+
|
1820
|
+
}
|
1821
|
+
|
1822
|
+
if (mConnectDeviceClientCallbackId > 0) {
|
1823
|
+
iHealthDevicesManager.getInstance().unRegisterClientCallback(mConnectDeviceClientCallbackId);
|
1824
|
+
mConnectDeviceClientCallbackId = 0;
|
1825
|
+
}
|
1826
|
+
break;
|
1827
|
+
case "HS2S":
|
1828
|
+
if (mHs2SControl != null) {
|
1829
|
+
mHs2SControl.disconnect();
|
1830
|
+
|
1831
|
+
mHs2SControl =null;
|
1832
|
+
|
1833
|
+
}
|
1834
|
+
showLog("test disconnect case HS2s" + mConnectDeviceClientCallbackId);
|
1835
|
+
showLog(String.valueOf(mConnectDeviceClientCallbackId > 0));
|
1836
|
+
|
1837
|
+
if (mConnectDeviceClientCallbackId > 0) {
|
1838
|
+
iHealthDevicesManager.getInstance().unRegisterClientCallback(mConnectDeviceClientCallbackId);
|
1839
|
+
mConnectDeviceClientCallbackId = 0;
|
1840
|
+
}
|
1841
|
+
break;
|
1842
|
+
case "PO3":
|
1843
|
+
if (mPo3Control != null) {
|
1844
|
+
mPo3Control.disconnect();
|
1845
|
+
mPo3Control =null;
|
1846
|
+
|
1847
|
+
}
|
1848
|
+
if (mConnectDeviceClientCallbackId > 0) {
|
1849
|
+
iHealthDevicesManager.getInstance().unRegisterClientCallback(mConnectDeviceClientCallbackId);
|
1850
|
+
mConnectDeviceClientCallbackId = 0;
|
1851
|
+
}
|
1852
|
+
break;
|
1853
|
+
case "BG5S":
|
1854
|
+
if (mBg5sControl != null) {
|
1855
|
+
mBg5sControl.disconnect();
|
1856
|
+
mBg5sControl =null;
|
1857
|
+
}
|
1858
|
+
if (mConnectDeviceClientCallbackId > 0) {
|
1859
|
+
iHealthDevicesManager.getInstance().unRegisterClientCallback(mConnectDeviceClientCallbackId);
|
1860
|
+
mConnectDeviceClientCallbackId = 0;
|
1861
|
+
}
|
1862
|
+
break;
|
1863
|
+
case "PT3SBT":
|
1864
|
+
if(mPt3sbtControl != null){
|
1865
|
+
mPt3sbtControl.disconnect();
|
1866
|
+
mPt3sbtControl =null;
|
1867
|
+
|
1868
|
+
}
|
1869
|
+
if (mConnectDeviceClientCallbackId > 0) {
|
1870
|
+
iHealthDevicesManager.getInstance().unRegisterClientCallback(mConnectDeviceClientCallbackId);
|
1871
|
+
mConnectDeviceClientCallbackId = 0;
|
1872
|
+
}
|
1873
|
+
break;
|
1874
|
+
case "KN-550BT":
|
1875
|
+
if(mBp550btControl != null){
|
1876
|
+
mBp550btControl.disconnect();
|
1877
|
+
mBp550btControl =null;
|
1878
|
+
|
1879
|
+
}
|
1880
|
+
if (mConnectDeviceClientCallbackId > 0) {
|
1881
|
+
iHealthDevicesManager.getInstance().unRegisterClientCallback(mConnectDeviceClientCallbackId);
|
1882
|
+
mConnectDeviceClientCallbackId = 0;
|
1883
|
+
}
|
1884
|
+
break;
|
1885
|
+
case "BP5S":
|
1886
|
+
if (mBp5sControl != null){
|
1887
|
+
mBp5sControl.disconnect();
|
1888
|
+
deviceTypeG="";
|
1889
|
+
deviceName="";
|
1890
|
+
deviceModel="";
|
1891
|
+
deviceMac="";
|
1892
|
+
mBp5sControl =null;
|
1893
|
+
|
1894
|
+
if (mConnectDeviceClientCallbackId > 0) {
|
1895
|
+
iHealthDevicesManager.getInstance().unRegisterClientCallback(mConnectDeviceClientCallbackId);
|
1896
|
+
mConnectDeviceClientCallbackId = 0;
|
1897
|
+
}
|
1898
|
+
}
|
1899
|
+
break;
|
1900
|
+
|
1901
|
+
}
|
1902
|
+
|
1903
|
+
}
|
1904
|
+
@PluginMethod()
|
1905
|
+
public void isBluetoothEnabled(@NonNull PluginCall call) {
|
18
1906
|
JSObject ret = new JSObject();
|
19
|
-
|
1907
|
+
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
1908
|
+
if (mBluetoothAdapter.isEnabled()) {
|
1909
|
+
ret.put("value", true);
|
1910
|
+
}else{
|
1911
|
+
ret.put("value", false);
|
1912
|
+
}
|
20
1913
|
call.resolve(ret);
|
21
1914
|
}
|
1915
|
+
|
1916
|
+
|
1917
|
+
public void showLog(String log) {
|
1918
|
+
Log.i(PageLogTag, log);
|
1919
|
+
}
|
1920
|
+
|
1921
|
+
@SuppressLint("HandlerLeak")
|
1922
|
+
private Handler myHandler = new Handler() {
|
1923
|
+
@Override
|
1924
|
+
public void handleMessage(Message msg) {
|
1925
|
+
super.handleMessage(msg);
|
1926
|
+
Log.i(PageLogTag, "handleMessage > Started");
|
1927
|
+
Log.i(PageLogTag, "handleMessage > " + msg.toString());
|
1928
|
+
switch (msg.what) {
|
1929
|
+
case HANDLER_SCAN:
|
1930
|
+
Bundle bundleScan = msg.getData();
|
1931
|
+
String macScan = bundleScan.getString("mac");
|
1932
|
+
String typeScan = bundleScan.getString("type");
|
1933
|
+
int rssi = bundleScan.getInt("rssi");
|
1934
|
+
DeviceCharacteristic device = new DeviceCharacteristic();
|
1935
|
+
device.setDeviceName(typeScan);
|
1936
|
+
device.setRssi(rssi);
|
1937
|
+
device.setDeviceMac(macScan);
|
1938
|
+
|
1939
|
+
showLog("getDeviceMac" + device.getDeviceName());
|
1940
|
+
showLog("getDeviceMac" + device.getDeviceMac());
|
1941
|
+
showLog("getDeviceType" + device.getDeviceType());
|
1942
|
+
showLog("scan device : type:" + typeScan + " mac:" + macScan + " rssi:" + rssi);
|
1943
|
+
break;
|
1944
|
+
case HANDLER_CONNECTED:
|
1945
|
+
Bundle bundleConnect = msg.getData();
|
1946
|
+
String macConnect = bundleConnect.getString("mac");
|
1947
|
+
String typeConnect = bundleConnect.getString("type");
|
1948
|
+
iHealthDevicesManager.getInstance().stopDiscovery();
|
1949
|
+
|
1950
|
+
showLog("connected device : type:" + typeConnect + " mac:" + macConnect);
|
1951
|
+
break;
|
1952
|
+
case HANDLER_DISCONNECT:
|
1953
|
+
JSObject result = new JSObject();
|
1954
|
+
result.put("data", "device disconnected");
|
1955
|
+
if(!deviceDisconnect){
|
1956
|
+
notifyListeners("deviceDisconnect", result);
|
1957
|
+
deviceDisconnect=true;
|
1958
|
+
}
|
1959
|
+
showLog("HANDLER_DISCONNECT");
|
1960
|
+
break;
|
1961
|
+
case HANDLER_CONNECT_FAIL:
|
1962
|
+
JSObject result1 = new JSObject();
|
1963
|
+
result1.put("connectfail", "Device ConnectFail");
|
1964
|
+
if(!deviceConnectFail){
|
1965
|
+
deviceConnectFail=true;
|
1966
|
+
notifyListeners("deviceConnectFail", result1);
|
1967
|
+
}
|
1968
|
+
break;
|
1969
|
+
case HANDLER_RECONNECT:
|
1970
|
+
break;
|
1971
|
+
|
1972
|
+
default:
|
1973
|
+
break;
|
1974
|
+
}
|
1975
|
+
Log.i(PageLogTag, "handleMessage > Completed");
|
1976
|
+
}
|
1977
|
+
};
|
1978
|
+
public void getOfflineData(String text) {
|
1979
|
+
showLog("iam call getOfflineData from "+ text);
|
1980
|
+
|
1981
|
+
if(Hs2sCounter < test_user_id.size()){
|
1982
|
+
mHs2SControl.getOfflineDataCount(test_user_id.get(Hs2sCounter));
|
1983
|
+
}
|
1984
|
+
}
|
22
1985
|
}
|