INFM HIL Interface
Interface between Artery simulation and DuTs
|
Handler between interface and simulation. Responsible for sending/receiving SimEvents to/from the simulation. More...
#include <SimComHandler.h>
Public Types | |
enum | connectorType { RESTDummyConnector , CANConnector , V2XConnector , Invalid_Connector } |
Public Member Functions | |
SimComHandler (SimToDuTInterface *interface, const SystemConfig &config) | |
~SimComHandler () | |
void | sendEventToSim (const SimEvent &simEvent) |
void | receive () |
void | getConfig () |
connectorType | resolveConnectorTypeForSwitch (std::string connectorTypeS) |
void | run () |
void | unbindPublisher () |
void | disconnectSubscriber () |
void | disconnectReceiveConfig () |
void | close () |
Handler between interface and simulation. Responsible for sending/receiving SimEvents to/from the simulation.
connectorType: numeration for the various connectorType RESTDummyConnector CANConnector V2XConnector Invalid_Connector: If the configuration of a connector is invalid in the config.xml
sim_interface::SimComHandler::SimComHandler | ( | SimToDuTInterface * | interface, |
const SystemConfig & | config | ||
) |
Constructor: Create a new handler.
interface | A pointer to communicate with the interface. |
config | System configuration. socketSimPub_: Create socket for publishing messages to simulation socketSimSub_: Create socket for subscribing messages from simulation socketSimSubConfig_: Create socket for subscribing xml-configuration from simulation |
Configure sockets with the addresses from the config context_recConfig: Defines the context of the zmq socket for the xml-Configuration Set the sockets to subscriber sockets and listen to any String
Open connecting of the sockets: Start Logger for connecting the sockets Bind: Publisher sockets have to bind to the address Connect: Subscriber sockets have to connect
sim_interface::SimComHandler::~SimComHandler | ( | ) |
Unbinds, disconnects and closes the sockets Stops all threads and destroys the handler
void sim_interface::SimComHandler::close | ( | ) |
close all sockets
void sim_interface::SimComHandler::disconnectReceiveConfig | ( | ) |
disconnect the subscriber config socket --> from simulation
void sim_interface::SimComHandler::disconnectSubscriber | ( | ) |
disconnect the subscriber socket --> from simulation
void sim_interface::SimComHandler::getConfig | ( | ) |
replyConfig: zmq message, which contains serialized data from the xml-config Receive the serialized data from the xml-config with exception-handling If receiving is failed, unbind and disconnect the sockets Start logging bufConfig: Buffer with the serialized string from the xml-config tree: Property tree for deserialize the xml-config convertedSimConfigBuffer: output stringstream for converting the buffer SimConfigString: convert the output stringstream to a string With these parameters parsing the XML into the property tree. If parsing is failed, unbind and disconnect the sockets Start logging
connectorTypes: create String for copmaring the names of the connectortypes xmlWriterSettings: preparing an xml writer with property tree
for each loop: run through each value type in a xml-file and get every value in connectors tags save the classtype of the xml attribute into the connectorTypes string for comparing compare the connector types with the enumeration
The principle of the deserializing for the three connector are working very similar Exception handling and logging The principle will be explained with RESTDummyConnector: restXMLStringStream: stringstream for writing the xml file writing the xml file with these parameters restXMLString: Convert the stringstream to a string replace not needed tags in the xml-file to make it shorter restConnectorConfig: Create Pointer from type RESTConnectorConfig xmliStringStream: Convert the string to a input stringstream for deserialization Deserialize the received RESTDummyConnector from xml-config Create RestConnector object and put it in the queue of the DuTToSim Add it to the interface
Start logging: shows message which connectors were created
void sim_interface::SimComHandler::receive | ( | ) |
Starts the handler to asynchronously receive incoming events. while loop: ends, if the thread was stopped replySimData: zmq message, which contains serialized data from the simulation Receive the serialized simulation data e.g. Speed with exception-handling If receiving is failed, unbind and disconnect the sockets Start logging bufSimData: Buffer with the serialized string inputSimData: Convert the buffer into a string archiveStreamSimData: for writing the inputSimData archiveSimData: input text archive for writing the inputSimData stringstream receiveMapSimData: variable map with operations and value e.g. speed 13.05 writing the archive into the map with exception handling start logging, if writing failed for each loop: run through element from the receiveMapSimData create for each key and value an event Send the Simulation Event to the Interface
connectorType sim_interface::SimComHandler::resolveConnectorTypeForSwitch | ( | std::string | connectorTypeS | ) |
function for checking the various connector types in the config file
connectorTypeS | String for comparing the name of the connector types in the config.xml |
void sim_interface::SimComHandler::run | ( | ) |
starts the receive method in a own thread
void sim_interface::SimComHandler::sendEventToSim | ( | const SimEvent & | simEvent | ) |
Asynchronous sending of events to simulation.
simEvent | An event that should be sent to the simulation. logSimEvent: For Logging the SimEvents simEventMap: A variable Map for events to the Simulation adding keys and values to the simEventMap simEventsStringStream: output stringstream for publishing archiveSimEvent: put the stringstream into the output text archive write the Map to the archive simEventData: Convert simEventsStringStream into a string msgToSend: preparing zmq:message type for publishing Send message via socket and start logger for event |
void sim_interface::SimComHandler::unbindPublisher | ( | ) |
unbind the publisher socket --> to simulation