From 39227f66d02a919668d0f0803da4c6bf784f8a23 Mon Sep 17 00:00:00 2001 From: fujr Date: Tue, 22 Apr 2025 17:53:36 +0800 Subject: [PATCH] tom_modem: enhance user input parsing and update usage instructions --- application/tom_modem/src/main.c | 24 +++++++++++++++++++++++- application/tom_modem/src/utils.c | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/application/tom_modem/src/main.c b/application/tom_modem/src/main.c index 8c076b0..36a4826 100644 --- a/application/tom_modem/src/main.c +++ b/application/tom_modem/src/main.c @@ -1,4 +1,3 @@ - #include "main.h" FDS_T s_fds; @@ -7,11 +6,28 @@ PROFILE_T s_profile; // global profile int parse_user_input(int argc, char *argv[], PROFILE_T *profile) { int opt = 1; + int anonymous_arg = 0; int option; profile->sms_index = -1; #define has_more_argv() (opt < argc ? 1 : 0) while (opt < argc) { + if (argv[opt][0] != '-') { + if (anonymous_arg == 0) { + profile->tty_dev = argv[opt]; + } + if (anonymous_arg == 1){ + profile->at_cmd = argv[opt]; + } + if (anonymous_arg >= 2) { + err_msg("Too many anonymous arguments"); + return INVALID_PARAM; + } + anonymous_arg++; + opt++; + continue; + } + option = match_option(argv[opt]); if (option == -1) { @@ -120,7 +136,13 @@ int parse_user_input(int argc, char *argv[], PROFILE_T *profile) break; } } + // default settings: + if (profile->tty_dev == NULL) + { + usage(argv[0]); + return INVALID_PARAM; + } if (profile->baud_rate == 0 ) { profile->baud_rate = 115200; diff --git a/application/tom_modem/src/utils.c b/application/tom_modem/src/utils.c index 0e0ae9e..872d4a3 100644 --- a/application/tom_modem/src/utils.c +++ b/application/tom_modem/src/utils.c @@ -390,6 +390,8 @@ void escape_json(char *input, char *output) int usage(char* name) { err_msg("Usage: %s [options]", name); + err_msg("Or %s [device_path] [AT command]", name); + err_msg("Or %s [device_path] [operation]", name); err_msg("Options:"); err_msg(" -c, --at_cmd AT command"); err_msg(" -d, --tty_dev TTY device **REQUIRED**");