diff --git a/SilKit/include/silkit/capi/Flexray.h b/SilKit/include/silkit/capi/Flexray.h index 038cf5c27..528f5b37f 100644 --- a/SilKit/include/silkit/capi/Flexray.h +++ b/SilKit/include/silkit/capi/Flexray.h @@ -216,12 +216,6 @@ struct SilKit_FlexrayNodeParameters //! Maximum permissible rate correction value (range 3-3846 MicroTicks). SilKit_FlexrayMicroTick pRateCorrectionOut; - ////! Not used by network simulator - // pSecondKeySlotID - - ////! Not used by network simulator - // pTwoKeySlotMode - //! Channel used by the node to send a wakeup pattern (values FlexrayChannel::A, FlexrayChannel::B). SilKit_FlexrayChannel pWakeupChannel; @@ -242,6 +236,15 @@ struct SilKit_FlexrayNodeParameters //! Number of samples per MicroTick (values 1 or 2). uint8_t pSamplesPerMicrotick; + + // ---------------------------------------------------------------------- + // Parameters according to B.3.2.1 (added in SIL Kit 5.0.3) + + //! Second Key Slot ID of the key slot (range 0-1023, value 0 means that there is no key slot). + uint16_t pSecondKeySlotId; + + //! Second Key slot is used for startup with a single cold start node (range 0, 1). + uint8_t pTwoKeySlotMode; }; typedef struct SilKit_FlexrayNodeParameters SilKit_FlexrayNodeParameters; diff --git a/SilKit/include/silkit/capi/InterfaceIdentifiers.h b/SilKit/include/silkit/capi/InterfaceIdentifiers.h index 609b2870a..7490bd666 100644 --- a/SilKit/include/silkit/capi/InterfaceIdentifiers.h +++ b/SilKit/include/silkit/capi/InterfaceIdentifiers.h @@ -137,7 +137,7 @@ typedef struct #define SilKit_FlexrayWakeupEvent_VERSION 1 #define SilKit_FlexrayControllerConfig_VERSION 1 #define SilKit_FlexrayClusterParameters_VERSION 1 -#define SilKit_FlexrayNodeParameters_VERSION 1 +#define SilKit_FlexrayNodeParameters_VERSION 2 #define SilKit_FlexrayHostCommand_VERSION 1 #define SilKit_FlexrayHeader_VERSION 1 #define SilKit_FlexrayFrame_VERSION 1 diff --git a/SilKit/include/silkit/detail/impl/HourglassConversions.hpp b/SilKit/include/silkit/detail/impl/HourglassConversions.hpp index b242e4225..a323d02e7 100644 --- a/SilKit/include/silkit/detail/impl/HourglassConversions.hpp +++ b/SilKit/include/silkit/detail/impl/HourglassConversions.hpp @@ -221,6 +221,8 @@ inline void assignCxxToC(const SilKit::Services::Flexray::FlexrayNodeParameters& cOut.pWakeupPattern = cxxIn.pWakeupPattern; cOut.pdMicrotick = static_cast(cxxIn.pdMicrotick); cOut.pSamplesPerMicrotick = cxxIn.pSamplesPerMicrotick; + cOut.pTwoKeySlotMode = cxxIn.pTwoKeySlotMode; + cOut.pSecondKeySlotId = cxxIn.pSecondKeySlotId; } inline void assignCxxToC(const SilKit::Services::Flexray::FlexrayTxBufferConfig& cxxIn, @@ -651,6 +653,8 @@ inline void assignCToCxx(const SilKit_FlexrayNodeParameters* cIn, cxxOut.pWakeupPattern = cIn->pWakeupPattern; cxxOut.pdMicrotick = (SilKit::Services::Flexray::FlexrayClockPeriod)cIn->pdMicrotick; cxxOut.pSamplesPerMicrotick = cIn->pSamplesPerMicrotick; + cxxOut.pTwoKeySlotMode = cIn->pTwoKeySlotMode; + cxxOut.pSecondKeySlotId = cIn->pSecondKeySlotId; } // ----------------------------------- diff --git a/SilKit/include/silkit/detail/impl/services/flexray/FlexrayController.hpp b/SilKit/include/silkit/detail/impl/services/flexray/FlexrayController.hpp index 06150cd29..6234b21fa 100644 --- a/SilKit/include/silkit/detail/impl/services/flexray/FlexrayController.hpp +++ b/SilKit/include/silkit/detail/impl/services/flexray/FlexrayController.hpp @@ -567,6 +567,8 @@ void CxxToC(const SilKit::Services::Flexray::FlexrayNodeParameters& cxxFlexrayNo cFlexrayNodeParameters.pWakeupPattern = cxxFlexrayNodeParameters.pWakeupPattern; cFlexrayNodeParameters.pdMicrotick = static_cast(cxxFlexrayNodeParameters.pdMicrotick); cFlexrayNodeParameters.pSamplesPerMicrotick = cxxFlexrayNodeParameters.pSamplesPerMicrotick; + cFlexrayNodeParameters.pTwoKeySlotMode = cxxFlexrayNodeParameters.pTwoKeySlotMode; + cFlexrayNodeParameters.pSecondKeySlotId = cxxFlexrayNodeParameters.pSecondKeySlotId; } void CxxToC(const SilKit::Services::Flexray::FlexrayTxBufferConfig& cxxFlexrayTxBufferConfig, diff --git a/SilKit/include/silkit/services/flexray/FlexrayDatatypes.hpp b/SilKit/include/silkit/services/flexray/FlexrayDatatypes.hpp index 62846f3ca..e7d1c04c6 100644 --- a/SilKit/include/silkit/services/flexray/FlexrayDatatypes.hpp +++ b/SilKit/include/silkit/services/flexray/FlexrayDatatypes.hpp @@ -211,13 +211,6 @@ struct FlexrayNodeParameters //! Maximum permissible rate correction value (range 3-3846 MicroTicks). FlexrayMicroTick pRateCorrectionOut; - - ////! Not used by network simulator - //pSecondKeySlotID - - ////! Not used by network simulator - //pTwoKeySlotMode - //! Channel used by the node to send a wakeup pattern (values FlexrayChannel::A, FlexrayChannel::B). FlexrayChannel pWakeupChannel; @@ -238,6 +231,15 @@ struct FlexrayNodeParameters //! Number of samples per MicroTick (values 1 or 2). uint8_t pSamplesPerMicrotick; + + // ---------------------------------------------------------------------- + // Parameters according to B.3.2.1 (added in SIL Kit 5.0.3) + + //! Second Key Slot ID of the key slot (range 0-1023, value 0 means that there is no key slot). + uint16_t pSecondKeySlotId; + + //! Second Key slot is used for startup with a single cold start node (range 0, 1). + uint8_t pTwoKeySlotMode; }; //! Transmission mode for FlexRay Tx-Buffer @@ -537,7 +539,9 @@ inline bool operator==(const FlexrayNodeParameters& lhs, const FlexrayNodeParame && lhs.pOffsetCorrectionStart == rhs.pOffsetCorrectionStart && lhs.pRateCorrectionOut == rhs.pRateCorrectionOut && lhs.pWakeupChannel == rhs.pWakeupChannel && lhs.pWakeupPattern == rhs.pWakeupPattern && lhs.pdMicrotick == rhs.pdMicrotick - && lhs.pSamplesPerMicrotick == rhs.pSamplesPerMicrotick; + && lhs.pSamplesPerMicrotick == rhs.pSamplesPerMicrotick && lhs.pSecondKeySlotId == rhs.pSecondKeySlotId + && lhs.pTwoKeySlotMode == rhs.pTwoKeySlotMode + ; } inline bool operator==(const FlexrayTxBufferConfig& lhs, const FlexrayTxBufferConfig& rhs) diff --git a/SilKit/source/capi/CapiFlexray.cpp b/SilKit/source/capi/CapiFlexray.cpp index 568f34df8..644706fce 100644 --- a/SilKit/source/capi/CapiFlexray.cpp +++ b/SilKit/source/capi/CapiFlexray.cpp @@ -54,29 +54,40 @@ void assign(SilKit::Services::Flexray::FlexrayClusterParameters& cppClusterParam void assign(SilKit::Services::Flexray::FlexrayNodeParameters& cppNodeParameters, const SilKit_FlexrayNodeParameters* nodeParameters) { - cppNodeParameters.pAllowHaltDueToClock = nodeParameters->pAllowHaltDueToClock; - cppNodeParameters.pAllowPassiveToActive = nodeParameters->pAllowPassiveToActive; - cppNodeParameters.pChannels = (SilKit::Services::Flexray::FlexrayChannel)nodeParameters->pChannels; - cppNodeParameters.pClusterDriftDamping = nodeParameters->pClusterDriftDamping; - cppNodeParameters.pdAcceptedStartupRange = nodeParameters->pdAcceptedStartupRange; - cppNodeParameters.pdListenTimeout = nodeParameters->pdListenTimeout; - cppNodeParameters.pKeySlotId = nodeParameters->pKeySlotId; - cppNodeParameters.pKeySlotOnlyEnabled = nodeParameters->pKeySlotOnlyEnabled; - cppNodeParameters.pKeySlotUsedForStartup = nodeParameters->pKeySlotUsedForStartup; - cppNodeParameters.pKeySlotUsedForSync = nodeParameters->pKeySlotUsedForSync; - cppNodeParameters.pLatestTx = nodeParameters->pLatestTx; - cppNodeParameters.pMacroInitialOffsetA = nodeParameters->pMacroInitialOffsetA; - cppNodeParameters.pMacroInitialOffsetB = nodeParameters->pMacroInitialOffsetB; - cppNodeParameters.pMicroInitialOffsetA = nodeParameters->pMicroInitialOffsetA; - cppNodeParameters.pMicroInitialOffsetB = nodeParameters->pMicroInitialOffsetB; - cppNodeParameters.pMicroPerCycle = nodeParameters->pMicroPerCycle; - cppNodeParameters.pOffsetCorrectionOut = nodeParameters->pOffsetCorrectionOut; - cppNodeParameters.pOffsetCorrectionStart = nodeParameters->pOffsetCorrectionStart; - cppNodeParameters.pRateCorrectionOut = nodeParameters->pRateCorrectionOut; - cppNodeParameters.pWakeupChannel = (SilKit::Services::Flexray::FlexrayChannel)nodeParameters->pWakeupChannel; - cppNodeParameters.pWakeupPattern = nodeParameters->pWakeupPattern; - cppNodeParameters.pdMicrotick = (SilKit::Services::Flexray::FlexrayClockPeriod)nodeParameters->pdMicrotick; - cppNodeParameters.pSamplesPerMicrotick = nodeParameters->pSamplesPerMicrotick; + const auto inputVersion = SK_ID_GET_VERSION(SilKit_Struct_GetId(*nodeParameters)); + + if (inputVersion == 1 || inputVersion == 2) + { + cppNodeParameters.pAllowHaltDueToClock = nodeParameters->pAllowHaltDueToClock; + cppNodeParameters.pAllowPassiveToActive = nodeParameters->pAllowPassiveToActive; + cppNodeParameters.pChannels = (SilKit::Services::Flexray::FlexrayChannel)nodeParameters->pChannels; + cppNodeParameters.pClusterDriftDamping = nodeParameters->pClusterDriftDamping; + cppNodeParameters.pdAcceptedStartupRange = nodeParameters->pdAcceptedStartupRange; + cppNodeParameters.pdListenTimeout = nodeParameters->pdListenTimeout; + cppNodeParameters.pKeySlotId = nodeParameters->pKeySlotId; + cppNodeParameters.pKeySlotOnlyEnabled = nodeParameters->pKeySlotOnlyEnabled; + cppNodeParameters.pKeySlotUsedForStartup = nodeParameters->pKeySlotUsedForStartup; + cppNodeParameters.pKeySlotUsedForSync = nodeParameters->pKeySlotUsedForSync; + cppNodeParameters.pLatestTx = nodeParameters->pLatestTx; + cppNodeParameters.pMacroInitialOffsetA = nodeParameters->pMacroInitialOffsetA; + cppNodeParameters.pMacroInitialOffsetB = nodeParameters->pMacroInitialOffsetB; + cppNodeParameters.pMicroInitialOffsetA = nodeParameters->pMicroInitialOffsetA; + cppNodeParameters.pMicroInitialOffsetB = nodeParameters->pMicroInitialOffsetB; + cppNodeParameters.pMicroPerCycle = nodeParameters->pMicroPerCycle; + cppNodeParameters.pOffsetCorrectionOut = nodeParameters->pOffsetCorrectionOut; + cppNodeParameters.pOffsetCorrectionStart = nodeParameters->pOffsetCorrectionStart; + cppNodeParameters.pRateCorrectionOut = nodeParameters->pRateCorrectionOut; + cppNodeParameters.pWakeupChannel = (SilKit::Services::Flexray::FlexrayChannel)nodeParameters->pWakeupChannel; + cppNodeParameters.pWakeupPattern = nodeParameters->pWakeupPattern; + cppNodeParameters.pdMicrotick = (SilKit::Services::Flexray::FlexrayClockPeriod)nodeParameters->pdMicrotick; + cppNodeParameters.pSamplesPerMicrotick = nodeParameters->pSamplesPerMicrotick; + } + + if (inputVersion == 2) + { + cppNodeParameters.pTwoKeySlotMode = nodeParameters->pTwoKeySlotMode; + cppNodeParameters.pSecondKeySlotId = nodeParameters->pSecondKeySlotId; + } } void assign(SilKit::Services::Flexray::FlexrayControllerConfig& cppConfig, const SilKit_FlexrayControllerConfig* config) diff --git a/SilKit/source/config/ParticipantConfiguration_Full.json b/SilKit/source/config/ParticipantConfiguration_Full.json index 877094193..6f04a8ed1 100644 --- a/SilKit/source/config/ParticipantConfiguration_Full.json +++ b/SilKit/source/config/ParticipantConfiguration_Full.json @@ -116,7 +116,9 @@ "pWakeupPattern": 33, "pdAcceptedStartupRange": 212, "pdListenTimeout": 400162, - "pdMicrotick": "25ns" + "pdMicrotick": "25ns", + "pSecondKeySlotId": 1337, + "pTwoKeySlotMode": 1 }, "TxBufferConfigurations": [ { diff --git a/SilKit/source/config/ParticipantConfiguration_Full.yaml b/SilKit/source/config/ParticipantConfiguration_Full.yaml index 3f938d2bc..4c08d28a3 100644 --- a/SilKit/source/config/ParticipantConfiguration_Full.yaml +++ b/SilKit/source/config/ParticipantConfiguration_Full.yaml @@ -89,11 +89,14 @@ FlexrayControllers: pOffsetCorrectionStart: 3632 pRateCorrectionOut: 81 pSamplesPerMicrotick: 2 + pSecondKeySlotId: 1337 + pTwoKeySlotMode: 1 pWakeupChannel: A pWakeupPattern: 33 pdAcceptedStartupRange: 212 pdListenTimeout: 400162 pdMicrotick: 25ns + TxBufferConfigurations: - channels: A headerCrc: 0 diff --git a/SilKit/source/config/YamlParser.hpp b/SilKit/source/config/YamlParser.hpp index 15bc54889..9684b5a4f 100644 --- a/SilKit/source/config/YamlParser.hpp +++ b/SilKit/source/config/YamlParser.hpp @@ -49,7 +49,7 @@ auto Deserialize(const std::string& input) -> T auto root = tree.crootref(); R reader{parser, root}; - T result; + T result{}; reader.Read(result); return result; } diff --git a/SilKit/source/config/YamlReader.cpp b/SilKit/source/config/YamlReader.cpp index f53c07f94..6a796eb39 100644 --- a/SilKit/source/config/YamlReader.cpp +++ b/SilKit/source/config/YamlReader.cpp @@ -97,6 +97,8 @@ void YamlReader::Read(SilKit::Services::Flexray::FlexrayNodeParameters& obj) ReadKeyValue(obj.pWakeupChannel, "pWakeupChannel"); ReadKeyValue(obj.pdMicrotick, "pdMicrotick"); ReadKeyValue(obj.pChannels, "pChannels"); + OptionalRead(obj.pSecondKeySlotId, "pSecondKeySlotId"); + OptionalRead(obj.pTwoKeySlotMode, "pTwoKeySlotMode"); } void YamlReader::Read(SilKit::Services::Flexray::FlexrayTxBufferConfig& obj) diff --git a/SilKit/source/config/YamlReader.hpp b/SilKit/source/config/YamlReader.hpp index d513e1d04..8e74b4fea 100644 --- a/SilKit/source/config/YamlReader.hpp +++ b/SilKit/source/config/YamlReader.hpp @@ -57,7 +57,7 @@ class BasicYamlReader auto&& child = GetChildSafe(name); if (child.IsValid()) { - T tmp; + T tmp{}; child.Read(tmp); val = std::move(tmp); // needs a proper setter to set "has_value" } diff --git a/SilKit/source/config/YamlValidator.cpp b/SilKit/source/config/YamlValidator.cpp index be94b362b..d22b36136 100644 --- a/SilKit/source/config/YamlValidator.cpp +++ b/SilKit/source/config/YamlValidator.cpp @@ -246,6 +246,10 @@ const std::set schemaPaths_v1 = { "/FlexRayControllers/NodeParameters/pWakeupChannel", "/FlexrayControllers/NodeParameters/pWakeupPattern", "/FlexRayControllers/NodeParameters/pWakeupPattern", + "/FlexrayControllers/NodeParameters/pSecondKeySlotId", + "/FlexRayControllers/NodeParameters/pSecondKeySlotId", + "/FlexrayControllers/NodeParameters/pTwoKeySlotMode", + "/FlexRayControllers/NodeParameters/pTwoKeySlotMode", "/FlexrayControllers/Replay", "/FlexRayControllers/Replay", "/FlexrayControllers/Replay/Direction", diff --git a/SilKit/source/config/YamlWriter.cpp b/SilKit/source/config/YamlWriter.cpp index 6e817aa84..1bcadc815 100644 --- a/SilKit/source/config/YamlWriter.cpp +++ b/SilKit/source/config/YamlWriter.cpp @@ -99,6 +99,7 @@ void YamlWriter::Write(const SilKit::Services::Flexray::FlexrayClusterParameters void YamlWriter::Write(const SilKit::Services::Flexray::FlexrayNodeParameters& obj) { + static const SilKit::Services::Flexray::FlexrayNodeParameters defaultNodeParams{}; MakeMap(); WriteKeyValue("pAllowHaltDueToClock", obj.pAllowHaltDueToClock); WriteKeyValue("pAllowPassiveToActive", obj.pAllowPassiveToActive); @@ -123,6 +124,8 @@ void YamlWriter::Write(const SilKit::Services::Flexray::FlexrayNodeParameters& o WriteKeyValue("pWakeupChannel", obj.pWakeupChannel); WriteKeyValue("pdMicrotick", obj.pdMicrotick); WriteKeyValue("pChannels", obj.pChannels); + NonDefaultWrite(obj.pSecondKeySlotId, "pSecondKeySlotId", defaultNodeParams.pSecondKeySlotId); + NonDefaultWrite(obj.pTwoKeySlotMode, "pTwoKeySlotMode", defaultNodeParams.pTwoKeySlotMode); } diff --git a/SilKit/source/services/flexray/FlexraySerdes.cpp b/SilKit/source/services/flexray/FlexraySerdes.cpp index 5456eabdb..7a4948158 100644 --- a/SilKit/source/services/flexray/FlexraySerdes.cpp +++ b/SilKit/source/services/flexray/FlexraySerdes.cpp @@ -184,12 +184,22 @@ inline SilKit::Core::MessageBuffer& operator<<(SilKit::Core::MessageBuffer& buff const FlexrayControllerConfig& config) { buffer << config.clusterParams << config.nodeParams << config.bufferConfigs; + // Support for struct FlexrayControllerConfig version 2: + // ensure that the pSecondKeySlotId and pTwoKeySlotMode are also serialized after the bufferConfigs + // otherwise we will confuse the buffer deserialization of the bufferConfigs + buffer << config.nodeParams.pSecondKeySlotId << config.nodeParams.pTwoKeySlotMode; return buffer; } inline SilKit::Core::MessageBuffer& operator>>(SilKit::Core::MessageBuffer& buffer, FlexrayControllerConfig& config) { buffer >> config.clusterParams >> config.nodeParams >> config.bufferConfigs; + // Support for struct FlexrayControllerConfig version 2: + // the pSecondKeySlotId and pTwoKeySlotMode were added after the bufferConfigs + if (buffer.RemainingBytesLeft() > 0) + { + buffer >> config.nodeParams.pSecondKeySlotId >> config.nodeParams.pTwoKeySlotMode; + } return buffer; } diff --git a/SilKit/source/services/flexray/Test_FlexrayController.cpp b/SilKit/source/services/flexray/Test_FlexrayController.cpp index 625345c55..5c08474b9 100644 --- a/SilKit/source/services/flexray/Test_FlexrayController.cpp +++ b/SilKit/source/services/flexray/Test_FlexrayController.cpp @@ -46,7 +46,7 @@ auto GetDummyConfig() -> SilKit::Config::FlexrayController auto MakeValidClusterParams() -> FlexrayClusterParameters { - FlexrayClusterParameters clusterParams; + FlexrayClusterParameters clusterParams{}; clusterParams.gColdstartAttempts = 2; clusterParams.gCycleCountMax = 7; clusterParams.gdActionPointOffset = 1; @@ -73,7 +73,7 @@ auto MakeValidClusterParams() -> FlexrayClusterParameters auto MakeValidNodeParams() -> FlexrayNodeParameters { - FlexrayNodeParameters nodeParams; + FlexrayNodeParameters nodeParams{}; nodeParams.pAllowHaltDueToClock = 0; nodeParams.pAllowPassiveToActive = 0; nodeParams.pChannels = FlexrayChannel::A; @@ -116,7 +116,7 @@ auto MakeValidTxBufferConfig() -> FlexrayTxBufferConfig auto GetDummyConfigWithValues() -> SilKit::Config::FlexrayController { - SilKit::Config::FlexrayController dummyConfig; + SilKit::Config::FlexrayController dummyConfig{}; dummyConfig.network = "testNetwork"; dummyConfig.name = "testController"; dummyConfig.clusterParameters = MakeValidClusterParams();