From b5ebdb8e41333bda1ef1d4e85f4f9e802cc375cd Mon Sep 17 00:00:00 2001 From: Tanja Baumann Date: Sat, 26 Sep 2020 19:09:01 +0200 Subject: [PATCH] add system command to get and set system time * add system_time command for all boards --- boards/aerotenna/ocpoc/default.cmake | 1 + boards/airmind/mindpx-v2/default.cmake | 1 + boards/atlflight/eagle/default.cmake | 1 + boards/atlflight/excelsior/default.cmake | 1 + boards/av/x-v1/default.cmake | 1 + boards/beaglebone/blue/default.cmake | 1 + boards/bitcraze/crazyflie/default.cmake | 1 + boards/cuav/nora/default.cmake | 1 + boards/cuav/x7pro/default.cmake | 1 + boards/emlid/navio2/default.cmake | 1 + boards/holybro/durandal-v1/default.cmake | 1 + boards/holybro/durandal-v1/stackcheck.cmake | 1 + boards/holybro/pix32v5/default.cmake | 1 + boards/intel/aerofc-v1/default.cmake | 1 + boards/intel/aerofc-v1/rtps.cmake | 1 + boards/modalai/fc-v1/default.cmake | 1 + boards/mro/ctrl-zero-f7/default.cmake | 1 + boards/mro/x21-777/default.cmake | 1 + boards/mro/x21/default.cmake | 1 + boards/nxp/fmuk66-e/default.cmake | 1 + boards/nxp/fmuk66-e/socketcan.cmake | 1 + boards/nxp/fmuk66-v3/default.cmake | 1 + boards/nxp/fmuk66-v3/rtps.cmake | 1 + boards/nxp/fmuk66-v3/socketcan.cmake | 1 + boards/nxp/fmurt1062-v1/default.cmake | 1 + boards/nxp/rddrone-uavcan146/default.cmake | 1 + boards/px4/fmu-v3/default.cmake | 1 + boards/px4/fmu-v3/rtps.cmake | 1 + boards/px4/fmu-v3/stackcheck.cmake | 1 + boards/px4/fmu-v4/cannode.cmake | 1 + boards/px4/fmu-v4/default.cmake | 1 + boards/px4/fmu-v4/optimized.cmake | 1 + boards/px4/fmu-v4/rtps.cmake | 1 + boards/px4/fmu-v4/stackcheck.cmake | 1 + boards/px4/fmu-v4pro/default.cmake | 1 + boards/px4/fmu-v4pro/rtps.cmake | 1 + boards/px4/fmu-v5/critmonitor.cmake | 1 + boards/px4/fmu-v5/debug.cmake | 1 + boards/px4/fmu-v5/default.cmake | 1 + boards/px4/fmu-v5/fixedwing.cmake | 1 + boards/px4/fmu-v5/irqmonitor.cmake | 1 + boards/px4/fmu-v5/multicopter.cmake | 1 + boards/px4/fmu-v5/optimized.cmake | 1 + boards/px4/fmu-v5/rover.cmake | 1 + boards/px4/fmu-v5/rtps.cmake | 1 + boards/px4/fmu-v5/stackcheck.cmake | 1 + boards/px4/fmu-v5x/base_phy_DP83848C.cmake | 1 + boards/px4/fmu-v5x/default.cmake | 1 + boards/px4/fmu-v6x/default.cmake | 1 + boards/px4/fmu-v6x/stackcheck.cmake | 1 + boards/px4/raspberrypi/default.cmake | 1 + boards/px4/sitl/default.cmake | 1 + boards/px4/sitl/nolockstep.cmake | 1 + boards/px4/sitl/rtps.cmake | 1 + boards/px4/sitl/test.cmake | 1 + boards/uvify/core/default.cmake | 1 + src/systemcmds/system_time/CMakeLists.txt | 39 ++++++ src/systemcmds/system_time/system_time.cpp | 127 ++++++++++++++++++++ 58 files changed, 222 insertions(+) create mode 100644 src/systemcmds/system_time/CMakeLists.txt create mode 100644 src/systemcmds/system_time/system_time.cpp diff --git a/boards/aerotenna/ocpoc/default.cmake b/boards/aerotenna/ocpoc/default.cmake index 6c05358a67..fbedfc2307 100644 --- a/boards/aerotenna/ocpoc/default.cmake +++ b/boards/aerotenna/ocpoc/default.cmake @@ -76,6 +76,7 @@ px4_add_board( perf pwm sd_bench + system_time shutdown tests # tests and test runner #top diff --git a/boards/airmind/mindpx-v2/default.cmake b/boards/airmind/mindpx-v2/default.cmake index 0341f5bf91..9814a4ed74 100644 --- a/boards/airmind/mindpx-v2/default.cmake +++ b/boards/airmind/mindpx-v2/default.cmake @@ -98,6 +98,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/atlflight/eagle/default.cmake b/boards/atlflight/eagle/default.cmake index 013df7e60d..777f863dc3 100644 --- a/boards/atlflight/eagle/default.cmake +++ b/boards/atlflight/eagle/default.cmake @@ -104,6 +104,7 @@ px4_add_board( pwm sd_bench shutdown + system_time #tests # tests and test runner #top topic_listener diff --git a/boards/atlflight/excelsior/default.cmake b/boards/atlflight/excelsior/default.cmake index 8091e611b3..e299119c36 100644 --- a/boards/atlflight/excelsior/default.cmake +++ b/boards/atlflight/excelsior/default.cmake @@ -102,6 +102,7 @@ px4_add_board( pwm sd_bench shutdown + system_time #tests # tests and test runner #top topic_listener diff --git a/boards/av/x-v1/default.cmake b/boards/av/x-v1/default.cmake index e0be6b8c4f..5e7747ba34 100644 --- a/boards/av/x-v1/default.cmake +++ b/boards/av/x-v1/default.cmake @@ -97,6 +97,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/beaglebone/blue/default.cmake b/boards/beaglebone/blue/default.cmake index 84088229e3..2331d8721d 100644 --- a/boards/beaglebone/blue/default.cmake +++ b/boards/beaglebone/blue/default.cmake @@ -73,6 +73,7 @@ px4_add_board( pwm sd_bench shutdown + system_time tests # tests and test runner #top topic_listener diff --git a/boards/bitcraze/crazyflie/default.cmake b/boards/bitcraze/crazyflie/default.cmake index bd6f7f6786..d779e0cae7 100644 --- a/boards/bitcraze/crazyflie/default.cmake +++ b/boards/bitcraze/crazyflie/default.cmake @@ -54,6 +54,7 @@ px4_add_board( reboot reflect sd_bench + system_time top topic_listener tune_control diff --git a/boards/cuav/nora/default.cmake b/boards/cuav/nora/default.cmake index b1356dd5a6..0faea69e8f 100644 --- a/boards/cuav/nora/default.cmake +++ b/boards/cuav/nora/default.cmake @@ -103,6 +103,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/cuav/x7pro/default.cmake b/boards/cuav/x7pro/default.cmake index 55b3ba1841..815071d6e9 100644 --- a/boards/cuav/x7pro/default.cmake +++ b/boards/cuav/x7pro/default.cmake @@ -106,6 +106,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/emlid/navio2/default.cmake b/boards/emlid/navio2/default.cmake index 496281d084..0b319eb392 100644 --- a/boards/emlid/navio2/default.cmake +++ b/boards/emlid/navio2/default.cmake @@ -72,6 +72,7 @@ px4_add_board( perf pwm sd_bench + system_time shutdown tests # tests and test runner #top diff --git a/boards/holybro/durandal-v1/default.cmake b/boards/holybro/durandal-v1/default.cmake index 8d78fc8df1..a049d2d35e 100644 --- a/boards/holybro/durandal-v1/default.cmake +++ b/boards/holybro/durandal-v1/default.cmake @@ -103,6 +103,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/holybro/durandal-v1/stackcheck.cmake b/boards/holybro/durandal-v1/stackcheck.cmake index 31d73b3024..60daf7c7b8 100644 --- a/boards/holybro/durandal-v1/stackcheck.cmake +++ b/boards/holybro/durandal-v1/stackcheck.cmake @@ -107,6 +107,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/holybro/pix32v5/default.cmake b/boards/holybro/pix32v5/default.cmake index aa83f941d4..3ceeeb7d16 100644 --- a/boards/holybro/pix32v5/default.cmake +++ b/boards/holybro/pix32v5/default.cmake @@ -111,6 +111,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/intel/aerofc-v1/default.cmake b/boards/intel/aerofc-v1/default.cmake index ec2574a73a..586653708f 100644 --- a/boards/intel/aerofc-v1/default.cmake +++ b/boards/intel/aerofc-v1/default.cmake @@ -79,6 +79,7 @@ px4_add_board( reboot reflect sd_bench + system_time #tests # tests and test runner top #topic_listener diff --git a/boards/intel/aerofc-v1/rtps.cmake b/boards/intel/aerofc-v1/rtps.cmake index a6b61a75f1..86893f003f 100644 --- a/boards/intel/aerofc-v1/rtps.cmake +++ b/boards/intel/aerofc-v1/rtps.cmake @@ -79,6 +79,7 @@ px4_add_board( reboot reflect sd_bench + system_time #tests # tests and test runner top #topic_listener diff --git a/boards/modalai/fc-v1/default.cmake b/boards/modalai/fc-v1/default.cmake index 69cfa3ad70..481d2472cd 100644 --- a/boards/modalai/fc-v1/default.cmake +++ b/boards/modalai/fc-v1/default.cmake @@ -97,6 +97,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/mro/ctrl-zero-f7/default.cmake b/boards/mro/ctrl-zero-f7/default.cmake index 84df969ad7..adfe04e9c0 100644 --- a/boards/mro/ctrl-zero-f7/default.cmake +++ b/boards/mro/ctrl-zero-f7/default.cmake @@ -103,6 +103,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/mro/x21-777/default.cmake b/boards/mro/x21-777/default.cmake index ee5f34f4ac..c22f6199bb 100644 --- a/boards/mro/x21-777/default.cmake +++ b/boards/mro/x21-777/default.cmake @@ -105,6 +105,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/mro/x21/default.cmake b/boards/mro/x21/default.cmake index d07ed40104..c48b8bee2c 100644 --- a/boards/mro/x21/default.cmake +++ b/boards/mro/x21/default.cmake @@ -100,6 +100,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/nxp/fmuk66-e/default.cmake b/boards/nxp/fmuk66-e/default.cmake index 4b0a3e6925..660c234ebd 100644 --- a/boards/nxp/fmuk66-e/default.cmake +++ b/boards/nxp/fmuk66-e/default.cmake @@ -98,6 +98,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/nxp/fmuk66-e/socketcan.cmake b/boards/nxp/fmuk66-e/socketcan.cmake index 9c3f56b775..544a180a36 100644 --- a/boards/nxp/fmuk66-e/socketcan.cmake +++ b/boards/nxp/fmuk66-e/socketcan.cmake @@ -98,6 +98,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/nxp/fmuk66-v3/default.cmake b/boards/nxp/fmuk66-v3/default.cmake index f4efcb24d7..09ed2399e0 100644 --- a/boards/nxp/fmuk66-v3/default.cmake +++ b/boards/nxp/fmuk66-v3/default.cmake @@ -98,6 +98,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/nxp/fmuk66-v3/rtps.cmake b/boards/nxp/fmuk66-v3/rtps.cmake index f005e9fdbb..e36aa42ca3 100644 --- a/boards/nxp/fmuk66-v3/rtps.cmake +++ b/boards/nxp/fmuk66-v3/rtps.cmake @@ -99,6 +99,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/nxp/fmuk66-v3/socketcan.cmake b/boards/nxp/fmuk66-v3/socketcan.cmake index 95eb123344..1f15284a47 100644 --- a/boards/nxp/fmuk66-v3/socketcan.cmake +++ b/boards/nxp/fmuk66-v3/socketcan.cmake @@ -98,6 +98,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/nxp/fmurt1062-v1/default.cmake b/boards/nxp/fmurt1062-v1/default.cmake index 453f1c7900..95bdb8395f 100644 --- a/boards/nxp/fmurt1062-v1/default.cmake +++ b/boards/nxp/fmurt1062-v1/default.cmake @@ -93,6 +93,7 @@ px4_add_board( reboot reflect sd_bench + system_time top topic_listener tune_control diff --git a/boards/nxp/rddrone-uavcan146/default.cmake b/boards/nxp/rddrone-uavcan146/default.cmake index c9a2bfdc43..5cc156a6c9 100644 --- a/boards/nxp/rddrone-uavcan146/default.cmake +++ b/boards/nxp/rddrone-uavcan146/default.cmake @@ -66,6 +66,7 @@ px4_add_board( reboot #reflect #sd_bench + system_time top #topic_listener #tune_control diff --git a/boards/px4/fmu-v3/default.cmake b/boards/px4/fmu-v3/default.cmake index d1668699ee..78a4cb667f 100644 --- a/boards/px4/fmu-v3/default.cmake +++ b/boards/px4/fmu-v3/default.cmake @@ -112,6 +112,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v3/rtps.cmake b/boards/px4/fmu-v3/rtps.cmake index 4584c10eba..241afc0d34 100644 --- a/boards/px4/fmu-v3/rtps.cmake +++ b/boards/px4/fmu-v3/rtps.cmake @@ -109,6 +109,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v3/stackcheck.cmake b/boards/px4/fmu-v3/stackcheck.cmake index 691ed0c14c..2fd123e4a1 100644 --- a/boards/px4/fmu-v3/stackcheck.cmake +++ b/boards/px4/fmu-v3/stackcheck.cmake @@ -104,6 +104,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v4/cannode.cmake b/boards/px4/fmu-v4/cannode.cmake index 589cd173da..ad0d78033e 100644 --- a/boards/px4/fmu-v4/cannode.cmake +++ b/boards/px4/fmu-v4/cannode.cmake @@ -79,6 +79,7 @@ px4_add_board( reboot #reflect #sd_bench + system_time #shutdown top #topic_listener diff --git a/boards/px4/fmu-v4/default.cmake b/boards/px4/fmu-v4/default.cmake index e673d16591..743bae159d 100644 --- a/boards/px4/fmu-v4/default.cmake +++ b/boards/px4/fmu-v4/default.cmake @@ -107,6 +107,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v4/optimized.cmake b/boards/px4/fmu-v4/optimized.cmake index eafe639800..01aa18ad5a 100644 --- a/boards/px4/fmu-v4/optimized.cmake +++ b/boards/px4/fmu-v4/optimized.cmake @@ -104,6 +104,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v4/rtps.cmake b/boards/px4/fmu-v4/rtps.cmake index cf364674be..0a0268b194 100644 --- a/boards/px4/fmu-v4/rtps.cmake +++ b/boards/px4/fmu-v4/rtps.cmake @@ -104,6 +104,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v4/stackcheck.cmake b/boards/px4/fmu-v4/stackcheck.cmake index 443a293992..a62f74615c 100644 --- a/boards/px4/fmu-v4/stackcheck.cmake +++ b/boards/px4/fmu-v4/stackcheck.cmake @@ -104,6 +104,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v4pro/default.cmake b/boards/px4/fmu-v4pro/default.cmake index e077ee3abe..e1c3002be2 100644 --- a/boards/px4/fmu-v4pro/default.cmake +++ b/boards/px4/fmu-v4pro/default.cmake @@ -105,6 +105,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v4pro/rtps.cmake b/boards/px4/fmu-v4pro/rtps.cmake index 31767457d1..b2f60bc9a5 100644 --- a/boards/px4/fmu-v4pro/rtps.cmake +++ b/boards/px4/fmu-v4pro/rtps.cmake @@ -103,6 +103,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v5/critmonitor.cmake b/boards/px4/fmu-v5/critmonitor.cmake index 18b0910090..173740450c 100644 --- a/boards/px4/fmu-v5/critmonitor.cmake +++ b/boards/px4/fmu-v5/critmonitor.cmake @@ -107,6 +107,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v5/debug.cmake b/boards/px4/fmu-v5/debug.cmake index 3f5f1b3966..8d827883fe 100644 --- a/boards/px4/fmu-v5/debug.cmake +++ b/boards/px4/fmu-v5/debug.cmake @@ -111,6 +111,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v5/default.cmake b/boards/px4/fmu-v5/default.cmake index d3ceb4a54b..19d3d9ff39 100644 --- a/boards/px4/fmu-v5/default.cmake +++ b/boards/px4/fmu-v5/default.cmake @@ -111,6 +111,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v5/fixedwing.cmake b/boards/px4/fmu-v5/fixedwing.cmake index 079c1c3d72..71d42e7702 100644 --- a/boards/px4/fmu-v5/fixedwing.cmake +++ b/boards/px4/fmu-v5/fixedwing.cmake @@ -82,6 +82,7 @@ px4_add_board( reboot reflect sd_bench + system_time top topic_listener tune_control diff --git a/boards/px4/fmu-v5/irqmonitor.cmake b/boards/px4/fmu-v5/irqmonitor.cmake index 95d49ec590..ea60335d56 100644 --- a/boards/px4/fmu-v5/irqmonitor.cmake +++ b/boards/px4/fmu-v5/irqmonitor.cmake @@ -108,6 +108,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v5/multicopter.cmake b/boards/px4/fmu-v5/multicopter.cmake index 850223af14..37e266a095 100644 --- a/boards/px4/fmu-v5/multicopter.cmake +++ b/boards/px4/fmu-v5/multicopter.cmake @@ -93,6 +93,7 @@ px4_add_board( reboot reflect sd_bench + system_time top topic_listener tune_control diff --git a/boards/px4/fmu-v5/optimized.cmake b/boards/px4/fmu-v5/optimized.cmake index 723e537b11..95c71fe110 100644 --- a/boards/px4/fmu-v5/optimized.cmake +++ b/boards/px4/fmu-v5/optimized.cmake @@ -104,6 +104,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v5/rover.cmake b/boards/px4/fmu-v5/rover.cmake index f96ea900f9..0c4b6b6868 100644 --- a/boards/px4/fmu-v5/rover.cmake +++ b/boards/px4/fmu-v5/rover.cmake @@ -82,6 +82,7 @@ px4_add_board( reboot reflect sd_bench + system_time top topic_listener tune_control diff --git a/boards/px4/fmu-v5/rtps.cmake b/boards/px4/fmu-v5/rtps.cmake index 04e66f1934..bdb56b5a8e 100644 --- a/boards/px4/fmu-v5/rtps.cmake +++ b/boards/px4/fmu-v5/rtps.cmake @@ -108,6 +108,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v5/stackcheck.cmake b/boards/px4/fmu-v5/stackcheck.cmake index 8009783856..4b31d0c0e3 100644 --- a/boards/px4/fmu-v5/stackcheck.cmake +++ b/boards/px4/fmu-v5/stackcheck.cmake @@ -111,6 +111,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v5x/base_phy_DP83848C.cmake b/boards/px4/fmu-v5x/base_phy_DP83848C.cmake index 7c032b4647..59954ca068 100644 --- a/boards/px4/fmu-v5x/base_phy_DP83848C.cmake +++ b/boards/px4/fmu-v5x/base_phy_DP83848C.cmake @@ -106,6 +106,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v5x/default.cmake b/boards/px4/fmu-v5x/default.cmake index 6ff61f13bc..84ee93a475 100644 --- a/boards/px4/fmu-v5x/default.cmake +++ b/boards/px4/fmu-v5x/default.cmake @@ -109,6 +109,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v6x/default.cmake b/boards/px4/fmu-v6x/default.cmake index a0ba89b333..706c214383 100644 --- a/boards/px4/fmu-v6x/default.cmake +++ b/boards/px4/fmu-v6x/default.cmake @@ -109,6 +109,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/fmu-v6x/stackcheck.cmake b/boards/px4/fmu-v6x/stackcheck.cmake index a0ba89b333..706c214383 100644 --- a/boards/px4/fmu-v6x/stackcheck.cmake +++ b/boards/px4/fmu-v6x/stackcheck.cmake @@ -109,6 +109,7 @@ px4_add_board( reboot reflect sd_bench + system_time tests # tests and test runner top topic_listener diff --git a/boards/px4/raspberrypi/default.cmake b/boards/px4/raspberrypi/default.cmake index 061fdd446b..46f93e8c1f 100644 --- a/boards/px4/raspberrypi/default.cmake +++ b/boards/px4/raspberrypi/default.cmake @@ -72,6 +72,7 @@ px4_add_board( perf pwm sd_bench + system_time shutdown tests # tests and test runner #top diff --git a/boards/px4/sitl/default.cmake b/boards/px4/sitl/default.cmake index afb55ce5ce..ea4664dcd7 100644 --- a/boards/px4/sitl/default.cmake +++ b/boards/px4/sitl/default.cmake @@ -72,6 +72,7 @@ px4_add_board( pwm sd_bench shutdown + system_time tests # tests and test runner #top topic_listener diff --git a/boards/px4/sitl/nolockstep.cmake b/boards/px4/sitl/nolockstep.cmake index 5942f2c1dc..0f38f318d4 100644 --- a/boards/px4/sitl/nolockstep.cmake +++ b/boards/px4/sitl/nolockstep.cmake @@ -72,6 +72,7 @@ px4_add_board( pwm sd_bench shutdown + system_time tests # tests and test runner #top topic_listener diff --git a/boards/px4/sitl/rtps.cmake b/boards/px4/sitl/rtps.cmake index 7d65372b0c..f6ef891267 100644 --- a/boards/px4/sitl/rtps.cmake +++ b/boards/px4/sitl/rtps.cmake @@ -71,6 +71,7 @@ px4_add_board( pwm sd_bench shutdown + system_time tests # tests and test runner #top topic_listener diff --git a/boards/px4/sitl/test.cmake b/boards/px4/sitl/test.cmake index 1e6f402a64..b33fed50e4 100644 --- a/boards/px4/sitl/test.cmake +++ b/boards/px4/sitl/test.cmake @@ -69,6 +69,7 @@ px4_add_board( pwm sd_bench shutdown + system_time tests # tests and test runner #top topic_listener diff --git a/boards/uvify/core/default.cmake b/boards/uvify/core/default.cmake index 8f3738422d..d73ab53a23 100644 --- a/boards/uvify/core/default.cmake +++ b/boards/uvify/core/default.cmake @@ -81,6 +81,7 @@ px4_add_board( reboot reflect sd_bench + system_time top topic_listener tune_control diff --git a/src/systemcmds/system_time/CMakeLists.txt b/src/systemcmds/system_time/CMakeLists.txt new file mode 100644 index 0000000000..edb2865f4e --- /dev/null +++ b/src/systemcmds/system_time/CMakeLists.txt @@ -0,0 +1,39 @@ +############################################################################ +# +# Copyright (c) 2020 PX4 Development Team. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name PX4 nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ +px4_add_module( + MODULE systemcmds__system_time + MAIN system_time + SRCS + system_time.cpp + DEPENDS + ) \ No newline at end of file diff --git a/src/systemcmds/system_time/system_time.cpp b/src/systemcmds/system_time/system_time.cpp new file mode 100644 index 0000000000..4d4b2d8feb --- /dev/null +++ b/src/systemcmds/system_time/system_time.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** + * + * Copyright (c) 2020 PX4 Development Team. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name PX4 nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#include +#include + +using namespace time_literals; + +static void usage(); + +extern "C" { + __EXPORT int system_time_main(int argc, char *argv[]); +} + +int +system_time_main(int argc, char *argv[]) +{ + if (argc >= 2) { + if (!strcmp(argv[1], "get")) { + //get system time + struct timespec ts = {}; + px4_clock_gettime(CLOCK_REALTIME, &ts); + time_t utc_time_sec = ts.tv_sec + (ts.tv_nsec / 1e9); + + //convert to date time + char buf[80]; + struct tm date_time; + localtime_r(&utc_time_sec, &date_time); + strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &date_time); + + //get time since boot + hrt_abstime since_boot_sec = hrt_absolute_time() / 1_s; + + PX4_INFO("Unix epoch time: %ld", (long)utc_time_sec); + PX4_INFO("System time: %s", buf); + PX4_INFO("Uptime (since boot): %" PRIu64 " s", since_boot_sec); + return 0; + } + + if (!strcmp(argv[1], "set")) { + if (argc == 3) { + //set system time + struct timespec ts = {}; + ts.tv_sec = (time_t)strtoul(argv[2], nullptr, 0); + ts.tv_nsec = 0.0; + + int res = px4_clock_settime(CLOCK_REALTIME, &ts); + + if (res == 0) { + PX4_INFO("Successfully set system time"); + return 0; + + } else { + PX4_ERR("Failed to set system time (%i)", res); + return 1; + } + + } else { + usage(); + return 1; + } + } + + //unknown command + PX4_ERR("system_time: Unknown subcommand"); + usage(); + return 1; + } + + //not enough arguments + PX4_ERR("system_time: not enough arguments"); + usage(); + return 1; +} + +static void +usage() +{ + + PRINT_MODULE_DESCRIPTION( + R"DESCR_STR( +### Description + +Command-line tool to set and get system time. + +### Examples + +Set the system time and read it back +$ system_time set 1600775044 +$ system_time get +)DESCR_STR"); + + PRINT_MODULE_USAGE_NAME("system_time", "command"); + PRINT_MODULE_USAGE_COMMAND_DESCR("set", "Set the system time, provide time in unix epoch time format"); + PRINT_MODULE_USAGE_COMMAND_DESCR("get", "Get the system time"); + +} \ No newline at end of file