react-native-mytatva-rn-sdk 1.2.52 → 1.2.54
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 +113 -73
- package/android/src/main/java/com/mytatvarnsdk/activity/ConnectSensorActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/activity/PermissionActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/activity/PlaceSensorActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/activity/PlaceTransmitterActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/activity/SearchTransmitterActivity.kt +3 -4
- package/android/src/main/java/com/mytatvarnsdk/activity/SensorConnectSuccessActivity.kt +8 -5
- package/android/src/main/java/com/mytatvarnsdk/activity/StartCGMActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/network/AuthenticateSDKService.kt +197 -197
- package/android/src/main/java/com/mytatvarnsdk/utils/TatvaEncryptionConfig.kt +1 -1
- package/ios/Database/KLTBluetoothManager.m +7 -2
- package/ios/Database/KLTDatabaseHandler.m +54 -104
- package/ios/Database/KLTLocalSettingManager.h +3 -0
- package/ios/MyReactNativeBridge.m +27 -15
- package/ios/Support/API.swift +30 -23
- package/ios/Support/Converter/DataConverter.swift +37 -22
- package/ios/ViewControllers/AttachTransmitterViewController.swift +4 -2
- package/ios/ViewModel/FinalViewModel.swift +52 -26
- package/lib/commonjs/CGMConnect.js +12 -12
- package/lib/commonjs/CGMConnect.js.map +1 -1
- package/lib/module/CGMConnect.js +12 -12
- package/lib/module/CGMConnect.js.map +1 -1
- package/lib/typescript/CGMConnect.d.ts +5 -5
- package/package.json +2 -2
- package/src/CGMConnect.ts +26 -12
|
@@ -118,6 +118,7 @@
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
// ------------- 保存血糖数据 -------------
|
|
121
|
+
//Save blood glucose data
|
|
121
122
|
- (GlucoseData *)addCT3GlucoseDataWithReceiveData:(ReceiveData *)data {
|
|
122
123
|
GlucoseData *glucose = [NSEntityDescription insertNewObjectForEntityForName:@"GlucoseData" inManagedObjectContext:self.context];
|
|
123
124
|
glucose.userBG = data.userBG;
|
|
@@ -130,20 +131,6 @@
|
|
|
130
131
|
glucose.temperature = data.temperature;
|
|
131
132
|
float algo_k = [[User_Defaults objectForKey:@"algo_k"] floatValue];
|
|
132
133
|
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
|
-
|
|
147
134
|
|
|
148
135
|
LatestData *d = nil;
|
|
149
136
|
NSString *localName = data.device.advertise.localName;
|
|
@@ -151,24 +138,13 @@
|
|
|
151
138
|
if (userBG > 0) {
|
|
152
139
|
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];
|
|
153
140
|
} else {
|
|
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
|
+
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];
|
|
155
142
|
}
|
|
156
143
|
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
|
-
|
|
168
144
|
|
|
145
|
+
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));
|
|
169
146
|
CurrentGlucose *currentGlucose = [AlgorithmTools algorithmLatestGlucose:d];
|
|
170
147
|
|
|
171
|
-
|
|
172
148
|
if (currentGlucose.errorCode == ERROR_CODE_ALGORITHM_DATA) {
|
|
173
149
|
[self reloadQueryHistoryData];
|
|
174
150
|
|
|
@@ -178,35 +154,11 @@
|
|
|
178
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];
|
|
179
155
|
}
|
|
180
156
|
d.algorithm = AlgorithmType_CT4;
|
|
181
|
-
|
|
182
157
|
|
|
183
|
-
|
|
158
|
+
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));
|
|
184
159
|
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
|
-
|
|
207
160
|
}
|
|
208
161
|
|
|
209
|
-
|
|
210
162
|
glucose.errorCode = @(currentGlucose.errorCode);
|
|
211
163
|
glucose.trend = @(currentGlucose.trend);
|
|
212
164
|
/* glucose.glu 保存 ADC 算法结果 单位mmol */
|
|
@@ -221,29 +173,11 @@
|
|
|
221
173
|
data.calibration = @(currentGlucose.BGMG);
|
|
222
174
|
data.error = @(currentGlucose.errorCode);
|
|
223
175
|
data.trend = @(currentGlucose.trend);
|
|
176
|
+
data.countdownDays = @(currentGlucose.countdownDays);
|
|
177
|
+
data.countdownHours = @(currentGlucose.countdownHours);
|
|
178
|
+
data.countdownMinutes = @(currentGlucose.countdownMinutes);
|
|
224
179
|
|
|
225
|
-
|
|
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
|
+
[Notification_Center postNotificationName:@"ErrorStatusFromTransmitter" object:data];
|
|
247
181
|
[self.appDelegate saveContext];
|
|
248
182
|
return glucose;
|
|
249
183
|
}
|
|
@@ -304,7 +238,7 @@
|
|
|
304
238
|
|
|
305
239
|
|
|
306
240
|
// 如果不是第一次连接发射器,更新device连接次数和连接时间
|
|
307
|
-
- (void)updateDeviceWithDeviceId:(NSString *)identify
|
|
241
|
+
- (void)updateDeviceWithDeviceId:(NSString *)identify
|
|
308
242
|
scannedTime:(NSString *)scannedTime
|
|
309
243
|
connectTime:(NSString *)connectTime
|
|
310
244
|
disConnectTime:(NSString *)disconnectTime {
|
|
@@ -362,42 +296,56 @@
|
|
|
362
296
|
|
|
363
297
|
// 根据条件查询Receivedata表
|
|
364
298
|
|
|
299
|
+
//- (NSArray *)queryReceiveDataWithDevice:(Device *)currentDevice needUserBG:(BOOL)needUserBG {
|
|
300
|
+
// if (!self.context) {
|
|
301
|
+
// NSLog(@"Core Data context is nil");
|
|
302
|
+
// return @[];
|
|
303
|
+
// }
|
|
304
|
+
//
|
|
305
|
+
// NSEntityDescription *entity = [NSEntityDescription entityForName:@"ReceiveDataInfo" inManagedObjectContext:self.context];
|
|
306
|
+
// if (!entity) {
|
|
307
|
+
// NSLog(@"Entity 'ReceiveDataInfo' not found in Core Data model");
|
|
308
|
+
// return @[];
|
|
309
|
+
// }
|
|
310
|
+
//
|
|
311
|
+
// NSFetchRequest *request = [[NSFetchRequest alloc] init];
|
|
312
|
+
// request.entity = entity;
|
|
313
|
+
//
|
|
314
|
+
// NSPredicate *predicate;
|
|
315
|
+
// if (needUserBG) {
|
|
316
|
+
// predicate = [NSPredicate predicateWithFormat:@"device.identifier = %@ AND initialBeginDate = %@ AND gluADC > 0 AND gluADC != nil AND isDelete == nil", currentDevice.identifier, currentDevice.initialBeginDate];
|
|
317
|
+
// } else {
|
|
318
|
+
// predicate = [NSPredicate predicateWithFormat:@"device.identifier = %@ AND initialBeginDate = %@ AND isDelete == nil", currentDevice.identifier, currentDevice.initialBeginDate];
|
|
319
|
+
// }
|
|
320
|
+
// request.predicate = predicate;
|
|
321
|
+
//
|
|
322
|
+
// NSError *fetchError = nil;
|
|
323
|
+
// NSArray *resendDatas = [self.context executeFetchRequest:request error:&fetchError];
|
|
324
|
+
//
|
|
325
|
+
// if (fetchError) {
|
|
326
|
+
// NSLog(@"❌ Fetch error: %@", fetchError.localizedDescription);
|
|
327
|
+
// return @[];
|
|
328
|
+
// }
|
|
329
|
+
//
|
|
330
|
+
// resendDatas = [resendDatas sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"receiveDateTime" ascending:YES]]];
|
|
331
|
+
// NSLog(@"📡 resendDatas: %@", resendDatas);
|
|
332
|
+
//
|
|
333
|
+
// return resendDatas;
|
|
334
|
+
//}
|
|
335
|
+
|
|
365
336
|
- (NSArray *)queryReceiveDataWithDevice:(Device *)currentDevice needUserBG:(BOOL)needUserBG {
|
|
366
|
-
if (!self.context) {
|
|
367
|
-
NSLog(@"Core Data context is nil");
|
|
368
|
-
return @[];
|
|
369
|
-
}
|
|
370
|
-
|
|
371
337
|
NSEntityDescription *entity = [NSEntityDescription entityForName:@"ReceiveDataInfo" inManagedObjectContext:self.context];
|
|
372
|
-
if (!entity) {
|
|
373
|
-
NSLog(@"Entity 'ReceiveDataInfo' not found in Core Data model");
|
|
374
|
-
return @[];
|
|
375
|
-
}
|
|
376
|
-
|
|
377
338
|
NSFetchRequest *request = [[NSFetchRequest alloc] init];
|
|
378
|
-
request.entity = entity;
|
|
379
|
-
|
|
380
339
|
NSPredicate *predicate;
|
|
381
340
|
if (needUserBG) {
|
|
382
|
-
predicate = [NSPredicate predicateWithFormat:@"device.identifier = %@ AND initialBeginDate = %@
|
|
341
|
+
predicate = [NSPredicate predicateWithFormat:@"device.identifier = %@ AND initialBeginDate = %@ && userBG > 0 && userBG != NIL",currentDevice.identifier, currentDevice.initialBeginDate];
|
|
383
342
|
} else {
|
|
384
|
-
predicate = [NSPredicate predicateWithFormat:@"device.identifier = %@ AND initialBeginDate = %@
|
|
343
|
+
predicate = [NSPredicate predicateWithFormat:@"device.identifier = %@ AND initialBeginDate = %@",currentDevice.identifier, currentDevice.initialBeginDate];
|
|
385
344
|
}
|
|
345
|
+
request.entity = entity;
|
|
386
346
|
request.predicate = predicate;
|
|
387
|
-
|
|
388
|
-
NSError *fetchError = nil;
|
|
389
|
-
NSArray *resendDatas = [self.context executeFetchRequest:request error:&fetchError];
|
|
390
|
-
|
|
391
|
-
if (fetchError) {
|
|
392
|
-
NSLog(@"❌ Fetch error: %@", fetchError.localizedDescription);
|
|
393
|
-
return @[];
|
|
394
|
-
}
|
|
395
|
-
|
|
347
|
+
NSArray *resendDatas = [self.context executeFetchRequest:request error:nil];
|
|
396
348
|
resendDatas = [resendDatas sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"receiveDateTime" ascending:YES]]];
|
|
397
|
-
NSLog(@"entity: %@", entity);
|
|
398
|
-
NSLog(@"predicate: %@", predicate);
|
|
399
|
-
NSLog(@"📡 resendDatas: %@", resendDatas);
|
|
400
|
-
|
|
401
349
|
return resendDatas;
|
|
402
350
|
}
|
|
403
351
|
|
|
@@ -448,7 +396,7 @@
|
|
|
448
396
|
}
|
|
449
397
|
|
|
450
398
|
// 查询最近一次连接的最大的血糖ID
|
|
451
|
-
//Query the highest
|
|
399
|
+
//Query the highest glucose ID from the most recent connection.
|
|
452
400
|
- (NSInteger)getLatestAndMaxGlucoseIdOfDevice:(Device *)currentDevice {
|
|
453
401
|
NSArray *array = [self queryReceiveDataWithDevice:currentDevice needUserBG:NO];
|
|
454
402
|
if (array.count > 0) {
|
|
@@ -459,6 +407,7 @@
|
|
|
459
407
|
}
|
|
460
408
|
|
|
461
409
|
// 获取距离某个设备的到期时间还剩多少数据没有接收完
|
|
410
|
+
//Get how much data remains to be received before the device reaches its expiration time
|
|
462
411
|
- (NSInteger)numberOfLifeCycleSensorWithDevice:(Device *)currentDevice endNumber:(int)endNumber {
|
|
463
412
|
if (currentDevice) {
|
|
464
413
|
NSArray *array = [self queryReceiveDataWithDevice:currentDevice needUserBG:NO];
|
|
@@ -468,7 +417,7 @@
|
|
|
468
417
|
}
|
|
469
418
|
|
|
470
419
|
#pragma mark - APP重启后需要手动调用历史数据
|
|
471
|
-
|
|
420
|
+
//After restarting the app, is it necessary to manually request historical data?
|
|
472
421
|
- (void)reloadQueryHistoryData {
|
|
473
422
|
Device *currentDevice = KLTBluetoothManager.sharedManager.currentDevice;
|
|
474
423
|
if (nil == currentDevice) {
|
|
@@ -512,6 +461,7 @@
|
|
|
512
461
|
data.TsCount = (int)index + 1;
|
|
513
462
|
|
|
514
463
|
// 校准后的点
|
|
464
|
+
//Point after calibration
|
|
515
465
|
NSArray<ReceiveData*> *needUserBgs = [self queryReceiveDataWithDevice:currentDevice needUserBG:YES];
|
|
516
466
|
NSUInteger numberOfUserBgs = needUserBgs.count;
|
|
517
467
|
if (needUserBgs.count > 0) {
|
|
@@ -31,6 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
31
31
|
@property (nonatomic, assign) BOOL hasNumberPrefix;
|
|
32
32
|
|
|
33
33
|
// 是否能连其他发射器 NO:标识当前已绑定发射器 YES:当前未绑定发射器
|
|
34
|
+
//Can other transmitters be connected
|
|
35
|
+
//NO: Indicates that a transmitter is already bound
|
|
36
|
+
//YES: Indicates that no transmitter is currently bound
|
|
34
37
|
@property (nonatomic, assign) BOOL canConnectOtherDevice;
|
|
35
38
|
|
|
36
39
|
@end
|
|
@@ -434,11 +434,14 @@ RCT_EXPORT_MODULE();
|
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
|
|
437
|
-
RCT_EXPORT_METHOD(startCgmTracky:(NSString *)token)
|
|
437
|
+
RCT_EXPORT_METHOD(startCgmTracky:(NSString *)token envType: (NSString *)envType)
|
|
438
438
|
{
|
|
439
|
-
|
|
440
|
-
[
|
|
441
|
-
|
|
439
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
440
|
+
[defaults setObject:token forKey:@"authToken"];
|
|
441
|
+
[defaults setBool:false forKey:@"isForReconnect"];
|
|
442
|
+
[defaults setObject:envType forKey:@"envType"];
|
|
443
|
+
|
|
444
|
+
[defaults synchronize];
|
|
442
445
|
|
|
443
446
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
444
447
|
UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
|
|
@@ -459,12 +462,14 @@ RCT_EXPORT_METHOD(startCgmTracky:(NSString *)token)
|
|
|
459
462
|
}
|
|
460
463
|
|
|
461
464
|
|
|
462
|
-
RCT_EXPORT_METHOD(reconnectCgmTracky:(NSString *)token) {
|
|
465
|
+
RCT_EXPORT_METHOD(reconnectCgmTracky:(NSString *)token envType: (NSString *)envType) {
|
|
463
466
|
NSLog(@"Received token: %@", token);
|
|
464
|
-
|
|
465
|
-
[
|
|
466
|
-
[
|
|
467
|
-
[
|
|
467
|
+
|
|
468
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
469
|
+
[defaults setObject:token forKey:@"authToken"];
|
|
470
|
+
[defaults setBool:YES forKey:@"isForReconnect"];
|
|
471
|
+
[defaults setObject:envType forKey:@"envType"];
|
|
472
|
+
[defaults synchronize];
|
|
468
473
|
|
|
469
474
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
470
475
|
UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
|
|
@@ -506,10 +511,12 @@ RCT_EXPORT_METHOD(openHelpSupport)
|
|
|
506
511
|
});
|
|
507
512
|
}
|
|
508
513
|
|
|
509
|
-
RCT_EXPORT_METHOD(observeAllGlucoseData:(NSString *)token)
|
|
514
|
+
RCT_EXPORT_METHOD(observeAllGlucoseData:(NSString *)token isForClearData:(BOOL)isForClearData envType:(NSString *)envType)
|
|
510
515
|
{
|
|
511
|
-
|
|
512
|
-
|
|
516
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
517
|
+
[defaults setObject:token forKey:@"authToken"];
|
|
518
|
+
[defaults setObject:envType forKey:@"envType"];
|
|
519
|
+
[defaults synchronize];
|
|
513
520
|
|
|
514
521
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
515
522
|
UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
|
|
@@ -534,6 +541,8 @@ RCT_EXPORT_METHOD(observeAllGlucoseData:(NSString *)token)
|
|
|
534
541
|
|
|
535
542
|
RCT_EXPORT_METHOD(observeTransmitterUnbindStatus:(NSString *)token
|
|
536
543
|
response:(NSString *)responseJsonString
|
|
544
|
+
patientId: (NSString *)patientId
|
|
545
|
+
envType: (NSString *)envType
|
|
537
546
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
538
547
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
539
548
|
if (responseJsonString == nil || ![responseJsonString isKindOfClass:[NSString class]]) {
|
|
@@ -553,9 +562,12 @@ RCT_EXPORT_METHOD(observeTransmitterUnbindStatus:(NSString *)token
|
|
|
553
562
|
return;
|
|
554
563
|
}
|
|
555
564
|
|
|
556
|
-
[
|
|
557
|
-
[
|
|
558
|
-
[
|
|
565
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
566
|
+
[defaults setObject:token forKey:@"authToken"];
|
|
567
|
+
[defaults setObject:data forKey:@"CGMStatusItem"];
|
|
568
|
+
[defaults setObject:patientId forKey:@"patientId"];
|
|
569
|
+
[defaults setObject:envType forKey:@"envType"];
|
|
570
|
+
[defaults synchronize];
|
|
559
571
|
|
|
560
572
|
FinalViewModelManager *manager = [FinalViewModelManager shared];
|
|
561
573
|
[manager callForObserveTransmitterUnbindStatusWithCompletion:^(NSDictionary *response, NSError *error) {
|
package/ios/Support/API.swift
CHANGED
|
@@ -10,8 +10,9 @@ import CommonCrypto
|
|
|
10
10
|
|
|
11
11
|
let PROD_API_KEY = "lChjFRJce3bxmoS3TSQk5w=="
|
|
12
12
|
let STAGE_API_KEY = "lChjFRJce3bxmoS3TSQk5w=="
|
|
13
|
+
|
|
13
14
|
let PROD_BASE_URL = "https://api.mytatva.in/api/v8"
|
|
14
|
-
let STAGE_BASE_URL = "https://api-
|
|
15
|
+
let STAGE_BASE_URL = "https://api-uat.mytatva.in/api/v8"
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
let PROD_ENC_KEY = "9Ddyaf6rfywpiTvTiax2iq6ykKpaxgJ6"
|
|
@@ -23,7 +24,7 @@ let STAGE_ENC_IV = "9Ddyaf6rfywpiTvT"
|
|
|
23
24
|
|
|
24
25
|
let defaultToken = "ILtFcw+xtbuy8IgsBCSyD6nSpgZd5AOz7T+g3N8Tef/INZi+dxwPJhnBc2kfdq2e8Kw2yayjaKjuji64coUJsK7e4QcF7sqXCp3Cy5S2OVE+hONwCipkrn9d1yjsBWIDqfLK9ModJCWdigDj5ZeSwkWYSSeTEVoN3Dc2Y8cuqKUQvN9ZcNGmdRrXz2oo3rm4EHQrXPo1Ijufm0HfcqzSH/Gh0TC5gFKjde/GEXIm5Z2Ju1/TTXVSJg/zxNuOF4iUKNEh4UIFUYxYpnqlALRCdF75J+9WAZ7/LBGyB1Wrx+D7bsrzRiQ5sCTwxE3TCM3s66lYJizX22VIzYKOIrJ6GTOYGTINHeIJKEPEvFceR+cG54ez15V1r77ErQElevItD3xIGe0uDezfnixJYPxPhSEOPOyIpxUFInXBRdGjllHPIevzBqqHeP76nz+1U7mFNs1kofugN+5huT3/tCifTQqFyWuxD+VIhl0UJxhxPMbBgoryANgKCToWrK2FqdJwBtZKwCj3S+yp0rff0fwrbMXXsYytJyVLLY2oNviHtzDa/kih0AnMA3vEbqYkf1PQ6LZv+AmtpNYHKh7kMDrhVE3wVxH4+ga0+sfuxYgfiZXCoQW7yY0wOZTiFbgvL2TQflDZR6ttK5abtyKYV4gl5KqbFLZW+d4pKLQoZb02NbJc+5h5gAH2VclTJc6fbkd0qIWuXyqGIBEc2uYrNl2v3vmVvbcGevSqb900ozo6SbFccQLjLcEon+okmgBIDPvBEZFj8fZgQV4z8/yzayDcfqZQPc9Wrw8JNrFLCd8emvo7QHFfGttnIsAtmR8Yp3x49sjEn3hFW6nEKl9FRtRT1r3LzHmIdokL5tz3nO/T3FzLn5sqfp5QBJKKK2dgJdmAz0KC6vKtJ0PtVR4shL7pqjoZuJimFObYKyQbQudW7gLH8WjqORNG2dsplOLzDQ0y7nQdQ0tWrLJtnAch0p5PyTXtunlkNWeuzrldkqVMTUPaAtGcEnmS4RFncD3C6sq9V6lpBKLdrh99vnH3EX81DTH2Hrqm0bN5Tl3UqzUJ7n/JQCR3phDmOo+Uk81y3z3ikiGZZpZikN7c3DtSP34Vc+cNUosWrChqj1gLL4Eg/jMDxE4+bdAGr03ALxEAj2uLGEsDaZRuio6e8/iMcA0z3oqhtAxQ0nU1ivAK7cHeddjRFtvrNb0l+TgrcQI9UVffMOoGDEfAQNUpT2+R5dIysw=="
|
|
25
26
|
let TOKEN = UserDefaults.standard.string(forKey: "authToken") ?? defaultToken
|
|
26
|
-
|
|
27
|
+
let envType = UserDefaults.standard.string(forKey: "envType") ?? "uat"
|
|
27
28
|
|
|
28
29
|
/*TatvaEncryptionConfig {
|
|
29
30
|
const val STAGE_BASE_URL = "https://api-feature2.mytatva.in/api/v8"
|
|
@@ -41,23 +42,23 @@ let TOKEN = UserDefaults.standard.string(forKey: "authToken") ?? defaultToken
|
|
|
41
42
|
|
|
42
43
|
struct CGMLog: Codable {
|
|
43
44
|
let timeInMillis: Double
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
// let countdownMinutes: Int
|
|
46
|
+
// let countdownDays: Int
|
|
46
47
|
let hypoglycemiaEarlyWarnMinutes: Int
|
|
47
48
|
let showGlucoseMG: Int
|
|
48
|
-
|
|
49
|
+
// let glucoseId: Int
|
|
49
50
|
let name: String
|
|
50
51
|
let bytes: [Int]
|
|
51
52
|
let showGlucose: Float
|
|
52
53
|
let Ib: Float
|
|
53
54
|
let Iw: Float
|
|
54
|
-
|
|
55
|
+
// let countdownHours: Int
|
|
55
56
|
let T: Float
|
|
56
|
-
let year: Int32
|
|
57
|
-
let month: Int32
|
|
58
|
-
let day: Int32
|
|
59
|
-
let hour: Int32
|
|
60
|
-
let minute: Int32
|
|
57
|
+
// let year: Int32
|
|
58
|
+
// let month: Int32
|
|
59
|
+
// let day: Int32
|
|
60
|
+
// let hour: Int32
|
|
61
|
+
// let minute: Int32
|
|
61
62
|
let trendObject: TrendObject
|
|
62
63
|
let glucoseStatusObject: GlucoseStatusObject
|
|
63
64
|
let errorObject: ErrorObject
|
|
@@ -96,14 +97,14 @@ class API {
|
|
|
96
97
|
private init() {}
|
|
97
98
|
|
|
98
99
|
func postCGMData(
|
|
99
|
-
environment: TatvaEnvironment,
|
|
100
100
|
data: Payload,
|
|
101
|
+
environment: TatvaEnvironment,
|
|
101
102
|
token: String = TOKEN,
|
|
102
103
|
encryptionKey: String = PROD_ENC_KEY,
|
|
103
104
|
encryptionIv: String = PROD_ENC_IV,
|
|
104
105
|
onSuccess: @escaping () -> Void,
|
|
105
106
|
onFailure: @escaping (Error?) -> Void
|
|
106
|
-
) {
|
|
107
|
+
) {// environment: TatvaEnvironment,
|
|
107
108
|
|
|
108
109
|
print("ios token:", token)
|
|
109
110
|
Task {
|
|
@@ -124,18 +125,20 @@ class API {
|
|
|
124
125
|
print("===>Decrypted (for verification): \(decrypted)")
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
let urlString = (
|
|
128
|
+
let urlString = (envType.lowercased() == "uat" ? STAGE_BASE_URL : PROD_BASE_URL) + "/cgm/logs"
|
|
129
|
+
// let urlString = (environment == .stage ? STAGE_BASE_URL : PROD_BASE_URL) + "/cgm/logs"
|
|
128
130
|
guard let url = URL(string: urlString) else {
|
|
129
131
|
throw URLError(.badURL)
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
var request = URLRequest(url: url)
|
|
133
135
|
request.httpMethod = "POST"
|
|
134
|
-
request.setValue(
|
|
136
|
+
request.setValue(envType.lowercased() == "uat" ? STAGE_API_KEY : PROD_API_KEY, forHTTPHeaderField: "api-key")
|
|
137
|
+
// request.setValue(environment == .stage ? STAGE_API_KEY : PROD_API_KEY, forHTTPHeaderField: "api-key")
|
|
135
138
|
request.setValue(token, forHTTPHeaderField: "token")
|
|
136
139
|
request.setValue("text/plain", forHTTPHeaderField: "Content-Type")
|
|
137
140
|
request.httpBody = encrypted.data(using: .utf8)
|
|
138
|
-
|
|
141
|
+
print("===>url:", urlString)
|
|
139
142
|
let (data, response) = try await URLSession.shared.data(for: request)
|
|
140
143
|
|
|
141
144
|
if let httpResponse = response as? HTTPURLResponse {
|
|
@@ -145,7 +148,7 @@ class API {
|
|
|
145
148
|
if let responseStr = String(data: data, encoding: .utf8) {
|
|
146
149
|
print("===>Server Response: \(responseStr)")
|
|
147
150
|
if let decrypted = Crypto.shared.getDecryptedData(cipherText: responseStr, encryptionKey: encryptionKey, encryptionIv: encryptionIv) {
|
|
148
|
-
print("===>Decrypted response (for verification): \(decrypted)")
|
|
151
|
+
print("===>Decrypted post cgm data response (for verification): \(decrypted)")
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
}
|
|
@@ -166,28 +169,32 @@ class API {
|
|
|
166
169
|
//addCT3GlucoseDataWithReceiveData
|
|
167
170
|
//updatePOCAlgoBeforeRef
|
|
168
171
|
func sendStatus(sensorId: String = UserDefaults.standard.string(forKey: "sensorId") ?? "",
|
|
172
|
+
environment: TatvaEnvironment,
|
|
169
173
|
status: CGMConnectionStatus,
|
|
170
174
|
transmitterName: String = KLTBluetoothManager.shared().currentDevice?.advertise?.localName ?? "",
|
|
171
175
|
encryptionKey: String = PROD_ENC_KEY,
|
|
172
176
|
encryptionIv: String = PROD_ENC_IV) {
|
|
173
177
|
if sensorId.isEmpty { return }
|
|
174
|
-
|
|
175
|
-
|
|
178
|
+
// let envType = UserDefaults.standard.string(forKey: "envType") ?? "uat"
|
|
179
|
+
print("envType: \(envType.lowercased())")
|
|
180
|
+
let urlString = (envType.lowercased() == "uat" ? STAGE_BASE_URL : PROD_BASE_URL) + "/cgm/connection"
|
|
181
|
+
//let urlString = (environment == .stage ? STAGE_BASE_URL : PROD_BASE_URL) + "/cgm/connection"
|
|
182
|
+
let url = URL(string: urlString)!
|
|
176
183
|
var request = URLRequest(url: url)
|
|
177
184
|
request.httpMethod = "POST"
|
|
178
185
|
|
|
179
186
|
// Set headers
|
|
180
187
|
request.addValue("text/plain", forHTTPHeaderField: "Content-Type")
|
|
181
|
-
request.
|
|
188
|
+
request.setValue(envType.lowercased() == "uat" ? STAGE_API_KEY : PROD_API_KEY, forHTTPHeaderField: "api-key")
|
|
189
|
+
//request.setValue(environment == .stage ? STAGE_API_KEY : PROD_API_KEY, forHTTPHeaderField: "api-key")
|
|
182
190
|
request.addValue(TOKEN, forHTTPHeaderField: "token")
|
|
183
|
-
print("===>url:",
|
|
191
|
+
print("===>url:", urlString)
|
|
184
192
|
print("===>api-key:", PROD_API_KEY)
|
|
185
193
|
print("===>httpmMethod:","POST")
|
|
186
194
|
print("===>ios token:", TOKEN)
|
|
187
195
|
// Set request body
|
|
188
196
|
let json: [String: Any] = [
|
|
189
197
|
"sensorId": sensorId,
|
|
190
|
-
// "sensorName": sensorId,
|
|
191
198
|
"status": status.rawValue,
|
|
192
199
|
"rawData": [
|
|
193
200
|
"transmitterName": transmitterName,
|
|
@@ -222,7 +229,7 @@ class API {
|
|
|
222
229
|
if let responseString = String(data: data, encoding: .utf8) {
|
|
223
230
|
print("===>Server Response: \(responseString)")
|
|
224
231
|
if let decrypted = Crypto.shared.getDecryptedData(cipherText: responseString, encryptionKey: encryptionKey, encryptionIv: encryptionIv) {
|
|
225
|
-
print("===>Decrypted response (for verification): \(decrypted)")
|
|
232
|
+
print("===>Decrypted connection api response (for verification): \(decrypted)")
|
|
226
233
|
}
|
|
227
234
|
}
|
|
228
235
|
}
|
|
@@ -7,28 +7,43 @@
|
|
|
7
7
|
|
|
8
8
|
import Foundation
|
|
9
9
|
|
|
10
|
-
func ReceiveDataToLog(data:
|
|
10
|
+
func ReceiveDataToLog(data: GlucoseData) -> CGMLog {
|
|
11
|
+
let cgmLogs = CGMLog(
|
|
12
|
+
timeInMillis: Double(Date().timeIntervalSince1970 * 1000),
|
|
13
|
+
// countdownMinutes: (data.countdownMinutes as? Int) ?? 0,
|
|
14
|
+
// countdownDays: (data.countdownDays as? Int) ?? 0,
|
|
15
|
+
hypoglycemiaEarlyWarnMinutes: 0, // still missing, you can map if available
|
|
16
|
+
showGlucoseMG: (data.gluADC as? Int) ?? 0,
|
|
17
|
+
// glucoseId: Int(truncating: data.glucoseId ?? 0),
|
|
18
|
+
name: data.device?.advertise?.localName ?? "",
|
|
19
|
+
bytes: [], // still missing: need raw data source
|
|
20
|
+
showGlucose: (data.glu as? Float) ?? 0,
|
|
21
|
+
Ib: (data.blankCurrent as? Float) ?? 0,
|
|
22
|
+
Iw: (data.operatingCurrent as? Float) ?? 0,
|
|
23
|
+
// countdownHours: (data.countdownHours as? Int) ?? 0,
|
|
24
|
+
T: (data.temperature as? Float) ?? 0.0,
|
|
25
|
+
// year: (data.year as? Int32) ?? 0,
|
|
26
|
+
// month: (data.month as? Int32) ?? 0,
|
|
27
|
+
// day: (data.day as? Int32) ?? 0,
|
|
28
|
+
// hour: (data.hour as? Int32) ?? 0,
|
|
29
|
+
// minute: (data.minute as? Int32) ?? 0,
|
|
30
|
+
|
|
31
|
+
trendObject: TrendObject(
|
|
32
|
+
trendId: (data.trend as? Int) ?? 0,
|
|
33
|
+
drawableId: 2103818652, // customize if needed
|
|
34
|
+
widgetImg: -1,
|
|
35
|
+
apsChangeRate: "FLAT" // you could map a real value if available
|
|
36
|
+
),
|
|
37
|
+
|
|
38
|
+
glucoseStatusObject: GlucoseStatusObject(
|
|
39
|
+
statusId: 1 // you may derive this from a field like `calibrationStatus`
|
|
40
|
+
),
|
|
41
|
+
|
|
42
|
+
errorObject: ErrorObject(
|
|
43
|
+
errorId: (data.errorCode as? Int) ?? 0,
|
|
44
|
+
sound: "None"
|
|
45
|
+
)
|
|
46
|
+
)
|
|
11
47
|
|
|
12
|
-
let cgmLogs = CGMLog(timeInMillis: Double(Date().timeIntervalSince1970 * 1000),
|
|
13
|
-
countdownMinutes: (data.countdownMinutes as? Int) ?? 0,
|
|
14
|
-
countdownDays: (data.countdownDays as? Int) ?? 0,
|
|
15
|
-
hypoglycemiaEarlyWarnMinutes: 0, //missing
|
|
16
|
-
showGlucoseMG: (data.gluADC as? Int) ?? 0,
|
|
17
|
-
glucoseId: Int(truncating: data.glucoseId ?? 0),
|
|
18
|
-
name: data.device?.advertise?.localName ?? "",
|
|
19
|
-
bytes: [], //missing
|
|
20
|
-
showGlucose: (data.glu as? Float) ?? 0 ,
|
|
21
|
-
Ib: (data.blankCurrent as? Float) ?? 0,
|
|
22
|
-
Iw: (data.operatingCurrent as? Float) ?? 0,
|
|
23
|
-
countdownHours: (data.countdownHours as? Int) ?? 0,
|
|
24
|
-
T: (data.temperature as? Float) ?? 0.0,
|
|
25
|
-
year: (data.year as? Int32) ?? 0,
|
|
26
|
-
month: (data.month as? Int32) ?? 0,
|
|
27
|
-
day: (data.day as? Int32) ?? 0,
|
|
28
|
-
hour: (data.hour as? Int32) ?? 0,
|
|
29
|
-
minute: (data.minute as? Int32) ?? 0,
|
|
30
|
-
trendObject: TrendObject(trendId: (data.trend as? Int) ?? 0, drawableId: 2103818652, widgetImg: -1, apsChangeRate: "FLAT"), //missing
|
|
31
|
-
glucoseStatusObject: GlucoseStatusObject(statusId: 1), //missing
|
|
32
|
-
errorObject: ErrorObject(errorId: (data.error as? Int) ?? 0, sound: "None"))
|
|
33
48
|
return cgmLogs
|
|
34
49
|
}
|
|
@@ -71,14 +71,16 @@ class AttachTransmitterViewController: UIViewController {
|
|
|
71
71
|
let data = KLTDatabaseHandler.shared().queryAllReceiveData() as! [ReceiveData]
|
|
72
72
|
print(data)
|
|
73
73
|
print("===> all data count: ", data.count)
|
|
74
|
-
KLTDatabaseHandler.shared().reloadQueryHistoryData()
|
|
74
|
+
// KLTDatabaseHandler.shared().reloadQueryHistoryData()
|
|
75
|
+
|
|
75
76
|
if let device = KLTBluetoothManager.shared().currentDevice {
|
|
76
|
-
let arrayFromInitial = KLTDatabaseHandler.shared().
|
|
77
|
+
let arrayFromInitial = KLTDatabaseHandler.shared().queryGlucoseData(with: device) as! [GlucoseData]
|
|
77
78
|
print(arrayFromInitial)
|
|
78
79
|
print("===> arrayFromInitial count: ", arrayFromInitial.count)
|
|
79
80
|
|
|
80
81
|
self.viewModel.uploadData(data: arrayFromInitial)
|
|
81
82
|
}
|
|
83
|
+
|
|
82
84
|
NotificationCenter.default.post(name: Notification.Name("cgmDeviceEvent"), object: nil, userInfo: ["a":"a"])
|
|
83
85
|
if let rootVC = UIApplication.shared.connectedScenes
|
|
84
86
|
.compactMap({ ($0 as? UIWindowScene)?.windows.first?.rootViewController })
|