85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
#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;
|
||
}
|
||
|