Commit a4088b9d authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

alarm entry for alarm attrribute error

parent 44f6ce87
...@@ -148,91 +148,96 @@ void AlarmTreeWidget::refresh(const CuData &v) { ...@@ -148,91 +148,96 @@ void AlarmTreeWidget::refresh(const CuData &v) {
QString ts = QDateTime::fromSecsSinceEpoch(d).toString("HH:mm:ss"); QString ts = QDateTime::fromSecsSinceEpoch(d).toString("HH:mm:ss");
ts += QString("+%1").arg(d - static_cast<int>(d)); ts += QString("+%1").arg(d - static_cast<int>(d));
QString src = QuString(v, "src"); QString src = QuString(v, "src");
QString dev = src.section('/', 0, src.count('/') - 1);
bool err = v["err"].toBool(); bool err = v["err"].toBool();
QStringList data = QuStringList(v, "value"); QStringList data;
setToolTip(QuString(v, "msg")); setToolTip(QuString(v, "msg"));
/* remove the filter */ /* remove the filter */
if (err) { if (err) {
src = src.section('/', 0, src.count('/') - 1); src = dev;
data = m_gen_error_item(v); data << m_gen_error_item(v);
perr("%s: %s\n", qstoc(src), qstoc(toolTip())); perr("%s: %s\n", qstoc(src), qstoc(toolTip()));
m_dev_err.insert(dev);
printf("\e[1;31mAlarmTreeWidget::refresh: src \e[1;33m%s\e[1;31m is in ERRROR\e[0m\n", qstoc(src));
} }
else { else {
int scrollBarPos; m_dev_err.remove(dev);
QStringList fields;
QStringList alrnames;
AlarmTreeWidgetItem* item = NULL;
data = QuStringList(v, "value"); data = QuStringList(v, "value");
QStringList high, medium, low, lowest, unknown_level; }
// group by level in order to sort view
foreach(QString row, data) {
QString level = row.split("\t").at(AlarmTreeWidget::LEVEL);
if(level.contains("high"))
high << row;
else if(level.contains("lowest"))
lowest << row;
else if(level.contains("medium"))
medium << row;
else if(level.contains("low"))
low << row;
else
unknown_level << row;
}
data = unknown_level + lowest + low + medium + high;
int index = 0;
const QSet<QString> oldset = mSrcAlarmHash.value(src);
QSet<QString>& alsrcset = mSrcAlarmHash[src];
alsrcset.clear(); // empty set for src
/* add items to the tree(s) if not already present */
for (int i = data.size() - 1; i >= 0; i--) {
fields = data[i].split("\t");
alrnames << fields.at(AlarmTreeWidgetItem::Alarm);
/* save current scroll bar value */
scrollBarPos = verticalScrollBar()->value();
/* instead of GROUP information, show DEVICE */
fields[DEVICE] = src.section('/', 0, src.count('/') - 1);
item = mItemHash.value(fields.at(AlarmTreeWidgetItem::Alarm));
if(!item) /* create a new item */ {
index = findPos(fields[0].toUInt(), fields[AlarmTreeWidgetItem::Level], fields[AlarmTreeWidgetItem::Status]);
m_insert_item(src, fields, index);
// printf("\e[1;33m%s \e[1;34m%s - number of tabs %d -- index %d\e[0m\n",
// qstoc(QDateTime::fromTime_t(fields.first().toUInt()).toString()),
// qstoc(data[i]), data[i].count("\t"), index);
}
else /* update fields of existing items */
item->update(fields);
/* restore scrollbar value */ int scrollBarPos;
verticalScrollBar()->setValue(scrollBarPos); QStringList fields;
QStringList alrnames;
AlarmTreeWidgetItem* item = NULL;
QStringList high, medium, low, lowest, unknown_level;
// group by level in order to sort view
foreach(QString row, data) {
QString level = row.split("\t").at(AlarmTreeWidget::LEVEL);
if(level.contains("high"))
high << row;
else if(level.contains("lowest"))
lowest << row;
else if(level.contains("medium"))
medium << row;
else if(level.contains("low"))
low << row;
else
unknown_level << row;
}
data = unknown_level + lowest + low + medium + high;
int index = 0;
const QSet<QString> oldset = mSrcAlarmHash.value(src);
QSet<QString>& alsrcset = mSrcAlarmHash[src];
alsrcset.clear(); // empty set for src
/* add items to the tree(s) if not already present */
for (int i = data.size() - 1; i >= 0; i--) {
fields = data[i].split("\t");
alrnames << fields.at(AlarmTreeWidgetItem::Alarm);
/* save current scroll bar value */
scrollBarPos = verticalScrollBar()->value();
/* instead of GROUP information, show DEVICE */
fields[DEVICE] = src.section('/', 0, src.count('/') - 1);
item = mItemHash.value(fields.at(AlarmTreeWidgetItem::Alarm));
if(!item) /* create a new item */ {
index = findPos(fields[0].toUInt(), fields[AlarmTreeWidgetItem::Level], fields[AlarmTreeWidgetItem::Status]);
m_insert_item(src, fields, index);
// printf("\e[1;33m%s \e[1;34m%s - number of tabs %d -- index %d\e[0m\n",
// qstoc(QDateTime::fromTime_t(fields.first().toUInt()).toString()),
// qstoc(data[i]), data[i].count("\t"), index);
}
else /* update fields of existing items */
item->update(fields);
// add alarm name to set of alarm names for this src /* restore scrollbar value */
alsrcset.insert(fields.at(AlarmTreeWidgetItem::Alarm)); verticalScrollBar()->setValue(scrollBarPos);
// notify new alarm detected. connected to Alarm::beep // add alarm name to set of alarm names for this src
if(fields.size() > 5 && (fields[3] == "ALARM" || fields[3] == "ERROR") && fields.last() == "NEW") alsrcset.insert(fields.at(AlarmTreeWidgetItem::Alarm));
emit newAlarmDetected();
}
/* remove stale items */ // notify new alarm detected. connected to Alarm::beep
QSet<QString> stale = oldset - alsrcset; if(fields.size() > 5 && (fields[3] == "ALARM" || fields[3] == "ERROR") && fields.last() == "NEW")
m_remove_stale_items(stale); emit newAlarmDetected();
} }
/* remove stale items */
QSet<QString> stale = oldset - alsrcset;
m_remove_stale_items(stale);
} }
int AlarmTreeWidget::findPos(time_t ts, const QString &pri, const QString& status) { int AlarmTreeWidget::findPos(time_t ts, const QString &pri, const QString& status) {
int i = 0, prio = m_pri_to_int(pri), stat = m_status_to_int(status); int i = 0, prio = m_pri_to_int(pri), stat = m_status_to_int(status);
// printf("findPos called with ts %ld, pri %d\n", ts, prio); // printf("findPos called with ts %ld, pri %d\n", ts, prio);
while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() > stat) { while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() > stat) {
// printf("1st pri %d pri %d --> i %d\n", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i); // printf("1st pri %d pri %d --> i %d\n", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i);
i++; i++;
} }
while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt() > prio while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt() > prio
&& topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() == stat) { && topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() == stat) {
// printf("1st pri %d pri %d --> i %d\n", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i); // printf("1st pri %d pri %d --> i %d\n", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i);
i++; i++;
} }
// i points to the first item with same pri or to the very last item in the view // i points to the first item with same pri or to the very last item in the view
...@@ -240,7 +245,7 @@ int AlarmTreeWidget::findPos(time_t ts, const QString &pri, const QString& statu ...@@ -240,7 +245,7 @@ int AlarmTreeWidget::findPos(time_t ts, const QString &pri, const QString& statu
while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::DateTime, Qt::UserRole).toUInt() > ts while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::DateTime, Qt::UserRole).toUInt() > ts
&& topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt() == prio && topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt() == prio
&& topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() == stat) { && topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() == stat) {
// printf("1st ts %u item ts %u --> i %d\n", ts, topLevelItem(i)->data(AlarmTreeWidgetItem::DateTime, Qt::UserRole).toUInt(), i); // printf("1st ts %u item ts %u --> i %d\n", ts, topLevelItem(i)->data(AlarmTreeWidgetItem::DateTime, Qt::UserRole).toUInt(), i);
i++; i++;
} }
return i; return i;
...@@ -306,13 +311,14 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list, ...@@ -306,13 +311,14 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list,
mItemHash.insert(fields.at(AlarmTreeWidgetItem::Alarm), item); mItemHash.insert(fields.at(AlarmTreeWidgetItem::Alarm), item);
} }
QStringList AlarmTreeWidget::m_gen_error_item(const CuData &da) const { QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const {
QStringList l; QStringList l;
QDateTime dt = QDateTime::currentDateTime(); QDateTime dt = QDateTime::currentDateTime();
QString dev = QuString(da, "src"); QString dev = QuString(da, "src"), msg = QuString(da, "msg");
dev = dev.section('/', 0, dev.count('/') - 1); dev = dev.section('/', 0, dev.count('/') - 1);
l << dt.toString() << "-" << dev << "ERROR" << "NACK" << "1" << "high" << "-1" << "gr_handler" << QuString(da, "msg"); l << QString::number(dt.toSecsSinceEpoch()) << "-" << dev << "ERROR" << "NACK" << "1" << "high" << "-1" << "gr_handler"
return l; << msg.replace("\n", " ") << "NEW";
return l.join("\t");
} }
......
...@@ -49,11 +49,12 @@ private: ...@@ -49,11 +49,12 @@ private:
int m_status_to_int(const QString& stat); int m_status_to_int(const QString& stat);
void m_remove_stale_items(const QSet<QString> stale_names); void m_remove_stale_items(const QSet<QString> stale_names);
void m_insert_item(const QString &src, const QStringList &list, int index); void m_insert_item(const QString &src, const QStringList &list, int index);
QStringList m_gen_error_item(const CuData& da) const; QString m_gen_error_item(const CuData& da) const;
bool _filter_enabled; bool _filter_enabled;
QHash<QString, AlarmTreeWidgetItem*> mItemHash; QHash<QString, AlarmTreeWidgetItem*> mItemHash;
QHash<QString, QSet<QString> >mSrcAlarmHash; QHash<QString, QSet<QString> >mSrcAlarmHash;
QSet<QString> m_dev_err;
Type m_type; Type m_type;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment