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

Support passing arguments via serial CLI to external FAPs #2505

Closed
str4d opened this issue Mar 17, 2023 · 2 comments
Closed

Support passing arguments via serial CLI to external FAPs #2505

str4d opened this issue Mar 17, 2023 · 2 comments
Assignees
Labels
Core+Services HAL, furi & core system services New Feature Contains an IMPLEMENTATION of a new feature

Comments

@str4d
Copy link

str4d commented Mar 17, 2023

All applications that aren't run on startup are required to have an entry point of the form int32_t entry_point(void* p):

def get_app_ep_forward(self, app: FlipperApplication):
if app.apptype == FlipperAppType.STARTUP:
return f"extern void {app.entry_point}();"
return f"extern int32_t {app.entry_point}(void* p);"

This implies that some kind of context or arguments object is provided by the Flipper Zero to the app via the void* p. This appears to be the case for built-in apps; for example, the iButton app checks if p is a C string, and then parses it:

int32_t ibutton_app(void* p) {
iButton* ibutton = ibutton_alloc();
ibutton_make_app_folder(ibutton);
bool key_loaded = false;
bool rpc_mode = false;
if(p && strlen(p)) {
uint32_t rpc_ctx = 0;
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
FURI_LOG_D(TAG, "Running in RPC mode");
ibutton->rpc_ctx = (void*)rpc_ctx;
rpc_mode = true;
rpc_system_app_set_callback(ibutton->rpc_ctx, ibutton_rpc_command_callback, ibutton);
rpc_system_app_send_started(ibutton->rpc_ctx);
} else {
furi_string_set(ibutton->file_path, (const char*)p);
if(ibutton_load_key_data(ibutton, ibutton->file_path, true)) {
key_loaded = true;
// TODO: Display an error if the key from p could not be loaded
}
}
}

However, when running an external FAP from the serial CLI, providing arguments causes it to fail to start:

> loader open Applications /path/to/the.fap some args
// On screen
Error
Preload failed
Invalid file

Allowing arguments to be passed when starting via the serial CLI would enable external FAPs to act similarly to built-in CLI apps (albeit with the loader open Applications prefix).

Alternatively, if there were a way for an external FAP to register a CLI interface (like is often done in apps with type FlipperAppType.STARTUP), that would satisfy the use case. However, I suspect this would be trickier as it would require scanning the entire directory tree to find external FAPs to register in this way, so passing arguments directly to the external FAP is likely to be simpler.

@hedger
Copy link
Member

hedger commented Mar 17, 2023

Yep, we're also planning on implementing fixes to add RPC communication to .faps.

@skotopes skotopes added New Feature Contains an IMPLEMENTATION of a new feature Core+Services HAL, furi & core system services labels Mar 20, 2023
@str4d
Copy link
Author

str4d commented Aug 11, 2023

AFAICT this is supported after the FAP loader refactor in 0.86.1: because the loader is now doing the FAP loading, its argument handling Just Works. Thanks!

@str4d str4d closed this as completed Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core+Services HAL, furi & core system services New Feature Contains an IMPLEMENTATION of a new feature
Projects
None yet
Development

No branches or pull requests

3 participants