AnalysisSystemForRadionucli.../AlertMessage.cpp
2024-06-04 15:27:02 +08:00

87 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "AlertMessage.h"
#include <QFile>
using namespace AlertData;
AlertMessage::AlertMessage()
{
}
AlertMessage::~AlertMessage()
{
}
bool AlertMessage::IsValid()
{
return bIsValid;
}
const AlertsInfo& AlertMessage::GetAlertsInfo()
{
return alerts_info;
}
void AlertMessage::ClearData()
{
bIsValid = false;
alerts_info.station_code.clear();
alerts_info.alert_type.clear();
alerts_info.date.clear();
alerts_info.time.clear();
alerts_info.desc.clear();
AbstractSpectrumDataMessage::ClearData();
}
bool AlertMessage::AnalyseMessgeBody(QTextStream &content)
{
const MessageInfo& msg = AbstractSpectrumDataMessage::GetMessageInfo();
if ( QLatin1String("ALERT_FLOW") != msg.data_type &&
QLatin1String("ALERT_SYSTEM") != msg.data_type &&
QLatin1String("ALERT_TEMP") != msg.data_type &&
QLatin1String("ALERT_UPS") != msg.data_type )
{
return bIsValid = false;
}
content >> alerts_info.station_code >> alerts_info.alert_type >> alerts_info.date >> alerts_info.time;
do
{
QString line = content.readLine();
if ( 0==line.compare(QLatin1String("STOP")) )
{
bIsValid = true; //检测到“STOP line”消息完整数据有效
break;
}
else if (content.atEnd())
{
bIsValid = false;
alerts_info.alert_type.clear();
alerts_info.date.clear();
alerts_info.desc.clear();
alerts_info.station_code.clear();
alerts_info.time.clear();
break;
}
else
{
// QString desc_row = QLatin1String("\n") + line;
QString desc_row;
if(alerts_info.desc.isEmpty())
{
desc_row = line;
}
else
{
desc_row = QLatin1String("\n") + line;
}
alerts_info.desc.append(desc_row);
}
}
while( !content.atEnd() );
return bIsValid;
}