mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-04-16 09:58:16 +00:00
@@ -0,0 +1,62 @@
|
||||
#include <iostream>
|
||||
#include "complex_service.h"
|
||||
|
||||
|
||||
void CTrunkExampleService::Initialize(const sdv::u8string& /*ssObjectConfig*/)
|
||||
{
|
||||
m_eStatus = sdv::EObjectStatus::initializing;
|
||||
|
||||
// Request the basic service for speed.
|
||||
auto pSpeedSvc = sdv::core::GetObject("Vehicle.Speed_Service").GetInterface<vss::Vehicle::SpeedService::IVSS_GetSpeed>();
|
||||
if (pSpeedSvc)
|
||||
{
|
||||
// Register speed change event handler.
|
||||
pSpeedSvc->RegisterOnSignalChangeOfVehicleSpeed(static_cast<vss::Vehicle::SpeedService::IVSS_SetSpeed_Event*> (this));
|
||||
}
|
||||
|
||||
// Request the basic service for opening the trunk
|
||||
m_pTrunkSvc = sdv::core::GetObject("Vehicle.Body.Trunk_Service").GetInterface<vss::Vehicle::Body::TrunkService::IVSS_SetOpen>();
|
||||
|
||||
if ((!pSpeedSvc) || (!m_pTrunkSvc))
|
||||
{
|
||||
SDV_LOG_ERROR("Could not get interfaces : [CTrunkExampleService]");
|
||||
m_eStatus = sdv::EObjectStatus::initialization_failure;
|
||||
return;
|
||||
}
|
||||
|
||||
m_eStatus = sdv::EObjectStatus::initialized;
|
||||
}
|
||||
|
||||
sdv::EObjectStatus CTrunkExampleService::GetStatus() const
|
||||
{
|
||||
return m_eStatus;
|
||||
}
|
||||
|
||||
void CTrunkExampleService::SetOperationMode(sdv::EOperationMode /*eMode*/)
|
||||
{
|
||||
// Not applicable
|
||||
}
|
||||
|
||||
void CTrunkExampleService::Shutdown()
|
||||
{
|
||||
// Unregister trunk change event handler.
|
||||
auto pSpeedSvc = sdv::core::GetObject("Vehicle.Speed_Service").GetInterface<vss::Vehicle::SpeedService::IVSS_GetSpeed>();
|
||||
if (pSpeedSvc)
|
||||
pSpeedSvc->UnregisterOnSignalChangeOfVehicleSpeed(static_cast<vss::Vehicle::SpeedService::IVSS_SetSpeed_Event*> (this));
|
||||
}
|
||||
|
||||
void CTrunkExampleService::SetSpeed(float value)
|
||||
{
|
||||
m_Speed = value;
|
||||
}
|
||||
|
||||
bool CTrunkExampleService::PopTrunk()
|
||||
{
|
||||
if (m_Speed == 0.0)
|
||||
{
|
||||
return m_pTrunkSvc->SetOpen(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
98
examples/open_trunk_example/trunk_service/complex_service.h
Normal file
98
examples/open_trunk_example/trunk_service/complex_service.h
Normal file
@@ -0,0 +1,98 @@
|
||||
#ifndef TRUNK_COMPLEX_SERVICE_EXAMPLE_H
|
||||
#define TRUNK_COMPLEX_SERVICE_EXAMPLE_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// SDV framework support
|
||||
#include <support/component_impl.h>
|
||||
#include <support/signal_support.h>
|
||||
|
||||
// VSS interfaces - located in ../interfaces
|
||||
#include "../generated/vss_files/vss_vehiclespeed_bs_rx.h"
|
||||
#include "../generated/vss_files/vss_vehiclebodytrunk_bs_tx.h"
|
||||
|
||||
// Complex service trunk interface - located in ../generated/trunk_service
|
||||
#include "trunkkit.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Open trunk service: opens the trunk if vehicle is not moving
|
||||
*/
|
||||
class CTrunkExampleService : public sdv::CSdvObject
|
||||
, public sdv::IObjectControl
|
||||
, public vss::Vehicle::SpeedService::IVSS_SetSpeed_Event
|
||||
, public ITrunkKitService
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
CTrunkExampleService(){}
|
||||
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~CTrunkExampleService()
|
||||
{
|
||||
// Just in case...
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
// Interface map
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectControl)
|
||||
SDV_INTERFACE_ENTRY(vss::Vehicle::SpeedService::IVSS_SetSpeed_Event)
|
||||
SDV_INTERFACE_ENTRY(ITrunkKitService)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
// Object declarations
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::ComplexService)
|
||||
DECLARE_OBJECT_CLASS_NAME("Open Trunk Service")
|
||||
DECLARE_OBJECT_SINGLETON()
|
||||
|
||||
/**
|
||||
* @brief Initialize the object. Overload of sdv::IObjectControl::Initialize.
|
||||
* @param[in] ssObjectConfig Optional configuration string.
|
||||
*/
|
||||
void Initialize(const sdv::u8string& ssObjectConfig) override;
|
||||
|
||||
/**
|
||||
* @brief Get the current status of the object. Overload of sdv::IObjectControl::GetStatus.
|
||||
* @return Return the current status of the object.
|
||||
*/
|
||||
sdv::EObjectStatus GetStatus() const override;
|
||||
|
||||
/**
|
||||
* @brief Set the component operation mode. Overload of sdv::IObjectControl::SetOperationMode.
|
||||
* @param[in] eMode The operation mode, the component should run in.
|
||||
*/
|
||||
void SetOperationMode(sdv::EOperationMode eMode) override;
|
||||
|
||||
/**
|
||||
* @brief Shutdown called before the object is destroyed. Overload of sdv::IObjectControl::Shutdown.
|
||||
*/
|
||||
void Shutdown() override;
|
||||
|
||||
/**
|
||||
* @brief Set vehicleSpeed signal
|
||||
* @param[in] value vehicleSpeed
|
||||
*/
|
||||
virtual void SetSpeed(float value) override;
|
||||
|
||||
/**
|
||||
* @brief Save call to open the trunk. Opening the trunk is onkly allowed when the vehicle is not moving
|
||||
* @return Returns whether the trunk could be opened or not.
|
||||
*/
|
||||
virtual bool PopTrunk() override;
|
||||
|
||||
private:
|
||||
|
||||
sdv::EObjectStatus m_eStatus = sdv::EObjectStatus::initialization_pending; ///< Current object status
|
||||
|
||||
float m_Speed = 0.0; ///< Speed
|
||||
vss::Vehicle::Body::TrunkService::IVSS_SetOpen* m_pTrunkSvc = nullptr; ///< Trunk
|
||||
};
|
||||
|
||||
DEFINE_SDV_OBJECT(CTrunkExampleService)
|
||||
|
||||
#endif // !define TRUNK_COMPLEX_SERVICE_EXAMPLE_H
|
||||
16
examples/open_trunk_example/trunk_service/trunkkit.idl
Normal file
16
examples/open_trunk_example/trunk_service/trunkkit.idl
Normal file
@@ -0,0 +1,16 @@
|
||||
/*******************************************************************************
|
||||
* @file trunkkit.idl
|
||||
* @details Service interface definition to open the trunk.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Service to open the trunk
|
||||
*/
|
||||
interface ITrunkKitService
|
||||
{
|
||||
/**
|
||||
* @brief Save call to open the trunk. Opening the trunk is onkly allowed when the vehicle is not moving
|
||||
* @return Returns whether the trunk could be opened or not.
|
||||
*/
|
||||
boolean PopTrunk();
|
||||
};
|
||||
Reference in New Issue
Block a user