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

85 lines
2.2 KiB
C++
Raw Permalink 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 "MeteorologicalMessage.h"
#include <QFile>
using namespace MetData;
MeteorologicalMessage::MeteorologicalMessage():bIsValid(false)
{
}
MeteorologicalMessage::~MeteorologicalMessage()
{
}
bool MeteorologicalMessage::IsValid()
{
return bIsValid;
}
const QList<MetDataItem>& MeteorologicalMessage::GetMetDatas()
{
return met_datas;
}
const MetData::MetDataStationCode& MeteorologicalMessage::GetStationCode()
{
return station_code;
}
void MeteorologicalMessage::ClearData()
{
bIsValid = false;
met_datas.clear();
AbstractSpectrumDataMessage::ClearData();
}
bool MeteorologicalMessage::AnalyseMessgeBody(QTextStream &content)
{
const MessageInfo& msg = AbstractSpectrumDataMessage::GetMessageInfo();
if ( QLatin1String("MET")!=msg.data_type )
{
return bIsValid=false;
}
station_code = content.readLine();
met_datas.clear();
do
{
QString line = content.readLine();
if ( 0==line.compare(QLatin1String("STOP")) )
{
bIsValid = true; //检测到“STOP line”消息完整数据有效
break;
}
else if (content.atEnd())
{
bIsValid = false;
met_datas.clear();
break;
}
else
{
MetDataItem met_data_item;
QTextStream line_stream(&line);
line_stream >> met_data_item.met_start_date;
line_stream >> met_data_item.met_start_time;
line_stream >> met_data_item.met_end_date;
line_stream >> met_data_item.met_end_time;
line_stream >> met_data_item.average_outside_temperature;
line_stream >> met_data_item.average_wind_direction;
line_stream >> met_data_item.average_wind_speed;
line_stream >> met_data_item.average_barometric_reading;
line_stream >> met_data_item.humidity;
line_stream >> met_data_item.rainfall;
met_datas.append(met_data_item);
if (line_stream.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
}
while( !content.atEnd() );
return bIsValid;
}