diff --git a/pvtoolsSrc/pvutils.cpp b/pvtoolsSrc/pvutils.cpp index 56e45ef..f7c85f2 100644 --- a/pvtoolsSrc/pvutils.cpp +++ b/pvtoolsSrc/pvutils.cpp @@ -184,6 +184,60 @@ std::ostream& printTimeT(std::ostream& o, epics::pvData::PVStructure::shared_poi return o; } +const char* severityNames[] = { + "NO_ALARM", // 0 + "MINOR", + "MAJOR", + "INVALID", + "UNDEFINED" // 4 +}; + +const char* statusNames[] = { + "NO_STATUS", // 0 + "DEVICE", + "DRIVER", + "RECORD", + "DB", + "CONF", + "UNDEFINED", + "CLIENT" // 7 +}; + +std::ostream& printAlarmT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvAlarmT) +{ + PVInt::shared_pointer pvSeverity = pvAlarmT->getSubField("severity"); + if (!pvSeverity) + throw std::runtime_error("alarm_t structure does not have 'int severity' field"); + + PVInt::shared_pointer pvStatus = pvAlarmT->getSubField("status"); + if (!pvStatus) + throw std::runtime_error("alarm_t structure does not have 'int status' field"); + + PVString::shared_pointer pvMessage = pvAlarmT->getSubField("message"); + if (!pvMessage) + throw std::runtime_error("alarm_t structure does not have 'string message' field"); + + int32 v = pvSeverity->get(); + if (v < 0 || v > 4) + o << v; + else + o << severityNames[v]; + o << separator; + + v = pvStatus->get(); + if (v < 0 || v > 7) + o << v; + else + o << statusNames[v]; + o << separator; + if (pvMessage->get().empty()) + o << ""; + else + o << pvMessage->get(); + return o; +} + + bool isTType(epics::pvData::PVStructure::shared_pointer const & pvStructure) { // "forget" about Ttype if disabled @@ -192,7 +246,8 @@ bool isTType(epics::pvData::PVStructure::shared_pointer const & pvStructure) string id = pvStructure->getStructure()->getID(); return (id == "enum_t" || - id == "time_t"); + id == "time_t" || + id == "alarm_t"); } bool formatTType(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvStructure) @@ -211,6 +266,11 @@ bool formatTType(std::ostream& o, epics::pvData::PVStructure::shared_pointer con printTimeT(o, pvStructure); return true; } + else if (id == "alarm_t") + { + printAlarmT(o, pvStructure); + return true; + } } return false; diff --git a/pvtoolsSrc/pvutils.h b/pvtoolsSrc/pvutils.h index ec2bfb4..f7fbb25 100644 --- a/pvtoolsSrc/pvutils.h +++ b/pvtoolsSrc/pvutils.h @@ -29,6 +29,7 @@ std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure const & pvE std::ostream& printEnumT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvEnumT); std::ostream& printTimeT(std::ostream& o, epics::pvData::PVStructure::shared_pointer const & pvTimeT); + /* Converts a hex character to its integer value */ char from_hex(char ch);