X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fcem-dt-885x%2Fprotocol.c;h=0366b29d95b5ac7a0832614dc53a4ce115a06ac2;hb=refs%2Fheads%2Flibsigrok-0.5.x;hp=bbb1a03a0b1a935af36bc59c011d93341f702899;hpb=1beccaed464a4d92a070988a0331fe399f9f7a7a;p=libsigrok.git
diff --git a/src/hardware/cem-dt-885x/protocol.c b/src/hardware/cem-dt-885x/protocol.c
index bbb1a03a..0366b29d 100644
--- a/src/hardware/cem-dt-885x/protocol.c
+++ b/src/hardware/cem-dt-885x/protocol.c
@@ -17,11 +17,12 @@
* along with this program. If not, see .
*/
+#include
#include
#include "protocol.h"
/* Length of expected payload for each token. */
-static int token_payloads[][2] = {
+static const int token_payloads[][2] = {
{ TOKEN_WEIGHT_TIME_FAST, 0 },
{ TOKEN_WEIGHT_TIME_SLOW, 0 },
{ TOKEN_HOLD_MAX, 0 },
@@ -66,6 +67,9 @@ static void process_mset(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 i;
@@ -84,7 +88,7 @@ static void process_mset(const struct sr_dev_inst *sdi)
g_string_free(dbg, TRUE);
}
- switch(devc->token) {
+ switch (devc->token) {
case TOKEN_WEIGHT_TIME_FAST:
devc->cur_mqflags |= SR_MQFLAG_SPL_TIME_WEIGHT_F;
devc->cur_mqflags &= ~SR_MQFLAG_SPL_TIME_WEIGHT_S;
@@ -130,21 +134,20 @@ static void process_mset(const struct sr_dev_inst *sdi)
break;
}
}
- memset(&analog, 0, sizeof(struct sr_datafeed_analog));
- analog.mq = SR_MQ_SOUND_PRESSURE_LEVEL;
- analog.mqflags = devc->cur_mqflags;
- 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->mqflags = devc->cur_mqflags;
+ analog.meaning->unit = SR_UNIT_DECIBEL_SPL;
+ analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
analog.data = &devc->last_spl;
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->limit_samples && devc->num_samples >= devc->limit_samples)
- sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi,
- devc->cb_data);
+ sr_dev_acquisition_stop((struct sr_dev_inst *)sdi);
break;
case TOKEN_RECORDING_ON:
devc->recording = TRUE;
@@ -166,7 +169,7 @@ static void process_mset(const struct sr_dev_inst *sdi)
case TOKEN_MEAS_RANGE_OK:
case TOKEN_MEAS_RANGE_OVER:
case TOKEN_MEAS_RANGE_UNDER:
- /* Not useful, or not expressable in sigrok. */
+ /* Not useful, or not expressible in sigrok. */
break;
}
@@ -178,32 +181,34 @@ static void send_data(const struct sr_dev_inst *sdi, unsigned char *data,
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;
float fbuf[SAMPLES_PER_PACKET];
unsigned int i;
devc = sdi->priv;
- for (i = 0; i < num_samples; i ++) {
+ for (i = 0; i < num_samples; i++) {
fbuf[i] = ((data[i * 2] & 0xf0) >> 4) * 100;
fbuf[i] += (data[i * 2] & 0x0f) * 10;
fbuf[i] += ((data[i * 2 + 1] & 0xf0) >> 4);
fbuf[i] += (data[i * 2 + 1] & 0x0f) / 10.0;
}
- memset(&analog, 0, sizeof(struct sr_datafeed_analog));
- analog.mq = SR_MQ_SOUND_PRESSURE_LEVEL;
- analog.mqflags = devc->cur_mqflags;
- 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->mqflags = devc->cur_mqflags;
+ analog.meaning->unit = SR_UNIT_DECIBEL_SPL;
+ analog.meaning->channels = sdi->channels;
analog.num_samples = num_samples;
analog.data = fbuf;
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
devc->num_samples += analog.num_samples;
if (devc->limit_samples && devc->num_samples >= devc->limit_samples)
- sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi,
- devc->cb_data);
+ sr_dev_acquisition_stop((struct sr_dev_inst *)sdi);
return;
}
@@ -316,8 +321,7 @@ static void process_byte(const struct sr_dev_inst *sdi, const unsigned char c,
* records. Otherwise the frontend would have no
* way to tell where stored data ends and live
* measurements begin. */
- sdi->driver->dev_acquisition_stop((struct sr_dev_inst *)sdi,
- devc->cb_data);
+ sr_dev_acquisition_stop((struct sr_dev_inst *)sdi);
} else if (c == RECORD_DATA) {
devc->buf_len = 0;
devc->state = ST_GET_LOG_RECORD_DATA;
@@ -341,8 +345,9 @@ static void process_byte(const struct sr_dev_inst *sdi, const unsigned char c,
src = sr_config_new(SR_CONF_SAMPLE_INTERVAL,
g_variant_new_uint64(devc->buf[7] * 1000));
meta.config = g_slist_append(NULL, src);
- sr_session_send(devc->cb_data, &packet);
- g_free(src);
+ sr_session_send(sdi, &packet);
+ g_slist_free(meta.config);
+ sr_config_free(src);
devc->buf_len = 0;
}
} else if (devc->state == ST_GET_LOG_RECORD_DATA) {
@@ -396,7 +401,7 @@ SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data)
} else {
/* Tell device to start transferring from memory. */
cmd = CMD_TRANSFER_MEMORY;
- serial_write_nonblocking(serial, &cmd, 1);
+ serial_write_blocking(serial, &cmd, 1, 0);
}
}
}
@@ -452,7 +457,7 @@ static int cem_dt_885x_toggle(const struct sr_dev_inst *sdi, uint8_t cmd,
* only thing to do is wait for the token that will confirm
* whether the command worked or not, and resend if needed. */
while (TRUE) {
- if (serial_write_nonblocking(serial, (const void *)&cmd, 1) != 1)
+ if (serial_write_blocking(serial, (const void *)&cmd, 1, 0) < 0)
return SR_ERR;
if (wait_for_token(sdi, tokens, timeout) == SR_ERR)
return SR_ERR;
@@ -766,11 +771,11 @@ SR_PRIV int cem_dt_885x_meas_range_set(const struct sr_dev_inst *sdi,
devc = sdi->priv;
if (low == 30 && high == 130)
token = TOKEN_MEAS_RANGE_30_130;
- else if (low == 30 && high == 80)
+ else if (low == 30 && high == 80)
token = TOKEN_MEAS_RANGE_30_80;
- else if (low == 50 && high == 100)
+ else if (low == 50 && high == 100)
token = TOKEN_MEAS_RANGE_50_100;
- else if (low == 80 && high == 130)
+ else if (low == 80 && high == 130)
token = TOKEN_MEAS_RANGE_80_130;
else
return SR_ERR;
@@ -813,7 +818,7 @@ SR_PRIV int cem_dt_885x_power_off(const struct sr_dev_inst *sdi)
cmd = CMD_TOGGLE_POWER_OFF;
while (TRUE) {
serial_flush(serial);
- if (serial_write_nonblocking(serial, (const void *)&cmd, 1) != 1)
+ if (serial_write_blocking(serial, (const void *)&cmd, 1, 0) < 0)
return SR_ERR;
/* It never takes more than 23ms for the next token to arrive. */
g_usleep(25 * 1000);