From 23d91ad453f5feafeb1e871bd243e01049faec5b Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周三, 05 8月 2015 02:52:30 +0800 Subject: [PATCH] Merge lhoerl changes --- libscpi/inc/scpi/debug.h | 4 libscpi/src/lexer.c | 10 libscpi/inc/scpi/error.h | 162 +++++++++++++++++++++++--- libscpi/inc/scpi/types.h | 36 +++-- libscpi/src/parser.c | 48 ++++--- libscpi/inc/scpi/config.h | 61 +++++++++ libscpi/src/error.c | 31 +++- libscpi/inc/scpi/parser.h | 1 libscpi/src/utils.c | 6 9 files changed, 278 insertions(+), 81 deletions(-) diff --git a/libscpi/inc/scpi/config.h b/libscpi/inc/scpi/config.h index 811d5a4..e301c56 100644 --- a/libscpi/inc/scpi/config.h +++ b/libscpi/inc/scpi/config.h @@ -2,7 +2,7 @@ * Copyright (c) 2012-2013 Jan Breuer, * * All Rights Reserved - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: @@ -11,7 +11,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -28,10 +28,10 @@ /** * @file config.h * @date Wed Mar 20 12:21:26 UTC 2013 - * + * * @brief SCPI Configuration - * - * + * + * */ #ifndef __SCPI_CONFIG_H_ @@ -41,7 +41,54 @@ extern "C" { #endif +#ifdef SCPI_USER_CONFIG +#include "scpi_user_config.h" +#endif + +/* set the termination character(s) */ +#define LINE_ENDING_CR "\r" /* use a <CR> carriage return as termination charcter */ +#define LINE_ENDING_LF "\n" /* use a <LF> line feed as termination charcter */ +#define LINE_ENDING_CRLF "\r\n" /* use <CR><LF> carriage return + line feed as termination charcters */ + +#ifndef SCPI_LINE_ENDING +#define SCPI_LINE_ENDING LINE_ENDING_CRLF +#endif + +/* Enable full error list + * 0 = Minimal set of errors + * 1 = Full set of errors + * + * For small systems, full set of errors will occupy large ammount of data + */ +#ifndef USE_FULL_ERROR_LIST +#define USE_FULL_ERROR_LIST 0 +#endif + +/** + * Enable also LIST_OF_USER_ERRORS to be included + * 0 = Use only library defined errors + * 1 = Use also LIST_OF_USER_ERRORS + */ +#ifndef USE_USER_ERROR_LIST +#define USE_USER_ERROR_LIST 0 +#endif + /* Compiler specific */ +/* RealView/Keil ARM Compiler, e.g. Cortex-M CPUs */ +#if defined(__CC_ARM) +#define HAVE_STRNLEN 0 +#define HAVE_STRNCASECMP 1 +#define HAVE_STRNICMP 0 +#endif + +/* National Instruments (R) CVI x86/x64 PC platform */ +#if defined(_CVI_) +#define HAVE_STRNLEN 0 +#define HAVE_STRNCASECMP 0 +#define HAVE_STRNICMP 1 +#define HAVE_STDBOOL 0 +#endif + /* 8bit PIC - PIC16, etc */ #if defined(_MPC_) #define HAVE_STRNLEN 0 @@ -82,6 +129,10 @@ #define HAVE_STRNICMP 0 #endif +#ifndef HAVE_STDBOOL +#define HAVE_STDBOOL 1 +#endif + /* define local macros depending on existance of strnlen */ #if HAVE_STRNLEN #define SCPIDEFINE_strnlen(s, l) strnlen((s), (l)) diff --git a/libscpi/inc/scpi/debug.h b/libscpi/inc/scpi/debug.h index b1e8047..8526a74 100644 --- a/libscpi/inc/scpi/debug.h +++ b/libscpi/inc/scpi/debug.h @@ -26,7 +26,7 @@ */ /** - * @file scpi_debug.h + * @file debug.h * @date Thu Nov 15 10:58:45 UTC 2012 * * @brief SCPI debug function @@ -44,7 +44,7 @@ #endif - /* #define SCPI_DEBUG_COMMAND(a) scpi_debug_command(a) */ + /* #define SCPI_DEBUG_COMMAND(a) SCPI_DebugCommand(a) */ #define SCPI_DEBUG_COMMAND(a) diff --git a/libscpi/inc/scpi/error.h b/libscpi/inc/scpi/error.h index 0e21a96..75d1166 100644 --- a/libscpi/inc/scpi/error.h +++ b/libscpi/inc/scpi/error.h @@ -35,11 +35,12 @@ */ #ifndef SCPI_ERROR_H -#define SCPI_ERROR_H +#define SCPI_ERROR_H +#include "scpi/config.h" #include "scpi/types.h" -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -50,33 +51,154 @@ int32_t SCPI_ErrorCount(scpi_t * context); const char * SCPI_ErrorTranslate(int16_t err); -/* 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_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_INVALID_STRING_DATA, -151, "Invalid string data") \ - X(SCPI_ERROR_INVALID_BLOCK_DATA, -161, "Invalid block 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") \ +/* Using X-Macro technique to define everything once + * http://en.wikipedia.org/wiki/X_Macro + * + * X macro is for minimal set of errors for library itself + * XE macro is for full set of SCPI errors available to user application + */ +#define LIST_OF_ERRORS \ + XE(SCPI_ERROR_COMMAND, -100, "Command error") \ + X(SCPI_ERROR_INVALID_CHARACTER, -101, "Invalid character") \ + XE(SCPI_ERROR_SYNTAX, -102, "Syntax error") \ + X(SCPI_ERROR_INVALID_SEPARATOR, -103, "Invalid separator") \ + X(SCPI_ERROR_DATA_TYPE_ERROR, -104, "Data type error") \ + XE(SCPI_ERROR_GET_NOT_ALLOWED, -105, "GET not allowed") \ + X(SCPI_ERROR_PARAMETER_NOT_ALLOWED, -108, "Parameter not allowed") \ + X(SCPI_ERROR_MISSING_PARAMETER, -109, "Missing parameter") \ + XE(SCPI_ERROR_COMMAND_HEADER, -110, "Command header error") \ + XE(SCPI_ERROR_HEADER_SEPARATOR, -111, "Header separator error") \ + XE(SCPI_ERROR_PRG_MNEMONIC_TOO_LONG, -112, "Program mnemonic too long") \ + X(SCPI_ERROR_UNDEFINED_HEADER, -113, "Undefined header") \ + XE(SCPI_ERROR_HEADER_SUFFIX_OUTOFRANGE, -114, "Header suffix out of range") \ + XE(SCPI_ERROR_UNEXP_NUM_OF_PARAMETER, -115, "Unexpected number of parameters") \ + XE(SCPI_ERROR_NUMERIC_DATA_ERROR, -120, "Numeric data error") \ + XE(SCPI_ERROR_INVAL_CHAR_IN_NUMBER, -121, "Invalid character in number") \ + XE(SCPI_ERROR_EXPONENT_TOO_LONG, -123, "Exponent too large") \ + XE(SCPI_ERROR_TOO_MANY_DIGITS, -124, "Too many digits") \ + XE(SCPI_ERROR_NUMERIC_DATA_NOT_ALLOWED, -128, "Numeric data not allowed") \ + XE(SCPI_ERROR_SUFFIX_ERROR, -130, "Suffix error") \ + X(SCPI_ERROR_INVALID_SUFFIX, -131, "Invalid suffix") \ + XE(SCPI_ERROR_SUFFIX_TOO_LONG, -134, "Suffix too long") \ + X(SCPI_ERROR_SUFFIX_NOT_ALLOWED, -138, "Suffix not allowed") \ + XE(SCPI_ERROR_CHARACTER_DATA_ERROR, -140, "Character data error") \ + XE(SCPI_ERROR_INVAL_CHARACTER_DATA, -141, "Invalid character data") \ + XE(SCPI_ERROR_CHARACTER_DATA_TOO_LONG, -144, "Character data too long") \ + XE(SCPI_ERROR_CHARACTER_DATA_NOT_ALLOWED, -148, "Character data not allowed") \ + XE(SCPI_ERROR_STRING_DATA_ERROR, -150, "String data error") \ + X(SCPI_ERROR_INVALID_STRING_DATA, -151, "Invalid string data") \ + XE(SCPI_ERROR_STRING_DATA_NOT_ALLOWED, -158, "String data not allowed") \ + XE(SCPI_ERROR_BLOCK_DATA_ERROR, -160, "Block data error") \ + XE(SCPI_ERROR_INVALID_BLOCK_DATA, -161, "Invalid block data") \ + XE(SCPI_ERROR_BLOCK_DATA_NOT_ALLOWED, -168, "Block data not allowed") \ + XE(SCPI_ERROR_EXPRESSION_PARSING_ERROR, -170, "Expression error") \ + XE(SCPI_ERROR_INVAL_EXPRESSION, -171, "Invalid expression") \ + XE(SCPI_ERROR_EXPRESSION_DATA_NOT_ALLOWED, -178, "Expression data not allowed") \ + XE(SCPI_ERROR_MACRO_DEFINITION_ERROR, -180, "Macro error") \ + XE(SCPI_ERROR_INVAL_OUTSIDE_MACRO_DEF, -181, "Invalid outside macro definition") \ + XE(SCPI_ERROR_INVAL_INSIDE_MACRO_DEF, -183, "Invalid inside macro definition") \ + XE(SCPI_ERROR_MACRO_PARAMETER_ERROR, -184, "Macro parameter error") \ + X(SCPI_ERROR_EXECUTION_ERROR, -200, "Execution error") \ + XE(SCPI_ERROR_INVAL_WHILE_IN_LOCAL, -201, "Invalid while in local") \ + XE(SCPI_ERROR_SETTINGS_LOST_DUE_TO_RTL, -202, "Settings lost due to rtl") \ + XE(SCPI_ERROR_COMMAND_PROTECTED, -203, "Command protected TK024") \ + XE(SCPI_ERROR_TRIGGER_ERROR, -210, "Trigger error") \ + XE(SCPI_ERROR_TRIGGER_IGNORED, -211, "Trigger ignored") \ + XE(SCPI_ERROR_ARM_IGNORED, -212, "Arm ignored") \ + XE(SCPI_ERROR_INIT_IGNORED, -213, "Init ignored") \ + XE(SCPI_ERROR_TRIGGER_DEADLOCK, -214, "Trigger deadlock") \ + XE(SCPI_ERROR_ARM_DEADLOCK, -215, "Arm deadlock") \ + XE(SCPI_ERROR_PARAMETER_ERROR, -220, "Parameter error") \ + XE(SCPI_ERROR_SETTINGS_CONFLICT, -221, "Settings conflict") \ + XE(SCPI_ERROR_DATA_OUT_OF_RANGE, -222, "Data out of range") \ + XE(SCPI_ERROR_TOO_MUCH_DATA, -223, "Too much data") \ + X(SCPI_ERROR_ILLEGAL_PARAMETER_VALUE, -224, "Illegal parameter value") \ + XE(SCPI_ERROR_OUT_OF_MEMORY_FOR_REQ_OP, -225, "Out of memory") \ + XE(SCPI_ERROR_LISTS_NOT_SAME_LENGTH, -226, "Lists not same length") \ + XE(SCPI_ERROR_DATA_CORRUPT, -230, "Data corrupt or stale") \ + XE(SCPI_ERROR_DATA_QUESTIONABLE, -231, "Data questionable") \ + XE(SCPI_ERROR_INVAL_VERSION, -233, "Invalid version") \ + XE(SCPI_ERROR_HARDWARE_ERROR, -240, "Hardware error") \ + XE(SCPI_ERROR_HARDWARE_MISSING, -241, "Hardware missing") \ + XE(SCPI_ERROR_MASS_STORAGE_ERROR, -250, "Mass storage error") \ + XE(SCPI_ERROR_MISSING_MASS_STORAGE, -251, "Missing mass storage") \ + XE(SCPI_ERROR_MISSING_MASS_MEDIA, -252, "Missing media") \ + XE(SCPI_ERROR_CORRUPT_MEDIA, -253, "Corrupt media") \ + XE(SCPI_ERROR_MEDIA_FULL, -254, "Media full") \ + XE(SCPI_ERROR_DIRECTORY_FULL, -255, "Directory full") \ + XE(SCPI_ERROR_FILE_NAME_NOT_FOUND, -256, "File name not found") \ + XE(SCPI_ERROR_FILE_NAME_ERROR, -257, "File name error") \ + XE(SCPI_ERROR_MEDIA_PROTECTED, -258, "Media protected") \ + XE(SCPI_ERROR_EXPRESSION_EXECUTING_ERROR, -260, "Expression error") \ + XE(SCPI_ERROR_MATH_ERROR_IN_EXPRESSION, -261, "Math error in expression") \ + XE(SCPI_ERROR_MACRO_UNDEF_EXEC_ERROR, -270, "Macro error") \ + XE(SCPI_ERROR_MACRO_SYNTAX_ERROR, -271, "Macro syntax error") \ + XE(SCPI_ERROR_MACRO_EXECUTION_ERROR, -272, "Macro execution error") \ + XE(SCPI_ERROR_ILLEGAL_MACRO_LABEL, -273, "Illegal macro label") \ + XE(SCPI_ERROR_IMPROPER_USED_MACRO_PARAM, -274, "Macro parameter error") \ + XE(SCPI_ERROR_MACRO_DEFINITION_TOO_LONG, -275, "Macro definition too long") \ + XE(SCPI_ERROR_MACRO_RECURSION_ERROR, -276, "Macro recursion error") \ + XE(SCPI_ERROR_MACRO_REDEF_NOT_ALLOWED, -277, "Macro redefinition not allowed") \ + XE(SCPI_ERROR_MACRO_HEADER_NOT_FOUND, -278, "Macro header not found") \ + XE(SCPI_ERROR_PROGRAM_ERROR, -280, "Program error") \ + XE(SCPI_ERROR_CANNOT_CREATE_PROGRAM, -281, "Cannot create program") \ + XE(SCPI_ERROR_ILLEGAL_PROGRAM_NAME, -282, "Illegal program name") \ + XE(SCPI_ERROR_ILLEGAL_VARIABLE_NAME, -283, "Illegal variable name") \ + XE(SCPI_ERROR_PROGRAM_CURRENTLY_RUNNING, -284, "Program currently running") \ + XE(SCPI_ERROR_PROGRAM_SYNTAX_ERROR, -285, "Program syntax error") \ + XE(SCPI_ERROR_PROGRAM_RUNTIME_ERROR, -286, "Program runtime error") \ + XE(SCPI_ERROR_MEMORY_USE_ERROR, -290, "Memory use error") \ + XE(SCPI_ERROR_OUT_OF_MEMORY, -291, "Out of memory") \ + XE(SCPI_ERROR_REF_NAME_DOES_NOT_EXIST, -292, "Referenced name does not exist") \ + XE(SCPI_ERROR_REF_NAME_ALREADY_EXISTS, -293, "Referenced name already exists") \ + XE(SCPI_ERROR_INCOMPATIBLE_TYPE, -294, "Incompatible type") \ + XE(SCPI_ERROR_DEVICE_ERROR, -300, "Device specific error") \ + X(SCPI_ERROR_SYSTEM_ERROR, -310, "System error") \ + XE(SCPI_ERROR_MEMORY_ERROR, -311, "Memory error") \ + XE(SCPI_ERROR_PUD_MEMORY_LOST, -312, "PUD memory lost") \ + XE(SCPI_ERROR_CALIBRATION_MEMORY_LOST, -313, "Calibration memory lost") \ + XE(SCPI_ERROR_SAVE_RECALL_MEMORY_LOST, -314, "Save/recall memory lost") \ + XE(SCPI_ERROR_CONFIGURATION_MEMORY_LOST, -315, "Configuration memory lost") \ + XE(SCPI_ERROR_STORAGE_FAULT, -320, "Storage fault") \ + XE(SCPI_ERROR_OUT_OF_DEVICE_MEMORY, -321, "Out of memory") \ + XE(SCPI_ERROR_SELF_TEST_FAILED, -330, "Self-test failed") \ + XE(SCPI_ERROR_CALIBRATION_FAILED, -340, "Calibration failed") \ + XE(SCPI_ERROR_QUEUE_OVERFLOW, -350, "Queue overflow") \ + XE(SCPI_ERROR_COMMUNICATION_ERROR, -360, "Communication error") \ + XE(SCPI_ERROR_PARITY_ERROR_IN_CMD_MSG, -361, "Parity error in program message") \ + XE(SCPI_ERROR_FRAMING_ERROR_IN_CMD_MSG, -362, "Framing error in program message") \ + XE(SCPI_ERROR_INPUT_BUFFER_OVERRUN, -363, "Input buffer overrun") \ + XE(SCPI_ERROR_TIME_OUT, -365, "Time out error") \ + XE(SCPI_ERROR_QUERY_ERROR, -400, "Query error") \ + XE(SCPI_ERROR_QUERY_INTERRUPTED, -410, "Query INTERRUPTED") \ + XE(SCPI_ERROR_QUERY_UNTERMINATED, -420, "Query UNTERMINATED") \ + XE(SCPI_ERROR_QUERY_DEADLOCKED, -430, "Query DEADLOCKED") \ + XE(SCPI_ERROR_QUERY_UNTERM_INDEF_RESP, -440, "Query UNTERMINATED after indefinite response") \ + XE(SCPI_ERROR_POWER_ON, -500, "Power on") \ + XE(SCPI_ERROR_USER_REQUEST, -600, "User request") \ + XE(SCPI_ERROR_REQUEST_CONTROL, -700, "Request control") \ + XE(SCPI_ERROR_OPERATION_COMPLETE, -800, "Operation complete") \ enum { #define X(def, val, str) def = val, +#if USE_FULL_ERROR_LIST +#define XE X +#else +#define XE(def, val, str) +#endif LIST_OF_ERRORS + +#if USE_USER_ERROR_LIST +LIST_OF_USER_ERRORS +#endif #undef X +#undef XE }; -#ifdef __cplusplus +#ifdef __cplusplus } #endif -#endif /* SCPI_ERROR_H */ +#endif /* SCPI_ERROR_H */ diff --git a/libscpi/inc/scpi/parser.h b/libscpi/inc/scpi/parser.h index cb90893..4bb8d2c 100644 --- a/libscpi/inc/scpi/parser.h +++ b/libscpi/inc/scpi/parser.h @@ -39,7 +39,6 @@ #include <string.h> #include "scpi/types.h" -#include "scpi/debug.h" #ifdef __cplusplus extern "C" { diff --git a/libscpi/inc/scpi/types.h b/libscpi/inc/scpi/types.h index 3ce30ab..db52e81 100644 --- a/libscpi/inc/scpi/types.h +++ b/libscpi/inc/scpi/types.h @@ -4,7 +4,7 @@ * Copyright (c) 2012 Jan Breuer * * All Rights Reserved - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: @@ -13,7 +13,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -30,10 +30,10 @@ /** * @file scpi_types.h * @date Thu Nov 15 10:58:45 UTC 2012 - * + * * @brief SCPI data types - * - * + * + * */ #ifndef SCPI_TYPES_H @@ -41,10 +41,18 @@ #include <stddef.h> #include <stdint.h> +#include "scpi/config.h" + +#if HAVE_STDBOOL #include <stdbool.h> +#endif #ifdef __cplusplus extern "C" { +#endif + +#if !HAVE_STDBOOL + typedef unsigned char bool; #endif #ifndef FALSE @@ -117,7 +125,7 @@ char * data; }; typedef struct _scpi_buffer_t scpi_buffer_t; - + struct _scpi_const_buffer_t { size_t length; size_t position; @@ -173,14 +181,14 @@ }; typedef struct _lex_state_t lex_state_t; - /* scpi parser */ + /* scpi parser */ enum _message_termination_t { SCPI_MESSAGE_TERMINATION_NONE, SCPI_MESSAGE_TERMINATION_NL, - SCPI_MESSAGE_TERMINATION_SEMICOLON, + SCPI_MESSAGE_TERMINATION_SEMICOLON, }; typedef enum _message_termination_t message_termination_t; - + struct _scpi_parser_state_t { scpi_token_t programHeader; scpi_token_t programData; @@ -241,8 +249,8 @@ lex_state_t lex_state; scpi_const_buffer_t cmd_raw; }; - typedef struct _scpi_param_list_t scpi_param_list_t; - + typedef struct _scpi_param_list_t scpi_param_list_t; + struct _scpi_number_parameter_t { scpi_bool_t special; union { @@ -256,12 +264,12 @@ struct _scpi_data_parameter_t { const char * ptr; - int32_t len; + int32_t len; }; typedef struct _scpi_data_parameter_t scpi_data_parameter_t; - + typedef scpi_token_t scpi_parameter_t; - + struct _scpi_command_t { const char * pattern; scpi_command_callback_t callback; diff --git a/libscpi/src/error.c b/libscpi/src/error.c index da0398e..d856db3 100644 --- a/libscpi/src/error.c +++ b/libscpi/src/error.c @@ -2,7 +2,7 @@ * Copyright (c) 2012-2013 Jan Breuer, * * All Rights Reserved - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: @@ -11,7 +11,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -28,10 +28,10 @@ /** * @file scpi_error.c * @date Thu Nov 15 10:58:45 UTC 2012 - * + * * @brief Error handling and storing routines - * - * + * + * */ #include <stdint.h> @@ -98,7 +98,7 @@ /** * Return number of errors/events in the queue * @param context - * @return + * @return */ int32_t SCPI_ErrorCount(scpi_t * context) { int16_t result = 0; @@ -130,12 +130,13 @@ scpi_reg_val_t bit; }; -#define ERROR_DEFS_N 8 +#define ERROR_DEFS_N 9 static const struct error_reg errs[ERROR_DEFS_N] = { {-100, -199, ESR_CER}, /* Command error (e.g. syntax error) ch 21.8.9 */ {-200, -299, ESR_EER}, /* Execution Error (e.g. range error) ch 21.8.10 */ {-300, -399, ESR_DER}, /* Device specific error -300, -399 ch 21.8.11 */ + { 1,32767, ESR_DER}, /* Device designer provided specific error 1, 32767 ch 21.8.11 */ {-400, -499, ESR_QER}, /* Query error -400, -499 ch 21.8.12 */ {-500, -599, ESR_PON}, /* Power on event -500, -599 ch 21.8.13 */ {-600, -699, ESR_URQ}, /* User Request Event -600, -699 ch 21.8.14 */ @@ -177,9 +178,19 @@ const char * SCPI_ErrorTranslate(int16_t err) { switch (err) { case 0: return "No error"; - #define X(def, val, str) case def: return str; - LIST_OF_ERRORS - #undef X +#define X(def, val, str) case def: return str; +#if USE_FULL_ERROR_LIST +#define XE X +#else +#define XE(def, val, str) +#endif +LIST_OF_ERRORS + +#if USE_USER_ERROR_LIST +LIST_OF_USER_ERRORS +#endif +#undef X +#undef XE default: return "Unknown error"; } } diff --git a/libscpi/src/lexer.c b/libscpi/src/lexer.c index c0505cc..194205b 100644 --- a/libscpi/src/lexer.c +++ b/libscpi/src/lexer.c @@ -594,8 +594,8 @@ * @return */ int scpiLex_NondecimalNumericData(lex_state_t * state, scpi_token_t * token) { - token->ptr = state->pos; int someNumbers = 0; + token->ptr = state->pos; if (skipChr(state, '#')) { if (!iseos(state)) { if (isH(state->pos[0])) { @@ -630,7 +630,7 @@ return (c >= 0) && (c <= 0x7f); } -static int skipQuoteProgramData(lex_state_t * state, int quote) { +static void skipQuoteProgramData(lex_state_t * state, int quote) { while (!iseos(state)) { if (isascii7bit(state->pos[0]) && !ischr(state, quote)) { state->pos++; @@ -646,11 +646,11 @@ } } -static int skipDoubleQuoteProgramData(lex_state_t * state) { +static void skipDoubleQuoteProgramData(lex_state_t * state) { skipQuoteProgramData(state, '"'); } -static int skipSingleQuoteProgramData(lex_state_t * state) { +static void skipSingleQuoteProgramData(lex_state_t * state) { skipQuoteProgramData(state, '\''); } @@ -716,8 +716,8 @@ int i; int arbitraryBlockLength = 0; const char * ptr = state->pos; - token->ptr = state->pos; int validData = -1; + token->ptr = state->pos; if (skipChr(state, '#')) { if (!iseos(state) && isNonzeroDigit(state->pos[0])) { diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index 375f4ac..921e885 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -44,6 +44,7 @@ #include "scpi/error.h" #include "scpi/constants.h" #include "scpi/utils.h" +#include "scpi/debug.h" /** * Write data to SCPI output @@ -90,7 +91,10 @@ static size_t writeNewLine(scpi_t * context) { if (context->output_count > 0) { size_t len; - len = writeData(context, "\r\n", 2); +#ifndef SCPI_LINE_ENDING +#error no termination character defined +#endif + len = writeData(context, SCPI_LINE_ENDING, strlen(SCPI_LINE_ENDING)); flushData(context); return len; } else { @@ -327,7 +331,7 @@ /** * Return prefix of nondecimal base * @param base - * @return + * @return */ static const char * getBasePrefix(int8_t base) { switch (base) { @@ -343,7 +347,7 @@ * @param context * @param val * @param base - * @return + * @return */ size_t SCPI_ResultIntBase(scpi_t * context, int32_t val, int8_t base) { char buffer[33]; @@ -402,7 +406,7 @@ * @param context * @param data * @param len - * @return + * @return */ size_t SCPI_ResultArbitraryBlock(scpi_t * context, const char * data, size_t len) { size_t result = 0; @@ -449,7 +453,7 @@ * @param context * @param parameter * @param mandatory - * @return + * @return */ scpi_bool_t SCPI_Parameter(scpi_t * context, scpi_parameter_t * parameter, scpi_bool_t mandatory) { lex_state_t * state; @@ -507,7 +511,7 @@ * Detect if parameter is number * @param parameter * @param suffixAllowed - * @return + * @return */ scpi_bool_t SCPI_ParamIsNumber(scpi_parameter_t * parameter, scpi_bool_t suffixAllowed) { switch (parameter->type) { @@ -528,7 +532,7 @@ * @param context * @param parameter * @param value result - * @return true if succesful + * @return TRUE if succesful */ scpi_bool_t SCPI_ParamToInt(scpi_t * context, scpi_parameter_t * parameter, int32_t * value) { @@ -556,7 +560,7 @@ * @param context * @param parameter * @param value result - * @return true if succesful + * @return TRUE if succesful */ scpi_bool_t SCPI_ParamToDouble(scpi_t * context, scpi_parameter_t * parameter, double * value) { scpi_bool_t result = FALSE; @@ -587,7 +591,7 @@ * @param context * @param value * @param mandatory - * @return + * @return */ scpi_bool_t SCPI_ParamDouble(scpi_t * context, double * value, scpi_bool_t mandatory) { scpi_bool_t result; @@ -618,7 +622,7 @@ * @param context * @param value * @param mandatory - * @return + * @return */ scpi_bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, scpi_bool_t mandatory) { scpi_bool_t result; @@ -650,7 +654,7 @@ * @param value * @param len * @param mandatory - * @return + * @return */ scpi_bool_t SCPI_ParamCharacters(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) { scpi_bool_t result; @@ -678,7 +682,7 @@ * @param value result pointer to data * @param len result length of data * @param mandatory - * @return + * @return */ scpi_bool_t SCPI_ParamArbitraryBlock(scpi_t * context, const char ** value, size_t * len, scpi_bool_t mandatory) { scpi_bool_t result; @@ -748,7 +752,7 @@ * @param parameter - should be PROGRAM_MNEMONIC * @param options - NULL terminated list of choices * @param value - index to options - * @return + * @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; @@ -783,7 +787,7 @@ * @param options specifications of choices numbers (patterns) * @param tag numerical representatio of choice * @param text result text - * @return true if succesfule, else false + * @return TRUE if succesfule, else false */ scpi_bool_t SCPI_ChoiceToName(const scpi_choice_def_t * options, int32_t tag, const char ** text) { int i; @@ -803,7 +807,7 @@ * @param context * @param value * @param mandatory - * @return + * @return */ scpi_bool_t SCPI_ParamBool(scpi_t * context, scpi_bool_t * value, scpi_bool_t mandatory) { scpi_bool_t result; @@ -844,7 +848,7 @@ * @param options * @param value * @param mandatory - * @return + * @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; @@ -867,7 +871,7 @@ * Parse one parameter and detect type * @param state * @param token - * @return + * @return */ int scpiParser_parseProgramData(lex_state_t * state, scpi_token_t * token) { scpi_token_t tmp; @@ -906,7 +910,7 @@ * @param state * @param token * @param numberOfParameters - * @return + * @return */ int scpiParser_parseAllProgramData(lex_state_t * state, scpi_token_t * token, int * numberOfParameters) { @@ -956,7 +960,7 @@ * @param state * @param buffer * @param len - * @return + * @return */ int scpiParser_detectProgramMessageUnit(scpi_parser_state_t * state, char * buffer, int len) { lex_state_t lex_state; @@ -1009,14 +1013,16 @@ * - suitable for one handle to multiple commands * @param context * @param cmd - * @return + * @return */ scpi_bool_t SCPI_IsCmd(scpi_t * context, const char * cmd) { + const char * pattern; + if (!context->param_list.cmd) { return FALSE; } - const char * pattern = context->param_list.cmd->pattern; + pattern = context->param_list.cmd->pattern; return matchCommand (pattern, cmd, strlen (cmd), NULL, 0); } diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c index 2569570..be9f93e 100644 --- a/libscpi/src/utils.c +++ b/libscpi/src/utils.c @@ -338,7 +338,7 @@ int rightFlag = 0; // flag for ']' on right int cmd_sep_pos = 0; - size_t numbers_idx = -1; + size_t numbers_idx = 0; int32_t *number_ptr = NULL; const char * pattern_ptr = pattern; @@ -379,13 +379,13 @@ } if (pattern_ptr[pattern_sep_pos - 1] == '#') { - numbers_idx++; if (numbers && (numbers_idx < numbers_len)) { number_ptr = numbers + numbers_idx; *number_ptr = 1; // default value } else { number_ptr = NULL; } + numbers_idx++; } else { number_ptr = NULL; } @@ -548,7 +548,7 @@ if (c1 != c2) { return c1 - c2; } - if (c1 = '\0') { + if (c1 == '\0') { return 0; } } -- Gitblit v1.9.1