diff --git a/Sources/BluetoothHCI/HCIAcceptConnectionRequest.swift b/Sources/BluetoothHCI/HCIAcceptConnectionRequest.swift index 1af9a6416..0b302c6d6 100644 --- a/Sources/BluetoothHCI/HCIAcceptConnectionRequest.swift +++ b/Sources/BluetoothHCI/HCIAcceptConnectionRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - public extension BluetoothHostControllerInterface { /// Accept Connection Command @@ -57,11 +55,11 @@ public struct HCIAcceptConnectionRequest: HCICommandParameter { self.role = role } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, @@ -69,7 +67,7 @@ public struct HCIAcceptConnectionRequest: HCICommandParameter { addressBytes.4, addressBytes.5, role.rawValue - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIAuthenticationComplete.swift b/Sources/BluetoothHCI/HCIAuthenticationComplete.swift index 15367fc5b..7690e87fd 100644 --- a/Sources/BluetoothHCI/HCIAuthenticationComplete.swift +++ b/Sources/BluetoothHCI/HCIAuthenticationComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Authentication Complete Event /// /// The Authentication Complete event occurs when authentication has been completed for the specified connection. The Connection_Handle must be a Connection_Handle for an ACL connection. diff --git a/Sources/BluetoothHCI/HCIAuthenticationRequested.swift b/Sources/BluetoothHCI/HCIAuthenticationRequested.swift index 4663db831..b6af2b431 100644 --- a/Sources/BluetoothHCI/HCIAuthenticationRequested.swift +++ b/Sources/BluetoothHCI/HCIAuthenticationRequested.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -51,10 +49,10 @@ public struct HCIAuthenticationRequested: HCICommandParameter { self.handle = handle } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = handle.littleEndian.bytes - return Data([handleBytes.0, handleBytes.1]) + data += [handleBytes.0, handleBytes.1] } } diff --git a/Sources/BluetoothHCI/HCIChangeConnectionPacketType.swift b/Sources/BluetoothHCI/HCIChangeConnectionPacketType.swift index fd737d6b7..f91004a12 100644 --- a/Sources/BluetoothHCI/HCIChangeConnectionPacketType.swift +++ b/Sources/BluetoothHCI/HCIChangeConnectionPacketType.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -56,12 +54,12 @@ public struct HCIChangeConnectionPacketType: HCICommandParameter { self.packetType = packetType } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = handle.littleEndian.bytes let packetTypeBytes = packetType.rawValue.littleEndian.bytes - return Data([handleBytes.0, handleBytes.1, packetTypeBytes.0, packetTypeBytes.1]) + data += [handleBytes.0, handleBytes.1, packetTypeBytes.0, packetTypeBytes.1] } } diff --git a/Sources/BluetoothHCI/HCICommand.swift b/Sources/BluetoothHCI/HCICommand.swift index a7f501e78..82cf91e5d 100644 --- a/Sources/BluetoothHCI/HCICommand.swift +++ b/Sources/BluetoothHCI/HCICommand.swift @@ -6,8 +6,6 @@ // Copyright © 2016 PureSwift. All rights reserved. // -import Foundation - /// HCI Command. public protocol HCICommand: RawRepresentable, Hashable, CustomStringConvertible { @@ -49,8 +47,17 @@ public protocol HCICommandParameter { static var command: Command { get } - /// Converts command parameter to raw bytes. - var data: Data { get } + /// Append the command parameter bytes into the buffer. + func append(to data: inout Data) +} + +public extension DataContainer { + + /// Initialize data with contents of command parameter. + init(_ value: T) { + self.init() + value.append(to: &self) + } } /// The return value (not event) returned by an HCI command. diff --git a/Sources/BluetoothHCI/HCICommandComplete.swift b/Sources/BluetoothHCI/HCICommandComplete.swift index 87176400d..1575cf180 100644 --- a/Sources/BluetoothHCI/HCICommandComplete.swift +++ b/Sources/BluetoothHCI/HCICommandComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// HCI Command Complete @frozen public struct HCICommandComplete: HCIEventParameter { diff --git a/Sources/BluetoothHCI/HCICommandStatus.swift b/Sources/BluetoothHCI/HCICommandStatus.swift index 7e25ae4f1..8da363cab 100644 --- a/Sources/BluetoothHCI/HCICommandStatus.swift +++ b/Sources/BluetoothHCI/HCICommandStatus.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// HCI Command Status Event @frozen public struct HCICommandStatus: HCIEventParameter { diff --git a/Sources/BluetoothHCI/HCIConnectionComplete.swift b/Sources/BluetoothHCI/HCIConnectionComplete.swift index 3fa8bbbba..9e9f06130 100644 --- a/Sources/BluetoothHCI/HCIConnectionComplete.swift +++ b/Sources/BluetoothHCI/HCIConnectionComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Connection Complete Event /// /// The Connection Complete event indicates to both of the Hosts forming the connection that a new connection has been established. This event also indicates to the Host, which issued the Create_Connection, or Accept_Connection_ Request or Reject_Connection_Request command and then received a Command Status event, if the issued command failed or was successful. diff --git a/Sources/BluetoothHCI/HCIConnectionPacketTypeChange.swift b/Sources/BluetoothHCI/HCIConnectionPacketTypeChange.swift index 3d7c1973a..fbc4182b9 100644 --- a/Sources/BluetoothHCI/HCIConnectionPacketTypeChange.swift +++ b/Sources/BluetoothHCI/HCIConnectionPacketTypeChange.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// The Connection Packet Type Changed event is used to indicate that the process has completed of the Link Manager changing which packet types can be used for the connection. This allows current connections to be dynamically modified to support different types of user data. The Packet_Type event parameter specifies which packet types the Link Manager can use for the connection identified by the Connection_Handle event parameter for sending L2CAP data or voice. The Packet_Type event parameter does not decide which packet types the LM is allowed to use for sending LMP PDUs. @frozen public struct HCIConnectionPacketTypeChange: HCIEventParameter { diff --git a/Sources/BluetoothHCI/HCIConnectionRequest.swift b/Sources/BluetoothHCI/HCIConnectionRequest.swift index c60dcc189..693b26758 100644 --- a/Sources/BluetoothHCI/HCIConnectionRequest.swift +++ b/Sources/BluetoothHCI/HCIConnectionRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Connection Request Event /// /// The Connection Request event is used to indicate that a new incoming connection is trying to be established. The connection may either be accepted or rejected. If this event is masked away and there is an incoming connection attempt and the BR/EDR Controller is not set to auto-accept this connection attempt, the BR/EDR Controller shall automatically refuse the connection attempt. When the Host receives this event and the link type parameter is ACL, it should respond with either an Accept_Connection_Request or Reject_Connection_Request command before the timer Conn_Accept_Timeout expires. If the link type is SCO or eSCO, the Host should reply with the Accept_Synchronous_Connection_Request or the Reject_Synchronous_Connection_Request command. If the link type is SCO, the Host may respond with Accept_Connection_Request command. If the event is responded to with Accept_Connection_Request command, then the default parameter settings of the Accept_Synchronous_Connection_Request command (see Section 7.1.27 on page 504) should be used by the local Link Manager when negotiating the SCO link parameters. In that case, the Connection Complete event and not the Synchronous Connection Complete event, shall be returned on completion of the connection. diff --git a/Sources/BluetoothHCI/HCICreateConnection.swift b/Sources/BluetoothHCI/HCICreateConnection.swift index 0280b4a9c..56190da75 100644 --- a/Sources/BluetoothHCI/HCICreateConnection.swift +++ b/Sources/BluetoothHCI/HCICreateConnection.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -82,7 +80,7 @@ public struct HCICreateConnection: HCICommandParameter { self.allowRoleSwitch = allowRoleSwitch } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes @@ -90,14 +88,14 @@ public struct HCICreateConnection: HCICommandParameter { let clockOffsetBytes = clockOffset.rawValue.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5, // address packetTypeBytes.0, packetTypeBytes.1, // packet type pageScanRepetitionMode.rawValue, // page scan repetition mode reserved.rawValue, // reserved clockOffsetBytes.0, clockOffsetBytes.1, // clock offset allowRoleSwitch.rawValue - ]) // allow role switch + ] // allow role switch } } diff --git a/Sources/BluetoothHCI/HCICreateConnectionCancel.swift b/Sources/BluetoothHCI/HCICreateConnectionCancel.swift index b737f7e57..ca1e2e9f4 100644 --- a/Sources/BluetoothHCI/HCICreateConnectionCancel.swift +++ b/Sources/BluetoothHCI/HCICreateConnectionCancel.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -44,11 +42,11 @@ public struct HCICreateConnectionCancel: HCICommandParameter { self.address = address } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes - return Data([addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5]) + data += [addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5] } } diff --git a/Sources/BluetoothHCI/HCIDeleteStoredLinkKey.swift b/Sources/BluetoothHCI/HCIDeleteStoredLinkKey.swift index 478ed7507..a2288a3f2 100644 --- a/Sources/BluetoothHCI/HCIDeleteStoredLinkKey.swift +++ b/Sources/BluetoothHCI/HCIDeleteStoredLinkKey.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -49,11 +47,11 @@ public struct HCIDeleteStoredLinkKey: HCICommandParameter { self.deleteFlag = deleteFlag } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, @@ -61,7 +59,7 @@ public struct HCIDeleteStoredLinkKey: HCICommandParameter { addressBytes.4, addressBytes.5, deleteFlag.rawValue - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIDisconnect.swift b/Sources/BluetoothHCI/HCIDisconnect.swift index a2f2870a8..6faf3ecdb 100644 --- a/Sources/BluetoothHCI/HCIDisconnect.swift +++ b/Sources/BluetoothHCI/HCIDisconnect.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -53,11 +51,11 @@ public struct HCIDisconnect: HCICommandParameter { self.error = error } - public var data: Data { + public func append(to data: inout Data) { let connectionBytes = connectionHandle.littleEndian.bytes - return Data([connectionBytes.0, connectionBytes.1, error.rawValue]) + data += [connectionBytes.0, connectionBytes.1, error.rawValue] } } diff --git a/Sources/BluetoothHCI/HCIDisconnectionComplete.swift b/Sources/BluetoothHCI/HCIDisconnectionComplete.swift index ee353b6fb..b4433ddd6 100644 --- a/Sources/BluetoothHCI/HCIDisconnectionComplete.swift +++ b/Sources/BluetoothHCI/HCIDisconnectionComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Disconnection Complete Event /// /// The Disconnection Complete event occurs when a connection is terminated. The status parameter indicates if the disconnection was successful or not. The reason parameter indicates the reason for the disconnection if the disconnection was successful. If the disconnection was not successful, the value of the reason parameter can be ignored by the Host. For example, this can be the case if the Host has issued the Disconnect command and there was a parameter error, or the command was not presently allowed, or a Connection_Handle that didn’t correspond to a connection was given. diff --git a/Sources/BluetoothHCI/HCIEncryptionChange.swift b/Sources/BluetoothHCI/HCIEncryptionChange.swift index aeace7d69..d8cb539cc 100644 --- a/Sources/BluetoothHCI/HCIEncryptionChange.swift +++ b/Sources/BluetoothHCI/HCIEncryptionChange.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Encryption Change Event /// /// The Encryption Change event is used to indicate that the change of the encryption mode has been completed. diff --git a/Sources/BluetoothHCI/HCIEncryptionKeyRefreshComplete.swift b/Sources/BluetoothHCI/HCIEncryptionKeyRefreshComplete.swift index 24b627a6a..65100a13b 100644 --- a/Sources/BluetoothHCI/HCIEncryptionKeyRefreshComplete.swift +++ b/Sources/BluetoothHCI/HCIEncryptionKeyRefreshComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Encryption Key Refresh Complete Event /// /// The Encryption Key Refresh Complete event is used to indicate to the Host that the encryption key was diff --git a/Sources/BluetoothHCI/HCIError.swift b/Sources/BluetoothHCI/HCIError.swift index 34fcf5a83..096a6ec89 100644 --- a/Sources/BluetoothHCI/HCIError.swift +++ b/Sources/BluetoothHCI/HCIError.swift @@ -6,6 +6,8 @@ // Copyright © 2017 PureSwift. All rights reserved. // +import Foundation + /// Bluetooth HCI Errors /// /// If an HCI Command that should generate a Command Complete event generates an error @@ -537,8 +539,6 @@ extension HCIError: CustomStringConvertible { #if canImport(Darwin) -import Foundation - extension HCIError: CustomNSError { public static var errorDomain: String { diff --git a/Sources/BluetoothHCI/HCIEvent.swift b/Sources/BluetoothHCI/HCIEvent.swift index f7b7a144a..075a9c360 100644 --- a/Sources/BluetoothHCI/HCIEvent.swift +++ b/Sources/BluetoothHCI/HCIEvent.swift @@ -6,8 +6,6 @@ // Copyright © 2016 PureSwift. All rights reserved. // -import Foundation - /// HCI Event Opcode public protocol HCIEvent: RawRepresentable, Hashable, CustomStringConvertible { diff --git a/Sources/BluetoothHCI/HCIExitPeriodicInquiryMode.swift b/Sources/BluetoothHCI/HCIExitPeriodicInquiryMode.swift index f2007e022..e8e14d9c7 100644 --- a/Sources/BluetoothHCI/HCIExitPeriodicInquiryMode.swift +++ b/Sources/BluetoothHCI/HCIExitPeriodicInquiryMode.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCIHoldMode.swift b/Sources/BluetoothHCI/HCIHoldMode.swift index 9c4dfe6c5..7934fe970 100644 --- a/Sources/BluetoothHCI/HCIHoldMode.swift +++ b/Sources/BluetoothHCI/HCIHoldMode.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Hold Mode Command /// /// The Hold_Mode command is used to alter the behavior of the Link Manager, and have it place the ACL baseband connection associated by the specified Connection_Handle into the hold mode. The Hold_Mode_Max_Interval and Hold_Mode_Min_Interval command parameters specify the length of time the Host wants to put the connection into the hold mode. The local and remote devices will negotiate the length in the hold mode. The Hold_Mode_Max_ Interval parameter is used to specify the maximum length of the Hold interval for which the Host may actually enter into the hold mode after negotiation with the remote device. The Hold interval defines the amount of time between when the Hold Mode begins and when the Hold Mode is completed. The Hold_ Mode_Min_Interval parameter is used to specify the minimum length of the Hold interval for which the Host may actually enter into the hold mode after the negotiation with the remote device. Therefore the Hold_Mode_Min_Interval cannot be greater than the Hold_Mode_Max_Interval. The BR/EDR Controller will return the actual Hold interval in the Interval parameter of the Mode Change event, if the command is successful. This command enables the Host to support a low-power policy for itself or several other BR/EDR Controllers, and allows the devices to enter Inquiry Scan, Page Scan, and a number of other possible actions. @@ -37,7 +35,7 @@ public struct HCIHoldMode: HCICommandParameter { self.interval = interval } - public var data: Data { + public func append(to data: inout Data) { // Connection_Handle let handleBytes = connectionHandle.littleEndian.bytes @@ -48,14 +46,14 @@ public struct HCIHoldMode: HCICommandParameter { // Hold_Mode_Min_Interval let intervalMinBytes = interval.rawValue.lowerBound.littleEndian.bytes - return Data([ + data += [ handleBytes.0, handleBytes.1, intervalMaxBytes.0, intervalMaxBytes.1, intervalMinBytes.0, intervalMinBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIIOCapabilityRequest.swift b/Sources/BluetoothHCI/HCIIOCapabilityRequest.swift index 28c43be34..758ebee4a 100644 --- a/Sources/BluetoothHCI/HCIIOCapabilityRequest.swift +++ b/Sources/BluetoothHCI/HCIIOCapabilityRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// The IO Capability Request event is used to indicate that the IO capabilities of the Host are required for a simple pairing process. The Host shall respond with an IO_Capability_Request_Reply command. This event shall only be generated if simple pairing has been enabled with the Write_Simple_Pairing_Mode command. @frozen public struct HCIIOCapabilityRequest: HCIEventParameter { diff --git a/Sources/BluetoothHCI/HCIIOCapabilityRequestReply.swift b/Sources/BluetoothHCI/HCIIOCapabilityRequestReply.swift index d869abd2d..71d079dab 100644 --- a/Sources/BluetoothHCI/HCIIOCapabilityRequestReply.swift +++ b/Sources/BluetoothHCI/HCIIOCapabilityRequestReply.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -71,11 +69,11 @@ public struct HCIIOCapabilityRequestReply: HCICommandParameter { self.authenticationRequirements = authenticationRequirements } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, @@ -85,7 +83,7 @@ public struct HCIIOCapabilityRequestReply: HCICommandParameter { ioCapability.rawValue, oobDataPresent.rawValue, authenticationRequirements.rawValue - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIIOCapabilityResponse.swift b/Sources/BluetoothHCI/HCIIOCapabilityResponse.swift index 4f030df26..eddd09cb5 100644 --- a/Sources/BluetoothHCI/HCIIOCapabilityResponse.swift +++ b/Sources/BluetoothHCI/HCIIOCapabilityResponse.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// The IO Capability Response event is used to indicate to the host that IO capa- bilities from a remote device specified by BD_ADDR have been received dur- ing a simple pairing process. This event will only be generated if simple pairing has been enabled with the Write_Simple_Pairing_Mode command. @frozen public struct HCIIOCapabilityResponse: HCIEventParameter { diff --git a/Sources/BluetoothHCI/HCIInquiry.swift b/Sources/BluetoothHCI/HCIInquiry.swift index b05558f71..bccf814ed 100644 --- a/Sources/BluetoothHCI/HCIInquiry.swift +++ b/Sources/BluetoothHCI/HCIInquiry.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -38,7 +36,6 @@ public extension BluetoothHostControllerInterface { try pollEvent(HCInquiryComplete.self, shouldContinue: shouldContinue) { (complete) in - }*/ } } @@ -77,11 +74,11 @@ public struct HCIInquiry: HCICommandParameter { self.responses = responses } - public var data: Data { + public func append(to data: inout Data) { let lapBytes = lap.rawValue.littleEndian.bytes - return Data([lapBytes.0, lapBytes.1, lapBytes.2, duration.rawValue, responses.rawValue]) + data += [lapBytes.0, lapBytes.1, lapBytes.2, duration.rawValue, responses.rawValue] } } diff --git a/Sources/BluetoothHCI/HCIInquiryCancel.swift b/Sources/BluetoothHCI/HCIInquiryCancel.swift index 62879e386..6752a0a1a 100644 --- a/Sources/BluetoothHCI/HCIInquiryCancel.swift +++ b/Sources/BluetoothHCI/HCIInquiryCancel.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCIInquiryComplete.swift b/Sources/BluetoothHCI/HCIInquiryComplete.swift index 4a6510045..e498e369f 100644 --- a/Sources/BluetoothHCI/HCIInquiryComplete.swift +++ b/Sources/BluetoothHCI/HCIInquiryComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Inquiry Complete Event /// /// The Inquiry Complete event indicates that the Inquiry is finished. This event contains a Status parameter, which is used to indicate if the Inquiry completed successfully or if the Inquiry was not completed. diff --git a/Sources/BluetoothHCI/HCIInquiryResult.swift b/Sources/BluetoothHCI/HCIInquiryResult.swift index 844daadf7..0de4593d1 100644 --- a/Sources/BluetoothHCI/HCIInquiryResult.swift +++ b/Sources/BluetoothHCI/HCIInquiryResult.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Inquiry Result Event /// /// The Inquiry Result event indicates that a BR/EDR Controller or multiple BR/ EDR Controllers have responded so far during the current Inquiry process. This event will be sent from the BR/EDR Controller to the Host as soon as an Inquiry Response from a remote device is received if the remote device supports only mandatory paging scheme. The BR/EDR Controller may queue these Inquiry Responses and send multiple BR/EDR Controllers information in one Inquiry Result event. The event can be used to return one or more Inquiry responses in one event. diff --git a/Sources/BluetoothHCI/HCILEAddDeviceToPeriodicAdvertiserList.swift b/Sources/BluetoothHCI/HCILEAddDeviceToPeriodicAdvertiserList.swift index 26ac898bd..255bd7707 100644 --- a/Sources/BluetoothHCI/HCILEAddDeviceToPeriodicAdvertiserList.swift +++ b/Sources/BluetoothHCI/HCILEAddDeviceToPeriodicAdvertiserList.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -63,11 +61,11 @@ public struct HCILEAddDeviceToPeriodicAdvertiserList: HCICommandParameter { self.advertisingSid = advertisingSid } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes - return Data([ + data += [ advertiserAddressType.rawValue, addressBytes.0, addressBytes.1, @@ -76,6 +74,6 @@ public struct HCILEAddDeviceToPeriodicAdvertiserList: HCICommandParameter { addressBytes.4, addressBytes.5, advertisingSid - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEAddDeviceToResolvingList.swift b/Sources/BluetoothHCI/HCILEAddDeviceToResolvingList.swift index ebe673419..80b81efd2 100644 --- a/Sources/BluetoothHCI/HCILEAddDeviceToResolvingList.swift +++ b/Sources/BluetoothHCI/HCILEAddDeviceToResolvingList.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -67,13 +65,13 @@ public struct HCILEAddDeviceToResolvingList: HCICommandParameter { self.localIrk = localIrk } - public var data: Data { + public func append(to data: inout Data) { let peerIdentifyAddressBytes = peerIdentifyAddress.littleEndian.bytes let peerIrkBytes = peerIrk.littleEndian.bytes let localIrkBytes = localIrk.littleEndian.bytes - return Data([ + data += [ peerIdentifyAddressType.rawValue, peerIdentifyAddressBytes.0, peerIdentifyAddressBytes.1, @@ -115,6 +113,6 @@ public struct HCILEAddDeviceToResolvingList: HCICommandParameter { localIrkBytes.13, localIrkBytes.14, localIrkBytes.15 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEAddDeviceToWhiteList.swift b/Sources/BluetoothHCI/HCILEAddDeviceToWhiteList.swift index 69413d4c3..a4371cd4c 100644 --- a/Sources/BluetoothHCI/HCILEAddDeviceToWhiteList.swift +++ b/Sources/BluetoothHCI/HCILEAddDeviceToWhiteList.swift @@ -6,7 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation import Bluetooth // MARK: - Method @@ -84,7 +83,4 @@ extension HCILEAddDeviceToWhiteList: DataConvertible { Self.length } - public var data: Data { - return Data(self) - } } diff --git a/Sources/BluetoothHCI/HCILEAdvertisingReport.swift b/Sources/BluetoothHCI/HCILEAdvertisingReport.swift index 841ca522e..1334a4fb3 100644 --- a/Sources/BluetoothHCI/HCILEAdvertisingReport.swift +++ b/Sources/BluetoothHCI/HCILEAdvertisingReport.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Advertising Report Event /// /// The LE Advertising Report event indicates that a Bluetooth device diff --git a/Sources/BluetoothHCI/HCILEAdvertisingSetTerminated.swift b/Sources/BluetoothHCI/HCILEAdvertisingSetTerminated.swift index e525e67b6..38bad1584 100644 --- a/Sources/BluetoothHCI/HCILEAdvertisingSetTerminated.swift +++ b/Sources/BluetoothHCI/HCILEAdvertisingSetTerminated.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Advertising Set Terminated Event /// /// The event indicates that the Controller has terminated advertising in the advertising sets specified by the Advertising_Handle parameter. diff --git a/Sources/BluetoothHCI/HCILEChannelSelectionAlgorithm.swift b/Sources/BluetoothHCI/HCILEChannelSelectionAlgorithm.swift index a81a92602..804fabfaa 100644 --- a/Sources/BluetoothHCI/HCILEChannelSelectionAlgorithm.swift +++ b/Sources/BluetoothHCI/HCILEChannelSelectionAlgorithm.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Channel Selection Algorithm Event /// /// The LE Channel Selection Algorithm Event indicates which channel selection algorithm is used on a data channel connection. diff --git a/Sources/BluetoothHCI/HCILEConnectionComplete.swift b/Sources/BluetoothHCI/HCILEConnectionComplete.swift index bd3f280c8..a282235b7 100644 --- a/Sources/BluetoothHCI/HCILEConnectionComplete.swift +++ b/Sources/BluetoothHCI/HCILEConnectionComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Connection Complete Event /// /// The LE Connection Complete event indicates to both of the Hosts forming the connection diff --git a/Sources/BluetoothHCI/HCILEConnectionUpdateComplete.swift b/Sources/BluetoothHCI/HCILEConnectionUpdateComplete.swift index 06b26c199..c1f34738d 100644 --- a/Sources/BluetoothHCI/HCILEConnectionUpdateComplete.swift +++ b/Sources/BluetoothHCI/HCILEConnectionUpdateComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Connection Update Complete Event /// /// The event is used to indicate that the Controller process to update the connection has completed. diff --git a/Sources/BluetoothHCI/HCILECreateConnection.swift b/Sources/BluetoothHCI/HCILECreateConnection.swift index bab7d48c7..8253ec272 100644 --- a/Sources/BluetoothHCI/HCILECreateConnection.swift +++ b/Sources/BluetoothHCI/HCILECreateConnection.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -157,11 +155,8 @@ extension HCILECreateConnection { static var length: Int { return 2 + 2 + 1 + 1 + 6 + 1 + 2 + 2 + 2 + 2 + 2 + 2 } - public var data: Data { - var data = Data() - data.reserveCapacity(Self.length) + public func append(to data: inout Data) { data += self - return data } var dataLength: Int { diff --git a/Sources/BluetoothHCI/HCILEDataLengthChange.swift b/Sources/BluetoothHCI/HCILEDataLengthChange.swift index b394317f4..7f48bead5 100644 --- a/Sources/BluetoothHCI/HCILEDataLengthChange.swift +++ b/Sources/BluetoothHCI/HCILEDataLengthChange.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Data Length Change Event /// /// event notifies the Host of a change to either the maximum Payload length or the maximum transmission time of packets diff --git a/Sources/BluetoothHCI/HCILEDirectedAdvertisingReport.swift b/Sources/BluetoothHCI/HCILEDirectedAdvertisingReport.swift index 477c0a39c..eb7392a81 100644 --- a/Sources/BluetoothHCI/HCILEDirectedAdvertisingReport.swift +++ b/Sources/BluetoothHCI/HCILEDirectedAdvertisingReport.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Directed Advertising Report Event /// /// The event indicates that directed advertisements have been received where the advertiser diff --git a/Sources/BluetoothHCI/HCILEEncrypt.swift b/Sources/BluetoothHCI/HCILEEncrypt.swift index 4fa5b9271..cbede1460 100644 --- a/Sources/BluetoothHCI/HCILEEncrypt.swift +++ b/Sources/BluetoothHCI/HCILEEncrypt.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -60,11 +58,8 @@ public struct HCILEEncrypt: HCICommandParameter { // HCI_LE_Encrypt extension HCILEEncrypt { - public var data: Data { - var data = Data() - data.reserveCapacity(self.dataLength) + public func append(to data: inout Data) { data += self - return data } var dataLength: Int { return 32 } diff --git a/Sources/BluetoothHCI/HCILEEnhancedConnectionComplete.swift b/Sources/BluetoothHCI/HCILEEnhancedConnectionComplete.swift index 8266f021f..490a94cb4 100644 --- a/Sources/BluetoothHCI/HCILEEnhancedConnectionComplete.swift +++ b/Sources/BluetoothHCI/HCILEEnhancedConnectionComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Enhanced Connection Complete Event /// /// The event indicates to both of the Hosts forming the connection that a new connection has been created. diff --git a/Sources/BluetoothHCI/HCILEEnhancedReceiverTest.swift b/Sources/BluetoothHCI/HCILEEnhancedReceiverTest.swift index de901cb0d..70585fd1d 100644 --- a/Sources/BluetoothHCI/HCILEEnhancedReceiverTest.swift +++ b/Sources/BluetoothHCI/HCILEEnhancedReceiverTest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -46,8 +44,8 @@ public struct HCILEEnhancedReceiverTest: HCICommandParameter { self.modulationIndex = modulationIndex } - public var data: Data { - return Data([rxChannel.rawValue, phy.rawValue, modulationIndex.rawValue]) + public func append(to data: inout Data) { + data += [rxChannel.rawValue, phy.rawValue, modulationIndex.rawValue] } public enum Phy: UInt8 { diff --git a/Sources/BluetoothHCI/HCILEEnhancedTransmitterTest.swift b/Sources/BluetoothHCI/HCILEEnhancedTransmitterTest.swift index f1a3d11a1..44cee9ae8 100644 --- a/Sources/BluetoothHCI/HCILEEnhancedTransmitterTest.swift +++ b/Sources/BluetoothHCI/HCILEEnhancedTransmitterTest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -64,9 +62,9 @@ public struct HCILEEnhancedTransmitterTest: HCICommandParameter { self.phy = phy } - public var data: Data { + public func append(to data: inout Data) { - return Data([txChannel.rawValue, lengthOfTestData, packetPayload.rawValue, phy.rawValue]) + data += [txChannel.rawValue, lengthOfTestData, packetPayload.rawValue, phy.rawValue] } public enum Phy: UInt8 { diff --git a/Sources/BluetoothHCI/HCILEExtendedCreateConnection.swift b/Sources/BluetoothHCI/HCILEExtendedCreateConnection.swift index 85bab7ac5..06a5599fb 100644 --- a/Sources/BluetoothHCI/HCILEExtendedCreateConnection.swift +++ b/Sources/BluetoothHCI/HCILEExtendedCreateConnection.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -78,11 +76,11 @@ public struct HCILEExtendedCreateConnection: HCICommandParameter { self.initialingPHY = initialingPHY } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = peerAddress.littleEndian.bytes - return Data([ + data += [ initialingFilterPolicy.rawValue, ownAddressType.rawValue, peerAddressType.rawValue, @@ -92,7 +90,7 @@ public struct HCILEExtendedCreateConnection: HCICommandParameter { addressBytes.3, addressBytes.4, addressBytes.5 - ]) + ] } public enum InitialingFilterPolicy: UInt8 { // Initiating_Filter_Policy diff --git a/Sources/BluetoothHCI/HCILEGenerateDHKey.swift b/Sources/BluetoothHCI/HCILEGenerateDHKey.swift index adadc81f8..71897a136 100644 --- a/Sources/BluetoothHCI/HCILEGenerateDHKey.swift +++ b/Sources/BluetoothHCI/HCILEGenerateDHKey.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -47,11 +45,11 @@ public struct HCILEGenerateDHKey: HCICommandParameter { self.remoteP256PublicKey = remoteP256PublicKey } - public var data: Data { + public func append(to data: inout Data) { let remoteP256PublicKeyBytes = remoteP256PublicKey.littleEndian.bytes - return Data([ + data += [ remoteP256PublicKeyBytes.0, remoteP256PublicKeyBytes.1, remoteP256PublicKeyBytes.2, @@ -117,6 +115,6 @@ public struct HCILEGenerateDHKey: HCICommandParameter { remoteP256PublicKeyBytes.61, remoteP256PublicKeyBytes.62, remoteP256PublicKeyBytes.63 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEGenerateDHKeyComplete.swift b/Sources/BluetoothHCI/HCILEGenerateDHKeyComplete.swift index c20b77dd1..d88cc7227 100644 --- a/Sources/BluetoothHCI/HCILEGenerateDHKeyComplete.swift +++ b/Sources/BluetoothHCI/HCILEGenerateDHKeyComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Generate DHKey Complete Event /// /// This event indicates that LE Diffie Hellman key generation has been completed by the Controller. diff --git a/Sources/BluetoothHCI/HCILELongTermKeyRequest.swift b/Sources/BluetoothHCI/HCILELongTermKeyRequest.swift index 61471b3b5..bb253ac2c 100644 --- a/Sources/BluetoothHCI/HCILELongTermKeyRequest.swift +++ b/Sources/BluetoothHCI/HCILELongTermKeyRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Long Term Key Request Event /// /// The LE Long Term Key Request event indicates that the master device is attempting diff --git a/Sources/BluetoothHCI/HCILELongTermKeyRequestNegativeReply.swift b/Sources/BluetoothHCI/HCILELongTermKeyRequestNegativeReply.swift index b809b8fda..298919c47 100644 --- a/Sources/BluetoothHCI/HCILELongTermKeyRequestNegativeReply.swift +++ b/Sources/BluetoothHCI/HCILELongTermKeyRequestNegativeReply.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -45,14 +43,14 @@ public struct HCILELongTermKeyRequestNegativeReply: HCICommandParameter { self.connectionHandle = connectionHandle } - public var data: Data { + public func append(to data: inout Data) { let connectionHandleBytes = connectionHandle.littleEndian.bytes - return Data([ + data += [ connectionHandleBytes.0, connectionHandleBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILELongTermKeyRequestReply.swift b/Sources/BluetoothHCI/HCILELongTermKeyRequestReply.swift index ca7bb79b7..d38c16e75 100644 --- a/Sources/BluetoothHCI/HCILELongTermKeyRequestReply.swift +++ b/Sources/BluetoothHCI/HCILELongTermKeyRequestReply.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -50,12 +48,12 @@ public struct HCILELongTermKeyRequestReply: HCICommandParameter { self.longTermKey = longTermKey } - public var data: Data { + public func append(to data: inout Data) { let connectionHandleBytes = connectionHandle.littleEndian.bytes let longTermKeyBytes = longTermKey.littleEndian.bytes - return Data([ + data += [ connectionHandleBytes.0, connectionHandleBytes.1, longTermKeyBytes.0, @@ -74,7 +72,7 @@ public struct HCILELongTermKeyRequestReply: HCICommandParameter { longTermKeyBytes.13, longTermKeyBytes.14, longTermKeyBytes.15 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEPeriodicAdvertisingCreateSync.swift b/Sources/BluetoothHCI/HCILEPeriodicAdvertisingCreateSync.swift index f94ae2693..36656e372 100644 --- a/Sources/BluetoothHCI/HCILEPeriodicAdvertisingCreateSync.swift +++ b/Sources/BluetoothHCI/HCILEPeriodicAdvertisingCreateSync.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -72,13 +70,13 @@ public struct HCILEPeriodicAdvertisingCreateSync: HCICommandParameter { self.unused = unused } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes let skipBytes = skip.littleEndian.bytes let syncTimeoutBytes = syncTimeout.rawValue.littleEndian.bytes - return Data([ + data += [ filterPolicy.rawValue, advertisingSid, advertisingAddressType.rawValue, @@ -93,7 +91,7 @@ public struct HCILEPeriodicAdvertisingCreateSync: HCICommandParameter { syncTimeoutBytes.0, syncTimeoutBytes.1, unused - ]) + ] } public struct SyncTimeout: RawRepresentable, Equatable, Hashable, Comparable, Sendable { diff --git a/Sources/BluetoothHCI/HCILEPeriodicAdvertisingSyncEstablished.swift b/Sources/BluetoothHCI/HCILEPeriodicAdvertisingSyncEstablished.swift index dd067339f..34fb4f3c0 100644 --- a/Sources/BluetoothHCI/HCILEPeriodicAdvertisingSyncEstablished.swift +++ b/Sources/BluetoothHCI/HCILEPeriodicAdvertisingSyncEstablished.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Periodic Advertising Sync Established Event /// /// The event indicates that the Controller has received the first periodic advertising packet from an advertiser diff --git a/Sources/BluetoothHCI/HCILEPeriodicAdvertisingSyncLost.swift b/Sources/BluetoothHCI/HCILEPeriodicAdvertisingSyncLost.swift index b594744b5..ed09e1295 100644 --- a/Sources/BluetoothHCI/HCILEPeriodicAdvertisingSyncLost.swift +++ b/Sources/BluetoothHCI/HCILEPeriodicAdvertisingSyncLost.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Periodic Advertising Sync Lost Event /// /// The event indicates that the Controller has not received a Periodic Advertising packet identified diff --git a/Sources/BluetoothHCI/HCILEPeriodicAdvertisingTerminateSync.swift b/Sources/BluetoothHCI/HCILEPeriodicAdvertisingTerminateSync.swift index 260afae0d..8c5fe2bfc 100644 --- a/Sources/BluetoothHCI/HCILEPeriodicAdvertisingTerminateSync.swift +++ b/Sources/BluetoothHCI/HCILEPeriodicAdvertisingTerminateSync.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -48,9 +46,9 @@ public struct HCILEPeriodicAdvertisingTerminateSync: HCICommandParameter { self.syncHandle = syncHandle } - public var data: Data { + public func append(to data: inout Data) { let syncHandleBytes = syncHandle.littleEndian.bytes - return Data([syncHandleBytes.0, syncHandleBytes.1]) + data += [syncHandleBytes.0, syncHandleBytes.1] } } diff --git a/Sources/BluetoothHCI/HCILEPhyUpdateComplete.swift b/Sources/BluetoothHCI/HCILEPhyUpdateComplete.swift index 2677a5de7..5acd68e30 100644 --- a/Sources/BluetoothHCI/HCILEPhyUpdateComplete.swift +++ b/Sources/BluetoothHCI/HCILEPhyUpdateComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE PHY Update Complete Event /// /// The LE PHY Update Complete Event is used to indicate that the Controller has changed diff --git a/Sources/BluetoothHCI/HCILERandom.swift b/Sources/BluetoothHCI/HCILERandom.swift index 59d82b0dc..697faeee9 100644 --- a/Sources/BluetoothHCI/HCILERandom.swift +++ b/Sources/BluetoothHCI/HCILERandom.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadAdvertisingChannelTxPower.swift b/Sources/BluetoothHCI/HCILEReadAdvertisingChannelTxPower.swift index d9b8b3bbc..d45723c73 100644 --- a/Sources/BluetoothHCI/HCILEReadAdvertisingChannelTxPower.swift +++ b/Sources/BluetoothHCI/HCILEReadAdvertisingChannelTxPower.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadBufferSize.swift b/Sources/BluetoothHCI/HCILEReadBufferSize.swift index 11a63d23b..2d368a385 100644 --- a/Sources/BluetoothHCI/HCILEReadBufferSize.swift +++ b/Sources/BluetoothHCI/HCILEReadBufferSize.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadChannelMap.swift b/Sources/BluetoothHCI/HCILEReadChannelMap.swift index 2db8f1acd..31b39e5d9 100644 --- a/Sources/BluetoothHCI/HCILEReadChannelMap.swift +++ b/Sources/BluetoothHCI/HCILEReadChannelMap.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -46,14 +44,14 @@ public struct HCILEReadChannelMap: HCICommandParameter { // HCI_LE_Read_Channel self.connectionHandle = connectionHandle } - public var data: Data { + public func append(to data: inout Data) { let connectionHandleBytes = connectionHandle.littleEndian.bytes - return Data([ + data += [ connectionHandleBytes.0, connectionHandleBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEReadLocalP256PublicKeyComplete.swift b/Sources/BluetoothHCI/HCILEReadLocalP256PublicKeyComplete.swift index b0badb3fb..ae69b461b 100644 --- a/Sources/BluetoothHCI/HCILEReadLocalP256PublicKeyComplete.swift +++ b/Sources/BluetoothHCI/HCILEReadLocalP256PublicKeyComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Read Local P-256 Public Key Complete Event /// /// This event is generated when local P-256 key generation is complete. diff --git a/Sources/BluetoothHCI/HCILEReadLocalResolvableAddressReturn.swift b/Sources/BluetoothHCI/HCILEReadLocalResolvableAddressReturn.swift index eb6720cae..9d2a55cc9 100644 --- a/Sources/BluetoothHCI/HCILEReadLocalResolvableAddressReturn.swift +++ b/Sources/BluetoothHCI/HCILEReadLocalResolvableAddressReturn.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -62,11 +60,11 @@ public struct HCILEReadLocalResolvableAddress: HCICommandParameter { //HCI_LE_R self.peerIdentifyAddress = peerIdentifyAddress } - public var data: Data { + public func append(to data: inout Data) { let peerIdentifyAddressBytes = peerIdentifyAddress.littleEndian.bytes - return Data([ + data += [ peerIdentifyAddressType.rawValue, peerIdentifyAddressBytes.0, peerIdentifyAddressBytes.1, @@ -76,7 +74,7 @@ public struct HCILEReadLocalResolvableAddress: HCICommandParameter { //HCI_LE_R peerIdentifyAddressBytes.5, peerIdentifyAddressBytes.6, peerIdentifyAddressBytes.7 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEReadLocalSupportedFeatures.swift b/Sources/BluetoothHCI/HCILEReadLocalSupportedFeatures.swift index 84bf4b1ce..41d885b8e 100644 --- a/Sources/BluetoothHCI/HCILEReadLocalSupportedFeatures.swift +++ b/Sources/BluetoothHCI/HCILEReadLocalSupportedFeatures.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadMaximumAdvertisingDataLength.swift b/Sources/BluetoothHCI/HCILEReadMaximumAdvertisingDataLength.swift index ca9206630..4aa47a60d 100644 --- a/Sources/BluetoothHCI/HCILEReadMaximumAdvertisingDataLength.swift +++ b/Sources/BluetoothHCI/HCILEReadMaximumAdvertisingDataLength.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadMaximumDataLength.swift b/Sources/BluetoothHCI/HCILEReadMaximumDataLength.swift index cad515933..7ac3000e8 100644 --- a/Sources/BluetoothHCI/HCILEReadMaximumDataLength.swift +++ b/Sources/BluetoothHCI/HCILEReadMaximumDataLength.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadNumberOfSupportedAdvertisingSets.swift b/Sources/BluetoothHCI/HCILEReadNumberOfSupportedAdvertisingSets.swift index 5b195aacf..88107d194 100644 --- a/Sources/BluetoothHCI/HCILEReadNumberOfSupportedAdvertisingSets.swift +++ b/Sources/BluetoothHCI/HCILEReadNumberOfSupportedAdvertisingSets.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadPeerResolvableAddressReturn.swift b/Sources/BluetoothHCI/HCILEReadPeerResolvableAddressReturn.swift index 3623cd98b..1ba11fab3 100644 --- a/Sources/BluetoothHCI/HCILEReadPeerResolvableAddressReturn.swift +++ b/Sources/BluetoothHCI/HCILEReadPeerResolvableAddressReturn.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -58,11 +56,11 @@ public struct HCILEReadPeerResolvableAddress: HCICommandParameter { //HCI_LE_Re self.peerIdentifyAddress = peerIdentifyAddress } - public var data: Data { + public func append(to data: inout Data) { let peerIdentifyAddressBytes = peerIdentifyAddress.littleEndian.bytes - return Data([ + data += [ peerIdentifyAddressType.rawValue, peerIdentifyAddressBytes.0, peerIdentifyAddressBytes.1, @@ -72,7 +70,7 @@ public struct HCILEReadPeerResolvableAddress: HCICommandParameter { //HCI_LE_Re peerIdentifyAddressBytes.5, peerIdentifyAddressBytes.6, peerIdentifyAddressBytes.7 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEReadPeriodicAdvertisingListSize.swift b/Sources/BluetoothHCI/HCILEReadPeriodicAdvertisingListSize.swift index f3520aa18..a308c16a5 100644 --- a/Sources/BluetoothHCI/HCILEReadPeriodicAdvertisingListSize.swift +++ b/Sources/BluetoothHCI/HCILEReadPeriodicAdvertisingListSize.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadPhy.swift b/Sources/BluetoothHCI/HCILEReadPhy.swift index 39d28951a..2c4fc4159 100644 --- a/Sources/BluetoothHCI/HCILEReadPhy.swift +++ b/Sources/BluetoothHCI/HCILEReadPhy.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -45,14 +43,14 @@ public struct HCILEReadPHY: HCICommandParameter { self.connectionHandle = connectionHandle } - public var data: Data { + public func append(to data: inout Data) { let connectionHandleBytes = connectionHandle.littleEndian.bytes - return Data([ + data += [ connectionHandleBytes.0, connectionHandleBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEReadRemoteUsedFeatures.swift b/Sources/BluetoothHCI/HCILEReadRemoteUsedFeatures.swift index ee6336e6c..4c28f6291 100644 --- a/Sources/BluetoothHCI/HCILEReadRemoteUsedFeatures.swift +++ b/Sources/BluetoothHCI/HCILEReadRemoteUsedFeatures.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -61,13 +59,13 @@ public struct HCILEReadRemoteUsedFeatures: HCICommandParameter { //HCI_LE_Read_ self.connectionHandle = connectionHandle } - public var data: Data { + public func append(to data: inout Data) { let connectionHandleBytes = connectionHandle.littleEndian.bytes - return Data([ + data += [ connectionHandleBytes.0, connectionHandleBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEReadRemoteUsedFeaturesComplete.swift b/Sources/BluetoothHCI/HCILEReadRemoteUsedFeaturesComplete.swift index 91b3039d5..dbcfaca93 100644 --- a/Sources/BluetoothHCI/HCILEReadRemoteUsedFeaturesComplete.swift +++ b/Sources/BluetoothHCI/HCILEReadRemoteUsedFeaturesComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Read Remote Features Complete Event /// /// The event is used to indicate the completion of the process of the Controller diff --git a/Sources/BluetoothHCI/HCILEReadResolvingListSize.swift b/Sources/BluetoothHCI/HCILEReadResolvingListSize.swift index 4cb8f7352..07e60249e 100644 --- a/Sources/BluetoothHCI/HCILEReadResolvingListSize.swift +++ b/Sources/BluetoothHCI/HCILEReadResolvingListSize.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadRfPathCompensation.swift b/Sources/BluetoothHCI/HCILEReadRfPathCompensation.swift index 160b2f493..70a9c0ca9 100644 --- a/Sources/BluetoothHCI/HCILEReadRfPathCompensation.swift +++ b/Sources/BluetoothHCI/HCILEReadRfPathCompensation.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadSuggestedDefaultDataLength.swift b/Sources/BluetoothHCI/HCILEReadSuggestedDefaultDataLength.swift index 6c8f074a6..1643702a0 100644 --- a/Sources/BluetoothHCI/HCILEReadSuggestedDefaultDataLength.swift +++ b/Sources/BluetoothHCI/HCILEReadSuggestedDefaultDataLength.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadSupportedStates.swift b/Sources/BluetoothHCI/HCILEReadSupportedStates.swift index 8bc0948a9..d269ae8c2 100644 --- a/Sources/BluetoothHCI/HCILEReadSupportedStates.swift +++ b/Sources/BluetoothHCI/HCILEReadSupportedStates.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadTransmitPower.swift b/Sources/BluetoothHCI/HCILEReadTransmitPower.swift index d0e7bc4e0..340747509 100644 --- a/Sources/BluetoothHCI/HCILEReadTransmitPower.swift +++ b/Sources/BluetoothHCI/HCILEReadTransmitPower.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReadWhiteListSize.swift b/Sources/BluetoothHCI/HCILEReadWhiteListSize.swift index 3604d3611..c5efaaed2 100644 --- a/Sources/BluetoothHCI/HCILEReadWhiteListSize.swift +++ b/Sources/BluetoothHCI/HCILEReadWhiteListSize.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILEReceiverTest.swift b/Sources/BluetoothHCI/HCILEReceiverTest.swift index dedfcb6ab..7a4b9d145 100644 --- a/Sources/BluetoothHCI/HCILEReceiverTest.swift +++ b/Sources/BluetoothHCI/HCILEReceiverTest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -44,8 +42,8 @@ public struct HCILEReceiverTest: HCICommandParameter { self.rxChannel = rxChannel } - public var data: Data { + public func append(to data: inout Data) { - return Data([rxChannel.rawValue]) + data += [rxChannel.rawValue] } } diff --git a/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequest.swift b/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequest.swift index 8ab16e7c0..8f2430352 100644 --- a/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequest.swift +++ b/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Remote Connection Parameter Request Event /// /// This event indicates to the master’s Host or the slave’s Host that the remote device is requesting diff --git a/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequestNegativeReply.swift b/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequestNegativeReply.swift index d3363d688..d11265bcf 100644 --- a/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequestNegativeReply.swift +++ b/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequestNegativeReply.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -60,15 +58,15 @@ public struct HCILERemoteConnectionParameterRequestNegativeReply: HCICommandPara self.reason = reason } - public var data: Data { + public func append(to data: inout Data) { let connectionHandleBytes = connectionHandle.littleEndian.bytes - return Data([ + data += [ connectionHandleBytes.0, connectionHandleBytes.1, reason - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequestReply.swift b/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequestReply.swift index 2e395368a..52eefcec3 100644 --- a/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequestReply.swift +++ b/Sources/BluetoothHCI/HCILERemoteConnectionParameterRequestReply.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -76,7 +74,7 @@ public struct HCILERemoteConnectionParameterRequestReply: HCICommandParameter { self.length = length } - public var data: Data { + public func append(to data: inout Data) { let connectionHandleBytes = connectionHandle.littleEndian.bytes let connectionIntervalMinBytes = interval.rawValue.lowerBound.littleEndian.bytes @@ -86,7 +84,7 @@ public struct HCILERemoteConnectionParameterRequestReply: HCICommandParameter { let connectionLengthMinBytes = length.rawValue.lowerBound.littleEndian.bytes let connectionLengthMaxBytes = length.rawValue.upperBound.littleEndian.bytes - return Data([ + data += [ connectionHandleBytes.0, connectionHandleBytes.1, connectionIntervalMinBytes.0, @@ -101,7 +99,7 @@ public struct HCILERemoteConnectionParameterRequestReply: HCICommandParameter { connectionLengthMinBytes.1, connectionLengthMaxBytes.0, connectionLengthMaxBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILERemoveAdvertisingSet.swift b/Sources/BluetoothHCI/HCILERemoveAdvertisingSet.swift index 0d9f36538..550b57123 100644 --- a/Sources/BluetoothHCI/HCILERemoveAdvertisingSet.swift +++ b/Sources/BluetoothHCI/HCILERemoveAdvertisingSet.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -45,7 +43,7 @@ public struct HCILERemoveAdvertisingSet: HCICommandParameter { self.advertisingHandle = advertisingHandle } - public var data: Data { - return Data([advertisingHandle]) + public func append(to data: inout Data) { + data += [advertisingHandle] } } diff --git a/Sources/BluetoothHCI/HCILERemoveDeviceFromResolvingList.swift b/Sources/BluetoothHCI/HCILERemoveDeviceFromResolvingList.swift index 725eeb216..da24b5bf6 100644 --- a/Sources/BluetoothHCI/HCILERemoveDeviceFromResolvingList.swift +++ b/Sources/BluetoothHCI/HCILERemoveDeviceFromResolvingList.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -67,11 +65,11 @@ public struct HCILERemoveDeviceFromResolvingList: HCICommandParameter { self.peerIdentifyAddress = peerIdentifyAddress } - public var data: Data { + public func append(to data: inout Data) { let peerIdentifyAddressBytes = peerIdentifyAddress.littleEndian.bytes - return Data([ + data += [ peerIdentifyAddressType.rawValue, peerIdentifyAddressBytes.0, peerIdentifyAddressBytes.1, @@ -81,6 +79,6 @@ public struct HCILERemoveDeviceFromResolvingList: HCICommandParameter { peerIdentifyAddressBytes.5, peerIdentifyAddressBytes.6, peerIdentifyAddressBytes.7 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILERemoveDeviceFromWhiteList.swift b/Sources/BluetoothHCI/HCILERemoveDeviceFromWhiteList.swift index b4fb7c506..cfb39a971 100644 --- a/Sources/BluetoothHCI/HCILERemoveDeviceFromWhiteList.swift +++ b/Sources/BluetoothHCI/HCILERemoveDeviceFromWhiteList.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -51,11 +49,8 @@ public struct HCILERemoveDeviceFromWhiteList: HCICommandParameter { // HCI_LE_R extension HCILERemoveDeviceFromWhiteList { - public var data: Data { - var data = Data() - data.reserveCapacity(self.dataLength) + public func append(to data: inout Data) { data += self - return data } var dataLength: Int { diff --git a/Sources/BluetoothHCI/HCILERemoveDeviceToPeriodicAdvertiserList.swift b/Sources/BluetoothHCI/HCILERemoveDeviceToPeriodicAdvertiserList.swift index 55b05a2f8..e89cf1a02 100644 --- a/Sources/BluetoothHCI/HCILERemoveDeviceToPeriodicAdvertiserList.swift +++ b/Sources/BluetoothHCI/HCILERemoveDeviceToPeriodicAdvertiserList.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -69,11 +67,8 @@ public struct HCILERemoveDeviceToPeriodicAdvertiserList: HCICommandParameter { extension HCILERemoveDeviceToPeriodicAdvertiserList { - public var data: Data { - var data = Data() - data.reserveCapacity(self.dataLength) + public func append(to data: inout Data) { data += self - return data } var dataLength: Int { return 1 + BluetoothAddress.length + 1 } diff --git a/Sources/BluetoothHCI/HCILEScanRequestReceived.swift b/Sources/BluetoothHCI/HCILEScanRequestReceived.swift index ee26185cb..b294bfd5b 100644 --- a/Sources/BluetoothHCI/HCILEScanRequestReceived.swift +++ b/Sources/BluetoothHCI/HCILEScanRequestReceived.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Scan Request Received Event /// /// The vent indicates that a SCAN_REQ PDU or an AUX_SCAN_REQ PDU has been received by the advertiser. diff --git a/Sources/BluetoothHCI/HCILESetAddressResolutionEnable.swift b/Sources/BluetoothHCI/HCILESetAddressResolutionEnable.swift index 957a46ce7..7839455e4 100644 --- a/Sources/BluetoothHCI/HCILESetAddressResolutionEnable.swift +++ b/Sources/BluetoothHCI/HCILESetAddressResolutionEnable.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -50,8 +48,8 @@ public struct HCILESetAddressResolutionEnable: HCICommandParameter { //HCI_LE_S self.addressResolutionEnable = addressResolutionEnable } - public var data: Data { - return Data([addressResolutionEnable.rawValue]) + public func append(to data: inout Data) { + data += [addressResolutionEnable.rawValue] } public enum AddressResolutionEnable: UInt8 { diff --git a/Sources/BluetoothHCI/HCILESetAdvertiseEnable.swift b/Sources/BluetoothHCI/HCILESetAdvertiseEnable.swift index 41ccc7370..a985aeda7 100644 --- a/Sources/BluetoothHCI/HCILESetAdvertiseEnable.swift +++ b/Sources/BluetoothHCI/HCILESetAdvertiseEnable.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -54,8 +52,8 @@ public struct HCILESetAdvertiseEnable: HCICommandParameter { // HCI_LE_Set_Adve self.isEnabled = isEnabled } - public var data: Data { + public func append(to data: inout Data) { - return Data([isEnabled.byteValue]) + data += [isEnabled.byteValue] } } diff --git a/Sources/BluetoothHCI/HCILESetAdvertisingData.swift b/Sources/BluetoothHCI/HCILESetAdvertisingData.swift index b196fe235..130f8a817 100644 --- a/Sources/BluetoothHCI/HCILESetAdvertisingData.swift +++ b/Sources/BluetoothHCI/HCILESetAdvertisingData.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -47,8 +45,8 @@ public struct HCILESetAdvertisingData: HCICommandParameter { // HCI_LE_Set_Adve self.advertisingData = advertisingData } - public var data: Data { + public func append(to data: inout Data) { - return Data([advertisingData.length, advertisingData.bytes.0, advertisingData.bytes.1, advertisingData.bytes.2, advertisingData.bytes.3, advertisingData.bytes.4, advertisingData.bytes.5, advertisingData.bytes.6, advertisingData.bytes.7, advertisingData.bytes.8, advertisingData.bytes.9, advertisingData.bytes.10, advertisingData.bytes.11, advertisingData.bytes.12, advertisingData.bytes.13, advertisingData.bytes.14, advertisingData.bytes.15, advertisingData.bytes.16, advertisingData.bytes.17, advertisingData.bytes.18, advertisingData.bytes.19, advertisingData.bytes.20, advertisingData.bytes.21, advertisingData.bytes.22, advertisingData.bytes.23, advertisingData.bytes.24, advertisingData.bytes.25, advertisingData.bytes.26, advertisingData.bytes.27, advertisingData.bytes.28, advertisingData.bytes.29, advertisingData.bytes.30]) + data += [advertisingData.length, advertisingData.bytes.0, advertisingData.bytes.1, advertisingData.bytes.2, advertisingData.bytes.3, advertisingData.bytes.4, advertisingData.bytes.5, advertisingData.bytes.6, advertisingData.bytes.7, advertisingData.bytes.8, advertisingData.bytes.9, advertisingData.bytes.10, advertisingData.bytes.11, advertisingData.bytes.12, advertisingData.bytes.13, advertisingData.bytes.14, advertisingData.bytes.15, advertisingData.bytes.16, advertisingData.bytes.17, advertisingData.bytes.18, advertisingData.bytes.19, advertisingData.bytes.20, advertisingData.bytes.21, advertisingData.bytes.22, advertisingData.bytes.23, advertisingData.bytes.24, advertisingData.bytes.25, advertisingData.bytes.26, advertisingData.bytes.27, advertisingData.bytes.28, advertisingData.bytes.29, advertisingData.bytes.30] } } diff --git a/Sources/BluetoothHCI/HCILESetAdvertisingParameters.swift b/Sources/BluetoothHCI/HCILESetAdvertisingParameters.swift index 2a06201c3..e6de67f3c 100644 --- a/Sources/BluetoothHCI/HCILESetAdvertisingParameters.swift +++ b/Sources/BluetoothHCI/HCILESetAdvertisingParameters.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -93,11 +91,8 @@ extension HCILESetAdvertisingParameters { static var length: Int { return 2 + 2 + 1 + 1 + 1 + 6 + 1 + 1 } - public var data: Data { - var data = Data() - data.reserveCapacity(Self.length) + public func append(to data: inout Data) { data += self - return data } var dataLength: Int { diff --git a/Sources/BluetoothHCI/HCILESetAdvertisingSetRandomAddress.swift b/Sources/BluetoothHCI/HCILESetAdvertisingSetRandomAddress.swift index b67c74e5b..67af53192 100644 --- a/Sources/BluetoothHCI/HCILESetAdvertisingSetRandomAddress.swift +++ b/Sources/BluetoothHCI/HCILESetAdvertisingSetRandomAddress.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -57,11 +55,11 @@ public struct HCILESetAdvertisingSetRandomAddress: HCICommandParameter { //HCI_ self.advertisingRandomAddress = advertisingRandomAddress } - public var data: Data { + public func append(to data: inout Data) { let advertisingRandomAddressBytes = advertisingRandomAddress.littleEndian.bytes - return Data([ + data += [ advertisingHandle, advertisingRandomAddressBytes.0, advertisingRandomAddressBytes.1, @@ -69,6 +67,6 @@ public struct HCILESetAdvertisingSetRandomAddress: HCICommandParameter { //HCI_ advertisingRandomAddressBytes.3, advertisingRandomAddressBytes.4, advertisingRandomAddressBytes.5 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILESetDataLength.swift b/Sources/BluetoothHCI/HCILESetDataLength.swift index 18a602822..ca32912ca 100644 --- a/Sources/BluetoothHCI/HCILESetDataLength.swift +++ b/Sources/BluetoothHCI/HCILESetDataLength.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -62,20 +60,20 @@ public struct HCILESetDataLength: HCICommandParameter { self.txTime = txTime } - public var data: Data { + public func append(to data: inout Data) { let connectionHandleBytes = connectionHandle.littleEndian.bytes let txOctetsBytes = txOctets.rawValue.littleEndian.bytes let txTimeBytes = txTime.rawValue.littleEndian.bytes - return Data([ + data += [ connectionHandleBytes.0, connectionHandleBytes.1, txOctetsBytes.0, txOctetsBytes.1, txTimeBytes.0, txTimeBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILESetDefaultPhy.swift b/Sources/BluetoothHCI/HCILESetDefaultPhy.swift index 170febded..a214e300e 100644 --- a/Sources/BluetoothHCI/HCILESetDefaultPhy.swift +++ b/Sources/BluetoothHCI/HCILESetDefaultPhy.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -56,7 +54,7 @@ public struct HCILESetDefaultPhy: HCICommandParameter { self.rxPhys = rxPhys } - public var data: Data { - return Data([allPhys.rawValue, txPhys.rawValue, rxPhys.rawValue]) + public func append(to data: inout Data) { + data += [allPhys.rawValue, txPhys.rawValue, rxPhys.rawValue] } } diff --git a/Sources/BluetoothHCI/HCILESetEventMask.swift b/Sources/BluetoothHCI/HCILESetEventMask.swift index 264dec03d..89866d838 100644 --- a/Sources/BluetoothHCI/HCILESetEventMask.swift +++ b/Sources/BluetoothHCI/HCILESetEventMask.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - BluetoothHostControllerInterface public extension BluetoothHostControllerInterface { @@ -55,11 +53,11 @@ public struct HCILESetEventMask: HCICommandParameter { self.eventMask = eventMask } - public var data: Data { + public func append(to data: inout Data) { let eventMaskBytes = eventMask.rawValue.littleEndian.bytes - return Data([ + data += [ eventMaskBytes.0, eventMaskBytes.1, eventMaskBytes.2, @@ -68,7 +66,7 @@ public struct HCILESetEventMask: HCICommandParameter { eventMaskBytes.5, eventMaskBytes.6, eventMaskBytes.7 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILESetExtendedAdvertisingData.swift b/Sources/BluetoothHCI/HCILESetExtendedAdvertisingData.swift index aa8bdc03a..e87b52a66 100644 --- a/Sources/BluetoothHCI/HCILESetExtendedAdvertisingData.swift +++ b/Sources/BluetoothHCI/HCILESetExtendedAdvertisingData.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -57,16 +55,17 @@ public struct HCILESetExtendedAdvertisingData: HCICommandParameter { self.advertisingData = advertisingData } - public var data: Data { + public func append(to data: inout Data) { let advertisingDataLength = UInt8(advertisingData.count) - return Data([ + data += [ advertisingHandle, operation.rawValue, fragmentPreference.rawValue, advertisingDataLength - ]) + advertisingData + ] + data += advertisingData } public enum Operation: UInt8 { //Operation diff --git a/Sources/BluetoothHCI/HCILESetExtendedAdvertisingParameters.swift b/Sources/BluetoothHCI/HCILESetExtendedAdvertisingParameters.swift index 5b5f2bb44..6cd24d629 100644 --- a/Sources/BluetoothHCI/HCILESetExtendedAdvertisingParameters.swift +++ b/Sources/BluetoothHCI/HCILESetExtendedAdvertisingParameters.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -121,7 +119,7 @@ public struct HCILESetExtendedAdvertisingParameters: HCICommandParameter { //HC self.scanRequestNotificationEnable = scanRequestNotificationEnable } - public var data: Data { + public func append(to data: inout Data) { let advertisingEventPropertiesBytes = advertisingEventProperties.rawValue.littleEndian.bytes @@ -132,7 +130,7 @@ public struct HCILESetExtendedAdvertisingParameters: HCICommandParameter { //HC let advertisingTxPowerByte = UInt8.init(bitPattern: advertisingTxPower.rawValue) - return Data([ + data += [ advertisingHandle, advertisingEventPropertiesBytes.0, advertisingEventPropertiesBytes.1, @@ -158,7 +156,7 @@ public struct HCILESetExtendedAdvertisingParameters: HCICommandParameter { //HC secondaryAdvertisingPhy.rawValue, advertisingSid, scanRequestNotificationEnable.rawValue - ]) + ] } /// The Scan_Request_Notification_Enable parameter indicates whether the Controller shall send diff --git a/Sources/BluetoothHCI/HCILESetExtendedScanEnable.swift b/Sources/BluetoothHCI/HCILESetExtendedScanEnable.swift index de25b0343..1b6e60908 100644 --- a/Sources/BluetoothHCI/HCILESetExtendedScanEnable.swift +++ b/Sources/BluetoothHCI/HCILESetExtendedScanEnable.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -61,19 +59,19 @@ public struct HCILESetExtendedScanEnable: HCICommandParameter { self.period = period } - public var data: Data { + public func append(to data: inout Data) { let durationBytes = duration.rawValue.littleEndian.bytes let periodBytes = period.rawValue.littleEndian.bytes - return Data([ + data += [ enable.rawValue, filterDuplicates.rawValue, durationBytes.0, durationBytes.1, periodBytes.0, periodBytes.1 - ]) + ] } /// The Enable parameter determines whether scanning is enabled or disabled. diff --git a/Sources/BluetoothHCI/HCILESetExtendedScanParameters.swift b/Sources/BluetoothHCI/HCILESetExtendedScanParameters.swift index 0f68d87c7..91f09ca82 100644 --- a/Sources/BluetoothHCI/HCILESetExtendedScanParameters.swift +++ b/Sources/BluetoothHCI/HCILESetExtendedScanParameters.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -55,7 +53,7 @@ public struct HCILESetExtendedScanParameters: HCICommandParameter { self.scanningPHY = scanningPHY } - public var data: Data { + public func append(to data: inout Data) { let length: Int @@ -69,8 +67,6 @@ public struct HCILESetExtendedScanParameters: HCICommandParameter { length = 3 + 10 } - - var data = Data() data.reserveCapacity(length) // improve buffer performance // Own_Address_Type @@ -107,8 +103,6 @@ public struct HCILESetExtendedScanParameters: HCICommandParameter { } assert(data.count == length, "Invalid number of bytes") - - return data } public enum ScanningFilterPolicy: UInt8 { diff --git a/Sources/BluetoothHCI/HCILESetExtendedScanResponseData.swift b/Sources/BluetoothHCI/HCILESetExtendedScanResponseData.swift index e5e303589..d84106a3c 100644 --- a/Sources/BluetoothHCI/HCILESetExtendedScanResponseData.swift +++ b/Sources/BluetoothHCI/HCILESetExtendedScanResponseData.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -58,14 +56,15 @@ public struct HCILESetExtendedScanResponseData: HCICommandParameter { self.scanResponseData = scanResponseData } - public var data: Data { + public func append(to data: inout Data) { let scanResponseDataLength = UInt8(scanResponseData.count) - return Data([ + data += [ advertisingHandle, operation.rawValue, fragmentPreference.rawValue, scanResponseDataLength - ]) + scanResponseData + ] + data += scanResponseData } public enum Operation: UInt8 { //Operation diff --git a/Sources/BluetoothHCI/HCILESetHostChannelClassification.swift b/Sources/BluetoothHCI/HCILESetHostChannelClassification.swift index c4470a0d7..579809b17 100644 --- a/Sources/BluetoothHCI/HCILESetHostChannelClassification.swift +++ b/Sources/BluetoothHCI/HCILESetHostChannelClassification.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Command /// LE Set Host Channel Classification Command @@ -31,13 +29,13 @@ public struct HCILESetHostChannelClassification: HCICommandParameter { // HCI_L self.channelMap = channelMap } - public var data: Data { - return Data([ + public func append(to data: inout Data) { + data += [ channelMap.0, channelMap.1, channelMap.2, channelMap.3, channelMap.4 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingData.swift b/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingData.swift index 1f12e5cea..1cdd54c2c 100644 --- a/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingData.swift +++ b/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingData.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -53,15 +51,16 @@ public struct HCILESetPeriodicAdvertisingData: HCICommandParameter { self.advertisingData = advertisingData } - public var data: Data { + public func append(to data: inout Data) { let advertisingDataLength = UInt8(advertisingData.count) - return Data([ + data += [ advertisingHandle, operation.rawValue, advertisingDataLength - ]) + advertisingData + ] + data += advertisingData } public enum Operation: UInt8 { //Operation diff --git a/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingEnable.swift b/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingEnable.swift index f9e8113fc..2690ad1ed 100644 --- a/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingEnable.swift +++ b/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingEnable.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -47,11 +45,11 @@ public struct HCILESetPeriodicAdvertisingEnable: HCICommandParameter { self.advertisingHandle = advertisingHandle } - public var data: Data { - return Data([ + public func append(to data: inout Data) { + data += [ enable.rawValue, advertisingHandle - ]) + ] } public enum Enable: UInt8 { diff --git a/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingParameters.swift b/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingParameters.swift index 5e0977b36..7a50b47a0 100644 --- a/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingParameters.swift +++ b/Sources/BluetoothHCI/HCILESetPeriodicAdvertisingParameters.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -76,12 +74,12 @@ public struct HCILESetPeriodicAdvertisingParameters: HCICommandParameter { self.advertisingEventProperties = advertisingEventProperties } - public var data: Data { + public func append(to data: inout Data) { let periodicAdvertisingIntervalMinBytes = periodicAdvertisingInterval.rawValue.lowerBound.littleEndian.bytes let periodicAdvertisingIntervalMaxBytes = periodicAdvertisingInterval.rawValue.upperBound.littleEndian.bytes let advertisingEventPropertiesytes = advertisingEventProperties.rawValue.littleEndian.bytes - return Data([ + data += [ advertisingHandle, periodicAdvertisingIntervalMinBytes.0, periodicAdvertisingIntervalMinBytes.1, @@ -89,7 +87,7 @@ public struct HCILESetPeriodicAdvertisingParameters: HCICommandParameter { periodicAdvertisingIntervalMaxBytes.1, advertisingEventPropertiesytes.0, advertisingEventPropertiesytes.1 - ]) + ] } public struct PeriodicAdvertisingInterval: RawRepresentable, Equatable, Hashable, Sendable { diff --git a/Sources/BluetoothHCI/HCILESetPhy.swift b/Sources/BluetoothHCI/HCILESetPhy.swift index c039c2dc3..723c99f82 100644 --- a/Sources/BluetoothHCI/HCILESetPhy.swift +++ b/Sources/BluetoothHCI/HCILESetPhy.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -84,12 +82,12 @@ public struct HCILESetPhy: HCICommandParameter { self.phyOptions = phyOptions } - public var data: Data { + public func append(to data: inout Data) { let connectionHandleBytes = connectionHandle.littleEndian.bytes let phyOptionsBytes = phyOptions.rawValue.littleEndian.bytes - return Data([ + data += [ connectionHandleBytes.0, connectionHandleBytes.1, allPhys.rawValue, @@ -97,6 +95,6 @@ public struct HCILESetPhy: HCICommandParameter { rxPhys.rawValue, phyOptionsBytes.0, phyOptionsBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILESetPrivacyMode.swift b/Sources/BluetoothHCI/HCILESetPrivacyMode.swift index 41e3b36bf..56d347a65 100644 --- a/Sources/BluetoothHCI/HCILESetPrivacyMode.swift +++ b/Sources/BluetoothHCI/HCILESetPrivacyMode.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -56,11 +54,11 @@ public struct HCILESetPrivacyMode: HCICommandParameter { self.privacyMode = privacyMode } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = peerIdentityAddress.littleEndian.bytes - return Data([ + data += [ peerIdentityAddressType.rawValue, addressBytes.0, addressBytes.1, @@ -69,7 +67,7 @@ public struct HCILESetPrivacyMode: HCICommandParameter { addressBytes.4, addressBytes.5, privacyMode.rawValue - ]) + ] } public enum PrivacyMode: UInt8 { diff --git a/Sources/BluetoothHCI/HCILESetRandomAddress.swift b/Sources/BluetoothHCI/HCILESetRandomAddress.swift index 229935ec9..6d4a1a80b 100644 --- a/Sources/BluetoothHCI/HCILESetRandomAddress.swift +++ b/Sources/BluetoothHCI/HCILESetRandomAddress.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -49,10 +47,10 @@ public struct HCILESetRandomAddress: HCICommandParameter { self.address = address } - public var data: Data { + public func append(to data: inout Data) { let bytes = address.littleEndian.bytes - return Data([bytes.0, bytes.1, bytes.2, bytes.3, bytes.4, bytes.5]) + data += [bytes.0, bytes.1, bytes.2, bytes.3, bytes.4, bytes.5] } } diff --git a/Sources/BluetoothHCI/HCILESetResolvablePrivateAddressTimeout.swift b/Sources/BluetoothHCI/HCILESetResolvablePrivateAddressTimeout.swift index 73014a871..8a42a6fa1 100644 --- a/Sources/BluetoothHCI/HCILESetResolvablePrivateAddressTimeout.swift +++ b/Sources/BluetoothHCI/HCILESetResolvablePrivateAddressTimeout.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -49,14 +47,14 @@ public struct HCILESetResolvablePrivateAddressTimeout: HCICommandParameter { self.rpaTimeout = rpaTimeout } - public var data: Data { + public func append(to data: inout Data) { let rpaTimeoutBytes = rpaTimeout.rawValue.littleEndian.bytes - return Data([ + data += [ rpaTimeoutBytes.0, rpaTimeoutBytes.1 - ]) + ] } /// RPA_Timeout measured in s diff --git a/Sources/BluetoothHCI/HCILESetScanEnable.swift b/Sources/BluetoothHCI/HCILESetScanEnable.swift index 90bff0a64..e0e99a1ac 100644 --- a/Sources/BluetoothHCI/HCILESetScanEnable.swift +++ b/Sources/BluetoothHCI/HCILESetScanEnable.swift @@ -142,8 +142,8 @@ public struct HCILESetScanEnable: HCICommandParameter { // HCI_LE_Set_Scan_Enab self.filterDuplicates = filterDuplicates } - public var data: Data { + public func append(to data: inout Data) { - return Data([isEnabled.byteValue, filterDuplicates.byteValue]) + data += [isEnabled.byteValue, filterDuplicates.byteValue] } } diff --git a/Sources/BluetoothHCI/HCILESetScanParameters.swift b/Sources/BluetoothHCI/HCILESetScanParameters.swift index a4cee6ba7..ae6bdb933 100644 --- a/Sources/BluetoothHCI/HCILESetScanParameters.swift +++ b/Sources/BluetoothHCI/HCILESetScanParameters.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// LE Set Scan Parameters Command /// /// Used to set the scan parameters. @@ -55,7 +53,7 @@ public struct HCILESetScanParameters: HCICommandParameter { // HCI_LE_Set_Scan_ self.filterPolicy = filterPolicy } - public var data: Data { + public func append(to data: inout Data) { let scanType = type.rawValue let scanInterval = interval.rawValue.littleEndian.bytes @@ -63,7 +61,7 @@ public struct HCILESetScanParameters: HCICommandParameter { // HCI_LE_Set_Scan_ let ownAddressType = addressType.rawValue let filter = filterPolicy.rawValue - return Data([scanType, scanInterval.0, scanInterval.1, scanWindow.0, scanWindow.1, ownAddressType, filter]) + data += [scanType, scanInterval.0, scanInterval.1, scanWindow.0, scanWindow.1, ownAddressType, filter] } } diff --git a/Sources/BluetoothHCI/HCILESetScanResponseData.swift b/Sources/BluetoothHCI/HCILESetScanResponseData.swift index d9e5eba8b..d41111e35 100644 --- a/Sources/BluetoothHCI/HCILESetScanResponseData.swift +++ b/Sources/BluetoothHCI/HCILESetScanResponseData.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -53,8 +51,8 @@ public struct HCILESetScanResponseData: HCICommandParameter { // HCI_LE_Set_Sca self.advertisingData = advertisingData } - public var data: Data { + public func append(to data: inout Data) { - return Data([advertisingData.length, advertisingData.bytes.0, advertisingData.bytes.1, advertisingData.bytes.2, advertisingData.bytes.3, advertisingData.bytes.4, advertisingData.bytes.5, advertisingData.bytes.6, advertisingData.bytes.7, advertisingData.bytes.8, advertisingData.bytes.9, advertisingData.bytes.10, advertisingData.bytes.11, advertisingData.bytes.12, advertisingData.bytes.13, advertisingData.bytes.14, advertisingData.bytes.15, advertisingData.bytes.16, advertisingData.bytes.17, advertisingData.bytes.18, advertisingData.bytes.19, advertisingData.bytes.20, advertisingData.bytes.21, advertisingData.bytes.22, advertisingData.bytes.23, advertisingData.bytes.24, advertisingData.bytes.25, advertisingData.bytes.26, advertisingData.bytes.27, advertisingData.bytes.28, advertisingData.bytes.29, advertisingData.bytes.30]) + data += [advertisingData.length, advertisingData.bytes.0, advertisingData.bytes.1, advertisingData.bytes.2, advertisingData.bytes.3, advertisingData.bytes.4, advertisingData.bytes.5, advertisingData.bytes.6, advertisingData.bytes.7, advertisingData.bytes.8, advertisingData.bytes.9, advertisingData.bytes.10, advertisingData.bytes.11, advertisingData.bytes.12, advertisingData.bytes.13, advertisingData.bytes.14, advertisingData.bytes.15, advertisingData.bytes.16, advertisingData.bytes.17, advertisingData.bytes.18, advertisingData.bytes.19, advertisingData.bytes.20, advertisingData.bytes.21, advertisingData.bytes.22, advertisingData.bytes.23, advertisingData.bytes.24, advertisingData.bytes.25, advertisingData.bytes.26, advertisingData.bytes.27, advertisingData.bytes.28, advertisingData.bytes.29, advertisingData.bytes.30] } } diff --git a/Sources/BluetoothHCI/HCILEStartEncryption.swift b/Sources/BluetoothHCI/HCILEStartEncryption.swift index b909cc271..ee3f2c9fe 100644 --- a/Sources/BluetoothHCI/HCILEStartEncryption.swift +++ b/Sources/BluetoothHCI/HCILEStartEncryption.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -142,11 +140,8 @@ public struct HCILEStartEncryption: HCICommandParameter { // HCI_LE_Start_Encry extension HCILEStartEncryption { - public var data: Data { - var data = Data() - data.reserveCapacity(self.dataLength) + public func append(to data: inout Data) { data += self - return data } var dataLength: Int { diff --git a/Sources/BluetoothHCI/HCILETestEnd.swift b/Sources/BluetoothHCI/HCILETestEnd.swift index d8e55ce81..8717b0c7e 100644 --- a/Sources/BluetoothHCI/HCILETestEnd.swift +++ b/Sources/BluetoothHCI/HCILETestEnd.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCILETransmitterTest.swift b/Sources/BluetoothHCI/HCILETransmitterTest.swift index 10aff4720..2049a9c7b 100644 --- a/Sources/BluetoothHCI/HCILETransmitterTest.swift +++ b/Sources/BluetoothHCI/HCILETransmitterTest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -63,8 +61,8 @@ public struct HCILETransmitterTest: HCICommandParameter { self.packetPayload = packetPayload } - public var data: Data { + public func append(to data: inout Data) { - return Data([txChannel.rawValue, packetPayload.rawValue]) + data += [txChannel.rawValue, packetPayload.rawValue] } } diff --git a/Sources/BluetoothHCI/HCILEUpdateConnection.swift b/Sources/BluetoothHCI/HCILEUpdateConnection.swift index 3712c7ad2..3849ca564 100644 --- a/Sources/BluetoothHCI/HCILEUpdateConnection.swift +++ b/Sources/BluetoothHCI/HCILEUpdateConnection.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -105,7 +103,7 @@ public struct HCILEUpdateConnection: HCICommandParameter { // HCI_LE_Connection self.connectionLength = connectionLength } - public var data: Data { + public func append(to data: inout Data) { let connectionIntervalMinBytes = connectionInterval.rawValue.lowerBound.littleEndian.bytes let connectionIntervalMaxBytes = connectionInterval.rawValue.upperBound.littleEndian.bytes let connectionLatencyBytes = connectionLatency.rawValue.littleEndian.bytes @@ -113,7 +111,7 @@ public struct HCILEUpdateConnection: HCICommandParameter { // HCI_LE_Connection let connectionLengthMinBytes = connectionLength.rawValue.lowerBound.littleEndian.bytes let connectionLengthMaxBytes = connectionLength.rawValue.upperBound.littleEndian.bytes - return Data([ + data += [ connectionHandle.littleEndian.bytes.0, connectionHandle.littleEndian.bytes.1, connectionIntervalMinBytes.0, @@ -128,6 +126,6 @@ public struct HCILEUpdateConnection: HCICommandParameter { // HCI_LE_Connection connectionLengthMinBytes.1, connectionLengthMaxBytes.0, connectionLengthMaxBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEWriteRfPathCompensation.swift b/Sources/BluetoothHCI/HCILEWriteRfPathCompensation.swift index e9af63a05..acc14a10b 100644 --- a/Sources/BluetoothHCI/HCILEWriteRfPathCompensation.swift +++ b/Sources/BluetoothHCI/HCILEWriteRfPathCompensation.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -63,16 +61,16 @@ public struct HCILEWriteRfPathCompensation: HCICommandParameter { self.rfRxPathCompensationValue = rfRxPathCompensationValue } - public var data: Data { + public func append(to data: inout Data) { let rfTxPathCompensationValueBytes = UInt16.init(bitPattern: rfTxPathCompensationValue.rawValue).littleEndian.bytes let rfRxPathCompensationValueBytes = UInt16.init(bitPattern: rfRxPathCompensationValue.rawValue).littleEndian.bytes - return Data([ + data += [ rfTxPathCompensationValueBytes.0, rfTxPathCompensationValueBytes.1, rfRxPathCompensationValueBytes.0, rfRxPathCompensationValueBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILEWriteSuggestedDefaultDataLength.swift b/Sources/BluetoothHCI/HCILEWriteSuggestedDefaultDataLength.swift index a80d0dcca..4359b820d 100644 --- a/Sources/BluetoothHCI/HCILEWriteSuggestedDefaultDataLength.swift +++ b/Sources/BluetoothHCI/HCILEWriteSuggestedDefaultDataLength.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -53,15 +51,15 @@ public struct HCILEWriteSuggestedDefaultDataLength: HCICommandParameter { self.suggestedMaxTxTime = suggestedMaxTxTime } - public var data: Data { + public func append(to data: inout Data) { let suggestedMaxTxOctetsBytes = suggestedMaxTxOctets.rawValue.littleEndian.bytes let suggestedMaxTxTimeBytes = suggestedMaxTxTime.rawValue.littleEndian.bytes - return Data([ + data += [ suggestedMaxTxOctetsBytes.0, suggestedMaxTxOctetsBytes.1, suggestedMaxTxTimeBytes.0, suggestedMaxTxTimeBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILinkKeyNotification.swift b/Sources/BluetoothHCI/HCILinkKeyNotification.swift index 840d9c959..2c2310541 100644 --- a/Sources/BluetoothHCI/HCILinkKeyNotification.swift +++ b/Sources/BluetoothHCI/HCILinkKeyNotification.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Link Key Notification Event /// /// The Link Key Notification event is used to indicate to the Host that a new Link Key has been created for the connection with the device specified in BD_ADDR. The Host can save this new Link Key in its own storage for future use. Also, the Host can decided to store the Link Key in the BR/EDR Control- ler’s Link Key Storage by using the Write_Stored_Link_Key command. The Key_Type event parameter informs the Host about which key type (combina- tion key, local unit key, or remote unit key, debug combination key, unauthenti- cated combination key, authenticated combination key or changed combination key) that was used during pairing. If pairing with unit key is not supported, the Host can for instance discard the key or disconnect the link. diff --git a/Sources/BluetoothHCI/HCILinkKeyRequest.swift b/Sources/BluetoothHCI/HCILinkKeyRequest.swift index d2000430d..99e07972c 100644 --- a/Sources/BluetoothHCI/HCILinkKeyRequest.swift +++ b/Sources/BluetoothHCI/HCILinkKeyRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Link Key Request Event /// /// The Link Key Request event is used to indicate that a Link Key is required for the connection with the device specified in BD_ADDR. If the Host has the requested stored Link Key, then the Host shall pass the requested Key to the Controller using the Link_Key_Request_Reply command. If the Host does not have the requested stored Link Key, or the stored Link Key does not meet the security requirements for the requested service, then the Host shall use the Link_Key_Request_Negative_Reply command to indicate to the Controller that the Host does not have the requested key. diff --git a/Sources/BluetoothHCI/HCILinkKeyRequestNegativeReply.swift b/Sources/BluetoothHCI/HCILinkKeyRequestNegativeReply.swift index cb442e6d8..6a0e97524 100644 --- a/Sources/BluetoothHCI/HCILinkKeyRequestNegativeReply.swift +++ b/Sources/BluetoothHCI/HCILinkKeyRequestNegativeReply.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -44,18 +42,18 @@ public struct HCILinkKeyRequestNegativeReply: HCICommandParameter { self.address = address } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCILinkKeyRequestReply.swift b/Sources/BluetoothHCI/HCILinkKeyRequestReply.swift index c9c6fbee8..7944121fc 100644 --- a/Sources/BluetoothHCI/HCILinkKeyRequestReply.swift +++ b/Sources/BluetoothHCI/HCILinkKeyRequestReply.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -51,13 +49,13 @@ public struct HCILinkKeyRequestReply: HCICommandParameter { self.linkKey = linkKey } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes let linkKeyBytes = linkKey.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, @@ -80,7 +78,7 @@ public struct HCILinkKeyRequestReply: HCICommandParameter { linkKeyBytes.13, linkKeyBytes.14, linkKeyBytes.15 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIMaxSlotsChange.swift b/Sources/BluetoothHCI/HCIMaxSlotsChange.swift index 85e434854..abed3bb97 100644 --- a/Sources/BluetoothHCI/HCIMaxSlotsChange.swift +++ b/Sources/BluetoothHCI/HCIMaxSlotsChange.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Max Slots Change Event /// /// This event is used to notify the Host about the LMP_Max_Slots parameter when the value of this parameter changes. It shall be sent each time the maximum allowed length, in number of slots, for baseband packets transmitted by the local device, changes. The Connection_Handle will be a Connection_Handle for an ACL connection. diff --git a/Sources/BluetoothHCI/HCIModeChange.swift b/Sources/BluetoothHCI/HCIModeChange.swift index e46e1344c..b7c80326d 100644 --- a/Sources/BluetoothHCI/HCIModeChange.swift +++ b/Sources/BluetoothHCI/HCIModeChange.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Mode Change Event /// /// The Mode Change event is used to indicate when the device associated with the Connection_Handle changes between Active mode, Hold mode, and Sniff mode, and Park state. The Connection_Handle will be a Connection_Handle for an ACL connection. The Connection_Handle event parameter is used to indicate which connection the Mode Change event is for. The Current_Mode event parameter is used to indicate which state the connection is currently in. The Interval parameter is used to specify a time amount specific to each state. Each Controller that is associated with the Connection_Handle which has changed Modes shall send the Mode Change event to its Host. diff --git a/Sources/BluetoothHCI/HCINumberOfCompletedPackets.swift b/Sources/BluetoothHCI/HCINumberOfCompletedPackets.swift index e2b255846..407d9c796 100644 --- a/Sources/BluetoothHCI/HCINumberOfCompletedPackets.swift +++ b/Sources/BluetoothHCI/HCINumberOfCompletedPackets.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// The Number Of Completed Packets event is used by the Controller to indicate to the Host how many HCI Data Packets have been completed (transmitted or flushed) for each Connection_Handle since the previous Number Of Completed Packets event was sent to the Host. This means that the corresponding buffer space has been freed in the Controller. Based on this information, and the HC_Total_Num_ACL_Data_Packets and HC_Total_Num_Synchronous_Data_Packets return parameter of the Read_Buffer_Size command, the Host can determine for which Connection_Handles the following HCI Data Packets should be sent to the Controller. The Number Of Completed Packets event must not be sent before the corresponding Connection Complete event. While the Controller has HCI data packets in its buffer, it must keep sending the Number Of Completed Packets event to the Host at least periodically, until it finally reports that all the pending ACL Data Packets have been transmitted or flushed. The rate with which this event is sent is manufacturer specific. /// /// - Note: Number Of Completed Packets events will not report on synchronous Connection Handles if synchronous Flow Control is disabled. diff --git a/Sources/BluetoothHCI/HCIPINCodeRequest.swift b/Sources/BluetoothHCI/HCIPINCodeRequest.swift index 59b5c263f..7baa13b0b 100644 --- a/Sources/BluetoothHCI/HCIPINCodeRequest.swift +++ b/Sources/BluetoothHCI/HCIPINCodeRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// The PIN Code Request event is used to indicate that a PIN code is required to create a new link key. The Host shall respond using either the PIN_Code_Request_Reply or the PIN_Code_Request_Negative_Reply command, depending on whether the Host can provide the Controller with a PIN code or not. /// /// - Note: If the PIN Code Request event is masked away, then the BR/EDR Controller will assume that the Host has no PIN Code. diff --git a/Sources/BluetoothHCI/HCIPINCodeRequestReply.swift b/Sources/BluetoothHCI/HCIPINCodeRequestReply.swift index 8b4f3a724..c0716978d 100644 --- a/Sources/BluetoothHCI/HCIPINCodeRequestReply.swift +++ b/Sources/BluetoothHCI/HCIPINCodeRequestReply.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -62,13 +60,13 @@ public struct HCIPINCodeRequestReply: HCICommandParameter { self.pinCode = pinCode } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes let pinCodeBytes = pinCode.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, @@ -92,7 +90,7 @@ public struct HCIPINCodeRequestReply: HCICommandParameter { pinCodeBytes.13, pinCodeBytes.14, pinCodeBytes.15 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIPacketHeader.swift b/Sources/BluetoothHCI/HCIPacketHeader.swift index bd84011f7..9f47d2ef2 100644 --- a/Sources/BluetoothHCI/HCIPacketHeader.swift +++ b/Sources/BluetoothHCI/HCIPacketHeader.swift @@ -16,7 +16,18 @@ public protocol HCIPacketHeader { init?(data: Data) - var data: Data { get } + /// Append the header bytes into the buffer. + func append(to data: inout Data) +} + +public extension DataContainer { + + /// Initialize data with contents of packet header. + init(_ value: T) { + self.init() + self.reserveCapacity(T.length) + value.append(to: &self) + } } // MARK: - Command Header @@ -50,7 +61,7 @@ public struct HCICommandHeader: HCIPacketHeader { // hci_command_hdr (packed) public static func from(_ commandParameter: T) -> (HCICommandHeader, Data) { let command = type(of: commandParameter).command - let parameterData = commandParameter.data + let parameterData = Data(commandParameter) let header = HCICommandHeader( command: command, @@ -68,11 +79,11 @@ public struct HCICommandHeader: HCIPacketHeader { // hci_command_hdr (packed) self.parameterLength = data[2] } - public var data: Data { + public func append(to data: inout Data) { let opcodeBytes = opcode.littleEndian.bytes - return Data([opcodeBytes.0, opcodeBytes.1, parameterLength]) + data += [opcodeBytes.0, opcodeBytes.1, parameterLength] } } @@ -108,8 +119,8 @@ public struct HCIEventHeader: HCIPacketHeader { self.parameterLength = data[1] } - public var data: Data { + public func append(to data: inout Data) { - return Data([event.rawValue, parameterLength]) + data += [event.rawValue, parameterLength] } } diff --git a/Sources/BluetoothHCI/HCIPageScanRepetitionMode.swift b/Sources/BluetoothHCI/HCIPageScanRepetitionMode.swift index 85a57fa40..c01ee8cec 100644 --- a/Sources/BluetoothHCI/HCIPageScanRepetitionMode.swift +++ b/Sources/BluetoothHCI/HCIPageScanRepetitionMode.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// The Page_Scan_Repetition_Mode parameter specifies the page scan repetition mode supported by the remote device with the BD_ADDR. This is the information that was acquired during the inquiry process. @frozen public struct PageScanRepetitionMode: RawRepresentable { diff --git a/Sources/BluetoothHCI/HCIPeriodicInquiryMode.swift b/Sources/BluetoothHCI/HCIPeriodicInquiryMode.swift index 67966b67b..af0a00ee9 100644 --- a/Sources/BluetoothHCI/HCIPeriodicInquiryMode.swift +++ b/Sources/BluetoothHCI/HCIPeriodicInquiryMode.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -90,7 +88,7 @@ public struct HCIPeriodicInquiryMode: HCICommandParameter { self.responses = responses } - public var data: Data { + public func append(to data: inout Data) { let minDurationBytes = minDuration.rawValue.littleEndian.bytes @@ -98,13 +96,13 @@ public struct HCIPeriodicInquiryMode: HCICommandParameter { let lapBytes = lap.rawValue.littleEndian.bytes - return Data([ + data += [ maxDurationBytes.0, maxDurationBytes.1, minDurationBytes.0, minDurationBytes.1, lapBytes.0, lapBytes.1, lapBytes.2, length.rawValue, responses.rawValue - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIQoSSetup.swift b/Sources/BluetoothHCI/HCIQoSSetup.swift index 72c2ee88e..cde7761aa 100644 --- a/Sources/BluetoothHCI/HCIQoSSetup.swift +++ b/Sources/BluetoothHCI/HCIQoSSetup.swift @@ -7,8 +7,6 @@ // // swiftlint:disable function_parameter_count -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -85,7 +83,7 @@ public struct HCIQoSSetup: HCICommandParameter { self.delayVariation = delayVariation } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = connectionHandle.littleEndian.bytes @@ -97,7 +95,7 @@ public struct HCIQoSSetup: HCICommandParameter { let delayVariationBytes = delayVariation.littleEndian.bytes - return Data([ + data += [ handleBytes.0, handleBytes.1, flags, @@ -118,7 +116,7 @@ public struct HCIQoSSetup: HCICommandParameter { delayVariationBytes.1, delayVariationBytes.2, delayVariationBytes.3 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIQoSSetupComplete.swift b/Sources/BluetoothHCI/HCIQoSSetupComplete.swift index a3deac6cb..5caa0129a 100644 --- a/Sources/BluetoothHCI/HCIQoSSetupComplete.swift +++ b/Sources/BluetoothHCI/HCIQoSSetupComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// QoS Setup Complete Event /// /// The QoS Setup Complete event is used to indicate the completion of the process of the Link Manager setting up QoS with the remote BR/EDR Control- ler specified by the Connection_Handle event parameter. The Connection_Handle will be a Connection_Handle for an ACL connection. diff --git a/Sources/BluetoothHCI/HCIReadClassOfDevice.swift b/Sources/BluetoothHCI/HCIReadClassOfDevice.swift index f765eb7ef..5ed2fdb18 100644 --- a/Sources/BluetoothHCI/HCIReadClassOfDevice.swift +++ b/Sources/BluetoothHCI/HCIReadClassOfDevice.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCIReadClockOffset.swift b/Sources/BluetoothHCI/HCIReadClockOffset.swift index ddb9f9077..17e8a9a29 100644 --- a/Sources/BluetoothHCI/HCIReadClockOffset.swift +++ b/Sources/BluetoothHCI/HCIReadClockOffset.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -48,10 +46,10 @@ public struct HCIReadClockOffset: HCICommandParameter { self.handle = handle } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = handle.littleEndian.bytes - return Data([handleBytes.0, handleBytes.1]) + data += [handleBytes.0, handleBytes.1] } } diff --git a/Sources/BluetoothHCI/HCIReadClockOffsetComplete.swift b/Sources/BluetoothHCI/HCIReadClockOffsetComplete.swift index f3c2c85ec..811b307de 100644 --- a/Sources/BluetoothHCI/HCIReadClockOffsetComplete.swift +++ b/Sources/BluetoothHCI/HCIReadClockOffsetComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Read Clock Offset Complete Event /// /// The Read Clock Offset Complete event is used to indicate the completion of the process of the Link Manager obtaining the Clock Offset information of the BR/EDR Controller specified by the Connection_Handle event parameter. The Connection_Handle will be a Connection_Handle for an ACL connection. diff --git a/Sources/BluetoothHCI/HCIReadConnectionAcceptTimeout.swift b/Sources/BluetoothHCI/HCIReadConnectionAcceptTimeout.swift index 9304c75df..912e9feca 100644 --- a/Sources/BluetoothHCI/HCIReadConnectionAcceptTimeout.swift +++ b/Sources/BluetoothHCI/HCIReadConnectionAcceptTimeout.swift @@ -8,8 +8,6 @@ // MARK: - Command -import Foundation - /// Read Connection Accept Timeout Command /// /// This command reads the value for the Connection Accept Timeout configuration parameter. diff --git a/Sources/BluetoothHCI/HCIReadDataBlockSize.swift b/Sources/BluetoothHCI/HCIReadDataBlockSize.swift index a68ad75be..356dc9131 100644 --- a/Sources/BluetoothHCI/HCIReadDataBlockSize.swift +++ b/Sources/BluetoothHCI/HCIReadDataBlockSize.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCIReadDeviceAddress.swift b/Sources/BluetoothHCI/HCIReadDeviceAddress.swift index 94ce571cf..2eb282d28 100644 --- a/Sources/BluetoothHCI/HCIReadDeviceAddress.swift +++ b/Sources/BluetoothHCI/HCIReadDeviceAddress.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCIReadLMPHandle.swift b/Sources/BluetoothHCI/HCIReadLMPHandle.swift index 8c3938303..d27af638f 100644 --- a/Sources/BluetoothHCI/HCIReadLMPHandle.swift +++ b/Sources/BluetoothHCI/HCIReadLMPHandle.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -49,11 +47,11 @@ public struct HCIReadLMPHandle: HCICommandParameter { self.handle = handle } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = handle.littleEndian.bytes - return Data([handleBytes.0, handleBytes.1]) + data += [handleBytes.0, handleBytes.1] } } diff --git a/Sources/BluetoothHCI/HCIReadLocalName.swift b/Sources/BluetoothHCI/HCIReadLocalName.swift index 3d5df6689..33d21a0b6 100644 --- a/Sources/BluetoothHCI/HCIReadLocalName.swift +++ b/Sources/BluetoothHCI/HCIReadLocalName.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCIReadLocalSupportedFeatures.swift b/Sources/BluetoothHCI/HCIReadLocalSupportedFeatures.swift index 4e22dbb98..3bc8f4da9 100644 --- a/Sources/BluetoothHCI/HCIReadLocalSupportedFeatures.swift +++ b/Sources/BluetoothHCI/HCIReadLocalSupportedFeatures.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCIReadLocalVersionInformation.swift b/Sources/BluetoothHCI/HCIReadLocalVersionInformation.swift index 535f3fb2b..d3391d532 100644 --- a/Sources/BluetoothHCI/HCIReadLocalVersionInformation.swift +++ b/Sources/BluetoothHCI/HCIReadLocalVersionInformation.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCIReadPageTimeout.swift b/Sources/BluetoothHCI/HCIReadPageTimeout.swift index 46876a5e7..739df8c60 100644 --- a/Sources/BluetoothHCI/HCIReadPageTimeout.swift +++ b/Sources/BluetoothHCI/HCIReadPageTimeout.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCIReadRemoteExtendedFeatures.swift b/Sources/BluetoothHCI/HCIReadRemoteExtendedFeatures.swift index 3cdec2aa9..ef5fc8932 100644 --- a/Sources/BluetoothHCI/HCIReadRemoteExtendedFeatures.swift +++ b/Sources/BluetoothHCI/HCIReadRemoteExtendedFeatures.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -52,10 +50,10 @@ public struct HCIReadRemoteExtendedFeatures: HCICommandParameter { self.pageNumber = pageNumber } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = handle.littleEndian.bytes - return Data([handleBytes.0, handleBytes.1, pageNumber]) + data += [handleBytes.0, handleBytes.1, pageNumber] } } diff --git a/Sources/BluetoothHCI/HCIReadRemoteExtendedFeaturesComplete.swift b/Sources/BluetoothHCI/HCIReadRemoteExtendedFeaturesComplete.swift index cbe953b3f..c87d31bb9 100644 --- a/Sources/BluetoothHCI/HCIReadRemoteExtendedFeaturesComplete.swift +++ b/Sources/BluetoothHCI/HCIReadRemoteExtendedFeaturesComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Read Remote Extended Features Complete Event /// /// The Read Remote Extended Features Complete event is used to indicate the completion of the process of the Link Manager obtaining the remote extended LMP features of the remote device specified by the Connection_Handle event parameter. The Connection_Handle will be a Connection_Handle for an ACL connection. The event parameters include a page of the remote devices extended LMP features. diff --git a/Sources/BluetoothHCI/HCIReadRemoteFeaturesComplete.swift b/Sources/BluetoothHCI/HCIReadRemoteFeaturesComplete.swift index 6f854dd9b..c8f6e0036 100644 --- a/Sources/BluetoothHCI/HCIReadRemoteFeaturesComplete.swift +++ b/Sources/BluetoothHCI/HCIReadRemoteFeaturesComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Read Remote Supported Features Complete Event /// /// The Read Remote Supported Features Complete event is used to indicate the completion of the process of the Link Manager obtaining the supported features of the remote BR/EDR Controller specified by the Connection_Handle event parameter. The Connection_Handle will be a Connection_Handle for an ACL connection. The event parameters include a list of LMP features diff --git a/Sources/BluetoothHCI/HCIReadRemoteSupportedFeatures.swift b/Sources/BluetoothHCI/HCIReadRemoteSupportedFeatures.swift index b57af8a48..c9c7e2447 100644 --- a/Sources/BluetoothHCI/HCIReadRemoteSupportedFeatures.swift +++ b/Sources/BluetoothHCI/HCIReadRemoteSupportedFeatures.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -48,10 +46,10 @@ public struct HCIReadRemoteSupportedFeatures: HCICommandParameter { self.handle = handle } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = handle.littleEndian.bytes - return Data([handleBytes.0, handleBytes.1]) + data += [handleBytes.0, handleBytes.1] } } diff --git a/Sources/BluetoothHCI/HCIReadRemoteVersionInformation.swift b/Sources/BluetoothHCI/HCIReadRemoteVersionInformation.swift index 5c4db8d2e..ce9bc42a5 100644 --- a/Sources/BluetoothHCI/HCIReadRemoteVersionInformation.swift +++ b/Sources/BluetoothHCI/HCIReadRemoteVersionInformation.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -47,10 +45,10 @@ public struct HCIReadRemoteVersionInformation: HCICommandParameter { self.handle = handle } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = handle.littleEndian.bytes - return Data([handleBytes.0, handleBytes.1]) + data += [handleBytes.0, handleBytes.1] } } diff --git a/Sources/BluetoothHCI/HCIReadRemoteVersionInformationComplete.swift b/Sources/BluetoothHCI/HCIReadRemoteVersionInformationComplete.swift index ad80d492a..94a9f090b 100644 --- a/Sources/BluetoothHCI/HCIReadRemoteVersionInformationComplete.swift +++ b/Sources/BluetoothHCI/HCIReadRemoteVersionInformationComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Read Remote Extended Features Complete Event /// /// The Read Remote Extended Features Complete event is used to indicate the completion of the process of the Link Manager obtaining the remote extended LMP features of the remote device specified by the Connection_Handle event parameter. The Connection_Handle will be a Connection_Handle for an ACL connection. The event parameters include a page of the remote devices extended LMP features. diff --git a/Sources/BluetoothHCI/HCIReadStoredLinkKey.swift b/Sources/BluetoothHCI/HCIReadStoredLinkKey.swift index 40531c945..c5fbe9ebc 100644 --- a/Sources/BluetoothHCI/HCIReadStoredLinkKey.swift +++ b/Sources/BluetoothHCI/HCIReadStoredLinkKey.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -49,11 +47,11 @@ public struct HCIReadStoredLinkKey: HCICommandParameter { self.readFlag = readFlag } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, @@ -61,7 +59,7 @@ public struct HCIReadStoredLinkKey: HCICommandParameter { addressBytes.4, addressBytes.5, readFlag.rawValue - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIRejectConnectionRequest.swift b/Sources/BluetoothHCI/HCIRejectConnectionRequest.swift index 89183fb2d..f852ebffe 100644 --- a/Sources/BluetoothHCI/HCIRejectConnectionRequest.swift +++ b/Sources/BluetoothHCI/HCIRejectConnectionRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -48,10 +46,10 @@ public struct HCIRejectConnectionRequest: HCICommandParameter { self.error = error } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes - return Data([addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5, error.rawValue]) + data += [addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5, error.rawValue] } } diff --git a/Sources/BluetoothHCI/HCIRemoteNameRequest.swift b/Sources/BluetoothHCI/HCIRemoteNameRequest.swift index ef7d67287..3bf2dd5e9 100644 --- a/Sources/BluetoothHCI/HCIRemoteNameRequest.swift +++ b/Sources/BluetoothHCI/HCIRemoteNameRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -91,13 +89,13 @@ public struct HCIRemoteNameRequest: HCICommandParameter { self.clockOffset = ClockOffset(rawValue: UInt16(littleEndian: UInt16(bytes: (data[8], data[9])))) } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes let clockOffsetBytes = clockOffset.rawValue.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, @@ -108,7 +106,7 @@ public struct HCIRemoteNameRequest: HCICommandParameter { reserved.rawValue, clockOffsetBytes.0, clockOffsetBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIRemoteNameRequestComplete.swift b/Sources/BluetoothHCI/HCIRemoteNameRequestComplete.swift index c38abaec2..b792ed1d4 100644 --- a/Sources/BluetoothHCI/HCIRemoteNameRequestComplete.swift +++ b/Sources/BluetoothHCI/HCIRemoteNameRequestComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// HCI Remote Name Request Complete Event @frozen public struct HCIRemoteNameRequestComplete: HCIEventParameter { diff --git a/Sources/BluetoothHCI/HCIReset.swift b/Sources/BluetoothHCI/HCIReset.swift index e794a72b8..ca6322569 100644 --- a/Sources/BluetoothHCI/HCIReset.swift +++ b/Sources/BluetoothHCI/HCIReset.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/HCISetConnectionEncryption.swift b/Sources/BluetoothHCI/HCISetConnectionEncryption.swift index fa51564fe..0a3129866 100644 --- a/Sources/BluetoothHCI/HCISetConnectionEncryption.swift +++ b/Sources/BluetoothHCI/HCISetConnectionEncryption.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -47,11 +45,11 @@ public struct HCISetConnectionEncryption: HCICommandParameter { self.encryption = encryption } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = handle.littleEndian.bytes - return Data([handleBytes.0, handleBytes.1, encryption.rawValue]) + data += [handleBytes.0, handleBytes.1, encryption.rawValue] } } diff --git a/Sources/BluetoothHCI/HCISetEventFilter.swift b/Sources/BluetoothHCI/HCISetEventFilter.swift index 20576cf97..ecb15bcff 100644 --- a/Sources/BluetoothHCI/HCISetEventFilter.swift +++ b/Sources/BluetoothHCI/HCISetEventFilter.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Command /// Set Event Filter Command @@ -49,7 +47,7 @@ public struct HCISetEventFilter: HCICommandParameter { /// public var filterType: FilterType // Filter_Type - public var data: Data { + public func append(to data: inout Data) { fatalError("\(#function) TODO") } diff --git a/Sources/BluetoothHCI/HCISimplePairingComplete.swift b/Sources/BluetoothHCI/HCISimplePairingComplete.swift index 3109f380f..d4d02ea06 100644 --- a/Sources/BluetoothHCI/HCISimplePairingComplete.swift +++ b/Sources/BluetoothHCI/HCISimplePairingComplete.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// The Simple Pairing Complete event is used to indicate that the simple pairing process has completed. A Host that is displaying a numeric value can use this event to change its UI. /// /// When the LMP simple pairing sequences fail for any reason, the Simple Pairing Complete event shall be sent to the Host. When Simple Pairing Complete event is sent in response to the IO capability exchange failing, the Status parameter shall be set to the error code received from the remote device. Oth- erwise, the Status shall be set to the error code “Authentication Failure.” diff --git a/Sources/BluetoothHCI/HCIUserConfirmationRequest.swift b/Sources/BluetoothHCI/HCIUserConfirmationRequest.swift index d8c0c9dec..7a048d903 100644 --- a/Sources/BluetoothHCI/HCIUserConfirmationRequest.swift +++ b/Sources/BluetoothHCI/HCIUserConfirmationRequest.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// The User Confirmation Request event is used to indicate that user confirmation of a numeric value is required. The Host shall reply with either the User_Confirmation_Request_Reply or the User_Confirmation_Request_Negative_Reply command. If the Host has output capability (DisplayYesNo or KeyboardOnly), it shall display the Numeric_Value until the Simple Pairing Complete event is received. It shall reply based on the yes/no response from the user. If the Host has no input and no output it shall reply with the User Confirmation Request Reply command. When the Controller generates a User Confirmation Request event, in order for the local Link Manager to respond to the request from the remote Link Manager, the local Host must respond with either a User_Confirmation_Request_Reply or a User_Confirmation_Request_Negative_Reply command before the remote Link Manager detects LMP response timeout. @frozen public struct HCIUserConfirmationRequest: HCIEventParameter { diff --git a/Sources/BluetoothHCI/HCIUserConfirmationRequestReply.swift b/Sources/BluetoothHCI/HCIUserConfirmationRequestReply.swift index 9690e26e8..8c56052e5 100644 --- a/Sources/BluetoothHCI/HCIUserConfirmationRequestReply.swift +++ b/Sources/BluetoothHCI/HCIUserConfirmationRequestReply.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -41,18 +39,18 @@ public struct HCIUserConfirmationRequestReply: HCICommandParameter { self.address = address } - public var data: Data { + public func append(to data: inout Data) { let addressBytes = address.littleEndian.bytes - return Data([ + data += [ addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIWriteClassOfDevice.swift b/Sources/BluetoothHCI/HCIWriteClassOfDevice.swift index 0a8671717..b6c458879 100644 --- a/Sources/BluetoothHCI/HCIWriteClassOfDevice.swift +++ b/Sources/BluetoothHCI/HCIWriteClassOfDevice.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -43,8 +41,8 @@ public struct HCIWriteClassOfDevice: HCICommandParameter { self.classOfDevice = classOfDevice } - public var data: Data { + public func append(to data: inout Data) { - return Data(classOfDevice) + data += classOfDevice } } diff --git a/Sources/BluetoothHCI/HCIWriteConnectionAcceptTimeout.swift b/Sources/BluetoothHCI/HCIWriteConnectionAcceptTimeout.swift index 2c038cefc..dc09469aa 100644 --- a/Sources/BluetoothHCI/HCIWriteConnectionAcceptTimeout.swift +++ b/Sources/BluetoothHCI/HCIWriteConnectionAcceptTimeout.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Write Connection Accept Timeout Command /// /// This command writes the value for the Connection Accept Timeout configuration parameter. @@ -23,10 +21,10 @@ public struct HCIWriteConnectionAcceptTimeout: HCICommandParameter { self.timeout = timeout } - public var data: Data { + public func append(to data: inout Data) { let timeoutBytes = timeout.rawValue.littleEndian.bytes - return Data([timeoutBytes.0, timeoutBytes.1]) + data += [timeoutBytes.0, timeoutBytes.1] } } diff --git a/Sources/BluetoothHCI/HCIWriteLinkPolicySettings.swift b/Sources/BluetoothHCI/HCIWriteLinkPolicySettings.swift index f4680d09d..9810a4ba9 100644 --- a/Sources/BluetoothHCI/HCIWriteLinkPolicySettings.swift +++ b/Sources/BluetoothHCI/HCIWriteLinkPolicySettings.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -53,17 +51,17 @@ public struct HCIWriteLinkPolicySettings: HCICommandParameter { self.settings = settings } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = connectionHandle.littleEndian.bytes let settingsBytes = settings.rawValue.littleEndian.bytes - return Data([ + data += [ handleBytes.0, handleBytes.1, settingsBytes.0, settingsBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIWriteLinkSupervisionTimeout.swift b/Sources/BluetoothHCI/HCIWriteLinkSupervisionTimeout.swift index 08056313e..9dd6341c6 100644 --- a/Sources/BluetoothHCI/HCIWriteLinkSupervisionTimeout.swift +++ b/Sources/BluetoothHCI/HCIWriteLinkSupervisionTimeout.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -57,18 +55,18 @@ public struct HCIWriteLinkSupervisionTimeout: HCICommandParameter { self.linkSupervisionTimeout = linkSupervisionTimeout } - public var data: Data { + public func append(to data: inout Data) { let handleBytes = handle.littleEndian.bytes let timeoutBytes = linkSupervisionTimeout.rawValue.littleEndian.bytes - return Data([ + data += [ handleBytes.0, handleBytes.1, timeoutBytes.0, timeoutBytes.1 - ]) + ] } } diff --git a/Sources/BluetoothHCI/HCIWriteLocalName.swift b/Sources/BluetoothHCI/HCIWriteLocalName.swift index 36ad293b2..a64e31497 100644 --- a/Sources/BluetoothHCI/HCIWriteLocalName.swift +++ b/Sources/BluetoothHCI/HCIWriteLocalName.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -44,19 +42,18 @@ public struct HCIWriteLocalName: HCICommandParameter { self.localName = localName } - public var data: Data { + public func append(to data: inout Data) { let maxLength = Self.length + let utf8 = localName.utf8 - var data = Data(localName.utf8) + assert(utf8.count <= maxLength) - assert(data.count <= maxLength) + data += utf8 - if data.count < maxLength { + if utf8.count < maxLength { - data += Data(repeating: 0x00, count: maxLength - data.count) + data += repeatElement(0x00, count: maxLength - utf8.count) } - - return data } } diff --git a/Sources/BluetoothHCI/HCIWritePageScanActivity.swift b/Sources/BluetoothHCI/HCIWritePageScanActivity.swift index b2875342c..d2c78346c 100644 --- a/Sources/BluetoothHCI/HCIWritePageScanActivity.swift +++ b/Sources/BluetoothHCI/HCIWritePageScanActivity.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -49,13 +47,13 @@ public struct HCIWritePageScanActivity: HCICommandParameter { self.scanWindow = scanWindow } - public var data: Data { + public func append(to data: inout Data) { let intervalBytes = scanInterval.rawValue.littleEndian.bytes let windowBytes = scanWindow.rawValue.littleEndian.bytes - return Data([intervalBytes.0, intervalBytes.1, windowBytes.0, windowBytes.1]) + data += [intervalBytes.0, intervalBytes.1, windowBytes.0, windowBytes.1] } } diff --git a/Sources/BluetoothHCI/HCIWritePageScanType.swift b/Sources/BluetoothHCI/HCIWritePageScanType.swift index bd93e71a1..90c5b4e77 100644 --- a/Sources/BluetoothHCI/HCIWritePageScanType.swift +++ b/Sources/BluetoothHCI/HCIWritePageScanType.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -43,9 +41,9 @@ public struct HCIWritePageScanType: HCICommandParameter { self.pageScanType = pageScanType } - public var data: Data { + public func append(to data: inout Data) { - return Data([pageScanType.rawValue]) + data += [pageScanType.rawValue] } } diff --git a/Sources/BluetoothHCI/HCIWritePageTimeout.swift b/Sources/BluetoothHCI/HCIWritePageTimeout.swift index 648aa6535..b5f9c1d1a 100644 --- a/Sources/BluetoothHCI/HCIWritePageTimeout.swift +++ b/Sources/BluetoothHCI/HCIWritePageTimeout.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -45,10 +43,10 @@ public struct HCIWritePageTimeout: HCICommandParameter { self.pageTimeout = pageTimeout } - public var data: Data { + public func append(to data: inout Data) { let pageTimeoutBytes = pageTimeout.rawValue.littleEndian.bytes - return Data([pageTimeoutBytes.0, pageTimeoutBytes.1]) + data += [pageTimeoutBytes.0, pageTimeoutBytes.1] } } diff --git a/Sources/BluetoothHCI/HCIWriteScanEnable.swift b/Sources/BluetoothHCI/HCIWriteScanEnable.swift index d2cc1dc21..85ec224f6 100644 --- a/Sources/BluetoothHCI/HCIWriteScanEnable.swift +++ b/Sources/BluetoothHCI/HCIWriteScanEnable.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - Method public extension BluetoothHostControllerInterface { @@ -43,9 +41,9 @@ public struct HCIWriteScanEnable: HCICommandParameter { self.scanEnable = scanEnable } - public var data: Data { + public func append(to data: inout Data) { - return Data([scanEnable.rawValue]) + data += [scanEnable.rawValue] } } diff --git a/Sources/BluetoothHCI/InformationalCommand.swift b/Sources/BluetoothHCI/InformationalCommand.swift index 1f7ed8a4a..f47f6e4c6 100644 --- a/Sources/BluetoothHCI/InformationalCommand.swift +++ b/Sources/BluetoothHCI/InformationalCommand.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - @frozen public enum InformationalCommand: UInt16, HCICommand { diff --git a/Sources/BluetoothHCI/LMPFeature.swift b/Sources/BluetoothHCI/LMPFeature.swift index a671715af..bdcb2732a 100644 --- a/Sources/BluetoothHCI/LMPFeature.swift +++ b/Sources/BluetoothHCI/LMPFeature.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// Bluetooth LMP Feature @frozen public enum LMPFeature: UInt64, BitMaskOption { diff --git a/Sources/BluetoothHCI/LowEnergyAdvertising.swift b/Sources/BluetoothHCI/LowEnergyAdvertising.swift index d558b14a0..14d855c65 100644 --- a/Sources/BluetoothHCI/LowEnergyAdvertising.swift +++ b/Sources/BluetoothHCI/LowEnergyAdvertising.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - // MARK: - BluetoothHostControllerInterface public extension BluetoothHostControllerInterface { diff --git a/Sources/BluetoothHCI/PacketType.swift b/Sources/BluetoothHCI/PacketType.swift index 001103db1..669e7837f 100644 --- a/Sources/BluetoothHCI/PacketType.swift +++ b/Sources/BluetoothHCI/PacketType.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - /// The packets used on the piconet are related to the logical transports they are used in. Three logical transports with distinct packet types are defined (see Section 4 on page 97): the SCO logical transport, the eSCO logical transport, and the ACL logical transport. For each of these logical transports, 15 different packet types can be defined. /// /// To indicate the different packets on a logical transport, the 4-bit TYPE code is used. The packet types are divided into four segments. The first segment is reserved for control packets. All control packets occupy a single time slot. The sec- ond segment is reserved for packets occupying a single time slot. The third seg- ment is reserved for packets occupying three time slots. The fourth segment is reserved for packets occupying five time slots. The slot occupancy is reflected in the segmentation and can directly be derived from the type code. Table 6.2 on page 118 summarizes the packets defined for the SCO, eSCO, and ACL logical transport types. diff --git a/Sources/BluetoothHCI/VendorCommand.swift b/Sources/BluetoothHCI/VendorCommand.swift index ce2edece4..7e0a8d780 100644 --- a/Sources/BluetoothHCI/VendorCommand.swift +++ b/Sources/BluetoothHCI/VendorCommand.swift @@ -6,8 +6,6 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation - @frozen public struct VendorCommand: HCICommand, Equatable, Hashable { diff --git a/Sources/BluetoothHCI/iBeacon.swift b/Sources/BluetoothHCI/iBeacon.swift index e217fe0ef..1a13f8e8f 100644 --- a/Sources/BluetoothHCI/iBeacon.swift +++ b/Sources/BluetoothHCI/iBeacon.swift @@ -5,7 +5,6 @@ // Created by Alsey Coleman Miller on 10/22/20. // -import Foundation import Bluetooth import BluetoothGAP diff --git a/Tests/BluetoothTests/HostController.swift b/Tests/BluetoothTests/HostController.swift index 529df127b..a69d070f8 100644 --- a/Tests/BluetoothTests/HostController.swift +++ b/Tests/BluetoothTests/HostController.swift @@ -365,4 +365,18 @@ extension Array { return first } } + +internal extension HCICommandParameter { + + var data: Data { + Data(self) + } +} + +internal extension HCIPacketHeader { + + var data: Data { + Data(self) + } +} #endif