diff --git a/.gitignore b/.gitignore index 44f996c51bf0094017262207e78b297650e5605f..e6a64c445f74bd87e406e1c44fca9800c376f43d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -test.log \ No newline at end of file +test.log +groundStation/gui/build* +.gdb_history diff --git a/groundStation/gui/MicroCART/MicroCART.pro b/groundStation/gui/MicroCART/MicroCART.pro index cd3d24f692062a3f8e5af3a5a922fd813a9c9170..874beeab9d98f9f1a9314e2c86726d21ab7191bc 100644 --- a/groundStation/gui/MicroCART/MicroCART.pro +++ b/groundStation/gui/MicroCART/MicroCART.pro @@ -13,8 +13,10 @@ TEMPLATE = app SOURCES += main.cpp\ - mainwindow.cpp + mainwindow.cpp \ + wrappers.c -HEADERS += mainwindow.h +HEADERS += mainwindow.h \ + wrappers.h FORMS += mainwindow.ui diff --git a/groundStation/gui/MicroCART/mainwindow.cpp b/groundStation/gui/MicroCART/mainwindow.cpp index 49d64fce7cedf4ed8c5e0124cfe43e90c23c6ab6..01aa006e06ba3d63f34841a8bb6c11e1f165ffa2 100644 --- a/groundStation/gui/MicroCART/mainwindow.cpp +++ b/groundStation/gui/MicroCART/mainwindow.cpp @@ -1,6 +1,8 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "wrappers.h" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -12,3 +14,27 @@ MainWindow::~MainWindow() { delete ui; } + +void MainWindow::on_pbStart_clicked() +{ + this->backendPid = startBackend(); + findChild<QPushButton *>("pbStart")->setEnabled(false); + findChild<QPushButton *>("pbConnect")->setEnabled(false); + findChild<QPushButton *>("pbStop")->setEnabled(true); +} + +void MainWindow::on_pbConnect_clicked() +{ + // TODO: Connect to existing backend (what is connected?) + findChild<QPushButton *>("pbStart")->setEnabled(false); + findChild<QPushButton *>("pbConnect")->setEnabled(false); + findChild<QPushButton *>("pbStop")->setEnabled(true); +} + +void MainWindow::on_pbStop_clicked() +{ + stopBackend(backendPid); + findChild<QPushButton *>("pbStart")->setEnabled(true); + //findChild<QPushButton *>("pbConnect")->setEnabled(true); + findChild<QPushButton *>("pbStop")->setEnabled(false); +} diff --git a/groundStation/gui/MicroCART/mainwindow.h b/groundStation/gui/MicroCART/mainwindow.h index a3948a91785f23b0d16b2459b21c04ee7f0a845e..08c56474fa70af9423135e32c9005ef2e0bae9bf 100644 --- a/groundStation/gui/MicroCART/mainwindow.h +++ b/groundStation/gui/MicroCART/mainwindow.h @@ -15,8 +15,17 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); +private slots: + void on_pbStart_clicked(); + + void on_pbConnect_clicked(); + + void on_pbStop_clicked(); + private: Ui::MainWindow *ui; + pid_t backendPid; + int backendState; }; #endif // MAINWINDOW_H diff --git a/groundStation/gui/MicroCART/mainwindow.ui b/groundStation/gui/MicroCART/mainwindow.ui index f3ddeb8234d8e791bcd22bd3305e1d3213ec7349..c613f8104b06d6a5eae17f8a0cb43fc278f03154 100644 --- a/groundStation/gui/MicroCART/mainwindow.ui +++ b/groundStation/gui/MicroCART/mainwindow.ui @@ -54,6 +54,9 @@ </item> <item> <widget class="QPushButton" name="pbConnect"> + <property name="enabled"> + <bool>false</bool> + </property> <property name="text"> <string>Connect</string> </property> diff --git a/groundStation/gui/MicroCART/wrappers.c b/groundStation/gui/MicroCART/wrappers.c new file mode 100644 index 0000000000000000000000000000000000000000..58f718fc86ba7516457e651f95678ca91eb6461c --- /dev/null +++ b/groundStation/gui/MicroCART/wrappers.c @@ -0,0 +1,26 @@ +#include "wrappers.h" +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> +#include <signal.h> +#include <stdlib.h> + +int stopBackend(int pid) +{ + kill(pid, SIGTERM); + int status; + wait(&status); + return status; +} + +int startBackend() +{ + int pid = fork(); + if (!pid) { + // TODO: Make dynamic + // TODO: Redirect stdout to pipe to GUI + execl("backEnd", "backEnd", NULL); + exit(0); + } + return pid; +} diff --git a/groundStation/gui/MicroCART/wrappers.h b/groundStation/gui/MicroCART/wrappers.h new file mode 100644 index 0000000000000000000000000000000000000000..0ac1d1151499f54c12204b5153e1ccf43e469c03 --- /dev/null +++ b/groundStation/gui/MicroCART/wrappers.h @@ -0,0 +1,16 @@ +#ifndef WRAPPERS_H +#define WRAPPERS_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +int startBackend(void); +int stopBackend(int pid); + +#ifdef __cplusplus +} +#endif + +#endif // WRAPPERS_H