YMSCBService Class Reference

Inherits from NSObject
Declared in YMSCBService.h
YMSCBService.m

Overview

Base class for defining a Bluetooth LE service.

YMSCBService holds an instance of CBService (cbService).

This class is typically subclassed to map to a service in a BLE peripheral. The subclass typically implements notifyCharacteristicHandler:error: to handle characteristics whose BLE notification has been enabled.

Properties

  name

Human-friendly name for this BLE service

@property (atomic, strong) NSString *name

Discussion

Human-friendly name for this BLE service

Declared In

YMSCBService.h

  cbService

Pointer to CBService. Note that access to the peripheral is available via the peripheral property of cbService.

@property (atomic, strong) CBService *cbService

Discussion

Pointer to CBService. Note that access to the peripheral is available via the peripheral property of cbService.

Declared In

YMSCBService.h

  parent

Pointer to parent peripheral.

@property (nonatomic, weak) YMSCBPeripheral *parent

Discussion

Pointer to parent peripheral.

Declared In

YMSCBService.h

  base

128 bit base address struct

@property (atomic, assign) yms_u128_t base

Discussion

128 bit base address struct

Declared In

YMSCBService.h

  uuid

Service UUID

@property (atomic, strong) CBUUID *uuid

Discussion

Service UUID

Declared In

YMSCBService.h

  isOn

When set to YES, the CoreBluetooth service is turned on.

@property (atomic, assign) BOOL isOn

Discussion

When set to YES, the CoreBluetooth service is turned on.

Declared In

YMSCBService.h

  isEnabled

CoreBluetooth characteristics are synchronized

@property (atomic, assign) BOOL isEnabled

Discussion

CoreBluetooth characteristics are synchronized

Declared In

YMSCBService.h

  characteristicDict

Dictionary of (key, value) pairs of (NSString, YMSCBCharacteristic) instances

@property (atomic, strong) NSMutableDictionary *characteristicDict

Discussion

Dictionary of (key, value) pairs of (NSString, YMSCBCharacteristic) instances

Declared In

YMSCBService.h

  discoverCharacteristicsCallback

Callback for characteristics that are discovered.

@property (atomic, copy) YMSCBDiscoverCharacteristicsCallbackBlockType discoverCharacteristicsCallback

Discussion

Callback for characteristics that are discovered.

Declared In

YMSCBService.h

– initWithName:parent:baseHi:baseLo:serviceOffset:

Initialize class instance.

- (instancetype)initWithName:(NSString *)oName parent:(YMSCBPeripheral *)pObj baseHi:(int64_t)hi baseLo:(int64_t)lo serviceOffset:(int)serviceOffset

Parameters

oName

name of service

pObj

parent object which owns this service

hi

top 64 bits of 128-bit base address value

lo

bottom 64 bits of 128-bit base address value

serviceOffset

offset address of service

Return Value

YMSCBCharacteristic

Discussion

Initialize class instance.

Declared In

YMSCBService.h

– initWithName:parent:baseHi:baseLo:serviceBLEOffset:

Initialize class instance.

- (instancetype)initWithName:(NSString *)oName parent:(YMSCBPeripheral *)pObj baseHi:(int64_t)hi baseLo:(int64_t)lo serviceBLEOffset:(int)serviceOffset

Parameters

oName

name of service

pObj

parent object which owns this service

hi

top 64 bits of 128-bit base address value

lo

bottom 64 bits of 128-bit base address value

serviceOffset

BLE offset address of service

Return Value

YMSCBCharacteristic

Discussion

Initialize class instance.

Declared In

YMSCBService.h

Adding a BLE characteristic

– addCharacteristic:withOffset:

Add YMSCBCharacteristic instance given address offset.

- (void)addCharacteristic:(NSString *)cname withOffset:(int)addrOffset

Parameters

cname

Characteristic name

addrOffset

Offset value

Discussion

Add YMSCBCharacteristic instance given address offset.

Declared In

YMSCBService.h

– addCharacteristic:withBLEOffset:

Add YMSCBCharacteristic instance given BLE address offset

- (void)addCharacteristic:(NSString *)cname withBLEOffset:(int)addrOffset

