diff options
| author | Monika Forstner <Monika_Forstner@mentor.com> | 2020-09-16 10:20:03 +0200 |
|---|---|---|
| committer | Monika Forstner <Monika_Forstner@mentor.com> | 2020-09-16 10:50:27 +0200 |
| commit | 2fb502b4bc23aa13fee1db3395b3cae5e34cc871 (patch) | |
| tree | d9cd2c64522f190500dc53291b4fbcf5100b9720 /NodeStateMachineStub | |
| parent | 253d10aada6bf5cdfe307aaff55363f08194c85e (diff) | |
| download | node-state-manager-release_NSM_CommonAPI.tar.gz | |
NSM Release 3.0release_NSM_CommonAPI
Diffstat (limited to 'NodeStateMachineStub')
| -rw-r--r-- | NodeStateMachineStub/CMakeLists.txt | 50 | ||||
| -rw-r--r-- | NodeStateMachineStub/Makefile.am | 25 | ||||
| -rw-r--r-- | NodeStateMachineStub/NodeStateMachine.cpp (renamed from NodeStateMachineStub/NodeStateMachine.c) | 44 | ||||
| -rw-r--r-- | NodeStateMachineStub/NodeStateMachine.hpp (renamed from NodeStateMachineStub/NodeStateMachine.h) | 15 | ||||
| -rw-r--r-- | NodeStateMachineStub/Test_StubImpl.cpp | 61 | ||||
| -rw-r--r-- | NodeStateMachineStub/Test_StubImpl.hpp | 42 |
6 files changed, 193 insertions, 44 deletions
diff --git a/NodeStateMachineStub/CMakeLists.txt b/NodeStateMachineStub/CMakeLists.txt new file mode 100644 index 0000000..311e261 --- /dev/null +++ b/NodeStateMachineStub/CMakeLists.txt @@ -0,0 +1,50 @@ +####################################################################################################################### +# +# Copyright (C) 2020 Mentor Graphics (Deutschland) GmbH +# +# Author: Vignesh_Rajendran@mentor.com +# +# CMake file of NodeStateMachineStub +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +####################################################################################################################### + +cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR) + +project(NodeStateMachineStub LANGUAGES CXX) + +set(SOURCE_FILES NodeStateMachine.cpp) + +if(WITH_TESTS) + file(GLOB SOURCE_FILES *.cpp) +endif(WITH_TESTS) + +add_library(NodeStateMachineStub SHARED ${SOURCE_FILES}) + +target_compile_features(NodeStateMachineStub PRIVATE cxx_std_11) + +target_compile_options(NodeStateMachineStub PRIVATE -Werror -pthread) + +target_link_libraries(NodeStateMachineStub PRIVATE + ${COMMONAPI_LIBS} + org.genivi.nodestatemanager.commonapi.core.stub + org.genivi.nodestatemanager.commonapi.someip.stub + pthread) + +install(TARGETS NodeStateMachineStub DESTINATION lib) + +install(TARGETS NodeStateMachineStub + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.hpp") + diff --git a/NodeStateMachineStub/Makefile.am b/NodeStateMachineStub/Makefile.am deleted file mode 100644 index 0905bd5..0000000 --- a/NodeStateMachineStub/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -####################################################################################################################### -# -# Copyright (C) 2012 Continental Automotive Systems, Inc. -# -# Author: Jean-Pierre.Bogler@continental-corporation.com -# -# Makefile template for the NodeStateMachineStub -# -# Process this file with automake to produce a Makefile.in. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -####################################################################################################################### - -lib_LTLIBRARIES = libNodeStateMachineStub.la - -libNodeStateMachineStub_la_CFLAGS = \ - -I$(top_srcdir)/NodeStateManager \ - $(PLATFORM_CFLAGS) - -libNodeStateMachineStub_la_SOURCES = NodeStateMachine.c NodeStateMachine.h - -libNodeStateMachineStub_la_LDFLAGS = -avoid-version diff --git a/NodeStateMachineStub/NodeStateMachine.c b/NodeStateMachineStub/NodeStateMachine.cpp index c890658..00de5fa 100644 --- a/NodeStateMachineStub/NodeStateMachine.c +++ b/NodeStateMachineStub/NodeStateMachine.cpp @@ -25,29 +25,36 @@ * **********************************************************************************************************************/ -#include "NodeStateMachine.h" /* own header file */ +#include "NodeStateMachine.hpp" /* own header file */ + #include "NodeStateManager.h" #include "NodeStateTypes.h" #include <stdio.h> +#include <CommonAPI/CommonAPI.hpp> - +#ifdef ENABLE_TESTS +#include "Test_StubImpl.hpp" +#include "v1/org/genivi/nodestatemachinetest/TestInstanceIds.hpp" +#endif /********************************************************************************************************************** * * Local defines, macros, constants and type definitions. * **********************************************************************************************************************/ -/* There are currently no local defines, macros or types */ - +// CommonAPI connection ID +const char* gConnectionID = "NSMimpl"; +const char* gCapiDomain = "local"; /********************************************************************************************************************** * * Local variables * **********************************************************************************************************************/ - -/* There are currently no local variables */ - +#ifdef ENABLE_TESTS +static std::shared_ptr<CommonAPI::Runtime> gRuntime = NULL; +static std::shared_ptr<Test_StubImpl> gTestStub = NULL; +#endif /********************************************************************************************************************** * * Prototypes for file local functions (see implementation for description) @@ -69,11 +76,30 @@ * Interfaces, exported functions. See header for detailed description. * **********************************************************************************************************************/ +unsigned char NsmcDeInit(void) +{ + printf("NSMC: NsmcDeInit called.\n"); +#ifdef ENABLE_TESTS + gRuntime->unregisterService(gCapiDomain, Test_StubImpl::StubInterface::getInterface(), v1::org::genivi::nodestatemachinetest::Test_INSTANCES[0]); + gTestStub = NULL; +#endif + + return 1; +} unsigned char NsmcInit(void) { printf("NSMC: NsmcInit called.\n"); - +#ifdef ENABLE_TESTS + // Get CommonAPI runtime + gRuntime = CommonAPI::Runtime::get(); + + gTestStub = std::make_shared<Test_StubImpl>(); + if (gRuntime->registerService(gCapiDomain, v1::org::genivi::nodestatemachinetest::Test_INSTANCES[0], gTestStub, gConnectionID) == false) + { + printf("NSMC: Failed to create NSMTest\n"); + } +#endif return 1; } @@ -88,7 +114,7 @@ unsigned char NsmcLucRequired(void) NsmErrorStatus_e NsmcSetData(NsmDataType_e enData, unsigned char *pData, unsigned int u32DataLen) { - printf("NSMC: NsmcSetData called. enData: %d. pData: 0x%08X. u32DataLen: %d\n", enData, (unsigned int) pData, u32DataLen); + printf("NSMC: NsmcSetData called. enData: %d. pData: 0x%08X. u32DataLen: %d\n", enData, (int)(size_t) pData, u32DataLen); return NsmErrorStatus_Ok; } diff --git a/NodeStateMachineStub/NodeStateMachine.h b/NodeStateMachineStub/NodeStateMachine.hpp index d745602..6a7d105 100644 --- a/NodeStateMachineStub/NodeStateMachine.h +++ b/NodeStateMachineStub/NodeStateMachine.hpp @@ -5,6 +5,7 @@ /********************************************************************************************************************** * * Copyright (C) 2012 Continental Automotive Systems, Inc. +* 2017 BMW AG * * Author: Jean-Pierre.Bogler@continental-corporation.com * @@ -78,6 +79,8 @@ the NSM. It is envisaged that in this call the NSMC will create and transfer con thread and will return in the original thread.*/ unsigned char NsmcInit(void); +unsigned char NsmcDeInit(void); + /** \brief Check for Last User Context \retval true: Last User Context (LUC) is required. false: No LUC required. @@ -88,10 +91,10 @@ unsigned char NsmcLucRequired(void); /** \brief Set data in the NodeStateMachine. -\param[in] enData Type of the data to set (see ::NsmDataType_e). +\param[in] enData Type of the data to set (see NsmDataType_e). \param[in] pData Pointer to the memory location containing the data. \param[in] u32DataLen Length of the data that should be set (in byte). -\retval see ::NsmErrorStatus_e +\retval see NsmErrorStatus_e This is a generic interface that can be used by the NSM to inform the NSMC about changes to data items (i.e. events that have occurred in the system) */ @@ -104,14 +107,6 @@ NsmErrorStatus_e NsmcSetData(NsmDataType_e enData, unsigned char *pData, unsigne This will be used by the NSM to request a node restart when requested by one of its clients.*/ unsigned char NsmcRequestNodeRestart(NsmRestartReason_e enRestartReason, unsigned int u32RestartType); - -/** \brief Get version of the interface -\retval Version of the interface as defined in ::SswVersion_t - -This function asks the lifecycle to perform a restart of the main controller. */ -unsigned int NsmcGetInterfaceVersion(void); - - /********************************************************************************************************************** * * MACROS diff --git a/NodeStateMachineStub/Test_StubImpl.cpp b/NodeStateMachineStub/Test_StubImpl.cpp new file mode 100644 index 0000000..422c281 --- /dev/null +++ b/NodeStateMachineStub/Test_StubImpl.cpp @@ -0,0 +1,61 @@ +/********************************************************************************************************************** +* +* Copyright (C) 2017 BMW AG +* +* The header file defines the interfaces offered by the NodeStateMachine stub. +* +* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. +* +**********************************************************************************************************************/ +#include "Test_StubImpl.hpp" + +#include "NodeStateManager.h" +#include "Watchdog.hpp" + +#include <string.h> +#include <unistd.h> + +void Test_StubImpl::SetNsmData(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, GENIVI::NodeStateManagerTypes::NsmDataType_e _DataType, + std::vector<uint8_t> _Data, uint32_t _DataLen, SetNsmDataReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + _reply(NsmSetData((NsmDataType_e)(int) _DataType, _Data.data(), _DataLen)); + NSMUnregisterWatchdog(); +} + +void Test_StubImpl::GetNsmData(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, GENIVI::NodeStateManagerTypes::NsmDataType_e _DataType, + std::vector<uint8_t> _DataIn, uint32_t _DataLen, GetNsmDataReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + /* + * The NSM has a read write interface for getting data. The largest data frame that can be + * exchanged is a NsmSession_s. Therefore, pDataIn is translated into this kind of variable. + */ + int retVal = 0; + std::vector<uint8_t> DataOut; + + NsmSession_s pData; + if(!_DataIn.empty() && sizeof(pData) <= _DataLen) + { + memcpy(&pData, _DataIn.data(), _DataLen); + } + else + { + memset(&pData, 0, sizeof(pData)); + } + + if (_DataLen != (uint32_t)(retVal = NsmGetData((NsmDataType_e)(int) _DataType, (unsigned char*) &pData, _DataLen))) + { + memset(&pData, 0, sizeof(pData)); + DataOut.insert(DataOut.begin(), (uint8_t*) &pData, ((uint8_t*) &pData) + sizeof(pData)); + } + else + { + DataOut.insert(DataOut.begin(), (uint8_t*) &pData, ((uint8_t*) &pData) + _DataLen); + } + + _reply(DataOut, retVal); + NSMUnregisterWatchdog(); +} diff --git a/NodeStateMachineStub/Test_StubImpl.hpp b/NodeStateMachineStub/Test_StubImpl.hpp new file mode 100644 index 0000000..d910a56 --- /dev/null +++ b/NodeStateMachineStub/Test_StubImpl.hpp @@ -0,0 +1,42 @@ +/********************************************************************************************************************** +* +* Copyright (C) 2017 BMW AG +* +* The header file defines the interfaces offered by the NodeStateMachine stub. +* +* This Source Code Form is subject to the terms of the Mozilla Public +* License, v. 2.0. If a copy of the MPL was not distributed with this +* file, You can obtain one at http://mozilla.org/MPL/2.0/. +* +**********************************************************************************************************************/ + +#ifndef TEST_STUBIMPL_HPP +#define TEST_STUBIMPL_HPP + +#include <v1/org/genivi/nodestatemachinetest/TestStubDefault.hpp> +#include <v1/org/genivi/NodeStateManagerTypes.hpp> + +namespace GENIVI = v1::org::genivi; +namespace NodeStateMachineTest = v1::org::genivi::nodestatemachinetest; + +/********************************************************************************************* + * + * NodeStateMachineTest Class + * + *********************************************************************************************/ + +class Test_StubImpl: public NodeStateMachineTest::TestStubDefault +{ + +public: + void SetNsmData(const std::shared_ptr<CommonAPI::ClientId> _client, GENIVI::NodeStateManagerTypes::NsmDataType_e _DataType, + std::vector<uint8_t> _Data, uint32_t _DataLen, SetNsmDataReply_t _reply); + + void GetNsmData(const std::shared_ptr<CommonAPI::ClientId> _client, GENIVI::NodeStateManagerTypes::NsmDataType_e _DataType, + std::vector<uint8_t> _DataIn, uint32_t _DataLen, GetNsmDataReply_t _reply); + +}; + + + +#endif /* NODESTATEMACHINELIFECYCLE_TEST_STUBIMPL_HPP */ |
