Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Sep 11, 2019
2 parents e8f560d + a485ba4 commit 3800897
Show file tree
Hide file tree
Showing 8 changed files with 554 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sdk-xyobleinterface-swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'sdk-xyobleinterface-swift'
s.version = '3.0.4'
s.version = '3.0.5'
s.summary = 'A short description of sdk-xyobleinterface-swift'
s.swift_version = '5.0'
# This description is used to generate tags and improve search results.
Expand All @@ -35,6 +35,6 @@ XYO Ble Interface

s.dependency 'sdk-objectmodel-swift', '~> 3.0'
s.dependency 'sdk-core-swift', '~> 3.0.1'
s.dependency 'XyBleSdk', '~> 3.0.1'
s.dependency 'XyBleSdk', '~> 3.0.3'

end
2 changes: 1 addition & 1 deletion sdk-xyobleinterface-swift/XyoBluetoothDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ open class XyoBluetoothDevice: XYBluetoothDeviceBase, XYBluetoothDeviceNotifyDel

inputStream.removePacket()

print("READ ENTIRE \(latestPacket?.toHexString())")
print("READ ENTIRE \(latestPacket?.toHexString() ?? "--")")
return latestPacket
}

Expand Down
185 changes: 185 additions & 0 deletions sdk-xyobleinterface-swift/devices/androidX/XyoAndroidXDevice.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
//
// XyoAndroidXDevice.swift
// sdk-xyobleinterface-swift
//
// Created by Carter Harrison on 4/9/19.
//

import Foundation
import sdk_objectmodel_swift
import XyBleSdk
import CoreBluetooth

public enum XyoAndroidWifiStatus {
case notConnected
case connecting
case connected
case unknown
}

class XyoAndroidNetworkStausListener : XYBluetoothDeviceNotifyDelegate {
var onWifiChangeCallback: ((_: XyoAndroidWifiStatus) -> ())? = nil

func update(for serviceCharacteristic: XYServiceCharacteristic, value: XYBluetoothResult) {
print("XyoAndroidNetworkStausListener \(value.asString)")
guard let stringValue = value.asString else {
return
}

if (stringValue == "0") {
onWifiChangeCallback?(XyoAndroidWifiStatus.notConnected)
return
}

if (stringValue == "1") {
onWifiChangeCallback?(XyoAndroidWifiStatus.connecting)
return
}

if (stringValue == "2") {
onWifiChangeCallback?(XyoAndroidWifiStatus.connected)
return
}

onWifiChangeCallback?(XyoAndroidWifiStatus.unknown)
}
}

class XyoAndroidIpListener : XYBluetoothDeviceNotifyDelegate {
var onIpChange: ((_: String) -> ())? = nil

func update(for serviceCharacteristic: XYServiceCharacteristic, value: XYBluetoothResult) {
print("XyoAndroidIpListener \(value.asString)")
guard let stringValue = value.asString else {
return
}

onIpChange?(stringValue)
}
}

class XyoAndroidSsidListener : XYBluetoothDeviceNotifyDelegate {
var onSsidChange: ((_: String) -> ())? = nil

func update(for serviceCharacteristic: XYServiceCharacteristic, value: XYBluetoothResult) {
print("XyoAndroidSsidListener \(value.asString)")
guard let stringValue = value.asString else {
return
}

onSsidChange?(stringValue)
}
}


