#include "demo_can_coder_generator.h"
ADTF_PLUGIN_VERSION("Can coder generator",
devicetb,
DEVICETB_VERSION_MAJOR,
DEVICETB_VERSION_MINOR,
DEVICETB_VERSION_PATCH,
cCanCoderGenerator)
cCanCoderGenerator::cCanCoderGenerator():
{
SetDescription("can_output", "The outcoming CAN sample stream containing the configured signal and value.");
m_nTimer.SetDescription("Generation rate in [ms]");
RegisterPropertyVariable("Timer", m_nTimer);
m_strSignal.SetDescription("The name of the signal.");
RegisterPropertyVariable("Signal", m_strSignal);
m_nChannelID.SetDescription("The channel and database which should be used.");
RegisterPropertyVariable("ChannelID", m_nChannelID);
m_nSignalValue.SetDescription("The value for the signal.");
RegisterPropertyVariable("Signalvalue", m_nSignalValue);
SetDescription("Use this Streaming Source to generate CAN data for a specific signal from a CAN database.");
SetHelpLink("$(ADTF_DEVICE_TOOLBOX_DIR)/doc/adtf_device_toolbox_html/page_example_source_can_coder_generator.html");
}
tResult cCanCoderGenerator::Init()
{
RETURN_IF_FAILED(_runtime->GetObject(m_pSupport));
RETURN_IF_FAILED(m_pSupport->GetDatabase(static_cast<tChannelID>(m_nChannelID), m_pDatabase));
RETURN_IF_FAILED(m_pSupport->CreateCoder(m_pCoder));
SetDatabaseNameProperty(pStreamType);
SetChannelNumberProperty(pStreamType);
SetNetworkNameProperty(pStreamType);
m_pWriter->ChangeType(pStreamType);
RETURN_IF_FAILED(_runtime->GetObject(m_pClock));
return cSampleStreamingSource::Init();
}
tResult cCanCoderGenerator::StartStreaming()
{
if (m_strSignal->IsEmpty())
{
RETURN_ERROR_DESC(ERR_INVALID_ARG, "Please set a signal name");
}
tSignalID nSgnlId;
RETURN_IF_FAILED(m_pDatabase->GetSignalID(m_strSignal->GetPtr(), &nSgnlId));
m_pDatabase->GetSignalInfo(nSgnlId, &pInfo);
auto strMyName = adtf::streaming::get_named_graph_object_full_name(*this);
m_oLooper = system::kernel_timer(strMyName, m_nTimer * 1000, 0, &cCanCoderGenerator::ProcessSample,this, *pInfo);
return cSampleStreamingSource::StartStreaming();
}
tResult cCanCoderGenerator::StopStreaming()
{
m_oLooper.Stop();
return cSampleStreamingSource::StopStreaming();
}
tResult cCanCoderGenerator::ProcessSample(
const tSignalInfo& pInfo)
{
streaming::output_sample_data<tCANData> pSample(m_pClock->GetStreamTime());
pSample->sData = {};
m_pCoder->Begin(pSample.GetDataPtr(),
sizeof(
tCANData));
m_pCoder->SetMessageInfo(static_cast<tChannelID>(m_nChannelID), pInfo.nMessageId, pInfo.bCANExtended);
oValue.nTypeTag = tSignalValue::TAG_FLOAT64;
oValue.f64Value = m_nSignalValue;
m_pCoder->SetSignalValue(pInfo.nSignalID, &oValue);
{
oTimeValue.nTypeTag = tSignalValue::TAG_UINT64;
oTimeValue.nui64Value = static_cast<tUInt64>(m_pClock->GetStreamTime());
m_pCoder->SetSignalValue(CAN_SIGNALID_HEADER_HWTIME, &oTimeValue);
}
m_pCoder->End();
m_pWriter->Write(pSample.Release());
return m_pWriter->ManualTrigger();
}
tResult cCanCoderGenerator::SetDatabaseNameProperty(ucom::object_ptr<streaming::ant::IStreamType>& pStreamType)
{
return streaming::set_property<util::cString>(*pStreamType.Get(), devicetb::sdk::can::stream_meta_type_can::CanDatabaseName,
"");
}
tResult cCanCoderGenerator::SetNetworkNameProperty(ucom::object_ptr<streaming::ant::IStreamType>& pStreamType)
{
ucom::object_ptr<ICANDatabase> pDatabase;
RETURN_IF_FAILED(m_pCoder->GetDatabase(static_cast<tChannelID>(m_nChannelID), pDatabase));
std::vector<const tChar*> strNames;
RETURN_IF_FAILED(pDatabase->GetNetworkNames(strNames));
return streaming::set_property<util::cString>(*pStreamType.Get(),
devicetb::sdk::can::stream_meta_type_can::CanNetworkName,
strNames[0]);
}
tResult cCanCoderGenerator::SetChannelNumberProperty(ucom::object_ptr<streaming::ant::IStreamType>& pStreamType)
{
return streaming::set_property<util::cString>(*pStreamType.Get(), devicetb::sdk::can::stream_meta_type_can::CanChannelNumber,
std::to_string(m_nChannelID).c_str());
}
Copyright 2024 CARIAD SE.
Namespace for functionality provided by V3.0.0.
axle::tSignalValue tSignalValue
axle::tSignalInfo tSignalInfo
axle::tCANData tCANData
The CAN data structure is used by CAN MediaSamples use following code within your filter:
axle::stream_meta_type_can stream_meta_type_can
Definition of Stream Meta Type CAN Messages.