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

522 lines
16 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 "StateOfHealthMessage.h"
#include <QFile>
using namespace RMSSOHData;
StateOfHealthMessage::StateOfHealthMessage()
{
bIsValid = false;
InitBlockFlagInfo();
}
StateOfHealthMessage::~StateOfHealthMessage()
{
}
bool StateOfHealthMessage::IsValid()
{
return bIsValid;
}
const QVariant StateOfHealthMessage::GetBlockData(QString &block_name)
{
if ( rmssoh_msg_data.contains(block_name) )
{
return rmssoh_msg_data[block_name];
}
return QVariant();
}
void StateOfHealthMessage::ClearData()
{
bIsValid = false;
rmssoh_msg_data.clear();
AbstractSpectrumDataMessage::ClearData();
}
void StateOfHealthMessage::InitBlockFlagInfo()
{
block_flag.append(QLatin1String("#Header")); // [ 0 ]
block_flag.append(QLatin1String("#Comment")); // [ 1 ]
block_flag.append(QLatin1String("#AirSamplerFlow")); // [ 2 ]
block_flag.append(QLatin1String("#AirSamplerEnv")); // [ 3 ]
block_flag.append(QLatin1String("#DetEnv")); // [ 4 ]
block_flag.append(QLatin1String("#NIMBIN")); // [ 5 ]
block_flag.append(QLatin1String("#PowerSupply")); // [ 6 ]
block_flag.append(QLatin1String("#EquipStatus")); // [ 7 ]
block_flag.append(QLatin1String("#TamperEnv")); // [ 8 ]
block_flag.append(QLatin1String("#ProcessSensors")); // [ 9 ]
block_flag.append(QLatin1String("#Chromatogram")); // [ 10 ]
block_flag.append(QLatin1String("STOP")); // [ STOP ]
block_flag.append(QLatin1String("BEGIN")); // [ BEGIN ]
}
bool StateOfHealthMessage::AnalyseMessgeBody(QTextStream &content)
{
const MessageInfo& msg = AbstractSpectrumDataMessage::GetMessageInfo();
if ( QLatin1String("RMSSOH") != msg.data_type )
{
return bIsValid = false;
}
bool bRet = true;
QString line = content.readLine();
do
{
if ( 0==line.left(7).compare(block_flag.at(0)) && bRet)
{
bRet &= Analyse_Header_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(1)) && bRet)
{
bRet &= Analyse_Comment_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(2)) && bRet)
{
bRet &= Analyse_AirSamplerFlow_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(3)) && bRet)
{
bRet &= Analyse_AirSamplerEnv_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(4)) && bRet)
{
bRet &= Analyse_DetEnv_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(5)) && bRet)
{
bRet &= Analyse_NIMBIN_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(6)) && bRet)
{
bRet &= Analyse_PowerSupply_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(7)) && bRet)
{
bRet &= Analyse_EquipStatus_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(8)) && bRet)
{
bRet &= Analyse_TamperEnv_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(9)) && bRet)
{
bRet &= Analyse_ProcessSensors_Block(content, line);
}
else if ( 0==line.compare(block_flag.at(10)) && bRet)
{
bRet &= Analyse_ChromatogramBlock(content, line);
}
else
{ // 数据错误,数据有效
bIsValid = false;
bRet = bIsValid;
}
if (0==line.compare(block_flag.at(11)) && bRet )
{
bIsValid = true; //检测到“STOP line”消息完整数据有效
break;
}
else if (content.atEnd())
{
bIsValid = false;
rmssoh_msg_data.clear();
bRet = bIsValid;
break;
}
}
while( bRet );
return bRet;
}
bool StateOfHealthMessage::Analyse_Header_Block(QTextStream &content, QString &nextBlock)
{
HeaderBlock Header;
QString &line = nextBlock;
Header.designator = line.mid(8);
content >> Header.station_code >> Header.detector_code;
content >> Header.start_date >> Header.start_time >> Header.end_date >> Header.end_time >> Header.transmit_date >> Header.transmit_time;
rmssoh_msg_data.insert(block_flag.at(0), QVariant::fromValue(Header));
content >> nextBlock;
content.readLine();
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_Comment_Block(QTextStream& content, QString& nextBlock)
{
CommentBlock comment;
nextBlock = content.readLine();
while ( !block_flag.contains(nextBlock) && !content.atEnd())
{
if ( !nextBlock.isEmpty() )
{
comment.append(nextBlock + QLatin1String("\n"));
}
nextBlock = content.readLine();
}
rmssoh_msg_data.insert(block_flag.at(1), QVariant::fromValue(comment));
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_AirSamplerFlow_Block(QTextStream &content, QString &nextBlock)
{
AirSamplerFlowBlock air_sampler_flow;
int row_count = 0;
nextBlock = content.readLine();
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
double average_flow_rate;
double flow_rate_standard_deviation;
QString start_date;
QString start_time;
long interval_duration;
QTextStream line_content(&nextBlock);
line_content >> average_flow_rate >> flow_rate_standard_deviation >> start_date >> start_time >> interval_duration;
air_sampler_flow.average_flow_rate << average_flow_rate;
air_sampler_flow.flow_rate_standard_deviation << flow_rate_standard_deviation;
air_sampler_flow.start_date << start_date;
air_sampler_flow.start_time << start_time;
air_sampler_flow.interval_duration << interval_duration;
++ row_count;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
air_sampler_flow.record_count = row_count;
rmssoh_msg_data.insert( block_flag.at(2), QVariant::fromValue(air_sampler_flow) );
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_AirSamplerEnv_Block(QTextStream &content, QString &nextBlock)
{
AirSamplerEnvBlock air_sampler_env;
int row_count = 0;
nextBlock = content.readLine();
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
double temperature;
double pressure;
QString date;
QString time;
long interval_duration;
QTextStream line_content(&nextBlock);
line_content >> temperature >> pressure >> date >> time >> interval_duration;
air_sampler_env.temperature << temperature;
air_sampler_env.pressure << pressure;
air_sampler_env.date << date;
air_sampler_env.time << time;
air_sampler_env.interval_duration << interval_duration;
++ row_count;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
air_sampler_env.record_count = row_count;
rmssoh_msg_data.insert( block_flag.at(3), QVariant::fromValue(air_sampler_env) );
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_DetEnv_Block(QTextStream &content, QString &nextBlock)
{
DetEnvBlock det_env;
int row_count = 0;
nextBlock = content.readLine();
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
double room_temperature;
QString detector_shield_status;
short humidity;
long voltage;
long crystal_temperature;
QString electric_cooler_status;
double fill_fraction;
double leakage;
QString date;
QString time;
long interval_duration;
QTextStream line_content(&nextBlock);
line_content >> room_temperature >> detector_shield_status >> humidity >> voltage >> \
crystal_temperature >> electric_cooler_status >> fill_fraction >> leakage >> \
date >> time >> interval_duration;
det_env.room_temperature << room_temperature;
det_env.detector_shield_status << detector_shield_status;
det_env.humidity << humidity;
det_env.voltage << voltage;
det_env.crystal_temperature << crystal_temperature;
det_env.electric_cooler_status << electric_cooler_status;
det_env.fill_fraction << fill_fraction;
det_env.leakage << leakage;
det_env.date << date;
det_env.time << time;
det_env.interval_duration << interval_duration;
++ row_count;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
det_env.record_count = row_count;
rmssoh_msg_data.insert( block_flag.at(4), QVariant::fromValue(det_env) );
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_NIMBIN_Block(QTextStream &content, QString &nextBlock)
{
NIMBIN_Block nimbin;
int row_count = 0;
nextBlock = content.readLine();
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
QString flag;
short voltage;
QString date;
QString time;
long interval_duration;
QTextStream line_content(&nextBlock);
line_content >> flag >> voltage >> date >> time >> interval_duration;
nimbin.flag << flag;
nimbin.voltage << voltage;
nimbin.date << date;
nimbin.time << time;
nimbin.interval_duration << interval_duration;
++ row_count;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
nimbin.record_count = row_count;
rmssoh_msg_data.insert( block_flag.at(5), QVariant::fromValue(nimbin) );
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_PowerSupply_Block(QTextStream &content, QString &nextBlock)
{
PowerSupplyBlock power_supply;
int row_count = 0;
nextBlock = content.readLine();
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
QString MAIN;
QString main_power_status;
QString AUX;
QString aux_power_status;
QString UPS;
QString ups_status;
QString date;
QString time;
long interval_duration;
QTextStream line_content(&nextBlock);
line_content >> MAIN >> main_power_status >> AUX >> aux_power_status >> UPS >> ups_status >> date >> time >> interval_duration;
power_supply.MAIN << MAIN;
power_supply.main_power_status << main_power_status;
power_supply.AUX << AUX;
power_supply.aux_power_status << aux_power_status;
power_supply.UPS << ups_status;
power_supply.date << date;
power_supply.time << time;
power_supply.interval_duration << interval_duration;
++ row_count;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
power_supply.record_count = row_count;
rmssoh_msg_data.insert( block_flag.at(6), QVariant::fromValue(power_supply) );
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_EquipStatus_Block(QTextStream &content, QString &nextBlock)
{
EquipStatusBlock equip_status;
int row_count = 0;
nextBlock = content.readLine();
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
QString temp_flag;
QString C_value;
QString P_value;
QString A_value;
QString date;
QString time;
long interval_duration;
QTextStream line_content(&nextBlock);
line_content >> temp_flag >> C_value >> temp_flag >> P_value >> temp_flag >> A_value >> date >> time >> interval_duration;
equip_status.C_value << C_value;
equip_status.P_value << P_value;
equip_status.A_value << A_value;
equip_status.date << date;
equip_status.time << time;
equip_status.interval_duration << interval_duration;
++ row_count;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
equip_status.record_count = row_count;
rmssoh_msg_data.insert( block_flag.at(7), QVariant::fromValue(equip_status) );
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_TamperEnv_Block(QTextStream &content, QString &nextBlock)
{
TamperEnvBlock tamper_env;
int row_count = 0;
nextBlock = content.readLine();
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
QString tamper_sensor_name;
QString tamper_sensor_status;
QString date;
QString time;
long interval_duration;
QTextStream line_content(&nextBlock);
line_content >> tamper_sensor_name >> tamper_sensor_status >> date >> time >> interval_duration;
tamper_env.tamper_sensor_name << tamper_sensor_name;
tamper_env.tamper_sensor_status << tamper_sensor_status;
tamper_env.date << date;
tamper_env.time << time;
tamper_env.interval_duration << interval_duration;
++ row_count;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
tamper_env.record_count = row_count;
rmssoh_msg_data.insert( block_flag.at(8), QVariant::fromValue(tamper_env) );
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_ProcessSensors_Block(QTextStream &content, QString &nextBlock)
{
ProcessSensorsBlock process_sensors;
int row_count = 0;
nextBlock = content.readLine();
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
QString sensor_type;
QString sensor_name;
double sensor_reading;
QString date;
QString time;
long duration;
QTextStream line_content(&nextBlock);
line_content >> sensor_type >> sensor_name >> sensor_reading >> date >> time >> duration;
process_sensors.sensor_type << sensor_type;
process_sensors.sensor_name << sensor_name;
process_sensors.sensor_reading << sensor_reading;
process_sensors.date << date;
process_sensors.time << time;
process_sensors.duration << duration;
++ row_count;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
process_sensors.record_count = row_count;
rmssoh_msg_data.insert( block_flag.at(9), QVariant::fromValue(process_sensors) );
return (content.status()==QTextStream::Ok)?true:false;
}
bool StateOfHealthMessage::Analyse_ChromatogramBlock(QTextStream &content, QString &nextBlock)
{
ChromatogramBlock chromatogram;
content >> chromatogram.srid;
content >> chromatogram.total_number;
int row_count = 0;
nextBlock = content.readLine();
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
QTextStream line_content(&nextBlock);
long interval_number;
long interval_start_channel;
double duration;
line_content >> interval_number;
if ( 0==interval_number )
{
break;
}
line_content >> interval_start_channel >> duration;
++ row_count;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
chromatogram.interval_record_count = row_count;
while (!block_flag.contains(nextBlock) && !content.atEnd())
{
QTextStream line_content(&nextBlock);
long detector_response;
line_content >> detector_response;
chromatogram.detector_response << detector_response;
nextBlock = content.readLine();
if (line_content.status()==QTextStream::ReadCorruptData)
{
return false;
}
}
rmssoh_msg_data.insert( block_flag.at(10), QVariant::fromValue(chromatogram) );
return (content.status()==QTextStream::Ok)?true:false;
}