Skip to content

Commit

Permalink
fixed iBeacon functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Apr 30, 2016
1 parent 533f4c2 commit a042fb4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
41 changes: 21 additions & 20 deletions Sources/BluetoothLinux/iBeacon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,34 @@ internal func SetBeaconData(UUID: SwiftFoundation.UUID, major: UInt16, minor: UI

// set UUID bytes

let littleUUIDBytes = isBigEndian ? UUID.toData().byteValue : UUID.toData().byteValue.reversed()
let littleUUIDBytes = isBigEndian ? UUID.toData().byteValue.reversed() : 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]
parameter.data.11 = littleUUIDBytes[2]
parameter.data.12 = littleUUIDBytes[3]
parameter.data.13 = littleUUIDBytes[4]
parameter.data.14 = littleUUIDBytes[5]
parameter.data.15 = littleUUIDBytes[6]
parameter.data.16 = littleUUIDBytes[7]
parameter.data.17 = littleUUIDBytes[8]
parameter.data.18 = littleUUIDBytes[9]
parameter.data.19 = littleUUIDBytes[10]
parameter.data.20 = littleUUIDBytes[11]
parameter.data.21 = littleUUIDBytes[12]
parameter.data.22 = littleUUIDBytes[13]
parameter.data.23 = littleUUIDBytes[14]
parameter.data.24 = littleUUIDBytes[15]

let majorBytes = major.littleEndian.bytes
let majorBytes = major.bytes

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

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

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

parameter.data.29 = RSSI
}
Expand Down
11 changes: 7 additions & 4 deletions Sources/UnitTests/iBeaconTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

let identifier = UUID()

let major: UInt16 = 0
let major: UInt16 = 1

let minor: UInt16 = 1

let rssi: Int8 = -59
let rssi: Int8 = -29

var adverstisementDataParameter = beaconAdvertisementData(identifier.toData().byteValue, CInt(major), CInt(minor), CInt(rssi))
var adverstisementDataParameter = beaconAdvertisementData(identifier.toData().byteValue, CInt(major).littleEndian, CInt(minor).littleEndian, CInt(rssi).littleEndian)

var parameterBytes = [UInt8].init(repeating: 0, count: Int(adverstisementDataParameter.length))

Expand All @@ -37,7 +37,10 @@

XCTAssert(adverstisementDataParameter.length == advertisingDataCommand.length, "Invalid Length: \(adverstisementDataParameter.length) == \(advertisingDataCommand.length)")

//XCTAssert(memcmp(<#T##UnsafePointer<Void>!#>, <#T##UnsafePointer<Void>!#>, <#T##Int#>))
let dataPointer1 = withUnsafePointer(&adverstisementDataParameter.data) { return UnsafePointer<Void>($0) }
let dataPointer2 = withUnsafePointer(&advertisingDataCommand.data) { return UnsafePointer<Void>($0) }

XCTAssert(memcmp(dataPointer1, dataPointer2, Int(advertisingDataCommand.length)) == 0, "Invalid generated data: \n\(adverstisementDataParameter.data)\n == \n\(advertisingDataCommand.data))")
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/iBeaconTest/iBeaconTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func iBeaconTest(adapter: Adapter, timeout: Int) {

print("Enabling iBeacon \(iBeaconUUID) for \(timeout) seconds")

do { try adapter.enableBeacon(UUID: iBeaconUUID, mayor: 1, minor: 1, RSSI: -59) }
do { try adapter.enableBeacon(UUID: iBeaconUUID, mayor: 1, minor: 1, RSSI: -29) }

catch { Error("Error enabling iBeacon: \(error)") }

Expand Down
2 changes: 1 addition & 1 deletion Xcode/BluetoothLinuxTests/iBeaconTestsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static inline le_set_advertising_data_cp beaconAdvertisementData(const unsigned
int i;
for(i = 0; i < 16; i++)
{
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs((unsigned char)uuid[i]); segment_length++;
adv_data_cp.data[adv_data_cp.length + segment_length] = (unsigned char)uuid[i]; segment_length++;
}

// Major number
Expand Down

0 comments on commit a042fb4

Please sign in to comment.