Skip to content

Commit 7e7861e

Browse files
authored
Add port to OsTime to set the current time (#3607)
1 parent 23d259a commit 7e7861e

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

Svc/OsTime/OsTime.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ void OsTime::set_epoch(const Fw::Time& fw_time, const Os::RawTime& os_time) {
3333
m_epoch_valid = true;
3434
}
3535

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) {
40+
this->log_WARNING_HI_SetCurrentTimeError(stat);
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+
3649
// ----------------------------------------------------------------------
3750
// Handler implementations for user-defined typed input ports
3851
// ----------------------------------------------------------------------

Svc/OsTime/OsTime.fpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,34 @@ module Svc {
55
include "../Interfaces/TimeInterface.fppi"
66

77
sync input port setEpoch: OsTimeEpoch
8+
9+
@ Port for receiving commands
10+
command recv port CmdDisp
11+
12+
@ Port for sending command registration requests
13+
command reg port CmdReg
14+
15+
@ Port for sending command responses
16+
command resp port CmdStatus
17+
18+
@ Event port
19+
event port EventOut
20+
21+
@ Text event port
22+
text event port LogText
23+
24+
@ Time get port
25+
time get port timeCaller
26+
27+
sync command SetCurrentTime(seconds_now: U32) opcode 0x00
28+
29+
@ An error occurred while attempting to set the current time
30+
event SetCurrentTimeError(
31+
status: U32 @< The error status
32+
) \
33+
severity warning high \
34+
id 0x00 \
35+
format "Could not set current time due to RawTime error status {}"
36+
837
}
938
}

Svc/OsTime/OsTime.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class OsTime final : public OsTimeComponentBase {
4949
const Fw::Time& fw_time,
5050
const Os::RawTime& os_time) override;
5151

52+
53+
//! Handler implementation for command SetCurrentTime
54+
void SetCurrentTime_cmdHandler(FwOpcodeType opCode, //!< The opcode
55+
U32 cmdSeq, //!< The command sequence number
56+
U32 seconds_now) override;
57+
5258
Fw::Time m_epoch_fw_time;
5359
Os::RawTime m_epoch_os_time;
5460
bool m_epoch_valid;

0 commit comments

Comments
 (0)