X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Ftondaj-sl-814%2Fprotocol.c;h=13f043056255b7d42fcbae3f1370e2486a615dd9;hb=81ceb6a51dd666987fb5c67b83c5ba14d105b301;hp=feeec69aa559c7f947eacc111952aa991cc9aa2e;hpb=155b680da482cea2381becb73c51cfb838bff31e;p=libsigrok.git
diff --git a/src/hardware/tondaj-sl-814/protocol.c b/src/hardware/tondaj-sl-814/protocol.c
index feeec69a..13f04305 100644
--- a/src/hardware/tondaj-sl-814/protocol.c
+++ b/src/hardware/tondaj-sl-814/protocol.c
@@ -14,13 +14,13 @@
* 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
#include
-#include "libsigrok.h"
+#include
#include "libsigrok-internal.h"
#include "protocol.h"
@@ -68,18 +68,18 @@ static void parse_packet(const uint8_t *buf, float *floatval,
/* The value on the display always has one digit after the comma. */
*floatval /= 10;
- analog->mq = SR_MQ_SOUND_PRESSURE_LEVEL;
- analog->unit = SR_UNIT_DECIBEL_SPL;
+ analog->meaning->mq = SR_MQ_SOUND_PRESSURE_LEVEL;
+ analog->meaning->unit = SR_UNIT_DECIBEL_SPL;
if (is_a)
- analog->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_A;
+ analog->meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_A;
else
- analog->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_C;
+ analog->meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_C;
if (is_fast)
- analog->mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_F;
+ analog->meaning->mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_F;
else
- analog->mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_S;
+ analog->meaning->mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_S;
/* TODO: How to handle level? */
(void)level;
@@ -89,26 +89,30 @@ static void decode_packet(struct sr_dev_inst *sdi)
{
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;
float floatval;
devc = sdi->priv;
- memset(&analog, 0, sizeof(struct sr_datafeed_analog));
+
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 1);
parse_packet(devc->buf, &floatval, &analog);
/* Send a sample packet with one analog value. */
- analog.channels = sdi->channels;
+ analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
analog.data = &floatval;
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
- devc->num_samples++;
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
}
-int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
+SR_PRIV int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
@@ -133,14 +137,15 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
buf[2] = 0x0d;
sr_spew("Sending init command: %02x %02x %02x.",
buf[0], buf[1], buf[2]);
- if ((ret = serial_write(serial, buf, 3)) < 0) {
+ if ((ret = serial_write_blocking(serial, buf, 3,
+ serial_timeout(serial, 3))) < 0) {
sr_err("Error sending init command: %d.", ret);
return FALSE;
}
devc->state = GET_INIT_REPLY;
} else if (devc->state == GET_INIT_REPLY) {
/* If we just sent the "init" command, get its reply. */
- if ((ret = serial_read(serial, buf, 2)) < 0) {
+ if ((ret = serial_read_blocking(serial, buf, 2, 0)) < 0) {
sr_err("Error reading init reply: %d.", ret);
return FALSE;
}
@@ -159,7 +164,8 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
buf[2] = 0x0d;
sr_spew("Sending data request command: %02x %02x %02x.",
buf[0], buf[1], buf[2]);
- if ((ret = serial_write(serial, buf, 3)) < 0) {
+ if ((ret = serial_write_blocking(serial, buf, 3,
+ serial_timeout(serial, 3))) < 0) {
sr_err("Error sending request command: %d.", ret);
return FALSE;
}
@@ -167,8 +173,8 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
devc->state = GET_PACKET;
} else if (devc->state == GET_PACKET) {
/* Read a packet from the device. */
- ret = serial_read(serial, devc->buf + devc->buflen,
- 4 - devc->buflen);
+ ret = serial_read_nonblocking(serial, devc->buf + devc->buflen,
+ 4 - devc->buflen);
if (ret < 0) {
sr_err("Error reading packet: %d.", ret);
return TRUE;
@@ -198,11 +204,8 @@ int tondaj_sl_814_receive_data(int fd, int revents, void *cb_data)
return FALSE;
}
- /* Stop acquisition if we acquired enough samples. */
- 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);
- }
+ if (sr_sw_limits_check(&devc->limits))
+ sr_dev_acquisition_stop(sdi);
return TRUE;
}