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());
#include <QCoreApplication>
#include <QJsonDocument>
#include <QStringList>
-#include <QSocketNotifier>
+#include <QDebug>
#include "bluetooth5.h"
#include <serialport.hpp>
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());
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;
}
DebugOut()<<"NewConnection() called"<<endl;
gchar* device;
- int fd;
+ gint32 fd;
GVariantIter* iter;
g_variant_get(parameters,"(oha{sv})", &device, &fd, &iter);
}
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:
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);
+
+
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
+#include <stdio.h>
class SerialPort: public AbstractIo
{
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
{"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"}
{"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" }
data["property"] = property.c_str();
data["zone"] = zone;
data["source"] = reply->value->sourceUuid.c_str();
+ data["success"] = reply->success;
QVariantMap replyvar;
replyvar["type"]="methodReply";