-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:pushsnowboarding/Push-Snowboarding
Conflicts: PushBurton2/PushBurton2.pro.user
- Loading branch information
Showing
50 changed files
with
2,443 additions
and
1,714 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#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::getName() | ||
{ | ||
|
||
return QString("push.network.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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 getName(); | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.