Files
openpilot-evo/panda/drivers/windows/pandaJ2534DLL/MessageTxTimeout.cpp
T
Vehicle Researcher 6c702630ac Merge commit '9b8e11b10c8e13193eeb95c5f94ab4bf3f021980' as 'panda'
old-commit-hash: 14fb17e22fe4020a46b7be8ef486dddb5210ef08
2017-12-23 17:10:42 -08:00

44 lines
1.3 KiB
C++

#include "stdafx.h"
#include "J2534Connection.h"
#include "MessageTxTimeout.h"
MessageTxTimeoutable::MessageTxTimeoutable(
std::weak_ptr<J2534Connection> connection,
PASSTHRU_MSG& to_send
) : MessageTx(connection, to_send), recvCount(0) { };
void MessageTxTimeoutable::scheduleTimeout(std::chrono::microseconds timeoutus) {
if (auto conn_sp = this->connection.lock()) {
if (auto panda_dev_sp = conn_sp->getPandaDev()) {
auto timeoutobj = std::make_shared<MessageTxTimeout>(std::static_pointer_cast<MessageTxTimeoutable>(shared_from_this()), timeoutus);
panda_dev_sp->scheduleAction(std::static_pointer_cast<Action>(timeoutobj), TRUE);
}
}
}
void MessageTxTimeoutable::scheduleTimeout(unsigned long timeoutus) {
scheduleTimeout(std::chrono::microseconds(timeoutus));
}
MessageTxTimeout::MessageTxTimeout(
std::shared_ptr<MessageTxTimeoutable> msg,
std::chrono::microseconds timeout
) : Action(msg->connection), msg(msg), lastRecvCount(msg->getRecvCount()) {
delay = timeout;
};
MessageTxTimeout::MessageTxTimeout(
std::shared_ptr<MessageTxTimeoutable> msg,
unsigned long timeout
) : MessageTxTimeout(msg, std::chrono::microseconds(timeout * 1000)) { };
void MessageTxTimeout::execute() {
if (auto msg_sp = this->msg.lock()) {
if (msg_sp->getRecvCount() == this->lastRecvCount) {
msg_sp->onTimeout();
}
}
}