#include "demo_data_load_generator.h"
cDataLoadGenerator);
cDataLoadGenerator::cDataLoadGenerator()
{
m_fDataRate.SetDescription("Count of bytes which should be generated per second.");
RegisterPropertyVariable("data_rate_bytes_per_second", m_fDataRate);
m_nDataInterval.SetDescription("Update interval in microseconds to generate random data. This is only used when no Timer Runner is connected to the 'generate_data' runner.");
RegisterPropertyVariable("data_interval_us", m_nDataInterval);
m_pWriter = CreateOutputPin("data");
SetDescription("data", "Provides the randomly generated data");
{
auto oResult = GenerateData();
{
m_pWriter->SetStreamError(oResult);
}
});
SetDescription("generate_data",
"Connect a Timer Runner that will trigger the data generation. In this case the property `data_interval_us` has no effect."
"If this is not connected, the source will create a timer on its own.");
SetDescription("Use this Streaming Source to generate random data load configured by 'data_rate_bytes_per_second' and 'data_interval_us' properties.");
SetHelpLink("$(ADTF_DIR)/doc/html/page_demo_data_load_generator.html");
}
tResult cDataLoadGenerator::StartStreaming()
{
m_tmLastTrigger = std::nullopt;
}
tResult cDataLoadGenerator::GenerateData()
{
auto tmNow = m_pClock->GetStreamTimeNs();
if (m_tmLastTrigger)
{
const auto tmInterval = tmNow - *m_tmLastTrigger;
auto nSampleSize = static_cast<size_t>(m_fDataRate * tmInterval.nCount / 1000000000);
object_ptr<ISample> pSample;
{
object_ptr_locked<ISampleBuffer> pBuffer;
}
m_pWriter->Write(pSample);
m_pWriter->ManualTrigger(tmNow);
}
m_tmLastTrigger = tmNow;
}
tResult cDataLoadGenerator::StopStreaming()
{
m_oTimer.Deactivate();
return cSampleStreamingSource::StopStreaming();
}
#define ADTF_PLUGIN(__plugin_identifier,...)
The ADTF Plugin Macro will add the code of a adtf::ucom::ant::IPlugin implementation.
#define IS_FAILED(s)
Check if result is failed.
#define RETURN_IF_FAILED(s)
Return if expression is failed, which requires the calling function's return type to be tResult.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
virtual tResult GetObject(iobject_ptr< IObject > &pObject, const char *strNameOID) const =0
Get registered object from object registry.
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSampleObject, const char *strSampleCID)
Helper Function to get a Sample Instance through the adtf::ucom::ant::IRuntime.
Namespace for the ADTF Streaming SDK.
Namespace for the ADTF System SDK.
Namespace for the ADTF uCOM3 SDK.
adtf::ucom::IRuntime * _runtime
Global Runtime Pointer to reference to the current runtime.