Permalink
Browse files

Adding Bcaster prototype

  • Loading branch information...
Clovis Scotti
Clovis Scotti committed Jun 8, 2011
1 parent 6d78503 commit 9690258d88114dc5ac8745e25bffd07e090c00f5
@@ -26,7 +26,7 @@
#-------------------------------------------------
-QT += core gui xml phonon
+QT += core gui xml phonon network
TARGET = PushBurton2
TEMPLATE = app
@@ -78,7 +78,8 @@ SOURCES += main.cpp\
graphicssettings.cpp \
virtualbrosdevice.cpp \
rotationcounter.cpp \
- npushrotationstick.cpp
+ npushrotationstick.cpp \
+ broadcasterdevice.cpp
HEADERS += mainwindow.h \
graphicpixmapbt.h \
@@ -127,7 +128,8 @@ HEADERS += mainwindow.h \
FilesystemConventions.h \
virtualbrosdevice.h \
rotationcounter.h \
- npushrotationstick.h
+ npushrotationstick.h \
+ broadcasterdevice.h
FORMS += mainwindow.ui \
liveview.ui
@@ -0,0 +1,136 @@
+#include "broadcasterdevice.h"
+
+BroadcasterDevice::BroadcasterDevice(QObject *parent) :
+ PushBurtonGenericDevice(parent)
+{
+
+ running = false;
+
+
+ xmlWriter = 0;
+
+ currConnection = 0;
+
+
+
+ serverAddress = QHostAddress("192.168.0.3");
+
+ serverPort = 45454;
+
+}
+
+
+BroadcasterDevice::~BroadcasterDevice()
+{
+ if(currConnection)
+ currConnection->disconnectFromHost();
+}
+
+
+QString BroadcasterDevice::get_description()
+{
+ return QString("push.n8.broadcaster");
+}
+
+
+bool BroadcasterDevice::start_run()
+{
+ if(!running) {
+ running = true;
+ return true;
+ }
+ return false;
+}
+
+bool BroadcasterDevice::end_run()
+{
+ if(running) {
+ running = false;
+
+ return true;
+ }
+ return false;
+}
+
+void BroadcasterDevice::incoming_reading(NPushLogTick * tick)
+{
+ if(running) {
+ if(xmlWriter && currConnection->isWritable()) {
+ tick->dump_to_xml(*xmlWriter);
+ currConnection->flush();
+ }
+ }
+}
+
+void BroadcasterDevice::connected()
+{
+ qDebug() << "Connected";
+ xmlWriter = new QXmlStreamWriter(currConnection);
+ qDebug() << "coupled with xml writer";
+
+ emit connectionUpdate(true);
+}
+
+void BroadcasterDevice::disconnected()
+{
+ if(xmlWriter) {
+ delete xmlWriter;
+ xmlWriter = 0;
+ }
+ if(currConnection) {
+ currConnection->close();
+ currConnection->deleteLater();
+ currConnection = 0;
+ }
+ emit connectionUpdate(false);
+}
+
+void BroadcasterDevice::tryToConnect()
+{
+ if(currConnection) {
+ qDebug() << "Cleaning up old connection";
+ currConnection->close();
+ currConnection->deleteLater();
+ currConnection = 0;
+ }
+
+ qDebug() << "Trying to establish new connection";
+
+ currConnection = new QTcpSocket(this);
+
+ currConnection->connectToHost(serverAddress, serverPort, QIODevice::WriteOnly);
+
+ connect(currConnection, SIGNAL(connected()),
+ this, SLOT(connected()));
+
+ connect(currConnection, SIGNAL(disconnected()),
+ this, SLOT(disconnected()));
+}
+
+void BroadcasterDevice::setServerAddress(const QString &addr)
+{
+ serverAddress.setAddress(addr);
+ qDebug() << "Address set to " << serverAddress.toString();
+}
+
+void BroadcasterDevice::setServerPort(quint16 port)
+{
+ serverPort = port;
+ qDebug() << "Port set to " << serverPort;
+}
+
+void BroadcasterDevice::tryToDisconnect()
+{
+ if(xmlWriter) {
+ delete xmlWriter;
+ xmlWriter = 0;
+ }
+
+ if(currConnection) {
+ currConnection->close();
+ currConnection->deleteLater();
+ currConnection = 0;
+ }
+
+ emit connectionUpdate(false);
+}
@@ -0,0 +1,68 @@
+#ifndef BROADCASTERDEVICE_H
+#define BROADCASTERDEVICE_H
+
+#include "npushlogtick.h"
+#include "pushburtongenericdevice.h"
+
+#include <QtNetwork>
+#include <QHostAddress>
+#include <QXmlStreamWriter>
+#include <QIODevice>
+
+#include <QDebug>
+
+class BroadcasterDevice : public PushBurtonGenericDevice
+{
+ Q_OBJECT
+public:
+ explicit BroadcasterDevice(QObject *parent = 0);
+
+ ~BroadcasterDevice();
+
+
+ QString get_description();
+ bool is_online() {
+ return true;
+ }
+
+ //Our device subscribes to other devices so we need to reimplement these 2 functions
+ //accordingly. One can argue that subscribesToAny wouldn't be necessary but it SURE
+ //prevents doing a huge amount of unnecessary checks.
+ bool subscribesToAny() { return true; }
+
+ //This function will return true when the given device is a AirTimeDetector
+ bool subscribesTo(PushBurtonGenericDevice*) { return true; }
+
+ bool start_run();
+ bool end_run();
+
+signals:
+ void connectionUpdate(bool connState);
+
+public slots:
+
+ void tryToConnect();
+ void tryToDisconnect();
+
+ void setServerAddress(const QString& addr);
+ void setServerPort(quint16 port);
+
+ void connected();
+ void disconnected();
+ void incoming_reading(NPushLogTick *);
+
+private:
+ bool running;
+
+ QHostAddress serverAddress;
+ quint16 serverPort;
+
+
+ QTcpSocket *currConnection;
+
+ QXmlStreamWriter *xmlWriter;
+
+
+};
+
+#endif // BROADCASTERDEVICE_H
@@ -282,8 +282,6 @@ void DevicesManager::SetupPhoneDevices()
connect(phoneGPS, SIGNAL(disconnected()), &disconnectedMapper, SLOT(map()));
disconnectedMapper.setMapping(phoneGPS, "Location");
-// emit phone_gps_connecting();
-// connect(phoneGPS, SIGNAL(connected()), this, SIGNAL(phone_gps_connected()));
}
void DevicesManager::SetupAbstractDevices()
@@ -300,6 +298,9 @@ void DevicesManager::SetupAbstractDevices()
RotationCounter * spin2WinKid = new RotationCounter();
configuredDevices->push_back(spin2WinKid);
-// VirtualBrosDevice * virtualBros = new VirtualBrosDevice();
-// configuredDevices->push_back(virtualBros);
+ VirtualBrosDevice * virtualBros = new VirtualBrosDevice();
+ configuredDevices->push_back(virtualBros);
+
+ BroadcasterDevice * brodDevice = new BroadcasterDevice();
+ configuredDevices->push_back(brodDevice);
}
@@ -59,6 +59,8 @@
#include "pushn8phonegps.h"
#include "pushn8phonemag.h"
+#include "broadcasterdevice.h"
+
#include "pushn8absnormfeetdevice.h"
#include "pushn8airtimedetector.h"
#include "pushn8simplereportsgenerator.h"
@@ -54,16 +54,18 @@ FuzzyDetector::FuzzyDetector()
ia_onAir.push_back(Relation(-10.0, 0.0));
ia_onAir.push_back(Relation(-0.5, 0.0));
+ ia_onAir.push_back(Relation(-0.4, 0.6));
ia_onAir.push_back(Relation(0.0, 1.0));
ia_onAir.push_back(Relation(1.0, 1.0));
ia_onAir.push_back(Relation(1.5, 0.0));
ia_onAir.push_back(Relation(10.0, 0.0));
ia_onGrnd.push_back(Relation(-10.0, 1.0));
- ia_onGrnd.push_back(Relation(-3.0, 1.0));
- ia_onGrnd.push_back(Relation(-1.0, 0.6));
- ia_onGrnd.push_back(Relation(-0.3, 0.0));
- ia_onGrnd.push_back(Relation(10.0, 0.0));
+ ia_onGrnd.push_back(Relation(-1.5, 1.0));
+ ia_onGrnd.push_back(Relation(-1.0, 0.8));
+ ia_onGrnd.push_back(Relation(-0.6, 0.0));
+ ia_onGrnd.push_back(Relation(1.0, 0.0));
+ ia_onGrnd.push_back(Relation(3.0, 1.0));
// bpa_onGrnd.push_back(Relation(0.0, 0.0));
// bpa_onGrnd.push_back(Relation(0.85, 0.0));
@@ -102,14 +104,6 @@ Response FuzzyDetector::FuzzyficateToAirOrGround(double fp, double pa, double ia
og_ia = ia_onGrnd.fuzificate(ia);
}
-// if(!isnan(bpa)) {
-// og_bpa = bpa_onGrnd.fuzificate(bpa);
-// }
-
- //Most certain dictates all
-// double onAir = std::max(oa_fp, std::max(oa_pa, oa_ia));
-// double onGround = std::max(og_fp, std::max(og_pa, og_ia));
-
//Sum of all votes
double onAir = (oa_fp+oa_pa+oa_ia)/3.0;
double onGround = (og_fp+og_pa+og_ia)/3.0;//+og_bpa)/3.0;
@@ -131,22 +125,6 @@ Response FuzzyDetector::FuzzyficateToAirOrGround(double fp, double pa, double ia
resp = CantHelpYouOnThisOne;
}
-// QString sresp;
-// if(resp == FlyingLikeAnEagle) {
-// sresp = " AIR ";
-// } else if(resp == SlidingDownLikeAPenguin) {
-// sresp = " GROUND ";
-// } else {
-// sresp = " UNKNOWN ";
-// }
-
-// qDebug() << sresp << ": onAir (" << onAir << ") " << oa_fp <<"(fp)/"
-// << oa_pa <<"(pa)/"
-// << oa_ia << "(ia), onGround (" << onGround << ")"
-// << og_fp <<"(fp)/"
-// << og_pa <<"(pa)/"
-// << og_ia << "ia";
-
return resp;
}
Oops, something went wrong.

0 comments on commit 9690258

Please sign in to comment.