GCC Code Coverage Report


Directory: lib/fprime-samd/fprime-samd/Drv/RtcDriver/
File: RawTime.cpp
Date: 2026-09-26 00:05:16
Exec Total Coverage
Lines: 18 34 52.9%
Functions: 4 6 66.7%
Branches: 3 15 20.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title Samd21/Drv/RtcDriver/RawTime.cpp
3 // \brief Realtime clock implementation for Os::RawTime
4 // ======================================================================
5 #include "fprime-samd/Drv/RtcDriver/RawTime.hpp"
6 namespace Os {
7 namespace Samd21 {
8
9 //! \brief check is a is newer than b
10 ✗ bool isNewer(const Samd21RawTimeHandle& a, const Samd21RawTimeHandle& b) {
11 ✗ if (a.m_seconds > b.m_seconds) {
12 ✗ return true;
13 ✗ } else if (a.m_seconds == b.m_seconds) {
14 ✗ return a.m_micros > b.m_micros;
15 } else {
16 ✗ return false;
17 }
18 }
19
20 4 RawTimeHandle* Samd21RawTime::getHandle() {
21 4 return &this->m_handle;
22 }
23
24 2 RawTime::Status Samd21RawTime::now() {
25
1/1
✓ Branch 2 taken 2 times.
2 auto now = timeNow();
26 2 this->m_handle = now;
27 2 return Status::OP_OK;
28 }
29
30 ✗ RawTime::Status Samd21RawTime::getTimeInterval(const Os::RawTime& other, Fw::TimeInterval& interval) const {
31 ✗ interval.set(0, 0);
32 ✗ const Samd21RawTimeHandle& my_handle = this->m_handle;
33 const Samd21RawTimeHandle& other_handle =
34 ✗ static_cast<const Samd21RawTimeHandle&>(*const_cast<Os::RawTime&>(other).getHandle());
35
36 ✗ const Samd21RawTimeHandle& newer = isNewer(my_handle, other_handle) ? my_handle : other_handle;
37 ✗ const Samd21RawTimeHandle& older = isNewer(my_handle, other_handle) ? other_handle : my_handle;
38
39 ✗ if (newer.m_micros < older.m_micros) {
40 ✗ interval.set(newer.m_seconds - older.m_seconds - 1, 1000000 + newer.m_micros - older.m_micros);
41 } else {
42 ✗ interval.set(newer.m_seconds - older.m_seconds, newer.m_micros - older.m_micros);
43 }
44
45 ✗ return Status::OP_OK;
46 }
47
48 2 Fw::SerializeStatus Samd21RawTime::serializeTo(Fw::SerialBufferBase& buffer, Fw::Endianness mode) const {
49 2 Fw::SerializeStatus status = Fw::SerializeStatus::FW_SERIALIZE_OK;
50 2 status = buffer.serializeFrom(this->m_handle.m_seconds, mode);
51
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (status == Fw::FW_SERIALIZE_OK) {
52 2 status = buffer.serializeFrom(this->m_handle.m_micros, mode);
53 }
54 2 return status;
55 }
56
57 2 Fw::SerializeStatus Samd21RawTime::deserializeFrom(Fw::SerialBufferBase& buffer, Fw::Endianness mode) {
58 2 Fw::SerializeStatus status = Fw::SerializeStatus::FW_SERIALIZE_OK;
59 2 status = buffer.deserializeTo(this->m_handle.m_seconds, mode);
60
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (status == Fw::FW_SERIALIZE_OK) {
61 2 status = buffer.deserializeTo(this->m_handle.m_micros, mode);
62 }
63 2 return status;
64 }
65 } // namespace Samd21
66 } // namespace Os
67