radioshack-dmm: use new serial API
This commit is contained in:
parent
19ee7dff78
commit
401476daaf
|
@ -28,6 +28,8 @@
|
||||||
#include "libsigrok-internal.h"
|
#include "libsigrok-internal.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
|
#define SERIALCOMM "4800/8n1"
|
||||||
|
|
||||||
static const int hwopts[] = {
|
static const int hwopts[] = {
|
||||||
SR_HWOPT_CONN,
|
SR_HWOPT_CONN,
|
||||||
SR_HWOPT_SERIALCOMM,
|
SR_HWOPT_SERIALCOMM,
|
||||||
|
@ -95,21 +97,18 @@ static GSList *rs_22_812_scan(const char *conn, const char *serialcomm)
|
||||||
struct drv_context *drvc;
|
struct drv_context *drvc;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
|
struct sr_serial_dev_inst *serial;
|
||||||
GSList *devices;
|
GSList *devices;
|
||||||
int fd, retry;
|
int retry;
|
||||||
size_t len, i, good_packets, dropped;
|
size_t len, i, good_packets, dropped;
|
||||||
char buf[128], *b;
|
char buf[128], *b;
|
||||||
const struct rs_22_812_packet *rs_packet;
|
const struct rs_22_812_packet *rs_packet;
|
||||||
|
|
||||||
if ((fd = serial_open(conn, O_RDONLY | O_NONBLOCK)) < 0) {
|
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
|
||||||
sr_err("Unable to open '%s': %d.", conn, fd);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (serial_set_paramstr(fd, serialcomm) != SR_OK) {
|
if (serial_open(serial, O_RDONLY|O_NONBLOCK) != SR_OK)
|
||||||
sr_err("Unable to set serial parameters.");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
sr_info("Probing port '%s' readonly.", conn);
|
sr_info("Probing port '%s' readonly.", conn);
|
||||||
|
|
||||||
|
@ -126,11 +125,11 @@ static GSList *rs_22_812_scan(const char *conn, const char *serialcomm)
|
||||||
while (!devices && retry < 3) {
|
while (!devices && retry < 3) {
|
||||||
good_packets = 0;
|
good_packets = 0;
|
||||||
retry++;
|
retry++;
|
||||||
serial_flush(fd);
|
serial_flush(serial);
|
||||||
|
|
||||||
/* Let's get a bit of data and see if we can find a packet. */
|
/* Let's get a bit of data and see if we can find a packet. */
|
||||||
len = sizeof(buf);
|
len = sizeof(buf);
|
||||||
serial_readline(fd, &b, &len, 250);
|
serial_readline(serial, &b, &len, 250);
|
||||||
if ((len == 0) || (len < RS_22_812_PACKET_SIZE)) {
|
if ((len == 0) || (len < RS_22_812_PACKET_SIZE)) {
|
||||||
/* Not enough data received, is the DMM connected? */
|
/* Not enough data received, is the DMM connected? */
|
||||||
continue;
|
continue;
|
||||||
|
@ -167,8 +166,7 @@ static GSList *rs_22_812_scan(const char *conn, const char *serialcomm)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
devc->serial = sr_serial_dev_inst_new(conn, -1);
|
devc->serial = serial;
|
||||||
devc->serialcomm = g_strdup(serialcomm);
|
|
||||||
|
|
||||||
sdi->priv = devc;
|
sdi->priv = devc;
|
||||||
sdi->driver = di;
|
sdi->driver = di;
|
||||||
|
@ -179,7 +177,7 @@ static GSList *rs_22_812_scan(const char *conn, const char *serialcomm)
|
||||||
devices = g_slist_append(devices, sdi);
|
devices = g_slist_append(devices, sdi);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
serial_close(fd);
|
serial_close(serial);
|
||||||
|
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
@ -205,13 +203,12 @@ static GSList *hw_scan(GSList * options)
|
||||||
if (!conn)
|
if (!conn)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (serialcomm) {
|
if (serialcomm)
|
||||||
/* Use the provided comm specs. */
|
/* Use the provided comm specs. */
|
||||||
devices = rs_22_812_scan(conn, serialcomm);
|
devices = rs_22_812_scan(conn, serialcomm);
|
||||||
} else {
|
else
|
||||||
/* Try the default 4800/8n1. */
|
/* Try the default. */
|
||||||
devices = rs_22_812_scan(conn, "4800/8n1");
|
devices = rs_22_812_scan(conn, SERIALCOMM);
|
||||||
}
|
|
||||||
|
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
@ -234,15 +231,9 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
return SR_ERR_BUG;
|
return SR_ERR_BUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
devc->serial->fd = serial_open(devc->serial->port, O_RDONLY);
|
if (serial_open(devc->serial, O_RDONLY) != SR_OK)
|
||||||
if (devc->serial->fd < 0) {
|
|
||||||
sr_err("Couldn't open serial port '%s'.", devc->serial->port);
|
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
|
||||||
if (serial_set_paramstr(devc->serial->fd, devc->serialcomm) != SR_OK) {
|
|
||||||
sr_err("Unable to set serial parameters.");
|
|
||||||
return SR_ERR;
|
|
||||||
}
|
|
||||||
sdi->status = SR_ST_ACTIVE;
|
sdi->status = SR_ST_ACTIVE;
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
@ -258,8 +249,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devc->serial && devc->serial->fd != -1) {
|
if (devc->serial && devc->serial->fd != -1) {
|
||||||
serial_close(devc->serial->fd);
|
serial_close(devc->serial);
|
||||||
devc->serial->fd = -1;
|
|
||||||
sdi->status = SR_ST_INACTIVE;
|
sdi->status = SR_ST_INACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -419,7 +419,7 @@ static void handle_packet(struct rs_22_812_packet *rs_packet,
|
||||||
g_free(analog);
|
g_free(analog);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_new_data(struct dev_context *devc, int fd)
|
static void handle_new_data(struct dev_context *devc)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
size_t i, offset = 0;
|
size_t i, offset = 0;
|
||||||
|
@ -427,7 +427,7 @@ static void handle_new_data(struct dev_context *devc, int fd)
|
||||||
|
|
||||||
/* Try to get as much data as the buffer can hold. */
|
/* Try to get as much data as the buffer can hold. */
|
||||||
len = RS_DMM_BUFSIZE - devc->buflen;
|
len = RS_DMM_BUFSIZE - devc->buflen;
|
||||||
len = serial_read(fd, devc->buf + devc->buflen, len);
|
len = serial_read(devc->serial, devc->buf + devc->buflen, len);
|
||||||
if (len < 1) {
|
if (len < 1) {
|
||||||
sr_err("Serial port read error.");
|
sr_err("Serial port read error.");
|
||||||
return;
|
return;
|
||||||
|
@ -456,6 +456,8 @@ SR_PRIV int radioshack_dmm_receive_data(int fd, int revents, void *cb_data)
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
|
|
||||||
|
(void)fd;
|
||||||
|
|
||||||
if (!(sdi = cb_data))
|
if (!(sdi = cb_data))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -464,7 +466,7 @@ SR_PRIV int radioshack_dmm_receive_data(int fd, int revents, void *cb_data)
|
||||||
|
|
||||||
if (revents == G_IO_IN) {
|
if (revents == G_IO_IN) {
|
||||||
/* Serial data arrived. */
|
/* Serial data arrived. */
|
||||||
handle_new_data(devc, fd);
|
handle_new_data(devc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devc->num_samples >= devc->limit_samples) {
|
if (devc->num_samples >= devc->limit_samples) {
|
||||||
|
|
|
@ -50,7 +50,6 @@ struct rs_22_812_packet {
|
||||||
struct dev_context {
|
struct dev_context {
|
||||||
uint64_t limit_samples;
|
uint64_t limit_samples;
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
char *serialcomm;
|
|
||||||
|
|
||||||
/* Opaque pointer passed in by the frontend. */
|
/* Opaque pointer passed in by the frontend. */
|
||||||
void *cb_data;
|
void *cb_data;
|
||||||
|
|
Loading…
Reference in New Issue