scpi-parser icon indicating copy to clipboard operation
scpi-parser copied to clipboard

introduce SCPI_HelpQ with descriptions

Open MisterHW opened this issue 3 years ago • 5 comments

Human-readability is often a welcome aspect when developing software for SCPI devices, but also valuable when testing configurations or debugging issues in a lab or test setup. Command syntax and parameter ranges are traditionally only documented in manuals or programmer's guides, but often control software allows sending raw commands and performing queries.

To both help people implementing and using systems based on scpi-parser and to help projects stand the test of time, it seems valuable for the device to be able to list its supported commands, preferably with a short description exposing expected parameter types and ranges.

This PR provides

  • SCPI_HelpQ() callback for a "HELP?" pattern and a
  • USE_COMMAND_DESCRIPTIONS option which extends _scpi_command_t by a description string.

Data returned is formatted as an array of arbitrary block data. Newline characters are absorbed into the data of each block so the output is easily readable and can be parsed and displayed in control software (e.g. to provide a list of commands or syntax help).

Usage of the new features is demonstrated in the common example code.

image

The first column seen in the screenshot originates from the necessary block header information.

Memory Use

Backward compatibility is provided by setting USE_COMMAND_DESCRIPTIONS 0, not using SCPI_HelpQ() and if needed, by instructing the linker to drop unused sections (--gc-sections). Even with USE_COMMAND_DESCRIPTIONS 0, the help command can provide value by accessing the pattern strings already in place. When setting USE_COMMAND_DESCRIPTIONS 1 , _scpi_command_t is exended by a pointer (default: nullptr) to a null-terminated description string.

resolves #129

MisterHW avatar Feb 03 '22 13:02 MisterHW

Coverage Status

Coverage: 91.844% (-0.8%) from 92.594% when pulling a44b9aa12ee7f8b94f580cf32e4870a79bff95d2 on MisterHW:scpi_helpq_enhancement into e882505c642ad2592b51f912b0dac0ed806384a1 on j123b567:master.

coveralls avatar Jan 17 '23 11:01 coveralls

Yeah well, C89 build fails because strncasecmp() was introduced later.

MisterHW avatar Jan 17 '23 14:01 MisterHW

Unfortunately, some manufacturers stick to C89 for their compilers (e.g. Microchip was using a prehistoric compiler for PIC32. Newer version is now available but hard to adopt because of frequent and incompatible changes in their core libraries)

j123b567 avatar Jan 17 '23 15:01 j123b567

You can use use SCPIDEFINE_strncasecmp instead of strncasecmp. It is already provided by the library.

j123b567 avatar Jan 17 '23 15:01 j123b567

I will get back to this eventually :)

MisterHW avatar Nov 27 '23 00:11 MisterHW