/* Copyright (c) 2018, MIPI Alliance, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * Contributors: * Norbert Schulz (Intel Corporation) - Initial API and implementation */ #ifndef MIPI_SYST_MESSAGE_H_included #define MIPI_SYST_MESSAGE_H_included #include #include #include #include #include "mipi_syst_printer.h" #include "mipi_syst_guid.h" MIPI_SYST_NAMESPACE_BEGIN class collateral; /// Internal representation of a decoded SyS-T message /// class message { public: enum decode_state { OK = 0, UNKNOWN_TYPE = 1, TOO_SHORT = 2, TOO_LONG = 3, CHECKSUM_ERROR = 4, MISSING_COLLATERAL = 5 }; union header { public: struct fields { #if defined(MIPI_SYST_BIG_ENDIAN) uint32_t res31 : 1; ///< reserved, must be 0 uint32_t res30 : 1; ///< reserved, must be 0 uint32_t subtype : 6; ///< type dependent sub category uint32_t guid : 1; ///< 128 bit GUID present uint32_t originUnit : 11; ///< unit for GUID or module:unit pair uint32_t timestamp : 1; ///< indicate 64 bit timestamp uint32_t chksum : 1; ///< indicate 32bit CRC uint32_t length : 1; ///< indicate variable length message uint32_t location : 1; ///< indicate location information uint32_t res7 : 1; ///> 4); } uint32_t getUnit() const { return m_hdr.field.guid ? m_hdr.field.originUnit : (m_hdr.field.originUnit & 0xF); } uint64_t getMessageTS() const{ return m_msgTS; } uint64_t getContextTS()const { return m_ctxTS; } uint64_t getBuild() const { return m_build; } bool isShort() const { return isShort(getHeader()); }; static bool isShort(header hdr); static const char csvHeaderString[]; private: decode_state m_state; header m_hdr; uint64_t m_msgTS; uint64_t m_ctxTS; uint64_t m_build; guid m_guid; location m_loc; std::string m_payload; std::string m_clientname; uint32_t m_length; uint32_t m_crc; const collateral * m_coll; }; std::ostream& operator<<(std::ostream& os, const message& msg); MIPI_SYST_NAMESPACE_END #endif // MIPI_SYST_MESSAGE_H_included