norma-dmm: Added request timeout mechanism; docs.

This commit is contained in:
Matthias Heidbrink 2014-06-13 21:22:11 +02:00
parent 49c06128d7
commit a4e435eb49
3 changed files with 34 additions and 4 deletions

View File

@ -17,6 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file
* Norma DM9x0/Siemens B102x DMMs driver.
* @internal
*/
#include "protocol.h"
static const int32_t hwopts[] = {
@ -122,6 +127,7 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options)
snprintf(req, sizeof(req), "%s\r\n",
nmadmm_requests[NMADMM_REQ_IDN].req_str);
g_usleep(150 * 1000); /* Wait a little to allow serial port to settle. */
for (cnt = 0; cnt < 7; cnt++) {
if (serial_write(serial, req, strlen(req)) == -1) {
sr_err("Unable to send identification request: %d %s.",
@ -129,7 +135,7 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options)
return NULL;
}
len = BUF_MAX;
serial_readline(serial, &buf, &len, 1500);
serial_readline(serial, &buf, &len, NMADMM_TIMEOUT_MS);
if (!len)
continue;
buf[BUF_MAX - 1] = '\0';

View File

@ -17,6 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file
* Norma DM9x0/Siemens B102x DMMs driver.
* @internal
*/
#include "protocol.h"
SR_PRIV const struct nmadmm_req nmadmm_requests[] = {
@ -50,6 +55,8 @@ static int nma_send_req(const struct sr_dev_inst *sdi, int req, char *params)
return SR_ERR;
}
devc->req_sent_at = g_get_monotonic_time();
return SR_OK;
}
@ -417,9 +424,18 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data)
}
/* Request next package. */
if (!terminating && !devc->last_req_pending) {
if (nma_send_req(sdi, NMADMM_REQ_STATUS, NULL) != SR_OK)
return FALSE;
if (!terminating) {
if (devc->last_req_pending) {
gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at;
if (elapsed_us > NMADMM_TIMEOUT_MS * 1000) {/* Timeout! */
sr_spew("Request timeout!");
devc->last_req_pending = FALSE;
}
}
if (!devc->last_req_pending) {
if (nma_send_req(sdi, NMADMM_REQ_STATUS, NULL) != SR_OK)
return FALSE;
}
}
return TRUE;

View File

@ -29,10 +29,17 @@
#include "libsigrok.h"
#include "libsigrok-internal.h"
/** @file
* Norma DM9x0/Siemens B102x DMMs driver.
* @internal
*/
#define LOG_PREFIX "norma-dmm"
#define NMADMM_BUFSIZE 256
#define NMADMM_TIMEOUT_MS 2000 /**< Request timeout. */
/** Norma DMM request types (used ones only, the DMMs support about 50). */
enum {
NMADMM_REQ_IDN = 0, /**< Request identity */
@ -63,6 +70,7 @@ struct dev_context {
/* Operational state */
int last_req; /**< Last request. */
int64_t req_sent_at; /**< Request sent. */
gboolean last_req_pending; /**< Last request not answered yet. */
int lowbatt; /**< Low battery. 1=low, 2=critical. */