-
Notifications
You must be signed in to change notification settings - Fork 0
/
processthread.cpp
104 lines (98 loc) · 2.85 KB
/
processthread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// https://github.com/enderceliik
// Ender CELIK
#include "processthread.h"
#include "serialcom.h"
#include "database.h"
#include "synchronization.h"
#include "mainwindow.h"
void ProcessThread::run()
{
QEventLoop loop;
QByteArray responseFromCommunication;
while(true)
{
while(threadWorkSitutation)
{
qDebug() << "Serial port reading in progress...";
responseFromCommunication = glob_pointer_array_sync[0]->read();
if(responseFromCommunication.isEmpty())
{
emit afterProcessSignal("Port did not open");
threadWorkSitutation = false;
return;
}
if(!strcmp(responseFromCommunication, "#####") == 0) // if: If the response differs from the protocol we have sent
{
qDebug() << responseFromCommunication;
database_com(responseFromCommunication);
}
}
while(threadFuelWorkSituation)
{
qDebug() << "Fuel is being supplied...";
fuel_counter = fuel_counter + 0.1;
emit updateFuelValue(fuel_counter);
msleep(200);
loop.processEvents();
if((fuel_counter >= my_stc.fuel) || (!threadFuelWorkSituation))
{
emit afterFuelProcessSignal(fuel_counter);
threadFuelWorkSituation = false;
fuel_counter = 0;
break;
}
}
while(true)
{
qDebug() << "Waiting ...";
msleep(750);
loop.processEvents();
if(threadWorkSitutation||threadFuelWorkSituation)
break;
}
}
}
void ProcessThread::database_com(QByteArray response)
{
QByteArray responseHex = response.toHex();
QString officerID = QString(responseHex.mid(#, #));
qDebug() << officerID;
Database* databaseObject = new Database();
if(databaseObject->control_card_id(officerID)) // false: doesn't exist
{
messageForUpdateUI = "Registered officer found";
}
else
{
messageForUpdateUI = "Registered officer not found";
}
delete databaseObject;
threadWorkSitutation = false;
emit afterProcessSignal(messageForUpdateUI);
}
void ProcessThread::threadStarter(bool parameter)
{
qDebug() << "Thread starting...";
if(parameter)
{
this->threadWorkSitutation = true;
QTimer::singleShot(10000, this, SLOT(fifteenSecondControllerTerminate()));
}
else
{
threadFuelWorkSituation = true;
}
}
void ProcessThread::fifteenSecondControllerTerminate()
{
if(threadWorkSitutation)
{
qDebug() << " 10 seconds ";
threadWorkSitutation = false;
emit afterProcessSignal("Card not read");
}
}
void ProcessThread::threadStopFuel()
{
threadFuelWorkSituation = false;
}