From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Master/Masterarbeit/src/common/cpu_load.sh | 10 + .../Masterarbeit/src/common/inc/CNetworkStream.h | 189 ++++++++ .../Masterarbeit/src/common/inc/IPluginExecutor.h | 26 + .../Masterarbeit/src/common/inc/NetworkMessages.h | 282 +++++++++++ Master/Masterarbeit/src/common/inc/NetworkTypes.h | 467 ++++++++++++++++++ Master/Masterarbeit/src/common/inc/global.h | 162 +++++++ .../src/common/inc/interface_manager.h | 99 ++++ Master/Masterarbeit/src/common/inc/plugin_api.h | 138 ++++++ .../Masterarbeit/src/common/inc/plugin_api_heap.h | 53 ++ Master/Masterarbeit/src/common/inc/protocol.h | 70 +++ .../Masterarbeit/src/common/src/CNetworkStream.cpp | 203 ++++++++ .../Masterarbeit/src/common/src/NetworkTypes.cpp | 540 +++++++++++++++++++++ 12 files changed, 2239 insertions(+) create mode 100644 Master/Masterarbeit/src/common/cpu_load.sh create mode 100644 Master/Masterarbeit/src/common/inc/CNetworkStream.h create mode 100644 Master/Masterarbeit/src/common/inc/IPluginExecutor.h create mode 100644 Master/Masterarbeit/src/common/inc/NetworkMessages.h create mode 100644 Master/Masterarbeit/src/common/inc/NetworkTypes.h create mode 100644 Master/Masterarbeit/src/common/inc/global.h create mode 100644 Master/Masterarbeit/src/common/inc/interface_manager.h create mode 100644 Master/Masterarbeit/src/common/inc/plugin_api.h create mode 100644 Master/Masterarbeit/src/common/inc/plugin_api_heap.h create mode 100644 Master/Masterarbeit/src/common/inc/protocol.h create mode 100644 Master/Masterarbeit/src/common/src/CNetworkStream.cpp create mode 100644 Master/Masterarbeit/src/common/src/NetworkTypes.cpp (limited to 'Master/Masterarbeit/src/common') diff --git a/Master/Masterarbeit/src/common/cpu_load.sh b/Master/Masterarbeit/src/common/cpu_load.sh new file mode 100644 index 0000000..7ab284a --- /dev/null +++ b/Master/Masterarbeit/src/common/cpu_load.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# file: cpu_load.sh +# date: 20.12.2011 +# author: S. Eisenhauer +# purpose: Generate CPU load by generating random numbers and IO load by writing to a file at high priority +# +# warning: Must be called with root privileges for negative nice values (-20 means highest priority) +# +nice -n -20 dd if=/dev/urandom of=../data/urandom diff --git a/Master/Masterarbeit/src/common/inc/CNetworkStream.h b/Master/Masterarbeit/src/common/inc/CNetworkStream.h new file mode 100644 index 0000000..2b94e71 --- /dev/null +++ b/Master/Masterarbeit/src/common/inc/CNetworkStream.h @@ -0,0 +1,189 @@ +/*! + * \file CNetworkStream.h + * \author S. Eisenhauer + * \date 12.01.2012 + * \brief Stream access to network data buffers + * + * This file defines classes for accessing the data stored in networked buffers as streams + * + */ +#ifndef CNETWORKSTREAM_H_ +#define CNETWORKSTREAM_H_ + +#include "global.h" +#include "protocol.h" + +/// enumeration of stream errors +enum tenStreamError +{ + nenStreamOK = 0, //!< stream is ok + nenErrorValueOutOfRange = -1, //!< a value in the stream is out of the configured min. max. range + nenErrorStreamToShort = -2 //!< no bytes left in stream for reading or writing +}; + +/*! + * \brief class for read access to a data buffer as stream + */ +class CNetworkInStream +{ +public: + /*! + * \brief constructor + * \param[in] pu8Buffer Pointer to the buffer which is handled by the stream + * \param[in] u32BufferSize Size of the buffer in bytes + */ + CNetworkInStream(uint8_t* pu8Buffer, uint32_t u32BufferSize); + /*! + * \brief read a signed 8 bit integer from the stream + * \param[out] i8Val Reference to storage for the value + */ + void vReadInt8(int8_t& i8Val); + /*! + * \brief read a unsigned 8 bit integer from the stream + * \param[out] u8Val Reference to storage for the value + */ + void vReadUint8(uint8_t& u8Val); + /*! + * \brief read a signed 32 bit integer from the stream + * \param[out] i32Val Reference to storage for the value + */ + void vReadInt32(int32_t& i32Val); + /*! + * \brief read a unsigned 32 bit integer from the stream + * \param[out] u32Val Reference to storage for the value + */ + void vReadUint32(uint32_t& u32Val); + /*! + * \brief read a string from the stream + * \param[out] pcVal Reference to storage for the value + * \param[in] u32Length Length of the expected string + */ + void vReadString(char* pcVal, const uint32_t u32Length); + /*! + * \brief get number of bytes used in stream + * \return number of bytes used in stream + */ + uint32_t u32GetByteCount() const; + /*! + * \brief set stream to a position + * \param[in] u32Offset position to set stream to as offset from start position (=0) + */ + void vSetPosition(const uint32_t u32Offset); + /*! + * \brief check if stream is OK + * \return TRUE if no error is set for stream, FALSE otherwise + */ + bool boIsOK() const; + /*! + * \brief get error of stream + * \param[out] enError stream error code + */ + void vGetError(tenStreamError& enError) const; + /*! + * \brief set error code of stream + * \param[in] enError error to set for stream + */ + void vSetError(tenStreamError enError); + /*! + * \brief reset stream. Set position to start and error to nenStreamOK + */ + void vReset(); +private: + CNetworkInStream(const CNetworkInStream& rxOther); + CNetworkInStream& operator= (const CNetworkInStream& rxOther); + /*! + * \brief checks that a sufficient number of bytes is left in the stream + * \param[in] u32Length number of bytes to check the stream for + */ + bool boCheck(const uint32_t u32Length); + + const uint8_t* m_pu8CurrentPtr; + const uint8_t* const m_pru8StartPtr; + const uint8_t* const m_pru8EndPtr; + tenStreamError m_enError; +}; + +/*! + * \brief class for write access to a data buffer as stream + */ +class CNetworkOutStream +{ +public: + /*! + * \brief constructor + * \param[in] pu8Buffer Pointer to the buffer which is handled by the stream + * \param[in] u32BufferSize Size of the buffer in bytes + */ + CNetworkOutStream(uint8_t* pu8Buffer, uint32_t u32BufferSize); + /*! + * \brief write a signed 8 bit integer to the stream + * \param[in] i8Val Reference to the value to write to the stream + */ + void vWriteInt8(const int8_t i8Val); + /*! + * \brief write a unsigned 8 bit integer to the stream + * \param[in] u8Val Reference to the value to write to the stream + */ + void vWriteUint8(const uint8_t u8Val); + /*! + * \brief write a signed 32 bit integer to the stream + * \param[in] i32Val Reference to the value to write to the stream + */ + void vWriteInt32(const int32_t i32Val); + /*! + * \brief write a unsigned 32 bit integer to the stream + * \param[in] u32Val Reference to the value to write to the stream + */ + void vWriteUint32(const uint32_t u32Val); + /*! + * \brief write a string to the stream + * \param[in] pcVal string to write to the stream + * \param[in] u32Length Length of the string + */ + void vWriteString(const char* pcVal, const uint32_t u32Length); + /*! + * \brief get number of bytes used in stream + * \return number of bytes used in stream + */ + uint32_t u32GetByteCount() const; + /*! + * \brief set stream to a position + * \param[in] u32Offset position to set stream to as offset from start position (=0) + */ + void vSetPosition(const uint32_t u32Offset); + /*! + * \brief check if stream is OK + * \return TRUE if no error is set for stream, FALSE otherwise + */ + bool boIsOK() const; + /*! + * \brief get error of stream + * \param[out] enError stream error code + */ + void vGetError(tenStreamError& enError) const; + /*! + * \brief set error code of stream + * \param[in] enError error to set for stream + */ + void vSetError(tenStreamError enError); + /*! + * \brief reset stream. Set position to start and error to nenStreamOK + */ + void vReset(); +private: + CNetworkOutStream(const CNetworkOutStream& rxOther); + CNetworkOutStream& operator= (const CNetworkOutStream& rxOther); + + /*! + * \brief checks that a sufficient number of bytes is left in the stream + * \param[in] u32Length number of bytes to check the stream for + */ + bool boCheck(const uint32_t u32Length); + + uint8_t* m_pu8CurrentPtr; + const uint8_t* const m_pru8StartPtr; + const uint8_t* const m_pru8EndPtr; + tenStreamError m_enError; +}; + +#endif /*CNETWORKSTREAM_H_*/ diff --git a/Master/Masterarbeit/src/common/inc/IPluginExecutor.h b/Master/Masterarbeit/src/common/inc/IPluginExecutor.h new file mode 100644 index 0000000..2a862ac --- /dev/null +++ b/Master/Masterarbeit/src/common/inc/IPluginExecutor.h @@ -0,0 +1,26 @@ +/*! + * \file IPluginExecutor.h + * \author S. Eisenhauer + * \date 10.01.2012 + * \brief public interface of target main appilcation to be used by target plugins + * + * This file defines the interface of the target main application + * to be used by target plugins + */ +#ifndef IPLUGIN_EXECUTOR_H +#define IPLUGIN_EXECUTOR_H + +#include "global.h" + +/// pure virtual interface of the target main application +class IPluginExecutor +{ +public: + /*! + * \brief transmit a log buffer to CanEasy + * \param[in] stLogMsg reference to logged message + */ + virtual void vUploadLogMessage(const tstLogMessage& stLogMsg) = 0; +}; + +#endif /*IPLUGIN_EXECUTOR_H*/ diff --git a/Master/Masterarbeit/src/common/inc/NetworkMessages.h b/Master/Masterarbeit/src/common/inc/NetworkMessages.h new file mode 100644 index 0000000..359bb85 --- /dev/null +++ b/Master/Masterarbeit/src/common/inc/NetworkMessages.h @@ -0,0 +1,282 @@ +/*! + * \file NetworkMessages.h + * \author S. Eisenhauer + * \date 15.01.2012 + * \brief Defintion of network messages and constant decoding objects + */ +#ifndef NETWORKMESSAGES_H_ +#define NETWORKMESSAGES_H_ + +#include +#include "protocol.h" + +/// definition for received message type +static CONST_NETWORK_ENUM(senRxMsgType + ,static_cast(nenReqStartPlugin) + ,static_cast(nenNumberOfNetworkMessageTypes-1)); +/// definition for received message length +static CONST_NETWORK_UINT32(su32RxMsgMessageLength,8,512); +static const tstTypeInfo* sapstRxMsgInfoArray[] = +{ + &senRxMsgType + ,&su32RxMsgMessageLength +}; +/// decoding object for network message header +static CONST_NETWORK_RECORD_PROP(sxRxMsgHeader,nenNumberOfNetworkMessageTypes,2,sapstRxMsgInfoArray); + +static CONST_NETWORK_ENUM(senReqStartPluginMsgType + ,static_cast(nenReqStartPlugin) + ,static_cast(nenReqStartPlugin)); +static CONST_NETWORK_UINT32(su32ReqStartPluginMessageLength,8,512); +static CONST_NETWORK_INT32(si32ReqStartPluginInterface,-1,7); +static CONST_NETWORK_STRING(ssReqStartPluginFilename,nNETWORK_DATALENGTH-4); +static const tstTypeInfo* sapstReqStartPluginInfoArray[] = +{ + &senReqStartPluginMsgType + ,&su32ReqStartPluginMessageLength + ,&si32ReqStartPluginInterface + ,&ssReqStartPluginFilename +}; +/// decoding object for start plugin request +static CONST_NETWORK_RECORD_PROP(sxReqStartPluginMessage,nenReqStartPlugin,4,sapstReqStartPluginInfoArray); + +static CONST_NETWORK_ENUM(senRespStartPluginMessageType + ,static_cast(nenRespStartPlugin) + ,static_cast(nenRespStartPlugin)); +static CONST_NETWORK_UINT32(su32RespStartPluginMessageLength,8,8); +static const tstTypeInfo* sapstRespStartPluginInfoArray[] = +{ + &senRespStartPluginMessageType + ,&su32RespStartPluginMessageLength +}; +/// decoding object for start plugin response +static CONST_NETWORK_RECORD_PROP(sxRespStartPluginMessage,nenRespStartPlugin,2,sapstRespStartPluginInfoArray); + +static CONST_NETWORK_ENUM(senReqShutdownMessageType + ,static_cast(nenReqShutdown) + ,static_cast(nenReqShutdown)); +static CONST_NETWORK_UINT32(su32ReqShutdownMessageLength,8,8); +static const tstTypeInfo* sapstReqShutdownInfoArray[] = +{ + &senReqShutdownMessageType + ,&su32ReqShutdownMessageLength +}; +/// decoding object for shutdown response +static CONST_NETWORK_RECORD_PROP(sxReqShutdownMessage,nenReqShutdown,2,sapstReqShutdownInfoArray); + +static CONST_NETWORK_ENUM(senRespShutdownMessageType + ,static_cast(nenRespShutdown) + ,static_cast(nenRespShutdown)); +static CONST_NETWORK_UINT32(su32RespShutdownMessageLength,8,8); +static const tstTypeInfo* sapstRespShutdownInfoArray[] = +{ + &senRespShutdownMessageType + ,&su32RespShutdownMessageLength +}; +/// decoding object for shutdown response +static CONST_NETWORK_RECORD_PROP(sxRespShutdownMessage,nenRespShutdown,2,sapstRespShutdownInfoArray); + +static CONST_NETWORK_ENUM(senReqStopPluginMessageType + ,static_cast(nenReqStopPlugin) + ,static_cast(nenReqStopPlugin)); +static CONST_NETWORK_UINT32(su32ReqStopPluginMessageLength,12,12); +static CONST_NETWORK_INT32(si32ReqStopPluginInterface,1,7); +static const tstTypeInfo* sapstReqStopPluginInfoArray[] = +{ + &senReqStopPluginMessageType + ,&su32ReqStopPluginMessageLength + ,&si32ReqStopPluginInterface +}; +/// decoding object for stop plugin request +static CONST_NETWORK_RECORD_PROP(sxReqStopPluginMessage,nenReqStopPlugin,3,sapstReqStopPluginInfoArray); + +static CONST_NETWORK_ENUM(senRespStopPluginMessageType + ,static_cast(nenRespStopPlugin) + ,static_cast(nenRespStopPlugin)); +static CONST_NETWORK_UINT32(su32RespStopPluginMessageLength,8,8); +static const tstTypeInfo* sapstRespStopPluginInfoArray[] = +{ + &senRespStopPluginMessageType + ,&su32RespStopPluginMessageLength +}; +/// decoding object for stop plugin response +static CONST_NETWORK_RECORD_PROP(sxRespStopPluginMessage,nenRespStopPlugin,2,sapstRespStopPluginInfoArray); + +static CONST_NETWORK_ENUM(senRespUploadLogMsgMessageType + ,static_cast(nenRespUploadLogMsg) + ,static_cast(nenRespUploadLogMsg)); +static CONST_NETWORK_UINT32(su32RespUploadLogMsgMessageLength,8,8); +static const tstTypeInfo* sapstRespUploadLogMsgInfoArray[] = +{ + &senRespUploadLogMsgMessageType + ,&su32RespUploadLogMsgMessageLength +}; +static CONST_NETWORK_RECORD_PROP(sxRespUploadLogMsgMessage,nenRespUploadLogMsg,2,sapstRespUploadLogMsgInfoArray); + +static CONST_NETWORK_ENUM(senRespChangeMsgDataMessageType + ,static_cast(nenRespChangeMsgData) + ,static_cast(nenRespChangeMsgData)); +static CONST_NETWORK_UINT32(su32RespChangeMsgDataMessageLength,8,8); +static const tstTypeInfo* sapstRespChangeMsgDataInfoArray[] = +{ + &senRespChangeMsgDataMessageType + ,&su32RespChangeMsgDataMessageLength +}; +static CONST_NETWORK_RECORD_PROP(sxRespChangeMsgDataMessage,nenRespChangeMsgData,2,sapstRespChangeMsgDataInfoArray); + +static CONST_NETWORK_ENUM(senRespUnknownReqMessageType + ,static_cast(nenRespUnknownReq) + ,static_cast(nenRespUnknownReq)); +static CONST_NETWORK_UINT32(su32RespUnknownReqMessageLength,8,8); +static const tstTypeInfo* sapstRespUnknownReqInfoArray[] = +{ + &senRespUnknownReqMessageType + ,&su32RespUnknownReqMessageLength +}; +static CONST_NETWORK_RECORD_PROP(sxRespUnknownReqMessage,nenRespUnknownReq,2,sapstRespUnknownReqInfoArray); + +static CONST_NETWORK_ENUM(senReqEnumerateInterfacesMessageType + ,static_cast(nenReqEnumerateInterfaces) + ,static_cast(nenReqEnumerateInterfaces)); +static CONST_NETWORK_UINT32(su32ReqEnumerateInterfacesMessageLength,8,8); +static CONST_NETWORK_STRING(ssReqEnumerateInterfacesNames,nNETWORK_DATALENGTH); +static const tstTypeInfo* sapstReqEnumerateInterfacesInfoArray[] = +{ + &senReqEnumerateInterfacesMessageType + ,&su32ReqEnumerateInterfacesMessageLength +}; +static CONST_NETWORK_RECORD_PROP(sxReqEnumerateInterfacesMessage,nenReqEnumerateInterfaces,2,sapstReqEnumerateInterfacesInfoArray); + +static CONST_NETWORK_ENUM(senRespEnumerateInterfacesMessageType + ,static_cast(nenRespEnumerateInterfaces) + ,static_cast(nenRespEnumerateInterfaces)); +static CONST_NETWORK_UINT32(su32RespEnumerateInterfacesMessageLength,512,512); +static CONST_NETWORK_STRING(ssRespEnumerateInterfacesNames,nNETWORK_DATALENGTH); +static const tstTypeInfo* sapstRespEnumerateInterfacesInfoArray[] = +{ + &senRespEnumerateInterfacesMessageType + ,&su32RespEnumerateInterfacesMessageLength + ,&ssRespEnumerateInterfacesNames +}; +static CONST_NETWORK_RECORD_PROP(sxRespEnumerateInterfacesMessage,nenRespEnumerateInterfaces,3,sapstRespEnumerateInterfacesInfoArray); + +static CONST_NETWORK_ENUM(senReqImportLogMessageType + ,static_cast(nenReqImportLog) + ,static_cast(nenReqImportLog)); +static CONST_NETWORK_UINT32(su32ReqImportLogMessageLength,512,512); +static CONST_NETWORK_STRING(ssReqImportLogFilename,nNETWORK_DATALENGTH); +static const tstTypeInfo* sapstReqImportLogInfoArray[] = +{ + &senReqImportLogMessageType + ,&su32ReqImportLogMessageLength + ,&ssReqImportLogFilename +}; +static CONST_NETWORK_RECORD_PROP(sxReqImportLogMessage,nenReqImportLog,3,sapstReqImportLogInfoArray); + +static CONST_NETWORK_ENUM(senRespImportLogMessageType + ,static_cast(nenRespImportLog) + ,static_cast(nenRespImportLog)); +static CONST_NETWORK_UINT32(su32RespImportLogMessageLength,512,512); +static CONST_NETWORK_STRING(ssRespImportLogFilename,nNETWORK_DATALENGTH); +static const tstTypeInfo* sapstRespImportLogInfoArray[] = +{ + &senRespImportLogMessageType + ,&su32RespImportLogMessageLength + ,&ssRespImportLogFilename +}; +static CONST_NETWORK_RECORD_PROP(sxRespImportLogMessage,nenRespImportLog,3,sapstRespImportLogInfoArray); + +static CONST_NETWORK_ENUM(senReqChangeMsgDataMessageType + ,static_cast(nenReqChangeMsgData) + ,static_cast(nenReqChangeMsgData)); +static CONST_NETWORK_UINT32(su32ReqChangeMsgDataMessageLength,24,24); +static CONST_NETWORK_INT32(si32ReqChangeMsgDataInterface,1,7); +static CONST_NETWORK_UINT32(su32ReqChangeMsgDataCanMsgId,0,0x7FFFF); +static CONST_NETWORK_UINT8(su8ReqChangeMsgDataData0,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqChangeMsgDataData1,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqChangeMsgDataData2,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqChangeMsgDataData3,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqChangeMsgDataData4,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqChangeMsgDataData5,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqChangeMsgDataData6,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqChangeMsgDataData7,0,0xFF); +static const tstTypeInfo* sapstReqChangeMsgDataInfoArray[] = +{ + &senReqChangeMsgDataMessageType + ,&su32ReqChangeMsgDataMessageLength + ,&si32ReqChangeMsgDataInterface + ,&su32ReqChangeMsgDataCanMsgId + ,&su8ReqChangeMsgDataData0 + ,&su8ReqChangeMsgDataData1 + ,&su8ReqChangeMsgDataData2 + ,&su8ReqChangeMsgDataData3 + ,&su8ReqChangeMsgDataData4 + ,&su8ReqChangeMsgDataData5 + ,&su8ReqChangeMsgDataData6 + ,&su8ReqChangeMsgDataData7 +}; +static CONST_NETWORK_RECORD_PROP(sxReqChangeMsgDataMessage + ,nenReqChangeMsgData,12,sapstReqChangeMsgDataInfoArray); + +static CONST_NETWORK_ENUM(senReqEnumerateLogsMessageType + ,static_cast(nenReqEnumerateLogs) + ,static_cast(nenReqEnumerateLogs)); +static CONST_NETWORK_UINT32(su32ReqEnumerateLogsMessageLength,8,8); +static const tstTypeInfo* sapstReqEnumerateLogsInfoArray[] = +{ + &senReqEnumerateLogsMessageType + ,&su32ReqEnumerateLogsMessageLength +}; +static CONST_NETWORK_RECORD_PROP(sxReqEnumerateLogsMessage,nenReqEnumerateLogs,2,sapstReqEnumerateLogsInfoArray); + +static CONST_NETWORK_ENUM(senRespEnumerateLogsMessageType + ,static_cast(nenRespEnumerateLogs) + ,static_cast(nenRespEnumerateLogs)); +static CONST_NETWORK_UINT32(su32RespEnumerateLogsMessageLength,512,512); +static CONST_NETWORK_STRING(ssRespEnumerateLogsFilenames,nNETWORK_DATALENGTH); +static const tstTypeInfo* sapstRespEnumerateLogsInfoArray[] = +{ + &senRespEnumerateLogsMessageType + ,&su32RespEnumerateLogsMessageLength + ,&ssRespEnumerateLogsFilenames +}; +static CONST_NETWORK_RECORD_PROP(sxRespEnumarateLogsMessage,nenRespEnumerateLogs,3,sapstRespEnumerateLogsInfoArray); + +static CONST_NETWORK_ENUM(senReqUploadLogMsgMessageType + ,static_cast(nenReqUploadLogMsg) + ,static_cast(nenReqUploadLogMsg)); +static CONST_NETWORK_UINT32(su32ReqUploadLogMsgMessageLength,0,512); +static CONST_NETWORK_UINT32(su32ReqUploadLogMsgTimestampHigh,0,0xFFFFFFFF); +static CONST_NETWORK_UINT32(su32ReqUploadLogMsgTimestampLow,0,0xFFFFFFFF); +static CONST_NETWORK_INT32(si32ReqUploadLogMsgInterface,1,7); +static CONST_NETWORK_UINT32(su32ReqUploadLogMsgCanMsgId,0,0x7FFFF); +static CONST_NETWORK_UINT8(su8ReqUploadLogMsgData0,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqUploadLogMsgData1,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqUploadLogMsgData2,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqUploadLogMsgData3,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqUploadLogMsgData4,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqUploadLogMsgData5,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqUploadLogMsgData6,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqUploadLogMsgData7,0,0xFF); +static CONST_NETWORK_UINT8(su8ReqUploadLogMsgDirection,0,1); +static const tstTypeInfo* sapstReqUploadLogMsgInfoArray[] = +{ + &senReqUploadLogMsgMessageType + ,&su32ReqUploadLogMsgMessageLength + ,&su32ReqUploadLogMsgTimestampHigh + ,&su32ReqUploadLogMsgTimestampLow + ,&si32ReqUploadLogMsgInterface + ,&su32ReqUploadLogMsgCanMsgId + ,&su8ReqUploadLogMsgData0 + ,&su8ReqUploadLogMsgData1 + ,&su8ReqUploadLogMsgData2 + ,&su8ReqUploadLogMsgData3 + ,&su8ReqUploadLogMsgData4 + ,&su8ReqUploadLogMsgData5 + ,&su8ReqUploadLogMsgData6 + ,&su8ReqUploadLogMsgData7 + ,&su8ReqUploadLogMsgDirection +}; +static CONST_NETWORK_RECORD_PROP(sxReqUploadLogMsgMessage,nenReqUploadLogMsg,15,sapstReqUploadLogMsgInfoArray); + +#endif /*NETWORKMESSAGES_H_*/ diff --git a/Master/Masterarbeit/src/common/inc/NetworkTypes.h b/Master/Masterarbeit/src/common/inc/NetworkTypes.h new file mode 100644 index 0000000..5da2f64 --- /dev/null +++ b/Master/Masterarbeit/src/common/inc/NetworkTypes.h @@ -0,0 +1,467 @@ +/*! + * \file NetworkTypes.h + * \author S. Eisenhauer + * \date 15.01.2012 + * \brief Defintion of elementary data types used in network messages and classes for reading and writing them + */ +#ifndef NETWORK_TYPES_H_ +#define NETWORK_TYPES_H_ + +#include "global.h" +#include "CNetworkStream.h" +#include "protocol.h" + +/*! + * \brief Container class for data from and to network. Allows structured access to network message data. + */ +class CNetworkDatacontainer +{ +public: + /// constructor + CNetworkDatacontainer(); + /*! + * \brief get the pointer to the memory of the data for specified message type + * \param[in] enMsgIdx Enumerator of the message type + */ + void* pvGetVarPtr(tenNetworkMessageType enMsgIdx); + /*! + * \brief get the pointer to the memory of a data element for specified message type + * \param[in] enMsgIdx Enumerator of the message type + * \param[in] u8ElemIdx Index of the element in message data structure + */ + void* pvGetVarPtr(tenNetworkMessageType enMsgIdx, uint8_t u8ElemIdx); + /// type definition for structure of Start Plugin request + struct tstReqStartPlugin { + tstNetworkMessageHeader stHeader; //!< header + int32_t i32Interface; //!< number of the interface + char acFilename[nNETWORK_DATALENGTH-4]; //!< shared object path + }; + /// type definition for structure of Stop Plugin request + struct tstReqStopPlugin { + tstNetworkMessageHeader stHeader;//!< header + int32_t i32Interface; //!< number of the interface + }; + /// type definition for structure of Enumerate Interfaces request + struct tstReqEnumerateInterfaces { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of Enumerate Logfiles request + struct tstReqEnumerateLogs { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of Import Logfile request + struct tstReqImportLog { + tstNetworkMessageHeader stHeader;//!< header + char acFilename[nNETWORK_DATALENGTH]; //!< log file path + }; + /// type definition for structure of Change Message Data request + struct tstReqChangeMsgData { + tstNetworkMessageHeader stHeader;//!< header + int32_t i32Interface; //!< number of the interface + uint32_t u32CanMsgId; //!< CAN ID of the message + uint8_t au8Data[8]; //!< data bytes of the CAN message + }; + /// type definition for structure of Upload Logged Message request + struct tstReqUploadLogMsg { + tstNetworkMessageHeader stHeader;//!< header + tstLogMessage stLogMessage; //!< the logged message + }; + /// type definition for structure of Start Plugin response + struct tstRespStartPlugin { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of Stop Plugin response + struct tstRespStopPlugin { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of Shutdown response + struct tstRespShutdown { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of Shutdown request + struct tstReqShutdown { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of Import Logfile response + struct tstRespImportLog { + tstNetworkMessageHeader stHeader;//!< header + char acFilename[nNETWORK_DATALENGTH]; //!< logfile path + }; + /// type definition for structure of Enumerate Logfiles response + struct tstRespEnumerateLogs { + tstNetworkMessageHeader stHeader;//!< header + char acFilenames[nNETWORK_DATALENGTH]; //!< paths of the available logfiles + }; + /// type definition for structure of Enumerate Interfaces response + struct tstRespEnumerateInterfaces { + tstNetworkMessageHeader stHeader;//!< header + char acInterfaces[nNETWORK_DATALENGTH]; //!< interfaces + }; + /// type definition for structure of Upload Logged Message response + struct tstRespUploadLogMsg { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of Change Message Data response + struct tstRespChangeMsgData { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of Unknown Request response + struct tstRespUnknownReq { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of Invalid Argument response + struct tstRespInvalidArg { + tstNetworkMessageHeader stHeader;//!< header + }; + /// type definition for structure of header of received message + struct tstRxNetworkMessageMsg { + tstNetworkMessageHeader stHeader;//!< header + }; +private: + tstReqStartPlugin m_stReqStartPlugin; + tstReqStopPlugin m_stReqStopPlugin; + tstReqEnumerateInterfaces m_stReqEnumerateInterfaces; + tstReqEnumerateLogs m_stReqEnumerateLogs; + tstReqChangeMsgData m_stReqChangeMsgData; + tstReqUploadLogMsg m_stReqUploadLogMsg; + tstReqImportLog m_stReqImportLog; + tstReqShutdown m_stReqShutdown; + tstRespStartPlugin m_stRespStartPlugin; + tstRespStopPlugin m_stRespStopPlugin; + tstRespShutdown m_stRespShutdown; + tstRespImportLog m_stRespImportLog; + tstRespEnumerateLogs m_stRespEnumerateLogs; + tstRespEnumerateInterfaces m_stRespEnumerateInterfaces; + tstRespChangeMsgData m_stRespChangeMsgData; + tstRespUploadLogMsg m_stRespUploadLogMsg; + tstRespUnknownReq m_stRespUnknownReq; + tstRespInvalidArg m_stRespInvalidArg; + tstRxNetworkMessageMsg m_stRxMsg; +}; + +/// enumeration of elementary datatypes in netowrk messages +enum tenNetworkElementarTypes +{ + nenNetworkEnum //!< enum datatype + ,nenNetworkInt8 //!< 8 bit signed integer datatype + ,nenNetworkUint8 //!< 8 bit unsigned integer datatype + ,nenNetworkInt32 //!< 32 bit signed integer datatype + ,nenNetworkUint32 //!< 32 bit unsigned integer datatype + ,nenNetworkString //!< string datatype +}; + +/// structure describing a datum +struct tstTypeInfo +{ + tenNetworkElementarTypes m_enType; //!< type of the datum +}; + +/// structure describing a network record property +struct tstNetworkModelInfo +{ + tenNetworkMessageType m_enMsgType; //!< type of the message + uint8_t m_u8NumOfFields; //!< number of datum fields in the message + const tstTypeInfo* const* m_apstFieldInfoPtrArray; //!< array of pointers of datum descriptions +}; + +/// class for handling a network record property +class CNetworkRecordProp : public tstNetworkModelInfo +{ +public: + /*! + * \brief read a network message from a stream and store it in a destination + * \param[in] xDatacontainer reference to datacontainer for message + * \param[in] xStream stream containing the message + */ + void vRead(CNetworkDatacontainer& xDatacontainer, CNetworkInStream& xStream) const; + /*! + * \brief write a network message to a stream + * \param[in] xDatacontainer reference to datacontainer with message + * \param[in] xStream stream to which the message is written + */ + void vWrite(CNetworkDatacontainer& xDatacontainer, CNetworkOutStream& xStream) const; +// uint8_t m_u8NumOfFields; //!< number of datum fields in the message +// const tstTypeInfo* const* m_apstFieldInfoPtrArray; //!< array of pointers of datum descriptions +}; + +/// class for handling a enumeration datum +class CNetworkEnum : public tstTypeInfo +{ +public: + /*! + * \brief read elementary enum type from stream and verify it implicitly + * \param[in] pvDest pointer to memory where the value will be stored + * \param[in] xStream input stream from which to read the value + */ + void vRead(void* pvDest, CNetworkInStream& xStream) const; + /*! + * \brief write elementary enum type to stream and verify it implicitly + * \param[in] pvSrc pointer to memory where the value is stored + * \param[in] xStream output stream to which to write the value + */ + void vWrite(void* pvSrc, CNetworkOutStream& xStream) const; + /*! + * \brief validate datum + * \param[in] i32Value datum to validate + * \return TRUE if datum is valid, FALSE otherwise + */ + bool boIsValid(const int32_t i32Value) const; + int32_t m_i32Min; //!< valid minimum of the datum + int32_t m_i32Max; //!< valid maximum of the datum +}; + +/// class for handling a 8 bit signed integer datum +class CNetworkUint8 : public tstTypeInfo +{ +public: + /*! + * \brief read elementary 8-bit unsigned integer type from stream and verify it implicitly + * \param[in] pvDest pointer to memory where the value will be stored + * \param[in] xStream input stream from which to read the value + */ + void vRead(void* pvDest, CNetworkInStream& xStream) const; + /*! + * \brief write elementary 8-bit unsigned integer type to stream and verify it implicitly + * \param[in] pvSrc pointer to memory where the value is stored + * \param[in] xStream output stream to which to write the value + */ + void vWrite(void* pvSrc, CNetworkOutStream& xStream) const; + /*! + * \brief validate datum + * \param[in] u8Value datum to validate + * \return TRUE if datum is valid, FALSE otherwise + */ + bool boIsValid(const uint8_t u8Value) const; + uint8_t m_u8Min; //!< valid minimum of the datum + uint8_t m_u8Max; //!< valid maximum of the datum +}; + +/// class for handling a 8 bit unsigned integer datum +class CNetworkInt8 : public tstTypeInfo +{ +public: + /*! + * \brief read elementary 8-bit signed integer type from stream and verify it implicitly + * \param[in] pvDest pointer to memory where the value will be stored + * \param[in] xStream input stream from which to read the value + */ + void vRead(void* pvDest, CNetworkInStream& xStream) const; + /*! + * \brief write elementary 8-bit signed integer type to stream and verify it implicitly + * \param[in] pvSrc pointer to memory where the value is stored + * \param[in] xStream output stream to which to write the value + */ + void vWrite(void* pvSrc, CNetworkOutStream& xStream) const; + /*! + * \brief validate datum + * \param[in] i8Value datum to validate + * \return TRUE if datum is valid, FALSE otherwise + */ + bool boIsValid(const int8_t i8Value) const; + int8_t m_i8Min; //!< valid minimum of the datum + int8_t m_i8Max; //!< valid maximum of the datum +}; + +/// class for handling a 32 bit signed integer datum +class CNetworkUint32 : public tstTypeInfo +{ +public: + /*! + * \brief read elementary 32-bit unsigned integer type from stream and verify it implicitly + * \param[in] pvDest pointer to memory where the value will be stored + * \param[in] xStream input stream from which to read the value + */ + void vRead(void* pvDest, CNetworkInStream& xStream) const; + /*! + * \brief write elementary 32-bit unsigned integer type to stream and verify it implicitly + * \param[in] pvSrc pointer to memory where the value is stored + * \param[in] xStream output stream to which to write the value + */ + void vWrite(void* pvSrc, CNetworkOutStream& xStream) const; + /*! + * \brief validate datum + * \param[in] u32Value datum to validate + * \return TRUE if datum is valid, FALSE otherwise + */ + bool boIsValid(const uint32_t u32Value) const; + uint32_t m_u32Min; //!< valid minimum of the datum + uint32_t m_u32Max; //!< valid maximum of the datum +}; + +/// class for handling a 32 bit unsigned integer datum +class CNetworkInt32 : public tstTypeInfo +{ +public: + /*! + * \brief read elementary 32-bit signed integer type from stream and verify it implicitly + * \param[in] pvDest pointer to memory where the value will be stored + * \param[in] xStream input stream from which to read the value + */ + void vRead(void* pvDest, CNetworkInStream& xStream) const; + /*! + * \brief write elementary 32-bit signed integer type to stream and verify it implicitly + * \param[in] pvSrc pointer to memory where the value is stored + * \param[in] xStream output stream to which to write the value + */ + void vWrite(void* pvSrc, CNetworkOutStream& xStream) const; + /*! + * \brief validate datum + * \param[in] i32Value datum to validate + * \return TRUE if datum is valid, FALSE otherwise + */ + bool boIsValid(const int32_t i32Value) const; + int32_t m_i32Min; //!< valid minimum of the datum + int32_t m_i32Max; //!< valid maximum of the datum +}; + +/// class for handling a string datum +class CNetworkString : public tstTypeInfo +{ +public: + /*! + * \brief read elementary string type from stream + * \param[in] pvDest pointer to memory where the value will be stored + * \param[in] xStream input stream from which to read the value + */ + void vRead(void* pvDest, CNetworkInStream& xStream) const; + /*! + * \brief write elementary string type to stream and verify it implicitly + * \param[in] pvSrc pointer to memory where the value is stored + * \param[in] xStream output stream to which to write the value + */ + void vWrite(void* pvSrc, CNetworkOutStream& xStream) const; + uint32_t m_u32Length; //!< maximum length of the string +}; + +//struct tstNetworkRecordProp +//{ +// uint8_t m_u8NumOfFields; +// const tstTypeInfo* const* m_apstFieldInfoPtrArray; +//}; +/*! + * \brief macro for generating a network record property object, which represents a network message + * \param[in] name name of the object + * \param[in] msgType message type enumerator + * \param[in] numOfFields number of elements of the record + * \param[in] infoPtrArray pointer to array of pointers with datatype informations definitions + */ +#define CONST_NETWORK_RECORD_PROP(name,msgType,numOfFields,infoPtrArray)\ +const tstNetworkModelInfo name##_={msgType,numOfFields,infoPtrArray}; \ +const CNetworkRecordProp& name = reinterpret_cast(name##_); + +/// structure defining a network enum type +struct tstNetworkEnumType +{ + tenNetworkElementarTypes m_enType; //!< elementary datatype + int32_t m_i32Min; //!< valid minimum of the datum + int32_t m_i32Max; //!< valid maximum of the datum +}; +/*! + * \brief macro for generating a object coding a enumeration + * \param[in] name object name + * \param[in] min minimum valid value + * \param[in] max maximum valid value + */ +#define CONST_NETWORK_ENUM(name,min,max) \ +const tstNetworkEnumType name##_ = {nenNetworkEnum,min,max}; \ +const CNetworkEnum& name = reinterpret_cast(name##_); + +/// structure defining a network unsigned 8-bit integer type +struct tstNetworkUint8Type +{ + tenNetworkElementarTypes m_enType; //!< elementary datatype + uint8_t m_u8Min; //!< valid minimum of the datum + uint8_t m_u8Max; //!< valid maximum of the datum +}; +/*! + * \brief macro for generating a object coding a 8-bit unsigned integer + * \param[in] name object name + * \param[in] min minimum valid value + * \param[in] max maximum valid value + */ +#define CONST_NETWORK_UINT8(name,min,max) \ +const tstNetworkUint8Type name##_ = {nenNetworkUint8,min,max}; \ +const CNetworkUint8& name = reinterpret_cast(name##_); + +/// structure defining a network signed 8-bit integer type +struct tstNetworkInt8Type +{ + tenNetworkElementarTypes m_enType; //!< elementary datatype + int8_t m_i8Min; //!< valid minimum of the datum + int8_t m_i8Max; //!< valid maximum of the datum +}; +/*! + * \brief macro for generating a object coding a 8-bit signed integer + * \param[in] name object name + * \param[in] min minimum valid value + * \param[in] max maximum valid value + */ +#define CONST_NETWORK_INT8(name,min,max) \ +const tstNetworkInt8Type name##_ = {nenNetworkInt8,min,max}; \ +const CNetworkInt8& name = reinterpret_cast(name##_); + +/// structure defining a network unsigned 32-bit integer type +struct tstNetworkUint32Type +{ + tenNetworkElementarTypes m_enType; //!< elementary datatype + uint32_t m_u32Min; //!< valid minimum of the datum + uint32_t m_u32Max; //!< valid maximum of the datum +}; +/*! + * \brief macro for generating a object coding a 32-bit unsigned integer + * \param[in] name object name + * \param[in] min minimum valid value + * \param[in] max maximum valid value + */ +#define CONST_NETWORK_UINT32(name,min,max) \ +const tstNetworkUint32Type name##_ = {nenNetworkUint32,min,max}; \ +const CNetworkUint32& name = reinterpret_cast(name##_); + +/// structure defining a network signed 32-bit integer type +struct tstNetworkInt32Type +{ + tenNetworkElementarTypes m_enType; //!< elementary datatype + int32_t m_i32Min; //!< valid minimum of the datum + int32_t m_i32Max; //!< valid maximum of the datum +}; +/*! + * \brief macro for generating a object coding a 32-bit signed integer + * \param[in] name object name + * \param[in] min minimum valid value + * \param[in] max maximum valid value + */ +#define CONST_NETWORK_INT32(name,min,max) \ +const tstNetworkInt32Type name##_ = {nenNetworkInt32,min,max}; \ +const CNetworkInt32& name = reinterpret_cast(name##_); + +/// structure defining a network string type +struct tstNetworkStringType +{ + tenNetworkElementarTypes m_enType; //!< elementary datatype + uint32_t u32Length; //!< valid maximum length of the string +}; +/*! + * \brief macro for generating a string coding object + * \param[in] name object name + * \param[in] length length of the string + */ +#define CONST_NETWORK_STRING(name,length) \ +const tstNetworkStringType name##_ = {nenNetworkString,length}; \ +const CNetworkString& name = reinterpret_cast(name##_); + +/*! + * \brief function for compile time polymorphism to call right read method depending on datatype + * \param[in] pstObjPtr pointer to datatype definition + * \param[in] pvDst pointer to memory where the read value should be stored + * \param[in] xStream stream to read value from + */ +void vInvokeRead(const tstTypeInfo* pstObjPtr, void* pvDst, CNetworkInStream& xStream); +/*! + * \brief function for compile time polymorphism to call right write method depending on datatype + * \param[in] pstObjPtr pointer to datatype definition + * \param[in] pvSrc pointer to memory where the value is stored that should be written + * \param[in] xStream stream to write value to + */ +void vInvokeWrite(const tstTypeInfo* pstObjPtr, void* pvSrc, CNetworkOutStream& xStream); + +#endif /*NETWORK_TYPES_H_*/ diff --git a/Master/Masterarbeit/src/common/inc/global.h b/Master/Masterarbeit/src/common/inc/global.h new file mode 100644 index 0000000..df3d812 --- /dev/null +++ b/Master/Masterarbeit/src/common/inc/global.h @@ -0,0 +1,162 @@ +/*! + * \file global.h + * \author S. Eisenhauer + * \date 31.08.2011 + * \brief Global include file + * + * This file is used in all other components + * It defines + * \li common datatypes + * \li a macro for printing error messages to STDERR + * \li a macro for printing debug messages to STDOUT when compiled with -DDEBUG_MODE + * + */ + +#ifndef GLOBAL_H_ +#define GLOBAL_H_ + +#include + +#ifdef _MSC_VER + +#define nLITTLE_ENDIAN_HOST + +#include +using boost::uint32_t; +using boost::int32_t; +using boost::uint8_t; +using boost::int8_t; + +#ifdef DEBUG_MODE + +#define DEBUG_PRINT(format, ...) \ + { \ + static char message[512]; \ + sprintf_s(message,512,format, __VA_ARGS__); \ + fprintf(stdout, "[%s] line %d : %s\n", __FUNCTION__,__LINE__, message); \ + fflush(stdout); \ + } + +#else /* !DEBUG_MODE */ + +#define DEBUG_PRINT(format, ...) + +#endif /* !DEBUG_MODE */ + +#define ERROR_PRINT(format, ...) \ + { \ + static char message[512]; \ + sprintf_s(message,512,format, __VA_ARGS__); \ + fprintf(stderr, "[%s] line %d : %s\n", __FUNCTION__,__LINE__, message); \ + fflush(stderr); \ + } + +#else /* x2e embedded SDK*/ + +#include +#ifdef DEBUG_MODE + +#define DEBUG_PRINT(format, args...) \ + { \ + static char message[512]; \ + snprintf(message,512,format, ##args); \ + fprintf(stdout, "[%s] line %d : %s\n", __PRETTY_FUNCTION__,__LINE__, message); \ + fflush(stdout); \ + } + +#else /* !DEBUG_MODE */ + +#define DEBUG_PRINT(format, args...) + +#endif /* !DEBUG_MODE */ + +#define ERROR_PRINT(format, args...) \ + { \ + static char message[512]; \ + snprintf(message,512,format, ##args); \ + fprintf(stderr, "[%s] line %d : %s\n", __PRETTY_FUNCTION__,__LINE__, message); \ + fflush(stderr); \ + } +#endif /* _MSC_VER */ + +#ifdef nLITTLE_ENDIAN_HOST /* little endian macros, convert to big endian byte order */ +#define BYTE_SWAP16(type,value) \ + ( (type) ((0xff00 & val) >> 8) | ((0xff & val) << 8) ) + +#define BYTE_SWAP32(type,value) \ + ( (type) ((0xff000000 & value) >> 24) | \ + ((0x00ff0000 & value) >> 8) | \ + ((0x0000ff00 & value) << 8) | \ + ((0x000000ff & value) << 24) ) + +#define MAKE_INT32(a,b,c,d) int32_t( ( ( (uint32_t) d ) << 24 ) | ( ( (uint32_t) c ) << 16 ) | ( ( (uint32_t) b ) << 8 ) | uint8_t(a) ) +#define MAKE_UINT32(a,b,c,d) uint32_t( ( ( (uint32_t) d ) << 24 ) | ( ( (uint32_t) c ) << 16 ) | ( ( (uint32_t) b ) << 8 ) | uint8_t(a) ) +#define HIGH_BYTE(w) uint8_t( w >> 8 ) +#define LOW_BYTE(w) uint8_t( w & 0xff ) +#define HIGH_WORD(dw) uint16_t( dw >> 16 ) +#define LOW_WORD(dw) uint16_t( dw & 0xffff ) + +#else /* big endian macros, keep byte order*/ +#define BYTE_SWAP16(type,value) \ + ( (type) value ) + +#define BYTE_SWAP32(type,value) \ + ( (type) value ) + +#define MAKE_INT32(a,b,c,d) int32_t( ( ( (uint32_t) a ) << 24 ) | ( ( (uint32_t) b ) << 16 ) | ( ( (uint32_t) c ) << 8 ) | uint8_t(d) ) +#define MAKE_UINT32(a,b,c,d) uint32_t( ( ( (uint32_t) a ) << 24 ) | ( ( (uint32_t) b ) << 16 ) | ( ( (uint32_t) c ) << 8 ) | uint8_t(d) ) +#define HIGH_BYTE(w) uint8_t( w & 0xff ) +#define LOW_BYTE(w) uint8_t( w >> 8 ) +#define HIGH_WORD(dw) uint16_t( dw & 0xffff ) +#define LOW_WORD(dw) uint16_t( dw >> 16 ) + +#endif /* nLITTLE_ENDIAN_HOST endianess macros */ + +#define nTIMER_INTERVAL_US (1000) //timer interval in mircoseconds +#define nMAX_SAFE_STACK (4*1024) + +/*! + * \brief Enumeration of used priotities + */ +enum tenPrio +{ + nenRT=80, //!< real-time priority, above interrupts + nenNORMAL=20, //!< normal priority + nenLOW=10 //!< low priority +}; + +/*! + * \brief Enumeration for error codes + */ +enum tenRetCodes +{ + nenOK, //!< no error + nenERR_SOFILE, //!< shared object file could not be opened + nenERR_SYMBOL, //!< symbol could not be found in shared object + nenERR_MAKE, //!< Executing the generated Makefile resulted in error state + nenERR_FTP, //!< An error occured in FTP operation + nenERR_NOTIMPLEMENTED, //!< invoking an unimplemented method + nenERR_MOVELOG, //!< error in log rotation + nenERR_MAX_PLUGINS_REACHED //!< Maximum number of active plugins reached +}; +/*! + * \brief Enumeration for message direction + */ +enum tenMsgDirection +{ + nenRx = 0, //!< received message + nenTx = 1 //!< sent message +}; +/*! +* \brief Definition of a received message +*/ +struct tstLogMessage +{ + uint32_t u32TsHigh; //!< Upper 32 Bit of the 64 Bit 100 ns Timestamp + uint32_t u32TsLow; //!< Lower 32 Bit of the 64 Bit 100 ns Timestamp + int32_t i32Interface; //!< Interface-Handle on which the message was received + uint32_t u32MsgId; //!< ID of the received message + uint8_t au8Data[8]; //!< Data of the received message + uint8_t u8Dir; //!< direction of message +}; +#endif /* GLOBAL_H_ */ diff --git a/Master/Masterarbeit/src/common/inc/interface_manager.h b/Master/Masterarbeit/src/common/inc/interface_manager.h new file mode 100644 index 0000000..be910d4 --- /dev/null +++ b/Master/Masterarbeit/src/common/inc/interface_manager.h @@ -0,0 +1,99 @@ +/*! + * \file interface_manager.h + * + * \author S. Eisenhauer + * + * \date 31.08.2011 + * + * \brief Interface for accessing XORAYA hardware + * + * This file defines the interface for accessing XORAYA Connect hardware interfaces + * + */ + +#ifndef INTERFACE_MANAGER_H_ +#define INTERFACE_MANAGER_H_ + +#include "global.h" +#include "x2e/ReceiveQueue.hpp" + +/*! +* \brief Pure virtual interface used by other components and plugins to access XORAYA hardware +*/ +class IInterfaceManager +{ +public: + /*! + * Sends a mesage on a hardware interface + * \param[in] i32InterfaceHandle Interface handle + * \param[in] u32MsgId ID of the message + * \param[in] boIsExtended TRUE indicates an extended ID (29 bit long), FALSE a standard ID (11 bit long) + * \param[in] boIsRtrFrame is this an RTR frame + * \param[in] pu8Data pointer to the buffer for the message payload + * \param[in] u32DataLength Length of message payload in byte (DLC) + * \return status code + */ + virtual x2e::status_t enWriteCanMessage( + int32_t i32InterfaceHandle, + uint32_t u32MsgId, + bool boIsExtended, + bool boIsRtrFrame, + const uint8_t* pu8Data, + uint32_t u32DataLength) = 0; + + /*! + * Retrieve the fill level of the receive queue + * \param[out] stFillLevel Reference to a queueFillLevel object + * \return status code + */ + virtual x2e::status_t enGetQueueFillLevel(x2e::Log::queueFillLevel& stFillLevel) = 0; + + /*! + * Get a message from the receive queue + * \param[out] stFillLevel Reference to a queueFillLevel object + * \param[out] pstMsgDescr Pointer to a message description object + * \param[out] pstMsgPayload Pointer to framePayload object as buffer for the message content + * \return status code + */ + virtual x2e::status_t enPeekMessage( + x2e::Log::queueFillLevel& stFillLevel, + x2e::Log::messageDescription* pstMsgDescr, + x2e::Log::framePayload* pstMsgPayload) = 0; + + /*! + * Enable an Hardware interface + * \param[in] i32RequestedIntereface Interface handle + * \return status code + */ + virtual x2e::status_t enEnableInterface( int32_t i32RequestedIntereface ) = 0; + + /*! + * Enable all Hardware interface + * \return status code + */ + virtual x2e::status_t enEnableAllInterfaces( void ) = 0; + + /*! + * Gets the current 100 nanosecond timestamp of the system + * \param[out] pu32TsHigh Upper 32 bit of the timestamp + * \param[out] pu32TsLow Lower 32 bit of the timestamp + * \return status code + */ + virtual x2e::status_t enGetTimestamp( uint32_t* pu32TsHigh, uint32_t* pu32TsLow ) = 0; + + /*! + * wait on the internal hardware timer + * \return status code + */ + virtual x2e::status_t enWait() = 0; + + /*! + * get interface handle by a log interface id + * \param[in] u16LogIfId log interface id + * \return interface handle + */ + virtual int32_t i32GetInterfaceByLogIfId(x2e::Log::InterfaceId::ifid_t u16LogIfId) = 0; +}; + + +#endif /* INTERFACE_MANAGER_H_ */ diff --git a/Master/Masterarbeit/src/common/inc/plugin_api.h b/Master/Masterarbeit/src/common/inc/plugin_api.h new file mode 100644 index 0000000..a0c9e48 --- /dev/null +++ b/Master/Masterarbeit/src/common/inc/plugin_api.h @@ -0,0 +1,138 @@ +/*! + * \file plugin_api.h + * + * \author S. Eisenhauer + * + * \date 31.08.2011 + * + * \brief Interface of a plugin used by \ref CPluginExecutor + * + * This file defines the interface which must be provided by a plugin to \ref CPluginExecutor + * + */ + +#ifndef PLUGIN_API_H_ +#define PLUGIN_API_H_ + +#include "global.h" + +/*! +* \brief Definition of a message to be sent on the CAN bus +*/ +struct tstCanTxMessage +{ + uint32_t u32TxCycleMilliseconds; //!< Interval for sending cyclic message in milliseconds + uint32_t u32MillisecondCounter; //!< Incremented every millisecond, resetted to zero when message is sent + uint32_t u32CanId; //!< CAN ID of the message + uint8_t au8Data[8]; //!< data content of the message + uint8_t u8Dlc; //!< Data Length Code of the message: bytes of au8Data used by the message +}; +/*! +* \brief Type for pointer to a tstCanTxMessage +*/ +typedef tstCanTxMessage* tpstCanTxMessage; + +/*! + * \brief Pure virtual interface of a plugin. + * + * Must be implemented by concrete plugin + */ +class IPlugin +{ +public: + /*! + * executed every millisecond + * \warning Keep this method implementation short. It is executed with Real-Time priority. + */ + virtual void vRun( void ) = 0; + /*! + * Get a message to be send on CAN bus from plugin + * \param[in] u32MsgIndex Index of the message. Call u32GetNumOfCanTxMessages before to get the number of available messages + * \return Pointer to the message + */ + virtual tpstCanTxMessage pxGetCanTxMessage( const uint32_t u32MsgIndex ) = 0; + /*! + * Get the number of CAN TX messages defined in the plugin + * \return the number of messages + */ + virtual uint32_t u32GetNumOfCanTxMessages( void ) = 0; + /*! + * Get the number of the used CAN interface + * \return the number of the used CAN interface + */ + virtual int32_t i32GetCanInterfaceHandle( void ) = 0; + /*! + * Should this plugin be automatically loaded when CPluginExecutor starts up + * \return TRUE is the plugin should be autoloaded, FALSE otherwise + */ + virtual bool boAutoload( void ) = 0; + /*! + * Is this plugin the instance of the Log Plugin + * \return TRUE if it is the log plugin, FALSE otherwise + */ + virtual bool boIsLogger( void ) = 0; + /*! + * get a log file + * \param[in] pcRequest pointer to a memory buffer containing the filename of the request + * \param[out] pcResponse pointer to a memory buffer where the filename will be stored + * \return status + */ + virtual tenRetCodes enGetLog(const char* pcRequest, char* pcResponse) = 0; + /*! + * initialize the plugin + * + * \param[in] pvExecutor Pointer to target main application + * \param[in] pvIfMan Pointer to an interface manager object + * \param[in] i32Interface Number of the interface ti be used by the plugin + * \param[in] u32PluginId ID of the Plugin + */ + virtual void vInit(void* pvExecutor, void* pvIfMan, int32_t i32Interface, uint32_t u32PluginId) = 0; + /*! + * Add a message to the log + * + * \param[in] stLogMessage the message to log + */ + virtual void vLogMessage(const tstLogMessage& stLogMessage) = 0; +}; +extern "C" +{ + /*! + * \brief type for factory function + * \param[in] pvExecutor Pointer to target main application + * \param[in] pvIfMan Pointer to an interface manager object + * \param[in] i32Interface Number of the interface to be used by the plugin + * \param[in] u32PluginId ID of the Plugin + * \return Pointer to the Plugin object + */ + typedef IPlugin* tfctCreatePlugin( + void* pvExecutor, + void* pvIfMan, + int32_t i32Interface, + uint32_t u32PluginId + ); + /*! + * \brief type for factory function pointer + */ + typedef tfctCreatePlugin *tpfctCreatePlugin; + /*! + * \brief type for deinitialization function + * + * \param[in] pxPlugin Pointer to the plugin to be deinitialized + */ + typedef void tfctDestroyPlugin(IPlugin* pxPlugin); + /*! + * \brief type for deinitialization function pointer + * + * \param[in] pxPlugin Pointer to the plugin to be deinitialized + */ + typedef tfctDestroyPlugin *tpfctDestroyPlugin; + /*! + * C interface for the factory + */ + tfctCreatePlugin pxCreatePlugin; + /*! + * C interface for the deinitialization + */ + tfctDestroyPlugin vDestroyPlugin; +} +#endif /* PLUGIN_API_H_ */ diff --git a/Master/Masterarbeit/src/common/inc/plugin_api_heap.h b/Master/Masterarbeit/src/common/inc/plugin_api_heap.h new file mode 100644 index 0000000..5772a96 --- /dev/null +++ b/Master/Masterarbeit/src/common/inc/plugin_api_heap.h @@ -0,0 +1,53 @@ +/*! + * \file plugin_api_heap.h + * \author S. Eisenhauer + * \date 31.08.2011 + * \brief STL-based interface of a plugin used by \ref CPluginExecutor + * + * This file defines a interface for plugins to \ref CPluginExecutor. + * This interface is based on the STL which uses heap for internal allocations + * + */ + +#ifndef PLUGIN_API_H_ +#define PLUGIN_API_H_ + +#include "global.h" +#include "interface_manager.h" +#include +#include +#include + +struct tstCanTxMessage +{ + uint32_t u32TxCycleMilliseconds; + uint32_t u32MillisecondCounter; + uint32_t u32CanId; + uint8_t au8Data[8]; + uint8_t u8Dlc; +}; +typedef boost::shared_ptr< tstCanTxMessage > tpstCanTxMessage; +typedef std::vector< tpstCanTxMessage > tCanTxMessageList; + +class IPlugin +{ +public: + virtual void vRun( void ) = 0; + virtual tCanTxMessageList& xGetCanTxMessages( void ) = 0; + virtual int32_t i32GetCanInterfaceHandle( void ) = 0; +}; + +typedef IPlugin* tpxCreatePlugin( + IInterfaceManager& xIfMan, + int32_t i32Interface, + uint32_t u32PluginId + ); +typedef void tvDestroyPlugin(IPlugin*); + +extern "C" +{ + tpxCreatePlugin pxCreatePlugin; + tvDestroyPlugin vDestroyPlugin; +} + +#endif /* PLUGIN_API_H_ */ diff --git a/Master/Masterarbeit/src/common/inc/protocol.h b/Master/Masterarbeit/src/common/inc/protocol.h new file mode 100644 index 0000000..e3e21ef --- /dev/null +++ b/Master/Masterarbeit/src/common/inc/protocol.h @@ -0,0 +1,70 @@ +/*! + * \file protocol.h + * \author S. Eisenhauer + * \date 31.08.2011 + * \brief Network protocol definition + * + * This file defines the network protocol used between XORAYA Connect and CanEasy + * + */ +#ifndef PROTOCOL_H_SEI +#define PROTOCOL_H_SEI + +#include +#include "global.h" + +/// default IP of the XORAYA connect +#define nDEFAULT_IP _T("192.168.1.214") + +/// network port for communication +#define nPORT (7010) + +/// size of network buffers in bytes +#define nNETWORK_BUFFSIZE (512) + +/*! + * \brief type definition for network data buffer + */ +typedef boost::array tNetworkBuffer; + +/*! + * \brief Enumeration of Network message types + */ +enum tenNetworkMessageType +{ + nenReqStartPlugin //!< Request for starting a target plugin + ,nenReqStopPlugin //!< Request for stopping a target plugin + ,nenReqShutdown //!< Request for shutting down all target components + ,nenReqImportLog //!< Request for importing a log file + ,nenReqEnumerateLogs //!< Request for enumerating available log files + ,nenReqEnumerateInterfaces //!< Request for enumerating hardware interfaces + ,nenReqChangeMsgData //!< Request for changing the data of a CAN TX message + ,nenReqUploadLogMsg //!< Request with log data + ,nenRespStartPlugin //!< Response for a start plugin request + ,nenRespStopPlugin //!< Response for a stop plugin request + ,nenRespShutdown //!< Response for a shutdown request + ,nenRespImportLog //!< Response for a import log request + ,nenRespEnumerateLogs //!< Response for a enumerate logs request + ,nenRespEnumerateInterfaces //!< Response for a enumerate interfaces request + ,nenRespChangeMsgData //!< Response for a change message data request + ,nenRespUploadLogMsg //!< Response for a upload log request + ,nenRespUnknownReq //!< Response for a unknown request + ,nenRespInvalidArg //!< Response for a request with invalid arguments + ,nenNumberOfNetworkMessageTypes //!< must be last +}; + +/*! + * \brief structure of network message header + */ +struct tstNetworkMessageHeader +{ + tenNetworkMessageType enMessageType; //!< type of the message + uint32_t u32MessageLength; //!< total length of network message. less or equal nNETWORK_BUFFSIZE +}; + +/// maximum length of the data part in a network message +/// data size = message size - header size +#define nNETWORK_DATALENGTH (nNETWORK_BUFFSIZE - sizeof(tstNetworkMessageHeader)) + + +#endif /* PROTOCOL_H_SEI */ diff --git a/Master/Masterarbeit/src/common/src/CNetworkStream.cpp b/Master/Masterarbeit/src/common/src/CNetworkStream.cpp new file mode 100644 index 0000000..98f204d --- /dev/null +++ b/Master/Masterarbeit/src/common/src/CNetworkStream.cpp @@ -0,0 +1,203 @@ +#ifndef CNETWORKSTREAM_H_ +#include +#endif + +#include + +CNetworkInStream::CNetworkInStream(uint8_t* pu8Buffer, uint32_t u32BufferSize) +:m_pu8CurrentPtr(pu8Buffer),m_pru8StartPtr(pu8Buffer),m_pru8EndPtr(m_pru8StartPtr+u32BufferSize) +,m_enError(nenStreamOK) +{ +} + +bool CNetworkInStream::boCheck(const uint32_t u32Length) +{ + if( m_pu8CurrentPtr+u32Length <= m_pru8EndPtr ) + { + return true; + } + else + { + vSetError(nenErrorStreamToShort); + return false; + } +} + +void CNetworkInStream::vReadInt8(int8_t& i8Val) +{ + uint8_t u8Val; + vReadUint8(u8Val); + i8Val = static_cast(u8Val); +} + +void CNetworkInStream::vReadUint8(uint8_t& u8Val) +{ + if( boCheck(1) ) + { + u8Val = *m_pu8CurrentPtr; + m_pu8CurrentPtr++; + } +} + +void CNetworkInStream::vReadInt32(int32_t& i32Val) +{ + uint32_t u32Val; + vReadUint32(u32Val); + i32Val = static_cast(u32Val); +} + +void CNetworkInStream::vReadUint32(uint32_t& u32Val) +{ + uint32_t u32Tmp; + uint8_t* pu8Ptr = reinterpret_cast(&u32Tmp); + vReadUint8(*pu8Ptr); + pu8Ptr++; + vReadUint8(*pu8Ptr); + pu8Ptr++; + vReadUint8(*pu8Ptr); + pu8Ptr++; + vReadUint8(*pu8Ptr); + pu8Ptr++; + u32Val = BYTE_SWAP32(uint32_t,u32Tmp); +} + +void CNetworkInStream::vReadString(char* pcVal, uint32_t u32Length) +{ + if( boCheck(u32Length) ) + { + memcpy(pcVal,m_pu8CurrentPtr,u32Length); + m_pu8CurrentPtr += u32Length; + } +} + +uint32_t CNetworkInStream::u32GetByteCount() const +{ + return static_cast(m_pu8CurrentPtr-m_pru8StartPtr); +} + +void CNetworkInStream::vSetPosition(const uint32_t u32Offset) +{ + if( (m_pru8StartPtr <= (m_pu8CurrentPtr+u32Offset) ) + && ( (m_pu8CurrentPtr+u32Offset) <= m_pru8EndPtr) ) + { + m_pu8CurrentPtr = m_pru8StartPtr+u32Offset; + } +} + +void CNetworkInStream::vSetError(tenStreamError enError) +{ + m_enError = enError; +} + +void CNetworkInStream::vGetError(tenStreamError& enError) const +{ + enError = m_enError; +} + +bool CNetworkInStream::boIsOK() const +{ + return ( m_enError == nenStreamOK ); +} + +void CNetworkInStream::vReset() +{ + vSetPosition(0); + vSetError(nenStreamOK); +} + +CNetworkOutStream::CNetworkOutStream(uint8_t* pu8Buffer, uint32_t u32BufferSize) +:m_pu8CurrentPtr(pu8Buffer),m_pru8StartPtr(m_pu8CurrentPtr),m_pru8EndPtr(m_pru8StartPtr+u32BufferSize) +,m_enError(nenStreamOK) +{ +} + +bool CNetworkOutStream::boCheck(const uint32_t u32Length) +{ + if( m_pu8CurrentPtr+u32Length <= m_pru8EndPtr ) + { + return true; + } + else + { + vSetError(nenErrorStreamToShort); + return false; + } +} + +void CNetworkOutStream::vWriteInt8(const int8_t i8Val) +{ + uint8_t u8Val = static_cast(i8Val); + vWriteUint8(u8Val); +} + +void CNetworkOutStream::vWriteUint8(const uint8_t u8Val) +{ + if( boCheck(1) ) + { + *m_pu8CurrentPtr = u8Val; + m_pu8CurrentPtr++; + } +} + +void CNetworkOutStream::vWriteInt32(const int32_t i32Val) +{ + uint32_t u32Val = static_cast(i32Val); + vWriteUint32(u32Val); +} + +void CNetworkOutStream::vWriteUint32(const uint32_t u32Val) +{ + uint32_t u32Tmp = BYTE_SWAP32(uint32_t,u32Val); + uint8_t* pu8Ptr = reinterpret_cast(&u32Tmp); + vWriteUint8(*pu8Ptr); + pu8Ptr++; + vWriteUint8(*pu8Ptr); + pu8Ptr++; + vWriteUint8(*pu8Ptr); + pu8Ptr++; + vWriteUint8(*pu8Ptr); + pu8Ptr++; +} + +void CNetworkOutStream::vWriteString(const char* pcVal, const uint32_t u32Length) +{ + if( boCheck(u32Length) ) + { + memcpy(m_pu8CurrentPtr,pcVal,u32Length); + m_pu8CurrentPtr += u32Length; + } +} + +uint32_t CNetworkOutStream::u32GetByteCount() const +{ + uint32_t u32ByteCount = static_cast(m_pu8CurrentPtr-m_pru8StartPtr); + return u32ByteCount; +} +void CNetworkOutStream::vSetPosition(const uint32_t u32Offset) +{ + if( (m_pru8StartPtr <= (m_pu8CurrentPtr+u32Offset) ) + && ( (m_pu8CurrentPtr+u32Offset) <= m_pru8EndPtr) ) + { + m_pu8CurrentPtr = const_cast(m_pru8StartPtr)+u32Offset; + } +} +void CNetworkOutStream::vSetError(tenStreamError enError) +{ + m_enError = enError; +} + +void CNetworkOutStream::vGetError(tenStreamError& enError) const +{ + enError = m_enError; +} + +bool CNetworkOutStream::boIsOK() const +{ + return ( m_enError == nenStreamOK ); +} + +void CNetworkOutStream::vReset() +{ + vSetPosition(0); + vSetError(nenStreamOK); +} diff --git a/Master/Masterarbeit/src/common/src/NetworkTypes.cpp b/Master/Masterarbeit/src/common/src/NetworkTypes.cpp new file mode 100644 index 0000000..da398ad --- /dev/null +++ b/Master/Masterarbeit/src/common/src/NetworkTypes.cpp @@ -0,0 +1,540 @@ +#include +#include +#include + +CNetworkDatacontainer::CNetworkDatacontainer() +#ifndef _MSC_VER +/// target compiler supports initialization of member structs +:m_stReqUploadLogMsg({{nenReqUploadLogMsg,sizeof(tstNetworkMessageHeader)+sizeof(tstLogMessage)}}) +,m_stRespStartPlugin({{nenRespStartPlugin,8}}) +,m_stRespStopPlugin({{nenRespStopPlugin,8}}) +,m_stRespShutdown({{nenRespShutdown,8}}) +,m_stRespImportLog({{nenRespImportLog,512}}) +,m_stRespEnumerateLogs({{nenRespEnumerateLogs,512}}) +,m_stRespEnumerateInterfaces({{nenRespEnumerateInterfaces,512}}) +,m_stRespChangeMsgData({{nenRespChangeMsgData,8}}) +,m_stRespUnknownReq({{nenRespUnknownReq,8}}) +,m_stRespInvalidArg({{nenRespInvalidArg,8}}) +{} +#else +/// host compiler does not support initialization of member structs +{ + m_stReqUploadLogMsg.stHeader.enMessageType = nenReqUploadLogMsg; + m_stReqUploadLogMsg.stHeader.u32MessageLength = sizeof(tstNetworkMessageHeader)+sizeof(tstLogMessage); + m_stRespUploadLogMsg.stHeader.enMessageType = nenRespUploadLogMsg; + m_stRespUploadLogMsg.stHeader.u32MessageLength = 8; + m_stReqStartPlugin.stHeader.enMessageType = nenReqStartPlugin; + m_stReqStartPlugin.stHeader.u32MessageLength = 512; + m_stReqStopPlugin.stHeader.enMessageType = nenReqStopPlugin; + m_stReqStopPlugin.stHeader.u32MessageLength = 12; + m_stReqShutdown.stHeader.enMessageType = nenReqShutdown; + m_stReqShutdown.stHeader.u32MessageLength = 8; + m_stReqImportLog.stHeader.enMessageType = nenReqImportLog; + m_stReqImportLog.stHeader.u32MessageLength = 512; + m_stReqEnumerateLogs.stHeader.enMessageType = nenReqEnumerateLogs; + m_stReqEnumerateLogs.stHeader.u32MessageLength = 8; + m_stReqEnumerateInterfaces.stHeader.enMessageType = nenReqEnumerateInterfaces; + m_stReqEnumerateInterfaces.stHeader.u32MessageLength = 8; + m_stReqChangeMsgData.stHeader.enMessageType = nenReqChangeMsgData; + m_stReqChangeMsgData.stHeader.u32MessageLength = 24; + m_stRespUnknownReq.stHeader.enMessageType = nenRespUnknownReq; + m_stRespUnknownReq.stHeader.u32MessageLength = 8; + m_stRespInvalidArg.stHeader.enMessageType = nenRespInvalidArg; + m_stRespInvalidArg.stHeader.u32MessageLength = 8; +} +#endif +void* CNetworkDatacontainer::pvGetVarPtr( tenNetworkMessageType enMsgIdx) +{ + switch(enMsgIdx) + { + case nenReqStartPlugin: + return &m_stReqStartPlugin; + case nenReqStopPlugin: + return &m_stReqStopPlugin; + case nenReqEnumerateInterfaces: + return &m_stReqEnumerateInterfaces; + case nenReqEnumerateLogs: + return &m_stReqEnumerateLogs; + case nenReqShutdown: + return &m_stReqShutdown; + case nenReqChangeMsgData: + return &m_stReqChangeMsgData; + case nenReqUploadLogMsg: + return &m_stReqUploadLogMsg; + case nenReqImportLog: + return &m_stReqImportLog; + case nenRespStartPlugin: + return &m_stRespStartPlugin; + case nenRespStopPlugin: + return &m_stRespStopPlugin; + case nenRespShutdown: + return &m_stRespShutdown; + case nenRespImportLog: + return &m_stRespImportLog; + case nenRespEnumerateLogs: + return &m_stRespEnumerateLogs; + case nenRespEnumerateInterfaces: + return &m_stRespEnumerateInterfaces; + case nenRespChangeMsgData: + return &m_stRespChangeMsgData; + case nenRespUploadLogMsg: + return &m_stRespUploadLogMsg; + case nenRespUnknownReq: + return &m_stRespUnknownReq; + case nenRespInvalidArg: + return &m_stRespInvalidArg; + case nenNumberOfNetworkMessageTypes: + return &m_stRxMsg; + default: + return NULL; + }; + return NULL; +} + +void* CNetworkDatacontainer::pvGetVarPtr(tenNetworkMessageType enMsgIdx, uint8_t u8ElemIdx) +{ + switch(enMsgIdx) + { + case nenReqStartPlugin: + switch(u8ElemIdx) + { + case 0: return &m_stReqStartPlugin.stHeader.enMessageType; + case 1: return &m_stReqStartPlugin.stHeader.u32MessageLength; + case 2: return &m_stReqStartPlugin.i32Interface; + case 3: return &m_stReqStartPlugin.acFilename; + default: return NULL; + } + break; + case nenReqStopPlugin: + switch(u8ElemIdx) + { + case 0: return &m_stReqStopPlugin.stHeader.enMessageType; + case 1: return &m_stReqStopPlugin.stHeader.u32MessageLength; + case 2: return &m_stReqStopPlugin.i32Interface; + default: return NULL; + } + break; + case nenReqEnumerateInterfaces: + switch(u8ElemIdx) + { + case 0: return &m_stReqEnumerateInterfaces.stHeader.enMessageType; + case 1: return &m_stReqEnumerateInterfaces.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenReqEnumerateLogs: + switch(u8ElemIdx) + { + case 0: return &m_stReqEnumerateLogs.stHeader.enMessageType; + case 1: return &m_stReqEnumerateLogs.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenReqShutdown: + switch(u8ElemIdx) + { + case 0: return &m_stReqShutdown.stHeader.enMessageType; + case 1: return &m_stReqShutdown.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenReqImportLog: + switch(u8ElemIdx) + { + case 0: return &m_stReqImportLog.stHeader.enMessageType; + case 1: return &m_stReqImportLog.stHeader.u32MessageLength; + case 2: return &m_stReqImportLog.acFilename; + default: return NULL; + } + break; + case nenReqChangeMsgData: + switch(u8ElemIdx) + { + case 0: return &m_stReqChangeMsgData.stHeader.enMessageType; + case 1: return &m_stReqChangeMsgData.stHeader.u32MessageLength; + case 2: return &m_stReqChangeMsgData.i32Interface; + case 3: return &m_stReqChangeMsgData.u32CanMsgId; + case 4: return &m_stReqChangeMsgData.au8Data[0]; + case 5: return &m_stReqChangeMsgData.au8Data[1]; + case 6: return &m_stReqChangeMsgData.au8Data[2]; + case 7: return &m_stReqChangeMsgData.au8Data[3]; + case 8: return &m_stReqChangeMsgData.au8Data[4]; + case 9: return &m_stReqChangeMsgData.au8Data[5]; + case 10: return &m_stReqChangeMsgData.au8Data[6]; + case 11: return &m_stReqChangeMsgData.au8Data[7]; + default: return NULL; + } + break; + case nenReqUploadLogMsg: + switch(u8ElemIdx) + { + case 0: return &m_stReqUploadLogMsg.stHeader.enMessageType; + case 1: return &m_stReqUploadLogMsg.stHeader.u32MessageLength; + case 2: return &m_stReqUploadLogMsg.stLogMessage.u32TsHigh; + case 3: return &m_stReqUploadLogMsg.stLogMessage.u32TsLow; + case 4: return &m_stReqUploadLogMsg.stLogMessage.i32Interface; + case 5: return &m_stReqUploadLogMsg.stLogMessage.u32MsgId; + case 6: return &m_stReqUploadLogMsg.stLogMessage.au8Data[0]; + case 7: return &m_stReqUploadLogMsg.stLogMessage.au8Data[1]; + case 8: return &m_stReqUploadLogMsg.stLogMessage.au8Data[2]; + case 9: return &m_stReqUploadLogMsg.stLogMessage.au8Data[3]; + case 10: return &m_stReqUploadLogMsg.stLogMessage.au8Data[4]; + case 11: return &m_stReqUploadLogMsg.stLogMessage.au8Data[5]; + case 12: return &m_stReqUploadLogMsg.stLogMessage.au8Data[6]; + case 13: return &m_stReqUploadLogMsg.stLogMessage.au8Data[7]; + case 14: return &m_stReqUploadLogMsg.stLogMessage.u8Dir; + default: return NULL; + } + break; + case nenRespStartPlugin: + switch(u8ElemIdx) + { + case 0: return &m_stRespStartPlugin.stHeader.enMessageType; + case 1: return &m_stRespStartPlugin.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenRespStopPlugin: + switch(u8ElemIdx) + { + case 0: return &m_stRespStopPlugin.stHeader.enMessageType; + case 1: return &m_stRespStopPlugin.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenRespShutdown: + switch(u8ElemIdx) + { + case 0: return &m_stRespShutdown.stHeader.enMessageType; + case 1: return &m_stRespShutdown.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenRespImportLog: + switch(u8ElemIdx) + { + case 0: return &m_stRespImportLog.stHeader.enMessageType; + case 1: return &m_stRespImportLog.stHeader.u32MessageLength; + case 2: return &m_stRespImportLog.acFilename; + default: return NULL; + } + break; + case nenRespEnumerateLogs: + switch(u8ElemIdx) + { + case 0: return &m_stRespEnumerateLogs.stHeader.enMessageType; + case 1: return &m_stRespEnumerateLogs.stHeader.u32MessageLength; + case 2: return &m_stRespEnumerateLogs.acFilenames; + default: return NULL; + } + break; + case nenRespEnumerateInterfaces: + switch(u8ElemIdx) + { + case 0: return &m_stRespEnumerateInterfaces.stHeader.enMessageType; + case 1: return &m_stRespEnumerateInterfaces.stHeader.u32MessageLength; + case 2: return &m_stRespEnumerateInterfaces.acInterfaces; + default: return NULL; + } + break; + case nenRespChangeMsgData: + switch(u8ElemIdx) + { + case 0: return &m_stRespChangeMsgData.stHeader.enMessageType; + case 1: return &m_stRespChangeMsgData.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenRespUploadLogMsg: + switch(u8ElemIdx) + { + case 0: return &m_stRespUploadLogMsg.stHeader.enMessageType; + case 1: return &m_stRespUploadLogMsg.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenRespUnknownReq: + switch(u8ElemIdx) + { + case 0: return &m_stRespUnknownReq.stHeader.enMessageType; + case 1: return &m_stRespUnknownReq.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenRespInvalidArg: + switch(u8ElemIdx) + { + case 0: return &m_stRespInvalidArg.stHeader.enMessageType; + case 1: return &m_stRespInvalidArg.stHeader.u32MessageLength; + default: return NULL; + } + break; + case nenNumberOfNetworkMessageTypes: + switch(u8ElemIdx) + { + case 0: return &m_stRxMsg.stHeader.enMessageType; + case 1: return &m_stRxMsg.stHeader.u32MessageLength; + default: return NULL; + } + break; + default: + return NULL; + }; + return NULL; +} + +void CNetworkEnum::vRead(void* pvDest, CNetworkInStream& xStream) const +{ + int32_t& i32ActVal = *(reinterpret_cast(pvDest)); + xStream.vReadInt32(i32ActVal); + if( !boIsValid(i32ActVal) ) + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +void CNetworkEnum::vWrite(void* pvSrc, CNetworkOutStream& xStream) const +{ + int32_t& i32ActVal = *(reinterpret_cast(pvSrc)); + if( boIsValid(i32ActVal) ) + { + xStream.vWriteInt32(i32ActVal); + } + else + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +bool CNetworkEnum::boIsValid(const int32_t i32Value) const +{ + bool boValid = false; + if( ( m_i32Min <= i32Value ) && (m_i32Max >= i32Value) ) + { + boValid = true; + } + return boValid; +} + +void CNetworkUint32::vRead(void* pvDest, CNetworkInStream& xStream) const +{ + uint32_t& u32ActVal = *(reinterpret_cast(pvDest)); + xStream.vReadUint32(u32ActVal); + if( !boIsValid(u32ActVal) ) + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +void CNetworkUint32::vWrite(void* pvSrc, CNetworkOutStream& xStream) const +{ + uint32_t& u32ActVal = *(reinterpret_cast(pvSrc)); + if( boIsValid(u32ActVal) ) + { + xStream.vWriteUint32(u32ActVal); + } + else + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +bool CNetworkUint32::boIsValid(const uint32_t u32Value) const +{ + bool boValid = false; + if( ( m_u32Min <= u32Value ) && (m_u32Max >= u32Value) ) + { + boValid = true; + } + return boValid; +} + +void CNetworkInt32::vRead(void* pvDest, CNetworkInStream& xStream) const +{ + int32_t& i32ActVal = *(reinterpret_cast(pvDest)); + xStream.vReadInt32(i32ActVal); + if( !boIsValid(i32ActVal) ) + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +void CNetworkInt32::vWrite(void* pvSrc, CNetworkOutStream& xStream) const +{ + int32_t& i32ActVal = *(reinterpret_cast(pvSrc)); + if( boIsValid(i32ActVal) ) + { + xStream.vWriteInt32(i32ActVal); + } + else + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +bool CNetworkInt32::boIsValid(const int32_t i32Value) const +{ + bool boValid = false; + if( ( m_i32Min <= i32Value ) && (m_i32Max >= i32Value) ) + { + boValid = true; + } + return boValid; +} + +void CNetworkUint8::vRead(void* pvDest, CNetworkInStream& xStream) const +{ + uint8_t& u8ActVal = *(reinterpret_cast(pvDest)); + xStream.vReadUint8(u8ActVal); + if( !boIsValid(u8ActVal) ) + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +void CNetworkUint8::vWrite(void* pvSrc, CNetworkOutStream& xStream) const +{ + uint8_t& u8ActVal = *(reinterpret_cast(pvSrc)); + if( boIsValid(u8ActVal) ) + { + xStream.vWriteUint8(u8ActVal); + } + else + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +bool CNetworkUint8::boIsValid(const uint8_t u8Value) const +{ + bool boValid = false; + if( ( m_u8Min <= u8Value ) && (m_u8Max >= u8Value) ) + { + boValid = true; + } + return boValid; +} + +void CNetworkInt8::vRead(void* pvDest, CNetworkInStream& xStream) const +{ + int8_t& i8ActVal = *(reinterpret_cast(pvDest)); + xStream.vReadInt8(i8ActVal); + if( !boIsValid(i8ActVal) ) + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +void CNetworkInt8::vWrite(void* pvSrc, CNetworkOutStream& xStream) const +{ + int8_t& i8ActVal = *(reinterpret_cast(pvSrc)); + if( boIsValid(i8ActVal) ) + { + xStream.vWriteInt8(i8ActVal); + } + else + { + xStream.vSetError(nenErrorValueOutOfRange); + } +} + +bool CNetworkInt8::boIsValid(const int8_t i8Value) const +{ + bool boValid = false; + if( ( m_i8Min <= i8Value ) && (m_i8Max >= i8Value) ) + { + boValid = true; + } + return boValid; +} + +void CNetworkString::vRead(void* pvDest, CNetworkInStream& xStream) const +{ + memset(pvDest,0,m_u32Length); + xStream.vReadString(reinterpret_cast(pvDest),m_u32Length); +} + +void CNetworkString::vWrite(void* pvSrc, CNetworkOutStream& xStream) const +{ + xStream.vWriteString(reinterpret_cast(pvSrc),m_u32Length); +} + +void CNetworkRecordProp::vRead(CNetworkDatacontainer& xDatacontainer, CNetworkInStream& xStream) const +{ + void* pvSrc; + for(uint8_t u8Field = 0; u8Field < m_u8NumOfFields; u8Field++) + { + const tstTypeInfo* pstTypeInfo = m_apstFieldInfoPtrArray[u8Field]; + pvSrc = xDatacontainer.pvGetVarPtr(m_enMsgType,u8Field); + if(pvSrc) { + vInvokeRead(pstTypeInfo,pvSrc,xStream); + } + } +} + +void CNetworkRecordProp::vWrite(CNetworkDatacontainer& xDatacontainer, CNetworkOutStream& xStream) const +{ + void* pvDst; + for(uint8_t u8Field = 0; u8Field < m_u8NumOfFields; u8Field++) + { + const tstTypeInfo* pstTypeInfo = m_apstFieldInfoPtrArray[u8Field]; + pvDst = xDatacontainer.pvGetVarPtr(m_enMsgType,u8Field); + if(pvDst) { + vInvokeWrite(pstTypeInfo,pvDst,xStream); + } + } +} + +void vInvokeRead(const tstTypeInfo* pstObjPtr, void* pvDst, CNetworkInStream& xStream) +{ + switch(pstObjPtr->m_enType) + { + case nenNetworkEnum: + (static_cast(pstObjPtr))->vRead(pvDst,xStream); + break; + case nenNetworkInt8: + (static_cast(pstObjPtr))->vRead(pvDst,xStream); + break; + case nenNetworkUint8: + (static_cast(pstObjPtr))->vRead(pvDst,xStream); + break; + case nenNetworkInt32: + (static_cast(pstObjPtr))->vRead(pvDst,xStream); + break; + case nenNetworkUint32: + (static_cast(pstObjPtr))->vRead(pvDst,xStream); + break; + case nenNetworkString: + (static_cast(pstObjPtr))->vRead(pvDst,xStream); + break; + default: + break; + } +} + +void vInvokeWrite(const tstTypeInfo* pstObjPtr, void* pvSrc, CNetworkOutStream& xStream) +{ + switch(pstObjPtr->m_enType) + { + case nenNetworkEnum: + (static_cast(pstObjPtr))->vWrite(pvSrc,xStream); + break; + case nenNetworkInt8: + (static_cast(pstObjPtr))->vWrite(pvSrc,xStream); + break; + case nenNetworkUint8: + (static_cast(pstObjPtr))->vWrite(pvSrc,xStream); + break; + case nenNetworkInt32: + (static_cast(pstObjPtr))->vWrite(pvSrc,xStream); + break; + case nenNetworkUint32: + (static_cast(pstObjPtr))->vWrite(pvSrc,xStream); + break; + case nenNetworkString: + (static_cast(pstObjPtr))->vWrite(pvSrc,xStream); + break; + default: + break; + } +} -- cgit v1.2.3