Skip to content

Commit

Permalink
fix for the special case of RSSI=127 from CoreBluetooth and report di…
Browse files Browse the repository at this point in the history
…stanceMeters=inf in this case + bump version to 1.0.2
  • Loading branch information
igor-makarov committed Jul 25, 2017
1 parent 44f3a25 commit c33eaba
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion BeaconKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ filename = File.basename(__FILE__, '.podspec')
Pod::Spec.new do |s|

s.name = "#{filename}"
s.version = '1.0.1'
s.version = '1.0.2'
s.summary = 'Beacon detection framework using CoreBluetooth'

s.description = <<~DESC
Expand Down
6 changes: 6 additions & 0 deletions BeaconKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
0FAF5913EF533EC7C0CDC103D4344C13 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 255F3EFDFE70B9EB698EAC454421409E /* LaunchScreen.storyboard */; };
1DF5DF7F36BC1435E15B02A8002467F9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BA337C630C2F1D92E182CE150373C090 /* Main.storyboard */; };
251420086869E99FAD0911C8E7DFA907 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9B1BFB8729693412184D696FE7A92CC9 /* Main.storyboard */; };
3132635798A134D98632729C48CD7BBA /* BeaconTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D82E210F70917D2A8D7141C2151D641 /* BeaconTests.swift */; };
31A885EF214D58766225A4789E2A1051 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 764776738EE523A5389C7EA7B1B6B923 /* ViewController.swift */; };
43CDD2C9519D28C62944401F46E01567 /* Pods_Common_iOS_BeaconKitSample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A402F750E9D6E4C6D2195BC0123DD98F /* Pods_Common_iOS_BeaconKitSample.framework */; };
4633EE8F6E365266EB9985A3A1352561 /* Pods_Common_iOS_BeaconKitTests_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 532B743741D12355A8A95B18D05B9FB8 /* Pods_Common_iOS_BeaconKitTests_iOS.framework */; };
Expand All @@ -21,6 +22,7 @@
7015663F19EFDEBDFCB054ABC3A40D96 /* Pods_Common_macOS_Beaconator.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97B94B342605CAEA1100DF15E9A8696E /* Pods_Common_macOS_Beaconator.framework */; };
7ECD182B19C5D2EB9057A1EB8AB76833 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 654F7F1B768E28FA38BB68AF5310EEC9 /* main.m */; };
8CDCA5527EB9A56F9A1095C5B2DA502D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 803EFC6B427D20D4A61AD319FC4640AC /* LaunchScreen.storyboard */; };
920F2A42469289CD19E92BAE4C28BA90 /* BeaconTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D82E210F70917D2A8D7141C2151D641 /* BeaconTests.swift */; };
924D836F6511794DE69AA51B931FA2ED /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C38DA49F4E06DFEEBEB70891D78122D /* ViewController.m */; };
9711A091CABDDEDF379C46879E93284D /* Benchmark.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C96373FA24D919BCDCC7EBC587C4088 /* Benchmark.swift */; };
9EC22D7E64565461AC2F2E357E9DE8AA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3A1D8793D36CD078AAE5E1B2DEEA520 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -79,6 +81,7 @@
7411AF8026AD4D5C4508F3698787C48F /* Pods-Common-iOS-BeaconKitSampleObjC.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Common-iOS-BeaconKitSampleObjC.release.xcconfig"; path = "Pods/Target Support Files/Pods-Common-iOS-BeaconKitSampleObjC/Pods-Common-iOS-BeaconKitSampleObjC.release.xcconfig"; sourceTree = "<group>"; };
764776738EE523A5389C7EA7B1B6B923 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
7BCECF73B92C53F243DA22D354A2B168 /* Pods-Common-iOS-BeaconKitTests-iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Common-iOS-BeaconKitTests-iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Common-iOS-BeaconKitTests-iOS/Pods-Common-iOS-BeaconKitTests-iOS.release.xcconfig"; sourceTree = "<group>"; };
7D82E210F70917D2A8D7141C2151D641 /* BeaconTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BeaconTests.swift; sourceTree = "<group>"; };
87B3CA45A1226569FB77A36192C39F6D /* Pods-Common-iOS-BeaconKitSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Common-iOS-BeaconKitSample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Common-iOS-BeaconKitSample/Pods-Common-iOS-BeaconKitSample.debug.xcconfig"; sourceTree = "<group>"; };
8A74CAB46818993EF777F15BDE4CFA56 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8CBCF5C720F36FE044CACC657E142744 /* Pods-Common-iOS-BeaconKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Common-iOS-BeaconKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Common-iOS-BeaconKitTests/Pods-Common-iOS-BeaconKitTests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -195,6 +198,7 @@
28AC8BEF7F3B6F2EEAECFBA4A2568E56 /* BeaconKitTests */ = {
isa = PBXGroup;
children = (
7D82E210F70917D2A8D7141C2151D641 /* BeaconTests.swift */,
4C96373FA24D919BCDCC7EBC587C4088 /* Benchmark.swift */,
2FD9CD5A4939FA223C8D7C1DEA9B64AE /* EddystoneUidParserTests.swift */,
4DBC3AB48B756A366559974153453D0F /* EddystoneUrlParserTests.swift */,
Expand Down Expand Up @@ -767,6 +771,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3132635798A134D98632729C48CD7BBA /* BeaconTests.swift in Sources */,
0544FEDC8D94FFDBEF5A3CAE3902F04D /* Benchmark.swift in Sources */,
BFA647E6C7BF016E20B5C5911E33FE05 /* EddystoneUidParserTests.swift in Sources */,
E274F55BDD8092B0BE036FE286243D46 /* EddystoneUrlParserTests.swift in Sources */,
Expand All @@ -786,6 +791,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
920F2A42469289CD19E92BAE4C28BA90 /* BeaconTests.swift in Sources */,
9711A091CABDDEDF379C46879E93284D /* Benchmark.swift in Sources */,
5DA6CF180EF5CC3A4810DB9A6FBBB7A7 /* EddystoneUidParserTests.swift in Sources */,
BE3B08E79EC5CE073D6C37A4D97E9952 /* EddystoneUrlParserTests.swift in Sources */,
Expand Down
36 changes: 36 additions & 0 deletions BeaconKitTests/BeaconTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// BeaconTests.swift
//
// Created by Igor Makarov on 25/07/2017.
//
//

import XCTest
import CoreBluetooth
@testable import BeaconKit

// swiftlint:disable force_try
// swiftlint:disable force_unwrapping

class BeaconTests: XCTestCase {
let beaconParser = BeaconParser([EddystoneUidBeacon.self])

override func setUp() {
super.setUp()
continueAfterFailure = false
}

func test_when_RSSIZero_then_distanceInfinite() {
let data = Data.from(hex: "00010001020304050607080901020304050A")
let rssi = 0
let identifier = UUID()
let advertisement = BluetoothAdvertisement.service(CBUUID(string: "FEAA"), data)
let beacons = beaconParser.beacons(advertisements: [advertisement], rssi: rssi, identifier: identifier)
XCTAssertEqual(beacons.count, 1)

let beacon = beacons[0] as! EddystoneUidBeacon
XCTAssertEqual(beacon.rssi, 0)
XCTAssertEqual(beacon.distanceMeters, .infinity)
}

}
4 changes: 2 additions & 2 deletions Sources/Core/Classes/Beacon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ open class Beacon: NSObject {

public var distanceMeters: Double {
if rssi >= 0 {
return 0
return .infinity
}

let ratio: Double = Double(rssi) / Double(txPower)
let ratio = Double(rssi) / Double(txPower)
if ratio < 1 {
return pow(ratio, 10)
} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Classes/BeaconScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension BeaconScanner: CBCentralManagerDelegate {
identifier = UUID(uuidString: uuid.uuidString)!
}

let rssi = RSSI.intValue
let rssi = RSSI.intValue == 127 ? 0 : RSSI.intValue

guard let parsedBeacons = try? _beaconParser.beacons(from: advertisementData, rssi: rssi, identifier: identifier) else { return }

Expand Down

0 comments on commit c33eaba

Please sign in to comment.