Code Monkey home page Code Monkey logo

spo2-ble-for-ios's Introduction

demo

SpO2-BLE-for-iOS

This demo show you how to connect the BLE Oximeters, obtain & parse data, and display the pulse waveform. For protocol details, please refer the paper https://github.com/zh2x/BCI_Protocol

该demo用于演示如何连接 BLE 蓝牙血氧仪,获取并解析数据以及显示脉搏波形。关于协议细节可以参考协议文档 https://github.com/zh2x/BCI_Protocol

spo2-ble-for-ios's People

Contributors

zh2x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

spo2-ble-for-ios's Issues

EXC_BAD_ACCESS when running in Swift

Hi,

I'm trying to use this in a Swift project. I created a bridging header and added the following 4 files to my Xcode project.

BMOximeterAnalyzer.h
BMOximeterAnalyzer.m
BMOximeterParams.h
BMOximeterParams.m

When I run it and connect to the oximeter and start receiving data, it crashes with the following error when calling the removeObjectsInRange method at the end of the addData function.

Thread 1: EXC_BAD_ACCESS (code=1, address=0x50008f7f7f50008f)

-(void)addData:(NSData *)data
{
    BOOL isPackageHeaderFound = NO;
    Byte package[5]           = {0};
    int  packageIndex         = 0;
    
    int  parserIndex = 0;
    int  i = 0;

    
    Byte *bytes = (Byte *)[data bytes];
    for(int i= 0; i < data.length; i++)
    {
        [self.dataArray addObject: [NSNumber numberWithInt:(int)(bytes[i]&0xff) ]];
    }
    
    if(self.dataArray.count < 10)
    {
        return;
    }
    
    
    while (i < self.dataArray.count)
    {
        //scan for package header
        if([self.dataArray[i] integerValue] & 0x80)
        {
            isPackageHeaderFound     = YES;
            package[packageIndex ++] = [self.dataArray[i] integerValue];
            i++;
            continue;
        }
        
        if(isPackageHeaderFound)
        {
            package[packageIndex ++] = [self.dataArray[i] integerValue];
            if(packageIndex == 5)
            {
                BMOximeterParams *params = [[BMOximeterParams alloc] init];
                
                params.waveAmplitude  = package[1];
                params.pulseRateValue = package[3] | ((package[2] & 0x40) << 1);
                params.SpO2Value      = package[4];
                
                //refresh parameters
                if (params.SpO2Value != self.oximeterParams.SpO2Value || params.pulseRateValue != self.oximeterParams.pulseRateValue)
                {
                    
                    if([self.delegate respondsToSelector:@selector(OximeterAnalyzer:didRefreshOximeterParams:)])
                    {
                        [self.delegate performSelector:@selector(OximeterAnalyzer:didRefreshOximeterParams:) withObject:params];
                    }
                }
                
                //refresh pulse wave
                if([self.delegate respondsToSelector:@selector(OximeterAnalyzer:didRefreshOximeterWaveAmplitude:)])
                {
                    [self.delegate performSelector:@selector(OximeterAnalyzer:didRefreshOximeterWaveAmplitude:) withObject:params];
                }
                
                self.oximeterParams = params;
                
                
                packageIndex         = 0;
                isPackageHeaderFound = NO;
                parserIndex          = i;
                memset(package, 0, sizeof(package));
            }
        }
        
        i++;
        
    }
    [self.dataArray removeObjectsInRange:NSMakeRange(0, parserIndex+1)];
}

@end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.