Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switching BT backend to QtMobility1.2; working on the n900. Connected…

… DevDiscovery back to Search/Stop bts
  • Loading branch information...
commit cc3cc940292d6d728865fe38018d34b596943153 1 parent eca6ecf
Clovis Scotti authored
View
38 PushBurton2/PushBurton2.pro
@@ -80,7 +80,8 @@ SOURCES += \
virtualbrosdevice.cpp \
rotationcounter.cpp \
npushrotationstick.cpp \
- broadcasterdevice.cpp
+ broadcasterdevice.cpp \
+ qtmpushdevice.cpp
HEADERS += \
devicesmanager.h \
@@ -131,7 +132,8 @@ HEADERS += \
UI/liveview.h \
UI/graphicssettings.h \
UI/pushburtonanimation.h \
- broadcasterdevice.h
+ broadcasterdevice.h \
+ qtmpushdevice.h
FORMS += \
UI/mainwindow.ui \
@@ -174,22 +176,22 @@ symbian {
WriteUserData \
Location
- HEADERS += \
- pushn8btdevice.h \
- pushn8imudevice.h \
- pushn8heartdevice.h \
- pushn8gsrdevice.h \
- pushn8footdevice.h
-
- SOURCES += \
- pushn8btdevice.cpp \
- pushn8imudevice.cpp \
- pushn8heartdevice.cpp \
- pushn8gsrdevice.cpp \
- pushn8footdevice.cpp
-
- addFiles.sources = $(EPOCROOT)Epoc32/release/$(PLATFORM)/$(CFG)/QBluetooth.dll
- addFiles.path = /sys/bin
+# HEADERS += \
+# pushn8btdevice.h \
+# pushn8imudevice.h \
+# pushn8heartdevice.h \
+# pushn8gsrdevice.h \
+# pushn8footdevice.h
+
+# SOURCES += \
+# pushn8btdevice.cpp \
+# pushn8imudevice.cpp \
+# pushn8heartdevice.cpp \
+# pushn8gsrdevice.cpp \
+# pushn8footdevice.cpp
+
+# addFiles.sources = $(EPOCROOT)Epoc32/release/$(PLATFORM)/$(CFG)/QBluetooth.dll
+# addFiles.path = /sys/bin
DEPLOYMENT += addFiles
View
2  PushBurton2/UI/graphicsconnmenu.cpp
@@ -90,6 +90,7 @@ void GraphicsConnMenu::setupStateMachine()
btState->setInitialState(btStandBy);
btStandBy->addTransition(startBt, SIGNAL(activated()), btSearching);
btSearching->addTransition(stopBt, SIGNAL(activated()), btStandBy);
+ btSearching->addTransition(this, SIGNAL(searchFinished()), btStandBy);
btSearching->assignProperty(startBt, "y", -60);
btSearching->assignProperty(stopBt, "y", 0);
btStandBy->assignProperty(startBt, "y", 0);
@@ -113,4 +114,3 @@ void GraphicsConnMenu::kit_selected(QString selKit)
emit kit_selected(kitN);
qDebug() << "Kit " << kitN << " selected";
}
-
View
1  PushBurton2/UI/graphicsconnmenu.h
@@ -52,6 +52,7 @@ class GraphicsConnMenu : public QGraphicsObject
void startSearch_bt_clicked();
void stopSearch_bt_clicked();
void kit_selected(int n);
+ void searchFinished();
private slots:
void kit_selected(QString kit_selected);
View
6 PushBurton2/UI/mainwindow.cpp
@@ -58,6 +58,11 @@ MainWindow::MainWindow(const QString& simulationData, QWidget *parent) :
ui->graphicsView->showMaximized();
ui->graphicsView->show();
+// ui->graphicsView->fitInView(QRectF(0,0,36,48));
+#ifdef Q_WS_MAEMO_5
+ ui->graphicsView->scale(1.35,1.55);
+#endif
+
//Building state machine hierarchy (no connections)
rootState = new QState();
@@ -136,6 +141,7 @@ void MainWindow::fillStatesProperties()
connect(connMenu, SIGNAL(startSearch_bt_clicked()), &devicesManager, SLOT(start_bt_search()));
connect(connMenu, SIGNAL(stopSearch_bt_clicked()), &devicesManager, SLOT(stop_bt_search()));
connect(connMenu, SIGNAL(kit_selected(int)), &devicesManager, SLOT(kit_selected(int)));
+ connect(&devicesManager, SIGNAL(allDiscoveryFinished()), connMenu, SIGNAL(searchFinished()));
connMenu->setPos(10, -180);
scene->addItem(connMenu);
connectUsrState->assignProperty(connMenu, "y", 5);
View
138 PushBurton2/devicesmanager.cpp
@@ -27,14 +27,12 @@
#include "devicesmanager.h"
+#include <QBluetoothLocalDevice>
+
DevicesManager::DevicesManager(PushDevicesHolder * aDevHolder, QObject *parent) :
- QObject(parent), configuredDevices(aDevHolder)
+ QObject(parent), configuredDevices(aDevHolder),
+ devDiscoveryAgent(new QBluetoothDeviceDiscoveryAgent(this))
{
-
-#ifdef Q_OS_SYMBIAN
- deviceDiscoverer = 0;
-#endif
-
searching = false;
auto_connect = true;
@@ -47,37 +45,119 @@ DevicesManager::DevicesManager(PushDevicesHolder * aDevHolder, QObject *parent)
SetupPhoneDevices();
SetupAbstractDevices();
+
+
+ // start Bluetooth if not started
+ localDevice = new QBluetoothLocalDevice();
+
+ qDebug() << "device pointer is:" << localDevice;
+
+ if(localDevice)
+ {
+ localDevice->powerOn();
+ delete localDevice;
+ localDevice = 0;
+ }
+
+ connect(devDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
+ this, SLOT(deviceDiscovered(QBluetoothDeviceInfo)));
+ connect(devDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
+ this, SLOT(deviceDiscErrorDetected(QBluetoothDeviceDiscoveryAgent::Error)));
+ connect(devDiscoveryAgent, SIGNAL(finished()),
+ this, SLOT(deviceDiscoveryAgentFinished()));
+ connect(devDiscoveryAgent, SIGNAL(finished()),
+ this, SIGNAL(allDiscoveryFinished()));
+
+
+
}
DevicesManager::~DevicesManager()
{
-#ifdef Q_OS_SYMBIAN
- if(deviceDiscoverer)
- delete deviceDiscoverer;
- unknownFoundDevices.clear();
-#endif
+
}
void DevicesManager::start_bt_search()
{
-#ifdef Q_OS_SYMBIAN
- if(!searching)
+
+ if(devDiscoveryAgent)
+ {
+ devDiscoveryAgent->start();
+ }
+
+ qDebug() << "DevDiscovery Started";
+}
+
+void DevicesManager::deviceDiscovered(QtMobility::QBluetoothDeviceInfo info)
+{
+ qDebug() << "Device found: " << info.name();
+ if(info.name().contains("PUSHN8_") > 0)
{
- searching = true;
- QBtLocalDevice::askUserTurnOnBtPower();
- unknownFoundDevices.clear();
- if(deviceDiscoverer) delete deviceDiscoverer;
- deviceDiscoverer = new QBtDeviceDiscoverer(this);
- connect(deviceDiscoverer , SIGNAL(newDeviceFound (QBtDevice)), this, SLOT(deviceFound(QBtDevice)));
+ //saving device name for further lookup inside service found
+ if(!knownBtDevices.contains(info.address()))
+ {
+ knownBtDevices[info.address()] = info.name();
+ }
- deviceDiscoverer->startDiscovery();
- qDebug() << "Bluetooth Discovery started";
+ qDebug() << "Starting service discovery";
+ QBluetoothServiceDiscoveryAgent * tSrvcDiscoveryAgent = new QBluetoothServiceDiscoveryAgent(info.address(),this);
+
+ connect(tSrvcDiscoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
+ this, SLOT(serviceDiscovered(QBluetoothServiceInfo)));
+ connect(tSrvcDiscoveryAgent, SIGNAL(finished()),
+ this, SLOT(srvcDiscoveryAgentFinished()));
+ connect(tSrvcDiscoveryAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)),
+ this, SLOT(srvcDiscErrorDetected(QBluetoothServiceDiscoveryAgent::Error)));
+
+ tSrvcDiscoveryAgent->start();
}
-#endif
}
-#ifdef Q_OS_SYMBIAN
+void DevicesManager::deviceDiscoveryAgentFinished()
+{
+ qDebug() << "DevDiscovery Ended";
+}
+
+void DevicesManager::serviceDiscovered(QtMobility::QBluetoothServiceInfo info)
+{
+ qDebug() << "Service Found for " << knownBtDevices[info.device().address()];
+
+ if(knownBtDevices[info.device().address()].contains("PUSHN8_MOTION") > 0)
+ {
+ //Adding to configuredDevices
+ QtmPushDevice * qtmDevice = new QtmPushDevice(info);
+
+ configuredDevices->push_back(qtmDevice);
+
+ emit device_connecting(QString("Board"));
+
+ connect(qtmDevice, SIGNAL(connected()), &connectedMapper, SLOT(map()));
+ connectedMapper.setMapping(qtmDevice, QString("Board"));
+ connect(qtmDevice, SIGNAL(disconnected()), &disconnectedMapper, SLOT(map()));
+ disconnectedMapper.setMapping(qtmDevice, QString("Board"));
+
+ }
+}
+
+void DevicesManager::srvcDiscoveryAgentFinished()
+{
+ qDebug() << "A SrvcDiscovery Finished";
+ sender()->deleteLater();
+}
+
+void DevicesManager::srvcDiscErrorDetected(QBluetoothServiceDiscoveryAgent::Error error)
+{
+ qDebug() << "Service Discovery Got Error:" << error;
+}
+
+
+void DevicesManager::deviceDiscErrorDetected(QBluetoothDeviceDiscoveryAgent::Error error)
+{
+ qDebug() << "Device Discovery Got Error:" << error;
+}
+
+#if 0
void DevicesManager::deviceFound(QBtDevice newDevice)
{
QString devName = newDevice.getName();
@@ -200,13 +280,14 @@ bool DevicesManager::IsDeviceNovell(QBtDevice dev)
void DevicesManager::stop_bt_search()
{
-#ifdef Q_OS_SYMBIAN
- if(searching)
+ if(devDiscoveryAgent)
{
- searching = false;
- deviceDiscoverer->stopDiscovery();
+ if(devDiscoveryAgent->isActive())
+ {
+ devDiscoveryAgent->stop();
+ qDebug() << "DevDiscovery Stopped";
+ }
}
-#endif
}
void DevicesManager::switch_to_simulation_device(const QString& fname)
@@ -304,3 +385,4 @@ void DevicesManager::SetupAbstractDevices()
BroadcasterDevice * brodDevice = new BroadcasterDevice();
configuredDevices->push_back(brodDevice);
}
+
View
54 PushBurton2/devicesmanager.h
@@ -31,29 +31,20 @@
#include <QObject>
#include <QDebug>
-//Headers only necessary when bluetooth is available/on symbian device
-#ifdef Q_OS_SYMBIAN
-#include <QBluetooth/QBtDevice.h>
-#include <QBluetooth/QBtService.h>
-#include <QBluetooth/QBtConstants.h>
-#include <QBluetooth/QBluetooth.h>
-#include <QBluetooth/QBtDeviceDiscoverer.h>
-#include <QBluetooth/QBtServiceDiscoverer.h>
-#include <QBluetooth/QBtSerialPortClient.h>
-#include <QBluetooth/QBtLocalDevice.h>
-#endif
#include <QSignalMapper>
#include "pushdevicesholder.h"
-#ifdef Q_OS_SYMBIAN
-#include "pushn8btdevice.h"
-#include "pushn8footdevice.h"
-#include "pushn8gsrdevice.h"
-#include "pushn8imudevice.h"
-#include "pushn8heartdevice.h"
-#endif
+#include <QBluetoothAddress>
+#include <QBluetoothDeviceDiscoveryAgent>
+#include <QBluetoothServiceDiscoveryAgent>
+#include <QBluetoothDeviceInfo>
+#include <QBluetoothLocalDevice>
+
+#include <QMap>
+
+#include "qtmpushdevice.h"
#include "pushn8phoneacc.h"
#include "pushn8phonegps.h"
@@ -88,16 +79,22 @@ class DevicesManager : public QObject
void request_run_start();
void request_run_end();
+ void allDiscoveryFinished();
+
//This may seem abusive at first look
// but makes complete sense since they are just routed from
// signals comming from different objects and well.. at some point you need to break into!
public slots:
- //inner mechanisms
-#ifdef Q_OS_SYMBIAN
- void deviceFound(QBtDevice);
-#endif
+ void serviceDiscovered(QBluetoothServiceInfo info);
+ void srvcDiscErrorDetected(QBluetoothServiceDiscoveryAgent::Error error);
+ void srvcDiscoveryAgentFinished();
+
+ void deviceDiscovered(QBluetoothDeviceInfo info);
+ void deviceDiscErrorDetected(QBluetoothDeviceDiscoveryAgent::Error);
+ void deviceDiscoveryAgentFinished();
+
//comm with user app
void start_bt_search();
@@ -109,6 +106,11 @@ public slots:
private:
PushDevicesHolder * configuredDevices;
+ QBluetoothDeviceDiscoveryAgent * devDiscoveryAgent;
+ QBluetoothLocalDevice * localDevice;
+
+ QMap<QBluetoothAddress, QString> knownBtDevices;
+
bool searching;
bool auto_connect;
int auto_connect_to_kit;
@@ -119,14 +121,6 @@ public slots:
QSignalMapper connectedMapper;
QSignalMapper disconnectedMapper;
-#ifdef Q_OS_SYMBIAN
- QVector<QBtDevice> unknownFoundDevices;
- QBtDeviceDiscoverer * deviceDiscoverer;
-
- bool SetupDevice(QBtDevice);
- bool IsDeviceNovell(QBtDevice);
-#endif
-
void SetupPhoneDevices();
void SetupAbstractDevices();
View
126 PushBurton2/qtmpushdevice.cpp
@@ -0,0 +1,126 @@
+#include "qtmpushdevice.h"
+
+using namespace QtMobility;
+
+QtmPushDevice::QtmPushDevice(QBluetoothServiceInfo info, QObject *parent) :
+ PushBurtonGenericDevice(parent)
+{
+ timerId = 0;
+ timerPeriod = 25;
+ socket = 0;
+
+ socket = new QtMobility::QBluetoothSocket(QtMobility::QBluetoothSocket::RfcommSocket, this);
+
+ if(socket)
+ {
+ qDebug() << "Created socket";
+
+ connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket()));
+ connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
+ connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
+
+
+ connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(socketError(QBluetoothSocket::SocketError)));
+
+ socket->connectToService(info);
+ qDebug() << "ConnectToService done";
+ }
+
+ this->start_readings();
+
+}
+
+QtmPushDevice::~QtmPushDevice()
+{
+
+}
+
+
+void QtmPushDevice::readSocket()
+{
+ if(socket)
+ {
+ while (socket->canReadLine()) {
+ QByteArray line = socket->readLine();
+ qDebug() << "Received: " << line;
+
+ QString strLine(line);
+ QStringList heap = strLine.split(QRegExp("(,|;|\\n|\\r)+"), QString::SkipEmptyParts);
+
+ NPushIMUTick * newIMUTick = new NPushIMUTick(heap);
+
+ if(receivers(SIGNAL(reading_ready(NPushLogTick*))) > 0)
+ {
+ //anyone listening to us
+ emit reading_ready(newIMUTick);
+ } else {
+ delete newIMUTick;
+ }
+ }
+ }
+}
+
+QString QtmPushDevice::getName()
+{
+ return QString("push.qtm.bt.unknown");
+}
+
+bool QtmPushDevice::is_online()
+{
+ if(socket)
+ return(socket->isOpen());
+ else
+ return false;
+}
+
+void QtmPushDevice::disconnect_from_backend()
+{
+ if(socket)
+ {
+ socket->deleteLater();
+ socket = 0;
+ }
+}
+
+bool QtmPushDevice::subscribesToAny()
+{
+ return false;
+}
+
+bool QtmPushDevice::subscribesTo(PushBurtonGenericDevice *)
+{
+ return false;
+}
+
+void QtmPushDevice::socketConnected()
+{
+ qDebug() << "QBluetoothSocket connected";
+ this->start_readings();
+ emit connected();
+}
+
+void QtmPushDevice::socketDisconnected()
+{
+ qDebug() << "QBluetoothSocket disconnected";
+ this->stop_readings();
+ emit disconnected();
+}
+
+void QtmPushDevice::socketError(QBluetoothSocket::SocketError error)
+{
+ qDebug() << "QBluetoothSocket Error:" << error ;
+}
+
+void QtmPushDevice::timerEvent(QTimerEvent *)
+{
+ if(socket)
+ {
+ if(socket->isOpen() && socket->isWritable())
+ {
+// qDebug() << "Sent Request";
+ QByteArray text = "A\n";
+ socket->write(text);
+ }
+ }
+}
+
View
51 PushBurton2/qtmpushdevice.h
@@ -0,0 +1,51 @@
+#ifndef QTMPUSHDEVICE_H
+#define QTMPUSHDEVICE_H
+
+#include <QDebug>
+
+#include <QByteArray>
+#include <QDateTime>
+#include <QTimer>
+
+#include "pushburtongenericdevice.h"
+
+#include "npushimutick.h"
+#include <QStringList>
+
+#include <QBluetoothSocket>
+#include <QBluetoothServiceInfo>
+
+using namespace QtMobility;
+
+class QtmPushDevice : public PushBurtonGenericDevice
+{
+ Q_OBJECT
+public:
+ explicit QtmPushDevice(QBluetoothServiceInfo info, QObject *parent = 0);
+ ~QtmPushDevice();
+
+ virtual QString getName();
+
+ virtual bool is_online();
+
+ virtual void disconnect_from_backend();
+
+ virtual bool subscribesToAny();
+ virtual bool subscribesTo(PushBurtonGenericDevice* deviceType);
+
+public slots:
+ void socketConnected();
+ void socketDisconnected();
+ void socketError(QBluetoothSocket::SocketError);
+
+ void readSocket();
+
+protected:
+ void timerEvent(QTimerEvent *);
+
+private:
+ QBluetoothSocket * socket;
+
+};
+
+#endif // QTMPUSHDEVICE_H
Please sign in to comment.
Something went wrong with that request. Please try again.