Skip to content

Commit 3623d78

Browse files
authored
Initial project git files.
1 parent 0383edd commit 3623d78

32 files changed

+4407
-0
lines changed

RatModule.pro

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2019-05-31T10:16:50
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui charts network
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = RatModule
12+
TEMPLATE = app
13+
14+
# The following define makes your compiler emit warnings if you use
15+
# any feature of Qt which has been marked as deprecated (the exact warnings
16+
# depend on your compiler). Please consult the documentation of the
17+
# deprecated API in order to know how to port your code away from it.
18+
DEFINES += QT_DEPRECATED_WARNINGS
19+
20+
# You can also make your code fail to compile if you use deprecated APIs.
21+
# In order to do so, uncomment the following line.
22+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
23+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
24+
25+
CONFIG += c++11
26+
27+
SOURCES += \
28+
cmd.cpp \
29+
config.cpp \
30+
dialog.cpp \
31+
fields.cpp \
32+
main.cpp \
33+
mainwindow.cpp \
34+
myserver.cpp \
35+
settings.cpp \
36+
thread.cpp \
37+
ue.cpp
38+
39+
HEADERS += \
40+
cmd.h \
41+
config.h \
42+
cpu.h \
43+
dialog.h \
44+
fields.h \
45+
mainwindow.h \
46+
myserver.h \
47+
settings.h \
48+
thread.h \
49+
ue.h
50+
51+
FORMS += \
52+
config.ui \
53+
dialog.ui \
54+
fields.ui \
55+
mainwindow.ui \
56+
settings.ui
57+
58+
# Default rules for deployment.
59+
qnx: target.path = /tmp/$${TARGET}/bin
60+
else: unix:!android: target.path = /opt/$${TARGET}/bin
61+
!isEmpty(target.path): INSTALLS += target
62+

RatModule.pro.user

Lines changed: 340 additions & 0 deletions
Large diffs are not rendered by default.

RatModule.pro.user.b5fc943

Lines changed: 337 additions & 0 deletions
Large diffs are not rendered by default.

ap.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "ap.h"
2+
3+
ap::ap()
4+
{
5+
6+
}

ap.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef AP_H
2+
#define AP_H
3+
4+
#include <QtCharts/QtCharts>
5+
#include <QtCharts/QChartView>
6+
#include <QTimer>
7+
#include <QtCharts/QLineSeries>
8+
#include <QtCharts/QAreaSeries>
9+
#include <QHash>
10+
11+
12+
class ap
13+
{
14+
public:
15+
ap();
16+
QList<QLineSeries*> series_list;
17+
QHash<QString,int> series_hash;
18+
19+
};
20+
21+
#endif // AP_H

cmd.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "cmd.h"
2+
3+

cmd.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ----------------CLASS DEFINATION OF COMMANDS WE SAVE-----------------------
2+
3+
#ifndef CMD_H
4+
#define CMD_H
5+
#include <QString>
6+
#include <QDataStream>
7+
8+
class cmd
9+
{
10+
11+
public:
12+
int num;
13+
int type;
14+
bool fields;
15+
QString name;
16+
QString cmdstr;
17+
cmd(int n=0, QString nam="", QString postcm="",int type2 = 0)
18+
{
19+
num = n;
20+
name = nam;
21+
cmdstr = postcm;
22+
type = type2;
23+
fields = true;
24+
}
25+
26+
27+
28+
friend QDataStream &operator<<(QDataStream &out, const cmd &command)
29+
{
30+
out << int(command.num) << command.name
31+
<< command.cmdstr << int(command.type) << bool(command.fields);
32+
return out;
33+
}
34+
35+
friend QDataStream &operator>>(QDataStream &in, cmd &command)
36+
{
37+
QString name;
38+
QString postcmd;
39+
int type;
40+
int num;
41+
bool fields;
42+
in >> num >> name >> postcmd >> type >> fields;
43+
command = cmd(num,name,postcmd,type);
44+
return in;
45+
}
46+
47+
};
48+
49+
50+
#endif // CMD_H

config.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// THis class is mainly fo configuring the file //
2+
3+
#include "config.h"
4+
#include "ui_config.h"
5+
6+
config::config(QString path , QWidget *parent) :
7+
QDialog(parent),
8+
ui(new Ui::config)
9+
{
10+
ui->setupUi(this);
11+
12+
fpath = path;
13+
14+
QFile inputFile(path);
15+
if (inputFile.open(QIODevice::ReadOnly))
16+
{
17+
QTextStream in(&inputFile);
18+
QString text = in.readAll();
19+
ui->plainTextEdit->setPlainText(text);
20+
inputFile.close();
21+
}
22+
}
23+
24+
config::~config()
25+
{
26+
delete ui;
27+
}
28+
29+
// On clicking save this is executed
30+
// Output to the file aswell as the socket
31+
32+
void config::on_buttonBox_accepted()
33+
{
34+
QString path = fpath;
35+
36+
QFile outputFile(path);
37+
if (outputFile.open(QIODevice::WriteOnly | QFile::Text))
38+
{
39+
QTextStream out(&outputFile);
40+
out << ui->plainTextEdit->toPlainText();
41+
outputFile.flush();
42+
outputFile.close();
43+
}
44+
45+
QByteArray str = ui->plainTextEdit->toPlainText().toUtf8();
46+
47+
emit sockwrite(str);
48+
49+
}
50+
51+
// On clickiing the config file. The previous value must be shown
52+
53+
void config::created()
54+
{
55+
QString path = fpath;
56+
QFile inputFile(path);
57+
if (inputFile.open(QIODevice::ReadOnly))
58+
{
59+
QTextStream in(&inputFile);
60+
QString text = in.readAll();
61+
ui->plainTextEdit->setPlainText(text);
62+
inputFile.close();
63+
}
64+
65+
}

