Creating Components Part 2: Implementing MathSender Behavior
In this section
In this section you will edit MathSender.cpp
to implement the desired component behavior.
As a reminder, below is the component behavior you are trying to implement in this section of the tutorial.
Component Description
The MathSender
is going to be an active component which will receive parameters, send parameters, log events, and send telemetry.
Editing the Do Math Command Handler
The handler DO_MATH_handler
is called when the MathSender
component receives a DO_MATH
command. This handler overrides the corresponding pure virtual function in the auto-generated base class. Fill in the handler so that it looks like this:
// In: MathSender.cpp
void MathSender ::
DO_MATH_cmdHandler(
const FwOpcodeType opCode,
const U32 cmdSeq,
F32 val1,
MathOp op,
F32 val2
)
{
this->tlmWrite_VAL1(val1);
this->tlmWrite_OP(op);
this->tlmWrite_VAL2(val2);
this->log_ACTIVITY_LO_COMMAND_RECV(val1, op, val2);
this->mathOpOut_out(0, val1, op, val2);
this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
}
Explanation
The first two arguments to the handler function provide the command opcode and the command sequence number (a unique identifier generated by the command dispatcher). The remaining arguments are supplied when the command is sent, for example, from the F Prime ground data system (GDS). The implementation code does the following:
-
Emit telemetry and events.
-
Invoke the
mathOpOut
port to request thatMathReceiver
perform the operation. -
Send a command response indicating success. The command response goes out on the special port
cmdResponseOut
.
In F Prime, every execution of a command handler must end by sending a command response. The proper behavior of other framework components (e.g., command dispatcher, command sequencer) depends upon adherence to this rule.
Check the build using:
# In: MathSender
fprime-util build
Editing the Result Handler
The handler mathResultIn_handler
is called when the MathReceiver
component code returns a result by invoking the mathResultIn
port. Again the handler overrides the corresponding pure virtual function in the auto-generated base class. Fill in the handler so that it looks like this:
// In: MathSender.cpp
void MathSender ::
mathResultIn_handler(
const NATIVE_INT_TYPE portNum,
F32 result
)
{
this->tlmWrite_RESULT(result);
this->log_ACTIVITY_HI_RESULT(result);
}
Explanation
The implementation code emits the result on the RESULT
telemetry channel and as a RESULT
event report.
Check the build using:
# In: MathSender
fprime-util build
Summary
Congratulations, you have completed MathSender
! Well… there’s always more to be done, such as error handling, adding more telemetry,
creating more events, and generally messing around with what MathSender
can do. But for the purposes of getting a deployment
working, this component is done!