Skip to content

Add commands to tokenizer for "options" in command line#2024

Open
MaxineMuster wants to merge 3 commits intoopenshwprojects:mainfrom
MaxineMuster:_tokenizer
Open

Add commands to tokenizer for "options" in command line#2024
MaxineMuster wants to merge 3 commits intoopenshwprojects:mainfrom
MaxineMuster:_tokenizer

Conversation

@MaxineMuster
Copy link
Copy Markdown
Contributor

I often struggle on the parameters order e.g. when starting a driver like AHT2x:
is it <sda> <scl> <channel temp> <channel hum> ?
or <scl> <sda> <channel hum> <channel temp> ?
or ...

So I like a call with "named" arguments like

SDA=17 SCL=19 chan_h=3 chan_t=4
which is totally equal to
chan_h=3 SCL=19 chan_t=4 SDA=17

So I tried to add some "useful" extension to tokenizer code to allow this sort of arguments.

With this change you can check for options like this:

SDA=<pin-ID or pin name> / type=SHT4x / chan_t=<channel>
   or even str="a string"     // use new TOKENIZER_ALLOW_QUOTES_IN_NAMEDARG_VALUE for this

-SCL <pin-ID or pin name> / -type SHT3x / chan_h <channel>
   or -str "another string"    // will "only" need TOKENIZER_ALLOW_QUOTES

new command are (all will need a default in case the option is not found):
  const char *Tokenizer_GetArgEqualDefault(const char *search, const char *def);
  int Tokenizer_GetArgEqualInteger(const char *search, const int def);
  int Tokenizer_GetPinEqual(const char *search, const int def);

You can also check for a "single" option (like "-v" or "-single_mode")
  bool Tokenizer_IsStringPresent(const char *search);

Added selftest for the new commands, too.

You can check for options like

SDA=<pin-ID or pin name> / type=SHT4x / chan_t=<channel>
	or even  str="a string" 				// use new TOKENIZER_ALLOW_QUOTES_IN_NAMEDARG_VALUE for this

-SCL <pin-ID or pin name> / -type SHT3x / chan_h <channel>
	or even  -str "another string" 				// will "only" need TOKENIZER_ALLOW_QUOTES

new command are (all will need a default in case the option is not found):
	const char *Tokenizer_GetArgEqualDefault(const char *search, const char *def);
	int Tokenizer_GetArgEqualInteger(const char *search, const int def);
	int Tokenizer_GetPinEqual(const char *search, const int def);

You can also check for a "single" option (like "-v" or "-single_mode")
	bool Tokenizer_IsStringPresent(const char *search);

Added selftest for the new commands, too.
Changed to minimized version, only allowing to serch for args like "-SDA P16"
Only one new funktion, all others are "#defines" in default but can be compiled as functions using "#define TOKENIZER_PARAM_EXTENSION 1"
@MaxineMuster
Copy link
Copy Markdown
Contributor Author

Streamlined and minimized addition:

Now only args like "-SDA 4 -SCL P5" are possible (removed "XY=9" style)

Only one new function, all others as "optional" functions (enable with "#define TOKENIZER_PARAM_EXTENSION 1"), else they can be used as #defines using the one new function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant