| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 |
3/3✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 8 taken 1 times.
|
1 | DpDemo ::DpDemo(const char* const compName) : DpDemoComponentBase(compName) { |
| 16 |
1/1✓ Branch 1 taken 1 times.
|
1 | this->selectedColor = DpDemo_ColorEnum::RED; |
| 17 | 1 | this->numRecords = 0; | |
| 18 | 1 | this->dpPriority = 0; | |
| 19 | 1 | this->dpInProgress = false; | |
| 20 | 1 | } | |
| 21 | |||
| 22 | 2 | DpDemo ::~DpDemo() {} | |
| 23 | |||
| 24 | // ---------------------------------------------------------------------- | ||
| 25 | // Handler implementations for typed input ports | ||
| 26 | // ---------------------------------------------------------------------- | ||
| 27 | |||
| 28 | 118 | void DpDemo ::run_handler(FwIndexType portNum, U32 context) { | |
| 29 | // If a Data product is being generated, store records | ||
| 30 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 116 times.
|
118 | if (this->dpInProgress) { |
| 31 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | this->dpContainer.serializeRecord_StringRecord(Fw::String("Test string")); |
| 32 |
1/1✓ Branch 1 taken 2 times.
|
2 | this->dpContainer.serializeRecord_BooleanRecord(true); |
| 33 |
1/1✓ Branch 1 taken 2 times.
|
2 | this->dpContainer.serializeRecord_I32Record(-100); |
| 34 |
1/1✓ Branch 1 taken 2 times.
|
2 | this->dpContainer.serializeRecord_F64Record(1.25); |
| 35 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | this->dpContainer.serializeRecord_U32ArrayRecord(DpDemo_U32Array({1, 2, 3, 4, 5})); |
| 36 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | this->dpContainer.serializeRecord_F32ArrayRecord(DpDemo_F32Array({1.1f, 2.2f, 3.3f})); |
| 37 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | this->dpContainer.serializeRecord_BooleanArrayRecord(DpDemo_BooleanArray({true, false})); |
| 38 | // Array Records | ||
| 39 | // Array record of strings | ||
| 40 |
1/1✓ Branch 1 taken 2 times.
|
2 | Fw::String str0("String array element 0"); |
| 41 |
1/1✓ Branch 1 taken 2 times.
|
2 | Fw::String str1("String array element 1"); |
| 42 |
1/1✓ Branch 1 taken 2 times.
|
2 | Fw::String str2("String array element 2"); |
| 43 | 2 | const Fw::StringBase* strings[3] = {&str0, &str1, &str2}; | |
| 44 |
1/1✓ Branch 1 taken 2 times.
|
2 | this->dpContainer.serializeRecord_StringArrayRecord(strings, 3); |
| 45 | // Array record of arrays | ||
| 46 | const DpDemo_StringArray arrayArray[1] = {DpDemo_StringArray( | ||
| 47 |
2/8✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
10 | {Fw::String("0 - String array record element 0"), Fw::String("0 - String array record element 1")})}; |
| 48 |
1/1✓ Branch 1 taken 2 times.
|
2 | this->dpContainer.serializeRecord_ArrayArrayRecord(arrayArray, 1); |
| 49 | // Array record of structs | ||
| 50 | const DpDemo_StructWithStringMembers structArray[2] = { | ||
| 51 |
1/1✓ Branch 1 taken 2 times.
|
2 | DpDemo_StructWithStringMembers(Fw::String("0 - String member"), |
| 52 |
2/4✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
8 | DpDemo_StringArray({Fw::String("0 - String array element 0"), |
| 53 | 6 | Fw::String("0 - String array element 1")})), | |
| 54 |
1/1✓ Branch 1 taken 2 times.
|
2 | DpDemo_StructWithStringMembers(Fw::String("1 - String member"), |
| 55 |
2/4✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
8 | DpDemo_StringArray({Fw::String("1 - String array element 0"), |
| 56 |
2/6✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
16 | Fw::String("1 - String array element 1")}))}; |
| 57 |
1/1✓ Branch 1 taken 2 times.
|
2 | this->dpContainer.serializeRecord_StructArrayRecord(structArray, 2); |
| 58 |
3/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
10 | this->dpContainer.serializeRecord_ArrayOfStringArrayRecord(DpDemo_ArrayOfStringArray( |
| 59 | 4 | {DpDemo_StringArray({Fw::String("0 - String array element 0"), Fw::String("0 - String array element 1")}), | |
| 60 | 4 | DpDemo_StringArray({Fw::String("1 - String array element 0"), Fw::String("1 - String array element 1")}), | |
| 61 | DpDemo_StringArray( | ||
| 62 | 14 | {Fw::String("2 - String array element 0"), Fw::String("2 - String array element 1")})})); | |
| 63 |
3/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
10 | this->dpContainer.serializeRecord_ArrayOfStructsRecord(DpDemo_ArrayOfStructs( |
| 64 |
1/1✓ Branch 1 taken 2 times.
|
2 | {DpDemo_StructWithStringMembers(Fw::String("0 - String member"), |
| 65 |
2/4✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
8 | DpDemo_StringArray({Fw::String("0 - String array element 0"), |
| 66 | 6 | Fw::String("0 - String array element 1")})), | |
| 67 |
1/1✓ Branch 1 taken 2 times.
|
2 | DpDemo_StructWithStringMembers(Fw::String("1 - String member"), |
| 68 |
2/4✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
8 | DpDemo_StringArray({Fw::String("1 - String array element 0"), |
| 69 | 6 | Fw::String("1 - String array element 1")})), | |
| 70 |
1/1✓ Branch 1 taken 2 times.
|
4 | DpDemo_StructWithStringMembers(Fw::String("2 - String member"), |
| 71 |
2/4✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
8 | DpDemo_StringArray({Fw::String("2 - String array element 0"), |
| 72 | 14 | Fw::String("2 - String array element 1")}))})); | |
| 73 |
1/1✓ Branch 1 taken 2 times.
|
2 | this->dpContainer.serializeRecord_EnumArrayRecord( |
| 74 |
2/4✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
8 | DpDemo_EnumArray({DpDemo_ColorEnum::RED, DpDemo_ColorEnum::GREEN, DpDemo_ColorEnum::BLUE})); |
| 75 |
4/6✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 2 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
8 | this->dpContainer.serializeRecord_StructWithEverythingRecord(DpDemo_StructWithEverything( |
| 76 |
1/1✓ Branch 1 taken 2 times.
|
4 | -1, 2.5, Fw::String("String Member"), false, this->selectedColor, |
| 77 |
1/1✓ Branch 1 taken 2 times.
|
2 | {DpDemo_U32Array({1, 2, 3, 4, 5}), DpDemo_U32Array({6, 7, 8, 9, 10})}, DpDemo_F32Array({4.4f, 5.5f, 6.6f}), |
| 78 |
1/1✓ Branch 1 taken 2 times.
|
4 | DpDemo_U32Array({6, 7, 8, 9, 10}), |
| 79 |
2/4✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
8 | DpDemo_EnumArray({DpDemo_ColorEnum::RED, DpDemo_ColorEnum::GREEN, DpDemo_ColorEnum::BLUE}), |
| 80 |
2/4✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
6 | DpDemo_StringArray({Fw::String("String array element 0"), Fw::String("String array element 1")}), |
| 81 |
1/1✓ Branch 1 taken 2 times.
|
4 | DpDemo_BooleanArray({true, false}), |
| 82 |
1/1✓ Branch 1 taken 2 times.
|
4 | DpDemo_StructWithStringMembers( |
| 83 |
1/1✓ Branch 1 taken 2 times.
|
4 | Fw::String("String member"), |
| 84 |
2/4✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
6 | DpDemo_StringArray({Fw::String("String array element 0"), Fw::String("String array element 1")})), |
| 85 |
2/4✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
10 | DpDemo_ArrayOfStringArray({DpDemo_StringArray({Fw::String("0 - String array element 0"), |
| 86 | 4 | Fw::String("0 - String array element 1")}), | |
| 87 | DpDemo_StringArray({Fw::String("1 - String array element 0"), | ||
| 88 | 4 | Fw::String("1 - String array element 1")}), | |
| 89 | DpDemo_StringArray({Fw::String("2 - String array element 0"), | ||
| 90 | 20 | Fw::String("2 - String array element 1")})}))); | |
| 91 | 2 | this->log_ACTIVITY_LO_DpComplete(this->numRecords); | |
| 92 |
1/1✓ Branch 1 taken 2 times.
|
2 | this->cleanupAndSendDp(); |
| 93 | 12 | } | |
| 94 | 170 | } | |
| 95 | |||
| 96 | // ---------------------------------------------------------------------- | ||
| 97 | // Handler implementations for commands | ||
| 98 | // ---------------------------------------------------------------------- | ||
| 99 | |||
| 100 | ✗ | void DpDemo ::SelectColor_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, const Ref::DpDemo_ColorEnum& color) { | |
| 101 | ✗ | this->selectedColor = color; | |
| 102 | ✗ | log_ACTIVITY_HI_ColorSelected(color); | |
| 103 | ✗ | this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); | |
| 104 | ✗ | } | |
| 105 | |||
| 106 | 2 | void DpDemo ::Dp_cmdHandler(FwOpcodeType opCode, | |
| 107 | U32 cmdSeq, | ||
| 108 | const DpDemo_DpReqType& reqType, | ||
| 109 | U32 priority, | ||
| 110 | const Fw::DpCfg::ProcType& proc) { | ||
| 111 | // make sure DPs are available | ||
| 112 |
3/6✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
2 | if (!this->isConnected_productGetOut_OutputPort(0) || !this->isConnected_productRequestOut_OutputPort(0)) { |
| 113 | ✗ | this->log_WARNING_HI_DpsNotConnected(); | |
| 114 | ✗ | this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); | |
| 115 | ✗ | return; | |
| 116 | } | ||
| 117 | |||
| 118 | 2 | this->numRecords = 14; // 14 records in current demo | |
| 119 | |||
| 120 | // Element counts for the variable length array records serialized below | ||
| 121 | 2 | const FwSizeType stringArrayElements = 3; | |
| 122 | 2 | const FwSizeType arrayArrayElements = 1; | |
| 123 | 2 | const FwSizeType structArrayElements = 2; | |
| 124 | |||
| 125 | // The generated SIZE_OF_*_RECORD constants already account for the record | ||
| 126 | // id, and for array records the serialized length prefix, so the demo no | ||
| 127 | // longer has to reproduce the layout by hand | ||
| 128 | 2 | FwSizeType dpSize = SIZE_OF_StringRecord_RECORD + SIZE_OF_BooleanRecord_RECORD + SIZE_OF_I32Record_RECORD + | |
| 129 | SIZE_OF_F64Record_RECORD + SIZE_OF_U32ArrayRecord_RECORD + SIZE_OF_F32ArrayRecord_RECORD + | ||
| 130 | SIZE_OF_BooleanArrayRecord_RECORD + SIZE_OF_EnumArrayRecord_RECORD + | ||
| 131 | SIZE_OF_StructWithEverythingRecord_RECORD + SIZE_OF_ArrayOfStringArrayRecord_RECORD + | ||
| 132 | SIZE_OF_ArrayOfStructsRecord_RECORD + SIZE_OF_StringArrayRecord_RECORD(stringArrayElements) + | ||
| 133 | SIZE_OF_ArrayArrayRecord_RECORD(arrayArrayElements) + | ||
| 134 | SIZE_OF_StructArrayRecord_RECORD(structArrayElements); | ||
| 135 | |||
| 136 | 2 | this->dpPriority = static_cast<FwDpPriorityType>(priority); | |
| 137 | 2 | this->dpProc = proc; | |
| 138 | 2 | this->log_ACTIVITY_LO_DpMemRequested(dpSize); | |
| 139 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | if (reqType == DpDemo_DpReqType::IMMEDIATE) { |
| 140 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | Fw::Success stat = this->dpGet_DpDemoContainer(dpSize, this->dpContainer); |
| 141 | // make sure we got the memory we wanted | ||
| 142 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (Fw::Success::FAILURE == stat) { |
| 143 | ✗ | this->log_WARNING_HI_DpMemoryFail(); | |
| 144 | ✗ | this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); | |
| 145 | } else { | ||
| 146 | 2 | this->dpInProgress = true; | |
| 147 |
1/1✓ Branch 1 taken 2 times.
|
2 | this->log_ACTIVITY_LO_DpStarted(numRecords); |
| 148 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | this->log_ACTIVITY_LO_DpMemReceived(this->dpContainer.getBuffer().getSize()); |
| 149 | // override priority with requested priority | ||
| 150 | 2 | this->dpContainer.setPriority(priority); | |
| 151 | 2 | this->dpContainer.setProcTypes(proc); | |
| 152 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); |
| 153 | } | ||
| 154 |
0/2✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2 | } else if (reqType == DpDemo_DpReqType::ASYNC) { |
| 155 | // Response is deferred until the requested container arrives | ||
| 156 | ✗ | this->pendingOpCode = opCode; | |
| 157 | ✗ | this->pendingCmdSeq = cmdSeq; | |
| 158 | ✗ | this->dpRequest_DpDemoContainer(dpSize); | |
| 159 | } else { | ||
| 160 | // should never get here | ||
| 161 | ✗ | FW_ASSERT(0, reqType.e); | |
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | // ---------------------------------------------------------------------- | ||
| 166 | // Handler implementations for data products | ||
| 167 | // ---------------------------------------------------------------------- | ||
| 168 | |||
| 169 | ✗ | void DpDemo ::dpRecv_DpDemoContainer_handler(DpContainer& container, Fw::Success::T status) { | |
| 170 | // Make sure we got the buffer we wanted or quit | ||
| 171 | ✗ | if (Fw::Success::SUCCESS == status) { | |
| 172 | ✗ | this->dpContainer = container; | |
| 173 | ✗ | this->dpInProgress = true; | |
| 174 | // set previously requested priority | ||
| 175 | ✗ | this->dpContainer.setPriority(this->dpPriority); | |
| 176 | ✗ | this->dpContainer.setProcTypes(this->dpProc); | |
| 177 | ✗ | this->log_ACTIVITY_LO_DpStarted(this->numRecords); | |
| 178 | ✗ | this->cmdResponse_out(this->pendingOpCode, this->pendingCmdSeq, Fw::CmdResponse::OK); | |
| 179 | } else { | ||
| 180 | ✗ | this->log_WARNING_HI_DpMemoryFail(); | |
| 181 | // cleanup | ||
| 182 | ✗ | this->dpInProgress = false; | |
| 183 | ✗ | this->numRecords = 0; | |
| 184 | ✗ | this->cmdResponse_out(this->pendingOpCode, this->pendingCmdSeq, Fw::CmdResponse::EXECUTION_ERROR); | |
| 185 | } | ||
| 186 | ✗ | } | |
| 187 | |||
| 188 | 2 | void DpDemo ::cleanupAndSendDp() { | |
| 189 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | this->dpSend(this->dpContainer); |
| 190 | 2 | this->dpInProgress = false; | |
| 191 | 2 | this->numRecords = 0; | |
| 192 | 2 | } | |
| 193 | |||
| 194 | } // namespace Ref | ||
| 195 |