text: // ======================================================================
  // \title  BlspSpiDriver/test/ut/TesterBase.hpp
  // \author Auto-generated
  // \brief  hpp file for BlspSpiDriver component test harness base class
  //
  // \copyright
  // Copyright 2009-2015, by the California Institute of Technology.
  // ALL RIGHTS RESERVED.  United States Government Sponsorship
  // acknowledged. Any commercial use must be negotiated with the Office
  // of Technology Transfer at the California Institute of Technology.
  //
  // This software may be subject to U.S. export control laws and
  // regulations.  By accepting this document, the user agrees to comply
  // with all U.S. export laws and regulations.  User has the
  // responsibility to obtain export licenses, or other export authority
  // as may be required before exporting such information to foreign
  // countries or providing access to foreign persons.
  // ======================================================================
  
  #ifndef BlspSpiDriver_TESTER_BASE_HPP
  #define BlspSpiDriver_TESTER_BASE_HPP
  
  #include <SnapdragonFlight/BlspSpiDriver/BlspSpiDriverComponentAc.hpp>
  #include <Fw/Types/Assert.hpp>
  #include <Fw/Comp/PassiveComponentBase.hpp>
  #include <stdio.h>
  #include <Fw/Port/InputSerializePort.hpp>
  
  namespace SnapdragonFlight {
  
    //! \class BlspSpiDriverTesterBase
    //! \brief Auto-generated base class for BlspSpiDriver component test harness
    //!
    class BlspSpiDriverTesterBase :
      public Fw::PassiveComponentBase
    {
  
      public:
  
        // ----------------------------------------------------------------------
        // Initialization
        // ----------------------------------------------------------------------
  
        //! Initialize object BlspSpiDriverTesterBase
        //!
        virtual void init(
            const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/
        );
  
      public:
  
        // ----------------------------------------------------------------------
        // Connectors for 'to' ports
        // Connect these output ports to the input ports under test
        // ----------------------------------------------------------------------
  
        //! Connect SpiReadWrite to to_SpiReadWrite[portNum]
        //!
        void connect_to_SpiReadWrite(
            const NATIVE_INT_TYPE portNum, /*!< The port number*/
            Drv::InputSpiReadWritePort *const SpiReadWrite /*!< The port*/
        );
  
      public:
  
        // ----------------------------------------------------------------------
        // Getters for 'from' ports
        // Connect these input ports to the output ports under test
        // ----------------------------------------------------------------------
  
        //! Get the port that receives input from Tlm
        //!
        //! \return from_Tlm[portNum]
        //!
        Fw::InputTlmPort* get_from_Tlm(
            const NATIVE_INT_TYPE portNum /*!< The port number*/
        );
  
        //! Get the port that receives input from Time
        //!
        //! \return from_Time[portNum]
        //!
        Fw::InputTimePort* get_from_Time(
            const NATIVE_INT_TYPE portNum /*!< The port number*/
        );
  
        //! Get the port that receives input from Log
        //!
        //! \return from_Log[portNum]
        //!
        Fw::InputLogPort* get_from_Log(
            const NATIVE_INT_TYPE portNum /*!< The port number*/
        );
  
  #if FW_ENABLE_TEXT_LOGGING == 1
        //! Get the port that receives input from LogText
        //!
        //! \return from_LogText[portNum]
        //!
        Fw::InputLogTextPort* get_from_LogText(
            const NATIVE_INT_TYPE portNum /*!< The port number*/
        );
  #endif
  
      protected:
  
        // ----------------------------------------------------------------------
        // Construction and destruction
        // ----------------------------------------------------------------------
  
        //! Construct object BlspSpiDriverTesterBase
        //!
        BlspSpiDriverTesterBase(
  #if FW_OBJECT_NAMES == 1
            const char *const compName, /*!< The component name*/
            const U32 maxHistorySize /*!< The maximum size of each history*/
  #else
            const U32 maxHistorySize /*!< The maximum size of each history*/
  #endif
        );
  
        //! Destroy object BlspSpiDriverTesterBase
        //!
        virtual ~BlspSpiDriverTesterBase(void);
  
        // ----------------------------------------------------------------------
        // Test history
        // ----------------------------------------------------------------------
  
      protected:
  
        //! \class History
        //! \brief A history of port inputs
        //!
        template <typename T> class History {
  
          public:
  
            //! Create a History
            //!
            History(
                const U32 maxSize /*!< The maximum history size*/
            ) : 
                numEntries(0), 
                maxSize(maxSize) 
            { 
              this->entries = new T[maxSize];
            }
  
            //! Destroy a History
            //!
            ~History() {
              delete[] this->entries;
            }
  
            //! Clear the history
            //!
            void clear() { this->numEntries = 0; }
  
            //! Push an item onto the history
            //!
            void push_back(
                T entry /*!< The item*/
            ) {
              FW_ASSERT(this->numEntries < this->maxSize);
              entries[this->numEntries++] = entry;
            }
  
            //! Get an item at an index
            //!
            //! \return The item at index i
            //!
            T at(
                const U32 i /*!< The index*/
            ) const {
              FW_ASSERT(i < this->numEntries);
              return entries[i];
            }
  
            //! Get the number of entries in the history
            //!
            //! \return The number of entries in the history
            //!
            U32 size(void) const { return this->numEntries; }
  
          private:
  
            //! The number of entries in the history
            //!
            U32 numEntries;
  
            //! The maximum history size
            //!
            const U32 maxSize;
  
            //! The entries
            //!
            T *entries;
  
        };
  
        //! Clear all history
        //!
        void clearHistory(void);
  
      protected:
  
        // ----------------------------------------------------------------------
        // Invocation functions for to ports
        // ----------------------------------------------------------------------
  
        //! Invoke the to port connected to SpiReadWrite
        //!
        void invoke_to_SpiReadWrite(
            const NATIVE_INT_TYPE portNum, /*!< The port number*/
            Fw::Buffer &writeBuffer, 
            Fw::Buffer &readBuffer 
        );
  
      public:
  
        // ----------------------------------------------------------------------
        // Getters for port counts
        // ----------------------------------------------------------------------
  
        //! Get the number of to_SpiReadWrite ports
        //!
        //! \return The number of to_SpiReadWrite ports
        //!
        NATIVE_INT_TYPE getNum_to_SpiReadWrite(void) const;
  
        //! Get the number of from_Tlm ports
        //!
        //! \return The number of from_Tlm ports
        //!
        NATIVE_INT_TYPE getNum_from_Tlm(void) const;
  
        //! Get the number of from_Time ports
        //!
        //! \return The number of from_Time ports
        //!
        NATIVE_INT_TYPE getNum_from_Time(void) const;
  
        //! Get the number of from_Log ports
        //!
        //! \return The number of from_Log ports
        //!
        NATIVE_INT_TYPE getNum_from_Log(void) const;
  
  #if FW_ENABLE_TEXT_LOGGING == 1
        //! Get the number of from_LogText ports
        //!
        //! \return The number of from_LogText ports
        //!
        NATIVE_INT_TYPE getNum_from_LogText(void) const;
  #endif
  
      protected:
  
        // ----------------------------------------------------------------------
        // Connection status for to ports
        // ----------------------------------------------------------------------
  
        //! Check whether port is connected
        //!
        //! Whether to_SpiReadWrite[portNum] is connected
        //!
        bool isConnected_to_SpiReadWrite(
            const NATIVE_INT_TYPE portNum /*!< The port number*/
        );
  
      protected:
  
        // ----------------------------------------------------------------------
        // Event dispatch
        // ----------------------------------------------------------------------
  
        //! Dispatch an event
        //!
        void dispatchEvents(
            const FwEventIdType id, /*!< The event ID*/
            Fw::Time& timeTag, /*!< The time*/
            const Fw::LogSeverity severity, /*!< The severity*/
            Fw::LogBuffer& args /*!< The serialized arguments*/
        );
  
        //! Clear event history
        //!
        void clearEvents(void);
  
        //! The total number of events seen
        //!
        U32 eventsSize;
  
  #if FW_ENABLE_TEXT_LOGGING
  
      protected:
  
        // ----------------------------------------------------------------------
        // Text events
        // ----------------------------------------------------------------------
  
        //! Handle a text event
        //!
        virtual void textLogIn(
            const FwEventIdType id, /*!< The event ID*/
            Fw::Time& timeTag, /*!< The time*/
            const Fw::TextLogSeverity severity, /*!< The severity*/
            const Fw::TextLogString& text /*!< The event string*/
        );
  
        //! A history entry for the text log
        //!
        typedef struct {
          U32 id;
          Fw::Time timeTag;
          Fw::TextLogSeverity severity;
          Fw::TextLogString text;
        } TextLogEntry;
  
        //! The history of text log events
        //!
        History<TextLogEntry> *textLogHistory;
  
        //! Print a text log history entry
        //!
        static void printTextLogHistoryEntry(
            const TextLogEntry& e,
            FILE* file
        );
  
        //! Print the text log history
        //!
        void printTextLogHistory(FILE *const file);
  
  #endif
  
      protected:
  
        // ----------------------------------------------------------------------
        // Event: SPI_OpenError
        // ----------------------------------------------------------------------
  
        //! Handle event SPI_OpenError
        //!
        virtual void logIn_WARNING_HI_SPI_OpenError(
            I32 device, /*!< The device*/
            I32 error /*!< The error code*/
        );
  
        //! A history entry for event SPI_OpenError
        //!
        typedef struct {
          I32 device;
          I32 error;
        } EventEntry_SPI_OpenError;
  
        //! The history of SPI_OpenError events
        //!
        History<EventEntry_SPI_OpenError> 
          *eventHistory_SPI_OpenError;
  
      protected:
  
        // ----------------------------------------------------------------------
        // Event: SPI_ConfigError
        // ----------------------------------------------------------------------
  
        //! Handle event SPI_ConfigError
        //!
        virtual void logIn_WARNING_HI_SPI_ConfigError(
            I32 device, /*!< The device*/
            I32 error /*!< The error code*/
        );
  
        //! A history entry for event SPI_ConfigError
        //!
        typedef struct {
          I32 device;
          I32 error;
        } EventEntry_SPI_ConfigError;
  
        //! The history of SPI_ConfigError events
        //!
        History<EventEntry_SPI_ConfigError> 
          *eventHistory_SPI_ConfigError;
  
      protected:
  
        // ----------------------------------------------------------------------
        // Event: SPI_WriteError
        // ----------------------------------------------------------------------
  
        //! Handle event SPI_WriteError
        //!
        virtual void logIn_WARNING_HI_SPI_WriteError(
            I32 device, /*!< The device*/
            I32 error /*!< The error code*/
        );
  
        //! A history entry for event SPI_WriteError
        //!
        typedef struct {
          I32 device;
          I32 error;
        } EventEntry_SPI_WriteError;
  
        //! The history of SPI_WriteError events
        //!
        History<EventEntry_SPI_WriteError> 
          *eventHistory_SPI_WriteError;
  
      protected:
  
        // ----------------------------------------------------------------------
        // Event: SPI_PortOpened
        // ----------------------------------------------------------------------
  
        //! Handle event SPI_PortOpened
        //!
        virtual void logIn_ACTIVITY_HI_SPI_PortOpened(
            I32 device /*!< The device*/
        );
  
        //! A history entry for event SPI_PortOpened
        //!
        typedef struct {
          I32 device;
        } EventEntry_SPI_PortOpened;
  
        //! The history of SPI_PortOpened events
        //!
        History<EventEntry_SPI_PortOpened> 
          *eventHistory_SPI_PortOpened;
  
      protected:
  
        // ----------------------------------------------------------------------
        // Telemetry dispatch
        // ----------------------------------------------------------------------
  
        //! Dispatch telemetry
        //!
        void dispatchTlm(
            const FwChanIdType id, /*!< The channel ID*/
            const Fw::Time& timeTag, /*!< The time*/
            Fw::TlmBuffer& val /*!< The channel value*/
        );
  
        //! Clear telemetry history
        //!
        void clearTlm(void);
  
        //! The total number of telemetry inputs seen
        //!
        U32 tlmSize;
  
      protected:
  
        // ----------------------------------------------------------------------
        // Channel: SPI_Bytes
        // ----------------------------------------------------------------------
  
        //! Handle channel SPI_Bytes
        //!
        virtual void tlmInput_SPI_Bytes(
            const Fw::Time& timeTag, /*!< The time*/
            const U32& val /*!< The channel value*/
        );
  
        //! A telemetry entry for channel SPI_Bytes
        //!
        typedef struct {
          Fw::Time timeTag;
          U32 arg;
        } TlmEntry_SPI_Bytes;
  
        //! The history of SPI_Bytes values
        //!
        History<TlmEntry_SPI_Bytes> 
          *tlmHistory_SPI_Bytes;
  
      protected:
  
        // ----------------------------------------------------------------------
        // Test time
        // ----------------------------------------------------------------------
  
        //! Set the test time for events and telemetry
        //!
        void setTestTime(
            const Fw::Time& timeTag /*!< The time*/
        );
  
      private:
  
        // ----------------------------------------------------------------------
        // To ports
        // ----------------------------------------------------------------------
  
        //! To port connected to SpiReadWrite
        //!
        Drv::OutputSpiReadWritePort m_to_SpiReadWrite[1];
  
      private:
  
        // ----------------------------------------------------------------------
        // From ports
        // ----------------------------------------------------------------------
  
        //! From port connected to Tlm
        //!
        Fw::InputTlmPort m_from_Tlm[1];
  
        //! From port connected to Time
        //!
        Fw::InputTimePort m_from_Time[1];
  
        //! From port connected to Log
        //!
        Fw::InputLogPort m_from_Log[1];
  
  #if FW_ENABLE_TEXT_LOGGING == 1
        //! From port connected to LogText
        //!
        Fw::InputLogTextPort m_from_LogText[1];
  #endif
  
      private:
  
        // ----------------------------------------------------------------------
        // Static functions for output ports
        // ----------------------------------------------------------------------
  
        //! Static function for port from_Tlm
        //!
        static void from_Tlm_static(
            Fw::PassiveComponentBase *const callComp, /*!< The component instance*/
            const NATIVE_INT_TYPE portNum, /*!< The port number*/
            FwChanIdType id, /*!< Telemetry Channel ID*/
            Fw::Time &timeTag, /*!< Time Tag*/
            Fw::TlmBuffer &val /*!< Buffer containing serialized telemetry value*/
        );
  
        //! Static function for port from_Time
        //!
        static void from_Time_static(
            Fw::PassiveComponentBase *const callComp, /*!< The component instance*/
            const NATIVE_INT_TYPE portNum, /*!< The port number*/
            Fw::Time &time /*!< The U32 cmd argument*/
        );
  
        //! Static function for port from_Log
        //!
        static void from_Log_static(
            Fw::PassiveComponentBase *const callComp, /*!< The component instance*/
            const NATIVE_INT_TYPE portNum, /*!< The port number*/
            FwEventIdType id, /*!< Log ID*/
            Fw::Time &timeTag, /*!< Time Tag*/
            Fw::LogSeverity severity, /*!< The severity argument*/
            Fw::LogBuffer &args /*!< Buffer containing serialized log entry*/
        );
  
  #if FW_ENABLE_TEXT_LOGGING == 1
        //! Static function for port from_LogText
        //!
        static void from_LogText_static(
            Fw::PassiveComponentBase *const callComp, /*!< The component instance*/
            const NATIVE_INT_TYPE portNum, /*!< The port number*/
            FwEventIdType id, /*!< Log ID*/
            Fw::Time &timeTag, /*!< Time Tag*/
            Fw::TextLogSeverity severity, /*!< The severity argument*/
            Fw::TextLogString &text /*!< Text of log message*/
        );
  #endif
  
      private:
  
        // ----------------------------------------------------------------------
        // Test time
        // ----------------------------------------------------------------------
  
        //! Test time stamp
        //!
        Fw::Time m_testTime;
  
    };
  
  } // end namespace SnapdragonFlight
  
  #endif
  