Skip to content

Commit

Permalink
Release 2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilczajkasilabs committed Jun 12, 2020
1 parent 3f0a045 commit fa6dc34
Show file tree
Hide file tree
Showing 169 changed files with 3,050 additions and 862 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ xcuserdata/
*.dSYM

# CocoaPods - Refactored to standalone file

Pods/*

# Carthage - Refactored to standalone file

Expand Down
2 changes: 2 additions & 0 deletions SiliconLabsApp-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
#import "UIColor+SILColors.h"
#import "NSString+SILBrowserNotifications.h"
#import "SILBluetoothBrowser+Constants.h"
#import "SILAdvertisementDataModel.h"
#import "SILBluetoothModelManager.h"
112 changes: 91 additions & 21 deletions SiliconLabsApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

59 changes: 38 additions & 21 deletions SiliconLabsApp/BluetoothControllers/SILCentralManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -378,31 +378,30 @@ - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(C
[self removeUnfiredConnectionTimeoutTimer];
[self handleConnectionFailureWithError:error];
[self postRegisterLogNotification:[SILLogDataModel prepareLogDescription:@"didFailToConnectPeripheral: " andPeripheral:peripheral andError:error]];
[self postFailedToConnectPeripheral:peripheral andError:error];
}

- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
NSLog(@"didDisconnectPeripheral: %@", peripheral.name);
NSLog(@"error: %@", error);
if (self.connectedPeripheral && [self.connectedPeripheral isEqual:peripheral]) {
self.connectedPeripheral = nil;

NSMutableDictionary *userInfo = nil;
if(self.disconnectingPeripheral) {
self.disconnectingPeripheral = nil;
} else {
userInfo = [NSMutableDictionary dictionary];
userInfo[SILCentralManagerPeripheralKey] = peripheral;
if (error) {
userInfo[SILCentralManagerErrorKey] = error;
}
}

[[NSNotificationCenter defaultCenter] postNotificationName:SILCentralManagerDidDisconnectPeripheralNotification
object:self
userInfo:userInfo];

BOOL wasConnected = [self.connectionsViewModel isConnectedPeripheral:peripheral];
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
userInfo[SILCentralManagerPeripheralKey] = peripheral;
userInfo[SILNotificationKeyUUID] = peripheral.identifier.UUIDString;
if (error) {
userInfo[SILCentralManagerErrorKey] = error;
}

[[NSNotificationCenter defaultCenter] postNotificationName:SILCentralManagerDidDisconnectPeripheralNotification
object:self
userInfo:userInfo];
[self postRegisterLogNotification:[SILLogDataModel prepareLogDescription:@"didDisconnectPeripheral: " andPeripheral:peripheral andError:error]];
[self postDeleteDisconnectedPeripheral:peripheral];
if (wasConnected) {
[self postDeleteDisconnectedPeripheral:peripheral andError:error];
} else {
[self postFailedToConnectPeripheral:peripheral andError:error];
}
}

#pragma mark - Notifications
Expand Down Expand Up @@ -446,11 +445,29 @@ - (void)removeScanForPeripheralsObserver:(id)observer {
}

- (void)postRegisterLogNotification:(NSString*)description {
[[NSNotificationCenter defaultCenter] postNotificationName:SILNotificationRegisterLog object:self userInfo:@{ SILNotificationKeyDescription : description}];
[[NSNotificationCenter defaultCenter] postNotificationName:SILNotificationRegisterLog
object:self
userInfo:@{
SILNotificationKeyDescription : description
}];
}

- (void)postDeleteDisconnectedPeripheral:(CBPeripheral*)peripheral {
[[NSNotificationCenter defaultCenter] postNotificationName:SILNotificationDeleteDisconnectedPeripheral object:self userInfo:@{ SILNotificationKeyUUID: peripheral.identifier.UUIDString}];
- (void)postDeleteDisconnectedPeripheral:(CBPeripheral*)peripheral andError:(NSError*)error {
[[NSNotificationCenter defaultCenter] postNotificationName:SILNotificationDeleteDisconnectedPeripheral
object:self
userInfo:@{
SILNotificationKeyUUID: peripheral.identifier.UUIDString,
SILNotificationKeyError: [NSString stringWithFormat:@"%ld", (long)error.code]
}];
}

- (void)postFailedToConnectPeripheral:(CBPeripheral*)peripheral andError:(NSError*)error {
[[NSNotificationCenter defaultCenter] postNotificationName:SILNotificationFailedToConnectPeripheral
object:self
userInfo:@{
SILNotificationKeyPeripheralName: peripheral.name,
SILNotificationKeyError: [NSString stringWithFormat:@"%ld", (long)error.code]
}];
}

#pragma mark - CLLocationManagerDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
@property (strong, nonatomic) CBPeripheral *peripheral;
@property (strong, nonatomic) SILRSSIMeasurementTable *RSSIMeasurementTable;
@property (strong, nonatomic) NSString *advertisedLocalName;
@property (strong, nonatomic) NSArray *advertisedServiceUUIDs;
@property (strong, nonatomic) NSArray<CBUUID*>* advertisedServiceUUIDs;
@property (strong, nonatomic) NSNumber *txPowerLevel;
@property (strong, nonatomic) NSData *manufacturerData;
@property (strong, nonatomic) NSArray<CBUUID*>* solicitedServiceUUIDs;
@property (strong, nonatomic) NSDictionary<CBUUID*, NSData*>* dataServiceData;
@property (strong, nonatomic) SILBeacon* beacon;
@property (nonatomic) BOOL isFavourite;
@property double advertisingInterval;
Expand Down
13 changes: 11 additions & 2 deletions SiliconLabsApp/BluetoothControllers/SILDiscoveredPeripheral.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ @implementation SILDiscoveredPeripheral
NSString* const RSSIAppendingString = @" RSSI";
NSString* const ConnectableDevice = @"Connectable";
NSString* const NonConnectableDevice = @"Non-connectable";

NSString* const EddystoneService = @"FEAA";
+ (NSString *)connectableDevice { return ConnectableDevice; }
+ (NSString *)nonConnectableDevice { return NonConnectableDevice; }

Expand All @@ -51,13 +51,15 @@ - (instancetype)initWithPeripheral:(CBPeripheral *)peripheral
- (void)updateWithAdvertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI
andDiscoveringTimestamp:(double)timestamp {
self.advertisedLocalName = advertisementData[CBAdvertisementDataLocalNameKey] ?: self.peripheral.name;
self.advertisedLocalName = advertisementData[CBAdvertisementDataLocalNameKey];
self.advertisedServiceUUIDs = advertisementData[CBAdvertisementDataServiceUUIDsKey];
self.txPowerLevel = advertisementData[CBAdvertisementDataTxPowerLevelKey];
if (!self.isConnectable) {
self.isConnectable = [advertisementData[CBAdvertisementDataIsConnectable] boolValue];
}
self.manufacturerData = advertisementData[CBAdvertisementDataManufacturerDataKey];
self.solicitedServiceUUIDs = advertisementData[CBAdvertisementDataSolicitedServiceUUIDsKey];
self.dataServiceData = advertisementData[CBAdvertisementDataServiceDataKey];
self.beacon = [self parseBeaconData:advertisementData];
if ([self isCorrectAdvertisingPacket:timestamp]) {
self.packetReceivedCount++;
Expand Down Expand Up @@ -112,6 +114,9 @@ - (SILBeacon*)parseBeaconData:(NSDictionary*)adverisement {
if (error == nil) {
return beacon;
}
} else if ([self hasEddystoneService]) {
SILBeacon* eddystoneBeacon = [SILBeacon beaconWithEddystone:self.dataServiceData[[CBUUID UUIDWithString:EddystoneService]]];
return eddystoneBeacon;
}

SILBeacon* unknownBeacon = [[SILBeacon alloc] init];
Expand Down Expand Up @@ -180,6 +185,10 @@ - (BOOL)isRangeTest {
return [self isContainService:SILServiceNumberRangeTest];
}

- (BOOL)hasEddystoneService {
return [self isContainService:EddystoneService];
}

- (BOOL)isContainService:(NSString *)serviceUUID {
CBUUID * const service = [CBUUID UUIDWithString:serviceUUID];
return [self.advertisedServiceUUIDs containsObject:service];
Expand Down
4 changes: 2 additions & 2 deletions SiliconLabsApp/Categories/CBService+Categories.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ - (BOOL)hasOTADataCharacteristic {
}

- (CBCharacteristic *)otaDataCharacteristic {
return [self characteristicForUUID:[SILUUIDProvider sharedProvider].otaCharacteristicDataUUID];
return [self characteristicForUUID:[SILUUIDProvider sharedProvider].otaCharacteristicOTADataAttributeUUID];
}

- (BOOL)hasOTAControlCharacteristic {
return [self otaControlCharacteristic]!= nil;
}

- (CBCharacteristic *)otaControlCharacteristic {
return [self characteristicForUUID:[SILUUIDProvider sharedProvider].otaCharacteristicControlUUID];
return [self characteristicForUUID:[SILUUIDProvider sharedProvider].otaCharacteristicOTAControlAttributeUUID];
}

@end
5 changes: 5 additions & 0 deletions SiliconLabsApp/Categories/NSString+SILBrowserNotifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ extern NSString * const SILNotificationReloadLogTableView;
extern NSString * const SILNotificationDisconnectPeripheral;
extern NSString * const SILNotificationDeleteDisconnectedPeripheral;
extern NSString * const SILNotificationDisconnectAllPeripheral;
extern NSString * const SILNotificationFailedToConnectPeripheral;
extern NSString * const SILNotificationCellsForVisibleRows;
extern NSString * const SILNotificationDisplayToastRequest;
extern NSString * const SILNotificationDisplayToastResponse;

extern NSString * const SILNotificationKeyIndex;
extern NSString * const SILNotificationKeyUUID;
extern NSString * const SILNotificationKeyDescription;
extern NSString * const SILNotificationKeyError;
extern NSString * const SILNotificationKeyPeripheralName;
5 changes: 5 additions & 0 deletions SiliconLabsApp/Categories/NSString+SILBrowserNotifications.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
NSString * const SILNotificationReloadLogTableView = @"ReloadLogTableView";
NSString * const SILNotificationDisconnectPeripheral = @"DisconnectPeripheral";
NSString * const SILNotificationDeleteDisconnectedPeripheral = @"DeleteDisconnectedPeripheral";
NSString * const SILNotificationFailedToConnectPeripheral = @"FailedToConnectPeripheral";
NSString * const SILNotificationDisconnectAllPeripheral = @"DisconnectAllPeripheral";
NSString * const SILNotificationCellsForVisibleRows = @"CellsForVisibleRows";
NSString * const SILNotificationDisplayToastRequest = @"DisplayToastRequest";
NSString * const SILNotificationDisplayToastResponse = @"DisplayToastResponse";

NSString * const SILNotificationKeyIndex = @"index";
NSString * const SILNotificationKeyUUID = @"uuid";
NSString * const SILNotificationKeyDescription = @"description";
NSString * const SILNotificationKeyError = @"error";
NSString * const SILNotificationKeyPeripheralName = @"peripheralName";
4 changes: 4 additions & 0 deletions SiliconLabsApp/Categories/UIImage+SILImages.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ extern NSString * const SILImageConnectOff;
extern NSString * const SILImageConnectOn;
extern NSString * const SILImageSearchOff;
extern NSString * const SILImageSearchOn;
extern NSString * const SILImageFilterOff;
extern NSString * const SILImageFilterOffSelected;
extern NSString * const SILImageFilterOn;
extern NSString * const SILImageFilterOnSelected;
extern NSString * const SILImageConnectable;
extern NSString * const SILImageRSSI;
extern NSString * const SILImageBeacon;
Expand Down
8 changes: 6 additions & 2 deletions SiliconLabsApp/Categories/UIImage+SILImages.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@
NSString * const SILImageConnectOn = @"connectOn";
NSString * const SILImageSearchOff = @"searchOff";
NSString * const SILImageSearchOn = @"searchOn";
NSString * const SILImageFilterOff = @"filterOff";
NSString * const SILImageFilterOffSelected = @"filterOffSelected";
NSString * const SILImageFilterOn = @"filterOnActive";
NSString * const SILImageFilterOnSelected = @"filterOnActiveSelected";
NSString * const SILImageConnectable = @"connectable";
NSString * const SILImageRSSI = @"rssi";
NSString * const SILImageBeacon = @"beacon";
NSString * const SILImageBeacon = @"beaconDark";
NSString * const SILImageFavouriteOff = @"favouriteOff";
NSString * const SILImageFavouriteOn = @"favouriteOn";
NSString * const SILImageLoading = @"BTStrong";
NSString * const SILImageLoading = @"loading pulse";
NSString * const SILImageEmptyView = @"debug_not_found";
NSString * const SILImageExitView = @"exitView";
NSString * const SILImageChevronCollapsed = @"chevron_collapsed";
Expand Down
57 changes: 57 additions & 0 deletions SiliconLabsApp/Categories/UIViewController+Toast.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// UIViewController+Toast.swift
// BlueGecko
//
// Created by Kamil Czajka on 11/05/2020.
// Copyright © 2020 SiliconLabs. All rights reserved.
//

import Foundation

@objc
public enum ToastType: Int {
case disconnectionError
case gattPropertiesError
}

@objc
extension UIViewController {
@objc
func showToast(message : String, toastType: ToastType, completion: @escaping () -> ()) {
let values = displayParameters(for: toastType)
let AnimationDuration = 0.5
let AnimationDelay = values.delay
let ToastHeight: CGFloat = values.height
let ToastMargin: CGFloat = 16.0
let ToastBottomSpacing: CGFloat = values.bottomSpacing
let toastLabel = UILabel(frame: CGRect(x: ToastMargin, y: self.view.frame.size.height - ToastBottomSpacing, width: self.view.frame.size.width - 2 * ToastMargin, height: ToastHeight))
toastLabel.backgroundColor = values.backgroundColor.withAlphaComponent(0.8)
toastLabel.textColor = UIColor.white
toastLabel.font = UIFont.robotoMedium(size: 14.0)
toastLabel.textAlignment = .center
toastLabel.numberOfLines = 0
toastLabel.text = message
toastLabel.alpha = 1.0
toastLabel.layer.cornerRadius = CornerRadiusStandardValue
toastLabel.clipsToBounds = true
self.view.addSubview(toastLabel)
UIView.animate(withDuration: AnimationDuration, delay: AnimationDelay, options: .curveEaseOut, animations: {
toastLabel.alpha = 0.0
}, completion: {(isCompleted) in
toastLabel.removeFromSuperview()
completion()
})
}

@nonobjc
private func displayParameters(for toastType: ToastType) -> (delay: Double, height: CGFloat, bottomSpacing: CGFloat, backgroundColor: UIColor) {
switch toastType {
case .disconnectionError:
return (3.0, 60.0, 130.0, UIColor.sil_siliconLabsRed())
case .gattPropertiesError:
return (3.0, 60.0, 65.0, UIColor.sil_siliconLabsRed())
@unknown default:
return (0.0, 0.0, 0.0, .white)
}
}
}
77 changes: 77 additions & 0 deletions SiliconLabsApp/Helpers/SILRealmConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// SILRealmConfiguration.swift
// BlueGecko
//
// Created by Kamil Czajka on 28/05/2020.
// Copyright © 2020 SiliconLabs. All rights reserved.
//

import Foundation
import RealmSwift

class SILRealmConfiguration : NSObject {
// Initial version of database
static let SchemeVersionEFR_2_0_0: UInt64 = 0

// Updated:
// - removed mappings for OTA characteristics, they already have names the same as in document AN1086, page 10
// - removed mappings for missing services from Generic Access Profile (https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/)
// - removed "search by raw advertising data" from Saved Searches's objects
static let SchemeVersionEFR_2_0_3: UInt64 = 1

@objc
static func updateRealmConfigurationIfNeeded() {
let configuration = Realm.Configuration(
schemaVersion: SILRealmConfiguration.SchemeVersionEFR_2_0_3,
migrationBlock: { migration, oldSchemeVersion in
if oldSchemeVersion < SILRealmConfiguration.SchemeVersionEFR_2_0_3 {
SILRealmConfiguration.performUpdateDatabaseForEFR_2_0_3(migration: migration)
}
}
)
Realm.Configuration.defaultConfiguration = configuration
}

private static func performUpdateDatabaseForEFR_2_0_3(migration: Migration) {
func migrateServiceMappings() {
let servicesUUIDMappingsToRemove = [
"1827",
"1826",
"183A",
"1820",
"1828",
"1829"
]

migration.enumerateObjects(ofType: "SILServiceMap") { oldObject, _ in
if let oldObject = oldObject,
let uuid = oldObject["uuid"] as? String,
servicesUUIDMappingsToRemove.contains(uuid) {
migration.delete(oldObject)
}
}
}

func migrateCharacteristicMappings() {
let characteristicsUUIDMappingsToRemove = [
"F7BF3564-FB6D-4E53-88A4-5E37E0326063",
"984227F3-34FC-4045-A5D0-2C581F81A153",
"4F4A2368-8CCA-451E-BFFF-CF0E2EE23E9F",
"4CC07BCF-0868-4B32-9DAD-BA4CC41E5316",
"25F05C0A-E917-46E9-B2A5-AA2BE1245AFE",
"0D77CC11-4AC1-49F2-BFA9-CD96AC7A92F8"
]

migration.enumerateObjects(ofType: "SILCharacteristicMap") { oldObject, _ in
if let oldObject = oldObject,
let uuid = oldObject["uuid"] as? String,
characteristicsUUIDMappingsToRemove.contains(uuid) {
migration.delete(oldObject)
}
}
}

migrateServiceMappings()
migrateCharacteristicMappings()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ - (NSString *)secondaryTitle {
return self.fieldModel.name;
}

- (void)clearValues {
self.toggleValue = @"";
}


//@discussion current implementation has this called by SILBitFieldFieldModel, which handles correct length
- (NSInteger)consumeValue:(NSData *)value fromIndex:(NSInteger)index {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ - (NSString *)secondaryTitle {
return self.fieldModel.name;
}

- (void)clearValues {
[self consumeValue:[[NSData alloc] init] fromIndex:0];
}

- (NSInteger)consumeValue:(NSData *)value fromIndex:(NSInteger)index {
if (self.fieldModel.format) {
NSData *fieldData = [[SILCharacteristicFieldValueResolver sharedResolver] subsectionOfData:value fromIndex:index forFormat:self.fieldModel.format];
Expand Down
Loading

0 comments on commit fa6dc34

Please sign in to comment.