F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Version.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Version.cpp
3 // \author sreddy
4 // \brief cpp file for Version component implementation class
5 // ======================================================================
6 
9 
10 #include "versions/version.hpp" //autogenerated file containing hardcoded project and framework versions
11 
12 namespace Svc {
13 
14 // ----------------------------------------------------------------------
15 // Component construction and destruction
16 // ----------------------------------------------------------------------
17 
18 Version ::Version(const char* const compName)
19  : VersionComponentBase(compName), m_enable(false), m_num_custom_elements(0) {
20  Fw::String version_string = "no_ver";
21  // initialize all custom entries
23  // setVersion_enum is by default set to the first enum value, so not setting it here
24  this->verId_db[id].set_version_value(version_string);
25  this->verId_db[id].set_version_status(VersionStatus::FAILURE);
26  }
27 }
28 
30 
31 void Version::config(bool enable) {
32  // Set Verbosity for custom versions
33  this->m_enable = enable;
34 }
35 
37  // Send startup TLM and EVENTS
38  this->fwVersion_tlm();
39  this->projectVersion_tlm();
40  this->libraryVersion_tlm();
41 }
42 // ----------------------------------------------------------------------
43 // Handler implementations for user-defined typed input ports
44 // ----------------------------------------------------------------------
45 
46 void Version ::getVersion_handler(FwIndexType portNum,
47  const Svc::VersionCfg::VersionEnum& version_id,
48  Fw::StringBase& version_string,
49  Svc::VersionStatus& status) {
50  FW_ASSERT(version_id.isValid(), version_id.e);
51  U8 version_slot = VersionSlot(version_id.e);
52  version_string = static_cast<const Fw::StringBase&>(this->verId_db[version_slot].get_version_value());
53  status = this->verId_db[version_slot].get_version_status();
54 }
55 
56 void Version ::setVersion_handler(FwIndexType portNum,
57  const Svc::VersionCfg::VersionEnum& version_id,
58  Fw::StringBase& version_string,
59  Svc::VersionStatus& status) {
60  FW_ASSERT(version_id.isValid(), version_id.e);
61  auto ver_slot = VersionSlot(version_id.e);
62  this->verId_db[ver_slot].set_version_enum(version_id);
63  this->verId_db[ver_slot].set_version_value(version_string);
64  this->verId_db[ver_slot].set_version_status(status);
65  this->m_num_custom_elements++;
66  this->customVersion_tlm(ver_slot);
67 }
68 
69 // ----------------------------------------------------------------------
70 // Handler implementations for commands
71 // ----------------------------------------------------------------------
72 
73 void Version ::ENABLE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Svc::VersionEnabled& enable) {
74  this->m_enable = (enable == VersionEnabled::ENABLED);
75 
76  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
77 }
78 
79 // Command handler to event versions
80 void Version ::VERSION_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Svc::VersionType& version_type) {
81  FW_ASSERT(version_type.isValid(), version_type.e);
82 
83  switch (version_type) {
85  this->projectVersion_tlm();
86  break;
87 
89  this->fwVersion_tlm();
90  break;
91 
93  this->libraryVersion_tlm();
94  break;
95 
97  this->customVersion_tlm_all();
98  break;
99 
100  case (Svc::VersionType::ALL):
101  this->projectVersion_tlm();
102  this->fwVersion_tlm();
103  this->libraryVersion_tlm();
104  this->customVersion_tlm_all();
105  break;
106  default:
107  FW_ASSERT(false, version_type);
108  break;
109  }
110 
111  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
112 }
113 // ----------------------------------------------------------------------
114 // implementations for internal functions
115 // ----------------------------------------------------------------------
116 // Send both events and tlm for framework version
117 void Version ::fwVersion_tlm() {
119  this->log_ACTIVITY_LO_FrameworkVersion(fw_event);
121  this->tlmWrite_FrameworkVersion(fw_tlm);
122 }
123 
124 // Send both events and tlm for project version
125 void Version ::projectVersion_tlm() {
127  this->log_ACTIVITY_LO_ProjectVersion(proj_event);
129  this->tlmWrite_ProjectVersion(proj_tlm);
130 }
131 
132 // Send both events and tlm for library versions
133 void Version ::libraryVersion_tlm() {
134  // Process libraries array
135  for (U8 i = 0; i < Project::Version::LIBRARY_VERSIONS_COUNT; i++) {
136  FW_ASSERT(Project::Version::LIBRARY_VERSIONS[i] != nullptr, static_cast<FwAssertArgType>(i));
137  // Emit Event/TLM on library versions
139  // Write to Events
140  switch (i) {
141  case VER_SLOT_00:
143  break;
144  case VER_SLOT_01:
146  break;
147  case VER_SLOT_02:
149  break;
150  case VER_SLOT_03:
152  break;
153  case VER_SLOT_04:
155  break;
156  case VER_SLOT_05:
158  break;
159  case VER_SLOT_06:
161  break;
162  case VER_SLOT_07:
164  break;
165  case VER_SLOT_08:
167  break;
168  case VER_SLOT_09:
170  break;
171  default:
172  // It is possible to have more than 10 library versions; however design agreed to only
173  // provide 10 TLM channels for it
174  break;
175  }
176  }
177 }
178 
179 // Send all events and tlm (if verbosity is enabled) for custom versions
180 void Version ::customVersion_tlm_all() {
181  for (U8 i = 0;
182  (m_enable == true) && (m_num_custom_elements != 0) && (i < Svc::VersionCfg::VersionEnum::NUM_CONSTANTS); i++) {
183  Version::customVersion_tlm(VersionSlot(i));
184  }
185 }
186 
187 // Send events and tlm (if verbosity is enabled) for custom versions
188 void Version ::customVersion_tlm(VersionSlot custom_slot) {
189  // Process custom version TLM only if verbosity is enabled and there are any valid writes to it;
190  // it doesn't necessarily have to be consecutive
191  if ((this->verId_db[custom_slot].get_version_value() != "no_ver") &&
192  (this->m_num_custom_elements > 0)) { // Write TLM for valid writes
193 
194  // Emit Events/TLM on custom versions
195  this->log_ACTIVITY_LO_CustomVersions(this->verId_db[custom_slot].get_version_enum(),
196  this->verId_db[custom_slot].get_version_value());
197 
198  if (m_enable == true) { // Send TLM only if verbosity is enabled
199  // Write to TLM
200  switch (custom_slot) {
201  case VER_SLOT_00:
202  this->tlmWrite_CustomVersion01(verId_db[custom_slot]);
203  break;
204  case VER_SLOT_01:
205  this->tlmWrite_CustomVersion02(verId_db[custom_slot]);
206  break;
207  case VER_SLOT_02:
208  this->tlmWrite_CustomVersion03(verId_db[custom_slot]);
209  break;
210  case VER_SLOT_03:
211  this->tlmWrite_CustomVersion04(verId_db[custom_slot]);
212  break;
213  case VER_SLOT_04:
214  this->tlmWrite_CustomVersion05(verId_db[custom_slot]);
215  break;
216  case VER_SLOT_05:
217  this->tlmWrite_CustomVersion06(verId_db[custom_slot]);
218  break;
219  case VER_SLOT_06:
220  this->tlmWrite_CustomVersion07(verId_db[custom_slot]);
221  break;
222  case VER_SLOT_07:
223  this->tlmWrite_CustomVersion08(verId_db[custom_slot]);
224  break;
225  case VER_SLOT_08:
226  this->tlmWrite_CustomVersion09(verId_db[custom_slot]);
227  break;
228  case VER_SLOT_09:
229  this->tlmWrite_CustomVersion10(verId_db[custom_slot]);
230  break;
231  default:
232  // There are only 10 custom slots available
233  FW_ASSERT(false, custom_slot);
234  break;
235  }
236  }
237  }
238 }
239 
240 } // namespace Svc
static const char *const LIBRARY_VERSIONS[]
Definition: version.hpp:15
void tlmWrite_LibraryVersion10(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel LibraryVersion10.
void tlmWrite_CustomVersion07(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel CustomVersion07.
void set_version_value(const Fw::StringBase &version_value)
Set member version_value.
void tlmWrite_LibraryVersion04(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel LibraryVersion04.
FwIdType FwOpcodeType
The type of a command opcode.
void tlmWrite_LibraryVersion01(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
static const char *const PROJECT_VERSION
Definition: version.hpp:13
void set_version_status(Svc::VersionStatus::T version_status)
Set member version_status.
void tlmWrite_CustomVersion02(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel CustomVersion02.
all above versions
void tlmWrite_CustomVersion10(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel CustomVersion10.
void tlmWrite_LibraryVersion06(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel LibraryVersion06.
enum T e
The raw enum value.
void tlmWrite_CustomVersion03(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel CustomVersion03.
void start()
send initial version tlm and events
Definition: Version.cpp:36
Svc::VersionStatus::T get_version_status() const
Get member version_status.
void tlmWrite_LibraryVersion03(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel LibraryVersion03.
The number of enumerated constants.
static const FwIndexType LIBRARY_VERSIONS_COUNT
Definition: version.hpp:14
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
enum T e
The raw enum value.
void tlmWrite_LibraryVersion08(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel LibraryVersion08.
Failure to get version.
void tlmWrite_CustomVersion05(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel CustomVersion05.
Auto-generated base for Version component.
void log_ACTIVITY_LO_ProjectVersion(const Fw::StringBase &version) const
static const char *const FRAMEWORK_VERSION
Definition: version.hpp:12
An enumeration for version status.
void set_version_enum(Svc::VersionCfg::VersionEnum::T version_enum)
Set member version_enum.
void tlmWrite_LibraryVersion05(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel LibraryVersion05.
Fw::ExternalString & get_version_value()
Get member version_value.
Command successfully executed.
void log_ACTIVITY_LO_CustomVersions(const Svc::VersionCfg::VersionEnum &version_enum, const Fw::StringBase &version_value) const
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
Version(const char *const compName)
Construct Version object.
Definition: Version.cpp:18
void config(bool enable)
configure version&#39;s verbosity
Definition: Version.cpp:31
void tlmWrite_CustomVersion09(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel CustomVersion09.
PlatformIndexType FwIndexType
void tlmWrite_CustomVersion06(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel CustomVersion06.
void tlmWrite_LibraryVersion07(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel LibraryVersion07.
bool isValid() const
Check raw enum value for validity.
~Version()
Destroy Version object.
Definition: Version.cpp:29
RateGroupDivider component implementation.
An enumeration for Version Type.
void tlmWrite_LibraryVersion02(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel LibraryVersion02.
void tlmWrite_CustomVersion04(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel CustomVersion04.
void tlmWrite_CustomVersion01(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
void log_ACTIVITY_LO_FrameworkVersion(const Fw::StringBase &version) const
void log_ACTIVITY_LO_LibraryVersions(const Fw::StringBase &version) const
Tracks versions for project, framework and user defined versions etc.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
bool isValid() const
Check raw enum value for validity.
void tlmWrite_CustomVersion08(const Svc::CustomVersionDb &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel CustomVersion08.
void tlmWrite_LibraryVersion09(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
Write telemetry channel LibraryVersion09.
void tlmWrite_FrameworkVersion(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const
void tlmWrite_ProjectVersion(const Fw::StringBase &arg, Fw::Time _tlmTime=Fw::Time()) const