From d6d9a09d505d11148599a95a5be3e1351edbe0ac Mon Sep 17 00:00:00 2001 From: hc Date: Mon, 13 Apr 2026 15:17:52 +0800 Subject: Local iHealth SDK, device detail screen, iOS event fixes --- .../ios/ReactNativeIOSLibrary/BG1SModule.m | 224 +++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m') diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m new file mode 100644 index 0000000..f841037 --- /dev/null +++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m @@ -0,0 +1,224 @@ +// +// BG1SModule.m +// ReactNativeIOSLibrary +// +// Created by user on 2019/11/12. +// Copyright © 2019 daiqingquan. All rights reserved. +// + +#import "BG1SModule.h" +#import "BG1S.h" +#import "BG1SController.h" +#import "BG1SProfileModule.h" + +#import "BGHeader.h" + +@implementation BG1SModule +RCT_EXPORT_MODULE() +- (NSArray *)supportedEvents { + return @[@"event_notify", @"event_scan_device", @"event_scan_finish", + @"event_device_connected", @"event_device_connect_failed", + @"event_device_disconnect", @"event_authenticate_result", + @"event_notify_ts28b", @"event_notify_bg1", + @"action_connect_result_for_bg1"]; +} + + +- (NSDictionary *)constantsToExport +{ + return @{ @"Event_Notify": BG1S_EVENT_NOTIFY , + + }; +} + ++ (BOOL)requiresMainQueueSetup +{ + return YES; +} + + +-(BG1S*)getDeviceWithMac:(NSString*)mac{ + + BG1SController *controller = [BG1SController shareIHBG1SController]; + NSArray *BG1SDeviceArray = [controller getAllCurrentBG1SInstace]; + + for(BG1S *tempDevice in BG1SDeviceArray){ + if([mac isEqualToString:tempDevice.serialNumber]){ + + return tempDevice; + } + } + return nil; +} + +RCT_EXPORT_METHOD(getAllConnectedDevices){ + + + NSArray*BG1SDeviceArray= [[BG1SController shareIHBG1SController] getAllCurrentBG1SInstace]; + + NSMutableArray*deviceMacArray=[NSMutableArray array]; + + for (int i=0; i<[BG1SDeviceArray count]; i++) { + + BG1S *BG1S = [BG1SDeviceArray objectAtIndex:i]; + + [deviceMacArray addObject:BG1S.serialNumber]; + + } + + NSDictionary* deviceInfo = @{BG1S_ACTION:kACTION_GET_ALL_CONNECTED_DEVICES,BG1S_DEVICE:deviceMacArray}; + + [self sendEventWithName:BG1S_EVENT_NOTIFY body:deviceInfo]; +} + +RCT_EXPORT_METHOD(measure:(nonnull NSString *)mac measureMode:(nonnull NSNumber *)testType){ + + + if ([self getDeviceWithMac:mac] != nil) { + + BGMeasureMode models= BGMeasureMode_Blood; + + if ([testType intValue]==1) { + + models=BGMeasureMode_NoBlood; + + }else{ + + models=BGMeasureMode_Blood; + } + + [[self getDeviceWithMac:mac] commandCreateBG1STestModel:models DisposeBGStripInBlock:^(BOOL inORout) { + + if (inORout) { + [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{ + BG1S_ACTION:ACTION_STRIP_INSERTION_STATUS, + BG1S_KEY_MAC:mac, + BG1S_TYPE:@"BG1S", + OPERATION_DESCRIBE:@"strip in", + STRIP_INSERTION_STATUS:@1, + }]; + }else{ + + [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{ + BG1S_ACTION:ACTION_STRIP_INSERTION_STATUS, + BG1S_KEY_MAC:mac, + BG1S_TYPE:@"BG1S", + OPERATION_DESCRIBE:@"strip put", + STRIP_INSERTION_STATUS:@2, + }]; + } + + } DisposeBGBloodBlock:^{ + + [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{ + BG1S_ACTION:ACTION_GET_BLOOD, + BG1S_KEY_MAC:mac, + BG1S_TYPE:@"BG1S", + OPERATION_DESCRIBE:@"get blood" + }]; + + } DisposeBGResultBlock:^(NSDictionary *result) { + + + [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{ + BG1S_ACTION:ACTION_MEASURE_RESULT, + BG1S_KEY_MAC:mac, + BG1S_TYPE:@"BG1S", + MEASURE_RESULT:[result valueForKey:@"Result"], + MEASURE_MODE:[result valueForKey:@"TestState"] + }]; + + } DisposeBGErrorBlock:^(BG1SDeviceError error) { + + [self sendBG1SErrorCode:error mac:mac]; + + }]; + + + } + +} + +//getFunction +RCT_EXPORT_METHOD(getFunction:(nonnull NSString *)mac){ + if ([self getDeviceWithMac:mac]!=nil) { + + + [[self getDeviceWithMac:mac] commandFunction:^(NSDictionary *functionDict) { + + + [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{ + BG1S_ACTION:ACTION_CODE_ANALYSIS, + BG1S_KEY_MAC:mac, + BG1S_TYPE:@"BG1S", + INFO_BATTERY_BG1S:[functionDict valueForKey:@"Battary"], + INFO_VERSION_CODE_BLOOD_BG1S:[functionDict valueForKey:@"CodeVersion"], + INFO_VERSION_CODE_CTL_BG1S:[functionDict valueForKey:@"DcodeVersion"], + + }]; + + } DisposeBGErrorBlock:^(BG1SDeviceError error) { + + + [self sendBG1SErrorCode:error mac:mac]; + + }]; + + + } +} + +//断开连接 +RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){ + + if ([self getDeviceWithMac:mac]!=nil) { + + [[self getDeviceWithMac:mac] commandDisconnectDevice]; + } + +} + +-(void)sendBG1SErrorCode:(BG1SDeviceError)errorID mac:(NSString*)mac{ + + NSString *errorMassage = [NSString string]; + switch (errorID) { + case 0: + errorMassage = @"BG1SDeviceError0"; + break; + case 1: + errorMassage = @"BG1SError_LowBattery"; + break; + case 2: + errorMassage = @"BG1SError_ReferenceUnstable"; + break; + case 3: + errorMassage = @"BG1SError_BadStrip"; + break; + case 4: + errorMassage = @"BG1SError_BadEEPROM"; + break; + case 5: + errorMassage = @"BG1SError_LowAmbientTemperature"; + break; + case 6: + errorMassage = @"BG1SError_HighAmbientTemperature"; + break; + case 7: + errorMassage = @"BG1SError_BleedEarly"; + break; + case 8: + errorMassage = @"BG1SError_Other"; + break; + + + default: + break; + } + + NSDictionary *deviceInfo = @{BG1S_KEY_MAC:mac,BG1S_ACTION:ACTION_ERROR_BG1S,ERROR_NUM_BG1S:[NSNumber numberWithInt:errorID],ERROR_DESCRIPTION_BG1S:errorMassage}; + [self sendEventWithName:BG1S_EVENT_NOTIFY body:deviceInfo]; + + +} + +@end -- cgit