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
introduce SCPI_HelpQ
add SCPI_HelpQ callback , optional .description strings and provide conditional initializer macros dependent on config settings for USE_COMMAND_TAGS and USE_COMMAND_DESCRIPTIONS.
  • Loading branch information
MisterHW committed Feb 3, 2022
commit bc4f1d5069655e9166f09d84030f538a2c114cdb
15 changes: 15 additions & 0 deletions examples/common/scpi-def.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,22 @@ static scpi_result_t My_CoreTstQ(scpi_t * context) {
return SCPI_RES_OK;
}

#if USE_COMMAND_DESCRIPTIONS
#define SCPI_CMD_DESC(S) .description=(S),
#else
#define SCPI_CMD_DESC(S)
#endif

#if USE_COMMAND_TAGS
#define SCPI_CMD_TAG(T) .tag=(T),
#else
#define SCPI_CMD_TAG(T)
#endif

const scpi_command_t scpi_commands[] = {
/* Optional help commmand */
{.pattern = "HELP?", .callback = SCPI_HelpQ, SCPI_CMD_DESC("\t - list supported commands")},

/* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */
{ .pattern = "*CLS", .callback = SCPI_CoreCls,},
{ .pattern = "*ESE", .callback = SCPI_CoreEse,},
Expand Down
105 changes: 60 additions & 45 deletions examples/common/scpi-def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,60 +353,75 @@ static scpi_result_t My_CoreTstQ(scpi_t * context) {
return SCPI_RES_OK;
}

#if USE_COMMAND_DESCRIPTIONS
#define SCPI_CMD_DESC(S) (S),
#else
#define SCPI_CMD_DESC(S)
#endif

#if USE_COMMAND_TAGS
#define SCPI_CMD_TAG(T) (T),
#else
#define SCPI_CMD_TAG(T)
#endif

const scpi_command_t scpi_commands[] = {
/* Optional help command */
{"HELP?", SCPI_HelpQ, SCPI_CMD_DESC("\t - list supported commands") SCPI_CMD_TAG(0)},

/* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */
{"*CLS", SCPI_CoreCls, 0},
{"*ESE", SCPI_CoreEse, 0},
{"*ESE?", SCPI_CoreEseQ, 0},
{"*ESR?", SCPI_CoreEsrQ, 0},
{"*IDN?", SCPI_CoreIdnQ, 0},
{"*OPC", SCPI_CoreOpc, 0},
{"*OPC?", SCPI_CoreOpcQ, 0},
{"*RST", SCPI_CoreRst, 0},
{"*SRE", SCPI_CoreSre, 0},
{"*SRE?", SCPI_CoreSreQ, 0},
{"*STB?", SCPI_CoreStbQ, 0},
{"*TST?", My_CoreTstQ, 0},
{"*WAI", SCPI_CoreWai, 0},
{"*CLS", SCPI_CoreCls, SCPI_CMD_TAG(0)},
{"*ESE", SCPI_CoreEse, SCPI_CMD_TAG(0)},
{"*ESE?", SCPI_CoreEseQ, SCPI_CMD_TAG(0)},
{"*ESR?", SCPI_CoreEsrQ, SCPI_CMD_TAG(0)},
{"*IDN?", SCPI_CoreIdnQ, SCPI_CMD_TAG(0)},
{"*OPC", SCPI_CoreOpc, SCPI_CMD_TAG(0)},
{"*OPC?", SCPI_CoreOpcQ, SCPI_CMD_TAG(0)},
{"*RST", SCPI_CoreRst, SCPI_CMD_TAG(0)},
{"*SRE", SCPI_CoreSre, SCPI_CMD_TAG(0)},
{"*SRE?", SCPI_CoreSreQ, SCPI_CMD_TAG(0)},
{"*STB?", SCPI_CoreStbQ, SCPI_CMD_TAG(0)},
{"*TST?", My_CoreTstQ, SCPI_CMD_TAG(0)},
{"*WAI", SCPI_CoreWai, SCPI_CMD_TAG(0)},

/* Required SCPI commands (SCPI std V1999.0 4.2.1) */
{"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, 0},
{"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, 0},
{"SYSTem:VERSion?", SCPI_SystemVersionQ, 0},
{"SYSTem:ERRor[:NEXT]?", SCPI_SystemErrorNextQ, SCPI_CMD_TAG(0)},
{"SYSTem:ERRor:COUNt?", SCPI_SystemErrorCountQ, SCPI_CMD_TAG(0)},
{"SYSTem:VERSion?", SCPI_SystemVersionQ, SCPI_CMD_TAG(0)},

//{"STATus:OPERation?", scpi_stub_callback, 0},
//{"STATus:OPERation:EVENt?", scpi_stub_callback, 0},
//{"STATus:OPERation:CONDition?", scpi_stub_callback, 0},
//{"STATus:OPERation:ENABle", scpi_stub_callback, 0},
//{"STATus:OPERation:ENABle?", scpi_stub_callback, 0},
//{"STATus:OPERation?", scpi_stub_callback, SCPI_CMD_TAG(0)},
//{"STATus:OPERation:EVENt?", scpi_stub_callback, SCPI_CMD_TAG(0)},
//{"STATus:OPERation:CONDition?", scpi_stub_callback, SCPI_CMD_TAG(0)},
//{"STATus:OPERation:ENABle", scpi_stub_callback, SCPI_CMD_TAG(0)},
//{"STATus:OPERation:ENABle?", scpi_stub_callback, SCPI_CMD_TAG(0)},

{"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, 0},
//{"STATus:QUEStionable:CONDition?", scpi_stub_callback, 0},
{"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, 0},
{"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, 0},
{"STATus:QUEStionable[:EVENt]?", SCPI_StatusQuestionableEventQ, SCPI_CMD_TAG(0)},
//{"STATus:QUEStionable:CONDition?", scpi_stub_callback, SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle", SCPI_StatusQuestionableEnable, SCPI_CMD_TAG(0)},
{"STATus:QUEStionable:ENABle?", SCPI_StatusQuestionableEnableQ, SCPI_CMD_TAG(0)},

{"STATus:PRESet", SCPI_StatusPreset, 0},
{"STATus:PRESet", SCPI_StatusPreset, SCPI_CMD_TAG(0)},

/* DMM */
{"MEASure:VOLTage:DC?", DMM_MeasureVoltageDcQ, 0},
{"CONFigure:VOLTage:DC", DMM_ConfigureVoltageDc, 0},
{"MEASure:VOLTage:DC:RATio?", SCPI_StubQ, 0},
{"MEASure:VOLTage:AC?", DMM_MeasureVoltageAcQ, 0},
{"MEASure:CURRent:DC?", SCPI_StubQ, 0},
{"MEASure:CURRent:AC?", SCPI_StubQ, 0},
{"MEASure:RESistance?", SCPI_StubQ, 0},
{"MEASure:FRESistance?", SCPI_StubQ, 0},
{"MEASure:FREQuency?", SCPI_StubQ, 0},
{"MEASure:PERiod?", SCPI_StubQ, 0},

{"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, 0},

{"TEST:BOOL", TEST_Bool, 0},
{"TEST:CHOice?", TEST_ChoiceQ, 0},
{"TEST#:NUMbers#", TEST_Numbers, 0},
{"TEST:TEXT", TEST_Text, 0},
{"TEST:ARBitrary?", TEST_ArbQ, 0},
{"TEST:CHANnellist", TEST_Chanlst, 0},
{"MEASure:VOLTage:DC?", DMM_MeasureVoltageDcQ, SCPI_CMD_TAG(0)},
{"CONFigure:VOLTage:DC", DMM_ConfigureVoltageDc, SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:DC:RATio?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:VOLTage:AC?", DMM_MeasureVoltageAcQ, SCPI_CMD_TAG(0)},
{"MEASure:CURRent:DC?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:CURRent:AC?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:RESistance?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:FRESistance?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:FREQuency?", SCPI_StubQ, SCPI_CMD_TAG(0)},
{"MEASure:PERiod?", SCPI_StubQ, SCPI_CMD_TAG(0)},

{"SYSTem:COMMunication:TCPIP:CONTROL?", SCPI_SystemCommTcpipControlQ, SCPI_CMD_TAG(0)},

{"TEST:BOOL", TEST_Bool, SCPI_CMD_TAG(0)},
{"TEST:CHOice?", TEST_ChoiceQ, SCPI_CMD_TAG(0)},
{"TEST#:NUMbers#", TEST_Numbers, SCPI_CMD_TAG(0)},
{"TEST:TEXT", TEST_Text, SCPI_CMD_TAG(0)},
{"TEST:ARBitrary?", TEST_ArbQ, SCPI_CMD_TAG(0)},
{"TEST:CHANnellist", TEST_Chanlst, SCPI_CMD_TAG(0)},

SCPI_CMD_LIST_END
};
Expand Down
4 changes: 4 additions & 0 deletions libscpi/inc/scpi/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ extern "C" {
#define USE_COMMAND_TAGS 1
#endif

#ifndef USE_COMMAND_DESCRIPTIONS
#define USE_COMMAND_DESCRIPTIONS 1
#endif

#ifndef USE_DEPRECATED_FUNCTIONS
#define USE_DEPRECATED_FUNCTIONS 1
#endif
Expand Down
2 changes: 1 addition & 1 deletion libscpi/inc/scpi/minimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern "C" {
scpi_result_t SCPI_StatusOperationEnableQ(scpi_t * context);
scpi_result_t SCPI_StatusOperationEnable(scpi_t * context);
scpi_result_t SCPI_StatusPreset(scpi_t * context);

scpi_result_t SCPI_HelpQ(scpi_t * context);
MisterHW marked this conversation as resolved.
Show resolved Hide resolved

#ifdef __cplusplus
}
Expand Down
13 changes: 10 additions & 3 deletions libscpi/inc/scpi/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ extern "C" {

typedef struct _scpi_command_t scpi_command_t;

#if USE_COMMAND_TAGS
#define SCPI_CMD_LIST_END {NULL, NULL, 0}
#if USE_COMMAND_DESCRIPTIONS && USE_COMMAND_TAGS
MisterHW marked this conversation as resolved.
Show resolved Hide resolved
#define SCPI_CMD_LIST_END {NULL, NULL, NULL, 0}
#elif USE_COMMAND_DESCRIPTIONS
#define SCPI_CMD_LIST_END {NULL, NULL, NULL}
#elif USE_COMMAND_TAGS
#define SCPI_CMD_LIST_END {NULL, NULL, 0}
#else
#define SCPI_CMD_LIST_END {NULL, NULL}
#define SCPI_CMD_LIST_END {NULL, NULL}
#endif


Expand Down Expand Up @@ -351,6 +355,9 @@ extern "C" {
struct _scpi_command_t {
const char * pattern;
scpi_command_callback_t callback;
#if USE_COMMAND_DESCRIPTIONS
const char * description;
#endif /* USE_COMMAND_DESCRIPTIONS */
#if USE_COMMAND_TAGS
int32_t tag;
#endif /* USE_COMMAND_TAGS */
Expand Down
33 changes: 33 additions & 0 deletions libscpi/src/minimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,36 @@ scpi_result_t SCPI_StatusPreset(scpi_t * context) {
SCPI_RegSet(context, SCPI_REG_QUES, 0);
return SCPI_RES_OK;
}

/**
* HELP?
* @param context
* @return
*/
scpi_result_t SCPI_HelpQ(scpi_t * context) {
int i = 0;
for(;;) {
size_t pattern_len = strlen(context->cmdlist[i].pattern);
size_t block_len = 1 + pattern_len + strlen(SCPI_LINE_ENDING);
#if USE_COMMAND_DESCRIPTIONS
size_t description_len = context->cmdlist[i].description ? strlen(context->cmdlist[i].description) : 0;
if(description_len > 0){
block_len = 1 + pattern_len + 1 + description_len + strlen(SCPI_LINE_ENDING);
}
#endif
SCPI_ResultArbitraryBlockHeader(context, block_len);
SCPI_ResultArbitraryBlockData(context, "\t", 1);
SCPI_ResultArbitraryBlockData(context, context->cmdlist[i].pattern, pattern_len);
#if USE_COMMAND_DESCRIPTIONS
if(description_len > 0){
SCPI_ResultArbitraryBlockData(context, " ", 1);
SCPI_ResultArbitraryBlockData(context, context->cmdlist[i].description, description_len);
}
#endif
SCPI_ResultArbitraryBlockData(context, SCPI_LINE_ENDING, strlen(SCPI_LINE_ENDING));
if (context->cmdlist[++i].pattern == NULL) {
break;
}
}
return SCPI_RES_OK;
}