-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbroker.cpp
175 lines (162 loc) · 5.76 KB
/
broker.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "broker.h"
#include "aliseconstants.h"
#include <QDebug>
using namespace Alise;
Broker::Broker(QObject *parent) : QObject(parent)
{
m_clientTimeoutTimer.setInterval(AliseConstants::ReplyTimeoutPeriod());
QObject::connect(&m_clientTimeoutTimer, &QTimer::timeout, [&] {
qDebug() << "Health Query Timeout";
setIndication(AliseConstants::FailureIndication);
});
m_oldCode = 0;
m_clientTimeoutTimer.start();
}
void Broker::updateBlock(const DataTypes::BlockStruct &blk)
{
emit receivedBlock(blk);
}
void Broker::updateTime(const timespec &time)
{
emit receivedTime(time);
}
// Health code received
//
// code bits: 0: 0 - there's some errors, 1 - no errors
// 1 - booter working
// 2 - adminja working
// 3 - core working
// 4 - alise working
// 5 - ninja working
// 6 - vasya working
// 7 - petya working
// 8-10 - booter status:
// 000 - no status (bit 1 = 0) or working normally (bit 1 = 1)
// 001 - not installed
// 010 - starting
// 011 - need to merge settings
// 100 - broken hash
// 101 - stopping
// 110 - stopped
// 111 - unknown status
// 11-13 - adminja status
// 14-16 - core status
// 17-19 - alise status
// 20-22 - ninja status
// 23-25 - vasya status
// 26-28 - petya status
// 29-31 - errors: 000 - no errors, 001 - unknown controller, 111 - unknown error
void Broker::healthReceived(uint32_t code)
{
m_clientTimeoutTimer.start(); // restart health query timeout timer
if (code == m_oldCode)
return;
m_oldCode = code;
uint8_t processStatus;
uint8_t mainHealthBits = (code >> 29) & 0x07; // main health bits - three MSB's
uint8_t healthCode = code & 0x000000FF; // health bits by component and overall health in LSB
uint32_t componentHealthCodes = (code >> 8) & 0x001FFFFF; // healthes by component
m_worstProcessNumber = 0;
m_worstProcessError = NORMAL; // 0 - no errors, 1 - starting/stopping, 2 - stopped, 3 - error
AVTUK_CCU::Indication indic;
qDebug() << "Setting indication: " << code;
qDebug() << "MainHealthBits = " << mainHealthBits << "HealthCode = " << healthCode
<< "ComponentHealthCodes = " << componentHealthCodes;
if (mainHealthBits || !(healthCode & 0x01))
indic = AliseConstants::FailureIndication;
else
{
for (int i = 0; i < numberOfProcesses; ++i)
{
processStatus = (componentHealthCodes & 0x00000007);
componentHealthCodes >>= 3;
qDebug() << "processStatus now is: " << processStatus;
if (healthCode & (0x02 << i)) // process working
{
qDebug() << "healthCode for " << i << " = 1";
// check three bits in corresponding position
switch (processStatus)
{
case Alise::NEEDTOMERGE:
case Alise::BROKENHASH:
setSemiWorkingProcessError(i);
break;
case Alise::CHECKHTHBIT: // working normally
break; // default value is NORMAL
default:
qDebug() << "processStatus is unknown: " << processStatus << " not 0, 3, 4";
setFailedProcessError(i);
break;
}
}
else // process isn't working
{
qDebug() << "healthCode for " << i << " = 0";
// check three bits in corresponding position
switch (processStatus)
{
// any failure causes failed indication
case Alise::NOTINSTALLED:
case Alise::CHECKHTHBIT:
break; // that's normal for now, checking remains
case Alise::UNKNOWN:
case Alise::BROKENHASH:
setFailedProcessError(i);
break;
case Alise::STARTING:
case Alise::STOPPING:
setStartingProcessError(i);
break;
case Alise::NEEDTOMERGE:
case Alise::STOPPED:
setStoppedProcessError(i);
break;
}
}
}
if (m_worstProcessError == Alise::NORMAL) // all is good
indic = AliseConstants::NormalIndication;
else
{
indic.PulseCnt1 = firstPulsesCount; // first count is for showing status
indic.PulseCnt2 = m_worstProcessNumber + 1; // second count is the number of process
indic.PulseFreq1 = AliseConstants::ProcessBlink(m_worstProcessError);
indic.PulseFreq2 = numberFreq;
}
}
setIndication(indic);
}
void Broker::setStartingProcessError(int index)
{
if ((m_worstProcessError != Alise::RED) && (m_worstProcessError != Alise::VIOLET)
&& (m_worstProcessError != Alise::ORANGE))
{
qDebug() << "set mode YELLOW for " << index << " component";
m_worstProcessNumber = index;
m_worstProcessError = Alise::YELLOW;
}
}
void Broker::setStoppedProcessError(int index)
{
if ((m_worstProcessError != Alise::RED) && (m_worstProcessError != Alise::VIOLET))
{
qDebug() << "set mode ORANGE for " << index << " component";
m_worstProcessNumber = index;
m_worstProcessError = Alise::ORANGE;
}
}
void Broker::setFailedProcessError(int index)
{
qDebug() << "set mode FAILED for " << index << " component";
m_worstProcessNumber = index;
m_worstProcessError = Alise::RED;
}
void Broker::setSemiWorkingProcessError(int index)
{
if (m_worstProcessError != Alise::RED)
{
qDebug() << "set mode VIOLET for " << index << " component";
m_worstProcessNumber = index;
m_worstProcessError = Alise::VIOLET;
}
}