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 "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 // ----------------------------------------------------------------------
37 // Handler implementations for user-defined typed input ports
38 // ----------------------------------------------------------------------
39 
40 void OsTime ::timeGetPort_handler(FwIndexType portNum, Fw::Time& time) {
41  Fw::Time temp_epoch_fw_time;
42  Os::RawTime temp_epoch_os_time;
43  bool temp_epoch_valid;
44 
45  // Copy class state inside of a mutex
46  {
47  Os::ScopeLock lock(m_epoch_lock);
48  temp_epoch_fw_time = m_epoch_fw_time;
49  temp_epoch_os_time = m_epoch_os_time;
50  temp_epoch_valid = m_epoch_valid;
51  }
52 
53  time = Fw::ZERO_TIME;
54  if (!temp_epoch_valid) {
55  return;
56  }
57 
58  Os::RawTime time_now;
59  Os::RawTime::Status stat = time_now.now();
60  if (stat != Os::RawTime::OP_OK) {
61  return;
62  }
63 
64  Fw::TimeInterval elapsed;
65  stat = time_now.getTimeInterval(temp_epoch_os_time, elapsed);
66  if (stat != Os::RawTime::OP_OK) {
67  return;
68  }
69 
70  time = temp_epoch_fw_time;
71  time.add(elapsed.getSeconds(), elapsed.getUSeconds());
72 }
73 
74 void OsTime ::setEpoch_handler(FwIndexType portNum, const Fw::Time& fw_time, const Os::RawTime& os_time) {
75  set_epoch(fw_time, os_time);
76 }
77 
78 } // 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
Operation was successful.
Definition: RawTime.hpp:25
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
C++-compatible configuration header for fprime configuration.
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