Compare commits
No commits in common. "6da0474e59d617205b55b84c3cabb441735f116e" and "90ab682a441002fca1192d7eab04a2397d3957d4" have entirely different histories.
6da0474e59
...
90ab682a44
|
@ -326,7 +326,7 @@ func goOnDiscoverService(cid, cuuid *C.char, serv C.jobject) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//export goOnDiscoverCharacteristic
|
//export goOnDiscoverCharacteristic
|
||||||
func goOnDiscoverCharacteristic(cid, csuuid *C.char, serv C.jobject, ccuuid *C.char, characteristic C.jobject) {
|
func goOnDiscoverCharacteristic(cid, csuuid *C.char, serv C.jobject, ccuuid *C.char, char C.jobject) {
|
||||||
id := C.GoString(cid)
|
id := C.GoString(cid)
|
||||||
suuid := C.GoString(csuuid)
|
suuid := C.GoString(csuuid)
|
||||||
cuuid := C.GoString(ccuuid)
|
cuuid := C.GoString(ccuuid)
|
||||||
|
@ -339,34 +339,34 @@ func goOnDiscoverCharacteristic(cid, csuuid *C.char, serv C.jobject, ccuuid *C.c
|
||||||
service: serv,
|
service: serv,
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := Characteristic{
|
characteristic := Characteristic{
|
||||||
UUID: cuuid,
|
UUID: cuuid,
|
||||||
characteristic: characteristic,
|
characteristic: char,
|
||||||
}
|
}
|
||||||
|
|
||||||
gBLE.events <- DiscoverCharacteristicEvent{
|
gBLE.events <- DiscoverCharacteristicEvent{
|
||||||
Peripheral: peripheral,
|
Peripheral: peripheral,
|
||||||
Service: service,
|
Service: service,
|
||||||
Characteristic: ch,
|
Characteristic: characteristic,
|
||||||
Gatt: gatt.Characteristic{cuuid},
|
Gatt: gatt.Characteristic{cuuid},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export goOnCharacteristicChanged
|
//export goOnCharacteristicChanged
|
||||||
func goOnCharacteristicChanged(cid, ccuuid *C.char, characteristic C.jobject, cvalue *C.char, length C.jint) {
|
func goOnCharacteristicChanged(cid, ccuuid *C.char, char C.jobject, cvalue *C.char, length C.jint) {
|
||||||
id := C.GoString(cid)
|
id := C.GoString(cid)
|
||||||
cuuid := C.GoString(ccuuid)
|
cuuid := C.GoString(ccuuid)
|
||||||
|
|
||||||
peripheral := gBLE.retrievePeripheral(id)
|
peripheral := gBLE.retrievePeripheral(id)
|
||||||
|
|
||||||
ch := Characteristic{
|
characteristic := Characteristic{
|
||||||
UUID: cuuid,
|
UUID: cuuid,
|
||||||
characteristic: characteristic,
|
characteristic: char,
|
||||||
}
|
}
|
||||||
|
|
||||||
gBLE.events <- UpdateValueEvent{
|
gBLE.events <- UpdateValueEvent{
|
||||||
Peripheral: peripheral,
|
Peripheral: peripheral,
|
||||||
Characteristic: ch,
|
Characteristic: characteristic,
|
||||||
Data: C.GoBytes(unsafe.Pointer(cvalue), length),
|
Data: C.GoBytes(unsafe.Pointer(cvalue), length),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ func (p Peripheral) DiscoverCharacteristics(serv Service) {
|
||||||
|
|
||||||
//SetNotifyValue subscribes to a characteristic
|
//SetNotifyValue subscribes to a characteristic
|
||||||
func (p Peripheral) SetNotifyValue(c Characteristic) {
|
func (p Peripheral) SetNotifyValue(c Characteristic) {
|
||||||
p.p.SetNotifyValue((ns.BOOL)(true), c)
|
p.p.SetNotifyValue(1, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewBLE returns a pointer to a BLE struct after setting up the OS
|
//NewBLE returns a pointer to a BLE struct after setting up the OS
|
||||||
|
@ -207,8 +207,7 @@ func (b *BLE) Enable(v uintptr) {
|
||||||
|
|
||||||
// Core Bluetooth callback functions
|
// Core Bluetooth callback functions
|
||||||
|
|
||||||
func didUpdateState(d ns.CBDelegate, c *ns.CBCentralManager) {
|
func didUpdateState(c *ns.CBCentralManager) {
|
||||||
fmt.Print("didUpdateState")
|
|
||||||
b := cdLookup[c.Ptr()]
|
b := cdLookup[c.Ptr()]
|
||||||
st := c.CBManager.State()
|
st := c.CBManager.State()
|
||||||
if st == (ns.CBManagerState)(ns.CBManagerStatePoweredOn) {
|
if st == (ns.CBManagerState)(ns.CBManagerStatePoweredOn) {
|
||||||
|
@ -231,7 +230,7 @@ func didUpdateState(d ns.CBDelegate, c *ns.CBCentralManager) {
|
||||||
b.events <- UpdateStateEvent{State: b.stringState()}
|
b.events <- UpdateStateEvent{State: b.stringState()}
|
||||||
}
|
}
|
||||||
|
|
||||||
func didDiscoverPeripheral(d_ ns.CBDelegate, c *ns.CBCentralManager, p *ns.CBPeripheral, d *ns.NSDictionary, rssi *ns.NSNumber) {
|
func didDiscoverPeripheral(c *ns.CBCentralManager, p *ns.CBPeripheral, d *ns.NSDictionary, rssi *ns.NSNumber) {
|
||||||
b := cdLookup[c.Ptr()]
|
b := cdLookup[c.Ptr()]
|
||||||
peripheral := newPeripheral(p)
|
peripheral := newPeripheral(p)
|
||||||
peripheral.RSSI = (int)(rssi.IntValue())
|
peripheral.RSSI = (int)(rssi.IntValue())
|
||||||
|
@ -248,7 +247,7 @@ func _didDiscoverPeripheral(b *BLE, peripheral Peripheral) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func didConnectPeripheral(d ns.CBDelegate, c *ns.CBCentralManager, p *ns.CBPeripheral) {
|
func didConnectPeripheral(c *ns.CBCentralManager, p *ns.CBPeripheral) {
|
||||||
fmt.Printf("Did connect peripheral\n")
|
fmt.Printf("Did connect peripheral\n")
|
||||||
b := cdLookup[c.Ptr()]
|
b := cdLookup[c.Ptr()]
|
||||||
|
|
||||||
|
@ -281,7 +280,7 @@ func didConnectPeripheral(d ns.CBDelegate, c *ns.CBCentralManager, p *ns.CBPerip
|
||||||
fmt.Printf("Go: didConnectPeripheral returning\n")
|
fmt.Printf("Go: didConnectPeripheral returning\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func didDisconnectPeripheral(d ns.CBDelegate, c *ns.CBCentralManager, p *ns.CBPeripheral, e *ns.NSError) {
|
func didDisconnectPeripheral(c *ns.CBCentralManager, p *ns.CBPeripheral, e *ns.NSError) {
|
||||||
fmt.Printf("Did disconnect peripheral\n");
|
fmt.Printf("Did disconnect peripheral\n");
|
||||||
b := cdLookup[c.Ptr()]
|
b := cdLookup[c.Ptr()]
|
||||||
|
|
||||||
|
@ -312,7 +311,7 @@ func didDisconnectPeripheral(d ns.CBDelegate, c *ns.CBCentralManager, p *ns.CBPe
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func didDiscoverServices(d ns.CBDelegate, p *ns.CBPeripheral, e *ns.NSError) {
|
func didDiscoverServices(p *ns.CBPeripheral, e *ns.NSError) {
|
||||||
b := pdLookup[p.Ptr()]
|
b := pdLookup[p.Ptr()]
|
||||||
fmt.Printf("Did discover services\n")
|
fmt.Printf("Did discover services\n")
|
||||||
p.Services().ObjectEnumerator().ForIn(func(o *ns.Id) bool {
|
p.Services().ObjectEnumerator().ForIn(func(o *ns.Id) bool {
|
||||||
|
@ -328,7 +327,7 @@ func didDiscoverServices(d ns.CBDelegate, p *ns.CBPeripheral, e *ns.NSError) {
|
||||||
fmt.Printf("Go: didDiscoverServices returning\n")
|
fmt.Printf("Go: didDiscoverServices returning\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func didDiscoverCharacteristics(d ns.CBDelegate, p *ns.CBPeripheral, s *ns.CBService, e *ns.NSError) {
|
func didDiscoverCharacteristics(p *ns.CBPeripheral, s *ns.CBService, e *ns.NSError) {
|
||||||
b := pdLookup[p.Ptr()]
|
b := pdLookup[p.Ptr()]
|
||||||
fmt.Printf("Did discover characteristics\n")
|
fmt.Printf("Did discover characteristics\n")
|
||||||
s.Characteristics().ObjectEnumerator().ForIn(func(o *ns.Id) bool {
|
s.Characteristics().ObjectEnumerator().ForIn(func(o *ns.Id) bool {
|
||||||
|
@ -346,7 +345,7 @@ func didDiscoverCharacteristics(d ns.CBDelegate, p *ns.CBPeripheral, s *ns.CBSer
|
||||||
fmt.Printf("Go: didDiscoverCharacteristics returning\n")
|
fmt.Printf("Go: didDiscoverCharacteristics returning\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func didUpdateValue(d ns.CBDelegate, p *ns.CBPeripheral, chr *ns.CBCharacteristic, e *ns.NSError) {
|
func didUpdateValue(p *ns.CBPeripheral, chr *ns.CBCharacteristic, e *ns.NSError) {
|
||||||
b := pdLookup[p.Ptr()]
|
b := pdLookup[p.Ptr()]
|
||||||
v := chr.Value()
|
v := chr.Value()
|
||||||
b.events <-UpdateValueEvent{
|
b.events <-UpdateValueEvent{
|
||||||
|
|
|
@ -15,20 +15,27 @@ import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//export CBDelegateCentralManagerDidUpdateState
|
||||||
|
func CBDelegateCentralManagerDidUpdateState(o unsafe.Pointer, central unsafe.Pointer) {
|
||||||
|
CBDelegateMux.RLock()
|
||||||
|
cb := CBDelegateLookup[o].CentralManagerDidUpdateState
|
||||||
|
CBDelegateMux.RUnlock()
|
||||||
|
if cb == nil { return }
|
||||||
|
a1 := &CBCentralManager{}; a1.ptr = central
|
||||||
|
cb(a1)
|
||||||
|
}
|
||||||
|
|
||||||
//export CBDelegateCentralManagerDidConnectPeripheral
|
//export CBDelegateCentralManagerDidConnectPeripheral
|
||||||
func CBDelegateCentralManagerDidConnectPeripheral(o unsafe.Pointer, central unsafe.Pointer, peripheral unsafe.Pointer) {
|
func CBDelegateCentralManagerDidConnectPeripheral(o unsafe.Pointer, central unsafe.Pointer, peripheral unsafe.Pointer) {
|
||||||
CBDelegateMux.RLock()
|
CBDelegateMux.RLock()
|
||||||
cb := CBDelegateLookup[o].CentralManagerDidConnectPeripheral
|
cb := CBDelegateLookup[o].CentralManagerDidConnectPeripheral
|
||||||
CBDelegateMux.RUnlock()
|
CBDelegateMux.RUnlock()
|
||||||
if cb == nil { return }
|
if cb == nil { return }
|
||||||
self := CBDelegate{}
|
|
||||||
self.ptr = o
|
|
||||||
a1 := &CBCentralManager{}; a1.ptr = central
|
a1 := &CBCentralManager{}; a1.ptr = central
|
||||||
a2 := &CBPeripheral{}; a2.ptr = peripheral
|
a2 := &CBPeripheral{}; a2.ptr = peripheral
|
||||||
cb(self, a1, a2)
|
cb(a1, a2)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export CBDelegateCentralManagerDidDisconnectPeripheral
|
//export CBDelegateCentralManagerDidDisconnectPeripheral
|
||||||
|
@ -37,12 +44,10 @@ func CBDelegateCentralManagerDidDisconnectPeripheral(o unsafe.Pointer, central u
|
||||||
cb := CBDelegateLookup[o].CentralManagerDidDisconnectPeripheral
|
cb := CBDelegateLookup[o].CentralManagerDidDisconnectPeripheral
|
||||||
CBDelegateMux.RUnlock()
|
CBDelegateMux.RUnlock()
|
||||||
if cb == nil { return }
|
if cb == nil { return }
|
||||||
self := CBDelegate{}
|
|
||||||
self.ptr = o
|
|
||||||
a1 := &CBCentralManager{}; a1.ptr = central
|
a1 := &CBCentralManager{}; a1.ptr = central
|
||||||
a2 := &CBPeripheral{}; a2.ptr = peripheral
|
a2 := &CBPeripheral{}; a2.ptr = peripheral
|
||||||
a3 := &NSError{}; a3.ptr = error
|
a3 := &NSError{}; a3.ptr = error
|
||||||
cb(self, a1, a2, a3)
|
cb(a1, a2, a3)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export CBDelegateCentralManagerDidDiscoverPeripheral
|
//export CBDelegateCentralManagerDidDiscoverPeripheral
|
||||||
|
@ -51,26 +56,11 @@ func CBDelegateCentralManagerDidDiscoverPeripheral(o unsafe.Pointer, central uns
|
||||||
cb := CBDelegateLookup[o].CentralManagerDidDiscoverPeripheral
|
cb := CBDelegateLookup[o].CentralManagerDidDiscoverPeripheral
|
||||||
CBDelegateMux.RUnlock()
|
CBDelegateMux.RUnlock()
|
||||||
if cb == nil { return }
|
if cb == nil { return }
|
||||||
self := CBDelegate{}
|
|
||||||
self.ptr = o
|
|
||||||
a1 := &CBCentralManager{}; a1.ptr = central
|
a1 := &CBCentralManager{}; a1.ptr = central
|
||||||
a2 := &CBPeripheral{}; a2.ptr = peripheral
|
a2 := &CBPeripheral{}; a2.ptr = peripheral
|
||||||
a3 := &NSDictionary{}; a3.ptr = advertisementData
|
a3 := &NSDictionary{}; a3.ptr = advertisementData
|
||||||
a4 := &NSNumber{}; a4.ptr = RSSI
|
a4 := &NSNumber{}; a4.ptr = RSSI
|
||||||
cb(self, a1, a2, a3, a4)
|
cb(a1, a2, a3, a4)
|
||||||
}
|
|
||||||
|
|
||||||
//export CBDelegateCentralManagerDidUpdateState
|
|
||||||
func CBDelegateCentralManagerDidUpdateState(o unsafe.Pointer, central unsafe.Pointer) {
|
|
||||||
fmt.Print("CentralManagerDidUpdateState")
|
|
||||||
CBDelegateMux.RLock()
|
|
||||||
cb := CBDelegateLookup[o].CentralManagerDidUpdateState
|
|
||||||
CBDelegateMux.RUnlock()
|
|
||||||
if cb == nil { return }
|
|
||||||
self := CBDelegate{}
|
|
||||||
self.ptr = o
|
|
||||||
a1 := &CBCentralManager{}; a1.ptr = central
|
|
||||||
cb(self, a1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//export CBDelegatePeripheralDidDiscoverServices
|
//export CBDelegatePeripheralDidDiscoverServices
|
||||||
|
@ -79,11 +69,9 @@ func CBDelegatePeripheralDidDiscoverServices(o unsafe.Pointer, peripheral unsafe
|
||||||
cb := CBDelegateLookup[o].PeripheralDidDiscoverServices
|
cb := CBDelegateLookup[o].PeripheralDidDiscoverServices
|
||||||
CBDelegateMux.RUnlock()
|
CBDelegateMux.RUnlock()
|
||||||
if cb == nil { return }
|
if cb == nil { return }
|
||||||
self := CBDelegate{}
|
|
||||||
self.ptr = o
|
|
||||||
a1 := &CBPeripheral{}; a1.ptr = peripheral
|
a1 := &CBPeripheral{}; a1.ptr = peripheral
|
||||||
a2 := &NSError{}; a2.ptr = error
|
a2 := &NSError{}; a2.ptr = error
|
||||||
cb(self, a1, a2)
|
cb(a1, a2)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export CBDelegatePeripheralDidDiscoverCharacteristicsForService
|
//export CBDelegatePeripheralDidDiscoverCharacteristicsForService
|
||||||
|
@ -92,12 +80,10 @@ func CBDelegatePeripheralDidDiscoverCharacteristicsForService(o unsafe.Pointer,
|
||||||
cb := CBDelegateLookup[o].PeripheralDidDiscoverCharacteristicsForService
|
cb := CBDelegateLookup[o].PeripheralDidDiscoverCharacteristicsForService
|
||||||
CBDelegateMux.RUnlock()
|
CBDelegateMux.RUnlock()
|
||||||
if cb == nil { return }
|
if cb == nil { return }
|
||||||
self := CBDelegate{}
|
|
||||||
self.ptr = o
|
|
||||||
a1 := &CBPeripheral{}; a1.ptr = peripheral
|
a1 := &CBPeripheral{}; a1.ptr = peripheral
|
||||||
a2 := &CBService{}; a2.ptr = service
|
a2 := &CBService{}; a2.ptr = service
|
||||||
a3 := &NSError{}; a3.ptr = error
|
a3 := &NSError{}; a3.ptr = error
|
||||||
cb(self, a1, a2, a3)
|
cb(a1, a2, a3)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export CBDelegatePeripheralDidUpdateValueForCharacteristic
|
//export CBDelegatePeripheralDidUpdateValueForCharacteristic
|
||||||
|
@ -106,10 +92,8 @@ func CBDelegatePeripheralDidUpdateValueForCharacteristic(o unsafe.Pointer, perip
|
||||||
cb := CBDelegateLookup[o].PeripheralDidUpdateValueForCharacteristic
|
cb := CBDelegateLookup[o].PeripheralDidUpdateValueForCharacteristic
|
||||||
CBDelegateMux.RUnlock()
|
CBDelegateMux.RUnlock()
|
||||||
if cb == nil { return }
|
if cb == nil { return }
|
||||||
self := CBDelegate{}
|
|
||||||
self.ptr = o
|
|
||||||
a1 := &CBPeripheral{}; a1.ptr = peripheral
|
a1 := &CBPeripheral{}; a1.ptr = peripheral
|
||||||
a2 := &CBCharacteristic{}; a2.ptr = characteristic
|
a2 := &CBCharacteristic{}; a2.ptr = characteristic
|
||||||
a3 := &NSError{}; a3.ptr = error
|
a3 := &NSError{}; a3.ptr = error
|
||||||
cb(self, a1, a2, a3)
|
cb(a1, a2, a3)
|
||||||
}
|
}
|
||||||
|
|
105582
ns/main.go
105582
ns/main.go
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
||||||
inputfiles:
|
inputfiles:
|
||||||
- /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h
|
- /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h
|
||||||
- /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreBluetooth.framework/Headers/CoreBluetooth.h
|
- /System/Library/Frameworks/CoreBluetooth.framework/Headers/CoreBluetooth.h
|
||||||
|
|
||||||
classes:
|
classes:
|
||||||
- NSObject
|
- NSObject
|
||||||
|
|
Loading…
Reference in New Issue
Block a user