Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
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.
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
#include "timestamp.hpp"
|
||||
#include "vanetza/common/byte_order.hpp"
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <limits>
|
||||
|
||||
namespace vanetza
|
||||
{
|
||||
namespace geonet
|
||||
{
|
||||
|
||||
Timestamp::unit_type Timestamp::millisecond()
|
||||
{
|
||||
return Timestamp::unit_type();
|
||||
}
|
||||
|
||||
boost::posix_time::ptime Timestamp::start_time()
|
||||
{
|
||||
static const boost::posix_time::ptime start {
|
||||
boost::gregorian::date(2004, 1, 1),
|
||||
boost::posix_time::milliseconds(0)
|
||||
};
|
||||
return start;
|
||||
}
|
||||
|
||||
Timestamp::Timestamp(const Clock::time_point& time)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
const auto since_epoch = time.time_since_epoch();
|
||||
const auto since_epoch_ms = duration_cast<milliseconds>(since_epoch);
|
||||
m_timestamp = since_epoch_ms.count() * absolute_unit_type();
|
||||
}
|
||||
|
||||
Timestamp::Timestamp(const boost::posix_time::ptime& time)
|
||||
{
|
||||
assert(time >= start_time());
|
||||
const value_type since_start_ms = (time - start_time()).total_milliseconds();
|
||||
m_timestamp = since_start_ms * absolute_unit_type();
|
||||
}
|
||||
|
||||
Timestamp& Timestamp::operator+=(duration_type rhs)
|
||||
{
|
||||
m_timestamp += rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp& Timestamp::operator-=(duration_type rhs)
|
||||
{
|
||||
m_timestamp -= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp operator+(Timestamp lhs, Timestamp::duration_type rhs)
|
||||
{
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Timestamp operator-(Timestamp lhs, Timestamp::duration_type rhs)
|
||||
{
|
||||
lhs -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Timestamp::duration_type operator-(Timestamp lhs, Timestamp rhs)
|
||||
{
|
||||
return lhs.quantity() - rhs.quantity();
|
||||
}
|
||||
|
||||
bool Timestamp::before(const Timestamp& other) const
|
||||
{
|
||||
return *this < other;
|
||||
}
|
||||
|
||||
bool Timestamp::after(const Timestamp& other) const
|
||||
{
|
||||
return *this > other;
|
||||
}
|
||||
|
||||
bool is_greater(Timestamp lhs, Timestamp rhs)
|
||||
{
|
||||
const auto max = std::numeric_limits<Timestamp::value_type>::max();
|
||||
const Timestamp::value_type lhs_raw = lhs.raw();
|
||||
const Timestamp::value_type rhs_raw = rhs.raw();
|
||||
|
||||
if ((lhs_raw > rhs_raw && lhs_raw - rhs_raw <= max/2) ||
|
||||
(rhs_raw > lhs_raw && rhs_raw - lhs_raw > max/2)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool operator<(Timestamp lhs, Timestamp rhs)
|
||||
{
|
||||
return (!is_greater(lhs, rhs) && lhs != rhs);
|
||||
}
|
||||
|
||||
bool operator==(Timestamp lhs, Timestamp rhs)
|
||||
{
|
||||
return lhs.raw() == rhs.raw();
|
||||
}
|
||||
|
||||
void serialize(const Timestamp& ts, OutputArchive& ar)
|
||||
{
|
||||
serialize(host_cast(ts.raw()), ar);
|
||||
}
|
||||
|
||||
void deserialize(Timestamp& ts, InputArchive& ar)
|
||||
{
|
||||
Timestamp::value_type tmp;
|
||||
deserialize(tmp, ar);
|
||||
ts = Timestamp { Timestamp::time_type::from_value(tmp) };
|
||||
}
|
||||
|
||||
} // namespace geonet
|
||||
} // namespace vanetza
|
||||
|
||||
Reference in New Issue
Block a user