* @internal
*/
+#include <config.h>
#include <ctype.h>
-#include <errno.h>
#include <math.h>
#include <string.h>
#include "protocol.h"
/* Forward declarations */
SR_PRIV struct sr_dev_driver motech_lps_301_driver_info;
SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *buflen);
-SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char* fmt, va_list args);
-SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char* fmt, ...);
-SR_PRIV int lps_cmd_reply(char* reply, struct sr_serial_dev_inst *serial, const char* fmt, ...);
-SR_PRIV int lps_query_status(struct sr_dev_inst* sdi);
+SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char *fmt, va_list args);
+SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char *fmt, ...);
+SR_PRIV int lps_cmd_reply(char *reply, struct sr_serial_dev_inst *serial, const char *fmt, ...);
+SR_PRIV int lps_query_status(struct sr_dev_inst *sdi);
/* Serial communication parameters */
#define SERIALCOMM "2400/8n1/dtr=1/rts=1/flow=0"
/** Send command to device with va_list.
*/
-SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char* fmt, va_list args)
+SR_PRIV int lps_send_va(struct sr_serial_dev_inst *serial, const char *fmt, va_list args)
{
int retc;
char auxfmt[LINELEN_MAX];
sr_spew("lps_send_va: \"%s\"", buf);
- retc = serial_write_blocking(serial, buf, strlen(buf), 0);
+ retc = serial_write_blocking(serial, buf, strlen(buf),
+ serial_timeout(serial, strlen(buf)));
if (retc < 0)
return SR_ERR;
/** Send command to device.
*/
-SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char* fmt, ...)
+SR_PRIV int lps_send_req(struct sr_serial_dev_inst *serial, const char *fmt, ...)
{
int retc;
va_list args;
}
/** Send command and consume simple OK reply. */
-SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char* fmt, ...)
+SR_PRIV int lps_cmd_ok(struct sr_serial_dev_inst *serial, const char *fmt, ...)
{
int retc;
va_list args;
char buf[LINELEN_MAX];
- char* bufptr;
+ char *bufptr;
int buflen;
/* Send command */
}
/** Send command and read reply string.
- * \param reply Pointer to buffer of size LINELEN_MAX. Will be NUL-terminated.
+ * @param reply Pointer to buffer of size LINELEN_MAX. Will be NUL-terminated.
*/
-SR_PRIV int lps_cmd_reply(char* reply, struct sr_serial_dev_inst *serial, const char* fmt, ...)
+SR_PRIV int lps_cmd_reply(char *reply, struct sr_serial_dev_inst *serial, const char *fmt, ...)
{
int retc;
va_list args;
char buf[LINELEN_MAX];
- char* bufptr;
+ char *bufptr;
int buflen;
reply[0] = '\0';
}
/** Process integer value returned by STATUS command. */
-SR_PRIV int lps_process_status(struct sr_dev_inst* sdi, int stat)
+SR_PRIV int lps_process_status(struct sr_dev_inst *sdi, int stat)
{
- struct dev_context* devc;
+ struct dev_context *devc;
int tracking_mode;
- devc = (struct dev_context*)sdi->priv;
+ devc = (struct dev_context *)sdi->priv;
sr_spew("Status: %d", stat);
devc->channel_status[0].cc_mode = (stat & 0x01) != 0;
}
/** Send STATUS commend and process status string. */
-SR_PRIV int lps_query_status(struct sr_dev_inst* sdi)
+SR_PRIV int lps_query_status(struct sr_dev_inst *sdi)
{
char buf[LINELEN_MAX];
- int stat;
- struct dev_context* devc;
+ int stat, ret;
+ struct dev_context *devc;
- devc = (struct dev_context*)sdi->priv;
+ devc = (struct dev_context *)sdi->priv;
devc->req_sent_at = g_get_real_time();
- if (lps_cmd_reply(buf, sdi->conn, "STATUS") < 0) {
- sr_err("%s: Failed to read status: %d %s", __func__, errno, strerror(errno));
+ if ((ret = lps_cmd_reply(buf, sdi->conn, "STATUS")) < 0) {
+ sr_err("%s: Failed to read status: %s.", __func__,
+ sr_strerror(ret));
return SR_ERR;
}
}
/** Read message into buf until "OK" received.
- * \retval SR_OK Msg received; buf and buflen contain result, if any except OK.
- * \retval SR_ERR Error, including timeout.
+ * @retval SR_OK Msg received; buf and buflen contain result, if any except OK.
+ * @retval SR_ERR Error, including timeout.
*/
SR_PRIV int lps_read_reply(struct sr_serial_dev_inst *serial, char **buf, int *buflen)
{
struct sr_channel_group *cg;
GSList *devices;
const char *conn, *serialcomm;
- int cnt;
+ int cnt, ret;
gchar buf[LINELEN_MAX];
gchar channel[10];
char *verstr;
conn = serialcomm = NULL;
devices = NULL;
- drvc = drv->priv;
+ drvc = drv->context;
drvc->instances = NULL;
sr_spew("scan() called!");
/* Query version */
verstr = NULL;
- if (lps_cmd_reply(buf, serial, "VERSION") == SR_OK) {
+ if ((ret = lps_cmd_reply(buf, serial, "VERSION")) == SR_OK) {
if (strncmp(buf, "Ver-", 4)) {
sr_spew("Version string %s not recognized.", buf);
goto exit_err;
}
else /* Bug in device FW 1.17: Querying version string fails while output is active.
Therefore just print an error message, but do not exit with error. */
- sr_err("Failed to query for hardware version: %d %s", errno, strerror(errno));
+ sr_err("Failed to query for hardware version: %s.",
+ sr_strerror(ret));
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
static GSList *dev_list_lps301(const struct sr_dev_driver *di)
{
- return ((struct drv_context *)(di->priv))->instances;
+ return ((struct drv_context *)(di->context))->instances;
}
-static void dev_clear_private(struct dev_context* devc)
+static void dev_clear_private(struct dev_context *devc)
{
int ch_idx;
return SR_OK;
}
-static int dev_acquisition_start(const struct sr_dev_inst *sdi,
- void *cb_data)
+static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
{
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
.dev_close = std_serial_dev_close,
.dev_acquisition_start = dev_acquisition_start,
.dev_acquisition_stop = dev_acquisition_stop,
- .priv = NULL,
+ .context = NULL,
};