F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
DpDemo.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title DpDemo.cpp
3 // \author jawest
4 // \brief cpp file for DpDemo component implementation class
5 // ======================================================================
6 
7 #include "Ref/DpDemo/DpDemo.hpp"
8 
9 namespace Ref {
10 
11 // ----------------------------------------------------------------------
12 // Component construction and destruction
13 // ----------------------------------------------------------------------
14 
15 DpDemo ::DpDemo(const char* const compName) : DpDemoComponentBase(compName) {
16  this->selectedColor = DpDemo_ColorEnum::RED;
17  this->numRecords = 0;
18  this->dpPriority = 0;
19 }
20 
22 
23 // ----------------------------------------------------------------------
24 // Handler implementations for typed input ports
25 // ----------------------------------------------------------------------
26 
27 void DpDemo ::run_handler(FwIndexType portNum, U32 context) {
28  // If a Data product is being generated, store records
29  if (this->dpInProgress) {
30  this->dpContainer.serializeRecord_StringRecord(Fw::String("Test string"));
31  this->dpContainer.serializeRecord_BooleanRecord(true);
32  this->dpContainer.serializeRecord_I32Record(-100);
33  this->dpContainer.serializeRecord_F64Record(1.25);
34  this->dpContainer.serializeRecord_U32ArrayRecord(DpDemo_U32Array({1, 2, 3, 4, 5}));
35  this->dpContainer.serializeRecord_F32ArrayRecord(DpDemo_F32Array({1.1f, 2.2f, 3.3f}));
36  this->dpContainer.serializeRecord_BooleanArrayRecord(DpDemo_BooleanArray({true, false}));
37  // Array Records
38  // Array record of strings
39  Fw::String str0("String array element 0");
40  Fw::String str1("String array element 1");
41  Fw::String str2("String array element 2");
42  const Fw::StringBase* strings[3] = {&str0, &str1, &str2};
43  this->dpContainer.serializeRecord_StringArrayRecord(strings, 3);
44  // Array record of arrays
45  const DpDemo_StringArray arrayArray[1] = {DpDemo_StringArray(
46  {Fw::String("0 - String array record element 0"), Fw::String("0 - String array record element 1")})};
47  this->dpContainer.serializeRecord_ArrayArrayRecord(arrayArray, 1);
48  // Array record of structs
49  const DpDemo_StructWithStringMembers structArray[2] = {
50  DpDemo_StructWithStringMembers(Fw::String("0 - String member"),
51  DpDemo_StringArray({Fw::String("0 - String array element 0"),
52  Fw::String("0 - String array element 1")})),
53  DpDemo_StructWithStringMembers(Fw::String("1 - String member"),
54  DpDemo_StringArray({Fw::String("1 - String array element 0"),
55  Fw::String("1 - String array element 1")}))};
56  this->dpContainer.serializeRecord_StructArrayRecord(structArray, 2);
57  this->dpContainer.serializeRecord_ArrayOfStringArrayRecord(DpDemo_ArrayOfStringArray(
58  {DpDemo_StringArray({Fw::String("0 - String array element 0"), Fw::String("0 - String array element 1")}),
59  DpDemo_StringArray({Fw::String("1 - String array element 0"), Fw::String("1 - String array element 1")}),
60  DpDemo_StringArray(
61  {Fw::String("2 - String array element 0"), Fw::String("2 - String array element 1")})}));
62  this->dpContainer.serializeRecord_ArrayOfStructsRecord(DpDemo_ArrayOfStructs(
63  {DpDemo_StructWithStringMembers(Fw::String("0 - String member"),
64  DpDemo_StringArray({Fw::String("0 - String array element 0"),
65  Fw::String("0 - String array element 1")})),
66  DpDemo_StructWithStringMembers(Fw::String("1 - String member"),
67  DpDemo_StringArray({Fw::String("1 - String array element 0"),
68  Fw::String("1 - String array element 1")})),
69  DpDemo_StructWithStringMembers(Fw::String("2 - String member"),
70  DpDemo_StringArray({Fw::String("2 - String array element 0"),
71  Fw::String("2 - String array element 1")}))}));
72  this->dpContainer.serializeRecord_EnumArrayRecord(
73  DpDemo_EnumArray({DpDemo_ColorEnum::RED, DpDemo_ColorEnum::GREEN, DpDemo_ColorEnum::BLUE}));
74  this->dpContainer.serializeRecord_StructWithEverythingRecord(DpDemo_StructWithEverything(
75  -1, 2.5, Fw::String("String Member"), false, this->selectedColor,
76  {DpDemo_U32Array({1, 2, 3, 4, 5}), DpDemo_U32Array({6, 7, 8, 9, 10})}, DpDemo_F32Array({4.4f, 5.5f, 6.6f}),
77  DpDemo_U32Array({6, 7, 8, 9, 10}),
78  DpDemo_EnumArray({DpDemo_ColorEnum::RED, DpDemo_ColorEnum::GREEN, DpDemo_ColorEnum::BLUE}),
79  DpDemo_StringArray({Fw::String("String array element 0"), Fw::String("String array element 1")}),
80  DpDemo_BooleanArray({true, false}),
81  DpDemo_StructWithStringMembers(
82  Fw::String("String member"),
83  DpDemo_StringArray({Fw::String("String array element 0"), Fw::String("String array element 1")})),
84  DpDemo_ArrayOfStringArray({DpDemo_StringArray({Fw::String("0 - String array element 0"),
85  Fw::String("0 - String array element 1")}),
86  DpDemo_StringArray({Fw::String("1 - String array element 0"),
87  Fw::String("1 - String array element 1")}),
88  DpDemo_StringArray({Fw::String("2 - String array element 0"),
89  Fw::String("2 - String array element 1")})})));
90  this->log_ACTIVITY_LO_DpComplete(this->numRecords);
91  this->cleanupAndSendDp();
92  }
93 }
94 
95 // ----------------------------------------------------------------------
96 // Handler implementations for commands
97 // ----------------------------------------------------------------------
98 
99 void DpDemo ::SelectColor_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, Ref::DpDemo_ColorEnum color) {
100  this->selectedColor = color;
101  log_ACTIVITY_HI_ColorSelected(color);
102  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
103 }
104 
105 void DpDemo ::Dp_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, DpDemo_DpReqType reqType, U32 priority) {
106  // make sure DPs are available
107  if (!this->isConnected_productGetOut_OutputPort(0) || !this->isConnected_productRequestOut_OutputPort(0)) {
108  this->log_WARNING_HI_DpsNotConnected();
109  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
110  return;
111  }
112 
113  this->numRecords = 15; // 15 records in current demo
114  FwSizeType dpSize = DpDemo_StringAlias::SERIALIZED_SIZE + sizeof(DpDemo_BoolAlias) + sizeof(DpDemo_I32Alias) +
115  sizeof(DpDemo_F64Alias) + DpDemo_U32Array::SERIALIZED_SIZE + DpDemo_F32Array::SERIALIZED_SIZE +
116  DpDemo_BooleanArray::SERIALIZED_SIZE + DpDemo_EnumArray::SERIALIZED_SIZE +
117  DpDemo_StringArray::SERIALIZED_SIZE + DpDemo_StructWithEverything::SERIALIZED_SIZE +
118  DpDemo_StructWithStringMembers::SERIALIZED_SIZE + (DpDemo_StringArray::SERIALIZED_SIZE * 3) +
119  (DpDemo_StringArray::SERIALIZED_SIZE * 1) +
120  (DpDemo_StructWithStringMembers::SERIALIZED_SIZE * 2) +
121  DpDemo_ArrayOfStringArray::SERIALIZED_SIZE + (numRecords * sizeof(FwDpIdType));
122 
123  this->dpPriority = static_cast<FwDpPriorityType>(priority);
124  this->log_ACTIVITY_LO_DpMemRequested(dpSize);
125  if (reqType == DpDemo_DpReqType::IMMEDIATE) {
126  Fw::Success stat = this->dpGet_DpDemoContainer(dpSize, this->dpContainer);
127  // make sure we got the memory we wanted
128  if (Fw::Success::FAILURE == stat) {
129  this->log_WARNING_HI_DpMemoryFail();
130  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
131  } else {
132  this->dpInProgress = true;
133  this->log_ACTIVITY_LO_DpStarted(numRecords);
134  this->log_ACTIVITY_LO_DpMemReceived(this->dpContainer.getBuffer().getSize());
135  // override priority with requested priority
136  this->dpContainer.setPriority(priority);
137  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
138  }
139  } else if (reqType == DpDemo_DpReqType::ASYNC) {
140  this->dpRequest_DpDemoContainer(dpSize);
141  } else {
142  // should never get here
143  FW_ASSERT(0, reqType.e);
144  }
145 }
146 
147 // ----------------------------------------------------------------------
148 // Handler implementations for data products
149 // ----------------------------------------------------------------------
150 
151 void DpDemo ::dpRecv_DpDemoContainer_handler(DpContainer& container, Fw::Success::T status) {
152  // Make sure we got the buffer we wanted or quit
153  if (Fw::Success::SUCCESS == status) {
154  this->dpContainer = container;
155  this->dpInProgress = true;
156  // set previously requested priority
157  this->dpContainer.setPriority(this->dpPriority);
158  this->log_ACTIVITY_LO_DpStarted(this->numRecords);
159  } else {
160  this->log_WARNING_HI_DpMemoryFail();
161  // cleanup
162  this->dpInProgress = false;
163  this->numRecords = 0;
164  }
165 }
166 
167 void DpDemo ::cleanupAndSendDp() {
168  this->dpSend(this->dpContainer);
169  this->dpInProgress = false;
170  this->numRecords = 0;
171 }
172 
173 } // namespace Ref
FwIdType FwOpcodeType
The type of a command opcode.
Representing success.
PlatformSizeType FwSizeType
U32 FwDpPriorityType
The type of a data product priority.
StringTemplate< FW_FIXED_LENGTH_STRING_SIZE > String
Definition: String.hpp:14
~DpDemo()
Destroy DpDemo object.
Definition: DpDemo.cpp:21
T
The raw enum type.
Representing failure.
Command successfully executed.
Command had execution error.
FwIdType FwDpIdType
The type of a data product identifier.
PlatformIndexType FwIndexType
DpDemo(const char *const compName)
Construct DpDemo object.
Definition: DpDemo.cpp:15
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.