started cleanup up the socket mess
removed unused #include + dependency
more formatting fixes + fixed users of ReceiveSocket
cleaned more stuff up (converted from references to pointers is one)
wip. started rewriting everything, not quite finished
got everything except SensorOutput done (I think...)
got everything compiling except for missing SensorReceiver
worked on implementing the logic. didn't finish
made everything compile and finished implementing SensorReceiver
pulling over Austin's mock time stuff
added IncrementMockTime
finished up and started on tests
remembered something else
diff --git a/aos/common/time.h b/aos/common/time.h
index 1d7ccae..c081e09 100644
--- a/aos/common/time.h
+++ b/aos/common/time.h
@@ -60,6 +60,7 @@
return ans;
}
#endif // SWIG
+
// CLOCK_MONOTONIC on the fitpc and CLOCK_REALTIME on the cRIO because the
// cRIO doesn't have any others.
// CLOCK_REALTIME is the default realtime clock and CLOCK_MONOTONIC doesn't
@@ -113,6 +114,10 @@
int ToTicks() const {
return ToNSec() / static_cast<int64_t>(kNSecInSec / sysClkRateGet());
}
+ // Constructs a Time representing ticks.
+ static Time InTicks(int ticks) {
+ return Time::InSeconds(ticks * sysClkRateGet());
+ }
#endif
// Returns the time represented in milliseconds.
@@ -159,6 +164,25 @@
Check();
}
+ // Absolute value.
+ Time abs() const {
+ if (*this > Time(0, 0)) return *this;
+ return Time(-sec_ - 1, kNSecInSec - nsec_);
+ }
+
+ // Enables returning the mock time value for Now instead of checking the
+ // system clock. This should only be used when testing things depending on
+ // time, or many things may/will break.
+ static void EnableMockTime(const Time now);
+ // Sets now when time is being mocked.
+ static void SetMockTime(const Time now);
+ // Convenience function to just increment the mock time by a certain amount.
+ static void IncrementMockTime(const Time amount) {
+ SetMockTime(Now() + amount);
+ }
+ // Disables mocking time.
+ static void DisableMockTime();
+
private:
int32_t sec_, nsec_;
// LOG(FATAL)s if nsec_ is >= kNSecInSec.