I tried to recreate this with a simple little test_time program but it behaves as expected:
#include <stdio.h>
#include <time.h>
void main()
{
time_t t = time(NULL);
struct tm datetime = *localtime(&t);
printf("time:\n");
printf("%d-%d-%d_%d-%d-%d\n", datetime.tm_year+1900,datetime.tm_mon+1, datetime.tm_mday,datetime.tm_hour,datetime.tm_min,datetime.tm_sec);
printf("DONE\n");
return;
}
the result of starting this manually and from a systemd service is the same.
Aug 03 17:52:43 apq8096 systemd[1]: Starting test_time...
Aug 03 17:52:44 apq8096 systemd[1]: Started test_time.
Aug 03 17:52:44 apq8096 test_time[4238]: time:
Aug 03 17:52:44 apq8096 test_time[4238]: 2021-8-3_17-52-44
Aug 03 17:52:44 apq8096 test_time[4238]: DONE
Note that if you run this on boot then it will likely run before establishing an internet connection and fetching a date and time from either GPS or an NTP server. VOXL will not remember the date and time between reboots.
Also, modifying VVPX4 to log VIO data is an unnecessarily difficult way of going about this. It's also unsafe to write to a file in the same flight-critical thread that's sending PX4 high-rate commands. There is a tool called voxl-logger that likely does what you need, and would be safer to modify to do what you need than messing with VVPX4.
yocto:/etc/systemd/system$ voxl-logger -h
Tool to save data published through Modal Pipe Architecture to disk.
By default, this saves images to /data/voxl-logger/ since the /data/ parition is
the largest partition on VOXL. You can change this with the -d argument.
-c, --cam {name} name of a camera to log, e.g. tracking
-d, --directory {dir} name of the directory to save the log to, default
is /data/voxl-logger/ if argument is not provided.
-i, --imu {name} name of an imu to log, e.g. imu1.
-k, --skip {n_to_skip} number of samples to skip between logged samples
-h, --help print this help message
-n, --note {note} optionally add a very short note to the end of the log
directory name, e.g. flight_with_new_motors
-o, --preset_odometry record a preset log containing qvio, tracking cam and both
IMUs for testing VIO. This can be used with other pipes.
-s, --samples {samples} maximum samples to save for one specific channel,
otherwise it will run untill you quit the program.
-t, --time {seconds} time to log for in seconds.
-v, --vio {name} name of a vio pipe to log, e.g. qvio
-z, --debug enable verbose debug mode
typical uses:
To log one camera image:
yocto:/# voxl-logger --cam tracking --samples 1
To log 5000 imu samples:
yocto:/# voxl-logger -i imu1 -s 5000 --note "primary imu test"
To log 1000 imu0 samples and 2000 imu1 samples:
yocto:/# voxl-logger -i imu0 -s 1000 -i imu1 -s 2000
To log every 5th imu sample (skip 4) for 5.5 seconds:
yocto:/# voxl-logger -i imu1 --skip 4 -t 5.5
To log tracking camera and both imus until you press ctrl-c
yocto:/# voxl-logger --preset_odometry
To record a typical log for testing VIO (imu + tracking) for 1 minute
yocto:/# voxl-logger --preset_odometry --time 60 --note "log for vio replay test 1"
Here is the source code if you are curious, but it is installed by default as part of voxl-suite so you can use it out of the box. Note, we haven't used this tool in a while so if you find a bug/regression please let us know.
https://gitlab.com/voxl-public/modal-pipe-architecture/voxl-mpa-tools/-/blob/master/tools/voxl-logger.cpp
Best,
James