added more debug to bluetooth
authorKevron Rees <kevron.m.rees@intel.com>
Wed, 28 May 2014 20:45:43 +0000 (13:45 -0700)
committerKevron Rees <kevron.m.rees@intel.com>
Wed, 28 May 2014 20:45:43 +0000 (13:45 -0700)
plugins/bluetooth/bluetoothplugin.cpp
plugins/bluetooth/testAmbBt.cpp
plugins/common/bluetooth5.cpp
plugins/common/serialport.hpp
plugins/websocket/protocol
plugins/websocket/websocketsinkmanager.cpp

index 76c3076..451e10d 100644 (file)
@@ -109,7 +109,7 @@ void BluetoothSinkPlugin::release()
 
 void BluetoothSinkPlugin::newConnection(string path, QDBusUnixFileDescriptor fd, QVariantMap props)
 {
-       DebugOut()<<"new Connection! Path: "<<path<<endl;
+       DebugOut()<<"new Connection! Path: "<<path<<" fd: "<<fd.fileDescriptor()<<endl;
 
        socket.setDescriptor(fd.fileDescriptor());
 
index f00c046..53b470d 100644 (file)
@@ -3,7 +3,7 @@
 #include <QCoreApplication>
 #include <QJsonDocument>
 #include <QStringList>
-#include <QSocketNotifier>
+#include <QDebug>
 
 #include "bluetooth5.h"
 #include <serialport.hpp>
@@ -38,9 +38,14 @@ int main(int argc, char** argv)
 
        QString addy = app.arguments().at(1);
 
+       DebugOut::setDebugThreshhold(6);
+
+       qDebug()<<"connecting to: "<<addy;
+
        Bluetooth5 btdev;
-       btdev.getDeviceForAddress(addy.toStdString(),[](int fd){
-               DebugOut(0)<<"I am connected"<<endl;
+       btdev.getDeviceForAddress(addy.toStdString(),[](int fd)
+       {
+               qDebug()<<"I am connected "<<fd;
                s->setDescriptor(fd);
 
                GIOChannel *chan = g_io_channel_unix_new(s->fileDescriptor());
@@ -48,8 +53,12 @@ int main(int argc, char** argv)
                g_io_channel_set_close_on_unref(chan, true);
                g_io_channel_unref(chan);
 
-               s->write("ping");
+               s->write("ping\r\n");
        });
 
-       return app.exec();
+       app.exec();
+
+       s->close();
+
+       return 1;
 }
index 43a9058..b1934db 100644 (file)
@@ -42,7 +42,7 @@ static void handleMethodCall(GDBusConnection       *connection,
                DebugOut()<<"NewConnection() called"<<endl;
 
                gchar* device;
-               int fd;
+               gint32 fd;
                GVariantIter* iter;
 
                g_variant_get(parameters,"(oha{sv})", &device, &fd, &iter);
@@ -55,7 +55,7 @@ static void handleMethodCall(GDBusConnection       *connection,
        }
        else
        {
-               g_dbus_method_invocation_return_error(invocation,G_DBUS_ERROR,G_DBUS_ERROR_UNKNOWN_METHOD, "Unknown method.");
+               g_dbus_method_invocation_return_error(invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Unknown method.");
        }
 
        /// return nothing:
@@ -292,15 +292,26 @@ void Bluetooth5::getDeviceForAddress(std::string address, ConnectedCallback conn
 
        GError* error = nullptr;
 
-       g_dbus_proxy_call_sync(deviceProxy,"Connect", nullptr/*g_variant_new("(s)", "00001101-0000-1000-8000-00805F9B34FB")*/,G_DBUS_CALL_FLAGS_NONE,-1, nullptr, &error);
-
-       if(error)
+       g_dbus_proxy_call(deviceProxy, "Connect", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr,[](GObject *source_object,
+                                                                                                                                                                                          GAsyncResult *res,
+                                                                                                                                                                                          gpointer user_data)
        {
-               DebugOut(DebugOut::Error)<<"error trying to connect profile: "<<error->message<<endl;
-               g_error_free(error);
+
+               GError* error = nullptr;
+               GDBusProxy *deviceProxy = (GDBusProxy*)user_data;
+
+               g_dbus_proxy_call_finish(G_DBUS_PROXY (source_object),res, &error);
+
+               if(error)
+               {
+                       DebugOut(DebugOut::Error)<<"error trying to connect profile: "<<error->message<<endl;
+                       g_error_free(error);
+               }
+
                g_object_unref(deviceProxy);
-               return;
-       }
+       }, deviceProxy);
+
+
 
 
 
index fd049a7..0908687 100644 (file)
@@ -12,6 +12,7 @@
 #include <fcntl.h>
 #include <termios.h>
 #include <errno.h>
+#include <stdio.h>
 
 class SerialPort: public AbstractIo
 {
@@ -113,14 +114,15 @@ public:
                int written = ::write(fd,data.c_str(),data.length());
                if(written == -1)
                {
-                       DebugOut()<<"Unable to write"<<endl;
+                       DebugOut(DebugOut::Warning)<<"Unable to write ("<<fd<<")"<<endl;
+                       perror("write error: ");
                }
        }
 
        void setDescriptor(int d)
        {
                fd = d;
-               setupDevice();
+               //setupDevice();
        }
 
 private: ///methods
index d28da6c..d7089c9 100644 (file)
@@ -4,7 +4,7 @@ Property changed event:
 {"type":"valuechanged","name":"VehicleSpeed","data":{"value":"217","zone": 0, "timestamp":"1354521964.60253","sequence":"0"}, "transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66", }
 
 Get property request: 
-{"type":"method","name":"get","data":"VehicleSpeed","transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"}
+{"type":"method","name":"get","data": { "property" : "VehicleSpeed", "zone" : 0 }, "transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"}
 
 Get property reply:
 {"type":"methodReply","name":"get","data":{"property":"VehicleSpeed","value":"17", "timestamp" : "1354521964.24962", "sequence": "0" },"transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"}
@@ -19,7 +19,13 @@ Subscribe to data:
 {"type":"method","name":"subscribe","data": {"property":"EngineSpeed", "zone": 0},"transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"}
 
 Subscribe to data reply:
-{"type":"methodReply","name":"subscribe","data":["EngineSpeed"],"transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"}
+{"type":"methodReply","name":"subscribe","data":"EngineSpeed","transactionid":"d293f670-f0b3-11e1-aff1-0800200c9a66"}
 
 Get History request:
 {"type":"method","name":"getRange","data": {"property":"VehicleSpeed", "timeBegin":"1368825008.35948","timeEnd":"1368825018.35948","sequenceBegin":"-1","sequenceEnd":"-1"},"transactionid":"b07589ba-417c-4604-80c6-01c0dcbd524d"}
+
+Set property request:
+{ "type" : "method", "name" : "set", "data" : { "property" : "MachineGunTurretStatus", "value" : "true", "zone" : 0 }, "transactionid" : "4123123123" }
+
+Set property reply:
+{ "type" : "methodReply", "name" : "set", "data" : { "property" : "MachineGunTurretStatus", "value" : "true", "zone" : 0, "success" : true }, "transactionid" : "4123123123" }
index 7471d0f..185620d 100644 (file)
@@ -297,6 +297,7 @@ void WebSocketSinkManager::setValue(libwebsocket* socket,VehicleProperty::Proper
                data["property"] = property.c_str();
                data["zone"] = zone;
                data["source"] = reply->value->sourceUuid.c_str();
+               data["success"] = reply->success;
 
                QVariantMap replyvar;
                replyvar["type"]="methodReply";