Fotobot
Get data from your photovoltaic plant
invertors.cpp
Go to the documentation of this file.
1 
7 #include "invertors.h"
8 #include "fronius.h"
9 #include "static.h"
10 
11 
12 INVERTORS::INVERTORS(QCoreApplication *p) : QObject(p) {
13  m_invertors.clear();
14  m_timer = new QTimer(this);
15  m_timer->setSingleShot(true);
16  m_timer->setInterval(7000);
17  connect(m_timer, SIGNAL(timeout()),
18  this, SLOT(slotQuitInvertors()));
19  connect(Static::db, SIGNAL(databaseChanged()),
20  this, SLOT(databaseChanged()));
21 
22  m_timerWorking = new QTimer(this);
23  m_timerWorking->setSingleShot(true);
24  m_timerWorking->setInterval(1000);
25  connect(m_timerWorking, SIGNAL(timeout()),
26  this, SLOT(slotCountWorking()));
27  m_timerWorking->start();
28 }
29 
30 
38  m_timer->start();
39 }
40 
41 
46  emit quitInvertors();
47  QTimer::singleShot(5000, this, SLOT(closeLines()));
48 }
49 
50 
52  m_timerWorking->stop();
53  m_timerWorking->setInterval(1000);
54  QCoreApplication::processEvents();
55  for (int i=0; i<m_invertors.size(); i++) {
56  m_invertors.at(i)->wait(250);
57  m_invertors.at(i)->terminate();
58  delete m_invertors.at(i);
59  }
60  m_invertors.clear();
61  openLines();
62  m_timerWorking->start();
63  qWarning() << "INVERTORS::closeLines(): configuration reloaded";
64 }
65 
66 
67 QList<INVERTOR_status> INVERTORS::status() {
68  QList<INVERTOR_status> list;
69  for (int i=0; i<m_invertors.size(); i++) {
70  INVERTOR_status s = m_invertors.at(i)->status();
71  for (int w=0; w<m_working.size(); w++) {
72  if (m_working.at(w).line == s.line) {
73  s.working = m_working.at(w).working;
74  s.invertors = m_working.at(w).invertors;
75  }
76  }
77  list << s;
78  }
79  return list;
80 }
81 
82 
84  m_working = Static::db->linesStatus();
85  m_timerWorking->setInterval(30000);
86  m_timerWorking->start();
87 }
88 
89 
94  QList<DBT_LINES> lines = Static::db->lines();
95  for (int i=0; i<lines.size(); i++) {
96  QList<DBT_INVERTORS> invertors = Static::db->invertors(lines.at(i).line);
97  INVERTOR *f = INVERTOR::create(lines[i].type); // new FRONIUS();
98  f->setLine(lines.at(i));
99  f->setInvertors(invertors);
100  f->start();
101  connect (this, SIGNAL(quitInvertors()),
102  f, SLOT(quit()),
103  Qt::QueuedConnection);
104  connect (f, SIGNAL(data(DBT_DATA)),
105  this, SLOT(slotStoreData(DBT_DATA)),
106  Qt::QueuedConnection);
107  connect (this, SIGNAL(storeData(DBT_DATA)),
108  Static::db, SLOT(insertData(DBT_DATA)),
109  Qt::QueuedConnection);
110  connect (f, SIGNAL(loopFinished(int,int)),
111  Static::db, SLOT(commit()),
112  Qt::QueuedConnection);
113  connect (f, SIGNAL( loopFinished(int,int)),
114  this, SLOT(slotLoopFinished(int,int)),
115  Qt::QueuedConnection);
116  connect (f, SIGNAL(data(DBT_DATA)),
117  this, SLOT(data(DBT_DATA)),
118  Qt::QueuedConnection);
119  m_invertors << f;
120  }
121 }
122 
123 
125  qDebug() << QString("%1 sun=%2 pwr=%3 err=%4")
126  .arg(x.invertor)
127  .arg(Static::slunce->alt())
128  .arg(x.now_power.toInt())
129  .arg(x.error)
130  ;
131  return;
132  if (x.error.isEmpty()) {
133  qDebug() << "invertor=" << x.invertor
134  << "power=" << x.now_power
135  << "dc current=" << x.now_dc_current
136  << "dc voltage=" << x.now_dc_voltage
137  << "ac current=" << x.now_ac_current
138  << "ac voltage=" << x.now_ac_voltage
139  << "ac frequency=" << x.now_ac_frequency
140  << "\n"
141  << "ac voltage max=" << x.day_ac_voltage_maximum
142  << "ac voltage min=" << x.day_ac_voltage_minimum
143  << "dc voltage max=" << x.day_dc_voltage_maximum
144  << "powr max=" << x.day_power_maximum
145  << "hours=" << x.day_operating_hours
146  << "energy=" << x.day_energy
147  << "\n"
148  << "ac voltage max=" << x.total_ac_voltage_maximum
149  << "ac voltage min=" << x.total_ac_voltage_minimum
150  << "dc voltage max=" << x.total_dc_voltage_maximum
151  << "powr max=" << x.total_power_maximum
152  << "hours=" << x.total_operating_hours
153  << "energy=" << x.total_energy
154  ;
155  } else {
156  qDebug() << "invertor=" << x.invertor
157  << "err=" << x.error
158  ;
159  }
160 }
161 
162 void INVERTORS::slotLoopFinished(int number_of_ok, int number_of_err) {
163  if (number_of_ok > 0) return;
164  if (number_of_ok <= 0 || number_of_err <= 0) return;
165  if (Static::slunce == NULL || Static::slunce->alt() < 0.0) return;
166 
167  Static::interfacebox->restart();
168 }
169 
171  if (Static::slunce == NULL || Static::slunce->alt() > -18.0) { // astronomický soumrak
172  emit storeData(d);
173  }
174 }
175 
QTimer * m_timerWorking
Timer for periodic status update.
Definition: invertors.h:120
QList< DBT_LINES > lines(int line=0)
Returns list of communications lines.
Definition: database.cpp:380
QTimer * m_timer
Timer for database changes responses.
Definition: invertors.h:118
void data(DBT_DATA)
For debugging only, writes read data to console.
Definition: invertors.cpp:124
virtual void setLine(const DBT_LINES &)
Sets the parameters for the line.
Definition: invertor.cpp:42
void slotQuitInvertors()
Slot is called a few seconds after configuration change.
Definition: invertors.cpp:45
QList< INVERTOR * > m_invertors
List of all invertors.
Definition: invertors.h:117
void restart()
Restarts all connected interfaceboxes.
int invertors
Number of invertors.
Class describing database table DATA.
void databaseChanged()
Slot is called when configuration changed in database.
Definition: invertors.cpp:37
int line
line number (database id)
QList< DBT_INVERTORS > invertors(int line=0)
Returns list of invertors filtered by line number.
Definition: database.cpp:411
void storeData(DBT_DATA)
Signal for database to store invertor data.
QList< DBT_LINES_STATUS > m_working
List of working invertors.
Definition: invertors.h:121
int working
Number of working invertors.
void openLines()
Opens all configured invertors.
Definition: invertors.cpp:93
virtual void setInvertors(const QList< DBT_INVERTORS > &)
Sets the list of invertors connected to the line.
Definition: invertor.cpp:49
void slotLoopFinished(int number_of_ok, int number_of_err)
Slot is called when the line finished the reading cycle.
Definition: invertors.cpp:162
Stores the invertors status.
static INVERTOR * create(DBT_LINES::Type)
Factory makes instances depending on type.
Definition: invertor.cpp:17
Virtual class for invertor communication.
Definition: invertor.h:28
QList< INVERTOR_status > status()
Returns list of current invertors status.
Definition: invertors.cpp:67
void closeLines()
Closes all existing invertors and destoroy their instances.
Definition: invertors.cpp:51
void slotCountWorking()
Count working invertors.
Definition: invertors.cpp:83
QList< DBT_LINES_STATUS > linesStatus()
Returns status of lines.
Definition: database.cpp:1186
void quitInvertors()
Signal for invertors to quit.
void start(Priority priority=InheritPriority)
Starts the thread.
Definition: invertor.cpp:36
void slotStoreData(DBT_DATA)
Slot for handling of requests for storing of invertor data in database.
Definition: invertors.cpp:170