SR_PRIV int brymen_bm86x_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; (void)fd; (void)revents; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; if (!devc->interrupt_pending) { if (brymen_bm86x_send_command(sdi)) return FALSE; devc->interrupt_pending = 1; } if (brymen_bm86x_read_interrupt(sdi)) return FALSE; if (sr_sw_limits_check(&devc->sw_limits)) sdi->driver->dev_acquisition_stop(sdi); return TRUE; }
int receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct dmm_info *dmm; void *info; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; dmm = (struct dmm_info *)sdi->driver; if (revents == G_IO_IN) { /* Serial data arrived. */ info = g_malloc(dmm->info_size); handle_new_data(sdi, info); g_free(info); } else { /* Timeout; send another packet request if DMM needs it. */ if (dmm->packet_request && (req_packet(sdi) < 0)) return FALSE; } if (sr_sw_limits_check(&devc->limits)) sdi->driver->dev_acquisition_stop(sdi); return TRUE; }
SR_PRIV int brymen_dmm_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; int ret; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ handle_new_data(sdi); } else { /* Timeout, send another packet request. */ if ((ret = brymen_packet_request(serial)) < 0) { sr_err("Failed to request packet: %d.", ret); return FALSE; } } if (sr_sw_limits_check(&devc->sw_limits)) sdi->driver->dev_acquisition_stop(sdi); return TRUE; }
SR_PRIV int norma_dmm_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; int len; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ while (NMADMM_BUFSIZE - devc->buflen - 1 > 0) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) break; devc->buflen += len; *(devc->buf + devc->buflen) = '\0'; if (*(devc->buf + devc->buflen - 1) == '\n') { /* * TODO: According to specs, should be \r, but * then we'd have to get rid of the \n. */ devc->last_req_pending = FALSE; nma_process_line(sdi); break; } } } if (sr_sw_limits_check(&devc->limits)) { sr_dev_acquisition_stop(sdi); } else { /* Request next package. */ 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; }
SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; int len; int64_t now, elapsed; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ while (FLUKEDMM_BUFSIZE - devc->buflen - 1 > 0) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) break; devc->buflen++; *(devc->buf + devc->buflen) = '\0'; if (*(devc->buf + devc->buflen - 1) == '\r') { *(devc->buf + --devc->buflen) = '\0'; handle_line(sdi); break; } } } if (sr_sw_limits_check(&devc->limits)) { sdi->driver->dev_acquisition_stop(sdi); return TRUE; } now = g_get_monotonic_time() / 1000; elapsed = now - devc->cmd_sent_at; /* Send query command at poll_period interval, or after 1 second * has elapsed. This will make it easier to recover from any * out-of-sync or temporary disconnect issues. */ if ((devc->expect_response == FALSE && elapsed > devc->profile->poll_period) || elapsed > devc->profile->timeout) { if (serial_write_blocking(serial, "QM\r", 3, SERIAL_WRITE_TIMEOUT_MS) < 0) sr_err("Unable to send QM."); devc->cmd_sent_at = now; devc->expect_response = TRUE; } return TRUE; }
/** Driver/serial data reception function. */ 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; uint64_t elapsed_us; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* New data arrived. */ handle_new_data(sdi); } else { /* Timeout. */ } if (sr_sw_limits_check(&devc->limits)) { sdi->driver->dev_acquisition_stop(sdi); return TRUE; } /* Request next packet, if required. */ if (sdi->status == SR_ST_ACTIVE) { if (devc->reply_pending) { elapsed_us = g_get_monotonic_time() - devc->req_sent_at; if (elapsed_us > (REQ_TIMEOUT_MS * 1000)) devc->reply_pending = FALSE; return TRUE; } /* Send command to get voltage, current, and mode (CC or CV). */ if (hcs_send_cmd(serial, "GETD\r") < 0) return TRUE; devc->req_sent_at = g_get_monotonic_time(); devc->reply_pending = TRUE; } return TRUE; }
SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; const uint8_t *ptr, *next_ptr, *end_ptr; int len; (void)fd; if (!(sdi = cb_data) || !(devc = sdi->priv) || revents != G_IO_IN) return TRUE; serial = sdi->conn; /* Try to get as much data as the buffer can hold. */ len = TELEINFO_BUF_SIZE - devc->buf_len; len = serial_read_nonblocking(serial, devc->buf + devc->buf_len, len); if (len < 1) { sr_err("Serial port read error: %d.", len); return FALSE; } devc->buf_len += len; /* Now look for packets in that data. */ ptr = devc->buf; end_ptr = ptr + devc->buf_len; while ((next_ptr = teleinfo_parse_data(sdi, ptr, end_ptr - ptr, NULL))) ptr = next_ptr; /* If we have any data left, move it to the beginning of our buffer. */ memmove(devc->buf, ptr, end_ptr - ptr); devc->buf_len -= ptr - devc->buf; /* If buffer is full and no valid packet was found, wipe buffer. */ if (devc->buf_len >= TELEINFO_BUF_SIZE) { devc->buf_len = 0; return FALSE; } if (sr_sw_limits_check(&devc->sw_limits)) sdi->driver->dev_acquisition_stop(sdi); return TRUE; }
SR_PRIV int maynuo_m97_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_modbus_dev_inst *modbus; struct sr_datafeed_packet packet; uint16_t registers[4]; (void)fd; (void)revents; if (!(sdi = cb_data)) return TRUE; modbus = sdi->conn; devc = sdi->priv; devc->expecting_registers = 0; if (sr_modbus_read_holding_registers(modbus, -1, 4, registers) == SR_OK) { packet.type = SR_DF_FRAME_BEGIN; sr_session_send(sdi, &packet); maynuo_m97_session_send_value(sdi, sdi->channels->data, RBFL(registers + 0), SR_MQ_VOLTAGE, SR_UNIT_VOLT); maynuo_m97_session_send_value(sdi, sdi->channels->next->data, RBFL(registers + 2), SR_MQ_CURRENT, SR_UNIT_AMPERE); packet.type = SR_DF_FRAME_END; sr_session_send(sdi, &packet); sr_sw_limits_update_samples_read(&devc->limits, 1); } if (sr_sw_limits_check(&devc->limits)) { sdi->driver->dev_acquisition_stop(sdi); return TRUE; } maynuo_m97_capture_start(sdi); return TRUE; }
SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; gboolean stop = FALSE; int len; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ while (AGDMM_BUFSIZE - devc->buflen - 1 > 0) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) break; devc->buflen += len; *(devc->buf + devc->buflen) = '\0'; if (*(devc->buf + devc->buflen - 1) == '\n') { /* End of line */ stop = receive_line(sdi); break; } } } if (sr_sw_limits_check(&devc->limits) || stop) sr_dev_acquisition_stop(sdi); else dispatch(sdi); return TRUE; }
SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; int len; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ while (LINELEN_MAX - devc->buflen - 2 > 0) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) break; /* Eliminate whitespace at beginning of line. */ if (g_ascii_isspace(devc->buf[0])) { devc->buf[0] = '\0'; devc->buflen = 0; continue; } devc->buflen += len; devc->buf[devc->buflen] = '\0'; /* If line complete, process msg. */ if ((devc->buflen > 0) && ((devc->buf[devc->buflen-1] == '\r') || devc->buf[devc->buflen-1] == '\n')) { devc->buflen--; devc->buf[devc->buflen] = '\0'; sr_spew("Line complete: \"%s\"", devc->buf); process_line(sdi); } } } if (sr_sw_limits_check(&devc->limits)) sdi->driver->dev_acquisition_stop(sdi); /* Only request the next packet if required. */ if (!((sdi->status == SR_ST_ACTIVE) && (devc->acq_running))) return TRUE; if (devc->acq_req_pending) { int64_t elapsed_us = g_get_monotonic_time() - devc->req_sent_at; if (elapsed_us > (REQ_TIMEOUT_MS * 1000)) { sr_spew("Request timeout: req=%d t=%" PRIi64 "us", (int)devc->acq_req, elapsed_us); devc->acq_req_pending = 0; } } if (devc->acq_req_pending == 0) { switch (devc->acq_req) { case AQ_NONE: /* Fall through */ case AQ_STATUS: devc->acq_req = AQ_U1; lps_send_req(serial, "VOUT1"); break; case AQ_U1: devc->acq_req = AQ_I1; lps_send_req(serial, "IOUT1"); break; case AQ_I1: if (devc->model->num_channels == 1) { devc->acq_req = AQ_STATUS; lps_send_req(serial, "STATUS"); } else { devc->acq_req = AQ_U2; lps_send_req(serial, "VOUT2"); } break; case AQ_U2: devc->acq_req = AQ_I2; lps_send_req(serial, "IOUT2"); break; case AQ_I2: devc->acq_req = AQ_STATUS; lps_send_req(serial, "STATUS"); break; default: sr_err("Illegal devc->acq_req=%d", devc->acq_req); return SR_ERR; } devc->req_sent_at = g_get_real_time(); devc->acq_req_pending = 1; } return TRUE; }