INFM HIL Interface
Interface between Artery simulation and DuTs
SystemConfig.h
1
25#ifndef SIM_TO_DUT_INTERFACE_SYSTEMCONFIG_H
26#define SIM_TO_DUT_INTERFACE_SYSTEMCONFIG_H
27
28#include <boost/archive/xml_oarchive.hpp>
29#include <boost/archive/xml_iarchive.hpp>
30#include <fstream>
31#include "Interface_Logger/InterfaceLogger.h"
32
33namespace sim_interface {
41 public:
45 SystemConfig() = default;
46
54 std::string socketSimAddressSub = "tcp://localhost:7777";
58 std::string socketSimAddressPub = "tcp://*:7778";
59
60
64 std::string socketSimAddressReciverConfig = "tcp://localhost:7779";
65
72 static void saveToFile(const std::string &file, SystemConfig &systemConfig) {
73 try {
74 std::ofstream ofs(file);
75 boost::archive::xml_oarchive oa(ofs);
76 oa << BOOST_SERIALIZATION_NVP(systemConfig);
77 std::cout << "Successfully saved system config to <" << file << ">" << std::endl;
78 } catch (...) {
79 std::cout << "Save system config failed." << std::endl;
80 }
81 }
82
90 static void
91 loadFromFile(const std::string &file, SystemConfig &systemConfig, bool createNewIfNotFoundOrInvalid) {
92 try {
93 std::ifstream ifs(file);
94 boost::archive::xml_iarchive ia(ifs);
95 ia >> BOOST_SERIALIZATION_NVP(systemConfig);
96 std::cout << "Successfully loaded system config from <" << file << ">" << std::endl;
97 } catch (...) {
98 std::cout << "Load system config failed. Fallback to default values." << std::endl;
99 if (createNewIfNotFoundOrInvalid) {
100 sim_interface::SystemConfig::saveToFile(file, systemConfig);
101 }
102 }
103 }
104
105 private:
106 friend class boost::serialization::access;
107
108 template<class Archive>
109 void serialize(Archive &ar, const unsigned int version) {
110 ar & BOOST_SERIALIZATION_NVP(loggerConfig);
111 ar & BOOST_SERIALIZATION_NVP(socketSimAddressSub);
112 ar & BOOST_SERIALIZATION_NVP(socketSimAddressPub);
113 ar & BOOST_SERIALIZATION_NVP(socketSimAddressReciverConfig);
114 }
115 };
116}
117
118#endif //SIM_TO_DUT_INTERFACE_SYSTEMCONFIG_H
The logger needs a configuration before it can start logging.
Definition: InterfaceLoggerConfig.h:50
Contains the config for the SimComHandler, the SimToDuTInterface and the Logger.
Definition: SystemConfig.h:40
LoggerConfig loggerConfig
Definition: SystemConfig.h:50
std::string socketSimAddressPub
Definition: SystemConfig.h:58
std::string socketSimAddressSub
Definition: SystemConfig.h:54
static void loadFromFile(const std::string &file, SystemConfig &systemConfig, bool createNewIfNotFoundOrInvalid)
Definition: SystemConfig.h:91
static void saveToFile(const std::string &file, SystemConfig &systemConfig)
Definition: SystemConfig.h:72
std::string socketSimAddressReciverConfig
Definition: SystemConfig.h:64
void serialize(Archive &ar, sim_interface::dut_connector::ConnectorConfig &config, const unsigned int version)
Definition: ConfigSerializer.h:146
Definition: CANConnector.cpp:29