mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-22 00:33:44 +08:00
Squashed 'panda/' content from commit ae816c104
git-subtree-dir: panda git-subtree-split: ae816c104a99a8cd4d508ccd6abdc7b93053529c
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
#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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user