Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with advertising service uuids, and other server functionalities. #1

Closed
roylee17 opened this issue Jan 27, 2015 · 5 comments
Closed

Comments

@roylee17
Copy link
Contributor

Hi @raff ,

I'm currently integrating the goble (xpc, mostly) into gatt for MacOS support, I've got the client APIs unified (not completely done yet). But I'm having problem to get the server function work. It only broadcast name, but not service IDs. Any idea I can try?

xpc.Dict{
    "kCBMsgId":8,
     "kCBMsgArgs":xpc.Dict{
        "kCBAdvDataLocalName":"goble",
        "kCBAdvDataServiceUUIDs":[]string{"180f"}
    },
}

Thanks.
Roy

@raff
Copy link
Owner

raff commented Jan 27, 2015

I just checked in a fix. See goble.go.

The problem with Bluetooth via XPC (and the conversion from nodejs) it's
that is not really clear when things are strings, byte arrays or UUIDs, so
you just need to try until you get something that work :)

...actually, I wrote a 2 line program for nodejs, and run it as:

DEBUG=* node test.js

That dumps the messages, as close as they go "over the wire" and compared
with running goble in verbose mode it gives you an idea of what the
differences may be.

-- Raffaele

On Mon, Jan 26, 2015 at 11:17 PM, Tzu-Jung (Roy) Lee <
notifications@github.com> wrote:

Hi @raff https://github.com/raff ,

I'm currently integrating the goble (xpc, mostly) into gatt for MacOS
support, I've got the client APIs unified (not completely done yet). But
I'm having problem to get the server function work. It only broadcast name,
but not service IDs. Any idea I can try?

xpc.Dict{
"kCBMsgId":8,
"kCBMsgArgs":xpc.Dict{
"kCBAdvDataLocalName":"goble",
"kCBAdvDataServiceUUIDs":[]string{"180f"}
},
}

Thanks.
Roy


Reply to this email directly or view it on GitHub
#1.

@roylee17
Copy link
Contributor Author

Thanks a lot!

Another XPC issue, please see below snippet for characteristic data - "kCBMsgArgData"

func (ble *BLE) SetServices(services []Service) {
    ble.sendCBMsg(12, nil) // remove all services
    arg := dict{
        "kCBMsgArgAttributeID":  1,
        "kCBMsgArgUUID":         []byte{0x18, 0x0F},
        "kCBMsgArgAttributeIDs": []int{},
        "kCBMsgArgType":         1,
        "kCBMsgArgCharacteristics": array{
            dict{
                "kCBMsgArgAttributeID":              2,
                "kCBMsgArgUUID":                     []byte{0x2A, 0x19},
                "kCBMsgArgAttributePermissions":     1,
                "kCBMsgArgCharacteristicProperties": 2,

                // hardcoded for static value, or leave nil for "read event(19)"       
                "kCBMsgArgData":                     []byte{0x64},

                "kCBMsgArgDescriptors": array{
                    dict{
                        "kCBMsgArgData": "Battery level between 0 and 100 percent",
                        "kCBMsgArgUUID": []byte{0x29, 0x01},
                    },
                    dict{
                        "kCBMsgArgData": []byte{4, 1, 39, 173, 1, 0, 0},
                        "kCBMsgArgUUID": []byte{0x29, 0x04},
                    },
                },
            },
        },
    }
    ble.sendCBMsg(10, arg) // Add Service
}

noble DEBUG output shows it left it null, instead of empty array/dict.

 bindings sendCBMsg: 10, {
  "kCBMsgArgAttributeID": 1,
  "kCBMsgArgAttributeIDs": [],
  "kCBMsgArgCharacteristics": [
    {
      "kCBMsgArgAttributeID": 2,
      "kCBMsgArgAttributePermissions": 1,
      "kCBMsgArgCharacteristicProperties": 2,
      "kCBMsgArgData": null,
      "kCBMsgArgDescriptors": [
        {
          "kCBMsgArgData": "Battery level between 0 and 100 percent",

I've tried a few hack as follow to treat the nil specially, but haven't got any work.

func valueToXpc(val r.Value) C.xpc_object_t {
        ...
    case r.Map:
        xv = C.xpc_dictionary_create(nil, nil, 0)
        for _, k := range val.MapKeys() {
            v := valueToXpc(val.MapIndex(k))
            if v == nil {
                log.Printf("XXXXXXXX:%s", k.String())
                // vv := C.xpc_array_create(nil, 0)
                // vv := C.xpc_data_create(unsafe.Pointer(0), C.size_t(0)
                // C.xpc_dictionary_set_data(xv, C.CString(k.String()), unsafe.Pointer(nil), C.size_t(0))
                // C.xpc_dictionary_set_value(xv, C.CString(k.String()), C.xpc_object_t(nil))
                // or simply skip...
                continue
            }
            C.xpc_dictionary_set_value(xv, C.CString(k.String()), v)
            if v != nil {
                C.xpc_release(v)
            }
        }

@roylee17
Copy link
Contributor Author

I add some log in XpcConnection.cpp to see what's the final stuff passed to from node to XPC (or NULL value in the Dice are simply discarded).

diff --git a/src/XpcConnection.cpp b/src/XpcConnection.cpp
index 6d568cb..0819dfe 100644
--- a/src/XpcConnection.cpp
+++ b/src/XpcConnection.cpp
@@ -153,6 +153,11 @@ xpc_object_t XpcConnection::ObjectToXpcObject(v8::Handle<v8::Object> object) {
       v8::Handle<v8::Value> propertyValue = object->GetRealNamedProperty(propertyNameString);

       xpc_object_t xpcValue = XpcConnection::ValueToXpcObject(propertyValue);
+      if (xpcValue == NULL) {
+        NSLog(@"ROY: Set %s to NULL", *propertyNameStringValue);
+        xpc_dictionary_set_value(xpcObject, *propertyNameStringValue, NULL);
+        continue;
+      }
       xpc_dictionary_set_value(xpcObject, *propertyNameStringValue, xpcValue);
       if (xpcValue) {
         xpc_release(xpcValue);

According to the log, it seems that node passes NULL to XPC.

2015-01-28 14:51:12.417 node[27492:507] ROY: Set kCBMsgArgs to NULL
2015-01-28 14:51:12.418 node[27492:507] ROY: Set kCBMsgArgData to NULL

So I went back to try passing more different stuff from go to XPC. Still no luck so far.
Need more enlightenment.

// vv := C.xpc_dictionary_set_data(...)
// vv := C.xpc_dictionary_set_value(...)
// vv := C.xpc_null_create()
// vv := C.xpc_int64_create(0)
// vv := C.xpc_data_create(unsafe.Pointer(uintptr(0)), 0)
// ...
C.xpc_dictionary_set_value(xv, C.CString(k.String()), vv)

@roylee17
Copy link
Contributor Author

roylee17 commented Feb 2, 2015

Sorry for the false alarm, after changing the kCBMsgArgType to 1 during the initialization, things working fine now.

@roylee17 roylee17 closed this as completed Feb 2, 2015
@raff
Copy link
Owner

raff commented Feb 4, 2015

ok, great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants