int response_bytes_read;
};
-static int scpi_tcp_dev_inst_new(void *priv, const char *resource,
- char **params, const char *serialcomm)
+static int scpi_tcp_dev_inst_new(void *priv, struct drv_context *drvc,
+ const char *resource, char **params, const char *serialcomm)
{
struct scpi_tcp *tcp = priv;
+ (void)drvc;
(void)resource;
(void)serialcomm;
return SR_OK;
}
-SR_PRIV int scpi_tcp_open(void *priv)
+static int scpi_tcp_open(void *priv)
{
struct scpi_tcp *tcp = priv;
struct addrinfo hints;
return SR_OK;
}
-SR_PRIV int scpi_tcp_source_add(void *priv, int events, int timeout,
- sr_receive_data_callback_t cb, void *cb_data)
+static int scpi_tcp_source_add(void *priv, int events, int timeout,
+ sr_receive_data_callback cb, void *cb_data)
{
struct scpi_tcp *tcp = priv;
return sr_source_add(tcp->socket, events, timeout, cb, cb_data);
}
-SR_PRIV int scpi_tcp_source_remove(void *priv)
+static int scpi_tcp_source_remove(void *priv)
{
struct scpi_tcp *tcp = priv;
return sr_source_remove(tcp->socket);
}
-SR_PRIV int scpi_tcp_send(void *priv, const char *command)
+static int scpi_tcp_send(void *priv, const char *command)
{
struct scpi_tcp *tcp = priv;
int len, out;
return SR_OK;
}
-SR_PRIV int scpi_tcp_read_begin(void *priv)
+static int scpi_tcp_read_begin(void *priv)
{
struct scpi_tcp *tcp = priv;
return SR_OK;
}
-SR_PRIV int scpi_tcp_read_data(void *priv, char *buf, int maxlen)
+static int scpi_tcp_raw_read_data(void *priv, char *buf, int maxlen)
+{
+ struct scpi_tcp *tcp = priv;
+ int len;
+
+ len = recv(tcp->socket, buf, maxlen, 0);
+
+ if (len < 0) {
+ sr_err("Receive error: %s", strerror(errno));
+ return SR_ERR;
+ }
+
+ tcp->length_bytes_read = LENGTH_BYTES;
+ tcp->response_length = len < maxlen ? len : maxlen + 1;
+ tcp->response_bytes_read = len;
+
+ return len;
+}
+
+static int scpi_tcp_rigol_read_data(void *priv, char *buf, int maxlen)
{
struct scpi_tcp *tcp = priv;
int len;
return len;
}
-SR_PRIV int scpi_tcp_read_complete(void *priv)
+static int scpi_tcp_read_complete(void *priv)
{
struct scpi_tcp *tcp = priv;
tcp->response_bytes_read >= tcp->response_length);
}
-SR_PRIV int scpi_tcp_close(void *priv)
+static int scpi_tcp_close(void *priv)
{
struct scpi_tcp *tcp = priv;
return SR_OK;
}
-SR_PRIV void scpi_tcp_free(void *priv)
+static void scpi_tcp_free(void *priv)
{
struct scpi_tcp *tcp = priv;
g_free(tcp->port);
}
-SR_PRIV const struct sr_scpi_dev_inst scpi_tcp_dev = {
- .name = "TCP",
- .prefix = "tcp",
+SR_PRIV const struct sr_scpi_dev_inst scpi_tcp_raw_dev = {
+ .name = "RAW TCP",
+ .prefix = "tcp-raw",
+ .priv_size = sizeof(struct scpi_tcp),
+ .dev_inst_new = scpi_tcp_dev_inst_new,
+ .open = scpi_tcp_open,
+ .source_add = scpi_tcp_source_add,
+ .source_remove = scpi_tcp_source_remove,
+ .send = scpi_tcp_send,
+ .read_begin = scpi_tcp_read_begin,
+ .read_data = scpi_tcp_raw_read_data,
+ .read_complete = scpi_tcp_read_complete,
+ .close = scpi_tcp_close,
+ .free = scpi_tcp_free,
+};
+
+SR_PRIV const struct sr_scpi_dev_inst scpi_tcp_rigol_dev = {
+ .name = "RIGOL TCP",
+ .prefix = "tcp-rigol",
.priv_size = sizeof(struct scpi_tcp),
.dev_inst_new = scpi_tcp_dev_inst_new,
.open = scpi_tcp_open,
.source_remove = scpi_tcp_source_remove,
.send = scpi_tcp_send,
.read_begin = scpi_tcp_read_begin,
- .read_data = scpi_tcp_read_data,
+ .read_data = scpi_tcp_rigol_read_data,
.read_complete = scpi_tcp_read_complete,
.close = scpi_tcp_close,
.free = scpi_tcp_free,