-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Expose VEXos' time and date functions #127
Conversation
I think there are some newlib stubs we can implement while we're at it. The added bonus is that functions like The function is
should be straightforward math to convert year/month/day/hours/minutes to seconds since Won't be able to get microsecond precision, only millisecond precision but that's 🆗 |
Are you saying this in addition to the "raw" passthrough functions to vexOS? Or instead of those? |
Read back through the SDK documentation a bit ago and discovered that these functions have not been implemented in the SDK yet, and there's no real indication of when they will be implemented. Not sure if/when that will happen, so there won't be any more progress with this PR until then. |
257296d
to
42c44df
Compare
Instead of
We'd want to just handle Why How would |
Is it possible to implement the newlib stubs without an RTC of any sort on the brain? Last I heard, there isn't the hardware to support time and date functions... |
There are a lot of times where the brain wouldn't have power, so any clock with a non-local frame of reference can't really be implemented. The ones alex was talking about can just be the output of a timer we get from VexOS, since they only care about the time period. |
Yeah, like Nathan said: Linux and friends also provide ways to get system time since boot in milliseconds (that's the CLOCK_MONOTONIC thing or std::chrono::steady_clock), and the other two I mentioned are computed by the scheduler. Also if we want to go for POSIX compliance too, there are symbols we can define |
int _gettimeofday(struct timeval* tp, void* tzvp) { | ||
if (competition_is_connected()) { | ||
tp->tv_sec = vexSystemTimeGet() * 1000; | ||
tp->tv_usec = vexSystemHighResTimeGet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly the times in its current form are probably atomic enough given he's getting the seconds and then the microseconds.
Hi, I'm from Raider Robotics, and I'm working on a port of micro-ROS to the V5 Brain that I hope to release in the near future. micro-ROS has a dependency on #include <sys/time.h>
#include "api.h"
int clock_gettime(clockid_t unused, struct timespec *tp)
{
(void)unused;
uint64_t m = micros();
tp->tv_sec = m / 1000000;
tp->tv_nsec = (m % 1000000) * 1000;
return 0;
} Currently, I believe this PR will cause micro-ROS to crash, as calling I'm really excited to see that Thanks! |
Hi MSOE, Thanks for the heads up, I'm willing to delay this until 3.7.1 to get CLOCK_MONOTONIC. Glad to see you guys on here and checking in w/ development. Keep in touch on the midwest discord! -Will |
int _gettimeofday(struct timeval* tp, void* tzvp) { | ||
if (competition_is_connected()) { | ||
tp->tv_sec = vexSystemTimeGet() * 1000; | ||
tp->tv_usec = vexSystemHighResTimeGet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, the bigger issue is that tv_sec != tv_usec /1000 since the vex docs indicate that vexSystemHighResTimeGet comes from a timer. I'd personally just give msec precision here and tell users to call a monotonic timer if they need any more precision.
I added/fixed the things requested and tested it on real hardware:
|
* Expose VEXos' get time and date functions * wip: add clock_gettime impl * wip: fix errors with clock_gettime impl * wip: add _gettimeofday impl * Push code to build test for time implementation * Add integer timestamp to the generated timestamp info * Fix compile errors * Fix compile errors 2 * Change _PROS_COMPILE_TIMESTAMP_INT to be an actual integer * Test linking against _pros_ld_timestamp.o variables * Test linking against _pros_ld_timestamp.o variables 2 * Test linking against _pros_ld_timestamp.o variables 3 * Test linking against _pros_ld_timestamp.o variables 4 * Convert _PROS_COMPILE_TIMESTAMP_INT back into a string * Try using HOT_TABLE rather than the timestamp directly * Make _PROS_COMPILESTAMP_INT a weak symbol * Fix compiler error * Attempt to use functions to subvert linking issues * Try switching _PROS_COMPILE_TIMESTAMP_INT to an integer again * Revert back to hacky callback solution * Fix compile error * Fix compile error 2 * Fix compile error 3 * Fix compile error 4 * Fix? * Fix microsecond calculation * Account for timezones when generating _PROS_COMPILE_TIMESTAMP_INT * Fix formatting and accidental changes * Commit for applying template * Fix compilation errors and begin implementing clock_settime() * Update firmware * Update common.mk to allow POSIX functions in time.h * Add CLOCK_MONOTONIC to clock_gettime() * Add comment * Fix version Co-authored-by: Alex Brooke <akb.sbc@gmail.com> Co-authored-by: WillXuCodes <xu.z.william@gmail.com> Co-authored-by: Richard Stump <rnstump@purdue.edu>
Summary:
Adds functionality for retrieving the Date and Time stored in VEXos.
Motivation:
I'm working on setting up a logging utility for the BLRS robots and discovered that it would be helpful to set the log file's name as the current date and time to distinguish between the logs more easily.
Test Plan:
I printed the output from the functions and got 0:0:0 for time and 11/16/2016 for the date every time.