F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
8#include "FpConfig.hpp"
9
10#include "versions/version.hpp" //autogenerated file containing hardcoded project and framework versions
11
12namespace Svc {
13
14// ----------------------------------------------------------------------
15// Component construction and destruction
16// ----------------------------------------------------------------------
17
18Version ::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].setversion_value(version_string);
25 this->verId_db[id].setversion_status(VersionStatus::FAILURE);
26 }
27}
28
29Version ::~Version() {}
30
31void Version::config(bool enable) {
32 // Set Verbosity for custom versions
33 this->m_enable = enable;
34
35 // Setup and send startup TLM
36 this->fwVersion_tlm();
37 this->projectVersion_tlm();
38 this->libraryVersion_tlm();
39}
40// ----------------------------------------------------------------------
41// Handler implementations for user-defined typed input ports
42// ----------------------------------------------------------------------
43
44void Version ::getVersion_handler(FwIndexType portNum,
45 const Svc::VersionCfg::VersionEnum& version_id,
46 Fw::StringBase& version_string,
47 Svc::VersionStatus& status) {
48 FW_ASSERT(version_id.isValid(), version_id.e);
49 U8 version_slot = VersionSlot(version_id.e);
50 version_string = this->verId_db[version_slot].getversion_value();
51 status = this->verId_db[version_slot].getversion_status();
52}
53
54void Version ::setVersion_handler(FwIndexType portNum,
55 const Svc::VersionCfg::VersionEnum& version_id,
56 Fw::StringBase& version_string,
57 Svc::VersionStatus& status) {
58 FW_ASSERT(version_id.isValid(), version_id.e);
59 VersionSlot ver_slot = VersionSlot(version_id.e);
60 this->verId_db[ver_slot].setversion_enum(version_id);
61 this->verId_db[ver_slot].setversion_value(version_string);
62 this->verId_db[ver_slot].setversion_status(status);
63 this->m_num_custom_elements++;
64 this->customVersion_tlm(ver_slot);
65}
66
67// ----------------------------------------------------------------------
68// Handler implementations for commands
69// ----------------------------------------------------------------------
70
71void Version ::ENABLE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, Svc::VersionEnabled enable) {
72 this->m_enable = (enable == VersionEnabled::ENABLED);
73
74 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
75}
76
77// Command handler to event versions
78void Version ::VERSION_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, Svc::VersionType version_type) {
79
80 FW_ASSERT(version_type.isValid(),version_type.e);
81
82 switch (version_type) {
84 this->projectVersion_tlm();
85 break;
86
88 this->fwVersion_tlm();
89 break;
90
92 this->libraryVersion_tlm();
93 break;
94
96 this->customVersion_tlm_all();
97 break;
98
100 this->projectVersion_tlm();
101 this->fwVersion_tlm();
102 this->libraryVersion_tlm();
103 this->customVersion_tlm_all();
104 break;
105 default:
106 FW_ASSERT(0, version_type);
107 break;
108 }
109
110 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
111}
112// ----------------------------------------------------------------------
113// implementations for internal functions
114// ----------------------------------------------------------------------
115// Send both events and tlm for framework version
116void Version ::fwVersion_tlm() {
118 this->log_ACTIVITY_LO_FrameworkVersion(fw_event);
120 this->tlmWrite_FrameworkVersion(fw_tlm);
121}
122
123// Send both events and tlm for project version
124void Version ::projectVersion_tlm() {
126 this->log_ACTIVITY_LO_ProjectVersion(proj_event);
128 this->tlmWrite_ProjectVersion(proj_tlm);
129}
130
131// Send both events and tlm for library versions
132void Version ::libraryVersion_tlm() {
133
134 // Process libraries array
135 for (U8 i = 0; i < Project::Version::LIBRARY_VERSIONS_COUNT; i++) {
136 // Emit Event/TLM on library versions
137 this->log_ACTIVITY_LO_LibraryVersions(Fw::LogStringArg(Project::Version::LIBRARY_VERSIONS[i]));
138 // Write to Events
139 switch (i) {
140 case VER_SLOT_00:
141 this->tlmWrite_LibraryVersion01(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
142 break;
143 case VER_SLOT_01:
144 this->tlmWrite_LibraryVersion02(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
145 break;
146 case VER_SLOT_02:
147 this->tlmWrite_LibraryVersion03(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
148 break;
149 case VER_SLOT_03:
150 this->tlmWrite_LibraryVersion04(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
151 break;
152 case VER_SLOT_04:
153 this->tlmWrite_LibraryVersion05(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
154 break;
155 case VER_SLOT_05:
156 this->tlmWrite_LibraryVersion06(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
157 break;
158 case VER_SLOT_06:
159 this->tlmWrite_LibraryVersion07(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
160 break;
161 case VER_SLOT_07:
162 this->tlmWrite_LibraryVersion08(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
163 break;
164 case VER_SLOT_08:
165 this->tlmWrite_LibraryVersion09(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
166 break;
167 case VER_SLOT_09:
168 this->tlmWrite_LibraryVersion10(Fw::TlmString(Project::Version::LIBRARY_VERSIONS[i]));
169 break;
170 default:
171 // It is possible to have more than 10 library versions; however design agreed to only
172 // provide 10 TLM channels for it
173 break;
174 }
175 }
176}
177
178// Send all events and tlm (if verbosity is enabled) for custom versions
179void Version ::customVersion_tlm_all() {
180 for (U8 i = 0; (m_enable == true) && (m_num_custom_elements != 0) && (i < Svc::VersionCfg::VersionEnum::NUM_CONSTANTS);
181 i++) {
182 Version::customVersion_tlm(VersionSlot(i));
183 }
184}
185
186// Send events and tlm (if verbosity is enabled) for custom versions
187void Version ::customVersion_tlm(VersionSlot custom_slot) {
188 // Process custom version TLM only if verbosity is enabled and there are any valid writes to it;
189 // it doesn't necessarily have to be consecutive
190 if ((this->verId_db[custom_slot].getversion_value() != "no_ver") &&
191 (this->m_num_custom_elements > 0)) { // Write TLM for valid writes
192
193 // Emit Events/TLM on custom versions
194 this->log_ACTIVITY_LO_CustomVersions(this->verId_db[custom_slot].getversion_enum(),
195 this->verId_db[custom_slot].getversion_value());
196
197 if (m_enable == true) { //Send TLM only if verbosity is enabled
198 // Write to TLM
199 switch (custom_slot) {
200 case VER_SLOT_00:
201 this->tlmWrite_CustomVersion01(verId_db[custom_slot]);
202 break;
203 case VER_SLOT_01:
204 this->tlmWrite_CustomVersion02(verId_db[custom_slot]);
205 break;
206 case VER_SLOT_02:
207 this->tlmWrite_CustomVersion03(verId_db[custom_slot]);
208 break;
209 case VER_SLOT_03:
210 this->tlmWrite_CustomVersion04(verId_db[custom_slot]);
211 break;
212 case VER_SLOT_04:
213 this->tlmWrite_CustomVersion05(verId_db[custom_slot]);
214 break;
215 case VER_SLOT_05:
216 this->tlmWrite_CustomVersion06(verId_db[custom_slot]);
217 break;
218 case VER_SLOT_06:
219 this->tlmWrite_CustomVersion07(verId_db[custom_slot]);
220 break;
221 case VER_SLOT_07:
222 this->tlmWrite_CustomVersion08(verId_db[custom_slot]);
223 break;
224 case VER_SLOT_08:
225 this->tlmWrite_CustomVersion09(verId_db[custom_slot]);
226 break;
227 case VER_SLOT_09:
228 this->tlmWrite_CustomVersion10(verId_db[custom_slot]);
229 break;
230 default:
231 // There are only 10 custom slots available
232 FW_ASSERT(0, custom_slot);
233 break;
234 }
235 }
236 }
237}
238
239} // namespace Svc
#define FW_ASSERT(...)
Definition Assert.hpp:14
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:30
U32 FwOpcodeType
Definition FpConfig.h:91
PlatformIndexType FwIndexType
Definition FpConfig.h:25
C++-compatible configuration header for fprime configuration.
@ OK
Command successfully executed.
void setversion_status(Svc::VersionStatus::T version_status)
Set member version_status.
void setversion_value(const Fw::StringBase &version_value)
Set member version_value.
@ NUM_CONSTANTS
The number of enumerated constants.
bool isValid() const
Check raw enum value for validity.
Auto-generated base for Version component.
Tracks versions for project, framework and user defined versions etc.
@ ENABLED
verbosity enabled
void config(bool enable)
configure version's verbosity and startup
Definition Version.cpp:31
An enumeration for version status.
@ FAILURE
Failure to get version.
An enumeration for Version Type.
bool isValid() const
Check raw enum value for validity.
T e
The raw enum value.
@ LIBRARY
library version
@ FRAMEWORK
framework version
@ CUSTOM
custom version
@ ALL
all above versions
@ PROJECT
project version
static const char *const LIBRARY_VERSIONS[]
Definition version.hpp:15
static const char *const PROJECT_VERSION
Definition version.hpp:13
static const FwIndexType LIBRARY_VERSIONS_COUNT
Definition version.hpp:14
static const char *const FRAMEWORK_VERSION
Definition version.hpp:12