#include "demo_flexray_generator.h"
#include <cstring>
#include <adtf_systemsdk.h>
#include <adtf_devicetb_sdk.h>
using namespace adtf::util;
using namespace adtf::ucom;
using namespace adtf::base;
using namespace adtf::streaming;
using namespace adtf::system;
using namespace adtf::mediadescription;
ADTF_PLUGIN_VERSION("FlexRay generator",
devicetb,
DEVICETB_VERSION_MAJOR,
DEVICETB_VERSION_MINOR,
DEVICETB_VERSION_PATCH,
cFlexrayGenerator)
cFlexrayGenerator::cFlexrayGenerator():
{
SetDescription("flexray_output", "The outcoming FlexRay sample stream containing the configured PDU.");
m_nTimer.SetDescription("Generation rate in [ms]");
RegisterPropertyVariable("Timer", m_nTimer);
m_nFlexRayPDU.SetDescription("The ID of the PDU.");
RegisterPropertyVariable("PDUID", m_nFlexRayPDU);
m_nChannelID.SetDescription("The channel and database which should be used.");
RegisterPropertyVariable("ChannelID", m_nChannelID);
SetDescription("Use this Streaming Source to generate FlexRay data from database.");
SetHelpLink("$(ADTF_DEVICE_TOOLBOX_DIR)/doc/adtf_device_toolbox_html/page_example_source_flexray_generator.html");
}
tResult cFlexrayGenerator::Init()
{
object_ptr<IFlexRaySupport> pFlexraySupportService;
RETURN_IF_FAILED(_runtime->GetObject(m_pClock));
if (IS_FAILED(_runtime->GetObject(pFlexraySupportService)))
{
RETURN_ERROR_DESC(ERR_FAILED, "FlexRay support service is not available");
}
RETURN_IF_FAILED(pFlexraySupportService->GetDatabase(m_nChannelID, m_pFibexDatabase));
RETURN_IF_FAILED(pFlexraySupportService->CreateCoder(m_pFibexDatabase, m_pFlexrayCoder));
return cSampleStreamingSource::Init();
}
tResult cFlexrayGenerator::StartStreaming()
{
auto strMyName = get_named_graph_object_full_name(*this);
m_oLooper = kernel_timer(strMyName, *m_nTimer, 0, &cFlexrayGenerator::ProcessSample,this);
return cSampleStreamingSource::StartStreaming();
}
tResult cFlexrayGenerator::StopStreaming()
{
m_oLooper.Stop();
return cSampleStreamingSource::StopStreaming();
}
tResult cFlexrayGenerator::ProcessSample()
{
tPDUID nPDUID = 1;
tUInt32 nSignalCount = 0;
const tSignalID* pSignalIDMap = nullptr;
tInt nSize = 0;
if (m_nFlexRayPDU > 1)
{
nPDUID = m_nFlexRayPDU;
}
RETURN_IF_FAILED(m_pFibexDatabase->GetPDUInfo(nPDUID, &pPDUInfo));
RETURN_IF_FAILED(m_pFibexDatabase->GetPDUSignalMap(pPDUInfo->nPDUID, &nSignalCount, &pSignalIDMap));
RETURN_IF_FAILED(m_pFlexrayCoder->ResetData());
for (size_t nSignalIdx = 0; nSignalIdx < nSignalCount; nSignalIdx++)
{
if (IS_FAILED(m_pFibexDatabase->GetSignalInfo(pSignalIDMap[nSignalIdx], &pSignalInfo)))
{
LOG_ERROR("could not get signal info of signal %d", pSignalIDMap[nSignalIdx]);
continue;
}
oSignalValue.nf64Value = 10.10;
if (IS_FAILED(m_pFlexrayCoder->SetSignalValue(pSignalIDMap[nSignalIdx], &oSignalValue)))
{
LOG_ERROR("could not set signal value of signal %s", pSignalInfo->strShortName);
}
}
adtf::ucom::object_ptr<adtf::streaming::ISample> pSample;
adtf::ucom::object_ptr_locked<adtf::streaming::ISampleBuffer> pSampleLock;
RETURN_IF_FAILED(alloc_sample(pSample));
RETURN_IF_FAILED(m_pFlexrayCoder->TransmitData(nullptr, &nSize));
RETURN_IF_FAILED(pSample->WriteLock(pSampleLock, nSize));
RETURN_IF_FAILED(m_pFlexrayCoder->TransmitData(pSampleLock->GetPtr(), &nSize));
RETURN_IF_FAILED(pSampleLock->Unlock());
RETURN_IF_FAILED(m_pWriter->Write(pSample));
RETURN_IF_FAILED(m_pWriter->ManualTrigger());
RETURN_NOERROR;
}
Copyright 2024 CARIAD SE.
axle::tSignalValue tSignalValue
axle::tSignalInfo tSignalInfo
Namespace for FlexRay in ADTF-Devicetoolbox.
axle::stream_meta_type_flexray stream_meta_type_flexray
Definition of Stream Meta Type FlexRay Messages.
axle::tPDUInfo tPDUInfo
Structure with information about one PDU (may be a complete frame or part of a frame)