/** * \file * struct which represent LinDescriptionFile (header) */ #ifndef LDF_H #define LDF_H #include "buffer.h" /*=================================================================== ======= TYPES ======================================================= ====================================================================*/ #define NAD_BROADCAST 0x7F #define NAD_GOTO_SLEEP 0x00 #define SUPPLIER_WILDCARD 0x7FFF #define FUNCTION_WILDCARD 0xFFFF #define MESSAGE_WILDCARD 0xFFFF /** \addtogroup LDFstruct */ /** \{ */ enum LIN_ID_CONSTANTS /** Constants for LIN IDs. */ { FRAMEID_MAX_NR =64, /**< Maximal number of different frame IDs. */ FRAMEID_DIAGNOSTIC_REQ =60, /**< Message ID of diagnostic frames, request from master. */ FRAMEID_DIAGNOSTIC_RESP =61, /**< Message ID of diagnostic frames, response from slave. */ FRAMEID_USER_DEFINED =62, /**< Message ID of user defined frames. Their length could be greater than LDFstruct::DATABYTES_MAX_NUMBER_NORMAL. */ FRAMEID_RESERVED =63, /**< This message ID is reserved for frames for future use. Their length could be greater than LDFstruct::DATABYTES_MAX_NUMBER_NORMAL. */ }; enum LIN_PID_PARITY_CONSTANTS /** Constants for parity generation of PID field in LIN_parity. */ { LIN_PID_ID_MASK =0x3F, P1_DETERMINING_BITS =0x3A, P0_DETERMINING_BITS =0x17, }; enum Valid { VALID_BIT = 0x1 }; #define DATABYTES_MAX_NUMBER_NORMAL 8 /**< Maximal number of databytes in normal frames. */ #define DATABYTES_NUMBER_DIAGNOSTICFRAME 8 /**< Maximal number of databytes in normal frames. */ #define MAX_STRING_LEN 100 typedef unsigned int TimeRef; enum SlaveNodeDefined { SLAVENODEDEF_INVALID=0, SLAVENODEDEF_NODEVALID=1, SLAVENODEDEF_LOGICALNODE=2 }; /** dummy */ struct ConfiguredNAD { unsigned char configuredNAD; TimeRef startTimeRef; TimeRef endTimeRef; }; /** dummy */ struct ConfiguredFrame { size_t frameIdentPos; unsigned short messageID; /**< Only for 2.0 nodes. */ }; /** dummy */ struct LIN_SlaveNodeAttributesDef { unsigned char slaveNodeValid; char nodeIdent[MAX_STRING_LEN + 1]; /**< Identfier of slave node. */ size_t compositeNodePos; /**< Provides pos of node definition if this is only a logical node. */ unsigned char linProtocolVersionMajor; unsigned char linProtocolVersionMinor; unsigned char initNAD; BufferVector configuredNADs; /**< Configured NADs (struct ConfiguredNAD). */ unsigned short supplierID; unsigned short functionID; unsigned char variantID; size_t responseErrorSignalPos; BufferVector configuredFrames; /**< Configured Frames (struct ConfiguredFrame). */ }; /** dummy */ struct LIN_Nodes { char masterNodeIdent[MAX_STRING_LEN + 1]; /**< Identifier of master node. */ double timebase; /**< Timebase in ms for maximal allowed transfer time of frames. See lin specification. */ double jitter; /**< Jitter in ms. See lin specification. */ BufferVector slaveNodesAttributesDef; /**< Defintions of slave nodes (struct LIN_SlaveNodeAttributesDef). */ }; enum SignalDefined { SIGNALDEFINTION_INVALID=0, SIGNALDEFINTION_SIGNALVALID=1, SIGNALDEFINTION_ENCODINGVALID=2 }; /** dummy */ struct LIN_SignalDef { unsigned char signalValid; char signalIdent[MAX_STRING_LEN + 1]; unsigned char sizeBits; /*ignore initvalues, don't need them for proto*/ unsigned char byteArrayf; size_t publisherIdentPos; BufferVector subscriberNodes; size_t signalEncodingTypePos; /**< Encoding of this signal is defined in LDFstruct::LIN_signalEncodingTypes at this position. */ }; /** Used in union LIN_IncludedData with normal frames. */ struct LIN_IncludedSignal { size_t signalIdentPos; unsigned char signalOffset; /*in bits*/ }; /** Used in union LIN_IncludedData with event triggered frames. */ struct LIN_IncludedFrame { size_t frameIdentPos; }; /** dummy */ union LIN_IncludedData { struct LIN_IncludedSignal includedSignal; /**< Used with normal frames.*/ struct LIN_IncludedFrame includedFrame; /**< Used with event triggered frames.*/ }; /** dummy */ struct LIN_FrameID { unsigned char id; TimeRef startTimeRef; TimeRef endTimeRef; }; enum FrameDef_frameType { FRAMETYPE_NOTDEFINED=0, FRAMTEYPE_UNCONDITIONAL, FRAMETYPE_SPORADIC, FRAMETYPE_EVENTTRIGGERED, FRAMETYPE_DIAGNOSTIC }; enum FrameDef_ChecksumType { CHECKSUMTYPE_NOTDEFINED, CHECKSUMTYPE_CLASSIC, CHECKSUMTYPE_ENHANCED }; /** dummy */ struct LIN_FrameDef { unsigned char frameValidf; char frameIdent[MAX_STRING_LEN + 1]; BufferVector frameIDs; /** Defines assigned ID in dependency of timeRef (struct LIN_FrameID). */ unsigned char frameType; unsigned char checksumType; unsigned char frameSize; /*in bytes*/ size_t publisherIdentPos; BufferVector includedData; /**< Defines included signals (union LIN_IncludedData). */ }; enum SignalEncodingType { SIGNALENCODING_INVALID, SIGNALENCODING_LOGICVALUE, SIGNALENCODING_PHYSICALRANGE, SIGNALENCODING_BCDVALUE, SIGNALENCODING_ASCIIVALUE }; /** dummy */ struct SignalEncodingData { unsigned char encodingType; /**< Defines encoding type (enum LDFstruct::SignalEncodingType). */ union { struct { short unsigned int signalValue; char textInfo[MAX_STRING_LEN + 1]; } logic; struct { short unsigned int minValue; short unsigned int maxValue; double scale; double offset; char textInfo[MAX_STRING_LEN + 1]; } range; } encodingData; }; /** Stores one signal encoding type. */ struct LIN_SignalEncodingType { unsigned char signalEncodingTypeValidf; char encodingIdent[MAX_STRING_LEN + 1]; BufferVector signalEncodingData; /**< Defines encoding values (struct SignalEncodingData). */ }; /** Structure which hold data of parsed Lin Description File. */ typedef struct LDFstruct { struct ProtoInterface *protoInterfacep; const char *compositeConfigurationNamep; /**< Name of a optional composite configuration. */ unsigned char protocolVersionMajor; unsigned char protocolVersionMinor; unsigned char languageVersionMajor; unsigned char languageVersionMinor; double speed; char postfixChannelName[MAX_STRING_LEN + 1]; struct LIN_Nodes nodes; BufferVector LIN_signals; /**< Defined signals (struct LIN_SignalDef). */ BufferVector LIN_frames; /**< Defined frames (struct LIN_FrameDef). */ BufferVector LIN_signalEncodingTypes; /**< Defines signal encoding types (struct LIN_SignalEncodingType). */ } LDFstruct; /** \} */ /*=================================================================== ======= FUNCTIONS =================================================== ====================================================================*/ /** \addtogroup LDFstruct /** \{ */ int LDF_init(LDFstruct *ldfp, struct ProtoInterface *protoInterfacep, const char *compositeConfigurationNamep); /**< Initialize LDFstruct. */ void LDF_destroy(LDFstruct *ldfp); /**< Destroy LDFstruct. */ /** \} */ /** \addtogroup LDF_processing /** \{ */ int LDF_slaveNodeAttributesDefEntry_init(LDFstruct *ldfp, struct LIN_SlaveNodeAttributesDef *slaveNodeAttributesDefp); /**< Initialize struct LIN_SlaveNodeAttributesDef element in struct LIN_Nodes. */ void LDF_slaveNodeAttributesDefEntry_destroy(struct LIN_SlaveNodeAttributesDef *slaveNodeAttributesDefp); int LDF_configuredFrameEntry_init(LDFstruct *ldfp, struct ConfiguredFrame *configuredFramep); void LDF_configuredFrameEntry_destroy(struct ConfiguredFrame *configuredFramep); int LDF_signalDefEntry_init(LDFstruct *ldfp, struct LIN_SignalDef *signalDefp); /**< Initialize struct LIN_SignalDef element. */ void LDF_signalDefEntry_destroy(struct LIN_SignalDef *signalDefp); int LDF_frameDefEntry_init(LDFstruct *ldfp, struct LIN_FrameDef *frameDefp); void LDF_frameDefEntry_destroy(struct LIN_FrameDef *frameDefp); int LDF_frameIDEntry_init(LDFstruct *ldfp, struct LIN_FrameID *frameIDp); void LDF_frameIDEntry_destroy(struct LIN_FrameID *frameIDp); int LDF_includedSignalEntry_init(LDFstruct *ldfp, struct LIN_IncludedSignal *signalp); void LDF_includedSignalEntry_destroy(struct LIN_IncludedSignal *signalp); int LDF_includedFrameEntry_init(LDFstruct *ldfp, struct LIN_IncludedFrame *framep); void LDF_includedFrameEntry_destroy(struct LIN_IncludedFrame *framep); int LDF_signalEncodingTypeEntry_init(LDFstruct *ldfp, struct LIN_SignalEncodingType *encodingTypep); void LDF_signalEncodingTypeEntry_destroy(struct LIN_SignalEncodingType *encodingTypep); int LDF_encodingDataEntry_init(LDFstruct *ldfp, struct SignalEncodingData *encodingDatap); void LDF_encodingDataEntry_destroy(struct SignalEncodingData *encodingDatap); int LDF_nodeIdentFind(LDFstruct *ldfp, const char *identString, size_t *posp); /**< Searches in namespace of nodes for identifier \a identString and stores postion in \a posp. This value can be used to get information about this node later using e.g. LDF_slaveNodeAttributesDef_getRef(). \returns true if \a identString is in namespace of nodes. */ int LDF_nodeIdentFindCreate(LDFstruct *ldfp, const char *identString, size_t *posp); char* LDF_nodeIdentGet(LDFstruct *ldfp, size_t pos); /**< Returns pointer to name of identifier of node at position \a pos. \sa LDF_nodeIdentFind() */ int LDF_signalIdentFind(LDFstruct *ldfp, const char *identString, size_t *posp); /**< Searches in namespace of signals for identifier \a identString and stores position in \a posp. This value can be used to get information about this signal later using e.g. LDF_signalDef_getRef(). \returns true if \a identString is in namespace of signals. */ int LDF_signalIdentFindCreate(LDFstruct *ldfp, const char *identString, size_t *posp); char* LDF_signalIdentGet(LDFstruct* ldfp, size_t pos); /**< Returns pointer to name of identifier of signal at position \a pos. \sa LDF_signalIdentFind() */ int LDF_nodeFind_ByConfiguredNADTimeref(LDFstruct *ldfp, unsigned char configuredNAD, unsigned int timeRef, size_t *startPosp); /**< Returns true if slave node can be found with \a configuredNAD at \a timeRef and sets \a *posp to its position. \a *posp also defines the start position, therefore this function can be used in a while loop to find all matching slave nodes. Don't forget to increment *posp before calling this function again. To search all slave nodes set \a *posp = 0 or *posp = 1.*/ int LDF_nodeFind_ByInitNAD(LDFstruct *ldfp, unsigned char initNAD, size_t *posp); int LDF_configuredNAD_append(LDFstruct *ldfp, struct LIN_SlaveNodeAttributesDef *slaveNodeAttributesDefp, unsigned char configuredNAD, TimeRef timeRef); int LDF_frameIdentFind(LDFstruct *ldfp, const char *identString, size_t *posp); int LDF_frameIdentFindCreate(LDFstruct *ldfp, const char *identString, size_t *posp); char* LDF_frameIdentGet(LDFstruct* ldfp, size_t pos); int LDF_frameFind_ByIdTimeref(LDFstruct *ldfp, unsigned char frameID, unsigned int timeRef, size_t *posp); /**< Searches for definition of frame which has at \a timeRef the assigned ID \a id. */ int LDF_frameID_append(LDFstruct *ldfp, struct LIN_FrameDef *frameDefp, unsigned char id, TimeRef timeRef); int LDF_signalEncodingTypeIdentFind(LDFstruct *ldfp, const char *identString, size_t *posp); int LDF_signalEncodingTypeIdentFindCreate(LDFstruct *ldfp, const char *identString, size_t *posp); char* LDF_signalEncodingTypeIdentGet(LDFstruct* ldfp, size_t pos); struct SignalEncodingData* LDF_signalEncodingData_getRef_byRawValue(LDFstruct *ldfp, size_t signalEncodingTypePos, unsigned short rawValue); /**< Returns pointer to struct SignalEncodingData which matches the \a rawValue for an entry in struct LIN_SignalEncodingType::signalEncodingData buffer. The matching entry is searched in LDFstruct::LIN_signalEncodingTypes at position \a signalEncodingTypePos. */ struct SignalEncodingData* LDF_signalEncodingData_getRef_withoutRawValue(LDFstruct *ldfp, size_t signalEncodingTypePos); /** Initialize struct ConfiguredNAD element. Works identically to struct LIN_FrameID. */ INLINE int LDF_configuredNADEntry_init(LDFstruct *ldfp, struct ConfiguredNAD *configuredNADp) { return LDF_frameIDEntry_init(ldfp, (struct LIN_FrameID*) configuredNADp); } INLINE void LDF_configuredNADEntry_destroy(struct ConfiguredNAD *configuredNADp) { LDF_frameIDEntry_destroy((struct LIN_FrameID*) configuredNADp); } /** Returns pointer to node definition of node at postition \a pos or null pointer this node does not exist or if masternode was referenced. \sa LDF_nodeIdentFind() */ INLINE struct LIN_SlaveNodeAttributesDef* LDF_slaveNodeAttributesDef_getRef(LDFstruct *ldfp, size_t pos) { if (pos == 0) return NULL; return (struct LIN_SlaveNodeAttributesDef*) bufferVector_getElementRef(&ldfp->nodes.slaveNodesAttributesDef, pos - 1); } /** Returns pointer to signal definition of signal at position \a pos or null pointer if this signal does not exist. \sa LDF_signalIdentFind() */ INLINE struct LIN_SignalDef* LDF_signalDef_getRef(LDFstruct *ldfp, size_t pos) { return (struct LIN_SignalDef*) bufferVector_getElementRef(&ldfp->LIN_signals, pos); } INLINE struct LIN_FrameDef* LDF_frameDef_getRef(LDFstruct *ldfp, size_t pos) { return (struct LIN_FrameDef*) bufferVector_getElementRef(&ldfp->LIN_frames, pos); } INLINE struct LIN_SignalEncodingType* LDF_signalEncodingTypeDef_getRef(LDFstruct *ldfp, size_t pos) { return (struct LIN_SignalEncodingType*) bufferVector_getElementRef(&ldfp->LIN_signalEncodingTypes, pos); } INLINE int LDF_timeRefCheck(TimeRef compareTimeRef, TimeRef startTimeRef, TimeRef endTimeRef) { return (startTimeRef <= compareTimeRef && (endTimeRef == 0 || compareTimeRef < endTimeRef)); } INLINE size_t LDF_nodeGetPhysicalNode(LDFstruct *ldfp, size_t pos) { struct LIN_SlaveNodeAttributesDef *slaveNodeAttributesDefp = NULL; slaveNodeAttributesDefp = LDF_slaveNodeAttributesDef_getRef(ldfp, pos); while (slaveNodeAttributesDefp->slaveNodeValid == SLAVENODEDEF_LOGICALNODE) { pos = slaveNodeAttributesDefp->compositeNodePos; slaveNodeAttributesDefp = LDF_slaveNodeAttributesDef_getRef(ldfp, pos); } return pos; } /** \} */ #endif