From 5e68cb0db1499c7cda1e7448e8fc1ebdb3e9f322 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周一, 05 10月 2015 21:47:23 +0800 Subject: [PATCH] Resolve #54: Detect not typed numbers in SCPI_CommandNumbers --- libscpi/src/error.c | 59 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 44 insertions(+), 15 deletions(-) diff --git a/libscpi/src/error.c b/libscpi/src/error.c index be98d79..34735d2 100644 --- a/libscpi/src/error.c +++ b/libscpi/src/error.c @@ -39,7 +39,6 @@ #include "scpi/parser.h" #include "scpi/ieee488.h" #include "scpi/error.h" -#include "scpi-def.h" /* this file is needed for the user provided SCPI errors */ #include "fifo_private.h" /* basic FIFO */ @@ -62,6 +61,33 @@ } /** + * Emit no error + * @param context scpi context + */ +static void SCPI_ErrorEmitEmpty(scpi_t * context) { + if ((SCPI_ErrorCount(context) == 0) && (SCPI_RegGet(context, SCPI_REG_STB) & STB_QMA)) { + SCPI_RegClearBits(context, SCPI_REG_STB, STB_QMA); + + if (context->interface && context->interface->error) { + context->interface->error(context, 0); + } + } +} + +/** + * Emit error + * @param context scpi context + * @param err Error to emit + */ +static void SCPI_ErrorEmit(scpi_t * context, int16_t err) { + SCPI_RegSetBits(context, SCPI_REG_STB, STB_QMA); + + if (context->interface && context->interface->error) { + context->interface->error(context, err); + } +} + +/** * Clear error queue * @param context - scpi context */ @@ -73,6 +99,8 @@ /* basic FIFO */ fifo_clear((scpi_fifo_t *)context->error_queue); + + SCPI_ErrorEmitEmpty(context); } /** @@ -92,6 +120,8 @@ /* basic FIFO */ fifo_remove((scpi_fifo_t *)context->error_queue, &result); + + SCPI_ErrorEmitEmpty(context); return result; } @@ -162,11 +192,9 @@ } } - if (context) { - if (context->interface && context->interface->error) { - context->interface->error(context, err); - } + SCPI_ErrorEmit(context, err); + if (context) { context->cmd_error = TRUE; } } @@ -179,18 +207,19 @@ const char * SCPI_ErrorTranslate(int16_t err) { switch (err) { case 0: return "No error"; -#if ((USED_SCPI_ERROR_LIST == ERR_SCPI_MINIMUM) || (USED_SCPI_ERROR_LIST == ERR_SCPI_FULL)) - #define X(def, val, str) case def: return str; - LIST_OF_ERRORS - #undef X -#elif ((USED_SCPI_ERROR_LIST == ERR_SCPI_MIN_PLUS_USER) || (USED_SCPI_ERROR_LIST == ERR_SCPI_FULL_PLUS_USER)) - #define X(def, val, str) case def: return str; - LIST_OF_ERRORS - LIST_OF_USER_ERRORS - #undef X +#define X(def, val, str) case def: return str; +#if USE_FULL_ERROR_LIST +#define XE X #else -#error no SCPI error list defined! +#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"; } } -- Gitblit v1.9.1