Skip to content

Commit

Permalink
Merge pull request #18 from DrAma999/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
DrAma999 authored Jan 29, 2021
2 parents 52cf7de + 440d292 commit 99ebe19
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 42 deletions.
18 changes: 12 additions & 6 deletions LittleBlueTooth.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
65AD4BE324D437B700C0CBE6 /* CoreBluetoothTypeAliases.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_28 /* CoreBluetoothTypeAliases.swift */; };
65AD4BE424D437B700C0CBE6 /* LittleBlueTooth.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_29 /* LittleBlueTooth.swift */; };
65AD4BF024D438AD00C0CBE6 /* LittleBlueToothForTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65AD4BEB24D437B700C0CBE6 /* LittleBlueToothForTest.framework */; };
65B7D53D25C3E01300556409 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B7D53C25C3E01300556409 /* Log.swift */; };
65B7D53E25C3E01300556409 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B7D53C25C3E01300556409 /* Log.swift */; };
65BA2D0F24CDDE99008B4BD7 /* LittleBluetoothConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BA2D0E24CDDE99008B4BD7 /* LittleBluetoothConfiguration.swift */; };
65ED540124D85EFC00558C2C /* CoreBluetoothMock in Frameworks */ = {isa = PBXBuildFile; productRef = 65ED540024D85EFC00558C2C /* CoreBluetoothMock */; };
65F63EDF24F8EA73000E3474 /* JustLittleBlueTooth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65F63EDE24F8EA73000E3474 /* JustLittleBlueTooth.swift */; };
Expand Down Expand Up @@ -112,6 +114,7 @@
65A6B34F24DD29000068FE1C /* Loggable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Loggable.swift; sourceTree = "<group>"; };
65AD4BEB24D437B700C0CBE6 /* LittleBlueToothForTest.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LittleBlueToothForTest.framework; sourceTree = BUILT_PRODUCTS_DIR; };
65AD4BEC24D437B700C0CBE6 /* LittleBlueTooth copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "LittleBlueTooth copy-Info.plist"; path = "/Users/Andrea/Documents/GitHub/LittleBlueTooth/LittleBlueTooth copy-Info.plist"; sourceTree = "<absolute>"; };
65B7D53C25C3E01300556409 /* Log.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
65BA2D0E24CDDE99008B4BD7 /* LittleBluetoothConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LittleBluetoothConfiguration.swift; sourceTree = "<group>"; };
65F63EDE24F8EA73000E3474 /* JustLittleBlueTooth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustLittleBlueTooth.swift; sourceTree = "<group>"; };
"LittleBlueTooth::LittleBlueTooth::Product" /* LittleBlueTooth.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = LittleBlueTooth.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -187,6 +190,7 @@
650F378824F6B9B600C35395 /* ReadAndWrite.swift */,
650F378D24F6C33200C35395 /* Listen.swift */,
65F63EDE24F8EA73000E3474 /* JustLittleBlueTooth.swift */,
65B7D53C25C3E01300556409 /* Log.swift */,
);
path = CustomOperator;
sourceTree = "<group>";
Expand Down Expand Up @@ -481,6 +485,7 @@
files = (
65AD4BD624D437B700C0CBE6 /* LittleBlueToothError.swift in Sources */,
65F63EE024F8ED8E000E3474 /* JustLittleBlueTooth.swift in Sources */,
65B7D53E25C3E01300556409 /* Log.swift in Sources */,
6574671724F684E600E08B47 /* ScanAndConnection.swift in Sources */,
65F63EE424F9216A000E3474 /* ReplaySubject.swift in Sources */,
65AD4BD724D437B700C0CBE6 /* AdvertisingData.swift in Sources */,
Expand Down Expand Up @@ -509,6 +514,7 @@
files = (
OBJ_52 /* LittleBlueToothError.swift in Sources */,
65F63EDF24F8EA73000E3474 /* JustLittleBlueTooth.swift in Sources */,
65B7D53D25C3E01300556409 /* Log.swift in Sources */,
6574671624F631F700E08B47 /* ScanAndConnection.swift in Sources */,
65F63EE324F92169000E3474 /* ReplaySubject.swift in Sources */,
OBJ_53 /* AdvertisingData.swift in Sources */,
Expand Down Expand Up @@ -645,7 +651,7 @@
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.6.1;
MARKETING_VERSION = 0.6.2;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited) -DTEST";
Expand Down Expand Up @@ -736,7 +742,7 @@
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.6.0;
MARKETING_VERSION = 0.6.2;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down Expand Up @@ -770,7 +776,7 @@
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.6.0;
MARKETING_VERSION = 0.6.2;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited) -DTEST";
Expand Down Expand Up @@ -804,7 +810,7 @@
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.6.0;
MARKETING_VERSION = 0.6.2;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down Expand Up @@ -945,7 +951,7 @@
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.6.1;
MARKETING_VERSION = 0.6.2;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down Expand Up @@ -979,7 +985,7 @@
"$(TOOLCHAIN_DIR)/usr/lib/swift/macosx",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 0.6.1;
MARKETING_VERSION = 0.6.2;
OTHER_CFLAGS = "$(inherited)";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
Expand Down
18 changes: 18 additions & 0 deletions Sources/LittleBlueTooth/Classes/CustomOperator/Log.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Log.swift
// LittleBlueTooth
//
// Created by Andrea Finollo on 29/01/21.
//

