react-native-mytatva-rn-sdk 1.2.59 → 1.2.61
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/android/src/main/java/com/mytatvarnsdk/CgmTrackyLibModule.kt +9 -8
- package/ios/Database/KLTAppDelegate.h +3 -0
- package/ios/Database/KLTAppDelegate.m +24 -0
- package/ios/Database/KLTBluetoothManager.m +141 -51
- package/ios/Database/KLTDatabaseHandler.h +1 -1
- package/ios/Database/KLTDatabaseHandler.m +18 -13
- package/ios/MyReactNativeBridge.m +25 -22
- package/ios/ViewModel/FinalViewModel.swift +28 -5
- package/package.json +1 -1
|
@@ -192,16 +192,16 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
192
192
|
val startDate = sensor.startDate
|
|
193
193
|
val endDate = sensor.endDate
|
|
194
194
|
val sensorId = sensor.sensorId
|
|
195
|
-
|
|
195
|
+
/* val currentPatientId = patientId
|
|
196
196
|
val lastPatientId = prefsHelper?.lastPatientId
|
|
197
|
-
val lastSensorId = prefsHelper?.qrInformation?.sensor
|
|
197
|
+
val lastSensorId = prefsHelper?.qrInformation?.sensor */
|
|
198
198
|
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
/* if (lastPatientId != null && lastSensorId != null && lastPatientId.isNotEmpty() && lastSensorId.isNotEmpty() && (lastPatientId != currentPatientId || lastSensorId != sensorId)) {
|
|
201
201
|
Log.d("delete1111", "deleting database");
|
|
202
202
|
mModel.clearAllGlucoseAndDeviceData()
|
|
203
203
|
return
|
|
204
|
-
}
|
|
204
|
+
} */
|
|
205
205
|
|
|
206
206
|
if (isCurrentDateInRange(startDate, endDate)) {
|
|
207
207
|
println("Current date is in range")
|
|
@@ -217,8 +217,9 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
217
217
|
pocDevice.qrMessage, envType
|
|
218
218
|
)
|
|
219
219
|
} else {
|
|
220
|
-
|
|
221
|
-
prefsHelper?.qrInformation?.sensor = sensorId
|
|
220
|
+
/* prefsHelper?.lastPatientId = currentPatientId
|
|
221
|
+
prefsHelper?.qrInformation?.sensor = sensorId
|
|
222
|
+
*/
|
|
222
223
|
}
|
|
223
224
|
} else {
|
|
224
225
|
postEventDataToAPI(
|
|
@@ -597,10 +598,10 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
597
598
|
|
|
598
599
|
CoroutineScope(Dispatchers.IO).launch {
|
|
599
600
|
// Step 1: Clear DB first if needed
|
|
600
|
-
|
|
601
|
+
/* if (isForClear) {
|
|
601
602
|
Log.d("delete1111-observe", "observe delete")
|
|
602
603
|
mModel.clearAllGlucoseAndDeviceData() // suspend or blocking DB operation
|
|
603
|
-
}
|
|
604
|
+
} */
|
|
604
605
|
|
|
605
606
|
// Step 2: Back to main thread to stop observers and proceed
|
|
606
607
|
withContext(Dispatchers.Main) {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#import <Foundation/Foundation.h>
|
|
11
11
|
#import <CoreData/CoreData.h>
|
|
12
12
|
#import "KLTRunLog.h"
|
|
13
|
+
#import <CoreData/CoreData.h>
|
|
13
14
|
|
|
14
15
|
@interface KLTAppDelegate : NSObject
|
|
15
16
|
|
|
@@ -18,7 +19,9 @@
|
|
|
18
19
|
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
|
|
19
20
|
|
|
20
21
|
- (void)saveContext;
|
|
22
|
+
- (void)deleteAllCoreData;
|
|
21
23
|
- (NSURL *)applicationDocumentsDirectory;
|
|
22
24
|
+ (KLTRunLog *)getCurrentKLTRunLog;
|
|
25
|
+
@property (readonly, strong) NSPersistentContainer *persistentContainer;
|
|
23
26
|
|
|
24
27
|
@end
|
|
@@ -106,4 +106,28 @@
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
- (void)deleteAllCoreData {
|
|
110
|
+
NSPersistentStoreCoordinator *storeCoordinator = self.persistentStoreCoordinator;
|
|
111
|
+
NSManagedObjectContext *context = self.managedObjectContext;
|
|
112
|
+
NSManagedObjectModel *model = storeCoordinator.managedObjectModel;
|
|
113
|
+
|
|
114
|
+
for (NSEntityDescription *entity in model.entities) {
|
|
115
|
+
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:entity.name];
|
|
116
|
+
|
|
117
|
+
NSBatchDeleteRequest *deleteRequest = [[NSBatchDeleteRequest alloc] initWithFetchRequest:fetchRequest];
|
|
118
|
+
|
|
119
|
+
NSError *deleteError = nil;
|
|
120
|
+
[storeCoordinator executeRequest:deleteRequest withContext:context error:&deleteError];
|
|
121
|
+
|
|
122
|
+
if (deleteError) {
|
|
123
|
+
NSLog(@"Failed to delete entity %@: %@", entity.name, deleteError.localizedDescription);
|
|
124
|
+
} else {
|
|
125
|
+
NSLog(@"Successfully deleted entity %@", entity.name);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
[self saveContext];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
109
133
|
@end
|
|
@@ -62,6 +62,9 @@
|
|
|
62
62
|
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
|
|
63
63
|
self.peripherals = [NSMutableArray array];
|
|
64
64
|
self.status = BluetoothManagerStatusInitial;
|
|
65
|
+
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self
|
|
66
|
+
queue:dispatch_get_main_queue()
|
|
67
|
+
options:@{CBCentralManagerOptionRestoreIdentifierKey: @"com.drstore.bluetooth.central"}];
|
|
65
68
|
self.isInResend = NO;
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -181,32 +184,37 @@
|
|
|
181
184
|
}
|
|
182
185
|
|
|
183
186
|
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
|
|
184
|
-
|
|
187
|
+
NSLog(@"%s", __FUNCTION__);
|
|
185
188
|
self.bgConnectPeripheral = peripheral;
|
|
189
|
+
|
|
190
|
+
[[KLTDatabaseHandler shared] updateDeviceWithDeviceId:[self.connectedPeripheral.identifier UUIDString]
|
|
191
|
+
scannedTime:nil
|
|
192
|
+
connectTime:nil
|
|
193
|
+
disConnectTime:[NSString getWholeStringWithDate:NSDate.date]];
|
|
186
194
|
|
|
187
|
-
[[KLTDatabaseHandler shared] updateDeviceWithDeviceId:[self.connectedPeripheral.identifier UUIDString] scannedTime:nil connectTime:nil disConnectTime:[NSString getWholeStringWithDate:NSDate.date]];
|
|
188
195
|
self.connectedPeripheral = nil;
|
|
189
196
|
self.status = BluetoothManagerStatusDisconnected;
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
if (!
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
|
|
198
|
+
if (!KLTLocalSettingManager.shareInstance.canConnectOtherDevice) {
|
|
199
|
+
if (!self.isBgForceConnectDevice) {
|
|
200
|
+
[self connectPeripheral:peripheral];
|
|
201
|
+
self.isBgForceConnectDevice = YES;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (!_rescanTimer) {
|
|
205
|
+
[_rescanTimer invalidate];
|
|
206
|
+
_rescanTimer = nil;
|
|
207
|
+
_rescanTimer = [NSTimer scheduledTimerWithTimeInterval:30
|
|
208
|
+
target:self
|
|
209
|
+
selector:@selector(startScan)
|
|
210
|
+
userInfo:nil
|
|
211
|
+
repeats:YES];
|
|
204
212
|
}
|
|
205
213
|
} else {
|
|
206
214
|
self.isBgForceConnectDevice = NO;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
215
|
+
|
|
216
|
+
[self.peripherals removeObject:peripheral];
|
|
217
|
+
|
|
210
218
|
if ([self.bluetoothDelegate respondsToSelector:@selector(onFindDevices:connectedDevice:)]) {
|
|
211
219
|
[self.bluetoothDelegate onFindDevices:_peripherals connectedDevice:nil];
|
|
212
220
|
}
|
|
@@ -624,46 +632,69 @@
|
|
|
624
632
|
}
|
|
625
633
|
|
|
626
634
|
// 开始扫描
|
|
635
|
+
//- (void)startScan {
|
|
636
|
+
// self.connectedPeripheral = nil;
|
|
637
|
+
// [self.peripherals removeAllObjects];
|
|
638
|
+
//
|
|
639
|
+
// if (self.centralManager.state != CBManagerStatePoweredOn) {
|
|
640
|
+
// return;
|
|
641
|
+
// }
|
|
642
|
+
// KLTLog(@"Allen manager start scan %d", __LINE__);
|
|
643
|
+
//
|
|
644
|
+
// if ([[User_Defaults objectForKey:@"bgmode"] intValue] == 1) {
|
|
645
|
+
// self.status = BluetoothManagerStatusDisconnected;
|
|
646
|
+
//
|
|
647
|
+
// [[KLTDatabaseHandler shared] updateDeviceWithDeviceId:[self.bgConnectPeripheral.identifier UUIDString] scannedTime:nil connectTime:nil disConnectTime:[KLTFormat getDateString]];
|
|
648
|
+
// self.connectedPeripheral = nil;
|
|
649
|
+
//
|
|
650
|
+
// if (!KLTLocalSettingManager.shareInstance.canConnectOtherDevice) {
|
|
651
|
+
// /* 如果当前周期还没结束且处于后台,则强制连接发射器 */
|
|
652
|
+
// if (!self.isBgForceConnectDevice) {
|
|
653
|
+
// [self connectPeripheral:self.bgConnectPeripheral];
|
|
654
|
+
// self.isBgForceConnectDevice = YES;
|
|
655
|
+
// }
|
|
656
|
+
//
|
|
657
|
+
// if (!_rescanTimer) {
|
|
658
|
+
// [_rescanTimer invalidate];
|
|
659
|
+
// _rescanTimer = nil;
|
|
660
|
+
// _rescanTimer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(startScan) userInfo:nil repeats:YES];
|
|
661
|
+
// }
|
|
662
|
+
// }
|
|
663
|
+
// return;
|
|
664
|
+
// }
|
|
665
|
+
//
|
|
666
|
+
// self.isBgForceConnectDevice = NO;
|
|
667
|
+
// self.status = BluetoothManagerStatusScanStart;
|
|
668
|
+
// // 如果用特定的UUID传参可能找不到任何设备
|
|
669
|
+
// // [self.centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:SERVICE_UUID]] options:nil];
|
|
670
|
+
// // 扫描多台外设
|
|
671
|
+
// NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
|
|
672
|
+
// [self.centralManager scanForPeripheralsWithServices:nil options:scanOptions];
|
|
673
|
+
// // 用定时器来监控扫描超时的情况、监控扫描时间的定时器
|
|
674
|
+
// _connectTimer = [NSTimer scheduledTimerWithTimeInterval:20.f target:self selector:@selector(endScan) userInfo:nil repeats:NO];
|
|
675
|
+
//}
|
|
676
|
+
|
|
627
677
|
- (void)startScan {
|
|
628
678
|
self.connectedPeripheral = nil;
|
|
629
679
|
[self.peripherals removeAllObjects];
|
|
630
|
-
|
|
680
|
+
|
|
631
681
|
if (self.centralManager.state != CBManagerStatePoweredOn) {
|
|
682
|
+
NSLog(@"Bluetooth is not powered on. Aborting scan.");
|
|
632
683
|
return;
|
|
633
684
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if ([[User_Defaults objectForKey:@"bgmode"] intValue] == 1) {
|
|
637
|
-
self.status = BluetoothManagerStatusDisconnected;
|
|
638
|
-
|
|
639
|
-
[[KLTDatabaseHandler shared] updateDeviceWithDeviceId:[self.bgConnectPeripheral.identifier UUIDString] scannedTime:nil connectTime:nil disConnectTime:[KLTFormat getDateString]];
|
|
640
|
-
self.connectedPeripheral = nil;
|
|
641
|
-
|
|
642
|
-
if (!KLTLocalSettingManager.shareInstance.canConnectOtherDevice) {
|
|
643
|
-
/* 如果当前周期还没结束且处于后台,则强制连接发射器 */
|
|
644
|
-
if (!self.isBgForceConnectDevice) {
|
|
645
|
-
[self connectPeripheral:self.bgConnectPeripheral];
|
|
646
|
-
self.isBgForceConnectDevice = YES;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if (!_rescanTimer) {
|
|
650
|
-
[_rescanTimer invalidate];
|
|
651
|
-
_rescanTimer = nil;
|
|
652
|
-
_rescanTimer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(startScan) userInfo:nil repeats:YES];
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
self.isBgForceConnectDevice = NO;
|
|
685
|
+
|
|
686
|
+
NSLog(@"Allen manager start scan %d", __LINE__);
|
|
659
687
|
self.status = BluetoothManagerStatusScanStart;
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
NSDictionary *scanOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
|
|
688
|
+
self.isBgForceConnectDevice = NO;
|
|
689
|
+
|
|
690
|
+
NSDictionary *scanOptions = @{ CBCentralManagerScanOptionAllowDuplicatesKey: @(YES) };
|
|
664
691
|
[self.centralManager scanForPeripheralsWithServices:nil options:scanOptions];
|
|
665
|
-
|
|
666
|
-
_connectTimer = [NSTimer scheduledTimerWithTimeInterval:20.
|
|
692
|
+
|
|
693
|
+
_connectTimer = [NSTimer scheduledTimerWithTimeInterval:20.0
|
|
694
|
+
target:self
|
|
695
|
+
selector:@selector(endScan)
|
|
696
|
+
userInfo:nil
|
|
697
|
+
repeats:NO];
|
|
667
698
|
}
|
|
668
699
|
|
|
669
700
|
// 断开与外设的连接,取消对characteristic的监听
|
|
@@ -736,4 +767,63 @@
|
|
|
736
767
|
return _currentDevice;
|
|
737
768
|
}
|
|
738
769
|
|
|
770
|
+
- (void)setStatus:(BluetoothManagerStatus)newStatus {
|
|
771
|
+
_status = newStatus;
|
|
772
|
+
|
|
773
|
+
// Notify observers
|
|
774
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:@"BLEStatusUpdated" object:@(newStatus)];
|
|
775
|
+
|
|
776
|
+
// Print with foreground/background context
|
|
777
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
778
|
+
[self logBluetoothStatus:newStatus];
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
- (void)logBluetoothStatus:(BluetoothManagerStatus)status {
|
|
783
|
+
NSString *stateString = UIApplication.sharedApplication.applicationState == UIApplicationStateBackground ? @"Background" : @"Foreground";
|
|
784
|
+
NSLog(@"[BLE] App is in %@ — Status Code******: %ld", stateString, (long)status);
|
|
785
|
+
}
|
|
786
|
+
- (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary<NSString *,id> *)dict {
|
|
787
|
+
NSLog(@" [RestoreState] iOS triggered state restoration");
|
|
788
|
+
|
|
789
|
+
NSArray *peripherals = dict[CBCentralManagerRestoredStatePeripheralsKey];
|
|
790
|
+
for (CBPeripheral *peripheral in peripherals) {
|
|
791
|
+
if (!peripheral.identifier) {
|
|
792
|
+
NSLog(@" Skipping peripheral: missing identifier");
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
NSString *peripheralId = peripheral.identifier.UUIDString;
|
|
797
|
+
NSLog(@" Restoring peripheral: %@", peripheralId);
|
|
798
|
+
|
|
799
|
+
self.connectedPeripheral = peripheral;
|
|
800
|
+
self.connectedPeripheral.delegate = self;
|
|
801
|
+
|
|
802
|
+
Device *device = [[KLTDatabaseHandler shared] queryDeviceWithId:peripheralId];
|
|
803
|
+
if (!device || !device.advertise || !device.advertise.localName) {
|
|
804
|
+
NSLog(@"No valid device info found in DB for %@", peripheralId);
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
self.eDevice = [EDevice getEnumDevice:device.advertise.localName];
|
|
809
|
+
if (!self.eDevice || !self.eDevice.eGattMessage || !self.eDevice.eGattMessage.UUID_SERVICE) {
|
|
810
|
+
NSLog(@" Invalid eDevice config. Cannot reconnect.");
|
|
811
|
+
continue;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
NSLog(@"Attempting reconnect...");
|
|
815
|
+
[self.centralManager connectPeripheral:peripheral options:nil];
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
NSArray *scanServices = dict[CBCentralManagerRestoredStateScanServicesKey];
|
|
819
|
+
NSDictionary *scanOptions = dict[CBCentralManagerRestoredStateScanOptionsKey];
|
|
820
|
+
|
|
821
|
+
if (scanServices.count > 0) {
|
|
822
|
+
NSLog(@" Restored scan services: %@", scanServices);
|
|
823
|
+
}
|
|
824
|
+
if (scanOptions) {
|
|
825
|
+
NSLog(@"Restored scan options: %@", scanOptions);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
739
829
|
@end
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
|
|
49
49
|
LatestData *d = [[LatestData alloc] initWithParameters:[data.glucoseId intValue] andIw:[data.operatingCurrent floatValue] andIb:[data.blankCurrent floatValue] andT:[data.temperature floatValue] andK0:algo_k andR:algo_r andDay:(int)[comp day] andHour:(int)[comp hour] andMinute:(int)[comp minute] andName:localName];
|
|
50
50
|
d.algorithm = AlgorithmType_CT4;
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
KLTLog(@"算法入参dataId=%@, operatingCurrent=%@, blankCurrent=%@, temperature=%@, algo_k=%@, algo_r=%@, day=%@, hour=%@, minute=%@, localName=%@, algorithm=%@", @(d.glucoseId), @(d.Iw), @(d.Ib), @(d.T), @(d.K0), @(d.R), @(d.day), @(d.hour), @(d.minute), d.name, @(d.algorithm));
|
|
53
53
|
CurrentGlucose *currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
/* data.glu 保存 ADC 算法结果 单位mmol/L */
|
|
56
56
|
/* data.gluADC 保存 凯立特 算法结果 单位mg/dL */
|
|
57
57
|
data.glu = @(currentGlucose.GluMG/18.0);
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
data.countdownHours = @(currentGlucose.countdownHours);
|
|
64
64
|
data.countdownMinutes = @(currentGlucose.countdownMinutes);
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
// [Notification_Center postNotificationName:@"ErrorStatusFromTransmitter" object:data];
|
|
67
67
|
[self.appDelegate saveContext];
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
ReceiveData *receive = [NSEntityDescription insertNewObjectForEntityForName:@"ReceiveDataInfo" inManagedObjectContext:self.context];
|
|
73
73
|
receive.userBG = currentDevice.userBG;
|
|
74
74
|
receive.initialBeginDate = currentDevice.initialBeginDate;
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
[self.appDelegate saveContext];
|
|
77
77
|
return receive;
|
|
78
78
|
}
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
glucose.temperature = data.temperature;
|
|
134
134
|
float algo_k = [[User_Defaults objectForKey:@"algo_k"] floatValue];
|
|
135
135
|
float algo_r = [[User_Defaults objectForKey:@"algo_r"] floatValue];
|
|
136
|
-
|
|
136
|
+
|
|
137
137
|
LatestData *d = nil;
|
|
138
138
|
NSString *localName = data.device.advertise.localName;
|
|
139
139
|
int userBG = roundf(glucose.userBG.floatValue * 18);
|
|
@@ -143,7 +143,7 @@
|
|
|
143
143
|
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];
|
|
144
144
|
}
|
|
145
145
|
d.algorithm = AlgorithmType_CT4;
|
|
146
|
-
|
|
146
|
+
|
|
147
147
|
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));
|
|
148
148
|
CurrentGlucose *currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
|
|
149
149
|
|
|
@@ -156,11 +156,11 @@
|
|
|
156
156
|
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];
|
|
157
157
|
}
|
|
158
158
|
d.algorithm = AlgorithmType_CT4;
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
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));
|
|
161
161
|
currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
|
|
162
162
|
}
|
|
163
|
-
|
|
163
|
+
|
|
164
164
|
glucose.errorCode = @(currentGlucose.errorCode);
|
|
165
165
|
glucose.trend = @(currentGlucose.trend);
|
|
166
166
|
/* glucose.glu 保存 ADC 算法结果 单位mmol */
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
glucose.gluADC = @(currentGlucose.GluMG);
|
|
170
170
|
// 标识下次能不能再输入校准参比
|
|
171
171
|
glucose.calibrationStatus = @(currentGlucose.calibrationStatus);
|
|
172
|
-
|
|
172
|
+
|
|
173
173
|
data.glu = @(currentGlucose.GluMG/18.0);
|
|
174
174
|
data.gluADC = @(currentGlucose.GluMG);
|
|
175
175
|
data.calibration = @(currentGlucose.BGMG);
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
glucose.hour = data.hour;
|
|
191
191
|
glucose.error = data.error;
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
// [Notification_Center postNotificationName:@"ErrorStatusFromTransmitter" object: glucose];
|
|
194
194
|
[Notification_Center postNotificationName:@"CheckErrorStatusFromLastBatchData" object: glucose];
|
|
195
195
|
|
|
196
196
|
[self.appDelegate saveContext];
|
|
@@ -227,7 +227,7 @@
|
|
|
227
227
|
|
|
228
228
|
NSArray *resendDatas = [self.context executeFetchRequest:request error:nil];
|
|
229
229
|
resendDatas = [resendDatas sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"receiveDateTime" ascending:YES]]];
|
|
230
|
-
|
|
230
|
+
|
|
231
231
|
// 🖨️ Add single-line logging for each GlucoseData entry
|
|
232
232
|
NSLog(@"==== GlucoseData (Fetched %lu records) for Device: %@ ====", (unsigned long)resendDatas.count, currentDevice.identifier);
|
|
233
233
|
for (GlucoseData *g in resendDatas) {
|
|
@@ -247,9 +247,9 @@
|
|
|
247
247
|
g.countdownHours,
|
|
248
248
|
g.countdownDays
|
|
249
249
|
|
|
250
|
-
|
|
250
|
+
);
|
|
251
251
|
}
|
|
252
|
-
|
|
252
|
+
|
|
253
253
|
return resendDatas;
|
|
254
254
|
}
|
|
255
255
|
|
|
@@ -288,6 +288,11 @@
|
|
|
288
288
|
|
|
289
289
|
[self.appDelegate saveContext];
|
|
290
290
|
}
|
|
291
|
+
|
|
292
|
+
- (void)deleteSQLiteDataArray {
|
|
293
|
+
[self.appDelegate deleteAllCoreData];
|
|
294
|
+
}
|
|
295
|
+
|
|
291
296
|
- (void)deleteReceiveDataArray:(NSArray *)dataArray {
|
|
292
297
|
|
|
293
298
|
for (NSManagedObject *record in dataArray) {
|
|
@@ -203,6 +203,7 @@
|
|
|
203
203
|
#import <React/RCTBridgeModule.h>
|
|
204
204
|
#import <React/RCTEventEmitter.h>
|
|
205
205
|
#import "react_native_mytatva_rn_sdk-Swift.h"
|
|
206
|
+
#import "KLTDatabaseHandler.h"
|
|
206
207
|
|
|
207
208
|
@implementation MyEventEmitterManager
|
|
208
209
|
|
|
@@ -455,9 +456,9 @@ RCT_EXPORT_METHOD(startCgmTracky:(NSString *)token envType: (NSString *)envType
|
|
|
455
456
|
|
|
456
457
|
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:nativeVC];
|
|
457
458
|
navController.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
459
|
+
if (nativeVC) {
|
|
460
|
+
[rootVC presentViewController:navController animated:YES completion:nil];
|
|
461
|
+
}
|
|
461
462
|
});
|
|
462
463
|
}
|
|
463
464
|
|
|
@@ -513,28 +514,32 @@ RCT_EXPORT_METHOD(openHelpSupport)
|
|
|
513
514
|
|
|
514
515
|
RCT_EXPORT_METHOD(observeAllGlucoseData:(NSString *)token isForClearData:(BOOL)isForClearData envType:(NSString *)envType)
|
|
515
516
|
{
|
|
517
|
+
if (isForClearData == YES) {
|
|
518
|
+
[[KLTDatabaseHandler shared].appDelegate deleteAllCoreData];
|
|
519
|
+
}
|
|
520
|
+
|
|
516
521
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
517
522
|
[defaults setObject:token forKey:@"authToken"];
|
|
518
523
|
[defaults setObject:envType forKey:@"envType"];
|
|
519
|
-
|
|
524
|
+
[defaults synchronize];
|
|
520
525
|
|
|
521
526
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
527
|
+
UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
|
|
528
|
+
UIViewController *rootVC = keyWindow.rootViewController;
|
|
529
|
+
|
|
530
|
+
// Load the storyboard
|
|
531
|
+
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainCGM" bundle:nil];
|
|
532
|
+
|
|
533
|
+
// Instantiate the target ViewController
|
|
534
|
+
globalAttachTransmitterVC = [storyboard instantiateViewControllerWithIdentifier:@"AttachTransmitterViewController"];
|
|
535
|
+
|
|
536
|
+
// Set presentation style
|
|
537
|
+
// chatWithExpertVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
538
|
+
|
|
539
|
+
// Present it directly without navigation
|
|
540
|
+
//if (chatWithExpertVC) {
|
|
541
|
+
// [rootVC presentViewController:chatWithExpertVC animated:YES completion:nil];
|
|
542
|
+
// }
|
|
538
543
|
});
|
|
539
544
|
}
|
|
540
545
|
|
|
@@ -581,6 +586,4 @@ RCT_EXPORT_METHOD(observeTransmitterUnbindStatus:(NSString *)token
|
|
|
581
586
|
}];
|
|
582
587
|
}
|
|
583
588
|
|
|
584
|
-
|
|
585
|
-
|
|
586
589
|
@end
|
|
@@ -114,7 +114,14 @@ import Foundation
|
|
|
114
114
|
patientId: String
|
|
115
115
|
) -> [String: Any] {
|
|
116
116
|
let updatedResponse = response
|
|
117
|
-
|
|
117
|
+
let lastSensorId = UserDefaults.standard.string(forKey: "sensorId") ?? ""
|
|
118
|
+
let lastPatientId = UserDefaults.standard.string(forKey: "patientId") ?? ""
|
|
119
|
+
|
|
120
|
+
if (lastPatientId != "" && lastSensorId != "" && (lastPatientId != patientId || lastSensorId != sensorId)) {
|
|
121
|
+
KLTDatabaseHandler.shared().deleteSQLiteDataArray()
|
|
122
|
+
return [:]
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
if viewModel.isCurrentDateInRange(startDate: startDate, endDate: endDate) {
|
|
119
126
|
print("Current date is in range")
|
|
120
127
|
|
|
@@ -123,7 +130,11 @@ import Foundation
|
|
|
123
130
|
|
|
124
131
|
if connectedPeripheral == nil && !canConnectOther {
|
|
125
132
|
viewModel.manager.startScan()
|
|
126
|
-
|
|
133
|
+
let bluetoothOff = UserDefaults.standard.bool(forKey: "bluetoothOff")
|
|
134
|
+
if bluetoothOff == false {
|
|
135
|
+
viewModel.debouncer.update(with: .transmitterDisconnect)
|
|
136
|
+
}
|
|
137
|
+
|
|
127
138
|
} else {
|
|
128
139
|
if let device = KLTBluetoothManager.shared().currentDevice {
|
|
129
140
|
if device.connectedDateTime == nil && device.disconnectedDateTime == nil {
|
|
@@ -315,12 +326,21 @@ class FinalViewModel: NSObject {
|
|
|
315
326
|
|
|
316
327
|
addAllObservers()
|
|
317
328
|
}
|
|
318
|
-
|
|
329
|
+
|
|
330
|
+
@objc func onBLEStatusUpdate(_ notification: Notification) {
|
|
331
|
+
if let statusNumber = notification.object as? NSNumber {
|
|
332
|
+
let status = statusNumber.intValue
|
|
333
|
+
print("[UI] BLE status********: \(status)")
|
|
334
|
+
// update UI or call startScan again
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
319
338
|
func addAllObservers() {
|
|
320
339
|
manager.addObserver(self, forKeyPath: "status", options: .new, context: nil)
|
|
321
340
|
|
|
322
341
|
NotificationCenter.default.addObserver(self, selector: #selector(bluetoothEnable(_:)), name: NSNotification.Name("BluetoothEnable"), object: nil)
|
|
323
|
-
|
|
342
|
+
NotificationCenter.default.addObserver(self, selector: #selector(onBLEStatusUpdate(_:)), name: NSNotification.Name("BLEStatusUpdated"), object: nil)
|
|
343
|
+
|
|
324
344
|
// NotificationCenter.default.addObserver(self, selector: #selector(errorStatusFromTransmitter(_:)), name: NSNotification.Name("ErrorStatusFromTransmitter"), object: nil)
|
|
325
345
|
|
|
326
346
|
NotificationCenter.default.addObserver(self, selector: #selector(handleLatestReceiveData(_:)), name: NSNotification.Name(KLTAlertCurrentInInitialNotify), object: nil)
|
|
@@ -518,8 +538,11 @@ class FinalViewModel: NSObject {
|
|
|
518
538
|
@objc func bluetoothEnable(_ notification: Notification) {
|
|
519
539
|
if let isBluetoothEnabled = notification.object as? Bool {
|
|
520
540
|
if !isBluetoothEnabled {
|
|
541
|
+
UserDefaults.standard.set(true, forKey: "bluetoothOff")
|
|
521
542
|
debouncer.update(with: CGMConnectionStatus.bluetoothOff)
|
|
522
543
|
//API.shared.sendStatus(status: .bluetoothOff)
|
|
544
|
+
} else {
|
|
545
|
+
UserDefaults.standard.set(false, forKey: "bluetoothOff")
|
|
523
546
|
}
|
|
524
547
|
}
|
|
525
548
|
if ((manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
|
|
@@ -602,7 +625,7 @@ class FinalViewModel: NSObject {
|
|
|
602
625
|
|
|
603
626
|
if KLTLocalSettingManager.shareInstance().canConnectOtherDevice {
|
|
604
627
|
endBleSensorCycle()
|
|
605
|
-
} else if UserDefaults.standard.integer(forKey: "bgmode") != 1
|
|
628
|
+
} else {//if UserDefaults.standard.integer(forKey: "bgmode") != 1
|
|
606
629
|
manager.startScan()
|
|
607
630
|
}
|
|
608
631
|
|