X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fhardware%2Fmanson-hcs-3xxx%2Fprotocol.c;h=30017d1cdcbaeea092676db753ca31bdab4d8b42;hb=a82490b6f7ea4a65a45d96e1a55c7bd74a4e49c1;hp=a57c92d988149c7f04e729327d2c40431f72f387;hpb=bbff0fe0d242542c1585cc9e94b9d4638632a049;p=libsigrok.git
diff --git a/src/hardware/manson-hcs-3xxx/protocol.c b/src/hardware/manson-hcs-3xxx/protocol.c
index a57c92d9..30017d1c 100644
--- a/src/hardware/manson-hcs-3xxx/protocol.c
+++ b/src/hardware/manson-hcs-3xxx/protocol.c
@@ -15,15 +15,10 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see .
*/
-/** @file
- * Manson HCS-3xxx Series power supply driver
- * @internal
- */
-
+#include
#include "protocol.h"
#define REQ_TIMEOUT_MS 500
@@ -43,7 +38,8 @@ SR_PRIV int hcs_send_cmd(struct sr_serial_dev_inst *serial, const char *cmd, ...
sr_dbg("Sending '%s'.", cmd_esc);
g_free(cmd_esc);
- if ((ret = serial_write_blocking(serial, cmdbuf, strlen(cmdbuf))) < 0) {
+ if ((ret = serial_write_blocking(serial, cmdbuf, strlen(cmdbuf),
+ serial_timeout(serial, strlen(cmdbuf)))) < 0) {
sr_err("Error sending command: %d.", ret);
return ret;
}
@@ -54,15 +50,17 @@ SR_PRIV int hcs_send_cmd(struct sr_serial_dev_inst *serial, const char *cmd, ...
/**
* Read data from interface into buffer blocking until @a lines number of \\r chars
* received.
+ *
* @param serial Previously initialized serial port structure.
* @param[in] lines Number of \\r-terminated lines to read (1-n).
- * @param buf Buffer for result. Contents is NUL-terminated on success.
+ * @param buf Buffer for result. Contents is NUL-terminated on success.
* @param[in] buflen Buffer length (>0).
+ *
* @retval SR_OK Lines received and ending with "OK\r" (success).
* @retval SR_ERR Error.
* @retval SR_ERR_ARG Invalid argument.
*/
-SR_PRIV int hcs_read_reply(struct sr_serial_dev_inst *serial, int lines, char* buf, int buflen)
+SR_PRIV int hcs_read_reply(struct sr_serial_dev_inst *serial, int lines, char *buf, int buflen)
{
int l_recv = 0;
int bufpos = 0;
@@ -72,7 +70,7 @@ SR_PRIV int hcs_read_reply(struct sr_serial_dev_inst *serial, int lines, char* b
return SR_ERR_ARG;
while ((l_recv < lines) && (bufpos < (buflen + 1))) {
- retc = serial_read_blocking(serial, &buf[bufpos], 1);
+ retc = serial_read_blocking(serial, &buf[bufpos], 1, 0);
if (retc != 1)
return SR_ERR;
if (buf[bufpos] == '\r')
@@ -122,27 +120,33 @@ static void send_sample(struct sr_dev_inst *sdi)
struct dev_context *devc;
struct sr_datafeed_packet packet;
struct sr_datafeed_analog analog;
+ struct sr_analog_encoding encoding;
+ struct sr_analog_meaning meaning;
+ struct sr_analog_spec spec;
devc = sdi->priv;
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
+
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
- analog.channels = sdi->channels;
+ analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
- analog.mq = SR_MQ_VOLTAGE;
- analog.unit = SR_UNIT_VOLT;
- analog.mqflags = SR_MQFLAG_DC;
+ analog.meaning->mq = SR_MQ_VOLTAGE;
+ analog.meaning->unit = SR_UNIT_VOLT;
+ analog.meaning->mqflags = SR_MQFLAG_DC;
analog.data = &devc->voltage;
sr_session_send(sdi, &packet);
- analog.mq = SR_MQ_CURRENT;
- analog.unit = SR_UNIT_AMPERE;
- analog.mqflags = 0;
+ analog.meaning->mq = SR_MQ_CURRENT;
+ analog.meaning->unit = SR_UNIT_AMPERE;
+ analog.meaning->mqflags = 0;
analog.data = &devc->current;
sr_session_send(sdi, &packet);
- devc->num_samples++;
+
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
}
static int parse_reply(struct sr_dev_inst *sdi)
@@ -177,7 +181,7 @@ static int handle_new_data(struct sr_dev_inst *sdi)
devc = sdi->priv;
serial = sdi->conn;
- len = serial_read_blocking(serial, devc->buf + devc->buflen, 1);
+ len = serial_read_blocking(serial, devc->buf + devc->buflen, 1, 0);
if (len < 1)
return SR_ERR;
@@ -204,7 +208,7 @@ SR_PRIV int hcs_receive_data(int fd, int revents, void *cb_data)
struct sr_dev_inst *sdi;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
- int64_t t, elapsed_us;
+ uint64_t elapsed_us;
(void)fd;
@@ -223,21 +227,11 @@ SR_PRIV int hcs_receive_data(int fd, int revents, void *cb_data)
/* Timeout. */
}
- if (devc->limit_samples && (devc->num_samples >= devc->limit_samples)) {
- sr_info("Requested number of samples reached.");
- sdi->driver->dev_acquisition_stop(sdi, cb_data);
+ if (sr_sw_limits_check(&devc->limits)) {
+ sr_dev_acquisition_stop(sdi);
return TRUE;
}
- if (devc->limit_msec) {
- t = (g_get_monotonic_time() - devc->starttime) / 1000;
- if (t > (int64_t)devc->limit_msec) {
- sr_info("Requested time limit reached.");
- sdi->driver->dev_acquisition_stop(sdi, cb_data);
- return TRUE;
- }
- }
-
/* Request next packet, if required. */
if (sdi->status == SR_ST_ACTIVE) {
if (devc->reply_pending) {