#include "demo_data_trigger_function.h"
#include <functional>
ADTF_PLUGIN(
"Demo Data Trigger Plugin", cSimpleDataCalculator);
cSimpleDataCalculator::cSimpleDataCalculator()
{
m_pReader1 = CreateInputPin("in1", stream_type_plain<float>(), true);
SetDescription("in1", "First input value for calculation (in1 <operator> in2)");
m_pReader2 = CreateInputPin("in2", stream_type_plain<float>(), true);
SetDescription("in2", "Second input value for calculation (in1 <operator> in2)");
m_pWriter = CreateOutputPin("out", stream_type_plain<float>());
SetDescription("out", "Provides the calculated output (in1 <operator> in2)");
m_eOperator.SetValueList({{ePLUS, "PLUS"},
{eMINUS, "MINUS"},
{eMULTI, "MULTI"},
{eDIVIDE, "DIVIDE"}});
m_eOperator.SetDescription("Chooses the arithmetic operation used to calculate the output values.");
RegisterPropertyVariable("calculator_function/operator", m_eOperator);
SetDescription("Use this filter to calculate two input values while choosing the arithmetic operation with the property 'operator'.");
SetHelpLink("$(ADTF_DIR)/doc/html/page_demo_data_triggered_filter.html");
}
tResult cSimpleDataCalculator::Init(tInitStage eStage)
{
if (eStage == StageNormal)
{
switch (m_eOperator)
{
case ePLUS:
{
LOG_INFO(
"Current operation is Addition");
m_fnCalculator = std::plus<float>();
break;
}
case eMINUS:
{
LOG_INFO(
"Current operation is Subtraction");
m_fnCalculator = std::minus<float>();
break;
}
case eMULTI:
{
LOG_INFO(
"Current operation is Multiplication");
m_fnCalculator = std::multiplies<float>();
break;
}
case eDIVIDE:
{
LOG_INFO(
"Current operation is Division");
m_fnCalculator = std::divides<float>();
break;
}
default:
{
}
}
}
}
tResult cSimpleDataCalculator::ProcessInput(tNanoSeconds ,
ISampleReader* )
{
object_ptr<const ISample> pSample1;
object_ptr<const ISample> pSample2;
if (
IS_OK(m_pReader1->GetLastSample(pSample1)) &&
IS_OK(m_pReader2->GetLastSample(pSample2)))
{
output_sample_data<float> oOutput(tmSampleTimeStamp);
oOutput = m_fnCalculator(sample_data<float>(pSample1),
sample_data<float>(pSample2));
m_pWriter->Write(oOutput.Release());
}
}
#define ADTF_PLUGIN(__plugin_identifier,...)
The ADTF Plugin Macro will add the code of a adtf::ucom::ant::IPlugin implementation.
#define LOG_INFO(...)
Logs an info message.
#define RETURN_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
#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.
#define IS_OK(s)
Check if result is OK.
base::flash::tNanoSeconds get_sample_time(const ucom::ant::iobject_ptr< const ant::ISample > &pSample)
Returns the sample time stamp with nanosecond precision.