X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fscpi%2Fscpi_tcp.c;h=e87f5e784fb1d0ab61b0eaac8f44b06091b04076;hb=2463ec77fe51a7d7ec37f32ddd2f024b5f328f52;hp=ef3a6c7564e219a65e7f921a4bc72bb6f58501e1;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git
diff --git a/src/scpi/scpi_tcp.c b/src/scpi/scpi_tcp.c
index ef3a6c75..e87f5e78 100644
--- a/src/scpi/scpi_tcp.c
+++ b/src/scpi/scpi_tcp.c
@@ -17,15 +17,12 @@
* along with this program. If not, see .
*/
+#include
#ifdef _WIN32
#define _WIN32_WINNT 0x0501
#include
#include
#endif
-
-#include "libsigrok.h"
-#include "libsigrok-internal.h"
-
#include
#include
#include
@@ -36,6 +33,9 @@
#include
#endif
#include
+#include
+#include "libsigrok-internal.h"
+#include "scpi.h"
#define LOG_PREFIX "scpi_tcp"
@@ -72,9 +72,9 @@ static int scpi_tcp_dev_inst_new(void *priv, struct drv_context *drvc,
return SR_OK;
}
-static int scpi_tcp_open(void *priv)
+static int scpi_tcp_open(struct sr_scpi_dev_inst *scpi)
{
- struct scpi_tcp *tcp = priv;
+ struct scpi_tcp *tcp = scpi->priv;
struct addrinfo hints;
struct addrinfo *results, *res;
int err;
@@ -87,7 +87,7 @@ static int scpi_tcp_open(void *priv)
err = getaddrinfo(tcp->address, tcp->port, &hints, &results);
if (err) {
- sr_err("Address lookup failed: %s:%d: %s", tcp->address, tcp->port,
+ sr_err("Address lookup failed: %s:%s: %s", tcp->address, tcp->port,
gai_strerror(err));
return SR_ERR;
}
@@ -108,7 +108,7 @@ static int scpi_tcp_open(void *priv)
if (tcp->socket < 0) {
sr_err("Failed to connect to %s:%s: %s", tcp->address, tcp->port,
- strerror(errno));
+ g_strerror(errno));
return SR_ERR;
}
@@ -135,15 +135,12 @@ static int scpi_tcp_send(void *priv, const char *command)
{
struct scpi_tcp *tcp = priv;
int len, out;
- char *terminated_command;
- terminated_command = g_strdup_printf("%s\r\n", command);
- len = strlen(terminated_command);
- out = send(tcp->socket, terminated_command, len, 0);
- g_free(terminated_command);
+ len = strlen(command);
+ out = send(tcp->socket, command, len, 0);
if (out < 0) {
- sr_err("Send error: %s", strerror(errno));
+ sr_err("Send error: %s", g_strerror(errno));
return SR_ERR;
}
@@ -175,7 +172,7 @@ static int scpi_tcp_raw_read_data(void *priv, char *buf, int maxlen)
len = recv(tcp->socket, buf, maxlen, 0);
if (len < 0) {
- sr_err("Receive error: %s", strerror(errno));
+ sr_err("Receive error: %s", g_strerror(errno));
return SR_ERR;
}
@@ -195,7 +192,7 @@ static int scpi_tcp_rigol_read_data(void *priv, char *buf, int maxlen)
len = recv(tcp->socket, tcp->length_buf + tcp->length_bytes_read,
LENGTH_BYTES - tcp->length_bytes_read, 0);
if (len < 0) {
- sr_err("Receive error: %s", strerror(errno));
+ sr_err("Receive error: %s", g_strerror(errno));
return SR_ERR;
}
@@ -213,7 +210,7 @@ static int scpi_tcp_rigol_read_data(void *priv, char *buf, int maxlen)
len = recv(tcp->socket, buf, maxlen, 0);
if (len < 0) {
- sr_err("Receive error: %s", strerror(errno));
+ sr_err("Receive error: %s", g_strerror(errno));
return SR_ERR;
}
@@ -230,9 +227,9 @@ static int scpi_tcp_read_complete(void *priv)
tcp->response_bytes_read >= tcp->response_length);
}
-static int scpi_tcp_close(void *priv)
+static int scpi_tcp_close(struct sr_scpi_dev_inst *scpi)
{
- struct scpi_tcp *tcp = priv;
+ struct scpi_tcp *tcp = scpi->priv;
if (close(tcp->socket) < 0)
return SR_ERR;