| | |
| | | #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 */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | | */ |
| | |
| | | |
| | | /* basic FIFO */ |
| | | fifo_clear((scpi_fifo_t *)context->error_queue); |
| | | |
| | | SCPI_ErrorEmitEmpty(context); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | /* basic FIFO */ |
| | | fifo_remove((scpi_fifo_t *)context->error_queue, &result); |
| | | |
| | | SCPI_ErrorEmitEmpty(context); |
| | | |
| | | return result; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | if (context) { |
| | | if (context->interface && context->interface->error) { |
| | | context->interface->error(context, err); |
| | | } |
| | | SCPI_ErrorEmit(context, err); |
| | | |
| | | if (context) { |
| | | context->cmd_error = TRUE; |
| | | } |
| | | } |
| | |
| | | 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"; |
| | | } |
| | | } |