From f66536d84b38aa0eb46e928fdaf13d7da790b2ee Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Sun, 4 Jun 2017 16:26:56 +0930 Subject: added HTML/JS/PHP pages/scripts to allow RGB changes over a web page. Integrated a server into the application to allow incoming connections and receive commands --- qt/RGBController/.controllerwindow.cpp.swn | Bin 0 -> 16384 bytes qt/RGBController/Makefile | 45 ++++++++++++++++------ qt/RGBController/RGBController | Bin 136960 -> 143248 bytes qt/RGBController/RGBController.pro | 6 ++- qt/RGBController/controllerwindow.cpp | 39 ++++++++++++++++++- qt/RGBController/controllerwindow.h | 15 ++++++-- qt/RGBController/controllerwindow.ui | 59 ++++++++++++++++++++--------- qt/RGBController/irc.cpp | 2 +- qt/RGBController/server.cpp | 54 ++++++++++++++++++++++++++ qt/RGBController/server.h | 26 +++++++++++++ 10 files changed, 210 insertions(+), 36 deletions(-) create mode 100644 qt/RGBController/.controllerwindow.cpp.swn create mode 100644 qt/RGBController/server.cpp create mode 100644 qt/RGBController/server.h (limited to 'qt/RGBController') diff --git a/qt/RGBController/.controllerwindow.cpp.swn b/qt/RGBController/.controllerwindow.cpp.swn new file mode 100644 index 0000000..bc195e4 Binary files /dev/null and b/qt/RGBController/.controllerwindow.cpp.swn differ diff --git a/qt/RGBController/Makefile b/qt/RGBController/Makefile index f615390..4f437ac 100644 --- a/qt/RGBController/Makefile +++ b/qt/RGBController/Makefile @@ -50,13 +50,17 @@ OBJECTS_DIR = ./ SOURCES = main.cpp \ controllerwindow.cpp \ - irc.cpp moc_controllerwindow.cpp \ - moc_irc.cpp + irc.cpp \ + server.cpp moc_controllerwindow.cpp \ + moc_irc.cpp \ + moc_server.cpp OBJECTS = main.o \ controllerwindow.o \ irc.o \ + server.o \ moc_controllerwindow.o \ - moc_irc.o + moc_irc.o \ + moc_server.o DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/common/unix.conf \ /usr/lib/qt/mkspecs/common/linux.conf \ @@ -281,9 +285,11 @@ DIST = /usr/lib/qt/mkspecs/features/spec_pre.prf \ /usr/lib/qt/mkspecs/features/yacc.prf \ /usr/lib/qt/mkspecs/features/lex.prf \ RGBController.pro controllerwindow.h \ - irc.h main.cpp \ + irc.h \ + server.h main.cpp \ controllerwindow.cpp \ - irc.cpp + irc.cpp \ + server.cpp QMAKE_TARGET = RGBController DESTDIR = TARGET = RGBController @@ -769,8 +775,8 @@ distdir: FORCE @test -d $(DISTDIR) || mkdir -p $(DISTDIR) $(COPY_FILE) --parents $(DIST) $(DISTDIR)/ $(COPY_FILE) --parents /usr/lib/qt/mkspecs/features/data/dummy.cpp $(DISTDIR)/ - $(COPY_FILE) --parents controllerwindow.h irc.h $(DISTDIR)/ - $(COPY_FILE) --parents main.cpp controllerwindow.cpp irc.cpp $(DISTDIR)/ + $(COPY_FILE) --parents controllerwindow.h irc.h server.h $(DISTDIR)/ + $(COPY_FILE) --parents main.cpp controllerwindow.cpp irc.cpp server.cpp $(DISTDIR)/ $(COPY_FILE) --parents controllerwindow.ui $(DISTDIR)/ @@ -803,10 +809,12 @@ compiler_moc_predefs_clean: moc_predefs.h: /usr/lib/qt/mkspecs/features/data/dummy.cpp g++ -pipe -O2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -Wall -W -dM -E -o moc_predefs.h /usr/lib/qt/mkspecs/features/data/dummy.cpp -compiler_moc_header_make_all: moc_controllerwindow.cpp moc_irc.cpp +compiler_moc_header_make_all: moc_controllerwindow.cpp moc_irc.cpp moc_server.cpp compiler_moc_header_clean: - -$(DEL_FILE) moc_controllerwindow.cpp moc_irc.cpp + -$(DEL_FILE) moc_controllerwindow.cpp moc_irc.cpp moc_server.cpp moc_controllerwindow.cpp: ui_controllerwindow.h \ + irc.h \ + server.h \ controllerwindow.h \ moc_predefs.h \ /usr/bin/moc @@ -817,6 +825,11 @@ moc_irc.cpp: irc.h \ /usr/bin/moc /usr/bin/moc $(DEFINES) --include ./moc_predefs.h -I/usr/lib/qt/mkspecs/linux-g++ -I'/home/daniel_j/documents/school/2016 research project/RGBController/qt/RGBController' -I/usr/include/qt -I/usr/include/qt/QtWidgets -I/usr/include/qt/QtGui -I/usr/include/qt/QtSerialPort -I/usr/include/qt/QtNetwork -I/usr/include/qt/QtCore -I/usr/include/c++/6.3.1 -I/usr/include/c++/6.3.1/x86_64-pc-linux-gnu -I/usr/include/c++/6.3.1/backward -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include -I/usr/local/include -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include-fixed -I/usr/include irc.h -o moc_irc.cpp +moc_server.cpp: server.h \ + moc_predefs.h \ + /usr/bin/moc + /usr/bin/moc $(DEFINES) --include ./moc_predefs.h -I/usr/lib/qt/mkspecs/linux-g++ -I'/home/daniel_j/documents/school/2016 research project/RGBController/qt/RGBController' -I/usr/include/qt -I/usr/include/qt/QtWidgets -I/usr/include/qt/QtGui -I/usr/include/qt/QtSerialPort -I/usr/include/qt/QtNetwork -I/usr/include/qt/QtCore -I/usr/include/c++/6.3.1 -I/usr/include/c++/6.3.1/x86_64-pc-linux-gnu -I/usr/include/c++/6.3.1/backward -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include -I/usr/local/include -I/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.1/include-fixed -I/usr/include server.h -o moc_server.cpp + compiler_moc_source_make_all: compiler_moc_source_clean: compiler_uic_make_all: ui_controllerwindow.h @@ -837,22 +850,32 @@ compiler_clean: compiler_moc_predefs_clean compiler_moc_header_clean compiler_ui ####### Compile main.o: main.cpp controllerwindow.h \ - ui_controllerwindow.h + ui_controllerwindow.h \ + irc.h \ + server.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp controllerwindow.o: controllerwindow.cpp controllerwindow.h \ - ui_controllerwindow.h + ui_controllerwindow.h \ + irc.h \ + server.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o controllerwindow.o controllerwindow.cpp irc.o: irc.cpp irc.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o irc.o irc.cpp +server.o: server.cpp server.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o server.o server.cpp + moc_controllerwindow.o: moc_controllerwindow.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_controllerwindow.o moc_controllerwindow.cpp moc_irc.o: moc_irc.cpp $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_irc.o moc_irc.cpp +moc_server.o: moc_server.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_server.o moc_server.cpp + ####### Install install: FORCE diff --git a/qt/RGBController/RGBController b/qt/RGBController/RGBController index 7b54e8c..a6cfd3f 100755 Binary files a/qt/RGBController/RGBController and b/qt/RGBController/RGBController differ diff --git a/qt/RGBController/RGBController.pro b/qt/RGBController/RGBController.pro index 07060da..a4ed2e3 100755 --- a/qt/RGBController/RGBController.pro +++ b/qt/RGBController/RGBController.pro @@ -14,10 +14,12 @@ TEMPLATE = app SOURCES += main.cpp\ controllerwindow.cpp \ - irc.cpp + irc.cpp \ + server.cpp HEADERS += controllerwindow.h \ - irc.h + irc.h \ + server.h FORMS += controllerwindow.ui diff --git a/qt/RGBController/controllerwindow.cpp b/qt/RGBController/controllerwindow.cpp index 7c4f552..dd21ece 100755 --- a/qt/RGBController/controllerwindow.cpp +++ b/qt/RGBController/controllerwindow.cpp @@ -12,9 +12,12 @@ controllerWindow::controllerWindow(QWidget *parent) : connect(ser, &QSerialPort::readyRead, this, &controllerWindow::read); ptimer = new QTimer(this); connect(ptimer, SIGNAL(timeout()), this, SLOT(ping())); - connect (&ircbot, SIGNAL(sendcmd(QString)), this, SLOT(cmdrecv(QString))); + connect(&ircbot, SIGNAL(sendcmd(QString)), this, SLOT(cmdrecv(QString))); + connect(&srv, SIGNAL(sendcmd(QString)), this, SLOT(cmdrecv(QString))); pingtries = 0; irccon = false; + pingcount = 0; + server_started = false; /* disable buttons and widgets that should not be enabled yet, set slider values to 0 */ ui->disconnect_button->setEnabled(false); ui->connect_button->setEnabled(false); @@ -413,6 +416,7 @@ void controllerWindow::on_off_button_clicked() ui->r_slider->setValue(0); ui->g_slider->setValue(0); ui->b_slider->setValue(0); + send("off"); } void controllerWindow::on_set_preset_button_clicked() @@ -616,6 +620,8 @@ void controllerWindow::ping() send("ping\n"); tping = false; QTimer::singleShot(1000, this, SLOT(check_ping())); + pingcount++; + ui->ping_count_label->setText("Ping: " + QString::number(pingcount)); } void controllerWindow::check_ping() @@ -658,6 +664,37 @@ void controllerWindow::on_irc_connect_button_clicked() } } +void controllerWindow::on_server_start_button_clicked() +{ + if (!server_started) + { + if (srv.server_start()) + { + server_started = true; + ui->server_start_button->setText("Stop server"); + info_log("Server started"); + } + else + { + info_log("Server could not start"); + } + } + + else if (server_started) + { + if (srv.server_stop()) + { + server_started = false; + ui->server_start_button->setText("Start server"); + info_log("Server stopped"); + } + else + { + info_log("Server not not be stopped"); + } + } +} + void controllerWindow::cmdrecv(QString cmd) { qDebug() << "got cmd" << cmd; diff --git a/qt/RGBController/controllerwindow.h b/qt/RGBController/controllerwindow.h index a9196d2..b36d70b 100755 --- a/qt/RGBController/controllerwindow.h +++ b/qt/RGBController/controllerwindow.h @@ -15,6 +15,7 @@ #include #include "ui_controllerwindow.h" #include "irc.h" +#include "server.h" namespace Ui { class controllerWindow; @@ -64,7 +65,7 @@ class controllerWindow : public QMainWindow void cmdrecv(QString cmd); private slots: /* these slots are used to trigger button clicks and drop down items selections etc */ - void on_connect_button_clicked(); + void on_connect_button_clicked(); void on_disconnect_button_clicked(); @@ -120,16 +121,22 @@ class controllerWindow : public QMainWindow void on_bto_valueChanged(int arg1); - void on_serial_send_button_clicked(); + void on_serial_send_button_clicked(); void ping(); void check_ping(); - void on_irc_connect_button_clicked(); + void on_irc_connect_button_clicked(); -private: + void on_server_start_button_clicked(); + + + private: Ui::controllerWindow *ui; bool irccon; irc ircbot; + server srv; + int pingcount; + bool server_started; }; #endif // CONTROLLERWINDOW_H diff --git a/qt/RGBController/controllerwindow.ui b/qt/RGBController/controllerwindow.ui index 63a91b1..0a10269 100644 --- a/qt/RGBController/controllerwindow.ui +++ b/qt/RGBController/controllerwindow.ui @@ -9,8 +9,8 @@ 0 0 - 364 - 238 + 433 + 254 @@ -21,7 +21,7 @@ - 4 + 5 @@ -528,21 +528,21 @@ - + Server - + irc.danieljon.es - + @@ -558,42 +558,42 @@ - + Channel - + #csgo - + Name - + LightBot - + Port - + Connect @@ -602,15 +602,40 @@ + + + Server + + + + + + + + Start server + + + + + + + Log - + - + + + + Send + + + + @@ -620,10 +645,10 @@ - - + + - Send + Ping diff --git a/qt/RGBController/irc.cpp b/qt/RGBController/irc.cpp index 50f7fac..9c3c14d 100644 --- a/qt/RGBController/irc.cpp +++ b/qt/RGBController/irc.cpp @@ -33,7 +33,7 @@ void irc::read() buf = "JOIN " + channel + "\r\n"; socket->write(buf.toUtf8()); } - if (line.contains("!")) /* mostl ikely a message to handle */ + if (line.contains("!")) /* most likely a message to handle */ handle(line); if(socket->canReadLine()) read(); diff --git a/qt/RGBController/server.cpp b/qt/RGBController/server.cpp new file mode 100644 index 0000000..85e43ee --- /dev/null +++ b/qt/RGBController/server.cpp @@ -0,0 +1,54 @@ +#include "server.h" + +server::server(QObject *parent) : QObject(parent) +{ + srv = new QTcpServer(); + connect(srv, SIGNAL(newConnection()), this, SLOT(new_connection())); +} + +bool server::server_start() +{ + if (srv->listen(QHostAddress::Any, 3001)) + { + return true; + } + else + { + return false; + } +} + +bool server::server_stop() +{ + srv->close(); + if (srv->isListening()) + return false; + return true; +} + +void server::new_connection() +{ + QTcpSocket *socket; + socket = srv->nextPendingConnection(); + socket->waitForReadyRead(3000); + handle(QString(socket->readAll()).remove(QRegExp("[\\n\\t\\r]"))); + socket->close(); + delete socket; +} + +void server::handle(QString msg) +{ + if (msg.contains(";")) + { + QStringList tmp = msg.split(";"); + for (int x = 0; x < tmp.size(); x++) + { + emit sendcmd(tmp.at(x)); + } + } + else + { + emit sendcmd(msg); + } + +} diff --git a/qt/RGBController/server.h b/qt/RGBController/server.h new file mode 100644 index 0000000..8d46539 --- /dev/null +++ b/qt/RGBController/server.h @@ -0,0 +1,26 @@ +#ifndef SERVER_H +#define SERVER_H + +#include +#include + +class server : public QObject +{ + Q_OBJECT + public: + explicit server(QObject *parent = 0); + bool server_start(); + bool server_stop(); + private: + QTcpServer *srv; + void handle(QString msg); + private slots: + void new_connection(); +signals: + void sendcmd(QString cmd); + + + public slots: +}; + +#endif // SERVER_H -- cgit v1.2.3