Skip to content

Commit

Permalink
little endian fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Apr 5, 2016
1 parent 4acbf99 commit be5c7bb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "PureSwift/JSON-C" "e8e38025563d43e425536200002ad13c3f35a98b"
github "PureSwift/SwiftFoundation" "bca3dcff319698edecc8e5d5736ffafa0c1b06a1"
github "PureSwift/Bluetooth" "e723b53ae126a63fa2f54f2ac4d2f93a56fe2061"
github "PureSwift/SwiftFoundation" "a2f55d51c226f64e13299cf1395c65371e2356dc"
github "PureSwift/Bluetooth" "5dae61458de73f32d7fe4c421542128019546411"
7 changes: 3 additions & 4 deletions Sources/BluetoothLinux/GATTDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public struct GATTDatabase {
return attributes
}


// MARK: - Methods

public mutating func add(service: Service) -> Int {
Expand Down Expand Up @@ -168,9 +167,9 @@ public extension GATTDatabase {
/// ATT Attribute Value
private var littleEndian: [UInt8] {

let handleBytes = serviceHandle.littleEndianBytes
let handleBytes = serviceHandle.littleEndian.bytes

let endGroupBytes = endGroupHandle.littleEndianBytes
let endGroupBytes = endGroupHandle.littleEndian.bytes

return [handleBytes.0, handleBytes.1, endGroupBytes.0, endGroupBytes.1] + serviceUUID.littleEndian
}
Expand Down Expand Up @@ -222,7 +221,7 @@ public extension GATTDatabase {
let declarationAttribute: Attribute = {

let propertiesMask = characteristic.properties.optionsBitmask()
let valueHandleBytes = (handle + 1).littleEndianBytes
let valueHandleBytes = (handle + 1).littleEndian.bytes
let value = [propertiesMask, valueHandleBytes.0, valueHandleBytes.1] + characteristic.UUID.littleEndian

return Attribute(handle: currentHandle, UUID: GATT.UUID.Characteristic.toUUID(), value: Data(byteValue: value), permissions: [.Read])
Expand Down
4 changes: 2 additions & 2 deletions Sources/BluetoothLinux/HCI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ internal struct HCICommandHeader: HCIPacketHeader {
guard byteValue.count == HCICommandHeader.length
else { return nil }

self.opcode = UInt16(littleEndian: (byteValue[0], byteValue[1]))
self.opcode = UInt16(bytes: (byteValue[0], byteValue[1])).littleEndian
self.parameterLength = byteValue[2]
}

var byteValue: [UInt8] {

let opcodeBytes = opcode.littleEndianBytes
let opcodeBytes = opcode.littleEndian.bytes

return [opcodeBytes.0, opcodeBytes.1, parameterLength]
}
Expand Down
37 changes: 20 additions & 17 deletions Sources/BluetoothLinux/iBeacon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,31 @@ private func SetBeaconData(UUID: SwiftFoundation.UUID, mayor: UInt16, minor: UIn
parameter.data.8 = 0x15 // length: 16 byte UUID, 2 bytes major & minor, 1 byte RSSI

// set UUID bytes
parameter.data.9 = UUID.byteValue.0
parameter.data.10 = UUID.byteValue.1
parameter.data.12 = UUID.byteValue.2
parameter.data.13 = UUID.byteValue.3
parameter.data.14 = UUID.byteValue.4
parameter.data.15 = UUID.byteValue.5
parameter.data.16 = UUID.byteValue.6
parameter.data.17 = UUID.byteValue.7
parameter.data.18 = UUID.byteValue.8
parameter.data.19 = UUID.byteValue.9
parameter.data.20 = UUID.byteValue.10
parameter.data.21 = UUID.byteValue.11
parameter.data.22 = UUID.byteValue.12
parameter.data.23 = UUID.byteValue.13
parameter.data.24 = UUID.byteValue.14

let mayorBytes = mayor.littleEndianBytes
let littleUUIDBytes = isBigEndian ? UUID.toData().byteValue.reverse() : UUID.toData().byteValue

parameter.data.9 = littleUUIDBytes[0]
parameter.data.10 = littleUUIDBytes[1]
parameter.data.12 = littleUUIDBytes[2]
parameter.data.13 = littleUUIDBytes[3]
parameter.data.14 = littleUUIDBytes[4]
parameter.data.15 = littleUUIDBytes[5]
parameter.data.16 = littleUUIDBytes[6]
parameter.data.17 = littleUUIDBytes[7]
parameter.data.18 = littleUUIDBytes[8]
parameter.data.19 = littleUUIDBytes[9]
parameter.data.20 = littleUUIDBytes[10]
parameter.data.21 = littleUUIDBytes[11]
parameter.data.22 = littleUUIDBytes[12]
parameter.data.23 = littleUUIDBytes[13]
parameter.data.24 = littleUUIDBytes[14]

let mayorBytes = mayor.littleEndian.bytes

parameter.data.25 = mayorBytes.0
parameter.data.26 = mayorBytes.1

let minorBytes = minor.littleEndianBytes
let minorBytes = minor.littleEndian.bytes

parameter.data.27 = minorBytes.0
parameter.data.28 = minorBytes.1
Expand Down

0 comments on commit be5c7bb

Please sign in to comment.