config.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef CONFIG_H
2+
#define CONFIG_H
3+
4+
#include <QDialog>
5+
#include <QtCore>
6+
#include <QtGui>
7+
8+
namespace Ui {
9+
class config;
10+
}
11+
12+
class config : public QDialog
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
explicit config(QString path, QWidget *parent = nullptr);
18+
~config();
19+
20+
private slots:
21+
void on_buttonBox_accepted();
22+
23+
signals:
24+
void sockwrite(QByteArray str);
25+
26+
public slots:
27+
void created();
28+
29+
private:
30+
Ui::config *ui;
31+
QString fpath;
32+
};
33+
34+
#endif // CONFIG_H

config.ui

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>config</class>
4+
<widget class="QDialog" name="config">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>901</width>
10+
<height>826</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Dialog</string>
15+
</property>
16+
<layout class="QHBoxLayout" name="horizontalLayout">
17+
<item>
18+
<layout class="QVBoxLayout" name="verticalLayout_2">
19+
<item>
20+
<widget class="QLabel" name="label">
21+
<property name="text">
22+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:12pt; font-weight:600;&quot;&gt;Configuration File&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
23+
</property>
24+
</widget>
25+
</item>
26+
<item>
27+
<layout class="QVBoxLayout" name="verticalLayout">
28+
<item>
29+
<widget class="QPlainTextEdit" name="plainTextEdit"/>
30+
</item>
31+
<item>
32+
<widget class="QDialogButtonBox" name="buttonBox">
33+
<property name="orientation">
34+
<enum>Qt::Horizontal</enum>
35+
</property>
36+
<property name="standardButtons">
37+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
38+
</property>
39+
</widget>
40+
</item>
41+
</layout>
42+
</item>
43+
</layout>
44+
</item>
45+
</layout>
46+
</widget>
47+
<resources/>
48+
<connections>
49+
<connection>
50+
<sender>buttonBox</sender>
51+
<signal>accepted()</signal>
52+
<receiver>config</receiver>
53+
<slot>accept()</slot>
54+
<hints>
55+
<hint type="sourcelabel">
56+
<x>248</x>
57+
<y>254</y>
58+
</hint>
59+
<hint type="destinationlabel">
60+
<x>157</x>
61+
<y>274</y>
62+
</hint>
63+
</hints>
64+
</connection>
65+
<connection>
66+
<sender>buttonBox</sender>
67+
<signal>rejected()</signal>
68+
<receiver>config</receiver>
69+
<slot>reject()</slot>
70+
<hints>
71+
<hint type="sourcelabel">
72+
<x>316</x>
73+
<y>260</y>
74+
</hint>
75+
<hint type="destinationlabel">
76+
<x>286</x>
77+
<y>274</y>
78+
</hint>
79+
</hints>
80+
</connection>
81+
</connections>
82+
</ui>

cpu.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef CPU_H
2+
#define CPU_H
3+
4+
#include "stdlib.h"
5+
#include "stdio.h"
6+
#include "string.h"
7+
8+
static unsigned long long lastTotalUser, lastTotalUserLow, lastTotalSys, lastTotalIdle;
9+
10+
void init(){
11+
FILE* file = fopen("/proc/stat", "r");
12+
fscanf(file, "cpu %llu %llu %llu %llu", &lastTotalUser, &lastTotalUserLow,
13+
&lastTotalSys, &lastTotalIdle);
14+
fclose(file);
15+
}
16+
17+
double getCurrentValue(){
18+
double percent;
19+
FILE* file;
20+
unsigned long long totalUser, totalUserLow, totalSys, totalIdle, total;
21+
22+
file = fopen("/proc/stat", "r");
23+
fscanf(file, "cpu %llu %llu %llu %llu", &totalUser, &totalUserLow,
24+
&totalSys, &totalIdle);
25+
fclose(file);
26+
27+
if (totalUser < lastTotalUser || totalUserLow < lastTotalUserLow ||
28+
totalSys < lastTotalSys || totalIdle < lastTotalIdle){
29+
//Overflow detection. Just skip this value.
30+
percent = -1.0;
31+
}
32+
else{
33+
total = (totalUser - lastTotalUser) + (totalUserLow - lastTotalUserLow) +
34+
(totalSys - lastTotalSys);
35+
percent = total;
36+
total += (totalIdle - lastTotalIdle);
37+
percent /= total;
38+
percent *= 100;
39+
}
40+
41+
lastTotalUser = totalUser;
42+
lastTotalUserLow = totalUserLow;
43+
lastTotalSys = totalSys;
44+
lastTotalIdle = totalIdle;
45+
46+
return percent;
47+
}
48+
49+
#endif // CPU_H

0 commit comments

Comments
 (0)