diff --git a/include/flange/simulator_client.h b/include/flange/simulator_client.h index d3a32c079b800f67de63247a9feec9c6b381c253..74ad453ca53103f624a7ab825dc0f567bcedca78 100644 --- a/include/flange/simulator_client.h +++ b/include/flange/simulator_client.h @@ -30,6 +30,18 @@ public: */ SimulatorClient(ip_t ip, port_t port); + /** + * Create and start connection to simulation server. + * Automatically extract RCF port from environment, the simulation server is expected to run on + * the same host. + */ + SimulatorClient(); + + /** + * Copy constructor. + */ + SimulatorClient(SimulatorClient const& other); + /** * Close connection to simulator. */ diff --git a/include/hxcomm/common/simconnection.h b/include/hxcomm/common/simconnection.h index 60bb932c446cdbb79b39bdb3be94160cec87b9c4..a981ee001f4a9baa87bd3c1ee58d63b760715f10 100644 --- a/include/hxcomm/common/simconnection.h +++ b/include/hxcomm/common/simconnection.h @@ -56,6 +56,13 @@ public: */ SimConnection(ip_t ip, port_t port); + /** + * Create and start connection to simulation server. + * The RCF port is automatically extracted from the enviroment, the simulation server is + * expected to run on the same host. + */ + SimConnection(); + /** * Copy constructor (deleted because no two instances with the same simulator allocation can * coexist). @@ -177,7 +184,7 @@ private: constexpr static size_t receive_buffer_size = 100000; DoubleBuffer<Packet<subpacket_type, receive_buffer_size>> m_receive_buffer; - void work_fill_receive_buffer(ip_t ip, port_t port); + void work_fill_receive_buffer(); std::thread m_worker_fill_receive_buffer; void work_decode_messages(); diff --git a/include/hxcomm/common/simconnection.tcc b/include/hxcomm/common/simconnection.tcc index 5f49a2c81c58ad707bcf81bce99f2a0d4250884c..de3f5782d0f54e6ae7da7db5fd029b280e953956 100644 --- a/include/hxcomm/common/simconnection.tcc +++ b/include/hxcomm/common/simconnection.tcc @@ -14,7 +14,30 @@ SimConnection<ConnectionParameter>::SimConnection(ip_t ip, port_t port) : m_run_receive(true), m_receive_buffer(m_run_receive), m_worker_fill_receive_buffer( - &SimConnection<ConnectionParameter>::work_fill_receive_buffer, this, ip, port), + &SimConnection<ConnectionParameter>::work_fill_receive_buffer, this), + m_worker_decode_messages(&SimConnection<ConnectionParameter>::work_decode_messages, this), + m_runnable_mutex(), + m_terminate_on_destruction(false), + m_logger(log4cxx::Logger::getLogger("hxcomm.SimConnection")) +{ + HXCOMM_LOG_TRACE(m_logger, "SimConnection(): Sim connection started."); + + // reset synplify wrapper to align behavior to ARQ FPGA reset of ARQConnection. + m_sim.issue_reset(); +} + +template <typename ConnectionParameter> +SimConnection<ConnectionParameter>::SimConnection() : + m_sim(), + m_send_queue(), + m_encoder(m_send_queue), + m_receive_queue(), + m_listener_halt(), + m_decoder(m_receive_queue, m_listener_halt), + m_run_receive(true), + m_receive_buffer(m_run_receive), + m_worker_fill_receive_buffer( + &SimConnection<ConnectionParameter>::work_fill_receive_buffer, this), m_worker_decode_messages(&SimConnection<ConnectionParameter>::work_decode_messages, this), m_runnable_mutex(), m_terminate_on_destruction(false), @@ -85,9 +108,9 @@ bool SimConnection<ConnectionParameter>::try_receive(receive_message_type& messa } template <typename ConnectionParameter> -void SimConnection<ConnectionParameter>::work_fill_receive_buffer(ip_t ip, port_t port) +void SimConnection<ConnectionParameter>::work_fill_receive_buffer() { - thread_local decltype(m_sim) local_sim(ip, port); + thread_local decltype(m_sim) local_sim(m_sim); while (true) { auto const write_pointer = m_receive_buffer.start_write(); diff --git a/src/flange/simulator_client.cpp b/src/flange/simulator_client.cpp index 8d276164b931ed0e69fa2295361c03d9d0f0696a..fce0f051c0a1be100f5c28e32ddd902509710b68 100644 --- a/src/flange/simulator_client.cpp +++ b/src/flange/simulator_client.cpp @@ -21,6 +21,19 @@ struct SimulatorClient::Impl SimulatorClient::SimulatorClient(ip_t ip, port_t port) : m_impl(std::make_unique<Impl>(ip, port)) {} +SimulatorClient::SimulatorClient() : m_impl() +{ + char const* env_port = std::getenv("FLANGE_SIMULATION_RCF_PORT"); + if (env_port == nullptr) { + throw std::runtime_error("No port to simulator found in environment."); + } + m_impl = std::make_unique<Impl>("127.0.0.1", static_cast<port_t>(std::atoi(env_port))); +} + +SimulatorClient::SimulatorClient(SimulatorClient const& other) : + m_impl(std::make_unique<Impl>(*(other.m_impl))) +{} + SimulatorClient::~SimulatorClient() {} diff --git a/tests/hw/hxcomm/main.cpp b/tests/hw/hxcomm/main.cpp index ef34e435561cd6bf8955070e115c023fd83b8777..5b756d6a1afc64f31a16acdfdd4d7e99fd9118b0 100644 --- a/tests/hw/hxcomm/main.cpp +++ b/tests/hw/hxcomm/main.cpp @@ -7,18 +7,9 @@ // logger include directory structure omits prefix #include "logging_ctrl.h" -#ifndef HXCOMM_TEST_ARQ_CONNECTION -std::string simulation_ip; -unsigned int simulation_port; -#endif - TestConnection generate_test_connection() { -#ifdef HXCOMM_TEST_ARQ_CONNECTION return TestConnection(); -#else - return TestConnection(simulation_ip, simulation_port); -#endif } int main(int argc, char* argv[]) @@ -29,10 +20,6 @@ int main(int argc, char* argv[]) namespace bpo = boost::program_options; bpo::options_description desc("Options"); // clang-format off -#ifndef HXCOMM_TEST_ARQ_CONNECTION - desc.add_options()("simulation_ip", bpo::value<std::string>(&simulation_ip)->default_value("127.0.0.1")); - desc.add_options()("simulation_port", bpo::value<unsigned int>(&simulation_port)->required()); -#endif desc.add_options()("loglevel", bpo::value<std::string>(&loglevel)->default_value("trace")); // clang-format on