* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <config.h>
#include <stdlib.h>
#include <glib.h>
-#include "libsigrok.h"
+#include <string.h>
+#include <libsigrok/libsigrok.h>
#include "libsigrok-internal.h"
#include "protocol.h"
-#include <errno.h>
-#include <string.h>
static void process_packet(const struct sr_dev_inst *sdi)
{
struct dev_context *devc;
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;
GString *dbg;
float fvalue;
int checksum, mode, i;
}
fvalue /= 10;
- memset(&analog, 0, sizeof(struct sr_datafeed_analog));
- analog.mq = SR_MQ_SOUND_PRESSURE_LEVEL;
- analog.unit = SR_UNIT_DECIBEL_SPL;
- analog.channels = sdi->channels;
+ sr_analog_init(&analog, &encoding, &meaning, &spec, 1);
+ analog.meaning->mq = SR_MQ_SOUND_PRESSURE_LEVEL;
+ analog.meaning->unit = SR_UNIT_DECIBEL_SPL;
+ analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
analog.data = &fvalue;
/* High nibble should only have 0x01 or 0x02. */
mode = (devc->buf[2] >> 4) & 0x0f;
if (mode == 0x02)
- analog.mqflags |= SR_MQFLAG_HOLD;
+ analog.meaning->mqflags |= SR_MQFLAG_HOLD;
else if (mode != 0x01) {
sr_dbg("unknown measurement mode 0x%.2x", mode);
return;
* weighting. */
mode = devc->buf[2] & 0x0f;
switch (mode) {
- case 0x0:
- analog.mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_A \
- | SR_MQFLAG_SPL_TIME_WEIGHT_F;
- break;
- case 0x1:
- analog.mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_A \
- | SR_MQFLAG_SPL_TIME_WEIGHT_S;
- break;
- case 0x2:
- analog.mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_C \
- | SR_MQFLAG_SPL_TIME_WEIGHT_F;
- break;
- case 0x3:
- analog.mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_C \
- | SR_MQFLAG_SPL_TIME_WEIGHT_S;
- break;
- case 0x4:
- analog.mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT \
- | SR_MQFLAG_SPL_TIME_WEIGHT_F;
- break;
- case 0x5:
- analog.mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT \
- | SR_MQFLAG_SPL_TIME_WEIGHT_S;
- break;
- case 0x6:
- analog.mqflags |= SR_MQFLAG_SPL_PCT_OVER_ALARM \
- | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
- | SR_MQFLAG_SPL_TIME_WEIGHT_F;
- break;
- case 0x7:
- analog.mqflags |= SR_MQFLAG_SPL_PCT_OVER_ALARM \
- | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
- | SR_MQFLAG_SPL_TIME_WEIGHT_S;
- break;
- case 0x8:
- /* 10-second mean, but we don't have MQ flags to express it. */
- analog.mqflags |= SR_MQFLAG_SPL_LAT \
- | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
- | SR_MQFLAG_SPL_TIME_WEIGHT_F;
- break;
- case 0x9:
- /* Mean over a time period between 11 seconds and 24 hours.
- * Which is so silly that there's no point in expressing
- * either this or the previous case. */
- analog.mqflags |= SR_MQFLAG_SPL_LAT \
- | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
- | SR_MQFLAG_SPL_TIME_WEIGHT_F;
- break;
- case 0xa:
- /* 10-second mean. */
- analog.mqflags |= SR_MQFLAG_SPL_LAT \
- | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
- | SR_MQFLAG_SPL_TIME_WEIGHT_S;
- break;
- case 0xb:
- /* Mean over a time period between 11 seconds and 24 hours. */
- analog.mqflags |= SR_MQFLAG_SPL_LAT \
- | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
- | SR_MQFLAG_SPL_TIME_WEIGHT_S;
- break;
- case 0xc:
- /* Internal calibration on 1kHz sine at 94dB, not useful
- * to anything but the device. */
- analog.mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT;
- break;
- case 0xd:
- /* Internal calibration on 1kHz sine at 94dB, not useful
- * to anything but the device. */
- analog.mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT;
- break;
- default:
- sr_dbg("unknown configuration 0x%.2x", mode);
- return;
- break;
+ case 0x0:
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_A \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_F;
+ break;
+ case 0x1:
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_A \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_S;
+ break;
+ case 0x2:
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_C \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_F;
+ break;
+ case 0x3:
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_C \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_S;
+ break;
+ case 0x4:
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_F;
+ break;
+ case 0x5:
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_S;
+ break;
+ case 0x6:
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_PCT_OVER_ALARM \
+ | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_F;
+ break;
+ case 0x7:
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_PCT_OVER_ALARM \
+ | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_S;
+ break;
+ case 0x8:
+ /* 10-second mean, but we don't have MQ flags to express it. */
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_LAT \
+ | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_F;
+ break;
+ case 0x9:
+ /* Mean over a time period between 11 seconds and 24 hours.
+ * Which is so silly that there's no point in expressing
+ * either this or the previous case. */
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_LAT \
+ | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_F;
+ break;
+ case 0xa:
+ /* 10-second mean. */
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_LAT \
+ | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_S;
+ break;
+ case 0xb:
+ /* Mean over a time period between 11 seconds and 24 hours. */
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_LAT \
+ | SR_MQFLAG_SPL_FREQ_WEIGHT_A \
+ | SR_MQFLAG_SPL_TIME_WEIGHT_S;
+ break;
+ case 0xc:
+ /* Internal calibration on 1kHz sine at 94dB, not useful
+ * to anything but the device. */
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT;
+ break;
+ case 0xd:
+ /* Internal calibration on 1kHz sine at 94dB, not useful
+ * to anything but the device. */
+ analog.meaning->mqflags |= SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT;
+ break;
+ default:
+ sr_dbg("unknown configuration 0x%.2x", mode);
+ return;
}
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
- devc->num_samples++;
- if (devc->num_samples >= devc->limit_samples)
- sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi,
- devc->cb_data);
+ sr_sw_limits_update_samples_read(&devc->limits, 1);
+ if (sr_sw_limits_check(&devc->limits))
+ sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi);
}
SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data)
const struct sr_dev_inst *sdi;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
- int len;
+ int delay_ms, len;
char buf[128];
(void)fd;
serial = sdi->conn;
if (devc->state == IDLE) {
- if (serial_read(serial, buf, 128) != 1 || buf[0] != 0x10)
+ if (serial_read_nonblocking(serial, buf, 128) != 1 || buf[0] != 0x10)
/* Nothing there, or caught the tail end of a previous packet,
* or some garbage. Unless it's a single "data ready" byte,
* we don't want it. */
return TRUE;
/* Got 0x10, "measurement ready". */
- if (serial_write_blocking(serial, "\x20", 1) == -1)
- sr_err("unable to send command: %s", strerror(errno));
+ delay_ms = serial_timeout(serial, 1);
+ if (serial_write_blocking(serial, "\x20", 1, delay_ms) < 1)
+ sr_err("unable to send command");
else {
devc->state = COMMAND_SENT;
devc->buflen = 0;
}
} else {
- len = serial_read(serial, devc->buf + devc->buflen,
+ len = serial_read_nonblocking(serial, devc->buf + devc->buflen,
10 - devc->buflen);
if (len < 1)
return TRUE;