struct sr_serial_dev_inst *serial;
struct sr_dev_inst *sdi;
struct sr_probe *probe;
- GSList *devices = NULL, *l;
- const char *conn = NULL, *serialcomm = NULL;
+ struct sr_config *src;
+ GSList *devices, *l;
+ const char *conn, *serialcomm;
uint8_t buf[50];
- size_t len = sizeof(buf);
+ size_t len;
+ len = sizeof(buf);
+ devices = NULL;
+ conn = serialcomm = NULL;
for (l = options; l; l = l->next) {
- struct sr_config *src = l->data;
+ src = l->data;
switch (src->key) {
case SR_CONF_CONN:
conn = g_variant_get_string(src->data, NULL);
/* Let's get a bit of data and see if we can find a packet. */
if (serial_stream_detect(serial, buf, &len, 25,
- appa_55ii_packet_valid, 500, 9600) != SR_OK)
+ appa_55ii_packet_valid, 500, 9600) != SR_OK)
goto scan_cleanup;
sr_info("Found device on port %s.", conn);
}
static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
- const struct sr_probe_group *probe_group)
+ const struct sr_probe_group *probe_group)
{
struct dev_context *devc = sdi->priv;
const struct sr_probe_group *probe_group)
{
struct dev_context *devc;
+ const char *tmp_str;
+ unsigned int i;
(void)probe_group;
sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec);
break;
case SR_CONF_DATA_SOURCE: {
- const char *tmp_str = g_variant_get_string(data, NULL);
- unsigned int i;
- for (i=0; i<ARRAY_SIZE(data_sources); i++)
+ tmp_str = g_variant_get_string(data, NULL);
+ for (i = 0; i < ARRAY_SIZE(data_sources); i++)
if (!strcmp(tmp_str, data_sources[i])) {
devc->data_source = i;
break;
}
static int dev_acquisition_start(const struct sr_dev_inst *sdi,
- void *cb_data)
+ void *cb_data)
{
- struct sr_serial_dev_inst *serial = sdi->conn;
+ struct sr_serial_dev_inst *serial;
struct dev_context *devc;
+ serial = sdi->conn;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
return std_serial_dev_acquisition_stop(sdi, cb_data, std_serial_dev_close,
- sdi->conn, LOG_PREFIX);
+ sdi->conn, LOG_PREFIX);
}
SR_PRIV struct sr_dev_driver appa_55ii_driver_info = {
static gboolean appa_55ii_checksum(const uint8_t *buf)
{
- int i, size = buf[3]+4, checksum = 0;
- for (i=0; i<size; i++)
+ int i, size, checksum;
+
+ size = buf[3] + 4;
+ checksum = 0;
+ for (i = 0; i < size; i++)
checksum += buf[i];
+
return buf[size] == (checksum & 0xFF);
}
SR_PRIV gboolean appa_55ii_packet_valid(const uint8_t *buf)
{
if (buf[0] == 0x55 && buf[1] == 0x55 && buf[3] <= 32
- && appa_55ii_checksum(buf))
+ && appa_55ii_checksum(buf))
return TRUE;
+
return FALSE;
}
static uint64_t appa_55ii_flags(const uint8_t *buf)
{
- uint8_t disp_mode = buf[4+13];
- uint64_t flags = 0;
-
- if ((disp_mode & 0xF0) == 0x20) flags |= SR_MQFLAG_HOLD;
- if ((disp_mode & 0x0C) == 0x04) flags |= SR_MQFLAG_MAX;
- if ((disp_mode & 0x0C) == 0x08) flags |= SR_MQFLAG_MIN;
- if ((disp_mode & 0x0C) == 0x0C) flags |= SR_MQFLAG_AVG;
+ uint8_t disp_mode;
+ uint64_t flags;
+
+ disp_mode = buf[4 + 13];
+ flags = 0;
+ if ((disp_mode & 0xF0) == 0x20)
+ flags |= SR_MQFLAG_HOLD;
+ if ((disp_mode & 0x0C) == 0x04)
+ flags |= SR_MQFLAG_MAX;
+ if ((disp_mode & 0x0C) == 0x08)
+ flags |= SR_MQFLAG_MIN;
+ if ((disp_mode & 0x0C) == 0x0C)
+ flags |= SR_MQFLAG_AVG;
return flags;
}
static float appa_55ii_temp(const uint8_t *buf, int probe)
{
- const uint8_t *ptr = buf + 4 + 14 + 3*probe;
- int16_t temp = RL16(ptr);
- uint8_t flags = ptr[2];
-
- if (flags & 0x60) return INFINITY;
- else if (flags & 1) return (float)temp / 10;
- else return (float)temp;
+ const uint8_t *ptr;
+ int16_t temp;
+ uint8_t flags;
+
+ ptr = buf + 4 + 14 + 3 * probe;
+ temp = RL16(ptr);
+ flags = ptr[2];
+
+ if (flags & 0x60)
+ return INFINITY;
+ else if (flags & 1)
+ return (float)temp / 10;
+ else
+ return (float)temp;
}
static void appa_55ii_live_data(struct sr_dev_inst *sdi, const uint8_t *buf)
{
struct dev_context *devc = sdi->priv;
struct sr_datafeed_packet packet;
- struct sr_datafeed_analog analog = { 0 };
- float values[APPA_55II_NUM_PROBES], *val_ptr = values;
+ struct sr_datafeed_analog analog;
+ struct sr_probe *probe;
+ float values[APPA_55II_NUM_PROBES], *val_ptr;
int i;
if (devc->data_source != DATA_SOURCE_LIVE)
return;
+ val_ptr = values;
+ memset(&analog, 0, sizeof(analog));
analog.num_samples = 1;
analog.mq = SR_MQ_TEMPERATURE;
analog.unit = SR_UNIT_CELSIUS;
analog.mqflags = appa_55ii_flags(buf);
analog.data = values;
- for (i=0; i<APPA_55II_NUM_PROBES; i++) {
- struct sr_probe *probe = g_slist_nth_data(sdi->probes, i);
+ for (i = 0; i < APPA_55II_NUM_PROBES; i++) {
+ probe = g_slist_nth_data(sdi->probes, i);
if (!probe->enabled)
continue;
analog.probes = g_slist_append(analog.probes, probe);
static void appa_55ii_log_metadata(struct sr_dev_inst *sdi, const uint8_t *buf)
{
- struct dev_context *devc = sdi->priv;
+ struct dev_context *devc;
+
+ devc = sdi->priv;
devc->num_log_records = (buf[5] << 8) + buf[4];
}
static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi)
{
- struct dev_context *devc = sdi->priv;
- int offset = 0;
+ struct dev_context *devc;
+ struct sr_datafeed_packet packet;
+ struct sr_datafeed_analog analog = { 0 };
+ struct sr_probe *probe;
+ float values[APPA_55II_NUM_PROBES], *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) {
- const uint8_t *buf = devc->log_buf + offset;
- struct sr_datafeed_packet packet;
- struct sr_datafeed_analog analog = { 0 };
- float values[APPA_55II_NUM_PROBES], *val_ptr = values;
- int i;
+ 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_PROBES; i++) {
- int16_t temp = RL16(buf+12+2*i);
- struct sr_probe *probe = g_slist_nth_data(sdi->probes, i);
+ for (i = 0; i < APPA_55II_NUM_PROBES; i++) {
+ temp = RL16(buf + 12 + 2 * i);
+ probe = g_slist_nth_data(sdi->probes, i);
if (!probe->enabled)
continue;
analog.probes = g_slist_append(analog.probes, probe);
static void appa_55ii_log_data(struct sr_dev_inst *sdi, const uint8_t *buf)
{
- struct dev_context *devc = sdi->priv;
- const uint8_t *ptr = buf + 4;;
- unsigned int size = buf[3];
+ struct dev_context *devc;
+ const uint8_t *ptr;
+ unsigned int size;
+ int s;
+ devc = sdi->priv;
if (devc->data_source != DATA_SOURCE_MEMORY)
return;
+ ptr = buf + 4;;
+ size = buf[3];
while (size > 0) {
- int s = MIN(size, sizeof(devc->log_buf) - devc->log_buf_len);
+ s = MIN(size, sizeof(devc->log_buf) - devc->log_buf_len);
memcpy(devc->log_buf + devc->log_buf_len, ptr, s);
devc->log_buf_len += s;
size -= s;
static void appa_55ii_log_end(struct sr_dev_inst *sdi)
{
- struct dev_context *devc = sdi->priv;
+ struct dev_context *devc;
+ devc = sdi->priv;
if (devc->data_source != DATA_SOURCE_MEMORY)
return;
}
static const uint8_t *appa_55ii_parse_data(struct sr_dev_inst *sdi,
- const uint8_t *buf, int len)
+ const uint8_t *buf, int len)
{
if (len < 5)
- return NULL; /* need more data */
+ /* Need more data. */
+ return NULL;
if (buf[0] != 0x55 || buf[1] != 0x55)
- return buf + 1; /* try to re-synchronize on a packet start */
+ /* Try to re-synchronize on a packet start. */
+ return buf + 1;
- if (len < 5+buf[3])
- return NULL; /* need more data */
+ if (len < 5 + buf[3])
+ /* Need more data. */
+ return NULL;
if (!appa_55ii_checksum(buf))
- return buf + 4 + buf[3] + 1; /* skip broken packet */
+ /* Skip broken packet. */
+ return buf + 4 + buf[3] + 1;
switch ((PacketType) buf[2]) {
- case LIVE_DATA: appa_55ii_live_data(sdi, buf); break;
- case LOG_METADATA: appa_55ii_log_metadata(sdi, buf); break;
- case LOG_DATA: appa_55ii_log_data(sdi, buf); break;
- case LOG_START: break;
- case LOG_END: appa_55ii_log_end(sdi); break;
+ case LIVE_DATA:
+ appa_55ii_live_data(sdi, buf);
+ break;
+ case LOG_METADATA:
+ appa_55ii_log_metadata(sdi, buf);
+ break;
+ case LOG_DATA:
+ appa_55ii_log_data(sdi, buf);
+ break;
+ case LOG_START:
+ break;
+ case LOG_END:
+ appa_55ii_log_end(sdi);
+ break;
}
return buf + 4 + buf[3] + 1;
struct sr_dev_inst *sdi;
struct dev_context *devc;
struct sr_serial_dev_inst *serial;
+ int64_t time;
const uint8_t *ptr, *next_ptr, *end_ptr;
int len;
}
if (devc->limit_msec) {
- int64_t time = (g_get_monotonic_time() - devc->start_time) / 1000;
+ time = (g_get_monotonic_time() - devc->start_time) / 1000;
if (time > (int64_t)devc->limit_msec) {
sr_info("Requested time limit reached.");
sdi->driver->dev_acquisition_stop(sdi, devc->session_cb_data);