]> sigrok.org Git - libsigrok.git/commitdiff
scpi: accept numbers like 4.0000E3 as integer value
authorRalf <redacted>
Tue, 25 Aug 2020 06:19:18 +0000 (08:19 +0200)
committerGerhard Sittig <redacted>
Sun, 27 Sep 2020 10:51:39 +0000 (12:51 +0200)
MSO5000 returns memory depth value in that format, e.g.
sr: [04:21.491949] scpi_vxi: Successfully sent SCPI command: 'ACQ:MDEP?'.
sr: [04:21.501463] scpi: Got response: '4.0000E+03', length 10.

[ gsi: drop redundant assignment and parens, amend diag message ]

src/scpi/scpi.c

index f72164a63f177dce0b71dd5d07fbc312566dadd8..9fa4ac03605392245ca0077f468cd006bb99f235 100644 (file)
@@ -724,6 +724,7 @@ SR_PRIV int sr_scpi_get_int(struct sr_scpi_dev_inst *scpi,
                            const char *command, int *scpi_response)
 {
        int ret;
+       struct sr_rational ret_rational;
        char *response;
 
        response = NULL;
@@ -732,10 +733,14 @@ SR_PRIV int sr_scpi_get_int(struct sr_scpi_dev_inst *scpi,
        if (ret != SR_OK && !response)
                return ret;
 
-       if (sr_atoi(response, scpi_response) == SR_OK)
-               ret = SR_OK;
-       else
+       ret = sr_parse_rational(response, &ret_rational);
+       if (ret == SR_OK && (ret_rational.p % ret_rational.q) == 0) {
+               *scpi_response = ret_rational.p / ret_rational.q;
+       } else {
+               sr_dbg("get_int: non-integer rational=%" PRId64 "/%" PRIu64,
+                       ret_rational.p, ret_rational.q);
                ret = SR_ERR_DATA;
+       }
 
        g_free(response);