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

introduce SCPI_HelpQ with descriptions #135

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
28b17f7
output block data with delimiter
MisterHW Feb 1, 2022
8ed2623
fix typos
MisterHW Feb 2, 2022
bc4f1d5
introduce SCPI_HelpQ
MisterHW Feb 3, 2022
315f20d
introduce help search
MisterHW Feb 7, 2022
159fe83
drop C++20 keyword
MisterHW Feb 7, 2022
d099d9a
rename to USE_HELP_FILTER
MisterHW Feb 7, 2022
aa660db
fix expression
MisterHW Feb 7, 2022
1460793
add full command descriptions to examples common def, set desc. defau…
MisterHW Jan 6, 2023
7d0c83d
clean-up
MisterHW Jan 7, 2023
c394eb9
propagate MODE to Makefile for cross-compiling
MisterHW Jan 7, 2023
1e1b594
provide more elaborate description depending on USE_HELP_FILTER
MisterHW Jan 14, 2023
f7c4cc4
Merge branch 'j123b567:master' into scpi_helpq_enhancement
MisterHW Jan 16, 2023
b3668be
Merge branch 'j123b567:master' into scpi_helpq_enhancement
MisterHW Jan 17, 2023
36ddafe
strncasestr, strncasestrn_s, pp_xstr clean-up and formatting
MisterHW Jan 17, 2023
9c66dcd
fix C89 issue (FALSE, for syntax)
MisterHW Jan 17, 2023
0e7c828
remove strcasestr
MisterHW Jan 17, 2023
5dfac2b
strncasecmp -> SCPIDEFINE_strncasecmp
MisterHW Jan 17, 2023
5153e03
C style comments
MisterHW Jan 17, 2023
8aa90a7
split off HELP? into help.h/.c
MisterHW Jan 17, 2023
31a3e44
add help.c, help.h to Makefile
MisterHW Jan 17, 2023
d8a5d24
redo delete SCPI_HelpQ
MisterHW Jan 17, 2023
63f5e88
Revert "propagate MODE to Makefile for cross-compiling"
MisterHW Jan 17, 2023
d803ffe
simply SCPI_CMD_LIST_END definition
MisterHW Jan 17, 2023
a44b9aa
add missing ,
MisterHW Jan 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
strncasestr, strncasestrn_s, pp_xstr clean-up and formatting
remove / comment currently unused code. Double-indirection helper definition moved to utils.h.
  • Loading branch information
MisterHW committed Jan 17, 2023
commit 36ddafecf41f52ef016e310ef5f2edf0afc9a3f7
3 changes: 0 additions & 3 deletions examples/common/scpi-def.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,6 @@ static scpi_result_t My_CoreTstQ(scpi_t * context) {
return SCPI_RES_OK;
}

#define pp_xstr(s) pp_str(s)
#define pp_str(s) #s
#define SCPI_ERROR_QUEUE_SIZE_STR pp_xstr(SCPI_ERROR_QUEUE_SIZE)

const scpi_command_t scpi_commands[] = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide alternative definition files for this functionality?

It is a generally useful but unusual extension. I would like to keep examples simple. Users can decide on their own if they would like to use help command or not and it is generally not needed. It will find its way, but I would like to keep the first impression simple.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, somehow divide the existing source (it is just an example anyway) so one part of the commands has help and the other does not so it is clear, that it is not mandatory to use and define help and tag.

Copy link
Contributor Author

@MisterHW MisterHW Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scpi-def.c and scpi-def.cpp are essentially identical. scpi-def.c could be stripped down to illustrate what a version with no help and no command tags could look like. One could additionally introduce

#define NO_CMD_DESC SCPI_CMD_DESC(NULL)

which would help being explicit about the generalized structure. With scpi-def being in common, offering definitions for all possible cases seems a bit excessive to me.

Retrospective Context:
Keep in mind that prior to this PR, the default was

#define USE_COMMAND_TAGS 1

and setting it to 0 would cause a type mismatch, as in scpi-def.c/.cpp there were extra (unconditional) , 0 in the scpi_commands[] items.

