106 lines
3.3 KiB
C++
Executable File
106 lines
3.3 KiB
C++
Executable File
/**
|
|
* Handle one weatherstation consist of one wind- and climate sensor
|
|
* All data will be send by signal/slot connection in case of data change.
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by hjl, SLSE, 2016-09-22
|
|
*/
|
|
|
|
#include "tcpweatherstation.h"
|
|
#include "tcpclimate.h"
|
|
#include "tcpwind.h"
|
|
|
|
namespace MeteoDataManagement
|
|
{
|
|
|
|
TcpWeatherStation::TcpWeatherStation(int id,
|
|
const QString &converterIp,
|
|
quint16 climatePort,
|
|
quint16 windPort,
|
|
QObject *parent)
|
|
: QObject(parent)
|
|
, m_id(id)
|
|
, m_converterIp(converterIp)
|
|
, m_climatePort(climatePort)
|
|
, m_windPort(windPort)
|
|
, m_tcpClimate(nullptr)
|
|
, m_tcpWind(nullptr)
|
|
, m_pressure(800.0)
|
|
, m_temperature(0.0)
|
|
, m_humidity(0.0)
|
|
, m_direction(0.0)
|
|
, m_speed(0.0)
|
|
, m_climateOk(false)
|
|
, m_windOk(false)
|
|
, m_logger(getLogger("TcpWeatherStation"))
|
|
{
|
|
INFO_LOG(m_logger) << "Start TcpWeatherStation ip/(hostname): " << m_converterIp
|
|
<< " climatePort: " << m_climatePort
|
|
<< " windPort: " << m_windPort;
|
|
|
|
if (m_climatePort)
|
|
{
|
|
m_tcpClimate = new TcpClimate(this);
|
|
|
|
INFO_LOG(m_logger) << "m_tcpClimate->start(" << m_converterIp << ", "
|
|
<< QString::number(m_climatePort) << ")";
|
|
m_tcpClimate->start(m_converterIp, m_climatePort);
|
|
|
|
connect(m_tcpClimate, &TcpClimate::sigClimateDataChanged,
|
|
this, &TcpWeatherStation::onClimateDataChanged);
|
|
}
|
|
|
|
if (m_windPort)
|
|
{
|
|
m_tcpWind = new TcpWind(this);
|
|
|
|
INFO_LOG(m_logger) << "m_tcpWind->start(" << m_converterIp << ", "
|
|
<< QString::number(m_windPort) << ")";
|
|
|
|
m_tcpWind->start(m_converterIp, m_windPort);
|
|
|
|
connect(m_tcpWind, &TcpWind::sigWindDataChanged,
|
|
this, &TcpWeatherStation::onWindDataChanged);
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
void TcpWeatherStation::onClimateDataChanged(float pressure, float temperature, float humidity, bool climateOk)
|
|
{
|
|
INFO_LOG(m_logger) << "onClimateDataChanged()"
|
|
<< " MDU AssetId: " << m_id
|
|
<< " pressure: " << pressure
|
|
<< " temperature: " << temperature
|
|
<< " humidity: " << humidity
|
|
<< " climateOk: " << climateOk;
|
|
|
|
m_pressure = pressure;
|
|
m_temperature = temperature;
|
|
m_humidity = humidity;
|
|
m_climateOk = climateOk;
|
|
|
|
emit sigWeatherDataChanged(m_id, m_pressure, m_temperature, m_humidity, m_direction, m_speed, m_climateOk, m_windOk);
|
|
|
|
}
|
|
//-------------------------------------------------------------------
|
|
|
|
void TcpWeatherStation::onWindDataChanged(float direction, float speed, bool windOk)
|
|
{
|
|
INFO_LOG(m_logger) << "onWindDataChanged()"
|
|
<< " MDU AssetId: " << m_id
|
|
<< " direction: " << direction
|
|
<< " speed: " << speed
|
|
<< " climateOk: " << m_climateOk;
|
|
|
|
m_direction = direction;
|
|
m_speed = speed;
|
|
m_windOk = windOk;
|
|
|
|
emit sigWeatherDataChanged(m_id, m_pressure, m_temperature, m_humidity, m_direction, m_speed, m_climateOk, m_windOk);
|
|
}
|
|
//-------------------------------------------------------------------
|
|
|
|
} // namespace MeteoDataManagement
|