GCC Code Coverage Report


Directory: ./
File: Svc/OsTime/OsTime.cpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 0 50 0.0%
Functions: 0 6 0.0%
Branches: 0 39 0.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title OsTime.cpp
3 // \author kubiak
4 // \brief cpp file for OsTime component implementation class
5 // ======================================================================
6
7 #include "Svc/OsTime/OsTime.hpp"
8 #include "config/FpConfig.hpp"
9
10 #include <Fw/Time/TimeInterval.hpp>
11
12 namespace Svc {
13
14 // ----------------------------------------------------------------------
15 // Component construction and destruction
16 // ----------------------------------------------------------------------
17
18 OsTime ::OsTime(const char* const compName)
19 : OsTimeComponentBase(compName),
20 m_epoch_fw_time(Fw::ZERO_TIME),
21 m_epoch_os_time(),
22 m_epoch_valid(false),
23 m_epoch_lock() {}
24
25 OsTime ::~OsTime() {}
26
27 void OsTime::set_epoch(const Fw::Time& fw_time, const Os::RawTime& os_time) {
28 Os::ScopeLock lock(m_epoch_lock);
29 m_epoch_fw_time = fw_time;
30 m_epoch_os_time = os_time;
31 m_epoch_valid = true;
32 }
33
34 void OsTime::SetCurrentTime_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, U32 seconds_now) {
35 Os::RawTime time_now;
36 Os::RawTime::Status stat = time_now.now();
37 if (stat != Os::RawTime::OP_OK) {
38 this->log_WARNING_HI_SetCurrentTimeError(stat);
39 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
40 return;
41 }
42 Os::ScopeLock lock(m_epoch_lock);
43 m_epoch_fw_time = Fw::Time(seconds_now, 0);
44 m_epoch_os_time = time_now;
45 m_epoch_valid = true;
46 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
47 }
48
49 // ----------------------------------------------------------------------
50 // Handler implementations for user-defined typed input ports
51 // ----------------------------------------------------------------------
52
53 void OsTime ::timeGetPort_handler(FwIndexType portNum, Fw::Time& time) {
54 Fw::Time temp_epoch_fw_time;
55 Os::RawTime temp_epoch_os_time;
56 bool temp_epoch_valid;
57
58 // Copy class state inside of a mutex
59 {
60 Os::ScopeLock lock(m_epoch_lock);
61 temp_epoch_fw_time = m_epoch_fw_time;
62 temp_epoch_os_time = m_epoch_os_time;
63 temp_epoch_valid = m_epoch_valid;
64 }
65
66 time = Fw::ZERO_TIME;
67 if (!temp_epoch_valid) {
68 return;
69 }
70
71 Os::RawTime time_now;
72 Os::RawTime::Status stat = time_now.now();
73 if (stat != Os::RawTime::OP_OK) {
74 return;
75 }
76
77 Fw::TimeInterval elapsed;
78 stat = time_now.getTimeInterval(temp_epoch_os_time, elapsed);
79 if (stat != Os::RawTime::OP_OK) {
80 return;
81 }
82
83 time = temp_epoch_fw_time;
84 time.add(elapsed.getSeconds(), elapsed.getUSeconds());
85 }
86
87 void OsTime ::setEpoch_handler(FwIndexType portNum, const Fw::Time& fw_time, const Os::RawTime& os_time) {
88 set_epoch(fw_time, os_time);
89 }
90
91 } // namespace Svc
92