X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fcolead-slm%2Fprotocol.c;h=570e7db33a6a918eecff07f11bf2a9817dcd09be;hb=refs%2Fheads%2Flibsigrok-0.5.x;hp=6864cb68ee8615f369f478051ff2807e03ace329;hpb=081c214eace0c9088cbcbd9a3d448f6fac5e98f4;p=libsigrok.git
diff --git a/src/hardware/colead-slm/protocol.c b/src/hardware/colead-slm/protocol.c
index 6864cb68..570e7db3 100644
--- a/src/hardware/colead-slm/protocol.c
+++ b/src/hardware/colead-slm/protocol.c
@@ -17,19 +17,22 @@
* along with this program. If not, see .
*/
+#include
#include
#include
-#include "libsigrok.h"
+#include
+#include
#include "libsigrok-internal.h"
#include "protocol.h"
-#include
-#include
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;
@@ -71,17 +74,17 @@ static void process_packet(const struct sr_dev_inst *sdi)
}
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;
@@ -92,91 +95,89 @@ static void process_packet(const struct sr_dev_inst *sdi)
* 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))
+ sr_dev_acquisition_stop((struct sr_dev_inst *)sdi);
}
SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data)
@@ -184,7 +185,7 @@ 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;
@@ -201,13 +202,14 @@ SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data)
serial = sdi->conn;
if (devc->state == IDLE) {
- if (serial_read_nonblocking(serial, buf, 128) != 1 || buf[0] != 0x10)
+ if (serial_read_nonblocking(serial, buf, sizeof(buf)) != 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)
+ 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;