Skip to content

Commit 39227f6

Browse files
committed
tom_modem: enhance user input parsing and update usage instructions
1 parent 31a6343 commit 39227f6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

application/tom_modem/src/main.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include "main.h"
32

43
FDS_T s_fds;
@@ -7,11 +6,28 @@ PROFILE_T s_profile; // global profile
76
int parse_user_input(int argc, char *argv[], PROFILE_T *profile)
87
{
98
int opt = 1;
9+
int anonymous_arg = 0;
1010
int option;
1111
profile->sms_index = -1;
1212
#define has_more_argv() (opt < argc ? 1 : 0)
1313
while (opt < argc)
1414
{
15+
if (argv[opt][0] != '-') {
16+
if (anonymous_arg == 0) {
17+
profile->tty_dev = argv[opt];
18+
}
19+
if (anonymous_arg == 1){
20+
profile->at_cmd = argv[opt];
21+
}
22+
if (anonymous_arg >= 2) {
23+
err_msg("Too many anonymous arguments");
24+
return INVALID_PARAM;
25+
}
26+
anonymous_arg++;
27+
opt++;
28+
continue;
29+
}
30+
1531
option = match_option(argv[opt]);
1632
if (option == -1)
1733
{
@@ -120,7 +136,13 @@ int parse_user_input(int argc, char *argv[], PROFILE_T *profile)
120136
break;
121137
}
122138
}
139+
123140
// default settings:
141+
if (profile->tty_dev == NULL)
142+
{
143+
usage(argv[0]);
144+
return INVALID_PARAM;
145+
}
124146
if (profile->baud_rate == 0 )
125147
{
126148
profile->baud_rate = 115200;

application/tom_modem/src/utils.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ void escape_json(char *input, char *output)
390390
int usage(char* name)
391391
{
392392
err_msg("Usage: %s [options]", name);
393+
err_msg("Or %s [device_path] [AT command]", name);
394+
err_msg("Or %s [device_path] [operation]", name);
393395
err_msg("Options:");
394396
err_msg(" -c, --at_cmd <AT command> AT command");
395397
err_msg(" -d, --tty_dev <TTY device> TTY device **REQUIRED**");

0 commit comments

Comments
 (0)