obu-firmware builds against the vanetza-idf C-ITS library, which until now came from the colleague's microbu-esp32c5 tree beside the repository and was not tracked here, so a clone of this repository could not build the firmware it ships. The library alone is now part of obu-firmware, as obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from there by default; -DVANETZA_IDF_DIR still points the build elsewhere. The rest of the colleague's tree (their own VAM firmware, PKI tooling, station-link Python tools, the V2X2MAP bridge) stays out of this repository and gitignored; nothing is pushed to their repository. NOTES.md, docs/06, TODO.md and the pcap verifier's usage line point at the new location.
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#include "time_trigger.hpp"
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
#include <iostream>
|
|
#include <functional>
|
|
|
|
namespace asio = boost::asio;
|
|
namespace posix_time = boost::posix_time;
|
|
using namespace vanetza;
|
|
|
|
TimeTrigger::TimeTrigger(asio::io_context& io_context) :
|
|
io_context_(io_context), timer_(io_context), runtime_(Clock::at(now()))
|
|
{
|
|
std::cout << "Starting runtime at " << now() <<"\n";
|
|
schedule();
|
|
}
|
|
|
|
posix_time::ptime TimeTrigger::now() const
|
|
{
|
|
return posix_time::microsec_clock::universal_time();
|
|
}
|
|
|
|
void TimeTrigger::schedule()
|
|
{
|
|
update_runtime();
|
|
auto next = runtime_.next();
|
|
if (next < Clock::time_point::max()) {
|
|
auto timeout = next - runtime_.now();
|
|
timer_.expires_after(timeout);
|
|
timer_.async_wait(std::bind(&TimeTrigger::on_timeout, this, std::placeholders::_1));
|
|
} else {
|
|
timer_.cancel();
|
|
}
|
|
}
|
|
|
|
void TimeTrigger::on_timeout(const boost::system::error_code& ec)
|
|
{
|
|
if (asio::error::operation_aborted != ec) {
|
|
schedule();
|
|
}
|
|
}
|
|
|
|
void TimeTrigger::update_runtime()
|
|
{
|
|
auto current_time = now();
|
|
runtime_.trigger(Clock::at(current_time));
|
|
}
|