X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fcenter-3xx%2Fprotocol.c;h=81868b0618aa141f8702bdea993eac3a8fe96110;hb=ca7d442692a1785129cb5caba57c280bf5ce2a9f;hp=82fa19094f1093ff66ae91706c8889583ad4951b;hpb=c1da74fc0a345a01d5734ee93e035cf808803598;p=libsigrok.git diff --git a/src/hardware/center-3xx/protocol.c b/src/hardware/center-3xx/protocol.c index 82fa1909..81868b06 100644 --- a/src/hardware/center-3xx/protocol.c +++ b/src/hardware/center-3xx/protocol.c @@ -14,14 +14,17 @@ * 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 . */ +#include #include "protocol.h" +#define NUM_CHANNELS 4 + struct center_info { - float temp[4]; + float temp[NUM_CHANNELS]; + int digits[NUM_CHANNELS]; gboolean rec, std, max, min, maxmin, t1t2, rel, hold, lowbat, celsius; gboolean memfull, autooff; gboolean mode_std, mode_rel, mode_max, mode_min, mode_maxmin; @@ -31,7 +34,8 @@ static int center_send(struct sr_serial_dev_inst *serial, const char *cmd) { int ret; - if ((ret = serial_write_blocking(serial, cmd, strlen(cmd))) < 0) { + if ((ret = serial_write_blocking(serial, cmd, strlen(cmd), + serial_timeout(serial, strlen(cmd)))) < 0) { sr_err("Error sending '%s' command: %d.", cmd, ret); return SR_ERR; } @@ -84,21 +88,25 @@ static int packet_parse(const uint8_t *buf, int idx, struct center_info *info) info->autooff = (buf[2] & (1 << 7)) != 0; /* Byte 7+8/9+10/11+12/13+14: channel T1/T2/T3/T4 temperature. */ - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_CHANNELS; i++) { temp_u16 = buf[8 + (i * 2)]; temp_u16 |= ((uint16_t)buf[7 + (i * 2)] << 8); info->temp[i] = (float)temp_u16; } /* Byte 43: Specifies whether we need to divide the value(s) by 10. */ - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_CHANNELS; i++) { /* Bit = 0: Divide by 10. Bit = 1: Don't divide by 10. */ - if ((buf[43] & (1 << i)) == 0) + if ((buf[43] & (1 << i)) == 0) { info->temp[i] /= 10; + info->digits[i] = 1; + } else { + info->digits[i] = 0; + } } /* Bytes 39-42: Overflow/overlimit bits, depending on mode. */ - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_CHANNELS; i++) { if (info->mode_std && ((buf[39] & (1 << i)) != 0)) info->temp[i] = INFINITY; /* TODO: Rel. Not available on all models. */ @@ -120,6 +128,9 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx) { 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; struct dev_context *devc; struct center_info info; GSList *l; @@ -127,7 +138,8 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx) devc = sdi->priv; - memset(&analog, 0, sizeof(struct sr_datafeed_analog)); + /* Note: digits/spec_digits will be overridden later. */ + sr_analog_init(&analog, &encoding, &meaning, &spec, 0); memset(&info, 0, sizeof(struct center_info)); ret = packet_parse(buf, idx, &info); @@ -139,21 +151,23 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx) /* Common values for all 4 channels. */ packet.type = SR_DF_ANALOG; packet.payload = &analog; - analog.mq = SR_MQ_TEMPERATURE; - analog.unit = (info.celsius) ? SR_UNIT_CELSIUS : SR_UNIT_FAHRENHEIT; + analog.meaning->mq = SR_MQ_TEMPERATURE; + analog.meaning->unit = (info.celsius) ? SR_UNIT_CELSIUS : SR_UNIT_FAHRENHEIT; analog.num_samples = 1; /* Send the values for T1 - T4. */ - for (i = 0; i < 4; i++) { + for (i = 0; i < NUM_CHANNELS; i++) { l = NULL; l = g_slist_append(l, g_slist_nth_data(sdi->channels, i)); - analog.channels = l; + analog.meaning->channels = l; + analog.encoding->digits = info.digits[i]; + analog.spec->spec_digits = info.digits[i]; analog.data = &(info.temp[i]); - sr_session_send(devc->cb_data, &packet); + sr_session_send(sdi, &packet); g_slist_free(l); } - devc->num_samples++; + sr_sw_limits_update_samples_read(&devc->sw_limits, 1); return SR_OK; } @@ -163,7 +177,7 @@ static gboolean handle_new_data(struct sr_dev_inst *sdi, int idx) { struct dev_context *devc; struct sr_serial_dev_inst *serial; - int len, i, offset = 0, ret = FALSE; + int len, offset, ret = FALSE; devc = sdi->priv; serial = sdi->conn; @@ -179,6 +193,7 @@ static gboolean handle_new_data(struct sr_dev_inst *sdi, int idx) devc->buflen += len; /* Now look for packets in that data. */ + offset = 0; while ((devc->buflen - offset) >= center_devs[idx].packet_size) { if (center_devs[idx].packet_valid(devc->buf + offset)) { handle_packet(devc->buf + offset, sdi, idx); @@ -190,8 +205,8 @@ static gboolean handle_new_data(struct sr_dev_inst *sdi, int idx) } /* If we have any data left, move it to the beginning of our buffer. */ - for (i = 0; i < devc->buflen - offset; i++) - devc->buf[i] = devc->buf[offset + i]; + if (offset < devc->buflen) + memmove(devc->buf, devc->buf + offset, devc->buflen - offset); devc->buflen -= offset; return ret; @@ -201,7 +216,6 @@ static int receive_data(int fd, int revents, int idx, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; - int64_t t; static gboolean request_new_packet = TRUE; struct sr_serial_dev_inst *serial; @@ -229,20 +243,8 @@ static int receive_data(int fd, int revents, int idx, void *cb_data) } } - 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); - 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; - } - } + if (sr_sw_limits_check(&devc->sw_limits)) + sr_dev_acquisition_stop(sdi); return TRUE; }