Jan Breuer
2015-09-15 c1e514e03ab7de4399ca12c9ae988b0707a99f8b
Resolve #46: Detect missing parameter
2个文件已修改
23 ■■■■■ 已修改文件
libscpi/inc/scpi/parser.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libscpi/src/parser.c 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libscpi/inc/scpi/parser.h
@@ -59,6 +59,8 @@
    size_t SCPI_ResultBool(scpi_t * context, scpi_bool_t val);
   
    scpi_bool_t SCPI_Parameter(scpi_t * context, scpi_parameter_t * parameter, scpi_bool_t mandatory);
    scpi_bool_t SCPI_ParamIsValid(scpi_parameter_t * parameter);
    scpi_bool_t SCPI_ParamErrorOccurred(scpi_t * context);
    scpi_bool_t SCPI_ParamIsNumber(scpi_parameter_t * parameter, scpi_bool_t suffixAllowed);
    scpi_bool_t SCPI_ParamToInt(scpi_t * context, scpi_parameter_t * parameter, int32_t * value);
    scpi_bool_t SCPI_ParamToUnsignedInt(scpi_t * context, scpi_parameter_t * parameter, uint32_t * value);
libscpi/src/parser.c
@@ -1093,3 +1093,24 @@
scpi_bool_t SCPI_CommandNumbers(scpi_t * context, int32_t * numbers, size_t len) {
    return matchCommand (context->param_list.cmd->pattern,  context->param_list.cmd_raw.data, context->param_list.cmd_raw.length, numbers, len);
}
/**
 * If SCPI_Parameter() returns FALSE, this function can detect, if the parameter
 * is just missing (TRUE) or if there was an error during processing of the command (FALSE)
 * @param parameter
 * @return
 */
scpi_bool_t SCPI_ParamIsValid(scpi_parameter_t * parameter)
{
    return parameter->type == SCPI_TOKEN_UNKNOWN ? FALSE : TRUE;
}
/**
 * Returns TRUE if there was an error during parameter handling
 * @param context
 * @return
 */
scpi_bool_t SCPI_ParamErrorOccurred(scpi_t * context)
{
    return context->cmd_error;
}