From 83847012f9b0a0d479725d4741c551c88d7035c2 Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周六, 25 4月 2015 22:54:36 +0800
Subject: [PATCH] Solve #16 Multiple Identical Capabilities

---
 libscpi/src/ieee488.c |   44 +++++++++++++++++++++++++++++---------------
 1 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/libscpi/src/ieee488.c b/libscpi/src/ieee488.c
index 855c9f1..e91d62a 100644
--- a/libscpi/src/ieee488.c
+++ b/libscpi/src/ieee488.c
@@ -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);
 }
 
@@ -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;
 }
@@ -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