obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but that tree was gitignored, so a clone of this repository could not build the firmware it ships. It is now committed here as ordinary files in its own folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP bridge's signature verification (--trust) used on the bench. Nothing is fetched from or pushed to the colleague's repository; this repository and its remotes carry everything. The folder's own .gitignore keeps build output, downloaded components and private key material out, as it did there; the committed file set is identical to that repository's tracked files. The ESP32-C5 is still flashed from obu-firmware/, which only takes vanetza-idf from microbu-esp32c5/, so the two stay separate folders. FLASHING.md says how to take a newer version of the colleague's tree (copy it over the folder, rebuild, test, commit).
72 lines
1.4 KiB
C++
72 lines
1.4 KiB
C++
#include "vanetza/rpc/asio_event_port.hpp"
|
|
|
|
#include <boost/asio/post.hpp>
|
|
#include <chrono>
|
|
|
|
namespace vanetza
|
|
{
|
|
namespace rpc
|
|
{
|
|
|
|
AsioEventPort::AsioEventPort(boost::asio::io_context& io) :
|
|
io_(io),
|
|
steady_timer_(io_),
|
|
clock_(kj::systemPreciseMonotonicClock()),
|
|
timer_(clock_.now())
|
|
{
|
|
}
|
|
|
|
bool AsioEventPort::wait()
|
|
{
|
|
io_.run_one();
|
|
advanceTime();
|
|
armTimeout();
|
|
return false;
|
|
}
|
|
|
|
bool AsioEventPort::poll()
|
|
{
|
|
io_.poll();
|
|
advanceTime();
|
|
armTimeout();
|
|
return false;
|
|
}
|
|
|
|
void AsioEventPort::setRunnable(bool runnable)
|
|
{
|
|
if (runnable) {
|
|
boost::asio::post(io_, [this]() {
|
|
auto* loop = loop_.load(std::memory_order_acquire);
|
|
if (loop && loop->isRunnable()) {
|
|
loop->run();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
void AsioEventPort::advanceTime()
|
|
{
|
|
timer_.advanceTo(clock_.now());
|
|
}
|
|
|
|
void AsioEventPort::armTimeout()
|
|
{
|
|
std::chrono::nanoseconds dt {
|
|
timer_.timeoutToNextEvent(clock_.now(), kj::NANOSECONDS, kj::maxValue)
|
|
.map([](uint64_t ns) { return ns; })
|
|
.orDefault(0)
|
|
};
|
|
if (dt > std::chrono::nanoseconds::zero()) {
|
|
steady_timer_.expires_after(dt);
|
|
steady_timer_.async_wait([this](const boost::system::error_code& ec) {
|
|
if (!ec) {
|
|
advanceTime();
|
|
armTimeout();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
} // namespace rpc
|
|
} // namespace vanetza
|