From 4921a3b0fdac759b56134868e74392b289706af4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 21 Jan 2022 17:09:21 +0300 Subject: [PATCH] arduino PISystemTime::current --- libs/main/core/pitime.cpp | 37 ++++++++++++++++++++++++++----- libs/main/core/pivarianttypes.cpp | 8 +++++-- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/libs/main/core/pitime.cpp b/libs/main/core/pitime.cpp index bca22117..7cc9123c 100644 --- a/libs/main/core/pitime.cpp +++ b/libs/main/core/pitime.cpp @@ -19,7 +19,11 @@ #include "piincludes_p.h" #include "pitime.h" -#include "pisystemtests.h" +#ifndef MICRO_PIP +# include "pisystemtests.h" +#elif defined(ARDUINO) +# include +#endif #ifdef WINDOWS extern FILETIME __pi_ftjan1970; long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;} @@ -256,12 +260,19 @@ PISystemTime PISystemTime::current(bool precise_but_not_system) { clock_get_time(__pi_mac_clock, &t_cur); #elif defined(MICRO_PIP) timespec t_cur; +# ifdef ARDUINO + static const uint32_t offSetSinceEpoch_s = 1581897605UL; + uint32_t mt = millis(); + t_cur.tv_sec = offSetSinceEpoch_s + (mt / 1000); + t_cur.tv_nsec = (mt - (mt / 1000)) * 1000000UL; +# else timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; gettimeofday(&tv, NULL); t_cur.tv_sec = tv.tv_sec; t_cur.tv_nsec = tv.tv_usec * 1000; +# endif #else timespec t_cur; clock_gettime(precise_but_not_system ? CLOCK_MONOTONIC : 0, &t_cur); @@ -404,22 +415,38 @@ PITimeMeasurer::PITimeMeasurer() { double PITimeMeasurer::elapsed_n() const { - return (PISystemTime::current(true) - t_st).toNanoseconds() - PISystemTests::time_elapsed_ns; + return (PISystemTime::current(true) - t_st).toNanoseconds() +#ifndef MICRO_PIP + - PISystemTests::time_elapsed_ns +#endif + ; } double PITimeMeasurer::elapsed_u() const { - return (PISystemTime::current(true) - t_st).toMicroseconds() - PISystemTests::time_elapsed_ns / 1.E+3; + return (PISystemTime::current(true) - t_st).toMicroseconds() +#ifndef MICRO_PIP + - PISystemTests::time_elapsed_ns / 1.E+3 +#endif + ; } double PITimeMeasurer::elapsed_m() const { - return (PISystemTime::current(true) - t_st).toMilliseconds() - PISystemTests::time_elapsed_ns / 1.E+6; + return (PISystemTime::current(true) - t_st).toMilliseconds() +#ifndef MICRO_PIP + - PISystemTests::time_elapsed_ns / 1.E+6 +#endif + ; } double PITimeMeasurer::elapsed_s() const { - return (PISystemTime::current(true) - t_st).toSeconds() - PISystemTests::time_elapsed_ns / 1.E+9; + return (PISystemTime::current(true) - t_st).toSeconds() +#ifndef MICRO_PIP + - PISystemTests::time_elapsed_ns / 1.E+9 +#endif + ; } diff --git a/libs/main/core/pivarianttypes.cpp b/libs/main/core/pivarianttypes.cpp index de21989e..6eb609cb 100644 --- a/libs/main/core/pivarianttypes.cpp +++ b/libs/main/core/pivarianttypes.cpp @@ -84,9 +84,12 @@ PIStringList PIVariantTypes::Enum::names() const { -#ifndef MICRO_PIP PIVariantTypes::IODevice::IODevice() { +#ifndef MICRO_PIP mode = PIIODevice::ReadWrite; +#else + mode = 0; // TODO: PIIODevice for MICRO PIP +#endif // MICRO_PIP options = 0; } @@ -113,12 +116,14 @@ PIString PIVariantTypes::IODevice::toPICout() const { if (mode & 2) {s << "w"; ++rwc;} if (rwc == 1) s << "o"; s << ", flags="; +#ifndef MICRO_PIP // TODO: PIIODevice for MICRO PIP if (options != 0) { if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead]) s << " br"; if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite]) s << " bw"; } +#endif // MICRO_PIP PIPropertyStorage ps = get(); piForeachC (PIPropertyStorage::Property & p, ps) { s << ", " << p.name << "=\"" << p.value.toString() << "\""; @@ -126,7 +131,6 @@ PIString PIVariantTypes::IODevice::toPICout() const { s << ")"; return s; } -#endif // MICRO_PIP