import Foundation
import Combine

extension Publisher {
func customPrint(_ prefix: String = "", to: TextOutputStream? = nil, isEnabled: Bool = true) -> AnyPublisher<Self.Output, Self.Failure> {
if isEnabled {
return print(prefix, to: to).eraseToAnyPublisher()
}
return AnyPublisher(self)
}
}
4 changes: 2 additions & 2 deletions Sources/LittleBlueTooth/Classes/Model/Peripheral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ public class Peripheral: Identifiable {

fileprivate func discoverCharacteristic(_ charateristicUUID: CBUUID, fromService serviceUUID: CBUUID) -> AnyPublisher<CBCharacteristic, LittleBluetoothError> {
let discovery = self.getService(serviceUUID: serviceUUID)
.print("Discover service")
.customPrint("[LBT] Discover service", isEnabled: isLogEnabled)
.flatMap { services -> AnyPublisher<CBService, LittleBluetoothError> in
let service = services!.filter{ $0.uuid == serviceUUID}.first!
return self.getCharateristic(characteristicUUID: charateristicUUID, from: service)
}
.print("Discover characteristic")
.customPrint("[LBT] Discover characteristic", isEnabled: isLogEnabled)
.tryMap { (service) -> CBCharacteristic in
guard let charact = service.characteristics?.filter({ $0.uuid == charateristicUUID}).first else {
throw LittleBluetoothError.characteristicNotFound(nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CBCentralManagerDelegateProxy: NSObject {

extension CBCentralManagerDelegateProxy: CBCentralManagerDelegate {
func centralManagerDidUpdateState(_ central: CBCentralManager) {
log("CBCMD DidUpdateState %{public}d",
log("[LBT: CBCMD] DidUpdateState %{public}d",
log: OSLog.LittleBT_Log_CentralManager,
type: .debug,
arg: central.state.rawValue)
Expand All @@ -93,7 +93,7 @@ extension CBCentralManagerDelegateProxy: CBCentralManagerDelegate {

/// Scan
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
log("CBCMD DidDiscover %{public}@",
log("[LBT: CBCMD] DidDiscover %{public}@",
log: OSLog.LittleBT_Log_CentralManager,
type: .debug,
arg: peripheral.description)
Expand All @@ -103,7 +103,7 @@ extension CBCentralManagerDelegateProxy: CBCentralManagerDelegate {

/// Monitoring connection
func centralManager(_ central: CBCentralManager, didConnect: CBPeripheral) {
log("CBCMD DidConnect %{public}@",
log("[LBT: CBCMD] DidConnect %{public}@",
log: OSLog.LittleBT_Log_CentralManager,
type: .debug,
arg: didConnect.description)
Expand All @@ -118,7 +118,7 @@ extension CBCentralManagerDelegateProxy: CBCentralManagerDelegate {
}

func centralManager(_ central: CBCentralManager, didDisconnectPeripheral: CBPeripheral, error: Error?) {
log("CBCMD DidDisconnect %{public}@, Error %{public}@",
log("[LBT: CBCMD] DidDisconnect %{public}@, Error %{public}@",
log: OSLog.LittleBT_Log_CentralManager,
type: .debug,
arg: didDisconnectPeripheral.description,
Expand All @@ -143,7 +143,7 @@ extension CBCentralManagerDelegateProxy: CBCentralManagerDelegate {
}

func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) {
log("CBCMD WillRestoreState %{public}@",
log("[LBT: CBCMD] WillRestoreState %{public}@",
log: OSLog.LittleBT_Log_Restore,
type: .debug,
arg: dict.description)
Expand Down
18 changes: 9 additions & 9 deletions Sources/LittleBlueTooth/Classes/Proxies/CBPeripheralProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ class CBPeripheralDelegateProxy: NSObject {
extension CBPeripheralDelegateProxy: CBPeripheralDelegate {

func peripheralIsReady(toSendWriteWithoutResponse peripheral: CBPeripheral){
log("CBPD ReadyToSendWRiteWOResp",
log("[LBT: CBPD] ReadyToSendWRiteWOResp",
log: OSLog.LittleBT_Log_Peripheral,
type: .debug)
peripheralIsReadyToSendWriteWithoutResponse.send()
}

func peripheralDidUpdateName(_ peripheral: CBPeripheral) {
log("CBPD DidUpdateName %{public}@",
log("[LBT: CBPD] DidUpdateName %{public}@",
log: OSLog.LittleBT_Log_Peripheral,
type: .debug,
arg: peripheral.name ?? "na")
peripheralChangesPublisher.send(.name(peripheral.name))
}

func peripheral(_ peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]){
log("CBPD DidModifyServices %{public}@",
log("[LBT: CBPD] DidModifyServices %{public}@",
log: OSLog.LittleBT_Log_Peripheral,
type: .debug,
arg: invalidatedServices.description)
Expand All @@ -73,7 +73,7 @@ extension CBPeripheralDelegateProxy: CBPeripheralDelegate {
}

func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?){
log("CBPD DidDiscoverServices, Error %{public}@",
log("[LBT: CBPD] DidDiscoverServices, Error %{public}@",
log: OSLog.LittleBT_Log_Peripheral,
type: .debug,
arg: error?.localizedDescription ?? "")
Expand All @@ -85,7 +85,7 @@ extension CBPeripheralDelegateProxy: CBPeripheralDelegate {
}

func peripheral(_ peripheral: CBPeripheral, didDiscoverIncludedServicesFor service: CBService, error: Error?) {
log("CBPD DidDiscoverIncludedServices %{public}@, Error %{public}@",
log("[LBT: CBPD] DidDiscoverIncludedServices %{public}@, Error %{public}@",
log: OSLog.LittleBT_Log_Peripheral,
type: .debug,
arg: service.description,
Expand All @@ -98,7 +98,7 @@ extension CBPeripheralDelegateProxy: CBPeripheralDelegate {
}

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?){
log("CBPD DidDiscoverCharacteristic %{public}@, Error %{public}@",
log("[LBT: CBPD] DidDiscoverCharacteristic %{public}@, Error %{public}@",
log: OSLog.LittleBT_Log_Peripheral,
type: .debug,
arg: service.description,
Expand All @@ -111,7 +111,7 @@ extension CBPeripheralDelegateProxy: CBPeripheralDelegate {
}

func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?){
log("CBPD DidUpdateValue %{public}@, Error %{public}@",
log("[LBT: CBPD] DidUpdateValue %{public}@, Error %{public}@",
log: OSLog.LittleBT_Log_Peripheral,
type: .debug,
arg: characteristic.description,
Expand All @@ -128,7 +128,7 @@ extension CBPeripheralDelegateProxy: CBPeripheralDelegate {
}

func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {
log("CBPD DidWriteValue %{public}@, Error %{public}@",
log("[LBT: CBPD] DidWriteValue %{public}@, Error %{public}@",
log: OSLog.LittleBT_Log_Peripheral,
type: .debug,
arg: characteristic.description,
Expand All @@ -141,7 +141,7 @@ extension CBPeripheralDelegateProxy: CBPeripheralDelegate {
}

func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?){
log("CBPD DidUpdateNotifState %{public}@, Error %{public}@",
log("[LBT: CBPD] DidUpdateNotifState %{public}@, Error %{public}@",
log: OSLog.LittleBT_Log_Peripheral,
type: .debug,
arg: characteristic.description,
Expand Down
Loading

0 comments on commit 99ebe19

Please sign in to comment.