j123b567 / scpi-parser

Open Source SCPI device library
BSD 2-Clause "Simplified" License
447 stars 191 forks source link

introduce SCPI_HelpQ with descriptions #135

Open MisterHW opened 2 years ago

MisterHW commented 2 years ago

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

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

coveralls commented 1 year ago

Coverage Status

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

MisterHW commented 1 year ago

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

j123b567 commented 1 year ago

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 commented 1 year ago

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

MisterHW commented 7 months ago

I will get back to this eventually :)