<commit_before>//
//  iBeacon.swift
//  BlueZ
//
//  Created by <NAME> on 1/2/16.
//  Copyright © 2016 PureSwift. All rights reserved.
//

#if os(Linux)
    import CBlueZ
    import Glibc
#elseif os(OSX) || os(iOS)
    import Darwin.C
#endif

import SwiftFoundation

public extension Bluetooth {
    
    /// 31 Byte String
    public typealias LowEnergyAdvertisingData = (Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte)
}

public extension BluetoothAdapter {
    
    /// Enable iBeacon functionality.
    func enableBeacon(UUID: SwiftFoundation.UUID = UUID(), mayor: UInt16, minor: UInt16, RSSI: Byte, interval: Int = 100, commandTimeout: Int = 1000) throws {
        
        assert(interval <= Int(UInt16.max), "Interval can only be 2 bytes long")
        
        // set advertising parameters
        var advertisingParameters = le_set_advertising_parameters_cp()
        memset(&advertisingParameters, 0, sizeof(le_set_advertising_parameters_cp))
        
        advertisingParameters.max_interval = UInt16(interval).littleEndian
        advertisingParameters.min_interval = UInt16(interval).littleEndian
        advertisingParameters.advtype = 3  // advertising non-connectable
        advertisingParameters.chan_map = 7 // // all three advertising channels
        
        try self.deviceRequest(advertisingParameters, timeout: commandTimeout)
        
        // start advertising
        var enableAdvertise = le_set_advertise_enable_cp()
        memset(&enableAdvertise, 0, sizeof(le_set_advertise_enable_cp.self))
        
        enableAdvertise.enable = 0x01 // true
        
        try self.deviceRequest(enableAdvertise, timeout: commandTimeout)
        
        // set iBeacon data
        var advertisingDataCommand = le_set_advertising_data_cp()
        memset(&advertisingDataCommand, 0, sizeof(le_set_advertising_data_cp))
        
        let beaconData = GenerateBeaconData(UUID, mayor: mayor, minor: minor, RSSI: RSSI)<commit_msg>advertise as connectable<commit_after>//
//  iBeacon.swift
//  BlueZ
//
//  Created by <NAME> on 1/2/16.
//  Copyright © 2016 PureSwift. All rights reserved.
//

#if os(Linux)
    import CBlueZ
    import Glibc
#elseif os(OSX) || os(iOS)
    import Darwin.C
#endif

import SwiftFoundation

public extension Bluetooth {
    
    /// 31 Byte String
    public typealias LowEnergyAdvertisingData = (Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte, Byte)
}

public extension BluetoothAdapter {
    
    /// Enable iBeacon functionality.
    func enableBeacon(UUID: SwiftFoundation.UUID = UUID(), mayor: UInt16, minor: UInt16, RSSI: Byte, interval: Int = 100, commandTimeout: Int = 1000) throws {
        
        assert(interval <= Int(UInt16.max), "Interval can only be 2 bytes long")
        
        // set advertising parameters
        var advertisingParameters = le_set_advertising_parameters_cp()
        memset(&advertisingParameters, 0, sizeof(le_set_advertising_parameters_cp))
        
        advertisingParameters.max_interval = UInt16(interval).littleEndian
        advertisingParameters.min_interval = UInt16(interval).littleEndian
        //advertisingParameters.advtype = 3  // advertising non-connectable
        advertisingParameters.chan_map = 7 // // all three advertising channels
        
        try self.deviceRequest(advertisingParameters, timeout: commandTimeout)
        
        // start advertising
        var enableAdvertise = le_set_advertise_enable_cp()
        memset(&enableAdvertise, 0, sizeof(le_set_advertise_enable_cp.self))
        
        enableAdvertise.enable = 0x01 // true
        
        try self.deviceRequest(enableAdvertise, timeout: commandTimeout)
        
        // set iBeacon data
        var advertisingDataCommand = le_set_advertising_data_cp()
        memset(&advertisingDataCommand, 0, sizeof(le_set_advertising_data_cp))
        
        let beaconData = GenerateBeaconData(UUID, mayor: mayor, minor: minor, RSSI: RSSI)
{'fraction_non_alphanumeric': 0.09179548156956005, 'fraction_numerical': 0.017122473246135552, 'mean_word_length': 3.017191977077364, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6116470', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1207, 'n_words': 323}