norma-dmm: Added request timeout mechanism; docs.
This commit is contained in:
parent
49c06128d7
commit
a4e435eb49
|
@ -17,6 +17,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
* Norma DM9x0/Siemens B102x DMMs driver.
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
static const int32_t hwopts[] = {
|
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",
|
snprintf(req, sizeof(req), "%s\r\n",
|
||||||
nmadmm_requests[NMADMM_REQ_IDN].req_str);
|
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++) {
|
for (cnt = 0; cnt < 7; cnt++) {
|
||||||
if (serial_write(serial, req, strlen(req)) == -1) {
|
if (serial_write(serial, req, strlen(req)) == -1) {
|
||||||
sr_err("Unable to send identification request: %d %s.",
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
len = BUF_MAX;
|
len = BUF_MAX;
|
||||||
serial_readline(serial, &buf, &len, 1500);
|
serial_readline(serial, &buf, &len, NMADMM_TIMEOUT_MS);
|
||||||
if (!len)
|
if (!len)
|
||||||
continue;
|
continue;
|
||||||
buf[BUF_MAX - 1] = '\0';
|
buf[BUF_MAX - 1] = '\0';
|
||||||
|
|
|
@ -17,6 +17,11 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
* Norma DM9x0/Siemens B102x DMMs driver.
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
|
|
||||||
SR_PRIV const struct nmadmm_req nmadmm_requests[] = {
|
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;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devc->req_sent_at = g_get_monotonic_time();
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,9 +424,18 @@ SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Request next package. */
|
/* Request next package. */
|
||||||
if (!terminating && !devc->last_req_pending) {
|
if (!terminating) {
|
||||||
if (nma_send_req(sdi, NMADMM_REQ_STATUS, NULL) != SR_OK)
|
if (devc->last_req_pending) {
|
||||||
return FALSE;
|
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;
|
return TRUE;
|
||||||
|
|
|
@ -29,10 +29,17 @@
|
||||||
#include "libsigrok.h"
|
#include "libsigrok.h"
|
||||||
#include "libsigrok-internal.h"
|
#include "libsigrok-internal.h"
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
* Norma DM9x0/Siemens B102x DMMs driver.
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
|
||||||
#define LOG_PREFIX "norma-dmm"
|
#define LOG_PREFIX "norma-dmm"
|
||||||
|
|
||||||
#define NMADMM_BUFSIZE 256
|
#define NMADMM_BUFSIZE 256
|
||||||
|
|
||||||
|
#define NMADMM_TIMEOUT_MS 2000 /**< Request timeout. */
|
||||||
|
|
||||||
/** Norma DMM request types (used ones only, the DMMs support about 50). */
|
/** Norma DMM request types (used ones only, the DMMs support about 50). */
|
||||||
enum {
|
enum {
|
||||||
NMADMM_REQ_IDN = 0, /**< Request identity */
|
NMADMM_REQ_IDN = 0, /**< Request identity */
|
||||||
|
@ -63,6 +70,7 @@ struct dev_context {
|
||||||
|
|
||||||
/* Operational state */
|
/* Operational state */
|
||||||
int last_req; /**< Last request. */
|
int last_req; /**< Last request. */
|
||||||
|
int64_t req_sent_at; /**< Request sent. */
|
||||||
gboolean last_req_pending; /**< Last request not answered yet. */
|
gboolean last_req_pending; /**< Last request not answered yet. */
|
||||||
int lowbatt; /**< Low battery. 1=low, 2=critical. */
|
int lowbatt; /**< Low battery. 1=low, 2=critical. */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue