Stride sensor

From Polar Developers
Jump to: navigation, search


General

On this page you will find the operational flow diagrams for the stride sensor. You can also find links to the used Bluetooth specifications and example codes.

Services in use

Running Speed and Cadence: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.running_speed_and_cadence.xml
Device information: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.device_information.xml
Battery: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.battery_service.xml

Flow diagrams



Back to top

Running example code for iOS

// RSC (Running Speed And Cadence) example code

#define RSC_SERVICE @"1814"
#define RSC_MEASUREMENT @"2A53"

struct rscflags
{
	uint8_t _stride_length_present:1;
	uint8_t _distance_present:1;
	uint8_t _walking_status:1;
	uint8_t _reserved:5;
};


- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)aPeripheral
{
	[aPeripheral setDelegate:self];
	// NOTE you might only discover RSC service, but on this example we discover all services 
    [aPeripheral discoverServices:nil];
}

- (void) peripheral:(CBPeripheral *)aPeripheral didDiscoverServices:(NSError *)error
{
	if(!error)
	{
		for (CBService *aService in aPeripheral.services)
		{
			if( [aService.UUID isEqual:[CBUUID UUIDWithString:RSC_SERVICE]] )
			{
				[aPeripheral discoverCharacteristics:nil forService:aService];
			}
		}
	}
}

- (void) peripheral:(CBPeripheral *)aPeripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
	if(!error)
	{
		if( [aService.UUID isEqual:[CBUUID UUIDWithString:RSC_SERVICE]] )
		{
			for (CBCharacteristic *aChar in service.characteristics)
            {
                if( [aChar.UUID isEqual:[CBUUID UUIDWithString:RSC_MEASUREMENT]] )
                {
                    [aPeripheral setNotifyValue:YES forCharacteristic:aChar];
                }
            }
		}
	}
}

- (void) peripheral:(CBPeripheral *)aPeripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
	if(!error)
	{
		if( [characteristic.UUID isEqual:[CBUUID UUIDWithString:RSC_MEASUREMENT]] )
		{
			const uint8_t *report_data( (uint8_t*)[characteristic.value bytes] );
			int data_size( [characteristic.value length] );
			
			rscflags flags={0};
			memcpy(&flags,report_data,sizeof(flags));
			
			int offset(sizeof(flags));

			// get speed
			uint16_t speed_mask(0);
			memcpy(&speed_mask, report_data+offset, sizeof(speed_mask));
			// speed in km/h
			double speed_in_km_h = ((double)speed_mask/256.0)*3.6;
			offset += sizeof(speed_mask);

			// get cadence
			uint8_t cadence(0);
			memcpy(&cadence,report_data+offset,sizeof(cadence));
			offset += sizeof(cadence);

			// get stride length if present
			if( flags._stride_length_present )
			{
				uint16_t stride_length(0);
				memcpy(&stride_length, report_data+offset, sizeof(stride_length));
				offset += sizeof(stride_length);
			}
			
			// get distance if present
			if( flags._distance_present )
			{
				uint32_t distance_in_dm(0);
				memcpy(&distance_tmp, report_data+offset, sizeof(distance_tmp));
			}
		}
    }
} 




Back to top

Running example code for Android

Example codes for Android implementation can be found here on the Android developer site



Back to top

Other Sensors



Back to top