X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcommon%2Fscpi_serial.c;h=9711c010a80fb9f5c92cfe60af7710d5e8760684;hb=fe9d5abefcebb3a382d990e069d93c28e9541e35;hp=d4c3add23527f34745bfe434a62ea3c895613fa9;hpb=f754c1469188a5e1a82c98532cb21b334530a91a;p=libsigrok.git diff --git a/hardware/common/scpi_serial.c b/hardware/common/scpi_serial.c index d4c3add2..9711c010 100644 --- a/hardware/common/scpi_serial.c +++ b/hardware/common/scpi_serial.c @@ -47,7 +47,7 @@ static int scpi_serial_dev_inst_new(void *priv, const char *resource, return SR_OK; } -SR_PRIV int scpi_serial_open(void *priv) +static int scpi_serial_open(void *priv) { struct scpi_serial *sscpi = priv; struct sr_serial_dev_inst *serial = sscpi->serial; @@ -61,7 +61,7 @@ SR_PRIV int scpi_serial_open(void *priv) return SR_OK; } -SR_PRIV int scpi_serial_source_add(void *priv, int events, int timeout, +static int scpi_serial_source_add(void *priv, int events, int timeout, sr_receive_data_callback_t cb, void *cb_data) { struct scpi_serial *sscpi = priv; @@ -70,7 +70,7 @@ SR_PRIV int scpi_serial_source_add(void *priv, int events, int timeout, return serial_source_add(serial, events, timeout, cb, cb_data); } -SR_PRIV int scpi_serial_source_remove(void *priv) +static int scpi_serial_source_remove(void *priv) { struct scpi_serial *sscpi = priv; struct sr_serial_dev_inst *serial = sscpi->serial; @@ -78,7 +78,7 @@ SR_PRIV int scpi_serial_source_remove(void *priv) return serial_source_remove(serial); } -SR_PRIV int scpi_serial_send(void *priv, const char *command) +static int scpi_serial_send(void *priv, const char *command) { int len, result, written; gchar *terminated_command; @@ -105,61 +105,7 @@ SR_PRIV int scpi_serial_send(void *priv, const char *command) return SR_OK; } -SR_PRIV int scpi_serial_receive(void *priv, char **scpi_response) -{ - int len, ret; - char buf[256]; - unsigned int i; - GString *response; - struct scpi_serial *sscpi = priv; - struct sr_serial_dev_inst *serial = sscpi->serial; - - response = g_string_sized_new(1024); - - for (i = 0; i <= SCPI_READ_RETRIES; i++) { - while ((len = serial_read(serial, buf, sizeof(buf))) > 0) - response = g_string_append_len(response, buf, len); - - if (response->len > 0 && - response->str[response->len-1] == '\n') { - sr_spew("Fetched full SCPI response."); - break; - } - - g_usleep(SCPI_READ_RETRY_TIMEOUT); - } - - if (response->len == 0) { - sr_dbg("No SCPI response received."); - g_string_free(response, TRUE); - *scpi_response = NULL; - return SR_ERR; - } else if (response->str[response->len - 1] == '\n') { - /* - * The SCPI response contains a LF ('\n') at the end and we - * don't need this so replace it with a '\0' and decrement - * the length. - */ - response->str[--response->len] = '\0'; - ret = SR_OK; - } else { - sr_warn("Incomplete SCPI response received!"); - ret = SR_ERR; - } - - /* Minor optimization: steal the string instead of copying. */ - *scpi_response = response->str; - - /* A SCPI response can be quite large, print at most 50 characters. */ - sr_dbg("SCPI response received (length %d): '%.50s'", - response->len, response->str); - - g_string_free(response, FALSE); - - return ret; -} - -SR_PRIV int scpi_serial_read_begin(void *priv) +static int scpi_serial_read_begin(void *priv) { struct scpi_serial *sscpi = priv; @@ -168,7 +114,7 @@ SR_PRIV int scpi_serial_read_begin(void *priv) return SR_OK; } -SR_PRIV int scpi_serial_read_data(void *priv, char *buf, int maxlen) +static int scpi_serial_read_data(void *priv, char *buf, int maxlen) { struct scpi_serial *sscpi = priv; int ret; @@ -187,7 +133,7 @@ SR_PRIV int scpi_serial_read_data(void *priv, char *buf, int maxlen) return ret; } -SR_PRIV int scpi_serial_read_complete(void *priv) +static int scpi_serial_read_complete(void *priv) { struct scpi_serial *sscpi = priv;