merge functionality from 'master' branch
| | |
| | | *.out |
| | | *.app |
| | | *.test |
| | | examples/*/test |
| | | |
| | | # Backup files |
| | | *~ |
| | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | scpi_result_t SCPI_TestBool(scpi_t * context) { |
| | | scpi_result_t TEST_Bool(scpi_t * context) { |
| | | scpi_parameter_t param1; |
| | | fprintf(stderr, "TEST:BOOL\r\n"); // debug command name |
| | | |
| | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | const char * trigger_source[] = { |
| | | "BUS", |
| | | "IMMediate", |
| | | "EXTernal", |
| | | NULL /* termination of option list */ |
| | | }; |
| | | |
| | | |
| | | scpi_result_t TEST_ChoiceQ(scpi_t * context) { |
| | | scpi_parameter_t param1; |
| | | int32_t result; |
| | | |
| | | if (!SCPI_Parameter(context, ¶m1, true)) { |
| | | return SCPI_RES_ERR; |
| | | } |
| | | |
| | | result = SCPI_ParamGetChoiceVal(context, ¶m1, trigger_source); |
| | | |
| | | fprintf(stderr, "\tP1=%s (%d)\r\n", result >= 0 ? trigger_source[result] : "", result); |
| | | |
| | | SCPI_ResultInt(context, result); |
| | | |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | | static const scpi_command_t scpi_commands[] = { |
| | | /* IEEE Mandated Commands (SCPI std V1999.0 4.1.1) */ |
| | |
| | | |
| | | {.pattern = "SYSTem:COMMunication:TCPIP:CONTROL?", .callback = SCPI_SystemCommTcpipControlQ,}, |
| | | |
| | | {.pattern = "TEST:BOOL", .callback = SCPI_TestBool,}, |
| | | {.pattern = "TEST:BOOL", .callback = TEST_Bool,}, |
| | | {.pattern = "TEST:CHOice?", .callback = TEST_ChoiceQ,}, |
| | | |
| | | SCPI_CMD_LIST_END |
| | | }; |
| | |
| | | .registers = scpi_regs, |
| | | .units = scpi_units_def, |
| | | .special_numbers = scpi_special_numbers_def, |
| | | .idn = {"MANUFACTURE", "INSTR2013", NULL, "01-02"}, |
| | | }; |
| | |
| | | #endif |
| | | |
| | | |
| | | #define SCPI_MANUFACTURE "CTU FEE" |
| | | #define SCPI_DEV_NAME "TEST SCPI INSTRUMENT TSI3225" |
| | | #define SCPI_DEV_VERSION "v1.0" |
| | | /* 4.1.3.6 *IDN? */ |
| | | |
| | | #define SCPI_DEFAULT_1_MANUFACTURE "CTU FEE" |
| | | #define SCPI_DEFAULT_2_MODEL "TSI3225" |
| | | #define SCPI_DEFAULT_3 "0" |
| | | #define SCPI_DEFAULT_4_REVISION "01-01" |
| | | |
| | | /* 21.21 :VERSion? |
| | | * YYYY.V |
| | | * YYYY = SCPI year |
| | | * V = SCPI revision |
| | | */ |
| | | #define SCPI_STD_VERSION_REVISION "1999.0" |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | |
| | | |
| | | /* http://en.wikipedia.org/wiki/X_Macro */ |
| | | #define LIST_OF_ERRORS \ |
| | | X(SCPI_ERROR_INVALID_CHARACTER, -101, "Invalid character") \ |
| | | X(SCPI_ERROR_SYNTAX, -102, "Syntax error") \ |
| | | X(SCPI_ERROR_INVALID_SEPARATOR, -103, "Invalid separator") \ |
| | | X(SCPI_ERROR_UNDEFINED_HEADER, -113, "Undefined header") \ |
| | | X(SCPI_ERROR_DATA_TYPE_ERROR, -104, "Data type error") \ |
| | | X(SCPI_ERROR_PARAMETER_NOT_ALLOWED,-108, "Parameter not allowed") \ |
| | | X(SCPI_ERROR_MISSING_PARAMETER, -109, "Missing parameter") \ |
| | | X(SCPI_ERROR_UNDEFINED_HEADER, -113, "Undefined header") \ |
| | | X(SCPI_ERROR_INVALID_SUFFIX, -131, "Invalid suffix") \ |
| | | X(SCPI_ERROR_SUFFIX_NOT_ALLOWED, -138, "Suffix not allowed") \ |
| | | X(SCPI_ERROR_UNKNOWN_PARAMETER, -199, "Unknown parameter") \ |
| | | X(SCPI_ERROR_INVALID_PARAMETER, -198, "Invalid parameter") \ |
| | | X(SCPI_ERROR_UNEXPECTED_CHARACTER, -197, "Unexpected character") \ |
| | | X(SCPI_ERROR_INVALID_STRING_DATA, -151, "Invalid string data") \ |
| | | X(SCPI_ERROR_EXECUTION_ERROR, -200, "Execution error") \ |
| | | X(SCPI_ERROR_ILLEGAL_PARAMETER_VALUE,-224,"Illegal parameter value") \ |
| | | X(SCPI_ERROR_SYSTEM_ERROR, -310, "System error") \ |
| | | |
| | | |
| | | enum { |
| | |
| | | #ifndef SCPI_PARSER_H |
| | | #define SCPI_PARSER_H |
| | | |
| | | #include <string.h> |
| | | #include "scpi/types.h" |
| | | #include "scpi/debug.h" |
| | | #include "scpi/lexer.h" |
| | |
| | | |
| | | |
| | | size_t SCPI_ResultCharacters(scpi_t * context, const char * data, size_t len); |
| | | #define SCPI_ResultMnemonic(context, data) SCPI_ResultCharacters((context), (data), strlen(data)) |
| | | size_t SCPI_ResultInt(scpi_t * context, int32_t val); |
| | | size_t SCPI_ResultIntBase(scpi_t * context, int32_t val, int8_t base); |
| | | size_t SCPI_ResultDouble(scpi_t * context, double val); |
| | |
| | | #define SCPI_ParamGetCharactersVal SCPI_ParamGetTextVal |
| | | #define SCPI_ParamGetArbitraryBlockVal SCPI_ParamGetTextVal |
| | | bool_t SCPI_ParamGetBoolVal(scpi_t * context, scpi_parameter_t * parameter); |
| | | int32_t SCPI_ParamGetChoiceVal(scpi_t * context, scpi_parameter_t * parameter, const char * options[]); |
| | | |
| | | bool_t SCPI_Parameter(scpi_t * context, scpi_parameter_t * parameter, bool_t mandatory); |
| | | |
| | |
| | | const scpi_special_number_def_t * special_numbers; |
| | | void * user_context; |
| | | scpi_parser_state_t parser_state; |
| | | const char * idn[4]; |
| | | }; |
| | | |
| | | #ifdef __cplusplus |
| | |
| | | |
| | | /** |
| | | * *IDN? |
| | | * |
| | | * field1: MANUFACTURE |
| | | * field2: MODEL |
| | | * field4: SUBSYSTEMS REVISIONS |
| | | * |
| | | * example: MANUFACTURE,MODEL,0,01-02-01 |
| | | * @param context |
| | | * @return |
| | | */ |
| | | scpi_result_t SCPI_CoreIdnQ(scpi_t * context) { |
| | | SCPI_ResultText(context, SCPI_MANUFACTURE); |
| | | SCPI_ResultText(context, SCPI_DEV_NAME); |
| | | SCPI_ResultText(context, SCPI_DEV_VERSION); |
| | | SCPI_ResultMnemonic(context, context->idn[0]); |
| | | SCPI_ResultMnemonic(context, context->idn[1]); |
| | | SCPI_ResultMnemonic(context, context->idn[2]); |
| | | SCPI_ResultMnemonic(context, context->idn[3]); |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | scpi_result_t SCPI_SystemVersionQ(scpi_t * context) { |
| | | SCPI_ResultText(context, SCPI_DEV_VERSION); |
| | | SCPI_ResultText(context, SCPI_STD_VERSION_REVISION); |
| | | return SCPI_RES_OK; |
| | | } |
| | | |
| | |
| | | #include "scpi/lexer.h" |
| | | #include "utils.h" |
| | | #include "scpi/error.h" |
| | | #include "scpi/constants.h" |
| | | |
| | | /** |
| | | * Write data to SCPI output |
| | |
| | | r = SCPI_DetectProgramMessageUnit(state, data, len); |
| | | |
| | | if (state->programHeader.type == TokInvalid) { |
| | | SCPI_ErrorPush(context, SCPI_ERROR_UNEXPECTED_CHARACTER); |
| | | SCPI_ErrorPush(context, SCPI_ERROR_INVALID_CHARACTER); |
| | | } else if (state->programHeader.len > 0) { |
| | | if (findCommandHeader(context, state->programHeader.ptr, state->programHeader.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); |
| | | } |
| | |
| | | parameter->type = TokUnknown; |
| | | parameter->data.ptr = NULL; |
| | | parameter->data.len = 0; |
| | | SCPI_ErrorPush(context, SCPI_ERROR_UNKNOWN_PARAMETER); |
| | | SCPI_ErrorPush(context, SCPI_ERROR_INVALID_STRING_DATA); |
| | | return FALSE; |
| | | } |
| | | } |
| | |
| | | case TokDecimalNumericProgramDataWithSuffix: |
| | | return parameter->number.value; |
| | | default: |
| | | SCPI_ErrorPush(context, SCPI_ERROR_INVALID_PARAMETER); |
| | | SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR); |
| | | return 0; |
| | | } |
| | | } |
| | |
| | | } else if (compareStr("OFF", 3, parameter->data.ptr, parameter->data.len)) { |
| | | return FALSE; |
| | | } else { |
| | | SCPI_ErrorPush(context, SCPI_ERROR_INVALID_PARAMETER); |
| | | SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); |
| | | return FALSE; |
| | | } |
| | | default: |
| | | SCPI_ErrorPush(context, SCPI_ERROR_INVALID_PARAMETER); |
| | | SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR); |
| | | return FALSE; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Get choice parameter |
| | | */ |
| | | int32_t SCPI_ParamGetChoiceVal(scpi_t * context, scpi_parameter_t * parameter, const char * options[]) { |
| | | size_t res; |
| | | |
| | | if (!options) { |
| | | SCPI_ErrorPush(context, SCPI_ERROR_SYSTEM_ERROR); |
| | | return -1; |
| | | } |
| | | |
| | | switch(parameter->type) { |
| | | case TokProgramMnemonic: |
| | | for (res = 0; options[res]; ++res) { |
| | | if (matchPattern(options[res], strlen(options[res]), parameter->data.ptr, parameter->data.len)) { |
| | | return res; |
| | | } |
| | | } |
| | | SCPI_ErrorPush(context, SCPI_ERROR_ILLEGAL_PARAMETER_VALUE); |
| | | return -1; |
| | | default: |
| | | SCPI_ErrorPush(context, SCPI_ERROR_DATA_TYPE_ERROR); |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | int SCPI_ParseProgramData(lex_state_t * state, token_t * token) { |
| | | token_t tmp; |
| | | int result = 0; |
| | |
| | | state.pos = state.buffer; |
| | | state.len = parameter->data.len; |
| | | |
| | | if (parameter->type == TokDecimalNumericProgramDataWithSuffix) { |
| | | switch(parameter->type) { |
| | | case TokDecimalNumericProgramDataWithSuffix: |
| | | SCPI_LexDecimalNumericProgramData(&state, &token); |
| | | SCPI_LexWhiteSpace(&state, &token); |
| | | SCPI_LexSuffixProgramData(&state, &token); |
| | | |
| | | return transformNumber(context, token.ptr, token.len, ¶meter->number); |
| | | |
| | | } else if (parameter->type == TokProgramMnemonic) { |
| | | case TokProgramMnemonic: |
| | | SCPI_LexWhiteSpace(&state, &token); |
| | | SCPI_LexCharacterProgramData(&state, &token); |
| | | |
| | | /* convert string to special number type */ |
| | | if (translateSpecialNumber(context->special_numbers, token.ptr, token.len, ¶meter->number)) { |
| | | /* found special type */ |
| | | return TRUE; |
| | | } |
| | | } |
| | | |
| | | return translateSpecialNumber(context->special_numbers, token.ptr, token.len, ¶meter->number); |
| | | default: |
| | | return FALSE; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Convert scpi_number_t to string |