-
Notifications
You must be signed in to change notification settings - Fork 0
/
motordata.cpp
201 lines (170 loc) · 4.24 KB
/
motordata.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "motordata.h"
#include "paramwidget.h"
#include "motorform.h"
const int nTotalCount = 10;
MotorData::MotorData(const int nModeId,QObject *parent) :
QObject(parent),
m_nModeIdx(nModeId)
{
}
NormalModeData::NormalModeData(const int nRegulationCnt, const int nParamCnt, const int nActualCnt, const int nModeIdx, QObject *parent):
MotorData(nModeIdx,parent)
{
for (int i=0;i<nRegulationCnt;++i)
m_regulation.push_back(0);
for (int i=0;i<nParamCnt;++i)
m_param.push_back(0);
for (int i=0;i<nActualCnt;++i)
m_actural.push_back(0);
}
void NormalModeData::setRegulation(int nId, const qreal value)
{
if (nId>=0 && nId < m_regulation.size())
m_regulation[nId] = value;
}
qreal NormalModeData::getRegulation(int nId, bool *bOK)
{
if (nId>=0 && nId < m_regulation.size())
{
if(bOK)
*bOK = true;
return m_regulation.at(nId);
}
if(bOK)
*bOK = false;
return -1;
}
void NormalModeData::setParam(int nId, const qreal value)
{
if (nId>=0 && nId < m_param.size())
m_param[nId] = value;
}
qreal NormalModeData::getParam(int nId, bool *bOK)
{
if (nId>=0 && nId < m_param.size())
{
if(bOK)
*bOK = true;
return m_param.at(nId);
}
if(bOK)
*bOK = false;
return -1;
}
void NormalModeData::setActual(int nId, const qreal value)
{
if (nId>=0 && nId < m_actural.size())
{
if(nId == 0)
{
m_acturalCurrent.push_back(value);
if (m_acturalCurrent.size() >= nTotalCount)
{
qreal total = 0;
foreach (qreal perValue, m_acturalCurrent) {
total += perValue;
}
m_actural[nId] = total/nTotalCount;
m_acturalCurrent.clear();
}
}
else
{
m_actural[nId] = value;
}
}
}
qreal NormalModeData::getActual(int nId, bool *bOK)
{
if (nId>=0 && nId < m_actural.size())
{
if(bOK)
*bOK = true;
return m_actural.at(nId);
}
if(bOK)
*bOK = false;
return -1;
}
//data manager
DataMgr::DataMgr(const int nCurIdx, QObject *parent):
QObject(parent),
m_nCurIdx(nCurIdx)
{
}
qreal DataMgr::getRegulationValue(const int nId, bool *bOK)
{
return getRegulationValue(m_nCurIdx,nId,bOK);
}
void DataMgr::setRegulationValue(const int nId, qreal value)
{
setRegulationValue(m_nCurIdx,nId,value);
}
qreal DataMgr::getRegulationValue(const int nModeId, const int nId, bool *bOK)
{
MotorData * pData = getData(nModeId);
if(pData)
return pData->getRegulation(nId,bOK);
return -1;
}
void DataMgr::setActualValue(const int nModeId, const int nId, qreal value)
{
MotorData * pData = getData(nModeId);
if(pData)
pData->setActual(nId,value);
}
qreal DataMgr::getActualValue(const int nId, bool *bOK)
{
return getActualValue(m_nCurIdx,nId,bOK);
}
void DataMgr::setActualValue(const int nId, qreal value)
{
setActualValue(m_nCurIdx,nId,value);
}
qreal DataMgr::getActualValue(const int nModeId, const int nId, bool *bOK)
{
MotorData * pData = getData(nModeId);
if(pData)
return pData->getActual(nId,bOK);
return -1;
}
void DataMgr::setParamValue(const int nModeId, const int nId, qreal value)
{
MotorData * pData = getData(nModeId);
if(pData)
pData->setParam(nId,value);
}
qreal DataMgr::getParamValue(const int nId, bool *bOK)
{
return getParamValue(m_nCurIdx,nId,bOK);
}
void DataMgr::setParamValue(const int nId, qreal value)
{
setParamValue(m_nCurIdx,nId,value);
}
qreal DataMgr::getParamValue(const int nModeId, const int nId, bool *bOK)
{
MotorData * pData = getData(nModeId);
if(pData)
return pData->getParam(nId,bOK);
return -1;
}
void DataMgr::setRegulationValue(const int nModeId, const int nId, qreal value)
{
MotorData * pData = getData(nModeId);
if(pData)
pData->setRegulation(nId,value);
}
void DataMgr::changeCurIdx(const int nCurIdx)
{
m_nCurIdx = nCurIdx;
}
MotorData *DataMgr::getData(const int nIdx)
{
MotorData * pData = nullptr;
foreach (MotorData *tmp, m_vDatas) {
if(tmp->GetModeId() == nIdx)
return tmp;
}
return pData;
}