static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_datafeed_packet packet; struct sr_datafeed_analog analog; struct sr_channel *ch; float values[APPA_55II_NUM_CHANNELS], *val_ptr; const uint8_t *buf; int16_t temp; int offset, i; devc = sdi->priv; offset = 0; while (devc->log_buf_len >= 20 && devc->num_log_records > 0) { buf = devc->log_buf + offset; val_ptr = values; /* FIXME: Timestamp should be sent in the packet. */ sr_dbg("Timestamp: %02d:%02d:%02d", buf[2], buf[3], buf[4]); memset(&analog, 0, sizeof(analog)); analog.num_samples = 1; analog.mq = SR_MQ_TEMPERATURE; analog.unit = SR_UNIT_CELSIUS; analog.data = values; for (i = 0; i < APPA_55II_NUM_CHANNELS; i++) { temp = RL16(buf + 12 + 2 * i); ch = g_slist_nth_data(sdi->channels, i); if (!ch->enabled) continue; analog.channels = g_slist_append(analog.channels, ch); *val_ptr++ = temp == 0x7FFF ? INFINITY : (float)temp / 10; } packet.type = SR_DF_ANALOG; packet.payload = &analog; sr_session_send(devc->session_cb_data, &packet); g_slist_free(analog.channels); devc->num_samples++; devc->log_buf_len -= 20; offset += 20; devc->num_log_records--; } memmove(devc->log_buf, devc->log_buf + offset, devc->log_buf_len); }
static float appa_55ii_temp(const uint8_t *buf, int ch) { const uint8_t *ptr; int16_t temp; uint8_t flags; ptr = buf + 4 + 14 + 3 * ch; temp = RL16(ptr); flags = ptr[2]; if (flags & 0x60) return INFINITY; else if (flags & 1) return (float)temp / 10; else return (float)temp; }
static int parse_wav_header(GString *buf, struct context *inc) { uint64_t samplerate; unsigned int fmt_code, samplesize, num_channels, unitsize; if (buf->len < MIN_DATA_CHUNK_OFFSET) return SR_ERR_NA; fmt_code = RL16(buf->str + 20); samplerate = RL32(buf->str + 24); samplesize = RL16(buf->str + 32); num_channels = RL16(buf->str + 22); if (num_channels == 0) return SR_ERR; unitsize = samplesize / num_channels; if (unitsize != 1 && unitsize != 2 && unitsize != 4) { sr_err("Only 8, 16 or 32 bits per sample supported."); return SR_ERR_DATA; } if (fmt_code == WAVE_FORMAT_PCM_) { } else if (fmt_code == WAVE_FORMAT_IEEE_FLOAT_) { if (unitsize != 4) { sr_err("only 32-bit floats supported."); return SR_ERR_DATA; } } else if (fmt_code == WAVE_FORMAT_EXTENSIBLE_) { if (buf->len < 70) /* Not enough for extensible header and next chunk. */ return SR_ERR_NA; if (RL16(buf->str + 16) != 40) { sr_err("WAV extensible format chunk must be 40 bytes."); return SR_ERR; } if (RL16(buf->str + 36) != 22) { sr_err("WAV extension must be 22 bytes."); return SR_ERR; } if (RL16(buf->str + 34) != RL16(buf->str + 38)) { sr_err("Reduced valid bits per sample not supported."); return SR_ERR_DATA; } /* Real format code is the first two bytes of the GUID. */ fmt_code = RL16(buf->str + 44); if (fmt_code != WAVE_FORMAT_PCM_ && fmt_code != WAVE_FORMAT_IEEE_FLOAT_) { sr_err("Only PCM and floating point samples are supported."); return SR_ERR_DATA; } if (fmt_code == WAVE_FORMAT_IEEE_FLOAT_ && unitsize != 4) { sr_err("only 32-bit floats supported."); return SR_ERR_DATA; } } else { sr_err("Only PCM and floating point samples are supported."); return SR_ERR_DATA; } if (inc) { inc->fmt_code = fmt_code; inc->samplerate = samplerate; inc->samplesize = samplesize; inc->num_channels = num_channels; inc->unitsize = unitsize; inc->found_data = FALSE; } return SR_OK; }