The documentation on HELP? might be the best place to elaborate on way to further strip down the definition and explain the implications. This was warrented through the existence of USE_COMMAND_TAGS, and in my opinion is underscored yet again through the introduction of USE_COMMAND_DESCRIPTIONS.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, scpi-def.cpp is identical to the scpi-def.c but all C specific features are removed so it can be compiled by the C++ compiler. Because this is C library, C++ file is just an example without real usage here.

Initially, examples were more about the communication interface and the command interface was the same. In the current perspective, there could be more standalone examples promoting separate features of the library, like enabling/disabling TAGs, and more importantly, introducing HELP? command.

Maybe, there can be a new example based on e.g. test-interactive to show, how HELP? command works and how to define all strings. It can have a completely different structure and its own commands definition.

/* Optional help command */
Expand Down
3 changes: 0 additions & 3 deletions examples/common/scpi-def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,6 @@ static scpi_result_t My_CoreTstQ(scpi_t * context) {
return SCPI_RES_OK;
}

#define pp_xstr(s) pp_str(s)
#define pp_str(s) #s
#define SCPI_ERROR_QUEUE_SIZE_STR pp_xstr(SCPI_ERROR_QUEUE_SIZE)

const scpi_command_t scpi_commands[] = {
/* Optional help command */
Expand Down
2 changes: 2 additions & 0 deletions examples/common/scpi-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ extern "C" {
#define SCPI_IDN3 NULL
#define SCPI_IDN4 "01-02"

#define SCPI_ERROR_QUEUE_SIZE_STR PP_XSTR(SCPI_ERROR_QUEUE_SIZE)

extern const scpi_command_t scpi_commands[];
extern scpi_interface_t scpi_interface;
extern char scpi_input_buffer[];
Expand Down
1 change: 0 additions & 1 deletion libscpi/inc/scpi/minimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ extern "C" {
#endif

#endif /* SCPI_MINIMAL_H */

6 changes: 5 additions & 1 deletion libscpi/inc/scpi/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ extern "C" {
/* deprecated finction, should be removed later */
#define SCPI_LongToStr(val, str, len, base) SCPI_Int32ToStr((val), (str), (len), (base), TRUE)

/* Pre-Processor Transform String (double indirection PP_XSTR(s) converts a number definition into a string definiton) */
#define PP_STR(s) #s
#define PP_XSTR(s) PP_STR(s)


#ifdef __cplusplus
}
#endif

#endif /* SCPI_UTILS_H */

22 changes: 11 additions & 11 deletions libscpi/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1182,14 +1182,14 @@ char * strncasestrn (const char *s, size_t slen, const char *find, size_t findle
return (char *)s;
}

/**
* @brief Locate a substring in a binary string (case-insensitive `strnstr`).
* @param[in] s binary string
* @param[in] find substring (zero-terminated)
* @param[in] slen length of binary string s
* @return Pointer to first match in s if found, otherwise `NULL`.
*/
char * strncasestr (const char *s, const char *find, size_t slen)
{
return strncasestrn (s, slen, find, strlen(find));
}
#/**
# * @brief Locate a substring in a binary string (case-insensitive `strnstr`).
# * @param[in] s binary string
# * @param[in] find substring (zero-terminated)
# * @param[in] slen length of binary string s
# * @return Pointer to first match in s if found, otherwise `NULL`.
# */
#char * strncasestr (const char *s, const char *find, size_t slen)
#{
# return strncasestrn (s, slen, find, strlen(find));
#}
6 changes: 1 addition & 5 deletions libscpi/src/utils_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,8 @@ extern "C" {
char *OUR_strndup(const char *s, size_t n);
#endif

char * strncasestr (const char *s, const char *find, size_t slen);
char * strncasestrn (const char *s, size_t slen, const char *find, size_t findlen);

#ifndef strncasestrn_s
#define strncasestrn_s(s,s_len,lit) strncasestrn(s, s_len, lit, sizeof(lit)-1)
#endif
# char * strncasestr (const char *s, const char *find, size_t slen);

#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
Expand Down