From 94ccbeebf69d856effb7ba0dc2dd7e4b13ba3a06 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: ćšć, 03 10æ 2013 21:51:46 +0800 Subject: [PATCH] Add support for Boolean program data --- libscpi/src/parser.c | 31 +++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index cedce47..2a0eabf 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -342,6 +342,17 @@ return result; } +/** + * Write boolean value to the result + * @param context + * @param val + * @return + */ +size_t SCPI_ResultBool(scpi_t * context, bool_t val) { + return SCPI_ResultIntBase(context, val ? 1 : 0, 10); +} + + /* parsing parameters */ bool_t SCPI_Parameter(scpi_t * context, scpi_parameter_t * parameter, bool_t mandatory) { @@ -450,6 +461,26 @@ *len = parameter->data.len; } +/* SCPI-99 7.3 Boolean Program Data */ +bool_t SCPI_ParamGetBoolVal(scpi_t * context, scpi_parameter_t * parameter) { + switch (parameter->type) { + case TokDecimalNumericProgramData: + return parameter->number.value ? 1 : 0; + case TokProgramMnemonic: + if (compareStr("ON", 2, parameter->data.ptr, parameter->data.len)) { + return TRUE; + } else if (compareStr("OFF", 3, parameter->data.ptr, parameter->data.len)) { + return FALSE; + } else { + SCPI_ErrorPush(context, SCPI_ERROR_INVALID_PARAMETER); + return FALSE; + } + default: + SCPI_ErrorPush(context, SCPI_ERROR_INVALID_PARAMETER); + return FALSE; + } +} + int SCPI_ParseProgramData(lex_state_t * state, token_t * token) { token_t tmp; int result = 0; -- Gitblit v1.9.1