Parameters

cname

Characteristic name

addrOffset

BLE offset value

Discussion

Add YMSCBCharacteristic instance given BLE address offset

Declared In

YMSCBService.h

– addCharacteristic:withAddress:

Add YMSCBCharacteristic instance given absolute address.

- (void)addCharacteristic:(NSString *)cname withAddress:(int)addr

Parameters

cname

Characteristic name

addr

Absolute address value

Discussion

Add YMSCBCharacteristic instance given absolute address.

Declared In

YMSCBService.h

Retrieve CBUUIDs for all discovered characteristics

– characteristics

Return array of CBUUIDs for all YMSCBCharacteristic instances in characteristicDict.

- (NSArray *)characteristics

Return Value

array of CBUUIDs

Discussion

Return array of CBUUIDs for all YMSCBCharacteristic instances in characteristicDict.

Declared In

YMSCBService.h

– characteristicsSubset:

Return array of CBUUIDs for YMSCBCharacteristic instances in characteristicDict whose key is included in keys.

- (NSArray *)characteristicsSubset:(NSArray *)keys

Parameters

keys

array of NSString keys, where each key must exist in characteristicDict.

Return Value

array of CBUUIDs

Discussion

Return array of CBUUIDs for YMSCBCharacteristic instances in characteristicDict whose key is included in keys.

Declared In

YMSCBService.h

Synchronize found CBCharacteristic instances with corresponding their YMSCBCharacter instance

– syncCharacteristics:

Synchronize found CBCharacteristics with corresponding YMSCBCharacteristic containers.

- (void)syncCharacteristics:(NSArray *)foundCharacteristics

Parameters

foundCharacteristics

array of CBCharacteristics

Discussion

Synchronize found CBCharacteristics with corresponding YMSCBCharacteristic containers.

Declared In

YMSCBService.h

Find a YMSCBCharacteristic

– findCharacteristic:

Find characteristic container for CBCharacteristic.

- (YMSCBCharacteristic *)findCharacteristic:(CBCharacteristic *)ct

Parameters

ct

CBCharacteristic

Return Value

container of ct

Discussion

Find characteristic container for CBCharacteristic.

Declared In

YMSCBService.h

– notifyCharacteristicHandler:error:

Method to handle response update for a prior read or write request to a characteristic.

- (void)notifyCharacteristicHandler:(YMSCBCharacteristic *)yc error:(NSError *)error

Parameters

yc

Characteristic receiving update.

error

Error object.

Discussion

Method to handle response update for a prior read or write request to a characteristic.

This method is invoked by the CBPeripheralDelegate method peripheral:didUpdateValueForCharacteristic:error: conformed to by YMSCBPeripheral.

This method is typically overridden to handle characteristics whose notification has been turned on.

Declared In

YMSCBService.h

– discoverCharacteristics:withBlock:

Discover characteristics for this service.

- (void)discoverCharacteristics:(NSArray *)characteristicUUIDs withBlock:(void ( ^ ) ( NSDictionary *chDict , NSError *))callback

Parameters

characteristicUUIDs

An array of CBUUID objects that you are interested in. Here, each CBUUID object represents a UUID that identifies the type of a characteristic you want to discover.

callback

Callback block to execute upon response for discovered characteristics.

Discussion

Discover characteristics for this service.

Declared In

YMSCBService.h

– handleDiscoveredCharacteristicsResponse:withError:

Handler method for discovered characteristics.

- (void)handleDiscoveredCharacteristicsResponse:(NSDictionary *)chDict withError:(NSError *)error

Parameters

chDict

Dictionary of YMSCBCharacteristics that have been discovered.

error

Error object, if failure.

Discussion

Handler method for discovered characteristics.

Declared In

YMSCBService.h

– objectForKeyedSubscript:

Add dictionary style subscripting to YMSCBService instance to access objects in characteristicDict with key.

- (id)objectForKeyedSubscript:(id)key

Parameters

key

The key for which to return the corresponding value in characteristicDict.

Return Value

object in characteristicDict.

Discussion

Add dictionary style subscripting to YMSCBService instance to access objects in characteristicDict with key.

Declared In

YMSCBService.h