-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added LECreateConnection command line tool
- Loading branch information
1 parent
3c80478
commit 427661a
Showing
8 changed files
with
148 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// LEScanTest.swift | ||
// BluetoothLinux | ||
// | ||
// Created by Alsey Coleman Miller on 11/29/17. | ||
// Copyright © 2017 PureSwift. All rights reserved. | ||
// | ||
|
||
#if os(Linux) | ||
import BluetoothLinux | ||
import Glibc | ||
#elseif os(macOS) || os(iOS) | ||
import Darwin.C | ||
#endif | ||
|
||
import Foundation | ||
import Bluetooth | ||
|
||
/// Tests the Scanning functionality | ||
func LECreateConnection(adapter: Adapter, peerAddress: Address, duration: TimeInterval) { | ||
|
||
typealias ConnectionInterval = LowEnergyCommand.CreateConnectionParameter.ConnectionInterval | ||
|
||
let connectionParameters = LowEnergyCommand.CreateConnectionParameter | ||
.init(scanInterval: .min, // 0x0004 | ||
scanWindow: .min, // 0x0004 | ||
initiatorFilterPolicy: .peerAddress, | ||
peerAddressType: .public, | ||
peerAddress: peerAddress, | ||
ownAddressType: .public, | ||
connectionInterval: ConnectionInterval(rawValue: (0x000F ... 0x000F))!, | ||
connectionLatency: .zero, | ||
supervisionTimeout: .max, | ||
connectionLength: .init(rawValue: 0x0001 ... 0x0001)) | ||
|
||
do { | ||
|
||
let handle = try adapter.lowEnergyCreateConnection(parameters: connectionParameters, commandTimeout: 25000) | ||
|
||
print("Connection handle \(handle)") | ||
|
||
|
||
} | ||
|
||
catch { Error("Could not scan: \(error)") } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// main.swift | ||
// BluetoothLinux | ||
// | ||
// Created by Alsey Coleman Miller on 12/6/15. | ||
// Copyright © 2015 PureSwift. All rights reserved. | ||
// | ||
|
||
#if os(Linux) | ||
import BluetoothLinux | ||
import Glibc | ||
#elseif os(OSX) || os(iOS) | ||
import Darwin.C | ||
#endif | ||
|
||
import Foundation | ||
|
||
func Error(_ text: String) -> Never { | ||
|
||
print(text) | ||
exit(1) | ||
} | ||
|
||
// get Bluetooth device | ||
|
||
let adapter: Adapter | ||
|
||
do { adapter = try Adapter() } | ||
|
||
catch { Error("Error: \(error)") } | ||
|
||
print("Found Bluetooth adapter with device ID: \(adapter.identifier)") | ||
|
||
print("Address: \(adapter.address!)") | ||
|
||
/// Perform Test | ||
LECreateConnection(adapter: adapter, duration: 10) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters