| | |
| | | #include "scpi/parser.h" |
| | | #include "utils.h" |
| | | #include "scpi/error.h" |
| | | #include "scpi/constants.h" |
| | | |
| | | |
| | | static size_t cmdTerminatorPos(const char * cmd, size_t len); |
| | |
| | | * @param interface |
| | | */ |
| | | void SCPI_Init(scpi_t * context) { |
| | | if (context->idn[0] == NULL) { |
| | | context->idn[0] = SCPI_DEFAULT_1_MANUFACTURE; |
| | | } |
| | | if (context->idn[1] == NULL) { |
| | | context->idn[1] = SCPI_DEFAULT_2_MODEL; |
| | | } |
| | | if (context->idn[2] == NULL) { |
| | | context->idn[2] = SCPI_DEFAULT_3; |
| | | } |
| | | if (context->idn[3] == NULL) { |
| | | context->idn[3] = SCPI_DEFAULT_4_REVISION; |
| | | } |
| | | |
| | | context->buffer.position = 0; |
| | | SCPI_ErrorInit(context); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | size_t SCPI_ResultBool(scpi_t * context, bool_t val) { |
| | | return SCPI_ResultInt(context, val); |
| | | return SCPI_ResultInt(context, val ? 1 : 0); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * Parse boolean parameter |
| | | * Parse boolean parameter as described in the spec SCPI-99 7.3 Boolean Program Data |
| | | * @param context |
| | | * @param value |
| | | * @param mandatory |
| | |
| | | return TRUE; |
| | | } |
| | | |
| | | /** |
| | | * Parse choice parameter |
| | | * @param context |
| | | * @param options |
| | | * @param value |
| | | * @param mandatory |
| | | * @return |
| | | */ |
| | | bool_t SCPI_ParamChoice(scpi_t * context, const char * options[], int32_t * value, bool_t mandatory) { |
| | | const char * param; |
| | | size_t param_len; |
| | | size_t res; |
| | | |
| | | if (!options || !value) { |
| | | return FALSE; |
| | | } |
| | | |
| | | if (!SCPI_ParamString(context, ¶m, ¶m_len, mandatory)) { |
| | | return FALSE; |
| | | } |
| | | |
| | | for (res = 0; options[res]; ++res) { |
| | | if (matchPattern(options[res], strlen(options[res]), param, param_len)) { |
| | | *value = res; |
| | | return TRUE; |
| | | } |
| | | } |
| | | |
| | | SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); |
| | | return FALSE; |
| | | } |
| | | |