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/ieee488.c | 50 ++++++++++++++++++++++++++++++++------------------ 1 files changed, 32 insertions(+), 18 deletions(-) diff --git a/libscpi/src/ieee488.c b/libscpi/src/ieee488.c index 6b4e62e..0593d23 100644 --- a/libscpi/src/ieee488.c +++ b/libscpi/src/ieee488.c @@ -84,7 +84,7 @@ * @param ctrl number of controll message * @param value value of related register */ -static size_t writeControl(scpi_t * context, int ctrl, scpi_reg_val_t val) { +static size_t writeControl(scpi_t * context, scpi_ctrl_name_t ctrl, scpi_reg_val_t val) { if (context && context->interface && context->interface->control) { return context->interface->control(context, ctrl, val); } else { @@ -98,13 +98,16 @@ * @param val - new value */ void SCPI_RegSet(scpi_t * context, scpi_reg_name_t name, scpi_reg_val_t val) { - bool_t srq = FALSE; + scpi_bool_t srq = FALSE; scpi_reg_val_t mask; + scpi_reg_val_t old_val; if ((name >= SCPI_REG_COUNT) || (context->registers == NULL)) { return; } + /* store old register value */ + old_val = context->registers[name]; /* set register value */ context->registers[name] = val; @@ -116,7 +119,10 @@ mask &= ~STB_SRQ; if (val & mask) { val |= STB_SRQ; - srq = TRUE; + /* avoid sending SRQ if nothing has changed */ + if (old_val != val) { + srq = TRUE; + } } else { val &= ~STB_SRQ; } @@ -145,11 +151,11 @@ case SCPI_REG_COUNT: - // nothing to do + /* nothing to do */ break; } - // set updated register value + /* set updated register value */ context->registers[name] = val; if (srq) { @@ -180,7 +186,7 @@ * @param context */ void SCPI_EventClear(scpi_t * context) { - // TODO + /* TODO */ SCPI_RegSet(context, SCPI_REG_ESR, 0); } @@ -206,7 +212,7 @@ scpi_result_t SCPI_CoreEse(scpi_t * context) { int32_t new_ESE; if (SCPI_ParamInt(context, &new_ESE, TRUE)) { - SCPI_RegSet(context, SCPI_REG_ESE, new_ESE); + SCPI_RegSet(context, SCPI_REG_ESE, (scpi_reg_val_t)new_ESE); } return SCPI_RES_OK; } @@ -234,13 +240,24 @@ /** * *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_ResultString(context, SCPI_MANUFACTURE); - SCPI_ResultString(context, SCPI_DEV_NAME); - SCPI_ResultString(context, SCPI_DEV_VERSION); + int i; + for (i = 0; i<4; i++) { + if (context->idn[i]) { + SCPI_ResultMnemonic(context, context->idn[i]); + } else { + SCPI_ResultMnemonic(context, "0"); + } + } return SCPI_RES_OK; } @@ -260,7 +277,7 @@ * @return */ scpi_result_t SCPI_CoreOpcQ(scpi_t * context) { - // Operation is always completed + /* Operation is always completed */ SCPI_ResultInt(context, 1); return SCPI_RES_OK; } @@ -285,7 +302,7 @@ scpi_result_t SCPI_CoreSre(scpi_t * context) { int32_t new_SRE; if (SCPI_ParamInt(context, &new_SRE, TRUE)) { - SCPI_RegSet(context, SCPI_REG_SRE, new_SRE); + SCPI_RegSet(context, SCPI_REG_SRE, (scpi_reg_val_t)new_SRE); } return SCPI_RES_OK; } @@ -316,11 +333,8 @@ * @return */ scpi_result_t SCPI_CoreTstQ(scpi_t * context) { - int result = 0; - if (context && context->interface && context->interface->test) { - result = context->interface->test(context); - } - SCPI_ResultInt(context, result); + (void) context; + SCPI_ResultInt(context, 0); return SCPI_RES_OK; } @@ -331,7 +345,7 @@ */ scpi_result_t SCPI_CoreWai(scpi_t * context) { (void) context; - // NOP + /* NOP */ return SCPI_RES_OK; } -- Gitblit v1.9.1