45 tasks.push_back(std::make_shared<InterfaceQueued::PreStep>(*
this));
48 tasks.push_back(std::make_shared<InterfaceQueued::PostStep>(*
this));
54 if (timeStepCount % mIntf.mDownsampling == 0)
55 mIntf.popDpsimAttrsFromQueue();
59 if (timeStepCount % mIntf.mDownsampling == 0)
60 mIntf.pushDpsimAttrsToQueue();
88 [currentSequenceId, isSync](
auto attrTuple) {
89 auto &[_attr, seqId, blockOnRead, syncOnStart] =
92 return syncOnStart && seqId < currentSequenceId;
94 return blockOnRead && seqId < currentSequenceId;
102 SPDLOG_LOGGER_WARN(
mLog,
103 "Overrun detected! Discarding {} overrun packets!", i);
108 ->copyValue(receivedPacket.value)) {
110 mLog,
"Failed to copy received value onto attribute in Interface!");
113 receivedPacket.sequenceId;
120 ->copyValue(receivedPacket.value)) {
122 mLog,
"Failed to copy received value onto attribute in Interface!");
125 receivedPacket.sequenceId;
142 bool interfaceClosed =
false;
143 std::vector<InterfaceQueued::AttributePacket> attrsToWrite;
144 while (!interfaceClosed) {
149 mQueueDpsimToInterface->wait_dequeue(nextPacket);
151 interfaceClosed =
true;
153 attrsToWrite.push_back(nextPacket);
157 while (mQueueDpsimToInterface->try_dequeue(nextPacket)) {
159 interfaceClosed =
true;
161 attrsToWrite.push_back(nextPacket);
164 mInterfaceWorker->writeValuesToEnv(attrsToWrite);
169 std::vector<InterfaceQueued::AttributePacket> attrsRead;
171 mInterfaceWorker->readValuesFromEnv(attrsRead);
172 for (
const auto &packet : attrsRead) {
173 mQueueInterfaceToDpsim->enqueue(packet);
std::shared_ptr< spdlog::logger > Log
std::vector< std::tuple< CPS::AttributeBase::Ptr, UInt, bool, bool > > mImportAttrsDpsim
UInt mNextSequenceInterfaceToDpsim
std::atomic< bool > mOpened
UInt mCurrentSequenceDpsimToInterface
virtual void setLogger(CPS::Logger::Log log)
std::vector< std::tuple< CPS::AttributeBase::Ptr, UInt > > mExportAttrsDpsim
void execute(Real time, Int timeStepCount) override
void execute(Real time, Int timeStepCount) override
virtual void syncExports() override
std::shared_ptr< moodycamel::BlockingReaderWriterQueue< AttributePacket > > mQueueInterfaceToDpsim
std::shared_ptr< moodycamel::BlockingReaderWriterQueue< AttributePacket > > mQueueDpsimToInterface
virtual void open() override
virtual void setLogger(CPS::Logger::Log log) override
std::thread mInterfaceWriterThread
std::thread mInterfaceReaderThread
virtual void popDpsimAttrsFromQueue(bool isSync=false)
struct AttributePacket { CPS::AttributeBase::Ptr value; UInt attributeId; UInt sequenceId; unsigned char flags; } AttributePacket
virtual void close() override
virtual void syncImports() override
Function called by the Simulation to perform interface synchronization.
virtual CPS::Task::List getTasks() override
virtual void pushDpsimAttrsToQueue()
std::shared_ptr< InterfaceWorker > mInterfaceWorker