diff --git a/src/plugins/serialoutput/CMakeLists.txt b/src/plugins/serialoutput/CMakeLists.txt new file mode 100644 index 00000000..441b040f --- /dev/null +++ b/src/plugins/serialoutput/CMakeLists.txt @@ -0,0 +1,10 @@ +set(PLUGIN_NAME serialoutput) + +set(MY_PLUGIN_SRCS + SerialOutput.cc + SerialOutput.hpp +) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +## Build library +add_library(${PLUGIN_NAME} ${MY_PLUGIN_SRCS}) diff --git a/src/plugins/serialoutput/SerialOutput.cc b/src/plugins/serialoutput/SerialOutput.cc new file mode 100644 index 00000000..9fff8146 --- /dev/null +++ b/src/plugins/serialoutput/SerialOutput.cc @@ -0,0 +1,33 @@ +#include + +#include "SerialOutput.hpp" + +using namespace std; +using namespace fail; + +bool SerialOutput::run() +{ + IOPortListener ev_ioport(m_port, m_out); + BaseListener *ev; + while (true) { + simulator.addListener(&ev_ioport); + ev = simulator.resume(); + simulator.removeListener(&ev_ioport); + if (ev == &ev_ioport) { + m_output += ev_ioport.getData(); + } else { + break; + } + } + return true; +} + +void SerialOutput::resetOutput() +{ + m_output.clear(); +} + +string SerialOutput::getOutput() +{ + return m_output; +} diff --git a/src/plugins/serialoutput/SerialOutput.hpp b/src/plugins/serialoutput/SerialOutput.hpp new file mode 100644 index 00000000..6af327a8 --- /dev/null +++ b/src/plugins/serialoutput/SerialOutput.hpp @@ -0,0 +1,49 @@ +#ifndef __SERIAL_OUTPUT_HPP__ + #define __SERIAL_OUTPUT_HPP__ + +#include + +#include "efw/ExperimentFlow.hpp" +#include "config/FailConfig.hpp" + +// Check if configuration dependencies are satisfied: +#if !defined(CONFIG_EVENT_IOPORT) + #warning The serialoutput plugin may (depending on its use) need ioport event. Enable these in the cmake configuration tool. +#endif + +/** + * \class SerialOutput + * + * \brief Plugin to record ioport traffic. + */ +class SerialOutput : public fail::ExperimentFlow +{ + +private: + bool m_out; //!< Defines the direction of the listener. + unsigned m_port; //!< the port the listener is listening on + std::string m_output; //!< contains the traffic of ioport + +public: + /** + * Constructor of SerialOutput. + * + * @param port the port the listener is listening on + * @param out Defines the direction of the listener. + * \arg \c true Output on the given port is captured. + * \arg \c false Input on the given port is captured. + */ + SerialOutput(unsigned port, bool out) : m_out(out), m_port(port) { } + bool run(); + /** + * Resets the output variable which contains the traffic of + * ioport. + */ + void resetOutput(); + /** + * Returns the output variable. + */ + std::string getOutput(); +}; + +#endif // __SERIAL_OUTPUT_HPP__