Skip to content

Commit

Permalink
Merge pull request #12 from SensingKit/next
Browse files Browse the repository at this point in the history
Release 0.5.0
  • Loading branch information
minoskt authored Mar 2, 2017
2 parents 5143aaa + 780bd33 commit 22e354e
Show file tree
Hide file tree
Showing 96 changed files with 2,504 additions and 1,357 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

### 0.5.0 (March 2, 2017)
- Added error handling support using NSError.
- Updated Eddystone Scanner into latest version.
- Changed library into a dynamic framework.
- Added CocoaPod support.
- Added support for iOS 10.
- Improved SensingKit API.
- Updated SensingKit Documentation.

### 0.4.2 (November 27, 2015)
- Fixed a bug were sensor configuration was not updated.

Expand Down
Empty file modified ESSEddystone/AUTHORS
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion ESSEddystone/CONTRIBUTORS
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Roy Want <roywant@google.com>
Giovanni Ortuno <ortuno@google.com>
Dave Smith <smith@wiresareobsolete.com>
Christopher Dro <casheghian@gmail.com>

Shuichi Tsutsumi <shuichi0526@gmail.com>
3 changes: 3 additions & 0 deletions ESSEddystone/ESSBeaconScanner.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
- (void)beaconScanner:(ESSBeaconScanner *)scanner
didUpdateBeacon:(id)beaconInfo;

- (void)beaconScanner:(ESSBeaconScanner *)scanner
didFindURL:(NSURL *)url;

@end

