lascar-el-usb: Convert to SR_DF_ANALOG.
This commit is contained in:
parent
2c9111820a
commit
5ba417591c
|
@ -387,7 +387,10 @@ static void lascar_el_usb_dispatch(struct sr_dev_inst *sdi, unsigned char *buf,
|
||||||
{
|
{
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
struct sr_datafeed_analog_old analog;
|
struct sr_datafeed_analog analog;
|
||||||
|
struct sr_analog_encoding encoding;
|
||||||
|
struct sr_analog_meaning meaning;
|
||||||
|
struct sr_analog_spec spec;
|
||||||
struct sr_channel *ch;
|
struct sr_channel *ch;
|
||||||
float *temp, *rh;
|
float *temp, *rh;
|
||||||
uint16_t s;
|
uint16_t s;
|
||||||
|
@ -395,15 +398,17 @@ static void lascar_el_usb_dispatch(struct sr_dev_inst *sdi, unsigned char *buf,
|
||||||
|
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
|
|
||||||
|
sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
|
||||||
|
|
||||||
samples = buflen / devc->sample_size;
|
samples = buflen / devc->sample_size;
|
||||||
samples_left = devc->logged_samples - devc->rcvd_samples;
|
samples_left = devc->logged_samples - devc->rcvd_samples;
|
||||||
if (samples_left < samples)
|
if (samples_left < samples)
|
||||||
samples = samples_left;
|
samples = samples_left;
|
||||||
switch (devc->profile->logformat) {
|
switch (devc->profile->logformat) {
|
||||||
case LOG_TEMP_RH:
|
case LOG_TEMP_RH:
|
||||||
packet.type = SR_DF_ANALOG_OLD;
|
packet.type = SR_DF_ANALOG;
|
||||||
packet.payload = &analog;
|
packet.payload = &analog;
|
||||||
analog.mqflags = 0;
|
analog.meaning->mqflags = 0;
|
||||||
if (!(temp = g_try_malloc(sizeof(float) * samples)))
|
if (!(temp = g_try_malloc(sizeof(float) * samples)))
|
||||||
break;
|
break;
|
||||||
if (!(rh = g_try_malloc(sizeof(float) * samples)))
|
if (!(rh = g_try_malloc(sizeof(float) * samples)))
|
||||||
|
@ -427,45 +432,45 @@ static void lascar_el_usb_dispatch(struct sr_dev_inst *sdi, unsigned char *buf,
|
||||||
|
|
||||||
ch = sdi->channels->data;
|
ch = sdi->channels->data;
|
||||||
if (ch->enabled) {
|
if (ch->enabled) {
|
||||||
analog.channels = g_slist_append(NULL, ch);
|
analog.meaning->channels = g_slist_append(NULL, ch);
|
||||||
analog.mq = SR_MQ_TEMPERATURE;
|
analog.meaning->mq = SR_MQ_TEMPERATURE;
|
||||||
if (devc->temp_unit == 1)
|
if (devc->temp_unit == 1)
|
||||||
analog.unit = SR_UNIT_FAHRENHEIT;
|
analog.meaning->unit = SR_UNIT_FAHRENHEIT;
|
||||||
else
|
else
|
||||||
analog.unit = SR_UNIT_CELSIUS;
|
analog.meaning->unit = SR_UNIT_CELSIUS;
|
||||||
analog.data = temp;
|
analog.data = (void *)temp;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
g_slist_free(analog.channels);
|
g_slist_free(analog.meaning->channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
ch = sdi->channels->next->data;
|
ch = sdi->channels->next->data;
|
||||||
if (ch->enabled) {
|
if (ch->enabled) {
|
||||||
analog.channels = g_slist_append(NULL, ch);
|
analog.meaning->channels = g_slist_append(NULL, ch);
|
||||||
analog.mq = SR_MQ_RELATIVE_HUMIDITY;
|
analog.meaning->mq = SR_MQ_RELATIVE_HUMIDITY;
|
||||||
analog.unit = SR_UNIT_PERCENTAGE;
|
analog.meaning->unit = SR_UNIT_PERCENTAGE;
|
||||||
analog.data = rh;
|
analog.data = (void *)rh;
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
g_slist_free(analog.channels);
|
g_slist_free(analog.meaning->channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(temp);
|
g_free(temp);
|
||||||
g_free(rh);
|
g_free(rh);
|
||||||
break;
|
break;
|
||||||
case LOG_CO:
|
case LOG_CO:
|
||||||
packet.type = SR_DF_ANALOG_OLD;
|
packet.type = SR_DF_ANALOG;
|
||||||
packet.payload = &analog;
|
packet.payload = &analog;
|
||||||
analog.channels = sdi->channels;
|
analog.meaning->channels = sdi->channels;
|
||||||
analog.num_samples = samples;
|
analog.num_samples = samples;
|
||||||
analog.mq = SR_MQ_CARBON_MONOXIDE;
|
analog.meaning->mq = SR_MQ_CARBON_MONOXIDE;
|
||||||
analog.unit = SR_UNIT_CONCENTRATION;
|
analog.meaning->unit = SR_UNIT_CONCENTRATION;
|
||||||
analog.mqflags = 0;
|
analog.meaning->mqflags = 0;
|
||||||
if (!(analog.data = g_try_malloc(sizeof(float) * samples)))
|
if (!(analog.data = g_try_malloc(sizeof(float) * samples)))
|
||||||
break;
|
break;
|
||||||
for (i = 0; i < samples; i++) {
|
for (i = 0; i < samples; i++) {
|
||||||
s = (buf[i * 2] << 8) | buf[i * 2 + 1];
|
s = (buf[i * 2] << 8) | buf[i * 2 + 1];
|
||||||
analog.data[i] = (s * devc->co_high + devc->co_low) / (1000 * 1000);
|
((float *)analog.data)[i] = (s * devc->co_high + devc->co_low) / (1000 * 1000);
|
||||||
if (analog.data[i] < 0.0)
|
if (((float *)analog.data)[i] < 0.0)
|
||||||
analog.data[i] = 0.0;
|
((float *)analog.data)[i] = 0.0;
|
||||||
}
|
}
|
||||||
sr_session_send(sdi, &packet);
|
sr_session_send(sdi, &packet);
|
||||||
g_free(analog.data);
|
g_free(analog.data);
|
||||||
|
|
Loading…
Reference in New Issue