appa-55ii: Coding style fixes.
This commit is contained in:
parent
81a9ab725f
commit
7574e58c1a
|
@ -53,13 +53,17 @@ static GSList *scan(GSList *options)
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
GSList *devices = NULL, *l;
|
struct sr_config *src;
|
||||||
const char *conn = NULL, *serialcomm = NULL;
|
GSList *devices, *l;
|
||||||
|
const char *conn, *serialcomm;
|
||||||
uint8_t buf[50];
|
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) {
|
for (l = options; l; l = l->next) {
|
||||||
struct sr_config *src = l->data;
|
src = l->data;
|
||||||
switch (src->key) {
|
switch (src->key) {
|
||||||
case SR_CONF_CONN:
|
case SR_CONF_CONN:
|
||||||
conn = g_variant_get_string(src->data, NULL);
|
conn = g_variant_get_string(src->data, NULL);
|
||||||
|
@ -87,7 +91,7 @@ static GSList *scan(GSList *options)
|
||||||
|
|
||||||
/* Let's get a bit of data and see if we can find a packet. */
|
/* Let's get a bit of data and see if we can find a packet. */
|
||||||
if (serial_stream_detect(serial, buf, &len, 25,
|
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;
|
goto scan_cleanup;
|
||||||
|
|
||||||
sr_info("Found device on port %s.", conn);
|
sr_info("Found device on port %s.", conn);
|
||||||
|
@ -139,7 +143,7 @@ static int cleanup(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
|
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;
|
struct dev_context *devc = sdi->priv;
|
||||||
|
|
||||||
|
@ -166,6 +170,8 @@ static int config_set(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;
|
struct dev_context *devc;
|
||||||
|
const char *tmp_str;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
(void)probe_group;
|
(void)probe_group;
|
||||||
|
|
||||||
|
@ -187,9 +193,8 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
|
||||||
sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec);
|
sr_dbg("Setting time limit to %" PRIu64 "ms.", devc->limit_msec);
|
||||||
break;
|
break;
|
||||||
case SR_CONF_DATA_SOURCE: {
|
case SR_CONF_DATA_SOURCE: {
|
||||||
const char *tmp_str = g_variant_get_string(data, NULL);
|
tmp_str = g_variant_get_string(data, NULL);
|
||||||
unsigned int i;
|
for (i = 0; i < ARRAY_SIZE(data_sources); i++)
|
||||||
for (i=0; i<ARRAY_SIZE(data_sources); i++)
|
|
||||||
if (!strcmp(tmp_str, data_sources[i])) {
|
if (!strcmp(tmp_str, data_sources[i])) {
|
||||||
devc->data_source = i;
|
devc->data_source = i;
|
||||||
break;
|
break;
|
||||||
|
@ -231,11 +236,12 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dev_acquisition_start(const struct sr_dev_inst *sdi,
|
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;
|
struct dev_context *devc;
|
||||||
|
|
||||||
|
serial = sdi->conn;
|
||||||
if (sdi->status != SR_ST_ACTIVE)
|
if (sdi->status != SR_ST_ACTIVE)
|
||||||
return SR_ERR_DEV_CLOSED;
|
return SR_ERR_DEV_CLOSED;
|
||||||
|
|
||||||
|
@ -266,7 +272,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
|
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,
|
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 = {
|
SR_PRIV struct sr_dev_driver appa_55ii_driver_info = {
|
||||||
|
|
|
@ -31,63 +31,84 @@ typedef enum {
|
||||||
|
|
||||||
static gboolean appa_55ii_checksum(const uint8_t *buf)
|
static gboolean appa_55ii_checksum(const uint8_t *buf)
|
||||||
{
|
{
|
||||||
int i, size = buf[3]+4, checksum = 0;
|
int i, size, checksum;
|
||||||
for (i=0; i<size; i++)
|
|
||||||
|
size = buf[3] + 4;
|
||||||
|
checksum = 0;
|
||||||
|
for (i = 0; i < size; i++)
|
||||||
checksum += buf[i];
|
checksum += buf[i];
|
||||||
|
|
||||||
return buf[size] == (checksum & 0xFF);
|
return buf[size] == (checksum & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
SR_PRIV gboolean appa_55ii_packet_valid(const uint8_t *buf)
|
SR_PRIV gboolean appa_55ii_packet_valid(const uint8_t *buf)
|
||||||
{
|
{
|
||||||
if (buf[0] == 0x55 && buf[1] == 0x55 && buf[3] <= 32
|
if (buf[0] == 0x55 && buf[1] == 0x55 && buf[3] <= 32
|
||||||
&& appa_55ii_checksum(buf))
|
&& appa_55ii_checksum(buf))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t appa_55ii_flags(const uint8_t *buf)
|
static uint64_t appa_55ii_flags(const uint8_t *buf)
|
||||||
{
|
{
|
||||||
uint8_t disp_mode = buf[4+13];
|
uint8_t disp_mode;
|
||||||
uint64_t flags = 0;
|
uint64_t flags;
|
||||||
|
|
||||||
if ((disp_mode & 0xF0) == 0x20) flags |= SR_MQFLAG_HOLD;
|
disp_mode = buf[4 + 13];
|
||||||
if ((disp_mode & 0x0C) == 0x04) flags |= SR_MQFLAG_MAX;
|
flags = 0;
|
||||||
if ((disp_mode & 0x0C) == 0x08) flags |= SR_MQFLAG_MIN;
|
if ((disp_mode & 0xF0) == 0x20)
|
||||||
if ((disp_mode & 0x0C) == 0x0C) flags |= SR_MQFLAG_AVG;
|
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;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float appa_55ii_temp(const uint8_t *buf, int probe)
|
static float appa_55ii_temp(const uint8_t *buf, int probe)
|
||||||
{
|
{
|
||||||
const uint8_t *ptr = buf + 4 + 14 + 3*probe;
|
const uint8_t *ptr;
|
||||||
int16_t temp = RL16(ptr);
|
int16_t temp;
|
||||||
uint8_t flags = ptr[2];
|
uint8_t flags;
|
||||||
|
|
||||||
if (flags & 0x60) return INFINITY;
|
ptr = buf + 4 + 14 + 3 * probe;
|
||||||
else if (flags & 1) return (float)temp / 10;
|
temp = RL16(ptr);
|
||||||
else return (float)temp;
|
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)
|
static void appa_55ii_live_data(struct sr_dev_inst *sdi, const uint8_t *buf)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc = sdi->priv;
|
||||||
struct sr_datafeed_packet packet;
|
struct sr_datafeed_packet packet;
|
||||||
struct sr_datafeed_analog analog = { 0 };
|
struct sr_datafeed_analog analog;
|
||||||
float values[APPA_55II_NUM_PROBES], *val_ptr = values;
|
struct sr_probe *probe;
|
||||||
|
float values[APPA_55II_NUM_PROBES], *val_ptr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (devc->data_source != DATA_SOURCE_LIVE)
|
if (devc->data_source != DATA_SOURCE_LIVE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
val_ptr = values;
|
||||||
|
memset(&analog, 0, sizeof(analog));
|
||||||
analog.num_samples = 1;
|
analog.num_samples = 1;
|
||||||
analog.mq = SR_MQ_TEMPERATURE;
|
analog.mq = SR_MQ_TEMPERATURE;
|
||||||
analog.unit = SR_UNIT_CELSIUS;
|
analog.unit = SR_UNIT_CELSIUS;
|
||||||
analog.mqflags = appa_55ii_flags(buf);
|
analog.mqflags = appa_55ii_flags(buf);
|
||||||
analog.data = values;
|
analog.data = values;
|
||||||
|
|
||||||
for (i=0; i<APPA_55II_NUM_PROBES; i++) {
|
for (i = 0; i < APPA_55II_NUM_PROBES; i++) {
|
||||||
struct sr_probe *probe = g_slist_nth_data(sdi->probes, i);
|
probe = g_slist_nth_data(sdi->probes, i);
|
||||||
if (!probe->enabled)
|
if (!probe->enabled)
|
||||||
continue;
|
continue;
|
||||||
analog.probes = g_slist_append(analog.probes, probe);
|
analog.probes = g_slist_append(analog.probes, probe);
|
||||||
|
@ -104,33 +125,42 @@ static void appa_55ii_live_data(struct sr_dev_inst *sdi, const uint8_t *buf)
|
||||||
|
|
||||||
static void appa_55ii_log_metadata(struct sr_dev_inst *sdi, const uint8_t *buf)
|
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];
|
devc->num_log_records = (buf[5] << 8) + buf[4];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi)
|
static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc;
|
||||||
int offset = 0;
|
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) {
|
while (devc->log_buf_len >= 20 && devc->num_log_records > 0) {
|
||||||
const uint8_t *buf = devc->log_buf + offset;
|
buf = devc->log_buf + offset;
|
||||||
struct sr_datafeed_packet packet;
|
val_ptr = values;
|
||||||
struct sr_datafeed_analog analog = { 0 };
|
|
||||||
float values[APPA_55II_NUM_PROBES], *val_ptr = values;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* FIXME: timestamp should be sent in the packet */
|
/* FIXME: timestamp should be sent in the packet */
|
||||||
sr_dbg("Timestamp: %02d:%02d:%02d", buf[2], buf[3], buf[4]);
|
sr_dbg("Timestamp: %02d:%02d:%02d", buf[2], buf[3], buf[4]);
|
||||||
|
|
||||||
|
memset(&analog, 0, sizeof(analog));
|
||||||
analog.num_samples = 1;
|
analog.num_samples = 1;
|
||||||
analog.mq = SR_MQ_TEMPERATURE;
|
analog.mq = SR_MQ_TEMPERATURE;
|
||||||
analog.unit = SR_UNIT_CELSIUS;
|
analog.unit = SR_UNIT_CELSIUS;
|
||||||
analog.data = values;
|
analog.data = values;
|
||||||
|
|
||||||
for (i=0; i<APPA_55II_NUM_PROBES; i++) {
|
for (i = 0; i < APPA_55II_NUM_PROBES; i++) {
|
||||||
int16_t temp = RL16(buf+12+2*i);
|
temp = RL16(buf + 12 + 2 * i);
|
||||||
struct sr_probe *probe = g_slist_nth_data(sdi->probes, i);
|
probe = g_slist_nth_data(sdi->probes, i);
|
||||||
if (!probe->enabled)
|
if (!probe->enabled)
|
||||||
continue;
|
continue;
|
||||||
analog.probes = g_slist_append(analog.probes, probe);
|
analog.probes = g_slist_append(analog.probes, probe);
|
||||||
|
@ -153,15 +183,19 @@ static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
static void appa_55ii_log_data(struct sr_dev_inst *sdi, const uint8_t *buf)
|
static void appa_55ii_log_data(struct sr_dev_inst *sdi, const uint8_t *buf)
|
||||||
{
|
{
|
||||||
struct dev_context *devc = sdi->priv;
|
struct dev_context *devc;
|
||||||
const uint8_t *ptr = buf + 4;;
|
const uint8_t *ptr;
|
||||||
unsigned int size = buf[3];
|
unsigned int size;
|
||||||
|
int s;
|
||||||
|
|
||||||
|
devc = sdi->priv;
|
||||||
if (devc->data_source != DATA_SOURCE_MEMORY)
|
if (devc->data_source != DATA_SOURCE_MEMORY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
ptr = buf + 4;;
|
||||||
|
size = buf[3];
|
||||||
while (size > 0) {
|
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);
|
memcpy(devc->log_buf + devc->log_buf_len, ptr, s);
|
||||||
devc->log_buf_len += s;
|
devc->log_buf_len += s;
|
||||||
size -= s;
|
size -= s;
|
||||||
|
@ -173,8 +207,9 @@ static void appa_55ii_log_data(struct sr_dev_inst *sdi, const uint8_t *buf)
|
||||||
|
|
||||||
static void appa_55ii_log_end(struct sr_dev_inst *sdi)
|
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)
|
if (devc->data_source != DATA_SOURCE_MEMORY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -182,26 +217,39 @@ static void appa_55ii_log_end(struct sr_dev_inst *sdi)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const uint8_t *appa_55ii_parse_data(struct sr_dev_inst *sdi,
|
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)
|
if (len < 5)
|
||||||
return NULL; /* need more data */
|
/* Need more data. */
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (buf[0] != 0x55 || buf[1] != 0x55)
|
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])
|
if (len < 5 + buf[3])
|
||||||
return NULL; /* need more data */
|
/* Need more data. */
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (!appa_55ii_checksum(buf))
|
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]) {
|
switch ((PacketType) buf[2]) {
|
||||||
case LIVE_DATA: appa_55ii_live_data(sdi, buf); break;
|
case LIVE_DATA:
|
||||||
case LOG_METADATA: appa_55ii_log_metadata(sdi, buf); break;
|
appa_55ii_live_data(sdi, buf);
|
||||||
case LOG_DATA: appa_55ii_log_data(sdi, buf); break;
|
break;
|
||||||
case LOG_START: break;
|
case LOG_METADATA:
|
||||||
case LOG_END: appa_55ii_log_end(sdi); break;
|
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;
|
return buf + 4 + buf[3] + 1;
|
||||||
|
@ -212,6 +260,7 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data)
|
||||||
struct sr_dev_inst *sdi;
|
struct sr_dev_inst *sdi;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
|
int64_t time;
|
||||||
const uint8_t *ptr, *next_ptr, *end_ptr;
|
const uint8_t *ptr, *next_ptr, *end_ptr;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
@ -253,7 +302,7 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devc->limit_msec) {
|
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) {
|
if (time > (int64_t)devc->limit_msec) {
|
||||||
sr_info("Requested time limit reached.");
|
sr_info("Requested time limit reached.");
|
||||||
sdi->driver->dev_acquisition_stop(sdi, devc->session_cb_data);
|
sdi->driver->dev_acquisition_stop(sdi, devc->session_cb_data);
|
||||||
|
|
Loading…
Reference in New Issue