-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
290800c
commit 533f4c2
Showing
9 changed files
with
169 additions
and
47 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 was deleted.
Oops, something went wrong.
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,44 @@ | ||
// | ||
// iBeaconTests.swift | ||
// BluetoothLinux | ||
// | ||
// Created by Alsey Coleman Miller on 4/29/16. | ||
// Copyright © 2016 PureSwift. All rights reserved. | ||
// | ||
|
||
#if os(OSX) | ||
|
||
import XCTest | ||
import SwiftFoundation | ||
import Bluetooth | ||
@testable import BluetoothLinux | ||
|
||
final class iBeaconTests: XCTestCase { | ||
|
||
func testAdvertisementData() { | ||
|
||
let identifier = UUID() | ||
|
||
let major: UInt16 = 0 | ||
|
||
let minor: UInt16 = 1 | ||
|
||
let rssi: Int8 = -59 | ||
|
||
var adverstisementDataParameter = beaconAdvertisementData(identifier.toData().byteValue, CInt(major), CInt(minor), CInt(rssi)) | ||
|
||
var parameterBytes = [UInt8].init(repeating: 0, count: Int(adverstisementDataParameter.length)) | ||
|
||
withUnsafePointer(&adverstisementDataParameter.data) { memcpy(¶meterBytes, UnsafePointer<Void>($0), parameterBytes.count) } | ||
|
||
var advertisingDataCommand = LowEnergyCommand.SetAdvertisingDataParameter() | ||
|
||
SetBeaconData(UUID: identifier, major: major, minor: minor, RSSI: UInt8(bitPattern: rssi), parameter: &advertisingDataCommand) | ||
|
||
XCTAssert(adverstisementDataParameter.length == advertisingDataCommand.length, "Invalid Length: \(adverstisementDataParameter.length) == \(advertisingDataCommand.length)") | ||
|
||
//XCTAssert(memcmp(<#T##UnsafePointer<Void>!#>, <#T##UnsafePointer<Void>!#>, <#T##Int#>)) | ||
} | ||
} | ||
|
||
#endif |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
|
||
#import "MathTestsHelper.h" | ||
#import "IOCTLTestsHelper.h" | ||
#import "iBeaconTestsHelper.h" |
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,103 @@ | ||
// | ||
// iBeaconTestsHelper.h | ||
// BluetoothLinux | ||
// | ||
// Created by Alsey Coleman Miller on 4/29/16. | ||
// Copyright © 2016 PureSwift. All rights reserved. | ||
// | ||
|
||
#define EIR_FLAGS 0X01 | ||
#define EIR_NAME_SHORT 0x08 | ||
#define EIR_NAME_COMPLETE 0x09 | ||
#define EIR_MANUFACTURE_SPECIFIC 0xFF | ||
|
||
/* Byte order conversions */ | ||
#if __BYTE_ORDER == __LITTLE_ENDIAN | ||
#define htobs(d) (d) | ||
#define htobl(d) (d) | ||
#define htobll(d) (d) | ||
#define btohs(d) (d) | ||
#define btohl(d) (d) | ||
#define btohll(d) (d) | ||
#elif __BYTE_ORDER == __BIG_ENDIAN | ||
#define htobs(d) bswap_16(d) | ||
#define htobl(d) bswap_32(d) | ||
#define htobll(d) bswap_64(d) | ||
#define btohs(d) bswap_16(d) | ||
#define btohl(d) bswap_32(d) | ||
#define btohll(d) bswap_64(d) | ||
#else | ||
#error "Unknown byte order" | ||
#endif | ||
|
||
typedef struct { | ||
uint8_t length; | ||
uint8_t data[31]; | ||
} __attribute__ ((packed)) le_set_advertising_data_cp; | ||
|
||
static inline unsigned int twoc(int in, int t) | ||
{ | ||
return (in < 0) ? (in + (2 << (t-1))) : in; | ||
} | ||
|
||
static inline unsigned int *uuid_str_to_data(char *uuid) | ||
{ | ||
char conv[] = "0123456789ABCDEF"; | ||
int len = strlen(uuid); | ||
unsigned int *data = (unsigned int*)malloc(sizeof(unsigned int) * len); | ||
unsigned int *dp = data; | ||
char *cu = uuid; | ||
|
||
for(; cu<uuid+len; dp++,cu+=2) | ||
{ | ||
*dp = ((strchr(conv, toupper(*cu)) - conv) * 16) | ||
+ (strchr(conv, toupper(*(cu+1))) - conv); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
/** Generate iBeacon data from https://github.com/carsonmcdonald/bluez-ibeacon */ | ||
static inline le_set_advertising_data_cp beaconAdvertisementData(const unsigned char *uuid, int major_number, int minor_number, int rssi_value) | ||
{ | ||
|
||
le_set_advertising_data_cp adv_data_cp; | ||
memset(&adv_data_cp, 0, sizeof(adv_data_cp)); | ||
|
||
uint8_t segment_length = 1; | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(EIR_FLAGS); segment_length++; | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(0x1A); segment_length++; | ||
adv_data_cp.data[adv_data_cp.length] = htobs(segment_length - 1); | ||
|
||
adv_data_cp.length += segment_length; | ||
|
||
segment_length = 1; | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(EIR_MANUFACTURE_SPECIFIC); segment_length++; | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(0x4C); segment_length++; | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(0x00); segment_length++; | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(0x02); segment_length++; | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(0x15); segment_length++; | ||
|
||
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++; | ||
} | ||
|
||
// Major number | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(major_number >> 8 & 0x00FF); segment_length++; | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(major_number & 0x00FF); segment_length++; | ||
|
||
// Minor number | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(minor_number >> 8 & 0x00FF); segment_length++; | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(minor_number & 0x00FF); segment_length++; | ||
|
||
// RSSI calibration | ||
adv_data_cp.data[adv_data_cp.length + segment_length] = htobs(twoc(rssi_value, 8)); segment_length++; | ||
|
||
adv_data_cp.data[adv_data_cp.length] = htobs(segment_length - 1); | ||
|
||
adv_data_cp.length += segment_length; | ||
|
||
return adv_data_cp; | ||
} |