react-native-mytatva-rn-sdk 1.2.50 → 1.2.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/android/src/main/java/cgmblelib/base/BApplication.java +57 -57
  2. package/android/src/main/java/cgmblelib/ble/BleService.java +1 -1
  3. package/android/src/main/java/cgmblelib/ble/gattcallback/BleGattCallback.java +1 -1
  4. package/android/src/main/java/cgmblelib/database/dao/DaoDevice.java +4 -0
  5. package/android/src/main/java/cgmblelib/database/dao/DaoGlucose.java +334 -332
  6. package/android/src/main/java/cgmblelib/database/repository/RepositoryDevice.java +5 -0
  7. package/android/src/main/java/cgmblelib/database/repository/RepositoryGlucose.java +167 -162
  8. package/android/src/main/java/cgmblelib/database/source/SourceDevice.java +2 -0
  9. package/android/src/main/java/cgmblelib/database/source/SourceGlucose.java +2 -0
  10. package/android/src/main/java/cgmblelib/database/source/db/DeviceDBDataSource.java +171 -165
  11. package/android/src/main/java/cgmblelib/database/source/db/GlucoseDBDataSource.java +305 -296
  12. package/android/src/main/java/cgmblelib/utils/SharedPreferencesLibraryUtil.java +66 -44
  13. package/android/src/main/java/com/mytatvarnsdk/CgmTrackyLibModule.kt +13 -9
  14. package/android/src/main/java/com/mytatvarnsdk/MainApplication.kt +2 -2
  15. package/android/src/main/java/com/mytatvarnsdk/activity/PermissionActivity.kt +10 -4
  16. package/android/src/main/java/com/mytatvarnsdk/activity/StartCGMActivity.kt +5 -1
  17. package/android/src/main/java/com/mytatvarnsdk/model/BaseViewModel.java +88 -84
  18. package/ios/Database/KLTBluetoothManager.m +4 -0
  19. package/ios/Database/KLTDatabaseHandler.m +77 -7
  20. package/ios/ViewModel/FinalViewModel.swift +6 -1
  21. package/lib/commonjs/CGMConnect.js +2 -2
  22. package/lib/commonjs/CGMConnect.js.map +1 -1
  23. package/lib/module/CGMConnect.js +3 -3
  24. package/lib/module/CGMConnect.js.map +1 -1
  25. package/lib/typescript/CGMConnect.d.ts +2 -2
  26. package/package.json +1 -1
  27. package/src/CGMConnect.ts +63 -54
@@ -10,60 +10,82 @@ import cgmblelib.qr.QRInformation;
10
10
 
11
11
  public class SharedPreferencesLibraryUtil {
12
12
 
13
- BSharedPreferences prefsHelper;
14
- private final String QRInfo = "QRInformation";
15
- private final String SyncMeta = "SyncMeta";
13
+ BSharedPreferences prefsHelper;
14
+ private final String QRInfo = "QRInformation";
15
+ private final String SyncMeta = "SyncMeta";
16
+ private final String PatientId = "PatientId";
16
17
 
17
18
 
18
- public SharedPreferencesLibraryUtil(Context context) {
19
- prefsHelper = BSharedPreferences.getInstance(context);
20
- }
19
+ public SharedPreferencesLibraryUtil(Context context) {
20
+ prefsHelper = BSharedPreferences.getInstance(context);
21
+ }
22
+
23
+ public QRInformation getQRInformation() {
24
+ try {
25
+ String message = prefsHelper.getData(QRInfo);
26
+ if (message == null || message.isEmpty()) {
27
+ return null;
28
+ }
29
+ return new Gson().fromJson(message, QRInformation.class);
30
+ } catch (Exception e) {
31
+ Log.d("Error => ", "getQRInformation: " + e.getMessage());
32
+ return null;
33
+ }
34
+ }
21
35
 
22
- public QRInformation getQRInformation() {
23
- try {
24
- String message = prefsHelper.getData(QRInfo);
25
- if (message == null || message.isEmpty()) {
26
- return null;
27
- }
28
- return new Gson().fromJson(message, QRInformation.class);
29
- } catch (Exception e) {
30
- Log.d("Error => ", "getQRInformation: " + e.getMessage());
31
- return null;
36
+
37
+ public void setQRInformation(String transmitterName, String qrmessage, float K, float R, String sensor) {
38
+ try {
39
+ Log.d("Error => ", "setQRInformation: " + transmitterName + qrmessage + K + R + sensor);
40
+ prefsHelper.saveData(QRInfo, new Gson().toJson(new QRInformation(transmitterName, qrmessage, R, K, sensor)));
41
+ } catch (Exception e) {
42
+ Log.d("Error => ", "setQRInformation: " + e.getMessage());
43
+ }
32
44
  }
33
- }
34
45
 
46
+ public void setLastSyncData(SyncMeta syncMeta) {
47
+ try {
48
+ prefsHelper.saveData(SyncMeta, new Gson().toJson(syncMeta));
49
+ } catch (Exception e) {
50
+ Log.d("Error => ", "setLastSyncData: " + e.getMessage());
51
+ }
52
+ }
35
53
 
36
- public void setQRInformation(String transmitterName, String qrmessage, float K, float R, String sensor) {
37
- try {
38
- Log.d("Error => ", "setQRInformation: " + transmitterName + qrmessage + K + R + sensor);
39
- prefsHelper.saveData(QRInfo, new Gson().toJson(new QRInformation(transmitterName, qrmessage, R, K, sensor)));
40
- } catch (Exception e) {
41
- Log.d("Error => ", "setQRInformation: " + e.getMessage());
54
+ public SyncMeta getLastSyncData() {
55
+ try {
56
+ String message = prefsHelper.getData(SyncMeta);
57
+ if (message == null || message.isEmpty()) {
58
+ return null;
59
+ }
60
+ return new Gson().fromJson(message, SyncMeta.class);
61
+ } catch (Exception e) {
62
+ Log.d("Error => ", "getLastSyncData: " + e.getMessage());
63
+ return null;
64
+ }
42
65
  }
43
- }
44
66
 
45
- public void setLastSyncData(SyncMeta syncMeta) {
46
- try {
47
- prefsHelper.saveData(SyncMeta, new Gson().toJson(syncMeta));
48
- } catch (Exception e) {
49
- Log.d("Error => ", "setLastSyncData: " + e.getMessage());
67
+ public void setLastPatientId(String patientId) {
68
+ try {
69
+ prefsHelper.saveData(PatientId, patientId);
70
+ } catch (Exception e) {
71
+ Log.d("Error => ", "setLastUserId: " + e.getMessage());
72
+ }
50
73
  }
51
- }
52
74
 
53
- public SyncMeta getLastSyncData() {
54
- try {
55
- String message = prefsHelper.getData(SyncMeta);
56
- if (message == null || message.isEmpty()) {
57
- return null;
58
- }
59
- return new Gson().fromJson(message, SyncMeta.class);
60
- } catch (Exception e) {
61
- Log.d("Error => ", "getLastSyncData: " + e.getMessage());
62
- return null;
75
+ public String getLastPatientId() {
76
+ try {
77
+ String message = prefsHelper.getData(PatientId);
78
+ if (message == null || message.isEmpty()) {
79
+ return null;
80
+ }
81
+ return message;
82
+ } catch (Exception e) {
83
+ Log.d("Error => ", "getLastUserId: " + e.getMessage());
84
+ return null;
85
+ }
63
86
  }
64
- }
65
87
 
66
- public void clearQRInformation() {
67
- prefsHelper.saveData(QRInfo, null);
68
- }
88
+ public void clearQRInformation() {
89
+ prefsHelper.saveData(QRInfo, null);
90
+ }
69
91
  }
@@ -2,15 +2,10 @@ package com.mytatvarnsdk
2
2
 
3
3
  import android.app.Application
4
4
  import android.bluetooth.BluetoothAdapter
5
- import android.bluetooth.BluetoothManager
6
- import android.content.Context
7
5
  import android.content.Intent
8
- import android.content.pm.PackageManager
9
- import android.os.Build
10
6
  import android.os.Handler
11
7
  import android.os.Looper
12
8
  import android.util.Log
13
- import androidx.core.content.ContextCompat
14
9
  import androidx.lifecycle.Observer
15
10
  import androidx.lifecycle.ViewModelProvider
16
11
  import androidx.lifecycle.ViewModelStore
@@ -31,9 +26,6 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
31
26
  import com.google.gson.Gson
32
27
  import com.google.gson.GsonBuilder
33
28
  import com.mytatvarnsdk.activity.HelpActivity
34
- import com.mytatvarnsdk.activity.PermissionActivity
35
- import com.mytatvarnsdk.activity.PermissionUtils
36
- import com.mytatvarnsdk.activity.SearchTransmitterActivity
37
29
  import com.mytatvarnsdk.activity.StartCGMActivity
38
30
  import com.mytatvarnsdk.model.AllCGMLogRequest
39
31
  import com.mytatvarnsdk.model.CgmLog
@@ -123,7 +115,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
123
115
  }
124
116
 
125
117
  @ReactMethod
126
- fun observeTransmitterUnbindStatus(token: String, apiResponse: String?) {
118
+ fun observeTransmitterUnbindStatus(token: String, apiResponse: String?, patientId: String) {
127
119
  try {
128
120
  if (apiResponse != null && apiResponse.isNotEmpty()) {
129
121
  userToken = token
@@ -192,6 +184,15 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
192
184
  val startDate = sensor.startDate
193
185
  val endDate = sensor.endDate
194
186
  val sensorId = sensor.sensorId
187
+ val currentPatientId = patientId
188
+
189
+ val lastPatientId = prefsHelper.lastPatientId
190
+ val lastSensorId = prefsHelper.qrInformation.sensor
191
+
192
+ if (lastPatientId != null && lastSensorId != null && (lastPatientId != currentPatientId || lastSensorId != sensorId)) {
193
+ mModel.clearAllGlucoseAndDeviceData()
194
+ return
195
+ }
195
196
 
196
197
  if (isCurrentDateInRange(startDate, endDate)) {
197
198
  println("Current date is in range")
@@ -206,6 +207,9 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
206
207
  DeviceStatus.TRANSMITTER_DISCONNECT.id,
207
208
  pocDevice.qrMessage
208
209
  )
210
+ } else {
211
+ prefsHelper.lastPatientId = currentPatientId
212
+ prefsHelper.qrInformation.sensor = sensorId
209
213
  }
210
214
  } else {
211
215
  postEventDataToAPI(
@@ -39,8 +39,8 @@ class MainApplication : BApplication(), ReactApplication {
39
39
  super.onCreate()
40
40
  Log.d("MainApplication", "MainApplication onCreate called")
41
41
  SoLoader.init(this, false)
42
- BleService.startService(this)
43
- BSharedPreferences.init(this)
42
+ // BleService.startService(this)
43
+ // BSharedPreferences.init(this)
44
44
  }
45
45
 
46
46
  override fun getReactNativeHost(): ReactNativeHost {
@@ -94,17 +94,23 @@ class PermissionActivity : BasePermissionActivity() {
94
94
  return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
95
95
  val connectPermission = ContextCompat.checkSelfPermission(
96
96
  context,
97
- android.Manifest.permission.BLUETOOTH_CONNECT
97
+ Manifest.permission.BLUETOOTH_CONNECT
98
98
  ) == PackageManager.PERMISSION_GRANTED
99
99
 
100
100
  val scanPermission = ContextCompat.checkSelfPermission(
101
101
  context,
102
- android.Manifest.permission.BLUETOOTH_SCAN
102
+ Manifest.permission.BLUETOOTH_SCAN
103
103
  ) == PackageManager.PERMISSION_GRANTED
104
104
 
105
- connectPermission && scanPermission
105
+ val advertisePermission = ContextCompat.checkSelfPermission(
106
+ context,
107
+ Manifest.permission.BLUETOOTH_ADVERTISE
108
+ ) == PackageManager.PERMISSION_GRANTED
109
+
110
+ // Include advertisePermission only if your app uses Bluetooth advertising
111
+ connectPermission && scanPermission && advertisePermission
106
112
  } else {
107
- // For Android 11 and below, permission is granted at install time
113
+ // For Android 11 and below, permission is granted at install time or via location
108
114
  true
109
115
  }
110
116
  }
@@ -1,6 +1,7 @@
1
1
  package com.mytatvarnsdk.activity
2
2
 
3
3
  import android.app.Dialog
4
+ import android.bluetooth.BluetoothAdapter
4
5
  import android.content.Intent
5
6
  import android.content.pm.PackageManager
6
7
  import android.graphics.Color
@@ -33,6 +34,9 @@ class StartCGMActivity : AppCompatActivity() {
33
34
  private lateinit var binding: ActivityStartCgmactivityBinding
34
35
  private var isForReconnect: Boolean = false
35
36
  private val reactContext = CgmTrackyLibModule.mReactContext
37
+ private val bluetoothAdapter: BluetoothAdapter? by lazy {
38
+ BluetoothAdapter.getDefaultAdapter()
39
+ }
36
40
 
37
41
  override fun onCreate(savedInstanceState: Bundle?) {
38
42
  super.onCreate(savedInstanceState)
@@ -63,7 +67,7 @@ class StartCGMActivity : AppCompatActivity() {
63
67
  sendDataToRN("", "cgm_start_connection_journey_clicked")
64
68
 
65
69
  if (isForReconnect) {
66
- val intent = if (areAllPermissionsGranted()) {
70
+ val intent = if (areAllPermissionsGranted() && bluetoothAdapter!!.isEnabled) {
67
71
  Intent(this, SearchTransmitterActivity::class.java).putExtra(
68
72
  "IsForReconnect",
69
73
  true
@@ -8,7 +8,6 @@ import androidx.lifecycle.LiveData;
8
8
  import androidx.lifecycle.MediatorLiveData;
9
9
  import androidx.lifecycle.Transformations;
10
10
 
11
- import java.util.Date;
12
11
  import java.util.List;
13
12
 
14
13
  import cgmblelib.database.entity.PocDevice;
@@ -22,88 +21,93 @@ import cgmblelib.database.repository.RepositoryGlucose;
22
21
  * @author minyuchun
23
22
  */
24
23
  public class BaseViewModel extends AndroidViewModel {
25
- /**
26
- * 设备信息储存库
27
- */
28
- private RepositoryDevice mRepositoryDevice;
29
- /**
30
- * 血糖信息储存库
31
- */
32
- private RepositoryGlucose mRepositoryGlucose;
33
- /**
34
- * 最新的设备(数据库中最大Id的设备,无论是绑定还是非绑定)
35
- */
36
- private LiveData<PocDevice> mDevice;
37
- /**
38
- * 血糖数据集列表持久化
39
- */
40
- private LiveData<List<PocGlucose>> mGlucoseList;
41
- /**
42
- * 最新的血糖数据持久化,当发射器绑定时,获取最新的,若发射器解除绑定则无
43
- */
44
- private LiveData<PocGlucose> mLatestGlucose;
45
- /***
46
- * 设备是否绑定
47
- */
48
- private MediatorLiveData<Integer> mBindDeviceId = new MediatorLiveData<>();
49
-
50
- public BaseViewModel(@NonNull Application application) {
51
- super(application);
52
- mRepositoryDevice = RepositoryDevice.getInstance(application);
53
- mRepositoryGlucose = RepositoryGlucose.getInstance(application);
54
- mDevice = mRepositoryDevice.getLiveDataLatestDeviceIoThread();
55
- mBindDeviceId.addSource(mDevice, device -> {
56
- if (device != null && device.isBound()) {
57
- if (mBindDeviceId.getValue() == null || mBindDeviceId.getValue() != device.getId()) {
58
- mBindDeviceId.setValue(device.getId());
59
- }
60
- } else {
61
- mBindDeviceId.setValue(0);
62
- }
63
- });
64
- LoadGlucose();
65
- }
66
-
67
- /**
68
- * 获取持久化设备数据,获取最新的设备的所有信息
69
- */
70
- public synchronized LiveData<PocDevice> getDevice() {
71
- return mDevice;
72
- }
73
-
74
- public synchronized LiveData<List<PocGlucose>> getAllGlucose() {
75
- return mGlucoseList;
76
- }
77
-
78
- public synchronized LiveData<PocGlucose> getLatestGlucose() {
79
- return mLatestGlucose;
80
- }
81
-
82
- /**
83
- * 获取血糖数据
84
- */
85
- private synchronized void LoadGlucose() {
86
- mGlucoseList = Transformations.switchMap(mBindDeviceId, input -> mRepositoryGlucose.getLiveDataGlucoseListByDeviceId(input));
87
- mLatestGlucose = Transformations.map(mGlucoseList, input -> {
88
- if (input != null && input.size() > 0) {
89
- return input.get(input.size() - 1);
90
- } else {
91
- return null;
92
- }
93
- });
94
- }
95
-
96
-
97
- public List<PocGlucose> getGlucoseByTime() {
98
- return mRepositoryGlucose.getGlucoseByDeviceIdAndTimeMillis(7, 1748005587474L);
99
- }
100
-
101
- public List<PocGlucose> getGlucoseBetweenTime(long startTime) {
102
- return mRepositoryGlucose.getGlucoseByTimeMillis(startTime, System.currentTimeMillis());
103
- }
104
-
105
- public PocDevice getDeviceInfo(int deviceId) {
106
- return mRepositoryDevice.getDeviceByIdIoThread(deviceId);
107
- }
24
+ /**
25
+ * 设备信息储存库
26
+ */
27
+ private RepositoryDevice mRepositoryDevice;
28
+ /**
29
+ * 血糖信息储存库
30
+ */
31
+ private RepositoryGlucose mRepositoryGlucose;
32
+ /**
33
+ * 最新的设备(数据库中最大Id的设备,无论是绑定还是非绑定)
34
+ */
35
+ private LiveData<PocDevice> mDevice;
36
+ /**
37
+ * 血糖数据集列表持久化
38
+ */
39
+ private LiveData<List<PocGlucose>> mGlucoseList;
40
+ /**
41
+ * 最新的血糖数据持久化,当发射器绑定时,获取最新的,若发射器解除绑定则无
42
+ */
43
+ private LiveData<PocGlucose> mLatestGlucose;
44
+ /***
45
+ * 设备是否绑定
46
+ */
47
+ private MediatorLiveData<Integer> mBindDeviceId = new MediatorLiveData<>();
48
+
49
+ public BaseViewModel(@NonNull Application application) {
50
+ super(application);
51
+ mRepositoryDevice = RepositoryDevice.getInstance(application);
52
+ mRepositoryGlucose = RepositoryGlucose.getInstance(application);
53
+ mDevice = mRepositoryDevice.getLiveDataLatestDeviceIoThread();
54
+ mBindDeviceId.addSource(mDevice, device -> {
55
+ if (device != null && device.isBound()) {
56
+ if (mBindDeviceId.getValue() == null || mBindDeviceId.getValue() != device.getId()) {
57
+ mBindDeviceId.setValue(device.getId());
58
+ }
59
+ } else {
60
+ mBindDeviceId.setValue(0);
61
+ }
62
+ });
63
+ LoadGlucose();
64
+ }
65
+
66
+ /**
67
+ * 获取持久化设备数据,获取最新的设备的所有信息
68
+ */
69
+ public synchronized LiveData<PocDevice> getDevice() {
70
+ return mDevice;
71
+ }
72
+
73
+ public synchronized LiveData<List<PocGlucose>> getAllGlucose() {
74
+ return mGlucoseList;
75
+ }
76
+
77
+ public synchronized LiveData<PocGlucose> getLatestGlucose() {
78
+ return mLatestGlucose;
79
+ }
80
+
81
+ /**
82
+ * 获取血糖数据
83
+ */
84
+ private synchronized void LoadGlucose() {
85
+ mGlucoseList = Transformations.switchMap(mBindDeviceId, input -> mRepositoryGlucose.getLiveDataGlucoseListByDeviceId(input));
86
+ mLatestGlucose = Transformations.map(mGlucoseList, input -> {
87
+ if (input != null && input.size() > 0) {
88
+ return input.get(input.size() - 1);
89
+ } else {
90
+ return null;
91
+ }
92
+ });
93
+ }
94
+
95
+
96
+ public List<PocGlucose> getGlucoseByTime() {
97
+ return mRepositoryGlucose.getGlucoseByDeviceIdAndTimeMillis(7, 1748005587474L);
98
+ }
99
+
100
+ public List<PocGlucose> getGlucoseBetweenTime(long startTime) {
101
+ return mRepositoryGlucose.getGlucoseByTimeMillis(startTime, System.currentTimeMillis());
102
+ }
103
+
104
+ public PocDevice getDeviceInfo(int deviceId) {
105
+ return mRepositoryDevice.getDeviceByIdIoThread(deviceId);
106
+ }
107
+
108
+ public void clearAllGlucoseAndDeviceData() {
109
+ mRepositoryGlucose.deleteAllGlucoseData();
110
+ mRepositoryDevice.deleteAllDeviceData();
111
+ }
108
112
 
109
113
  }
@@ -265,6 +265,7 @@
265
265
  }
266
266
 
267
267
  // 获取外设发来的数据,不论是read还是notify,获取数据都是从这个方法中读取。
268
+ //To receive data sent from the peripheral, whether through read or notify, the data is obtained from this method.
268
269
  - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
269
270
  if (error) {
270
271
  return;
@@ -421,6 +422,7 @@
421
422
  }
422
423
 
423
424
  // 发射器处理单条血糖数据的通用解析
425
+ //Generic parsing of a single blood glucose data packet by the transmitter
424
426
  - (ReceiveData *)handleCommonReceiveGluData:(Glucose *)gluData commandText:(NSString *)commandText {
425
427
  Device *currentDevice = self.currentDevice;
426
428
  //接收到的数据先存放到ReceiveDataInfo表
@@ -488,6 +490,7 @@
488
490
  [self closeBleSensor];
489
491
  } else {
490
492
  // 数据没拉取完继续拉取蓝牙断开期间的数据(0x22拉取协议)
493
+ //Continue retrieving the remaining data that wasn't pulled before, including the data generated during the Bluetooth disconnection (using the 0x22 retrieval protocol).
491
494
  NSInteger pullNums = 20;
492
495
  if (remain_points < pullNums) {
493
496
  pullNums = remain_points;
@@ -518,6 +521,7 @@
518
521
  [self handleCommonCT3GlucoseDataWithReceiveData:receive];
519
522
  }
520
523
 
524
+
521
525
  [Notification_Center postNotificationName:KLTUpdateDataNotify object:NULL];
522
526
  NSLog(@"----------------------------------------------called handleResendDataWithPrefix22 for KLTUpdateDataNotify");
523
527
  NSInteger maxGlucoseId = [KLTDatabaseHandler.shared getLatestAndMaxGlucoseIdOfDevice:self.currentDevice];
@@ -130,6 +130,20 @@
130
130
  glucose.temperature = data.temperature;
131
131
  float algo_k = [[User_Defaults objectForKey:@"algo_k"] floatValue];
132
132
  float algo_r = [[User_Defaults objectForKey:@"algo_r"] floatValue];
133
+
134
+ NSString *dateString = data.receiveDateTime;
135
+ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
136
+ [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
137
+ [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
138
+ NSDate *date = [dateFormatter dateFromString:dateString];
139
+ if (date) {
140
+ NSTimeInterval timeMillis = [date timeIntervalSince1970] * 1000; // Convert to milliseconds
141
+ NSLog(@"Milliseconds since epoch: %.0f", timeMillis);
142
+ NSNumber *numberFromTimeMillis = [NSNumber numberWithDouble:timeMillis]; // Wrap the NSTimeInterval into an NSNumber
143
+ } else {
144
+ NSLog(@"Invalid date string format");
145
+ }
146
+
133
147
 
134
148
  LatestData *d = nil;
135
149
  NSString *localName = data.device.advertise.localName;
@@ -137,13 +151,24 @@
137
151
  if (userBG > 0) {
138
152
  d = [[LatestData alloc] initWithParameters:glucose.dataId.intValue andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andNewBgToGlucoseId:glucose.dataId.intValue andNewBgValue:userBG andName:localName];
139
153
  } else {
140
- d = [[LatestData alloc] initWithParameters:([glucose.dataId intValue]) andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andName:localName];
154
+ d = [[LatestData alloc] initWithParameters:([glucose.dataId intValue]) andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andName:localName ];
141
155
  }
142
156
  d.algorithm = AlgorithmType_CT4;
157
+
158
+
159
+
160
+ NSLog( @"sensorInfosensorInf %f", d.R);
161
+
162
+ NSLog( @"sensorInfosensorInfosensorInfosensorInfo %@", d.sensorInfo);
163
+
164
+ NSLog(@"算法入参dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, algorithm=%@, year=%@, milles=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.algorithm), @(d.year), @(d.timeMillis));
165
+
166
+
167
+
143
168
 
144
- KLTLog(@"算法入参dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, newBgValue=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.newBgValue), @(d.algorithm));
145
169
  CurrentGlucose *currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
146
170
 
171
+
147
172
  if (currentGlucose.errorCode == ERROR_CODE_ALGORITHM_DATA) {
148
173
  [self reloadQueryHistoryData];
149
174
 
@@ -153,11 +178,35 @@
153
178
  d = [[LatestData alloc] initWithParameters:([glucose.dataId intValue]) andIw:[glucose.operatingCurrent floatValue] andIb:[glucose.blankCurrent floatValue] andT:[glucose.temperature floatValue] andK0:algo_k andR:algo_r andDay:[data.day intValue] andHour:[data.hour intValue] andMinute:[data.minute intValue] andName:localName];
154
179
  }
155
180
  d.algorithm = AlgorithmType_CT4;
181
+
156
182
 
157
- KLTLog(@"ERROR_CODE_ALGORITHM_DATA:dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, newBgValue=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.newBgValue), @(d.algorithm));
183
+ NSLog(@"ERROR_CODE_ALGORITHM_DATA:dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, newBgValue=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.newBgValue), @(d.algorithm));
158
184
  currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
185
+
186
+ NSString *logString = [NSString stringWithFormat:@"glucoseId=%@, Iw=%@, Ib=%@, T=%@,dayCount=%@, hour=%@, minute=%@, milles=%@, GluMG=%@,BGCount=%@, BGICount=%@, errorCode=%@ trend=%@ calibrationStatus=%@, countdownDays=%@, countdownHours=%@, countdownMinutes=%@ ",
187
+ @(d.glucoseId),
188
+ @(d.Iw),
189
+ @(d.Ib),
190
+ @(d.T),
191
+ @(d.day),
192
+ @(d.hour),
193
+ @(d.minute),
194
+ @(d.timeMillis),
195
+ @(currentGlucose.GluMG),
196
+ @(currentGlucose.BGCount),
197
+ @(currentGlucose.BGICount),
198
+ @(currentGlucose.errorCode),
199
+ @(currentGlucose.trend),
200
+ @(currentGlucose.BGMG),
201
+ @(currentGlucose.countdownDays),
202
+ @(currentGlucose.countdownHours),
203
+ @(currentGlucose.countdownHours)
204
+
205
+ ];
206
+
159
207
  }
160
208
 
209
+
161
210
  glucose.errorCode = @(currentGlucose.errorCode);
162
211
  glucose.trend = @(currentGlucose.trend);
163
212
  /* glucose.glu 保存 ADC 算法结果 单位mmol */
@@ -172,11 +221,29 @@
172
221
  data.calibration = @(currentGlucose.BGMG);
173
222
  data.error = @(currentGlucose.errorCode);
174
223
  data.trend = @(currentGlucose.trend);
175
- data.countdownDays = @(currentGlucose.countdownDays);
176
- data.countdownHours = @(currentGlucose.countdownHours);
177
- data.countdownMinutes = @(currentGlucose.countdownMinutes);
178
224
 
179
- [Notification_Center postNotificationName:@"ErrorStatusFromTransmitter" object:data];
225
+ NSString *logString = [NSString stringWithFormat:@"glucoseId=%@, Iw=%@, Ib=%@, T=%@,dayCount=%@, hour=%@, minute=%@, milles=%@, GluMG=%@,BGCount=%@, BGICount=%@, errorCode=%@ trend=%@ calibrationStatus=%@, countdownDays=%@, countdownHours=%@, countdownMinutes=%@ ",
226
+ @(d.glucoseId),
227
+ @(d.Iw),
228
+ @(d.Ib),
229
+ @(d.T),
230
+ @(d.day),
231
+ @(d.hour),
232
+ @(d.minute),
233
+ @(d.timeMillis),
234
+ @(currentGlucose.GluMG),
235
+ @(currentGlucose.BGCount),
236
+ @(currentGlucose.BGICount),
237
+ @(currentGlucose.errorCode),
238
+ @(currentGlucose.trend),
239
+ @(currentGlucose.BGMG),
240
+ @(currentGlucose.countdownDays),
241
+ @(currentGlucose.countdownHours),
242
+ @(currentGlucose.countdownHours)
243
+
244
+ ];
245
+
246
+
180
247
  [self.appDelegate saveContext];
181
248
  return glucose;
182
249
  }
@@ -327,6 +394,8 @@
327
394
  }
328
395
 
329
396
  resendDatas = [resendDatas sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"receiveDateTime" ascending:YES]]];
397
+ NSLog(@"entity: %@", entity);
398
+ NSLog(@"predicate: %@", predicate);
330
399
  NSLog(@"📡 resendDatas: %@", resendDatas);
331
400
 
332
401
  return resendDatas;
@@ -379,6 +448,7 @@
379
448
  }
380
449
 
381
450
  // 查询最近一次连接的最大的血糖ID
451
+ //Query the highest blood glucose ID from the most recent connection
382
452
  - (NSInteger)getLatestAndMaxGlucoseIdOfDevice:(Device *)currentDevice {
383
453
  NSArray *array = [self queryReceiveDataWithDevice:currentDevice needUserBG:NO];
384
454
  if (array.count > 0) {
@@ -486,6 +486,7 @@ class FinalViewModel: NSObject {
486
486
  switch status {
487
487
 
488
488
  case .disconnected:
489
+ print("----device is disconnected--------")
489
490
  print("lastBluetoothStatus-------->> \(lastBluetoothStatus)")
490
491
  if lastBluetoothStatus == .connected {
491
492
  print("===> Previously connected, delaying disconnect for 1 minute")
@@ -523,10 +524,11 @@ class FinalViewModel: NSObject {
523
524
  startScanTimer = nil
524
525
  print("--------------------------- startScanTimer is nil")
525
526
  }
526
-
527
+ print("---device is connected--------")
527
528
  debouncer.update(with: CGMConnectionStatus.connected)
528
529
 
529
530
  case .timeOut:
531
+ print("----device is timeOut--------")
530
532
  lastBluetoothStatus = .timeOut
531
533
  if !KLTLocalSettingManager.shareInstance().canConnectOtherDevice {
532
534
  startScanTimer = Timer.scheduledTimer(timeInterval: 20,
@@ -537,14 +539,17 @@ class FinalViewModel: NSObject {
537
539
  }
538
540
 
539
541
  case .sensorLostPower:
542
+ print("----device is sensorLostPower--------")
540
543
  lastBluetoothStatus = .sensorLostPower
541
544
  sensorLostPower()
542
545
 
543
546
  case .updateBindWatchSuccess:
547
+ print("----device is updateBindWatchSuccess--------")
544
548
  lastBluetoothStatus = .updateBindWatchSuccess
545
549
  startCountDown()
546
550
 
547
551
  case .closed:
552
+ print("----device is closed--------")
548
553
  lastBluetoothStatus = .closed
549
554
  debouncer.update(with: CGMConnectionStatus.transmitterDisconnect)
550
555
 
@@ -102,10 +102,10 @@ const helpCGM = async token => {
102
102
  }
103
103
  };
104
104
  exports.helpCGM = helpCGM;
105
- const observeTransmitterUnbindStatusHandler = async (token, apiResponse) => {
105
+ const observeTransmitterUnbindStatusHandler = async (token, apiResponse, patientId) => {
106
106
  console.log('observeTransmitterUnbindStatusHandler====');
107
107
  try {
108
- const result = await cgmLib.observeTransmitterUnbindStatus(token, apiResponse);
108
+ const result = await cgmLib.observeTransmitterUnbindStatus(token, apiResponse, patientId);
109
109
  console.log(result);
110
110
  } catch (error) {
111
111
  console.error(error);