F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
OsTime.cpp
Go to the documentation of this file.
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 
27 {}
28 
29 void OsTime::set_epoch(const Fw::Time& fw_time, const Os::RawTime& os_time) {
30  Os::ScopeLock lock(m_epoch_lock);
31  m_epoch_fw_time = fw_time;
32  m_epoch_os_time = os_time;
33  m_epoch_valid = true;
34 }
35 
36 void OsTime::SetCurrentTime_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, U32 seconds_now) {
37  Os::RawTime time_now;
38  Os::RawTime::Status stat = time_now.now();
39  if (stat != Os::RawTime::OP_OK) {
41  return;
42  }
43  Os::ScopeLock lock(m_epoch_lock);
44  m_epoch_fw_time = Fw::Time(seconds_now, 0);
45  m_epoch_os_time = time_now;
46  m_epoch_valid = true;
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
~OsTime()
Destroy OsTime object.
Definition: OsTime.cpp:26
Definition: Time.hpp:9
void set_epoch(const Fw::Time &fw_time, const Os::RawTime &os_time)
Definition: OsTime.cpp:29
FwIdType FwOpcodeType
The type of a command opcode.
Operation was successful.
Definition: RawTime.hpp:25
void log_WARNING_HI_SetCurrentTimeError(U32 status) const
Status now() override
Get the current time.
Definition: RawTime.cpp:36
const Time ZERO_TIME
Definition: Time.cpp:5
OsTime(const char *const compName)
Construct OsTime object.
Definition: OsTime.cpp:18
U32 getUSeconds() const
static Time add(const Time &a, const Time &b)
Definition: Time.cpp:193
Auto-generated base for OsTime component.
PlatformIndexType FwIndexType
locks a mutex within the current scope
Definition: Mutex.hpp:80
Status getTimeInterval(const Os::RawTime &other, Fw::TimeInterval &interval) const override
Calculate the time interval between this and another raw time.
Definition: RawTime.cpp:41
RateGroupDivider component implementation.
U32 getSeconds() const