From 71c6c18189be9b7bf995d6e71b7ec5eb88161823 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周日, 24 4月 2016 23:18:58 +0800 Subject: [PATCH] Add support for array parameters represened as text (#52) --- libscpi/src/parser.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 96 insertions(+), 3 deletions(-) diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c index db6f5df..114fe3a 100644 --- a/libscpi/src/parser.c +++ b/libscpi/src/parser.c @@ -222,7 +222,7 @@ /* place undefined header with error */ /* calculate length of errornouse header and trim \r\n */ size_t r2 = r; - while(r2 > 0 && (data[r2 - 1] == '\r' || data[r2 - 1] == '\n')) r2--; + while (r2 > 0 && (data[r2 - 1] == '\r' || data[r2 - 1] == '\n')) r2--; SCPI_ErrorPushEx(context, SCPI_ERROR_UNDEFINED_HEADER, data, r2); result = FALSE; } @@ -280,6 +280,7 @@ } #if USE_DEVICE_DEPENDENT_ERROR_INFORMATION && !USE_MEMORY_ALLOCATION_FREE + /** * Initialize context's * @param context @@ -1545,7 +1546,7 @@ * @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) { +static size_t produceResultArrayBinary(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) { @@ -1610,7 +1611,7 @@ result += func(context, array[i]);\ }\ } else {\ - result = parserResultArrayBinary(context, array, count, sizeof(*array), format);\ + result = produceResultArrayBinary(context, array, count, sizeof(*array), format);\ }\ return result;\ } while(0) @@ -1734,3 +1735,95 @@ size_t SCPI_ResultArrayDouble(scpi_t * context, const double * array, size_t count, scpi_array_format_t format) { RESULT_ARRAY(SCPI_ResultDouble); } + +/* + * Template macro to generate all SCPI_ParamArrayXYZ function + */ +#define PARAM_ARRAY_TEMPLATE(func) do{\ + if (format != SCPI_FORMAT_ASCII) return FALSE;\ + for (*o_count = 0; *o_count < i_count; (*o_count)++) {\ + if (!func(context, &data[*o_count], mandatory)) {\ + break;\ + }\ + mandatory = FALSE;\ + }\ + return mandatory ? FALSE : TRUE;\ +}while(0) + +/** + * Read list of values up to i_count + * @param context + * @param data - array to fill + * @param i_count - number of elements of data + * @param o_count - real number of filled elements + * @param mandatory + * @return TRUE on success + */ +scpi_bool_t SCPI_ParamArrayInt32(scpi_t * context, int32_t *data, size_t i_count, size_t *o_count, scpi_array_format_t format, scpi_bool_t mandatory) { + PARAM_ARRAY_TEMPLATE(SCPI_ParamInt32); +} + +/** + * Read list of values up to i_count + * @param context + * @param data - array to fill + * @param i_count - number of elements of data + * @param o_count - real number of filled elements + * @param mandatory + * @return TRUE on success + */ +scpi_bool_t SCPI_ParamArrayUInt32(scpi_t * context, uint32_t *data, size_t i_count, size_t *o_count, scpi_array_format_t format, scpi_bool_t mandatory) { + PARAM_ARRAY_TEMPLATE(SCPI_ParamUInt32); +} + +/** + * Read list of values up to i_count + * @param context + * @param data - array to fill + * @param i_count - number of elements of data + * @param o_count - real number of filled elements + * @param mandatory + * @return TRUE on success + */ +scpi_bool_t SCPI_ParamArrayInt64(scpi_t * context, int64_t *data, size_t i_count, size_t *o_count, scpi_array_format_t format, scpi_bool_t mandatory) { + PARAM_ARRAY_TEMPLATE(SCPI_ParamInt64); +} + +/** + * Read list of values up to i_count + * @param context + * @param data - array to fill + * @param i_count - number of elements of data + * @param o_count - real number of filled elements + * @param mandatory + * @return TRUE on success + */ +scpi_bool_t SCPI_ParamArrayUInt64(scpi_t * context, uint64_t *data, size_t i_count, size_t *o_count, scpi_array_format_t format, scpi_bool_t mandatory) { + PARAM_ARRAY_TEMPLATE(SCPI_ParamUInt64); +} + +/** + * Read list of values up to i_count + * @param context + * @param data - array to fill + * @param i_count - number of elements of data + * @param o_count - real number of filled elements + * @param mandatory + * @return TRUE on success + */ +scpi_bool_t SCPI_ParamArrayFloat(scpi_t * context, float *data, size_t i_count, size_t *o_count, scpi_array_format_t format, scpi_bool_t mandatory) { + PARAM_ARRAY_TEMPLATE(SCPI_ParamFloat); +} + +/** + * Read list of values up to i_count + * @param context + * @param data - array to fill + * @param i_count - number of elements of data + * @param o_count - real number of filled elements + * @param mandatory + * @return TRUE on success + */ +scpi_bool_t SCPI_ParamArrayDouble(scpi_t * context, double *data, size_t i_count, size_t *o_count, scpi_array_format_t format, scpi_bool_t mandatory) { + PARAM_ARRAY_TEMPLATE(SCPI_ParamDouble); +} -- Gitblit v1.9.1