Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocoded function for invoking all connected input and output ports #3043

Open
Jmb5501 opened this issue Nov 22, 2024 · 3 comments
Open

Autocoded function for invoking all connected input and output ports #3043

Jmb5501 opened this issue Nov 22, 2024 · 3 comments
Labels
enhancement FPP Issues related to FPP

Comments

@Jmb5501
Copy link

Jmb5501 commented Nov 22, 2024

Affected Component All user-define components

Feature Description

It would be incredibly helpful for developers to have access to an autocoded function in each component's base class that invokes all connected input and output ports. I think the function could look like the following for output ports:

void ComponentBase::invokeAll<port>()
{
    // Loop through all connected output ports and invoke them
    for (unsigned int ii= 0; port < NUM_<port>_OUTPUT_PORTS; ii++)
    {
        if (true == this->isConnected_<port>_OutputPort(ii))
        {
            this-><port>_out(ii);
        }
    }
}

Rationale

This would streamline a developer's code and reduce the amount of copy-pasting of code templates that is needed with the current version of Fprime. This seems like a very simple thing that could be developed.

@thomas-bc
Copy link
Collaborator

thomas-bc commented Nov 22, 2024

Ports may need different arguments so I'm not sure how you would resolve that.

Could you elaborate on your use case?

You can always handcode that invokeAll() helper function and use it at will, configuring yourself which ports get invoked and what parameters to use.

@LeStarch
Copy link
Collaborator

I think this is meant for port arrays, where you might want to broadcast out to all connected ports. e.g.

broadcast_modeChange_out(Mode new_mode) {
    for ....
} 

It is an interesting idea. It does add more autocode, but reduces hand-written code in key circumstances.

@matt392code
Copy link
Contributor

port-invoke-helper.txt
Let's analyze this request for an autocoded port invocation helper. The concept needs to handle several cases:

This solution provides:

  1. Template-based Port Invocation
  • Handles any port type
  • Supports variable arguments
  • Type-safe parameter passing
  1. Two Invocation Modes
// Simple broadcast
invokeAll(component, numPorts, portInvoker, args...)

// With status collection
invokeAllWithStatus(component, numPorts, portInvoker, statuses, args...)
  1. Safety Features
  • Connection checking
  • Port range validation
  • Status collection option
  1. Usage Example for Autocode Generation:
// In component FPP
array ModeOut[3]
array CmdOut[5]

// Generated helper methods
void broadcastMode_out(const Mode& mode);
void broadcastCommand_out(const CmdPacket& cmd, 
                         Fw::SerializeableVector<ReturnStatus>& statuses);

@bocchino bocchino added the FPP Issues related to FPP label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement FPP Issues related to FPP
Projects
None yet
Development

No branches or pull requests

5 participants