ADTF_DEVICE_TOOLBOX  3.12.1 (ADTF 3.18.3)
Source Code for Demo FlexRay Generator
Location
./src/examples/src/flexray_generator/
This example shows:
Header file for the Demo FlexRay Generator Example
#pragma once
#include <adtf_filtersdk.h>
#include <adtf_base.h>
#include <adtf_systemsdk.h>
#include <adtf_devicetb_sdk.h>
class cFlexrayGenerator : public adtf::filter::cSampleStreamingSource
{
public:
ADTF_CLASS_ID_NAME(cFlexrayGenerator, "demo_flexray_generator.streaming_source.devicetb.cid","Demo FlexRay Generator");
ADTF_CLASS_DEPENDENCIES(REQUIRE_INTERFACE(adtf::services::IReferenceClock),
cFlexrayGenerator();
tResult Init() override;
tResult StartStreaming() override;
tResult StopStreaming() override;
tResult ProcessSample();
private:
adtf::base::property_variable<tUInt> m_nTimer = 10000;
adtf::base::property_variable<tUInt32> m_nFlexRayPDU = 1;
adtf::base::property_variable<tUInt8> m_nChannelID = 1;
adtf::system::kernel_timer m_oLooper;
adtf::streaming::ISampleWriter* m_pWriter;
adtf::ucom::object_ptr<adtf::devicetb::sdk::flexray::IFlexRayDatabase> m_pFibexDatabase;
adtf::ucom::object_ptr<adtf::devicetb::sdk::flexray::IFlexRayCoder> m_pFlexrayCoder;
adtf::ucom::object_ptr<adtf::services::IReferenceClock> m_pClock;
};
The IFlexRaySupport interface provides methods to query FIBEX databases.
Implementation for the Demo FlexRay Generator Example
#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():
m_pWriter(CreateOutputPin("flexray_output", stream_meta_type_flexray()))
{
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;
const tPDUInfo* pPDUInfo = 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++)
{
const tSignalInfo* pSignalInfo = nullptr;
if (IS_FAILED(m_pFibexDatabase->GetSignalInfo(pSignalIDMap[nSignalIdx], &pSignalInfo)))
{
LOG_ERROR("could not get signal info of signal %d", pSignalIDMap[nSignalIdx]);
continue;
}
tSignalValue oSignalValue;
//set default value of fibex database
//oSignalValue.nRawValue = std::lround(pSignalInfo->fDefault);
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
Definition: can_types.h:301
axle::tSignalInfo tSignalInfo
Definition: can_types.h:300
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)
Copyright © CARIAD SE.