/** * Read BOOL parameter (0,1,ON,OFF) * @param context * @param value * @param mandatory * @return */ scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t mandatory) { scpi_bool_t result; scpi_parameter_t param; int32_t intval; scpi_choice_def_t bool_options[] = { {"OFF", 0}, {"ON", 1}, SCPI_CHOICE_LIST_END /* termination of option list */ }; if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } result = SCPI_Parameter(context, ¶m, mandatory); if (result) { if (param.type == SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA) { SCPI_ParamToInt32(context, ¶m, &intval); *value = intval ? TRUE : FALSE; } else { result = SCPI_ParamToChoice(context, ¶m, bool_options, &intval); if (result) { *value = intval ? TRUE : FALSE; } } } return result; }
/** * Read value from list of options * @param context * @param options * @param value * @param mandatory * @return */ scpi_bool_t SCPI_ParamChoice(scpi_t * context, const scpi_choice_def_t * options, int32_t * value, scpi_bool_t mandatory) { scpi_bool_t result; scpi_parameter_t param; if (!options || !value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } result = SCPI_Parameter(context, ¶m, mandatory); if (result) { result = SCPI_ParamToChoice(context, ¶m, options, value); } return result; }
/** * Parse parameter as number, number with unit or special value (min, max, default, ...) * @param context * @param value return value * @param mandatory if the parameter is mandatory * @return */ scpi_bool_t SCPI_ParamNumber(scpi_t * context, const scpi_choice_def_t * special, scpi_number_t * value, scpi_bool_t mandatory) { scpi_token_t token; lex_state_t state; scpi_parameter_t param; scpi_bool_t result; int32_t tag; if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } result = SCPI_Parameter(context, ¶m, mandatory); if (!result) { return result; } state.buffer = param.ptr; state.pos = state.buffer; state.len = param.len; switch(param.type) { case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: case SCPI_TOKEN_HEXNUM: case SCPI_TOKEN_OCTNUM: case SCPI_TOKEN_BINNUM: case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: case SCPI_TOKEN_PROGRAM_MNEMONIC: value->unit = SCPI_UNIT_NONE; value->special = FALSE; result = TRUE; break; } switch(param.type) { case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: case SCPI_TOKEN_PROGRAM_MNEMONIC: value->base = 10; break; case SCPI_TOKEN_BINNUM: value->base = 2; break; case SCPI_TOKEN_HEXNUM: value->base = 16; break; case SCPI_TOKEN_OCTNUM: value->base = 8; break; } switch(param.type) { case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: SCPI_ParamToDouble(context, ¶m, &(value->value)); break; case SCPI_TOKEN_HEXNUM: SCPI_ParamToDouble(context, ¶m, &(value->value)); break; case SCPI_TOKEN_OCTNUM: SCPI_ParamToDouble(context, ¶m, &(value->value)); break; case SCPI_TOKEN_BINNUM: SCPI_ParamToDouble(context, ¶m, &(value->value)); break; case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: scpiLex_DecimalNumericProgramData(&state, &token); scpiLex_WhiteSpace(&state, &token); scpiLex_SuffixProgramData(&state, &token); SCPI_ParamToDouble(context, ¶m, &(value->value)); result = transformNumber(context, token.ptr, token.len, value); break; case SCPI_TOKEN_PROGRAM_MNEMONIC: scpiLex_WhiteSpace(&state, &token); scpiLex_CharacterProgramData(&state, &token); /* convert string to special number type */ SCPI_ParamToChoice(context, &token, special, &tag); value->special = TRUE; value->tag = tag; break; default: result = FALSE; } return result; }