public class XyoAndroidXDevice : XyoDiffereniableDevice {
private var delgateKey = ""
private var hasMutex = false
private let networkStatusListener = XyoAndroidNetworkStausListener()
private let ipListener = XyoAndroidIpListener()
private let ssidListener = XyoAndroidSsidListener()


public func onNetworkStatusChange (callback: @escaping (_: XyoAndroidWifiStatus) -> ()) -> Bool {
let key = "onNetworkStatusChange [DBG: \(#function)]: \(Unmanaged.passUnretained(networkStatusListener).toOpaque())"
let result = self.subscribe(to: XyoAndroidXService.status,
delegate: (key: key, delegate: networkStatusListener))

networkStatusListener.onWifiChangeCallback = callback

return result.error == nil
}

public func onIpChange (callback: @escaping (_: String) -> ()) -> Bool {
let key = "onIpChange [DBG: \(#function)]: \(Unmanaged.passUnretained(ipListener).toOpaque())"
let result = self.subscribe(to: XyoAndroidXService.ip,
delegate: (key: key, delegate: ipListener))

ipListener.onIpChange = callback

return result.error == nil
}

public func onSsidChange (callback: @escaping (_: String) -> ()) -> Bool {
let key = "onSsidChange [DBG: \(#function)]: \(Unmanaged.passUnretained(ssidListener).toOpaque())"
let result = self.subscribe(to: XyoAndroidXService.ssid,
delegate: (key: key, delegate: ssidListener))

ssidListener.onSsidChange = callback

return result.error == nil
}


public func getMutex () -> Bool {
self.delgateKey = "mutex [DBG: \(#function)]: \(Unmanaged.passUnretained(self).toOpaque())"
print("A")
let result = self.subscribe(to: XyoAndroidXService.mutex,
delegate: (key: self.delgateKey, delegate: self))

if (result.error == nil) {
self.hasMutex = true
}


return result.error == nil
}

public func connectToWifi (ssid: String, password: String) -> Bool {
let json = "{\"ssid\": \"\(ssid)\",\"password\": \"\(password)\"}".data(using: .utf8)

let error = self.set(XyoAndroidXService.connect, value: XYBluetoothResult(data: json)).error
return error == nil
}

public func releaseMutex () -> Bool {
if (hasMutex) {
let result = self.unsubscribe(from: XyoAndroidXService.mutex, key: self.delgateKey)

if (result.error == nil) {
hasMutex = false
}

return result.error == nil
}

return false
}

public func getSsids () -> [Substring] {
if (hasMutex) {
guard let result = self.get(XyoAndroidXService.scan).asString else {
return []
}

return result.split(separator: ",")
}

return []
}

public func isClaimed () -> Bool {
guard let minor = self.iBeacon?.minor else {
return false
}

let flags = XyoBuffer()
.put(bits: minor)
.getUInt8(offset: 1)

return flags & 1 != 0
}

public func isConnected () -> Bool {
guard let minor = self.iBeacon?.minor else {
return false
}

let flags = XyoBuffer()
.put(bits: minor)
.getUInt8(offset: 1)

return flags & 2 != 0
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// XyoAndroidXDeviceCreator.swift
// sdk-xyobleinterface-swift
//
// Created by Carter Harrison on 4/9/19.
//

import Foundation
import XyBleSdk

public struct XyoAndroidXDeviceCreator : XyoManufactorDeviceCreator {
public init () {}

public func createFromIBeacon(iBeacon: XYIBeaconDefinition, rssi: Int) -> XYBluetoothDevice? {
return XyoAndroidXDevice(iBeacon: iBeacon, rssi: rssi)
}

public func enable (enable : Bool) {
if (enable) {
XyoBluetoothDeviceCreator.manufactorMap[0x04] = XyoAndroidXDeviceCreator()
} else {
XyoBluetoothDeviceCreator.manufactorMap.removeValue(forKey: 0x04)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// XyoAndroidXService.swift
// sdk-xyobleinterface-swift
//
// Created by Carter Harrison on 4/9/19.
//

import Foundation
import XyBleSdk
import CoreBluetooth

public enum XyoAndroidXService : XYServiceCharacteristic {
case mutex
case connect
case status
case scan
case ip
case ssid

/// The display name of the service.
public var serviceDisplayName: String {
return "Primary"
}

public var serviceUuid: CBUUID {
switch self {
case .mutex: return CBUUID(string: "c9be9850-7a57-414a-b797-64c230d9ecb9")
case .connect: return CBUUID(string: "00010000-89BD-43C8-9231-40F6E305F96D")
case .status: return CBUUID(string: "00010000-89BD-43C8-9231-40F6E305F96D")
case .scan: return CBUUID(string: "00010000-89BD-43C8-9231-40F6E305F96D")
case .ip: return CBUUID(string: "00010000-89BD-43C8-9231-40F6E305F96D")
case .ssid: return CBUUID(string: "00010000-89BD-43C8-9231-40F6E305F96D")
}
}

// 00010000-89BD-43C8-9231-40F6E305F96D

public var characteristicUuid: CBUUID {
switch self {
case .mutex: return CBUUID(string: "e047295e-3df0-47cd-a841-be2d2a97dd21")
case .connect: return CBUUID(string: "00010001-89BD-43C8-9231-40F6E305F96D")
case .status: return CBUUID(string: "00010030-89BD-43C8-9231-40F6E305F96D")
case .scan: return CBUUID(string: "00010040-89BD-43C8-9231-40F6E305F96D")
case .ip: return CBUUID(string: "00010020-89BD-43C8-9231-40F6E305F96D")
case .ssid: return CBUUID(string: "00010010-89BD-43C8-9231-40F6E305F96D")
}
}

public var characteristicType: XYServiceCharacteristicType { return XYServiceCharacteristicType.byte }

public var displayName: String {
switch self {
case .mutex: return "Mutex"
case .connect: return "Connect"
case .status: return "Status"
case .scan: return "Scan"
case .ssid: return "Ssid"
case .ip: return "Ip"
}
}

public static var values: [XYServiceCharacteristic] = [ XyoAndroidXService.mutex ]

}

Loading

0 comments on commit 3800897

Please sign in to comment.