/** * Convert parameter to choice * @param context * @param parameter - should be PROGRAM_MNEMONIC * @param options - NULL terminated list of choices * @param value - index to options * @return */ scpi_bool_t SCPI_ParamToChoice(scpi_t * context, scpi_parameter_t * parameter, const scpi_choice_def_t * options, int32_t * value) { size_t res; scpi_bool_t result = FALSE; if (!options || !value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } if (parameter->type == SCPI_TOKEN_PROGRAM_MNEMONIC) { for (res = 0; options[res].name; ++res) { if (matchPattern(options[res].name, strlen(options[res].name), parameter->ptr, parameter->len, NULL)) { *value = options[res].tag; result = TRUE; break; } } if (!result) { SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); } } else { SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR); } return result; }
scpi_result_t SCPIMM_trigger_delay(scpi_t* context) { scpimm_context_t* const ctx = SCPIMM_CONTEXT(context); scpi_number_t num; if (!SCPI_ParamNumber(context, &num, TRUE)) { return SCPI_RES_ERR; } switch (num.type) { case SCPI_NUM_MIN: ctx->trigger_delay = TRIGGER_DELAY_MIN; break; case SCPI_NUM_MAX: ctx->trigger_delay = TRIGGER_DELAY_MAX; break; case SCPI_NUM_NUMBER: if (num.value < TRIGGER_DELAY_MIN || num.value > TRIGGER_DELAY_MAX) { SCPI_ErrorPush(context, SCPIMM_ERROR_DATA_OUT_OF_RANGE); return SCPI_RES_ERR; } ctx->trigger_delay = num.value; break; default: SCPI_ErrorPush(context, SCPIMM_ERROR_ILLEGAL_PARAMETER_VALUE); return SCPI_RES_ERR; } return SCPI_RES_OK; }
/** * Process command * @param context */ static void processCommand(scpi_t * context) { const scpi_command_t * cmd = context->paramlist.cmd; context->cmd_error = FALSE; context->output_count = 0; context->input_count = 0; SCPI_DEBUG_COMMAND(context); /* if callback exists - call command callback */ if (cmd->callback != NULL) { if ((cmd->callback(context) != SCPI_RES_OK) && !context->cmd_error) { SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); } } /* conditionaly write new line */ writeNewLine(context); /* skip all whitespaces */ paramSkipWhitespace(context); /* set error if command callback did not read all parameters */ if (context->paramlist.length != 0 && !context->cmd_error) { SCPI_ErrorPush(context, SCPI_ERROR_PARAMETER_NOT_ALLOWED); } }
scpi_result_t scpi_syst_Date(scpi_t * context) { int32_t year; if (!SCPI_ParamInt(context, &year, TRUE)) { return SCPI_RES_ERR; } int32_t month; if (!SCPI_ParamInt(context, &month, TRUE)) { return SCPI_RES_ERR; } int32_t day; if (!SCPI_ParamInt(context, &day, TRUE)) { return SCPI_RES_ERR; } if (year < 2000 || year > 2099) { SCPI_ErrorPush(context, SCPI_ERROR_DATA_OUT_OF_RANGE); return SCPI_RES_ERR; } year = year - 2000; if (!datetime::isValidDate((uint8_t)year, (uint8_t)month, (uint8_t)day)) { SCPI_ErrorPush(context, SCPI_ERROR_DATA_OUT_OF_RANGE); return SCPI_RES_ERR; } if (!datetime::setDate((uint8_t)year, (uint8_t)month, (uint8_t)day)) { SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); return SCPI_RES_ERR; } return SCPI_RES_OK; }
scpi_result_t scpi_syst_Time(scpi_t * context) { int32_t hour; if (!SCPI_ParamInt(context, &hour, TRUE)) { return SCPI_RES_ERR; } int32_t minute; if (!SCPI_ParamInt(context, &minute, TRUE)) { return SCPI_RES_ERR; } int32_t second; if (!SCPI_ParamInt(context, &second, TRUE)) { return SCPI_RES_ERR; } if (!datetime::isValidTime((uint8_t)hour, (uint8_t)minute, (uint8_t)second)) { SCPI_ErrorPush(context, SCPI_ERROR_DATA_OUT_OF_RANGE); return SCPI_RES_ERR; } if (!datetime::setTime((uint8_t)hour, (uint8_t)minute, (uint8_t)second)) { SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); return SCPI_RES_ERR; } return SCPI_RES_OK; }
/** * Process command * @param context */ static scpi_bool_t processCommand(scpi_t * context) { const scpi_command_t * cmd = context->param_list.cmd; lex_state_t * state = &context->param_list.lex_state; scpi_bool_t result = TRUE; /* conditionaly write ; */ writeSemicolon(context); context->cmd_error = FALSE; context->output_count = 0; context->input_count = 0; context->arbitrary_reminding = 0; /* if callback exists - call command callback */ if (cmd->callback != NULL) { if ((cmd->callback(context) != SCPI_RES_OK)) { if (!context->cmd_error) { SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); } result = FALSE; } else { if (context->cmd_error) { result = FALSE; } } } /* set error if command callback did not read all parameters */ if (state->pos < (state->buffer + state->len) && !context->cmd_error) { SCPI_ErrorPush(context, SCPI_ERROR_PARAMETER_NOT_ALLOWED); result = FALSE; } return result; }
/** * Parse one command line * @param context * @param data - complete command line * @param len - command line length * @return 1 if the last evaluated command was found */ int SCPI_Parse(scpi_t * context, char * data, int len) { int result = 0; scpi_parser_state_t * state; int r; scpi_token_t cmd_prev = {SCPI_TOKEN_UNKNOWN, NULL, 0}; if (context == NULL) { return -1; } state = &context->parser_state; context->output_count = 0; while (1) { result = 0; r = scpiParser_detectProgramMessageUnit(state, data, len); if (state->programHeader.type == SCPI_TOKEN_INVALID) { SCPI_ErrorPush(context, SCPI_ERROR_INVALID_CHARACTER); } else if (state->programHeader.len > 0) { composeCompoundCommand(&cmd_prev, &state->programHeader); if (findCommandHeader(context, state->programHeader.ptr, state->programHeader.len)) { context->param_list.lex_state.buffer = state->programData.ptr; context->param_list.lex_state.pos = context->param_list.lex_state.buffer; context->param_list.lex_state.len = state->programData.len; context->param_list.cmd_raw.data = state->programHeader.ptr; context->param_list.cmd_raw.position = 0; context->param_list.cmd_raw.length = state->programHeader.len; processCommand(context); result = 1; cmd_prev = state->programHeader; } else { SCPI_ErrorPush(context, SCPI_ERROR_UNDEFINED_HEADER); } } if (r < len) { data += r; len -= r; } else { break; } } /* conditionaly write new line */ writeNewLine(context); return result; }
/** * Result binary array and swap bytes if needed (native endiannes != required endiannes) * @param context * @param array * @param count * @param item_size * @param format * @return */ static size_t parserResultArrayBinary(scpi_t * context, const void * array, size_t count, size_t item_size, scpi_array_format_t format) { if (SCPI_GetNativeFormat() == format) { switch (item_size) { case 1: case 2: case 4: case 8: return SCPI_ResultArbitraryBlock(context, array, count * item_size); default: SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return 0; } } else { size_t result = 0; size_t i; switch (item_size) { case 1: case 2: case 4: case 8: result += SCPI_ResultArbitraryBlockHeader(context, count * item_size); break; default: SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return 0; } switch (item_size) { case 1: result += SCPI_ResultArbitraryBlockData(context, array, count); break; case 2: for (i = 0; i < count; i++) { uint16_t val = SCPI_Swap16(((uint16_t*) array)[i]); result += SCPI_ResultArbitraryBlockData(context, &val, item_size); } break; case 4: for (i = 0; i < count; i++) { uint32_t val = SCPI_Swap32(((uint32_t*) array)[i]); result += SCPI_ResultArbitraryBlockData(context, &val, item_size); } break; case 8: for (i = 0; i < count; i++) { uint64_t val = SCPI_Swap64(((uint64_t*) array)[i]); result += SCPI_ResultArbitraryBlockData(context, &val, item_size); } break; } return result; } }
/** * Get one parameter from command line * @param context * @param parameter * @param mandatory * @return */ scpi_bool_t SCPI_Parameter(scpi_t * context, scpi_parameter_t * parameter, scpi_bool_t mandatory) { lex_state_t * state; if (!parameter) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } invalidateToken(parameter, NULL); state = &context->param_list.lex_state; if (state->pos >= (state->buffer + state->len)) { if (mandatory) { SCPI_ErrorPush(context, SCPI_ERROR_MISSING_PARAMETER); } else { parameter->type = SCPI_TOKEN_PROGRAM_MNEMONIC; // TODO: select something different } return FALSE; } if (context->input_count != 0) { scpiLex_Comma(state, parameter); if (parameter->type != SCPI_TOKEN_COMMA) { invalidateToken(parameter, NULL); SCPI_ErrorPush(context, SCPI_ERROR_INVALID_SEPARATOR); return FALSE; } } context->input_count++; scpiParser_parseProgramData(&context->param_list.lex_state, parameter); switch (parameter->type) { case SCPI_TOKEN_HEXNUM: case SCPI_TOKEN_OCTNUM: case SCPI_TOKEN_BINNUM: case SCPI_TOKEN_PROGRAM_MNEMONIC: case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: case SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA: case SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA: case SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA: case SCPI_TOKEN_PROGRAM_EXPRESSION: return TRUE; default: invalidateToken(parameter, NULL); SCPI_ErrorPush(context, SCPI_ERROR_INVALID_STRING_DATA); return FALSE; } }
/** * Read character parameter * @param context * @param value * @param len * @param mandatory * @return */ scpi_bool_t SCPI_ParamCharacters(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) { scpi_bool_t result; scpi_parameter_t param; if (!value || !len) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } result = SCPI_Parameter(context, ¶m, mandatory); if (result) { switch(param.type) { case SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA: case SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA: *value = param.ptr + 1; *len = param.len - 2; break; default: *value = param.ptr; *len = param.len; break; } // TODO: return also parameter type (ProgramMnemonic, ArbitraryBlockProgramData, SingleQuoteProgramData, DoubleQuoteProgramData } return result; }
/** * Convert parameter to double (64 bit) * @param context * @param parameter * @param value result * @return TRUE if succesful */ scpi_bool_t SCPI_ParamToDouble(scpi_t * context, scpi_parameter_t * parameter, double * value) { scpi_bool_t result; uint64_t valint; if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } switch (parameter->type) { case SCPI_TOKEN_HEXNUM: case SCPI_TOKEN_OCTNUM: case SCPI_TOKEN_BINNUM: result = SCPI_ParamToUInt64(context, parameter, &valint); *value = valint; break; case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: result = strToDouble(parameter->ptr, value) > 0 ? TRUE : FALSE; break; default: result = FALSE; } return result; }
/** * Parse boolean parameter as described in the spec SCPI-99 7.3 Boolean Program Data * @param context * @param value * @param mandatory * @return */ scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t mandatory) { const char * param; size_t param_len; size_t num_len; int32_t i; if (!value) { return FALSE; } if (!SCPI_ParamString(context, ¶m, ¶m_len, mandatory)) { return FALSE; } if (matchPattern("ON", 2, param, param_len)) { *value = TRUE; } else if (matchPattern("OFF", 3, param, param_len)) { *value = FALSE; } else { num_len = strToLong(param, &i); if (num_len != param_len) { SCPI_ErrorPush(context, SCPI_ERROR_SUFFIX_NOT_ALLOWED); return FALSE; } *value = i ? TRUE : FALSE; } return TRUE; }
/** * Parse one command line * @param context * @param data - complete command line * @param len - command line length * @return 1 if the last evaluated command was found */ int SCPI_Parse(scpi_t * context, char * data, size_t len) { int result = 0; const char * cmdline_end = data + len; char * cmdline_ptr = data; size_t cmd_len; size_t cmdline_len; char * cmdline_ptr_prev = NULL; size_t cmd_len_prev = 0; if (context == NULL) { return -1; } while (cmdline_ptr < cmdline_end) { result = 0; cmd_len = cmdTerminatorPos(cmdline_ptr, cmdline_end - cmdline_ptr); if (cmd_len > 0) { composeCompoundCommand(cmdline_ptr_prev, cmd_len_prev, &cmdline_ptr, &cmd_len); cmdline_len = cmdlineSeparatorPos(cmdline_ptr, cmdline_end - cmdline_ptr); if(findCommand(context, cmdline_ptr, cmdline_len, cmd_len)) { processCommand(context); result = 1; cmdline_ptr_prev = cmdline_ptr; cmd_len_prev = cmd_len; } else { SCPI_ErrorPush(context, SCPI_ERROR_UNDEFINED_HEADER); } } cmdline_ptr += skipCmdLine(cmdline_ptr, cmdline_end - cmdline_ptr); cmdline_ptr += skipWhitespace(cmdline_ptr, cmdline_end - cmdline_ptr); } return result; }
/** * Parse one command line * @param context * @param data - complete command line * @param len - command line length * @return 1 if the last evaluated command was found */ int SCPI_Parse(scpi_t * context, const char * data, size_t len) { int result = 0; const char * cmdline_end = data + len; const char * cmdline_ptr = data; size_t cmd_len; size_t cmdline_len; if (context == NULL) { return -1; } while (cmdline_ptr < cmdline_end) { result = 0; cmd_len = cmdTerminatorPos(cmdline_ptr, cmdline_end - cmdline_ptr); cmdline_len = cmdlineSeparatorPos(cmdline_ptr, cmdline_end - cmdline_ptr); if (cmd_len > 0) { if(findCommand(context, cmdline_ptr, cmdline_len, cmd_len)) { processCommand(context); result = 1; } else { SCPI_ErrorPush(context, SCPI_ERROR_UNDEFINED_HEADER); } } cmdline_ptr = cmdlineNext(cmdline_ptr, cmdline_end - cmdline_ptr); } return result; }
static scpi_result_t get_source_value(scpi_t * context, float value, float min, float max, float def) { int32_t spec; if (!SCPI_ParamChoice(context, scpi_special_numbers_def, &spec, false)) { if (SCPI_ParamErrorOccurred(context)) { return SCPI_RES_ERR; } } else { if (spec == SCPI_NUM_MIN) { value = min; } else if (spec == SCPI_NUM_MAX) { value = max; } else if (spec == SCPI_NUM_DEF) { value = def; } else { SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); return SCPI_RES_ERR; } } return result_float(context, value); }
/** * Convert parameter to signed/unsigned 64 bit integer * @param context * @param parameter * @param value result * @param sign * @return TRUE if succesful */ static scpi_bool_t ParamSignToUInt64(scpi_t * context, scpi_parameter_t * parameter, uint64_t * value, scpi_bool_t sign) { if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } switch (parameter->type) { case SCPI_TOKEN_HEXNUM: return strBaseToUInt64(parameter->ptr, value, 16) > 0 ? TRUE : FALSE; case SCPI_TOKEN_OCTNUM: return strBaseToUInt64(parameter->ptr, value, 8) > 0 ? TRUE : FALSE; case SCPI_TOKEN_BINNUM: return strBaseToUInt64(parameter->ptr, value, 2) > 0 ? TRUE : FALSE; case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA: case SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA_WITH_SUFFIX: if (sign) { return strBaseToInt64(parameter->ptr, (int64_t *)value, 10) > 0 ? TRUE : FALSE; } else { return strBaseToUInt64(parameter->ptr, value, 10) > 0 ? TRUE : FALSE; } default: return FALSE; } }
/** * 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; }
scpi_result_t SCPIMM_trigger_delayQ(scpi_t* context) { scpi_number_t num; double res; if (!SCPI_ParamNumber(context, &num, FALSE)) { return SCPI_RES_ERR; } switch (num.type) { case SCPI_NUM_MIN: res = TRIGGER_DELAY_MIN; break; case SCPI_NUM_MAX: res = TRIGGER_DELAY_MAX; break; case SCPI_NUM_DEF: res = SCPIMM_CONTEXT(context)->trigger_delay; break; default: SCPI_ErrorPush(context, SCPIMM_ERROR_ILLEGAL_PARAMETER_VALUE); return SCPI_RES_ERR; } SCPI_ResultDouble(context, res); return SCPI_RES_OK; }
scpi_result_t SCPIMM_trigger_countQ(scpi_t* context) { scpimm_context_t* const ctx = SCPIMM_CONTEXT(context); scpi_number_t num = {0.0, SCPI_UNIT_NONE, SCPI_NUM_NUMBER}; int32_t lnum; if (!SCPI_ParamNumber(context, &num, FALSE)) { return SCPI_RES_ERR; } switch (num.type) { case SCPI_NUM_MIN: lnum = 1; break; case SCPI_NUM_MAX: lnum = max_trigger_count(); break; case SCPI_NUM_DEF: if (ctx->infinite_trigger_count) { SCPI_ResultDouble(context, INF_TRIGGER_COUNT); return SCPI_RES_OK; } lnum = ctx->trigger_count_num; break; default: SCPI_ErrorPush(context, SCPIMM_ERROR_ILLEGAL_PARAMETER_VALUE); return SCPI_RES_ERR; } SCPI_ResultInt(context, lnum); return SCPI_RES_OK; }
scpi_result_t scpi_syst_Power(scpi_t * context) { bool up; if (!SCPI_ParamBool(context, &up, TRUE)) { return SCPI_RES_ERR; } if (temperature::isSensorTripped(temp_sensor::MAIN)) { SCPI_ErrorPush(context, SCPI_ERROR_CANNOT_EXECUTE_BEFORE_CLEARING_PROTECTION); return SCPI_RES_ERR; } if (!psu::changePowerState(up)) { SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); return SCPI_RES_ERR; } return SCPI_RES_OK; }
scpi_result_t SCPIMM_trigger_count(scpi_t* context) { const long lmax = max_trigger_count(); scpimm_context_t* const ctx = SCPIMM_CONTEXT(context); scpi_number_t num; long lnum; if (!SCPI_ParamNumber(context, &num, TRUE)) { return SCPI_RES_ERR; } switch (num.type) { case SCPI_NUM_MIN: lnum = 1; ctx->infinite_trigger_count = FALSE; break; case SCPI_NUM_MAX: lnum = lmax; ctx->infinite_trigger_count = FALSE; break; case SCPI_NUM_INF: lnum = 0; ctx->infinite_trigger_count = TRUE; break; case SCPI_NUM_NUMBER: lnum = (long) num.value; ctx->infinite_trigger_count = FALSE; break; default: SCPI_ErrorPush(context, SCPIMM_ERROR_ILLEGAL_PARAMETER_VALUE); return SCPI_RES_ERR; } if (!ctx->infinite_trigger_count && (lnum < 1 || lnum > lmax)) { SCPI_ErrorPush(context, SCPIMM_ERROR_DATA_OUT_OF_RANGE); return SCPI_RES_ERR; } ctx->trigger_count_num = (unsigned) lnum; return SCPI_RES_OK; }
scpi_bool_t SCPI_ParamCopyText(scpi_t * context, char * buffer, size_t buffer_len, size_t * copy_len, scpi_bool_t mandatory) { scpi_bool_t result; scpi_parameter_t param; size_t i_from; size_t i_to; char quote; if (!buffer || !copy_len) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } result = SCPI_Parameter(context, ¶m, mandatory); if (result) { switch (param.type) { case SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA: case SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA: quote = param.type == SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA ? '\'' : '"'; for (i_from = 1, i_to = 0; i_from < (size_t) (param.len - 1); i_from++) { if (i_from >= buffer_len) { break; } buffer[i_to] = param.ptr[i_from]; i_to++; if (param.ptr[i_from] == quote) { i_from++; } } *copy_len = i_to; if (i_to < buffer_len) { buffer[i_to] = 0; } break; default: SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR); result = FALSE; } } return result; }
/** * Find next parameter * @param context * @param mandatory * @return */ scpi_bool_t paramNext(scpi_t * context, scpi_bool_t mandatory) { paramSkipWhitespace(context); if (context->paramlist.length == 0) { if (mandatory) { SCPI_ErrorPush(context, SCPI_ERROR_MISSING_PARAMETER); } return FALSE; } if (context->input_count != 0) { if (context->paramlist.parameters[0] == ',') { paramSkipBytes(context, 1); paramSkipWhitespace(context); } else { SCPI_ErrorPush(context, SCPI_ERROR_INVALID_SEPARATOR); return FALSE; } } context->input_count++; return TRUE; }
scpi_result_t scpi_syst_DateQ(scpi_t * context) { uint8_t year, month, day; if (!datetime::getDate(year, month, day)) { SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); return SCPI_RES_ERR; } char buffer[16] = { 0 }; sprintf_P(buffer, PSTR("%d, %d, %d"), (int)(year + 2000), (int)month, (int)day); SCPI_ResultCharacters(context, buffer, strlen(buffer)); return SCPI_RES_OK; }
scpi_result_t scpi_syst_TimeQ(scpi_t * context) { uint8_t hour, minute, second; if (!datetime::getTime(hour, minute, second)) { SCPI_ErrorPush(context, SCPI_ERROR_EXECUTION_ERROR); return SCPI_RES_ERR; } char buffer[16] = { 0 }; sprintf_P(buffer, PSTR("%d, %d, %d"), (int)hour, (int)minute, (int)second); SCPI_ResultCharacters(context, buffer, strlen(buffer)); return SCPI_RES_OK; }
/** * Get arbitrary block program data and returns pointer to data * @param context * @param value result pointer to data * @param len result length of data * @param mandatory * @return */ scpi_bool_t SCPI_ParamArbitraryBlock(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) { scpi_bool_t result; scpi_parameter_t param; if (!value || !len) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } result = SCPI_Parameter(context, ¶m, mandatory); if (result) { if (param.type == SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA) { *value = param.ptr; *len = param.len; } else { SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR); result = FALSE; } } return result; }
/** * Read signed/unsigned 64 bit integer parameter * @param context * @param value * @param mandatory * @param sign * @return */ static scpi_bool_t ParamSignUInt64(scpi_t * context, uint64_t * value, scpi_bool_t mandatory, scpi_bool_t sign) { scpi_bool_t result; scpi_parameter_t param; if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } result = SCPI_Parameter(context, ¶m, mandatory); if (result) { if (SCPI_ParamIsNumber(¶m, FALSE)) { result = ParamSignToUInt64(context, ¶m, value, sign); } else if (SCPI_ParamIsNumber(¶m, TRUE)) { SCPI_ErrorPush(context, SCPI_ERROR_SUFFIX_NOT_ALLOWED); result = FALSE; } else { SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR); result = FALSE; } } return result; }
/** * Read floating point double (64 bit) parameter * @param context * @param value * @param mandatory * @return */ scpi_bool_t SCPI_ParamDouble(scpi_t * context, double * value, scpi_bool_t mandatory) { scpi_bool_t result; scpi_parameter_t param; if (!value) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return FALSE; } result = SCPI_Parameter(context, ¶m, mandatory); if (result) { if (SCPI_ParamIsNumber(¶m, FALSE)) { SCPI_ParamToDouble(context, ¶m, value); } else if (SCPI_ParamIsNumber(¶m, TRUE)) { SCPI_ErrorPush(context, SCPI_ERROR_SUFFIX_NOT_ALLOWED); result = FALSE; } else { SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR); result = FALSE; } } return result; }
static scpi_result_t set_step(scpi_t * context, Channel::Value *cv, float min_value, float max_value, float def, _scpi_unit_t unit) { scpi_number_t step_param; if (!SCPI_ParamNumber(context, scpi_special_numbers_def, &step_param, true)) { return SCPI_RES_ERR; } float step; if (step_param.special) { if (step_param.tag == SCPI_NUM_DEF) { step = def; } else { SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); return SCPI_RES_ERR; } } else { if (step_param.unit != SCPI_UNIT_NONE && step_param.unit != unit) { SCPI_ErrorPush(context, SCPI_ERROR_INVALID_SUFFIX); return SCPI_RES_ERR; } step = (float)step_param.value; if (step < min_value || step > max_value) { SCPI_ErrorPush(context, SCPI_ERROR_DATA_OUT_OF_RANGE); return SCPI_RES_ERR; } } cv->step = step; profile::save(); return SCPI_RES_OK; }
/** * Add data to arbitrary block * @param context * @param data * @param len * @return */ size_t SCPI_ResultArbitraryBlockData(scpi_t * context, const void * data, size_t len) { if (context->arbitrary_reminding < len) { SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); return 0; } context->arbitrary_reminding -= len; if (context->arbitrary_reminding == 0) { context->output_count++; } return writeData(context, (const char *) data, len); }