@interface ESSBeaconScanner : NSObject
Expand Down
46 changes: 31 additions & 15 deletions ESSEddystone/ESSBeaconScanner.m
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ @interface ESSBeaconScanner () <CBCentralManagerDelegate> {
* Then, the next time we see a UID frame for that Eddystone, we can add the most recently seen
* telemetry frame to the sighting.
*/
NSMutableDictionary *_deviceIDCache;
NSMutableDictionary *_tlmCache;

/**
* Beacons we've seen already. If we see an Eddystone and notice that we've seen it before, we
Expand All @@ -63,7 +63,7 @@ @implementation ESSBeaconScanner
- (instancetype)init {
if ((self = [super init]) != nil) {
_onLostTimeout = 15.0;
_deviceIDCache = [NSMutableDictionary dictionary];
_tlmCache = [NSMutableDictionary dictionary];
_seenEddystoneCache = [NSMutableDictionary dictionary];
_beaconOperationsQueue = dispatch_queue_create(kBeaconsOperationQueueName, NULL);
_centralManager = [[CBCentralManager alloc] initWithDelegate:self
Expand Down Expand Up @@ -107,35 +107,51 @@ - (void)centralManagerDidUpdateState:(CBCentralManager *)central {

// This will be called from the |beaconsOperationQueue|.
- (void)centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI {

didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI {
NSDictionary *serviceData = advertisementData[CBAdvertisementDataServiceDataKey];
NSData *beaconServiceData = serviceData[[ESSBeaconInfo eddystoneServiceID]];

ESSFrameType frameType = [ESSBeaconInfo frameTypeForFrame:beaconServiceData];

// If it's a telemetry (TLM) frame, then save it into our cache so that the next time we get a
// UID frame (i.e. an Eddystone "sighting"), we can include the telemetry with it.
ESSFrameType frameType = [ESSBeaconInfo frameTypeForFrame:serviceData];
if (frameType == kESSEddystoneTelemetryFrameType) {
_deviceIDCache[peripheral.identifier] = [ESSBeaconInfo telemetryDataForFrame:serviceData];
} else if (frameType == kESSEddystoneUIDFrameType) {
_tlmCache[peripheral.identifier] = beaconServiceData;
} else if (frameType == kESSEddystoneURLFrameType) {
NSURL *url = [ESSBeaconInfo parseURLFromFrameData:beaconServiceData];

// Report the sighted URL frame.
if ([_delegate respondsToSelector:@selector(beaconScanner:didFindURL:)]) {
[_delegate beaconScanner:self didFindURL:url];
}
} else if (frameType == kESSEddystoneUIDFrameType
|| frameType == kESSEddystoneEIDFrameType) {
CBUUID *eddystoneServiceUUID = [ESSBeaconInfo eddystoneServiceID];
NSData *eddystoneServiceData = serviceData[eddystoneServiceUUID];

// If we have telemetry data for this Eddystone, include it in the construction of the
// ESSBeaconInfo object. Otherwise, nil is fine.
NSData *telemetry = _deviceIDCache[peripheral.identifier];
NSData *telemetry = _tlmCache[peripheral.identifier];

ESSBeaconInfo *beaconInfo = [ESSBeaconInfo beaconInfoForUIDFrameData:eddystoneServiceData
telemetry:telemetry
RSSI:RSSI];
ESSBeaconInfo *beaconInfo;
if (frameType == kESSEddystoneUIDFrameType) {
beaconInfo = [ESSBeaconInfo beaconInfoForUIDFrameData:eddystoneServiceData
telemetry:telemetry
RSSI:RSSI];
} else {
beaconInfo = [ESSBeaconInfo beaconInfoForEIDFrameData:eddystoneServiceData
telemetry:telemetry
RSSI:RSSI];
}

if (beaconInfo != nil) {
if (beaconInfo) {
// NOTE: At this point you can choose whether to keep or get rid of the telemetry data. You
// can either opt to include it with every single beacon sighting for this beacon, or
// delete it until we get a new / "fresh" TLM frame. We'll treat it as "report it only
// when you see it", so we'll delete it each time.
[_deviceIDCache removeObjectForKey:peripheral.identifier];
[_tlmCache removeObjectForKey:peripheral.identifier];

// If we haven't seen this Eddystone before, fire a beaconScanner:didFindBeacon: and mark it
// as seen.
Expand Down
28 changes: 18 additions & 10 deletions ESSEddystone/ESSEddystone.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

typedef NS_ENUM(NSUInteger, ESSBeaconType) {
kESSBeaconTypeEddystone = 1,
kESSBeaconTypeEddystoneEID = 2,
};

typedef NS_ENUM(NSUInteger, ESSFrameType) {
kESSEddystoneUnknownFrameType = 0,
kESSEddystoneUIDFrameType = 1,
kESSEddystoneUIDFrameType,
kESSEddystoneURLFrameType,
kESSEddystoneEIDFrameType,
kESSEddystoneTelemetryFrameType,
};

Expand All @@ -33,8 +36,7 @@ typedef NS_ENUM(NSUInteger, ESSFrameType) {
@interface ESSBeaconID : NSObject <NSCopying>

/**
* Currently there's only the Eddystone format, but we'd like to leave the door open to other
* possibilities, so let's have a beacon type here in the info.
* The type of the beacon. Currently only a couple of types are supported.
*/
@property(nonatomic, assign, readonly) ESSBeaconType beaconType;

Expand All @@ -59,7 +61,6 @@ typedef NS_ENUM(NSUInteger, ESSFrameType) {
*/
@property(nonatomic, strong, readonly) NSNumber *RSSI;


/**
* The beaconID for this Eddystone. All beacons have an ID.
*/
Expand All @@ -77,28 +78,35 @@ typedef NS_ENUM(NSUInteger, ESSFrameType) {
*/
@property(nonatomic, strong, readonly) NSNumber *txPower;


/**
* The scanner has seen a frame for an Eddystone. We'll need to know what type of Eddystone frame
* it is, as there are a few types.
*/
+ (ESSFrameType)frameTypeForFrame:(NSDictionary *)advFrameList;
+ (ESSFrameType)frameTypeForFrame:(NSData *)frameData;

/**
* Given some advertisement data that we have already verified is a TLM frame (using
* frameTypeForFrame:), return the actual telemetry data for that frame.
* Given the service data for a frame we know to be a UID frame, an RSSI sighting,
* and -- optionally -- telemetry data (if we've seen it), create a new ESSBeaconInfo object to
* represent this Eddystone
*/
+ (NSData *)telemetryDataForFrame:(NSDictionary *)advFrameList;
+ (instancetype)beaconInfoForUIDFrameData:(NSData *)UIDFrameData
telemetry:(NSData *)telemetry
RSSI:(NSNumber *)initialRSSI;

/**
* Given the service data for a frame we know to be a UID frame, an RSSI sighting,
* and -- optionally -- telemetry data (if we've seen it), create a new ESSBeaconInfo object to
* represent this Eddystone
*/
+ (instancetype)beaconInfoForUIDFrameData:(NSData *)UIDFrameData
+ (instancetype)beaconInfoForEIDFrameData:(NSData *)EIDFrameData
telemetry:(NSData *)telemetry
RSSI:(NSNumber *)initialRSSI;

/**
* If we're given a URL frame, extract the URL from it.
*/
+ (NSURL *)parseURLFromFrameData:(NSData *)URLFrameData;

/**
* Convenience method to save everybody from creating these things all the time.
*/
Expand Down
Loading

0 comments on commit 22e354e

Please sign in to comment.